undo/redo editing sign text

This commit is contained in:
2025-06-06 13:20:09 -05:00
parent 1e9b727798
commit 38d4701226
3 changed files with 41 additions and 10 deletions

View File

@@ -425,16 +425,18 @@ void edit_placed_item(short which_i) {
static bool edit_sign_event_filter(cDialog& me, sign_loc_t& which_sign) {
if(!me.toast(true)) return true;
which_sign.text = me["text"].getText();
#if 0 // TODO: Apparently there used to be left/right buttons on this dialog.
if(item_hit == 3)
which_sign--;
else which_sign++;
if(which_sign < 0)
which_sign = (editing_town) ? 14 : 7;
if(which_sign > (editing_town) ? 14 : 7)
which_sign = 0;
#endif
std::string cur_text = me["text"].getText();
if(which_sign.text != cur_text){
undo_list.add(action_ptr(new aEditSignText(which_sign, which_sign.text, cur_text)));
update_edit_menu();
which_sign.text = cur_text;
}
// There used to be left/right buttons in the sign editor dialog, but there shouldn't be,
// because left/right is not a meaningful index to let the designer know which sign they're editing.
// I removed the unused code.
return true;
}

View File

@@ -244,3 +244,19 @@ bool aPlaceEraseCreature::redo_me() {
}
return true;
}
bool aEditSignText::undo_me() {
cArea* cur_area = get_current_area();
auto& signs = cur_area->sign_locs;
auto iter = std::find(signs.begin(), signs.end(), area.where);
iter->text = old_text;
return true;
}
bool aEditSignText::redo_me() {
cArea* cur_area = get_current_area();
auto& signs = cur_area->sign_locs;
auto iter = std::find(signs.begin(), signs.end(), area.where);
iter->text = new_text;
return true;
}

View File

@@ -35,6 +35,7 @@ class cTerrainAction : public cAction {
public:
cTerrainAction(std::string name, short town_num, location where, bool reversed = false);
cTerrainAction(std::string name, location out_sec, location where, bool reversed = false);
// Construct cTerrainAction in the current town/outdoor section
cTerrainAction(std::string name, location where, bool reversed = false);
void undo();
void redo();
@@ -43,6 +44,7 @@ public:
private:
/// Show where the change happened
void showChangeSite();
protected:
area_ref_t area;
};
@@ -92,6 +94,17 @@ public:
aPlaceEraseCreature(std::string name, bool place, size_t index, cTownperson creature);
};
/// Action which edits sign text
class aEditSignText : public cTerrainAction {
std::string old_text;
std::string new_text;
bool undo_me() override;
bool redo_me() override;
public:
aEditSignText(location loc, std::string old_text, std::string new_text) :
cTerrainAction("Edit Sign Text", loc), old_text(old_text), new_text(new_text) {}
};
/// Action which adds a new town to the end of the list, or deletes the last one
class aCreateDeleteTown : public cAction {
bool created;