CreateComponentButton.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. var audioCreateSource = new Atomic.UIMenuItemSource();
  23. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundListener", "SoundListener"));
  24. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource", "SoundSource"));
  25. audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource3D", "SoundSource3D"));
  26. var _2DCreateSource = new Atomic.UIMenuItemSource();
  27. _2DCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld2D", "PhysicsWorld2D"));
  28. _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
  29. _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
  30. _2DCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter2D", "ParticleEmitter2D"));
  31. _2DCreateSource.addItem(new Atomic.UIMenuItem("PointLight2D", "PointLight2D"));
  32. _2DCreateSource.addItem(new Atomic.UIMenuItem("DirectionalLight2D", "DirectionalLight2D"));
  33. _2DCreateSource.addItem(new Atomic.UIMenuItem("RigidBody2D", "RigidBody2D"));
  34. _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionBox2D", "CollisionBox2D"));
  35. _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionCircle2D", "CollisionCircle2D"));
  36. _2DCreateSource.addItem(new Atomic.UIMenuItem("TileMap2D", "TileMap2D"));
  37. var geometryCreateSource = new Atomic.UIMenuItemSource();
  38. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModel", "StaticModel"));
  39. geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimatedModel", "AnimatedModel"));
  40. geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "AnimationController"));
  41. geometryCreateSource.addItem(new Atomic.UIMenuItem("BillboardSet", "BillboardSet"));
  42. geometryCreateSource.addItem(new Atomic.UIMenuItem("CustomGeometry", "CustomGeometry"));
  43. geometryCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter", "ParticleEmitter"));
  44. geometryCreateSource.addItem(new Atomic.UIMenuItem("RibbonTrail", "RibbonTrail"));
  45. geometryCreateSource.addItem(new Atomic.UIMenuItem("Skybox", "SkyBox"));
  46. geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModelGroup", "StaticModelGroup"));
  47. geometryCreateSource.addItem(new Atomic.UIMenuItem("Terrain", "Terrain"));
  48. geometryCreateSource.addItem(new Atomic.UIMenuItem("Text3D", "create component"));
  49. geometryCreateSource.addItem(new Atomic.UIMenuItem("Water", "Water"));
  50. var logicCreateSource = new Atomic.UIMenuItemSource();
  51. logicCreateSource.addItem(new Atomic.UIMenuItem("JSComponent", "JSComponent"));
  52. logicCreateSource.addItem(new Atomic.UIMenuItem("CSComponent", "CSComponent"));
  53. logicCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "AnimationController"));
  54. logicCreateSource.addItem(new Atomic.UIMenuItem("SplinePath", "SplinePath"));
  55. var navigationCreateSource = new Atomic.UIMenuItemSource();
  56. navigationCreateSource.addItem(new Atomic.UIMenuItem("CrowdAgent", "CrowdAgent"));
  57. navigationCreateSource.addItem(new Atomic.UIMenuItem("CrowdManager", "CrowdManager"));
  58. navigationCreateSource.addItem(new Atomic.UIMenuItem("NavArea", "NavArea"));
  59. navigationCreateSource.addItem(new Atomic.UIMenuItem("Navigable", "Navigable"));
  60. navigationCreateSource.addItem(new Atomic.UIMenuItem("NavigationMesh", "NavigationMesh"));
  61. navigationCreateSource.addItem(new Atomic.UIMenuItem("DynamicNavigationMesh", "DynamicNavigationMesh"));
  62. navigationCreateSource.addItem(new Atomic.UIMenuItem("Obstacle", "Obstacle"));
  63. navigationCreateSource.addItem(new Atomic.UIMenuItem("OffMeshConnection", "OffMeshConnection"));
  64. var networkCreateSource = new Atomic.UIMenuItemSource();
  65. networkCreateSource.addItem(new Atomic.UIMenuItem("Network Priority", "create component"));
  66. var physicsCreateSource = new Atomic.UIMenuItemSource();
  67. physicsCreateSource.addItem(new Atomic.UIMenuItem("CollisionShape", "CollisionShape"));
  68. physicsCreateSource.addItem(new Atomic.UIMenuItem("Constraint", "Constraint"));
  69. physicsCreateSource.addItem(new Atomic.UIMenuItem("RigidBody", "RigidBody"));
  70. var sceneCreateSource = new Atomic.UIMenuItemSource();
  71. sceneCreateSource.addItem(new Atomic.UIMenuItem("Camera", "Camera"));
  72. sceneCreateSource.addItem(new Atomic.UIMenuItem("Light", "Light"));
  73. sceneCreateSource.addItem(new Atomic.UIMenuItem("Zone", "Zone"));
  74. var subsystemCreateSource = new Atomic.UIMenuItemSource();
  75. subsystemCreateSource.addItem(new Atomic.UIMenuItem("DebugRenderer", "create component"));
  76. subsystemCreateSource.addItem(new Atomic.UIMenuItem("Octree", "create component"));
  77. subsystemCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld", "create component"));
  78. var editorCreateSource = new Atomic.UIMenuItemSource();
  79. editorCreateSource.addItem(new Atomic.UIMenuItem("GlowComponent", "GlowComponent"));
  80. editorCreateSource.addItem(new Atomic.UIMenuItem("CubemapGenerator", "CubemapGenerator"));
  81. var componentCreateSource = new Atomic.UIMenuItemSource();
  82. var sources = {
  83. Audio: audioCreateSource,
  84. "2D": _2DCreateSource,
  85. Geometry: geometryCreateSource,
  86. Logic: logicCreateSource,
  87. Navigation: navigationCreateSource,
  88. Network: networkCreateSource,
  89. Physics: physicsCreateSource,
  90. Scene: sceneCreateSource,
  91. SubSystem: subsystemCreateSource,
  92. Editor : editorCreateSource
  93. };
  94. for (var sub in sources) {
  95. var item = new Atomic.UIMenuItem(sub);
  96. item.subSource = sources[sub];
  97. componentCreateSource.addItem(item);
  98. }
  99. class CreateComponentButton extends Atomic.UIButton {
  100. constructor() {
  101. super();
  102. this.fd.id = "Vera";
  103. this.fd.size = 11;
  104. this.text = "Create Component";
  105. this.subscribeToEvent(Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  106. }
  107. // note instance method
  108. onClick = () => {
  109. var menu = new Atomic.UIMenuWindow(this, "create component popup");
  110. menu.fontDescription = this.fd;
  111. menu.show(componentCreateSource);
  112. };
  113. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  114. if (ev.type != Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
  115. return;
  116. if (ev.target && ev.target.id == "create component popup") {
  117. this.sendEvent(Editor.SelectionCreateComponentEventData({ componentTypeName : ev.refid}));
  118. return true;
  119. }
  120. }
  121. fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
  122. }
  123. export = CreateComponentButton;