CMapEditManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * CMapEditManager.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../GameConstants.h"
  12. #include "CMapOperation.h"
  13. #include "Terrain.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class CTerrainViewPatternConfig;
  17. struct TerrainViewPattern;
  18. class CMap;
  19. /// The CMapUndoManager provides the functionality to save operations and undo/redo them.
  20. class DLL_LINKAGE CMapUndoManager : boost::noncopyable
  21. {
  22. public:
  23. CMapUndoManager();
  24. void undo();
  25. void redo();
  26. void clearAll();
  27. /// The undo redo limit is a number which says how many undo/redo items can be saved. The default
  28. /// value is 10. If the value is 0, no undo/redo history will be maintained.
  29. /// FIXME: unlimited undo please
  30. int getUndoRedoLimit() const;
  31. void setUndoRedoLimit(int value);
  32. const CMapOperation * peekRedo() const;
  33. const CMapOperation * peekUndo() const;
  34. void addOperation(std::unique_ptr<CMapOperation> && operation); /// Client code does not need to call this method.
  35. //poor man's signal
  36. void setUndoCallback(std::function<void(bool, bool)> functor);
  37. private:
  38. typedef std::list<std::unique_ptr<CMapOperation> > TStack;
  39. void doOperation(TStack & fromStack, TStack & toStack, bool doUndo);
  40. const CMapOperation * peek(const TStack & stack) const;
  41. TStack undoStack;
  42. TStack redoStack;
  43. int undoRedoLimit;
  44. void onUndoRedo();
  45. std::function<void(bool allowUndo, bool allowRedo)> undoCallback;
  46. };
  47. /// The map edit manager provides functionality for drawing terrain and placing
  48. /// objects on the map.
  49. class DLL_LINKAGE CMapEditManager : boost::noncopyable
  50. {
  51. public:
  52. CMapEditManager(CMap * map);
  53. CMap * getMap();
  54. /// Clears the terrain. The free level is filled with water and the underground level with rock.
  55. void clearTerrain(CRandomGenerator * gen = nullptr);
  56. /// Draws terrain at the current terrain selection. The selection will be cleared automatically.
  57. void drawTerrain(TerrainId terType, CRandomGenerator * gen = nullptr);
  58. /// Draws roads at the current terrain selection. The selection will be cleared automatically.
  59. void drawRoad(RoadId roadType, CRandomGenerator * gen = nullptr);
  60. /// Draws rivers at the current terrain selection. The selection will be cleared automatically.
  61. void drawRiver(RiverId riverType, CRandomGenerator * gen = nullptr);
  62. void insertObject(CGObjectInstance * obj);
  63. void insertObjects(std::set<CGObjectInstance *> & objects);
  64. void moveObject(CGObjectInstance * obj, const int3 & pos);
  65. void removeObject(CGObjectInstance * obj);
  66. void removeObjects(std::set<CGObjectInstance *> & objects);
  67. CTerrainSelection & getTerrainSelection();
  68. CObjectSelection & getObjectSelection();
  69. CMapUndoManager & getUndoManager();
  70. private:
  71. void execute(std::unique_ptr<CMapOperation> && operation);
  72. CMap * map;
  73. CMapUndoManager undoManager;
  74. CRandomGenerator gen;
  75. CTerrainSelection terrainSel;
  76. CObjectSelection objectSel;
  77. };
  78. VCMI_LIB_NAMESPACE_END