editor.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, 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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/worldEditor/editor.h"
  23. #include "console/console.h"
  24. #include "console/consoleInternal.h"
  25. #include "gui/controls/guiTextListCtrl.h"
  26. #include "T3D/shapeBase.h"
  27. #include "T3D/gameBase/gameConnection.h"
  28. #ifndef TORQUE_PLAYER
  29. // See matching #ifdef in app/game.cpp
  30. bool gEditingMission = false;
  31. #endif
  32. //------------------------------------------------------------------------------
  33. // Class EditManager
  34. //------------------------------------------------------------------------------
  35. IMPLEMENT_CONOBJECT(EditManager);
  36. ConsoleDocClass( EditManager,
  37. "@brief For Editor use only, deprecated\n\n"
  38. "@internal"
  39. );
  40. EditManager::EditManager()
  41. {
  42. for(U32 i = 0; i < 10; i++)
  43. mBookmarks[i] = MatrixF(true);
  44. }
  45. EditManager::~EditManager()
  46. {
  47. }
  48. //------------------------------------------------------------------------------
  49. bool EditManager::onWake()
  50. {
  51. if(!Parent::onWake())
  52. return(false);
  53. return(true);
  54. }
  55. void EditManager::onSleep()
  56. {
  57. Parent::onSleep();
  58. }
  59. //------------------------------------------------------------------------------
  60. bool EditManager::onAdd()
  61. {
  62. if(!Parent::onAdd())
  63. return(false);
  64. // hook the namespace
  65. const char * name = getName();
  66. if(name && name[0] && getClassRep())
  67. {
  68. Namespace * parent = getClassRep()->getNameSpace();
  69. Con::linkNamespaces(parent->mName, name);
  70. mNameSpace = Con::lookupNamespace(name);
  71. }
  72. return(true);
  73. }
  74. //------------------------------------------------------------------------------
  75. // NOTE: since EditManager is not actually used as a gui anymore, onWake/Sleep
  76. // were never called, which broke anyone hooking into onEditorEnable/onEditorDisable
  77. // and gEditingMission. So, moved these to happen in response to console methods
  78. // which should be called at the appropriate time.
  79. //
  80. // This is a quick fix and this system is still "begging" for a remake.
  81. void EditManager::editorEnabled()
  82. {
  83. for(SimGroupIterator itr(Sim::getRootGroup()); *itr; ++itr)
  84. (*itr)->onEditorEnable();
  85. gEditingMission = true;
  86. }
  87. void EditManager::editorDisabled()
  88. {
  89. for(SimGroupIterator itr(Sim::getRootGroup()); *itr; ++itr)
  90. {
  91. SimObject *so = *itr;
  92. AssertFatal(so->isProperlyAdded() && !so->isRemoved(), "bad");
  93. so->onEditorDisable();
  94. }
  95. gEditingMission = false;
  96. }
  97. //------------------------------------------------------------------------------
  98. static GameBase * getControlObj()
  99. {
  100. GameConnection * connection = GameConnection::getLocalClientConnection();
  101. ShapeBase* control = 0;
  102. if(connection)
  103. control = dynamic_cast<ShapeBase*>(connection->getControlObject());
  104. return(control);
  105. }
  106. ConsoleMethod( EditManager, setBookmark, void, 3, 3, "(int slot)")
  107. {
  108. S32 val = dAtoi(argv[2]);
  109. if(val < 0 || val > 9)
  110. return;
  111. GameBase * control = getControlObj();
  112. if(control)
  113. object->mBookmarks[val] = control->getTransform();
  114. }
  115. ConsoleMethod( EditManager, gotoBookmark, void, 3, 3, "(int slot)")
  116. {
  117. S32 val = dAtoi(argv[2]);
  118. if(val < 0 || val > 9)
  119. return;
  120. GameBase * control = getControlObj();
  121. if(control)
  122. control->setTransform(object->mBookmarks[val]);
  123. }
  124. ConsoleMethod( EditManager, editorEnabled, void, 2, 2, "Perform the onEditorEnabled callback on all SimObjects and set gEditingMission true" )
  125. {
  126. object->editorEnabled();
  127. }
  128. ConsoleMethod( EditManager, editorDisabled, void, 2, 2, "Perform the onEditorDisabled callback on all SimObjects and set gEditingMission false" )
  129. {
  130. object->editorDisabled();
  131. }
  132. ConsoleMethod( EditManager, isEditorEnabled, bool, 2, 2, "Return the value of gEditingMission." )
  133. {
  134. return gEditingMission;
  135. }