diff --git a/src/scenario/talking.hpp b/src/scenario/talking.hpp index da9d1ab3..04bd98ea 100644 --- a/src/scenario/talking.hpp +++ b/src/scenario/talking.hpp @@ -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 people; std::vector talk_nodes; diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index a9c55c81..ebfb51e0 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -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(); diff --git a/src/scenedit/scen.undo.cpp b/src/scenedit/scen.undo.cpp index 76a1e100..85855039 100644 --- a/src/scenedit/scen.undo.cpp +++ b/src/scenedit/scen.undo.cpp @@ -1024,4 +1024,14 @@ bool aCreateDeleteTalkNode::redo_me() { // Show the change 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; } \ No newline at end of file diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index e3d3d173..b5889712 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -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 \ No newline at end of file