CreateComponentButton.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import ComponentInspector = require("./ComponentInspector");
  2. var audioCreateSource = new Atomic.UIMenuItemSource();
  3. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundListener", "SoundListener"));
  4. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource", "SoundSource"));
  5. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource3D", "SoundSource3D"));
  6. var _2DCreateSource = new Atomic.UIMenuItemSource();
  7. _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
  8. _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
  9. var geometryCreateSource = new Atomic.UIMenuItemSource();
  10. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModel", "StaticModel"));
  11. geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimatedModel", "create component"));
  12. geometryCreateSource.addItem(new Atomic.UIMenuItem("BillboardSet", "create component"));
  13. geometryCreateSource.addItem(new Atomic.UIMenuItem("CustomGeometry", "create component"));
  14. geometryCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter", "create component"));
  15. geometryCreateSource.addItem(new Atomic.UIMenuItem("Skybox", "SkyBox"));
  16. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModelGroup", "create component"));
  17. geometryCreateSource.addItem(new Atomic.UIMenuItem("Terrain", "create component"));
  18. geometryCreateSource.addItem(new Atomic.UIMenuItem("Text3D", "create component"));
  19. geometryCreateSource.addItem(new Atomic.UIMenuItem("Water", "create component"));
  20. var logicCreateSource = new Atomic.UIMenuItemSource();
  21. logicCreateSource.addItem(new Atomic.UIMenuItem("JSComponent", "JSComponent"));
  22. logicCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "create component"));
  23. logicCreateSource.addItem(new Atomic.UIMenuItem("SplinePath", "create component"));
  24. var navigationCreateSource = new Atomic.UIMenuItemSource();
  25. navigationCreateSource.addItem(new Atomic.UIMenuItem("Navigable", "create component"));
  26. navigationCreateSource.addItem(new Atomic.UIMenuItem("NavigationMesh", "create component"));
  27. navigationCreateSource.addItem(new Atomic.UIMenuItem("OffMeshConnection", "create component"));
  28. var networkCreateSource = new Atomic.UIMenuItemSource();
  29. networkCreateSource.addItem(new Atomic.UIMenuItem("Network Priority", "create component"));
  30. var physicsCreateSource = new Atomic.UIMenuItemSource();
  31. physicsCreateSource.addItem(new Atomic.UIMenuItem("CollisionShape", "CollisionShape"));
  32. physicsCreateSource.addItem(new Atomic.UIMenuItem("Constraint", "create component"));
  33. physicsCreateSource.addItem(new Atomic.UIMenuItem("RigidBody", "RigidBody"));
  34. var sceneCreateSource = new Atomic.UIMenuItemSource();
  35. sceneCreateSource.addItem(new Atomic.UIMenuItem("Camera", "Camera"));
  36. sceneCreateSource.addItem(new Atomic.UIMenuItem("Light", "Light"));
  37. sceneCreateSource.addItem(new Atomic.UIMenuItem("Zone", "create component"));
  38. var subsystemCreateSource = new Atomic.UIMenuItemSource();
  39. subsystemCreateSource.addItem(new Atomic.UIMenuItem("DebugRenderer", "create component"));
  40. subsystemCreateSource.addItem(new Atomic.UIMenuItem("Octree", "create component"));
  41. subsystemCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld", "create component"));
  42. var componentCreateSource = new Atomic.UIMenuItemSource();
  43. var sources = {
  44. Audio: audioCreateSource,
  45. "2D": _2DCreateSource,
  46. Geometry: geometryCreateSource,
  47. Logic: logicCreateSource,
  48. Navigation: navigationCreateSource,
  49. Network: networkCreateSource,
  50. Physics: physicsCreateSource,
  51. Scene: sceneCreateSource,
  52. SubSystem: subsystemCreateSource,
  53. }
  54. for (var sub in sources) {
  55. var item = new Atomic.UIMenuItem(sub);
  56. item.subSource = sources[sub];
  57. componentCreateSource.addItem(item);
  58. }
  59. class CreateComponentButton extends Atomic.UIButton {
  60. constructor(node: Atomic.Node) {
  61. super();
  62. this.node = node;
  63. this.fd.id = "Vera";
  64. this.fd.size = 11;
  65. this.text = "Create Component";
  66. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  67. }
  68. // note instance method
  69. onClick = () => {
  70. var menu = new Atomic.UIMenuWindow(this, "create component popup");
  71. menu.fontDescription = this.fd;
  72. menu.show(componentCreateSource);
  73. }
  74. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  75. if (ev.type != Atomic.UI_EVENT_TYPE_CLICK)
  76. return;
  77. if (ev.target && ev.target.id == "create component popup") {
  78. var c = this.node.createComponent(ev.refid);
  79. if (c) {
  80. var ci = new ComponentInspector();
  81. ci.inspect(c);
  82. this.parent.addChildRelative(ci, Atomic.UI_WIDGET_Z_REL_BEFORE, this);
  83. }
  84. return true;
  85. }
  86. }
  87. node: Atomic.Node;
  88. fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
  89. }
  90. export = CreateComponentButton;