Action.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef ACTION_H
  2. #define ACTION_H
  3. //--------------------------------------------------------------------------------
  4. //
  5. // Actions.h - header file for the Action Base object and the Action Mgr.
  6. // Actions are things that can be undone
  7. //
  8. //---------------------------------------------------------------------------//
  9. // Copyright (C) Microsoft Corporation. All rights reserved. //
  10. //===========================================================================//
  11. #define MAX_DESC_LENGTH 256
  12. class ActionUndoMgr;
  13. class Action;
  14. #ifndef ELIST_H
  15. #include "Elist.h"
  16. #endif
  17. // Abstract base class for all action objects
  18. class Action
  19. {
  20. public:
  21. virtual ~Action(){}
  22. virtual bool redo() = 0;
  23. virtual bool undo() = 0;
  24. Action& operator=( const Action& src );
  25. const char* getDescription(){ return m_strDescription; }
  26. char m_strDescription[MAX_DESC_LENGTH];
  27. protected:
  28. // suppressed
  29. Action( const char* pStr )
  30. {
  31. gosASSERT( strlen( pStr ) < MAX_DESC_LENGTH );
  32. strcpy( m_strDescription, pStr );
  33. }
  34. // if you call this, make sure you set the description
  35. Action(){ m_strDescription[0] = 0; }
  36. };
  37. struct VertexInfo
  38. {
  39. VertexInfo( long row, long column );
  40. ~VertexInfo(){}
  41. int row;
  42. int column;
  43. int terrainData;
  44. int textureData;
  45. float elevation;
  46. private:
  47. // make sure the list class doesn't try and use this
  48. VertexInfo& operator=( const VertexInfo& );
  49. };
  50. typedef EList< VertexInfo, const VertexInfo& > VERTEX_INFO_LIST;
  51. // for undo redo buffer, since it deals with
  52. // the same stuff as the tile brush, I put
  53. // it here
  54. class ActionPaintTile : public Action
  55. {
  56. public:
  57. ActionPaintTile(){}
  58. // virtual overrides
  59. virtual bool redo();
  60. virtual bool undo();
  61. bool doRedo(); // so we don't go through virtual functions
  62. ActionPaintTile( const char* pStr )
  63. : Action( pStr ){}
  64. void addChangedVertexInfo( int row, int column );
  65. void addVertexInfo( VertexInfo& );
  66. bool getOldHeight( int row, int column, float& oldHeight );
  67. VERTEX_INFO_LIST vertexInfoList;
  68. private:
  69. };
  70. #ifndef EDITOROBJECTS_H
  71. #include "EditorObjects.h"
  72. #endif
  73. class ModifyBuildingAction : public Action
  74. {
  75. public:
  76. virtual ~ModifyBuildingAction();
  77. virtual bool redo();
  78. virtual bool undo();
  79. bool doRedo(); // so we don't go through virtual functions
  80. virtual void addBuildingInfo(EditorObject& info);
  81. virtual bool isNotNull()
  82. {
  83. return (0 < buildingCopyPtrs.Count());
  84. }
  85. virtual void updateNotedObjectPositions();
  86. private:
  87. typedef EList< EditorObject *, EditorObject *> OBJ_INFO_PTR_LIST;
  88. typedef EList< ObjectAppearance, ObjectAppearance&> OBJ_APPEAR_LIST;
  89. struct CObjectID
  90. {
  91. float x;
  92. float y;
  93. };
  94. typedef EList<CObjectID, CObjectID&> OBJ_ID_LIST;
  95. OBJ_INFO_PTR_LIST buildingCopyPtrs;
  96. OBJ_APPEAR_LIST buildingAppearanceCopies;
  97. OBJ_INFO_PTR_LIST buildingPtrs;
  98. OBJ_ID_LIST buildingIDs;
  99. };
  100. // this mgr holds all the actions
  101. class ActionUndoMgr
  102. {
  103. public:
  104. ActionUndoMgr( );
  105. ~ActionUndoMgr();
  106. void AddAction( Action* pAction );
  107. bool Redo();
  108. bool Undo();
  109. void Reset();
  110. bool HaveUndo() const;
  111. bool HaveRedo() const;
  112. const char* GetUndoString();
  113. const char* GetRedoString();
  114. void NoteThatASaveHasJustOccurred();
  115. bool ThereHasBeenANetChangeFromWhenLastSaved();
  116. static ActionUndoMgr* instance;
  117. private:
  118. typedef EList< Action*, Action* > ACTION_LIST;
  119. typedef long ACTION_POS;
  120. void EmptyUndoList();
  121. ACTION_LIST m_listUndoActions;
  122. ACTION_POS m_CurrentPos;
  123. ACTION_POS m_PosOfLastSave;
  124. }; // class SActionMgr
  125. #endif// ACTION_H