diff --git a/src/scenario/scenario.cpp b/src/scenario/scenario.cpp index 8111a961..0337292a 100644 --- a/src/scenario/scenario.cpp +++ b/src/scenario/scenario.cpp @@ -649,4 +649,15 @@ std::string cScenario::get_sdf_name(int row, int col) { if(sdf_names[row].find(col) == sdf_names[row].end()) return ""; return sdf_names[row][col]; -} \ No newline at end of file +} + +bool cScenario::cItemStorage::operator==(const cScenario::cItemStorage& other) const { + CHECK_EQ(other, ter_type); + CHECK_EQ(other, property); + for(int i = 0; i < 10; ++i){ + if(item_num[i] != other.item_num[i]) return false; + if(item_odds[i] != other.item_odds[i]) return false; + } + + return true; +} diff --git a/src/scenario/scenario.hpp b/src/scenario/scenario.hpp index 3990b72c..f444c361 100644 --- a/src/scenario/scenario.hpp +++ b/src/scenario/scenario.hpp @@ -87,6 +87,8 @@ public: short property; cItemStorage(); cItemStorage& operator = (legacy::item_storage_shortcut_type& old); + bool operator==(const cItemStorage& other) const; + bool operator!=(const cItemStorage& other) { return !(*this == other); } }; void destroy_terrain(); public: diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 501a9972..b5645440 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -2997,7 +2997,12 @@ static bool save_item_placement(cDialog& me, cScenario::cItemStorage& storage, s if(cre(storage.item_odds[i], 0,100,"All item chances must bve from 0 to 100.","",&me)) return false; } - scenario.storage_shortcuts[which] = storage; + + if(storage != scenario.storage_shortcuts[which]){ + // the edit menu will update when the dialog closes + undo_list.add(action_ptr(new aEditItemShortcut(which, scenario.storage_shortcuts[which], storage))); + scenario.storage_shortcuts[which] = storage; + } return true; } @@ -3086,6 +3091,7 @@ void edit_item_placement() { put_item_placement_in_dlog(shortcut_dlg, storage, cur_shortcut); shortcut_dlg.run(); + update_edit_menu(); } static bool save_scen_details(cDialog& me, std::string, eKeyMod) { diff --git a/src/scenedit/scen.undo.cpp b/src/scenedit/scen.undo.cpp index 858202a5..c4a52b53 100644 --- a/src/scenedit/scen.undo.cpp +++ b/src/scenedit/scen.undo.cpp @@ -920,12 +920,12 @@ bool aEditScenTimers::redo_me() { return true; } -bool aEditItemShortcuts::undo_me() { - scenario.storage_shortcuts = old_shortcuts; +bool aEditItemShortcut::undo_me() { + scenario.storage_shortcuts[which] = old_shortcut; return true; } -bool aEditItemShortcuts::redo_me() { - scenario.storage_shortcuts = new_shortcuts; +bool aEditItemShortcut::redo_me() { + scenario.storage_shortcuts[which] = new_shortcut; return true; } \ No newline at end of file diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index b1384982..99b9051c 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -572,14 +572,15 @@ public: cAction("Edit Scenario Event Timers"), old_timers(old_timers), new_timers(new_timers) {} }; -class aEditItemShortcuts : public cAction { - std::array old_shortcuts; - std::array new_shortcuts; +class aEditItemShortcut : public cAction { + size_t which; + cScenario::cItemStorage old_shortcut; + cScenario::cItemStorage new_shortcut; bool undo_me() override; bool redo_me() override; public: - aEditItemShortcuts(std::array old_shortcuts, std::array new_shortcuts) : - cAction("Edit Item Placement Shortcuts"), old_shortcuts(old_shortcuts), new_shortcuts(new_shortcuts) {} + aEditItemShortcut(size_t which, cScenario::cItemStorage old_shortcut, cScenario::cItemStorage new_shortcut) : + cAction("Edit Item Placement Shortcut"), which(which), old_shortcut(old_shortcut), new_shortcut(new_shortcut) {} }; #endif \ No newline at end of file