editor.cpp 4.8 KB

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