undoActions.h 3.6 KB

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