CreateComponentButton.ts 5.8 KB

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