mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-18 03:21:27 +02:00
Support for composed erase operation
This commit is contained in:
parent
6165bac516
commit
738fbd77d4
@ -297,6 +297,16 @@ void CMapEditManager::removeObject(CGObjectInstance * obj)
|
||||
execute(make_unique<CRemoveObjectOperation>(map, obj));
|
||||
}
|
||||
|
||||
void CMapEditManager::removeObjects(std::set<CGObjectInstance*> & objects)
|
||||
{
|
||||
auto composedOperation = make_unique<CComposedOperation>(map);
|
||||
for (auto obj : objects)
|
||||
{
|
||||
composedOperation->addOperation(make_unique<CRemoveObjectOperation>(map, obj));
|
||||
}
|
||||
execute(std::move(composedOperation));
|
||||
}
|
||||
|
||||
void CMapEditManager::execute(std::unique_ptr<CMapOperation> && operation)
|
||||
{
|
||||
operation->execute();
|
||||
@ -333,21 +343,31 @@ void CComposedOperation::execute()
|
||||
|
||||
void CComposedOperation::undo()
|
||||
{
|
||||
for(auto & operation : operations)
|
||||
//reverse order
|
||||
for(auto & operation = operations.rbegin(); operation != operations.rend(); operation++)
|
||||
{
|
||||
operation->undo();
|
||||
operation->get()->undo();
|
||||
}
|
||||
}
|
||||
|
||||
void CComposedOperation::redo()
|
||||
{
|
||||
//TODO: double-chekcif the order is correct
|
||||
for(auto & operation : operations)
|
||||
{
|
||||
operation->redo();
|
||||
}
|
||||
}
|
||||
|
||||
std::string CComposedOperation::getLabel() const
|
||||
{
|
||||
std::string ret = "Composed operation: ";
|
||||
for (auto& operation : operations)
|
||||
{
|
||||
ret.append(operation->getLabel() + ";");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CComposedOperation::addOperation(std::unique_ptr<CMapOperation> && operation)
|
||||
{
|
||||
operations.push_back(std::move(operation));
|
||||
|
@ -188,6 +188,7 @@ public:
|
||||
void insertObject(CGObjectInstance * obj);
|
||||
void moveObject(CGObjectInstance * obj, const int3 & pos);
|
||||
void removeObject(CGObjectInstance * obj);
|
||||
void removeObjects(std::set<CGObjectInstance*>& objects);
|
||||
|
||||
CTerrainSelection & getTerrainSelection();
|
||||
CObjectSelection & getObjectSelection();
|
||||
@ -209,7 +210,7 @@ private:
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
|
||||
/// The CComposedOperation is an operation which consists of several operations.
|
||||
class CComposedOperation : public CMapOperation
|
||||
class DLL_LINKAGE CComposedOperation : public CMapOperation
|
||||
{
|
||||
public:
|
||||
CComposedOperation(CMap * map);
|
||||
@ -217,6 +218,7 @@ public:
|
||||
void execute() override;
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
std::string getLabel() const override;
|
||||
|
||||
void addOperation(std::unique_ptr<CMapOperation> && operation);
|
||||
|
||||
|
@ -133,11 +133,21 @@ void MapController::commitTerrainChange(int level, const Terrain & terrain)
|
||||
|
||||
void MapController::commitObjectErase(int level)
|
||||
{
|
||||
for(auto * obj : _scenes[level]->selectionObjectsView.getSelection())
|
||||
auto selectedObjects = _scenes[level]->selectionObjectsView.getSelection();
|
||||
if (selectedObjects.size() > 1)
|
||||
{
|
||||
_map->getEditManager()->removeObject(obj);
|
||||
//object ownership goes to EditManager, which can handle undo operation
|
||||
//mass erase => undo in one operation
|
||||
_map->getEditManager()->removeObjects(selectedObjects);
|
||||
}
|
||||
else if (selectedObjects.size() == 1)
|
||||
{
|
||||
_map->getEditManager()->removeObject(*selectedObjects.begin());
|
||||
}
|
||||
else //nothing to erase - shouldn't be here
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_scenes[level]->selectionObjectsView.clear();
|
||||
resetMapHandler();
|
||||
_scenes[level]->updateViews();
|
||||
|
Loading…
Reference in New Issue
Block a user