undo/redo for edit talk node

This commit is contained in:
2025-06-20 10:17:37 -05:00
parent 9e22ed04ea
commit 6044232713
4 changed files with 40 additions and 3 deletions

View File

@@ -88,6 +88,19 @@ public:
std::fill(link1, link1 + 4, ' ');
std::fill(link2, link2 + 4, ' ');
}
bool operator==(const cNode& other) const {
CHECK_EQ(other, personality);
CHECK_EQ(other, type);
for(int i = 0; i < 4; i++){
if(link1[i] != other.link1[i]) return false;
if(link2[i] != other.link2[i]) return false;
if(extras[i] != other.extras[i]) return false;
}
CHECK_EQ(other, str1);
CHECK_EQ(other, str2);
return true;
}
bool operator!=(const cNode& other) const { return !(*this == other); }
};
std::array<cPersonality, 10> people;
std::vector<cNode> talk_nodes;

View File

@@ -543,7 +543,8 @@ static bool handle_rb_action(location the_point, bool option_hit) {
is_new = true;
town->talking.talk_nodes.emplace_back();
}
if((j = edit_talk_node(j)) >= 0){
cSpeech::cNode old_node = town->talking.talk_nodes[j];
if(edit_talk_node(j) >= 0){
// Cancel create new
if(is_new)
town->talking.talk_nodes.erase(town->talking.talk_nodes.begin() + j);
@@ -554,8 +555,9 @@ static bool handle_rb_action(location the_point, bool option_hit) {
update_edit_menu();
}
// Edit confirmed
else{
else if(old_node != town->talking.talk_nodes[j]){
undo_list.add(action_ptr(new aEditTalkNode(cur_town, j, old_node, town->talking.talk_nodes[j])));
update_edit_menu();
}
}
start_dialogue_editing();

View File

@@ -1025,3 +1025,13 @@ bool aCreateDeleteTalkNode::redo_me() {
start_dialogue_editing();
return true;
}
bool aEditTalkNode::undo_me() {
scenario.towns[town_num]->talking.talk_nodes[which] = old_node;
return true;
}
bool aEditTalkNode::redo_me() {
scenario.towns[town_num]->talking.talk_nodes[which] = new_node;
return true;
}

View File

@@ -685,4 +685,16 @@ public:
cAction(create ? "Create Talk Node" : "Delete Talk Node", !create), town_num(town_num), which(which), node(node) {}
};
class aEditTalkNode : public cAction {
size_t town_num;
size_t which;
cSpeech::cNode old_node;
cSpeech::cNode new_node;
bool undo_me() override;
bool redo_me() override;
public:
aEditTalkNode(size_t town_num, size_t which, cSpeech::cNode old_node, cSpeech::cNode new_node) :
cAction("Edit Talk Node"), town_num(town_num), which(which), old_node(old_node), new_node(new_node) {}
};
#endif