undo/redo for advanced details
This commit is contained in:
@@ -219,7 +219,7 @@ inline scen_details_t details_from_scen(cScenario& scen) {
|
||||
};
|
||||
}
|
||||
|
||||
inline void scen_set_details(cScenario& scen, scen_details_t details) {
|
||||
inline void scen_set_details(cScenario& scen, const scen_details_t& details) {
|
||||
scen.difficulty = details.difficulty;
|
||||
scen.rating = details.rating;
|
||||
scen.scen_name = details.scen_name;
|
||||
@@ -252,9 +252,56 @@ inline scen_intro_t intro_from_scen(cScenario& scen) {
|
||||
return { scen.intro_pic, scen.intro_strs };
|
||||
}
|
||||
|
||||
inline void scen_set_intro(cScenario& scen, scen_intro_t details) {
|
||||
inline void scen_set_intro(cScenario& scen, const scen_intro_t& details) {
|
||||
scen.intro_pic = details.intro_pic;
|
||||
scen.intro_strs = details.intro_strs;
|
||||
}
|
||||
|
||||
// Store a version the scenario advanced details for undo history.
|
||||
// This could be made a struct that cScenario contains, and that would eliminate the next 2 functions, but it would
|
||||
// require changing every reference to these detail values in the game and fileio code, making them more verbose. I don't know
|
||||
// if that's worth it.
|
||||
struct scen_advanced_t {
|
||||
bool adjust_diff;
|
||||
std::string campaign_id;
|
||||
int bg_out;
|
||||
int bg_town;
|
||||
int bg_dungeon;
|
||||
int bg_fight;
|
||||
spec_num_t init_spec;
|
||||
bool operator==(const scen_advanced_t& other) const {
|
||||
CHECK_EQ(other, adjust_diff);
|
||||
CHECK_EQ(other, campaign_id);
|
||||
CHECK_EQ(other, bg_out);
|
||||
CHECK_EQ(other, bg_town);
|
||||
CHECK_EQ(other, bg_dungeon);
|
||||
CHECK_EQ(other, bg_fight);
|
||||
CHECK_EQ(other, init_spec);
|
||||
return true;
|
||||
}
|
||||
bool operator!=(const scen_advanced_t& other) const { return !(*this == other); }
|
||||
};
|
||||
|
||||
inline scen_advanced_t advanced_from_scen(cScenario& scen) {
|
||||
return {
|
||||
scen.adjust_diff,
|
||||
scen.campaign_id,
|
||||
scen.bg_out,
|
||||
scen.bg_town,
|
||||
scen.bg_dungeon,
|
||||
scen.bg_fight,
|
||||
scen.init_spec
|
||||
};
|
||||
}
|
||||
|
||||
inline void scen_set_advanced(cScenario& scen, const scen_advanced_t& details) {
|
||||
scen.adjust_diff = details.adjust_diff;
|
||||
scen.campaign_id = details.campaign_id;
|
||||
scen.bg_out = details.bg_out;
|
||||
scen.bg_town = details.bg_town;
|
||||
scen.bg_dungeon = details.bg_dungeon;
|
||||
scen.bg_fight = details.bg_fight;
|
||||
scen.init_spec = details.init_spec;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -3184,14 +3184,23 @@ void edit_scen_adv_details() {
|
||||
info_dlg.run();
|
||||
|
||||
if(info_dlg.accepted()){
|
||||
scenario.adjust_diff = dynamic_cast<cLed&>(info_dlg["adjust"]).getState() != led_red;
|
||||
scen_advanced_t old_advanced = advanced_from_scen(scenario);
|
||||
scen_advanced_t new_advanced;
|
||||
|
||||
scenario.campaign_id = info_dlg["cpnid"].getText();
|
||||
scenario.bg_out = boost::lexical_cast<int>(info_dlg["bg-out"].getText().substr(10));
|
||||
scenario.bg_town = boost::lexical_cast<int>(info_dlg["bg-town"].getText().substr(10));
|
||||
scenario.bg_dungeon = boost::lexical_cast<int>(info_dlg["bg-dungeon"].getText().substr(13));
|
||||
scenario.bg_fight = boost::lexical_cast<int>(info_dlg["bg-fight"].getText().substr(11));
|
||||
scenario.init_spec = info_dlg["oninit"].getTextAsNum();
|
||||
new_advanced.adjust_diff = dynamic_cast<cLed&>(info_dlg["adjust"]).getState() == led_red;
|
||||
|
||||
new_advanced.campaign_id = info_dlg["cpnid"].getText();
|
||||
new_advanced.bg_out = boost::lexical_cast<int>(info_dlg["bg-out"].getText().substr(10));
|
||||
new_advanced.bg_town = boost::lexical_cast<int>(info_dlg["bg-town"].getText().substr(10));
|
||||
new_advanced.bg_dungeon = boost::lexical_cast<int>(info_dlg["bg-dungeon"].getText().substr(13));
|
||||
new_advanced.bg_fight = boost::lexical_cast<int>(info_dlg["bg-fight"].getText().substr(11));
|
||||
new_advanced.init_spec = info_dlg["oninit"].getTextAsNum();
|
||||
|
||||
if(old_advanced != new_advanced){
|
||||
scen_set_advanced(scenario, new_advanced);
|
||||
undo_list.add(action_ptr(new aEditAdvancedDetails(old_advanced, new_advanced)));
|
||||
update_edit_menu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -888,4 +888,14 @@ bool aClassifyGraphics::undo_me() {
|
||||
bool aClassifyGraphics::redo_me() {
|
||||
scenario.custom_graphics = new_types;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditAdvancedDetails::undo_me() {
|
||||
scen_set_advanced(scenario, old_advanced);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool aEditAdvancedDetails::redo_me() {
|
||||
scen_set_advanced(scenario, new_advanced);
|
||||
return true;
|
||||
}
|
@@ -542,4 +542,14 @@ public:
|
||||
cAction("Classify Custom Graphics"), old_types(old_types), new_types(new_types) {}
|
||||
};
|
||||
|
||||
class aEditAdvancedDetails : public cAction {
|
||||
scen_advanced_t old_advanced;
|
||||
scen_advanced_t new_advanced;
|
||||
bool undo_me() override;
|
||||
bool redo_me() override;
|
||||
public:
|
||||
aEditAdvancedDetails(scen_advanced_t old_advanced, scen_advanced_t new_advanced) :
|
||||
cAction("Edit Advanced Details"), old_advanced(old_advanced), new_advanced(new_advanced) {}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user