2
0

CMapEditManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "MapEditUtils.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CMapOperation;
  15. namespace vstd
  16. {
  17. class RNG;
  18. }
  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. ~CMapUndoManager();
  25. void undo();
  26. void redo();
  27. void clearAll();
  28. /// The undo redo limit is a number which says how many undo/redo items can be saved. The default
  29. /// value is 10. If the value is 0, no undo/redo history will be maintained.
  30. /// FIXME: unlimited undo please
  31. int getUndoRedoLimit() const;
  32. void setUndoRedoLimit(int value);
  33. const CMapOperation * peekRedo() const;
  34. const CMapOperation * peekUndo() const;
  35. void addOperation(std::unique_ptr<CMapOperation> && operation); /// Client code does not need to call this method.
  36. //poor man's signal
  37. void setUndoCallback(std::function<void(bool, bool)> functor);
  38. private:
  39. using TStack = std::list<std::unique_ptr<CMapOperation>>;
  40. void doOperation(TStack & fromStack, TStack & toStack, bool doUndo);
  41. const CMapOperation * peek(const TStack & stack) const;
  42. TStack undoStack;
  43. TStack redoStack;
  44. int undoRedoLimit;
  45. void onUndoRedo();
  46. std::function<void(bool allowUndo, bool allowRedo)> undoCallback;
  47. };
  48. /// The map edit manager provides functionality for drawing terrain and placing
  49. /// objects on the map.
  50. class DLL_LINKAGE CMapEditManager : boost::noncopyable
  51. {
  52. public:
  53. CMapEditManager(CMap * map);
  54. ~CMapEditManager();
  55. CMap * getMap();
  56. /// Clears the terrain. The free level is filled with water and the underground level with rock.
  57. void clearTerrain(vstd::RNG * gen);
  58. /// Draws terrain at the current terrain selection. The selection will be cleared automatically.
  59. void drawTerrain(TerrainId terType, int decorationsPercentage, vstd::RNG * gen);
  60. /// Draws roads at the current terrain selection. The selection will be cleared automatically.
  61. void drawRoad(RoadId roadType, vstd::RNG * gen);
  62. /// Draws rivers at the current terrain selection. The selection will be cleared automatically.
  63. void drawRiver(RiverId riverType, vstd::RNG * gen);
  64. void insertObject(std::shared_ptr<CGObjectInstance> obj);
  65. void insertObjects(const std::set<std::shared_ptr<CGObjectInstance>> & objects);
  66. void moveObject(CGObjectInstance* obj, const int3 & pos);
  67. void removeObject(CGObjectInstance* obj);
  68. void removeObjects(std::set<CGObjectInstance*> & objects);
  69. CTerrainSelection & getTerrainSelection();
  70. CObjectSelection & getObjectSelection();
  71. CMapUndoManager & getUndoManager();
  72. private:
  73. void execute(std::unique_ptr<CMapOperation> && operation);
  74. CMap * map;
  75. CMapUndoManager undoManager;
  76. std::unique_ptr<vstd::RNG> gen;
  77. CTerrainSelection terrainSel;
  78. CObjectSelection objectSel;
  79. };
  80. VCMI_LIB_NAMESPACE_END