2013-01-06 22:30:12 +03:00
|
|
|
/*
|
|
|
|
* CMapEditManager.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "../GameConstants.h"
|
2022-09-17 13:04:01 +02:00
|
|
|
#include "CMapOperation.h"
|
2022-06-20 16:39:50 +02:00
|
|
|
#include "Terrain.h"
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-06 22:30:12 +03:00
|
|
|
class CGObjectInstance;
|
2013-04-16 16:16:58 +03:00
|
|
|
class CTerrainViewPatternConfig;
|
2013-04-21 15:49:26 +03:00
|
|
|
struct TerrainViewPattern;
|
2015-12-02 21:05:10 +02:00
|
|
|
class CMap;
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-04-19 14:43:11 +03:00
|
|
|
/// The CMapUndoManager provides the functionality to save operations and undo/redo them.
|
2013-04-22 17:49:28 +03:00
|
|
|
class DLL_LINKAGE CMapUndoManager : boost::noncopyable
|
2013-04-19 14:43:11 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMapUndoManager();
|
|
|
|
|
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
void clearAll();
|
|
|
|
|
|
|
|
/// The undo redo limit is a number which says how many undo/redo items can be saved. The default
|
|
|
|
/// value is 10. If the value is 0, no undo/redo history will be maintained.
|
2022-09-17 13:04:01 +02:00
|
|
|
|
|
|
|
/// FIXME: unlimited undo please
|
2013-04-19 14:43:11 +03:00
|
|
|
int getUndoRedoLimit() const;
|
|
|
|
void setUndoRedoLimit(int value);
|
|
|
|
|
|
|
|
const CMapOperation * peekRedo() const;
|
|
|
|
const CMapOperation * peekUndo() const;
|
|
|
|
|
2015-12-29 04:43:33 +02:00
|
|
|
void addOperation(std::unique_ptr<CMapOperation> && operation); /// Client code does not need to call this method.
|
2013-04-16 16:16:58 +03:00
|
|
|
|
2022-09-17 13:04:01 +02:00
|
|
|
//poor man's signal
|
|
|
|
void setUndoCallback(std::function<void(bool, bool)> functor);
|
|
|
|
|
2013-04-16 16:16:58 +03:00
|
|
|
private:
|
2015-12-29 04:43:33 +02:00
|
|
|
typedef std::list<std::unique_ptr<CMapOperation> > TStack;
|
2013-01-26 16:48:20 +03:00
|
|
|
|
2013-04-22 17:49:28 +03:00
|
|
|
void doOperation(TStack & fromStack, TStack & toStack, bool doUndo);
|
|
|
|
const CMapOperation * peek(const TStack & stack) const;
|
2013-01-26 16:48:20 +03:00
|
|
|
|
2013-04-19 14:43:11 +03:00
|
|
|
TStack undoStack;
|
|
|
|
TStack redoStack;
|
|
|
|
int undoRedoLimit;
|
2022-09-17 13:04:01 +02:00
|
|
|
|
|
|
|
void onUndoRedo();
|
|
|
|
std::function<void(bool allowUndo, bool allowRedo)> undoCallback;
|
2013-04-19 14:43:11 +03:00
|
|
|
};
|
2013-04-16 16:16:58 +03:00
|
|
|
|
2013-04-19 14:43:11 +03:00
|
|
|
/// The map edit manager provides functionality for drawing terrain and placing
|
|
|
|
/// objects on the map.
|
2013-04-20 14:34:01 +03:00
|
|
|
class DLL_LINKAGE CMapEditManager : boost::noncopyable
|
2013-04-19 14:43:11 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMapEditManager(CMap * map);
|
2013-04-29 18:51:39 +03:00
|
|
|
CMap * getMap();
|
2013-04-19 14:43:11 +03:00
|
|
|
|
|
|
|
/// Clears the terrain. The free level is filled with water and the underground level with rock.
|
2013-04-29 18:51:39 +03:00
|
|
|
void clearTerrain(CRandomGenerator * gen = nullptr);
|
|
|
|
|
|
|
|
/// Draws terrain at the current terrain selection. The selection will be cleared automatically.
|
2022-09-25 09:33:56 +02:00
|
|
|
void drawTerrain(TTerrainId terType, CRandomGenerator * gen = nullptr);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2015-01-03 01:29:42 +02:00
|
|
|
/// Draws roads at the current terrain selection. The selection will be cleared automatically.
|
2022-09-25 09:33:56 +02:00
|
|
|
void drawRoad(TRoadId roadType, CRandomGenerator * gen = nullptr);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
/// Draws rivers at the current terrain selection. The selection will be cleared automatically.
|
2022-09-25 09:33:56 +02:00
|
|
|
void drawRiver(TRiverId riverType, CRandomGenerator * gen = nullptr);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
void insertObject(CGObjectInstance * obj);
|
2022-09-17 13:04:01 +02:00
|
|
|
void insertObjects(std::set<CGObjectInstance *> & objects);
|
|
|
|
void moveObject(CGObjectInstance * obj, const int3 & pos);
|
|
|
|
void removeObject(CGObjectInstance * obj);
|
|
|
|
void removeObjects(std::set<CGObjectInstance *> & objects);
|
2013-04-19 14:43:11 +03:00
|
|
|
|
2013-04-29 18:51:39 +03:00
|
|
|
CTerrainSelection & getTerrainSelection();
|
|
|
|
CObjectSelection & getObjectSelection();
|
2013-04-19 14:43:11 +03:00
|
|
|
|
|
|
|
CMapUndoManager & getUndoManager();
|
|
|
|
|
|
|
|
private:
|
2015-12-29 04:43:33 +02:00
|
|
|
void execute(std::unique_ptr<CMapOperation> && operation);
|
2013-04-16 16:16:58 +03:00
|
|
|
|
|
|
|
CMap * map;
|
2013-04-19 14:43:11 +03:00
|
|
|
CMapUndoManager undoManager;
|
2013-04-29 18:51:39 +03:00
|
|
|
CRandomGenerator gen;
|
|
|
|
CTerrainSelection terrainSel;
|
|
|
|
CObjectSelection objectSel;
|
2013-04-16 16:16:58 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|