mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Draft state for terrain update
This commit is contained in:
parent
5bda5c3b44
commit
aa1cf5e16c
@ -864,7 +864,10 @@ void MainWindow::on_actionUpdate_appearance_triggered()
|
|||||||
if(QMessageBox::Yes != QMessageBox::question(this, "Update appearance", "This operation is irreversible. Do you want to continue?"))
|
if(QMessageBox::Yes != QMessageBox::question(this, "Update appearance", "This operation is irreversible. Do you want to continue?"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
controller.scene(mapLevel)->selectionTerrainView.clear();
|
||||||
|
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
std::set<CGObjectInstance*> staticObjects;
|
||||||
for(auto * obj : controller.scene(mapLevel)->selectionObjectsView.getSelection())
|
for(auto * obj : controller.scene(mapLevel)->selectionObjectsView.getSelection())
|
||||||
{
|
{
|
||||||
auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
|
auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
|
||||||
@ -875,26 +878,46 @@ void MainWindow::on_actionUpdate_appearance_triggered()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto terrain = controller.map()->getTile(obj->visitablePos()).terType;
|
auto terrain = controller.map()->getTile(obj->visitablePos()).terType;
|
||||||
auto app = handler->getOverride(terrain, obj);
|
|
||||||
if(!app)
|
if(handler->isStaticObject())
|
||||||
{
|
{
|
||||||
|
staticObjects.insert(obj);
|
||||||
if(obj->appearance.canBePlacedAt(terrain))
|
if(obj->appearance.canBePlacedAt(terrain))
|
||||||
continue;
|
|
||||||
|
|
||||||
auto templates = handler->getTemplates(terrain);
|
|
||||||
if(templates.empty())
|
|
||||||
{
|
{
|
||||||
++errors;
|
controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
app = templates.front();
|
|
||||||
|
for(auto & offset : obj->appearance.getBlockedOffsets())
|
||||||
|
controller.scene(mapLevel)->selectionTerrainView.select(obj->pos + offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto app = handler->getOverride(terrain, obj);
|
||||||
|
if(!app)
|
||||||
|
{
|
||||||
|
if(obj->appearance.canBePlacedAt(terrain))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto templates = handler->getTemplates(terrain);
|
||||||
|
if(templates.empty())
|
||||||
|
{
|
||||||
|
++errors;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
app = templates.front();
|
||||||
|
}
|
||||||
|
auto tiles = controller.mapHandler()->getTilesUnderObject(obj);
|
||||||
|
obj->appearance = app.get();
|
||||||
|
controller.mapHandler()->invalidate(tiles);
|
||||||
|
controller.mapHandler()->invalidate(obj);
|
||||||
|
controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj);
|
||||||
}
|
}
|
||||||
auto tiles = controller.mapHandler()->getTilesUnderObject(obj);
|
|
||||||
obj->appearance = app.get();
|
|
||||||
controller.mapHandler()->invalidate(tiles);
|
|
||||||
controller.mapHandler()->invalidate(obj);
|
|
||||||
}
|
}
|
||||||
controller.commitObjectChange(mapLevel);
|
controller.commitObjectChange(mapLevel);
|
||||||
|
controller.commitObjectErase(mapLevel);
|
||||||
|
controller.commitObstacleFill(mapLevel);
|
||||||
|
|
||||||
|
|
||||||
if(errors)
|
if(errors)
|
||||||
QMessageBox::warning(this, "Update appearance", QString("Errors occured. %1 objects were not updated").arg(errors));
|
QMessageBox::warning(this, "Update appearance", QString("Errors occured. %1 objects were not updated").arg(errors));
|
||||||
|
@ -81,16 +81,9 @@
|
|||||||
<addaction name="actionRedo"/>
|
<addaction name="actionRedo"/>
|
||||||
<addaction name="actionErase"/>
|
<addaction name="actionErase"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuPlayer">
|
|
||||||
<property name="title">
|
|
||||||
<string>Player</string>
|
|
||||||
</property>
|
|
||||||
<addaction name="actionNeutral"/>
|
|
||||||
</widget>
|
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuEdit"/>
|
<addaction name="menuEdit"/>
|
||||||
<addaction name="menuMap"/>
|
<addaction name="menuMap"/>
|
||||||
<addaction name="menuPlayer"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="toolBar">
|
<widget class="QToolBar" name="toolBar">
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -902,11 +895,17 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionUpdate_appearance">
|
<action name="actionUpdate_appearance">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Update appearance</string>
|
<string>Update appearance</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRecreate_obstacles">
|
<action name="actionRecreate_obstacles">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Recreate obstacles</string>
|
<string>Recreate obstacles</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -470,6 +470,11 @@ void SelectionObjectsLayer::selectObject(CGObjectInstance * obj, bool inform /*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SelectionObjectsLayer::deselectObject(CGObjectInstance * obj)
|
||||||
|
{
|
||||||
|
selectedObjects.erase(obj);
|
||||||
|
}
|
||||||
|
|
||||||
bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const
|
bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const
|
||||||
{
|
{
|
||||||
return selectedObjects.count(const_cast<CGObjectInstance*>(obj));
|
return selectedObjects.count(const_cast<CGObjectInstance*>(obj));
|
||||||
|
@ -127,6 +127,7 @@ public:
|
|||||||
CGObjectInstance * selectObjectAt(int x, int y) const;
|
CGObjectInstance * selectObjectAt(int x, int y) const;
|
||||||
void selectObjects(int x1, int y1, int x2, int y2);
|
void selectObjects(int x1, int y1, int x2, int y2);
|
||||||
void selectObject(CGObjectInstance *, bool inform = true);
|
void selectObject(CGObjectInstance *, bool inform = true);
|
||||||
|
void deselectObject(CGObjectInstance *);
|
||||||
bool isSelected(const CGObjectInstance *) const;
|
bool isSelected(const CGObjectInstance *) const;
|
||||||
std::set<CGObjectInstance*> getSelection() const;
|
std::set<CGObjectInstance*> getSelection() const;
|
||||||
void moveSelection(int x, int y);
|
void moveSelection(int x, int y);
|
||||||
|
Loading…
Reference in New Issue
Block a user