undo/redo for edit/clear terrain type.
This commit is contained in:
@@ -1302,8 +1302,12 @@ static bool handle_terpal_action(location cur_point, bool option_hit) {
|
||||
// option-click type that can't be deleted (because it would break other types' numbers, or is in use somewhere):
|
||||
// reset type info
|
||||
else{
|
||||
scenario.ter_types[i] = cTerrain();
|
||||
scenario.ter_types[i].name = "Unused Terrain";
|
||||
cTerrain before = scenario.ter_types[i];
|
||||
cTerrain after;
|
||||
after.name = "Unused Terrain";
|
||||
scenario.ter_types[i] = after;
|
||||
undo_list.add(action_ptr(new aEditClearTerrain("Clear Terrain Type", i, before, after)));
|
||||
update_edit_menu();
|
||||
}
|
||||
break;
|
||||
case DRAW_MONST:
|
||||
|
@@ -53,6 +53,7 @@ extern ter_num_t template_terrain[64][64];
|
||||
extern cScenario scenario;
|
||||
extern cCustomGraphics spec_scen_g;
|
||||
extern location cur_out;
|
||||
extern cUndoList undo_list;
|
||||
|
||||
const std::set<eItemAbil> items_no_strength = {
|
||||
eItemAbil::NONE, eItemAbil::HEALING_WEAPON, eItemAbil::RETURNING_MISSILE, eItemAbil::SEEKING_MISSILE, eItemAbil::DRAIN_MISSILES,
|
||||
@@ -463,8 +464,31 @@ static void fill_ter_info(cDialog& me, short ter){
|
||||
}
|
||||
|
||||
static bool finish_editing_ter(cDialog& me, std::string id, ter_num_t& which) {
|
||||
if(!save_ter_info(me, scenario.ter_types[which])) return true;
|
||||
|
||||
cTerrain after;
|
||||
if(!save_ter_info(me, after)) return true;
|
||||
cTerrain before = scenario.ter_types[which];
|
||||
|
||||
bool changed = (after != before);
|
||||
|
||||
if(changed){
|
||||
if(id == "left" || id == "right"){
|
||||
// Confirm keeping changes
|
||||
cChoiceDlog dlog("confirm-edit-terrain", {"keep","revert","cancel"}, &me);
|
||||
dlog->getControl("keep-msg").replaceText("{{ter}}", after.name);
|
||||
std::string choice = dlog.show();
|
||||
if(choice == "keep"){
|
||||
scenario.ter_types[which] = after;
|
||||
}else if(choice == "cancel"){
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
scenario.ter_types[which] = after;
|
||||
}
|
||||
// Store an undo action
|
||||
undo_list.add(action_ptr(new aEditClearTerrain("Edit Terrain Type", which, before, after)));
|
||||
update_edit_menu();
|
||||
}
|
||||
|
||||
if(!me.toast(true)) return true;
|
||||
if(id == "left") {
|
||||
me.untoast();
|
||||
|
@@ -110,6 +110,18 @@ bool aCreateDeleteTerrain::redo_me() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditClearTerrain::undo_me() {
|
||||
// TODO show the type
|
||||
scenario.ter_types[which] = before;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditClearTerrain::redo_me() {
|
||||
// TODO show the type
|
||||
scenario.ter_types[which] = after;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aCreateDeleteMonster::undo_me() {
|
||||
// TODO if not in MODE_EDIT_TYPES, show it
|
||||
for(cMonster monst : monsters){
|
||||
|
@@ -144,4 +144,16 @@ public:
|
||||
items(items) {}
|
||||
};
|
||||
|
||||
/// Action which edits or clears a terrain type
|
||||
class aEditClearTerrain : public cAction {
|
||||
ter_num_t which;
|
||||
cTerrain before;
|
||||
cTerrain after;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditClearTerrain(std::string name, ter_num_t which, cTerrain before, cTerrain after) :
|
||||
cAction(name), which(which), before(before), after(after) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user