CreateComponentButton.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // Native components aren't self registering with the editor, so we need to
  23. // add them to the component menu.
  24. // TODO: self registration of native components
  25. var myProjectSource = new Atomic.UIMenuItemSource();
  26. myProjectSource.addItem(new Atomic.UIMenuItem("MyNativeComponent", "MyNativeComponent"));
  27. var audioCreateSource = new Atomic.UIMenuItemSource();
  28. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundListener", "SoundListener"));
  29. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource", "SoundSource"));
  30. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource3D", "SoundSource3D"));
  31. var _2DCreateSource = new Atomic.UIMenuItemSource();
  32. _2DCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld2D", "PhysicsWorld2D"));
  33. _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
  34. _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
  35. _2DCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter2D", "ParticleEmitter2D"));
  36. _2DCreateSource.addItem(new Atomic.UIMenuItem("PointLight2D", "PointLight2D"));
  37. _2DCreateSource.addItem(new Atomic.UIMenuItem("DirectionalLight2D", "DirectionalLight2D"));
  38. _2DCreateSource.addItem(new Atomic.UIMenuItem("RigidBody2D", "RigidBody2D"));
  39. _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionBox2D", "CollisionBox2D"));
  40. _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionCircle2D", "CollisionCircle2D"));
  41. _2DCreateSource.addItem(new Atomic.UIMenuItem("TileMap2D", "TileMap2D"));
  42. var geometryCreateSource = new Atomic.UIMenuItemSource();
  43. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModel", "StaticModel"));
  44. geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimatedModel", "AnimatedModel"));
  45. geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "AnimationController"));
  46. geometryCreateSource.addItem(new Atomic.UIMenuItem("BillboardSet", "BillboardSet"));
  47. geometryCreateSource.addItem(new Atomic.UIMenuItem("CustomGeometry", "CustomGeometry"));
  48. geometryCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter", "ParticleEmitter"));
  49. geometryCreateSource.addItem(new Atomic.UIMenuItem("RibbonTrail", "RibbonTrail"));
  50. geometryCreateSource.addItem(new Atomic.UIMenuItem("Skybox", "SkyBox"));
  51. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModelGroup", "StaticModelGroup"));
  52. geometryCreateSource.addItem(new Atomic.UIMenuItem("Terrain", "Terrain"));
  53. geometryCreateSource.addItem(new Atomic.UIMenuItem("Text3D", "create component"));
  54. geometryCreateSource.addItem(new Atomic.UIMenuItem("Water", "Water"));
  55. var logicCreateSource = new Atomic.UIMenuItemSource();
  56. logicCreateSource.addItem(new Atomic.UIMenuItem("JSComponent", "JSComponent"));
  57. logicCreateSource.addItem(new Atomic.UIMenuItem("CSComponent", "CSComponent"));
  58. logicCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "AnimationController"));
  59. logicCreateSource.addItem(new Atomic.UIMenuItem("SplinePath", "SplinePath"));
  60. var navigationCreateSource = new Atomic.UIMenuItemSource();
  61. navigationCreateSource.addItem(new Atomic.UIMenuItem("CrowdAgent", "CrowdAgent"));
  62. navigationCreateSource.addItem(new Atomic.UIMenuItem("CrowdManager", "CrowdManager"));
  63. navigationCreateSource.addItem(new Atomic.UIMenuItem("NavArea", "NavArea"));
  64. navigationCreateSource.addItem(new Atomic.UIMenuItem("Navigable", "Navigable"));
  65. navigationCreateSource.addItem(new Atomic.UIMenuItem("NavigationMesh", "NavigationMesh"));
  66. navigationCreateSource.addItem(new Atomic.UIMenuItem("DynamicNavigationMesh", "DynamicNavigationMesh"));
  67. navigationCreateSource.addItem(new Atomic.UIMenuItem("Obstacle", "Obstacle"));
  68. navigationCreateSource.addItem(new Atomic.UIMenuItem("OffMeshConnection", "OffMeshConnection"));
  69. var networkCreateSource = new Atomic.UIMenuItemSource();
  70. networkCreateSource.addItem(new Atomic.UIMenuItem("Network Priority", "create component"));
  71. var physicsCreateSource = new Atomic.UIMenuItemSource();
  72. physicsCreateSource.addItem(new Atomic.UIMenuItem("CollisionShape", "CollisionShape"));
  73. physicsCreateSource.addItem(new Atomic.UIMenuItem("Constraint", "Constraint"));
  74. physicsCreateSource.addItem(new Atomic.UIMenuItem("RigidBody", "RigidBody"));
  75. var sceneCreateSource = new Atomic.UIMenuItemSource();
  76. sceneCreateSource.addItem(new Atomic.UIMenuItem("Camera", "Camera"));
  77. sceneCreateSource.addItem(new Atomic.UIMenuItem("Light", "Light"));
  78. sceneCreateSource.addItem(new Atomic.UIMenuItem("Zone", "Zone"));
  79. var subsystemCreateSource = new Atomic.UIMenuItemSource();
  80. subsystemCreateSource.addItem(new Atomic.UIMenuItem("DebugRenderer", "create component"));
  81. subsystemCreateSource.addItem(new Atomic.UIMenuItem("Octree", "create component"));
  82. subsystemCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld", "create component"));
  83. var editorCreateSource = new Atomic.UIMenuItemSource();
  84. editorCreateSource.addItem(new Atomic.UIMenuItem("CubemapGenerator", "CubemapGenerator"));
  85. var componentCreateSource = new Atomic.UIMenuItemSource();
  86. // TODO: self registration of native components/component groups
  87. var sources = {
  88. MyProject: myProjectSource, // add project menu source
  89. Audio: audioCreateSource,
  90. "2D": _2DCreateSource,
  91. Geometry: geometryCreateSource,
  92. Logic: logicCreateSource,
  93. Navigation: navigationCreateSource,
  94. Network: networkCreateSource,
  95. Physics: physicsCreateSource,
  96. Scene: sceneCreateSource,
  97. SubSystem: subsystemCreateSource,
  98. Editor : editorCreateSource
  99. };
  100. for (var sub in sources) {
  101. var item = new Atomic.UIMenuItem(sub);
  102. item.subSource = sources[sub];
  103. componentCreateSource.addItem(item);
  104. }
  105. class CreateComponentButton extends Atomic.UIButton {
  106. constructor() {
  107. super();
  108. this.fd.id = "Vera";
  109. this.fd.size = 11;
  110. this.text = "Create Component";
  111. this.subscribeToEvent(Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  112. }
  113. // note instance method
  114. onClick = () => {
  115. var menu = new Atomic.UIMenuWindow(this, "create component popup");
  116. menu.fontDescription = this.fd;
  117. menu.show(componentCreateSource);
  118. }
  119. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  120. if (ev.type != Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
  121. return;
  122. if (ev.target && ev.target.id == "create component popup") {
  123. this.sendEvent(Editor.SelectionCreateComponentEventData({ componentTypeName : ev.refid}));
  124. return true;
  125. }
  126. }
  127. fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
  128. }
  129. export = CreateComponentButton;