undo/redo for clear location string

This commit is contained in:
2025-06-21 11:21:28 -05:00
parent 69c7e4a293
commit db62203017
3 changed files with 63 additions and 4 deletions

View File

@@ -569,7 +569,11 @@ static bool handle_rb_action(location the_point, bool option_hit) {
update_edit_menu();
current_terrain->sign_locs.pop_back();
}
else current_terrain->sign_locs[j] = {-1, -1, "*"};
else{
undo_list.add(action_ptr(new aClearLocString(current_terrain, j, current_terrain->sign_locs[j], {-1, -1, "*"})));
update_edit_menu();
current_terrain->sign_locs[j] = {-1, -1, "*"};
}
} else {
edit_text_str(j,STRS_OUT_SIGN);
}
@@ -586,7 +590,11 @@ static bool handle_rb_action(location the_point, bool option_hit) {
update_edit_menu();
town->sign_locs.pop_back();
}
else town->sign_locs[j] = {-1, -1, "*"};
else{
undo_list.add(action_ptr(new aClearLocString(town, j, town->sign_locs[j], {-1, -1, "*"})));
update_edit_menu();
town->sign_locs[j] = {-1, -1, "*"};
}
} else {
edit_text_str(j,STRS_TOWN_SIGN);
}
@@ -603,7 +611,11 @@ static bool handle_rb_action(location the_point, bool option_hit) {
update_edit_menu();
current_terrain->area_desc.pop_back();
}
else current_terrain->area_desc[j] = {0, 0, 0, 0, "*"};
else{
undo_list.add(action_ptr(new aClearLocString(current_terrain, j, current_terrain->area_desc[j], {0, 0, 0, 0, "*"})));
update_edit_menu();
current_terrain->area_desc[j] = {0, 0, 0, 0, "*"};
}
} else {
edit_text_str(j,STRS_OUT_RECT);
}
@@ -620,7 +632,11 @@ static bool handle_rb_action(location the_point, bool option_hit) {
update_edit_menu();
town->area_desc.pop_back();
}
else town->area_desc[j] = {0, 0, 0, 0, "*"};
else{
undo_list.add(action_ptr(new aClearLocString(town, j, town->area_desc[j], {0, 0, 0, 0, "*"})));
update_edit_menu();
town->area_desc[j] = {0, 0, 0, 0, "*"};
}
} else {
edit_text_str(j,STRS_TOWN_RECT);
}

View File

@@ -1056,4 +1056,26 @@ bool aDeleteLocString::redo_me() {
start_string_editing(is_town ? STRS_TOWN_RECT : STRS_OUT_RECT);
}
return true;
}
bool aClearLocString::undo_me() {
if(is_sign){
area->sign_locs[which] = old_sign;
start_string_editing(is_town ? STRS_TOWN_SIGN : STRS_OUT_SIGN);
}else{
area->area_desc[which] = old_desc;
start_string_editing(is_town ? STRS_TOWN_RECT : STRS_OUT_RECT);
}
return true;
}
bool aClearLocString::redo_me() {
if(is_sign){
area->sign_locs[which] = new_sign;
start_string_editing(is_town ? STRS_TOWN_SIGN : STRS_OUT_SIGN);
}else{
area->area_desc[which] = new_desc;
start_string_editing(is_town ? STRS_TOWN_RECT : STRS_OUT_RECT);
}
return true;
}

View File

@@ -714,4 +714,25 @@ public:
cAction("Delete Area Description"), area(area), is_town(editing_town), is_sign(false), desc(desc) {}
};
/// Action representing clearing of a string tied to a location or rectangle in an area
class aClearLocString : public cAction {
cArea* area;
size_t which;
bool is_town;
bool is_sign; // either a sign or an area description
sign_loc_t old_sign;
info_rect_t old_desc;
sign_loc_t new_sign;
info_rect_t new_desc;
bool undo_me() override;
bool redo_me() override;
public:
aClearLocString(cArea* area, size_t which, sign_loc_t old_sign, sign_loc_t new_sign) :
cAction("Clear Sign Text"), area(area), which(which), is_town(editing_town), is_sign(true), old_sign(old_sign), new_sign(new_sign) {
}
aClearLocString(cArea* area, size_t which, info_rect_t old_desc, info_rect_t new_desc) :
cAction("Clear Area Description"), area(area), which(which), is_town(editing_town), is_sign(false), old_desc(old_desc), new_desc(new_desc) {
}
};
#endif