undoActions.h

Engine/source/gui/worldEditor/undoActions.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _GUI_WORLDEDITOR_UNDOACTIONS_H_
 25#define _GUI_WORLDEDITOR_UNDOACTIONS_H_
 26
 27#ifndef _UNDO_H_
 28#include "util/undo.h"
 29#endif
 30#ifndef _CONSOLE_SIMOBJECTMEMENTO_H_
 31#include "console/simObjectMemento.h"
 32#endif
 33
 34// Need full definition visible for SimObjectPtr<GuiInspectorField>
 35#include "gui/editor/inspector/field.h"
 36
 37class GuiInspector;
 38
 39class MECreateUndoAction : public UndoAction
 40{
 41   typedef UndoAction Parent;
 42
 43protected:
 44
 45   struct ObjectState
 46   {
 47      /// The object we created and will delete in undo.
 48      SimObjectId id;
 49
 50      /// The captured object state.
 51      SimObjectMemento memento;
 52
 53      /// Keep track of the parent group.
 54      SimObjectId groupId;
 55   };
 56
 57   /// All the objects that were created.
 58   Vector<ObjectState> mObjects;
 59
 60public:
 61
 62   DECLARE_CONOBJECT( MECreateUndoAction );
 63   static void initPersistFields();
 64   
 65   MECreateUndoAction( const UTF8* actionName = " " );
 66   virtual ~MECreateUndoAction();
 67
 68   void addObject( SimObject *object );
 69
 70   // UndoAction
 71   virtual void undo();
 72   virtual void redo();
 73};
 74
 75
 76class MEDeleteUndoAction : public UndoAction
 77{
 78   typedef UndoAction Parent;
 79
 80protected:
 81
 82   struct ObjectState
 83   {
 84      /// The object we deleted and will restore in undo.
 85      SimObjectId id;
 86
 87      /// The captured object state.
 88      SimObjectMemento memento;
 89
 90      /// Keep track of the parent group.
 91      SimObjectId groupId;
 92   };
 93
 94   /// All the objects we're deleting.
 95   Vector<ObjectState> mObjects;
 96
 97public:
 98
 99   DECLARE_CONOBJECT( MEDeleteUndoAction );
100   static void initPersistFields();
101   
102   MEDeleteUndoAction( const UTF8* actionName = "Delete Object" );
103   virtual ~MEDeleteUndoAction();
104
105   ///
106   void deleteObject( SimObject *object );
107   void deleteObject( const Vector<SimObject*> &objectList );
108
109   // UndoAction
110   virtual void undo();
111   virtual void redo();
112};
113
114class InspectorFieldUndoAction : public UndoAction
115{
116   typedef UndoAction Parent;
117
118public:
119
120   InspectorFieldUndoAction();
121   InspectorFieldUndoAction( const UTF8* actionName );
122
123   DECLARE_CONOBJECT( InspectorFieldUndoAction );
124   static void initPersistFields();
125
126   GuiInspector *mInspector;
127   SimObjectId mObjId;
128   SimObjectPtr<GuiInspectorField> mField; 
129   StringTableEntry mSlotName;
130   StringTableEntry mArrayIdx;
131   String mData;         
132
133   // UndoAction
134   virtual void undo();
135   virtual void redo() { undo(); }
136};
137
138#endif // _GUI_WORLDEDITOR_UNDOACTIONS_H_
139