2
0

EntityEditorPropertyView.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. Copyright (C) 2013 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "EntityEditorPropertyView.h"
  20. EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
  21. targetEntity = NULL;
  22. entityProps = new PropList();
  23. addChild(entityProps);
  24. transformSheet = new TransformSheet();
  25. entityProps->addPropSheet(transformSheet);
  26. transformSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  27. materialSheet = new MaterialPropSheet();
  28. entityProps->addPropSheet(materialSheet);
  29. materialSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  30. materialSheet->addEventListener(this, Event::CHANGE_EVENT);
  31. shaderTexturesSheet = new ShaderTexturesSheet();
  32. entityProps->addPropSheet(shaderTexturesSheet);
  33. shaderTexturesSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  34. shaderOptionsSheet = new ShaderOptionsSheet();
  35. entityProps->addPropSheet(shaderOptionsSheet);
  36. shaderOptionsSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  37. labelSheet = new SceneLabelSheet();
  38. entityProps->addPropSheet(labelSheet);
  39. labelSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  40. lightSheet = new SceneLightSheet();
  41. entityProps->addPropSheet(lightSheet);
  42. lightSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  43. particleSheet = new ParticleEmitterSheet();
  44. entityProps->addPropSheet(particleSheet);
  45. particleSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  46. spriteSheet = new SceneSpriteSheet();
  47. entityProps->addPropSheet(spriteSheet);
  48. spriteSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  49. primitiveSheet = new ScenePrimitiveSheet();
  50. entityProps->addPropSheet(primitiveSheet);
  51. primitiveSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  52. soundSheet = new SoundSheet();
  53. entityProps->addPropSheet(soundSheet);
  54. soundSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  55. cameraSheet = new CameraSheet();
  56. entityProps->addPropSheet(cameraSheet);
  57. cameraSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  58. entitySheet = new EntitySheet();
  59. entityProps->addPropSheet(entitySheet);
  60. entitySheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  61. propSheet = new EntityPropSheet();
  62. entityProps->addPropSheet(propSheet);
  63. propSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  64. }
  65. void EntityEditorPropertyView::setEntityInstance(SceneEntityInstance *instance) {
  66. materialSheet->setEntityInstance(instance);
  67. }
  68. void EntityEditorPropertyView::Resize(Number width, Number height) {
  69. entityProps->Resize(width, height);
  70. UIElement::Resize(width, height);
  71. }
  72. void EntityEditorPropertyView::handleEvent(Event *event) {
  73. if(event->getEventCode() == PropEvent::EVENT_PROP_CHANGE) {
  74. PropEvent *propEvent = (PropEvent*) event;
  75. PropEvent *newPropEvent = new PropEvent(propEvent->prop, propEvent->sheet, propEvent->beforeData, propEvent->afterData);
  76. dispatchEvent(newPropEvent, PropEvent::EVENT_PROP_CHANGE);
  77. } else {
  78. if(event->getDispatcher() == materialSheet) {
  79. if(targetEntity) {
  80. updateShaderOptions();
  81. }
  82. }
  83. }
  84. }
  85. void EntityEditorPropertyView::updateShaderOptions() {
  86. SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(targetEntity);
  87. SceneLabel *sceneLabel = dynamic_cast<SceneLabel*>(targetEntity);
  88. SceneSprite *sceneSprite = dynamic_cast<SceneSprite*>(targetEntity);
  89. shaderTexturesSheet->enabled = false;
  90. shaderOptionsSheet->enabled = false;
  91. if(sceneMesh) {
  92. if(sceneMesh->getMaterial() && sceneMesh->getLocalShaderOptions()) {
  93. // can't edit the textures manually on a scene label or sprite
  94. if(!sceneLabel && !sceneSprite) {
  95. shaderTexturesSheet->setShader(sceneMesh->getMaterial()->getShader(0), sceneMesh->getMaterial(), sceneMesh->getLocalShaderOptions());
  96. shaderTexturesSheet->enabled = true;
  97. }
  98. shaderOptionsSheet->setShader(sceneMesh->getMaterial()->getShader(0), sceneMesh->getMaterial(), sceneMesh->getLocalShaderOptions());
  99. }
  100. }
  101. }
  102. void EntityEditorPropertyView::setEntity(Entity *entity) {
  103. targetEntity = entity;
  104. SceneLight *sceneLight = dynamic_cast<SceneLight*>(entity);
  105. lightSheet->setSceneLight(sceneLight);
  106. SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(entity);
  107. materialSheet->setSceneMesh(sceneMesh);
  108. updateShaderOptions();
  109. SceneLabel *sceneLabel = dynamic_cast<SceneLabel*>(entity);
  110. labelSheet->setSceneLabel(sceneLabel);
  111. SceneSprite *sceneSprite = dynamic_cast<SceneSprite*>(entity);
  112. spriteSheet->setSprite(sceneSprite);
  113. ScenePrimitive *scenePrimitive = dynamic_cast<ScenePrimitive*>(entity);
  114. if(!sceneLabel && !sceneSprite) {
  115. primitiveSheet->setScenePrimitive(scenePrimitive);
  116. } else {
  117. primitiveSheet->setScenePrimitive(NULL);
  118. }
  119. SceneSound *sound = dynamic_cast<SceneSound*>(entity);
  120. soundSheet->setSound(sound);
  121. Camera *camera = dynamic_cast<Camera*>(entity);
  122. cameraSheet->setCamera(camera);
  123. SceneParticleEmitter *emitter = dynamic_cast<SceneParticleEmitter*>(entity);
  124. particleSheet->setParticleEmitter(emitter);
  125. entitySheet->setEntity(entity);
  126. propSheet->setEntity(entity);
  127. transformSheet->setEntity(entity);
  128. Resize(getWidth(), getHeight());
  129. }
  130. EntityEditorPropertyView::~EntityEditorPropertyView() {
  131. entityProps->setOwnsChildrenRecursive(true);
  132. delete entityProps;
  133. }