undoActions.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #ifndef _GUI_WORLDEDITOR_UNDOACTIONS_H_
  23. #define _GUI_WORLDEDITOR_UNDOACTIONS_H_
  24. #ifndef _UNDO_H_
  25. #include "util/undo.h"
  26. #endif
  27. #ifndef _CONSOLE_SIMOBJECTMEMENTO_H_
  28. #include "console/simObjectMemento.h"
  29. #endif
  30. class GuiInspectorField;
  31. class GuiInspector;
  32. class MECreateUndoAction : public UndoAction
  33. {
  34. typedef UndoAction Parent;
  35. protected:
  36. struct ObjectState
  37. {
  38. /// The object we created and will delete in undo.
  39. SimObjectId id;
  40. /// The captured object state.
  41. SimObjectMemento memento;
  42. /// Keep track of the parent group.
  43. SimObjectId groupId;
  44. };
  45. /// All the objects that were created.
  46. Vector<ObjectState> mObjects;
  47. public:
  48. DECLARE_CONOBJECT( MECreateUndoAction );
  49. static void initPersistFields();
  50. MECreateUndoAction( const UTF8* actionName = " " );
  51. virtual ~MECreateUndoAction();
  52. void addObject( SimObject *object );
  53. // UndoAction
  54. virtual void undo();
  55. virtual void redo();
  56. };
  57. class MEDeleteUndoAction : public UndoAction
  58. {
  59. typedef UndoAction Parent;
  60. protected:
  61. struct ObjectState
  62. {
  63. /// The object we deleted and will restore in undo.
  64. SimObjectId id;
  65. /// The captured object state.
  66. SimObjectMemento memento;
  67. /// Keep track of the parent group.
  68. SimObjectId groupId;
  69. };
  70. /// All the objects we're deleting.
  71. Vector<ObjectState> mObjects;
  72. public:
  73. DECLARE_CONOBJECT( MEDeleteUndoAction );
  74. static void initPersistFields();
  75. MEDeleteUndoAction( const UTF8* actionName = "Delete Object" );
  76. virtual ~MEDeleteUndoAction();
  77. ///
  78. void deleteObject( SimObject *object );
  79. void deleteObject( const Vector<SimObject*> &objectList );
  80. // UndoAction
  81. virtual void undo();
  82. virtual void redo();
  83. };
  84. class InspectorFieldUndoAction : public UndoAction
  85. {
  86. typedef UndoAction Parent;
  87. public:
  88. InspectorFieldUndoAction();
  89. InspectorFieldUndoAction( const UTF8* actionName );
  90. DECLARE_CONOBJECT( InspectorFieldUndoAction );
  91. static void initPersistFields();
  92. GuiInspector *mInspector;
  93. SimObjectId mObjId;
  94. SimObjectPtr<GuiInspectorField> mField;
  95. StringTableEntry mSlotName;
  96. StringTableEntry mArrayIdx;
  97. String mData;
  98. // UndoAction
  99. virtual void undo();
  100. virtual void redo() { undo(); }
  101. };
  102. #endif // _GUI_WORLDEDITOR_UNDOACTIONS_H_