when replaying, don't open file browsers

This commit is contained in:
2024-07-05 14:58:03 -06:00
committed by Celtic Minstrel
parent 3744005f68
commit 756cf658d6
4 changed files with 33 additions and 8 deletions

View File

@@ -21,6 +21,9 @@ class cUniverse;
fs::path locate_scenario(std::string scen_name); fs::path locate_scenario(std::string scen_name);
bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header = false); bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header = false);
fs::path nav_get_or_decode_party();
fs::path nav_put_or_temp_party(fs::path def = "");
bool load_party(fs::path file_to_load, cUniverse& univ); bool load_party(fs::path file_to_load, cUniverse& univ);
bool save_party(fs::path dest_file, const cUniverse& univ); bool save_party(fs::path dest_file, const cUniverse& univ);

View File

@@ -30,6 +30,28 @@ extern cCustomGraphics spec_scen_g;
static bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there, bool must_port); static bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there, bool must_port);
static bool load_party_v2(fs::path file_to_load, cUniverse& univ); static bool load_party_v2(fs::path file_to_load, cUniverse& univ);
fs::path nav_get_party();
fs::path nav_get_or_decode_party() {
if(replaying){
Element* next_action = pop_next_action("load_party");
decode_file(next_action->GetText(), tempDir / "temp.exg");
return tempDir / "temp.exg";
}else{
return nav_get_party();
}
}
fs::path nav_put_party(fs::path def);
fs::path nav_put_or_temp_party(fs::path def) {
if(replaying){
return tempDir / "temp.exg";
}else{
return nav_put_party(def);
}
}
bool load_party(fs::path file_to_load, cUniverse& univ){ bool load_party(fs::path file_to_load, cUniverse& univ){
bool town_restore = false; bool town_restore = false;
bool maps_there = false; bool maps_there = false;

View File

@@ -1010,7 +1010,7 @@ static void handle_victory() {
univ.party.scen_name = ""; // should be harmless... univ.party.scen_name = ""; // should be harmless...
if(cChoiceDlog("congrats-save",{"cancel","save"}).show() == "save"){ if(cChoiceDlog("congrats-save",{"cancel","save"}).show() == "save"){
// TODO: Wait, this shouldn't be a "save as" action, should it? It should save without asking for a location. // TODO: Wait, this shouldn't be a "save as" action, should it? It should save without asking for a location.
fs::path file = nav_put_party(); fs::path file = nav_put_or_temp_party();
if(!file.empty()) save_party(file, univ); if(!file.empty()) save_party(file, univ);
} }
} }
@@ -2153,7 +2153,7 @@ bool handle_scroll(const sf::Event& event) {
} }
void do_load() { void do_load() {
fs::path file_to_load = nav_get_party(); fs::path file_to_load = nav_get_or_decode_party();
if(file_to_load.empty()) return; if(file_to_load.empty()) return;
if(!load_party(file_to_load, univ)) if(!load_party(file_to_load, univ))
return; return;
@@ -2203,7 +2203,7 @@ void do_save(short mode) {
if(univ.party.is_in_scenario()) save_outdoor_maps(); if(univ.party.is_in_scenario()) save_outdoor_maps();
fs::path file = univ.file; fs::path file = univ.file;
if(mode == 1 || file.empty()) if(mode == 1 || file.empty())
file = nav_put_party(file); file = nav_put_or_temp_party(file);
bool saved = false; bool saved = false;
if(!file.empty()) { if(!file.empty()) {
univ.file = file; univ.file = file;
@@ -2595,7 +2595,7 @@ void handle_death() {
return; return;
} }
else if(choice == "load") { else if(choice == "load") {
fs::path file_to_load = nav_get_party(); fs::path file_to_load = nav_get_or_decode_party();
if(!file_to_load.empty()) load_party(file_to_load, univ); if(!file_to_load.empty()) load_party(file_to_load, univ);
if(univ.party.is_alive()) { if(univ.party.is_alive()) {
if(overall_mode != MODE_STARTUP) if(overall_mode != MODE_STARTUP)
@@ -2658,7 +2658,7 @@ void start_new_game(bool force) {
} }
party_in_memory = true; party_in_memory = true;
if(force) return; if(force) return;
fs::path file = nav_put_party(); fs::path file = nav_put_or_temp_party();
if(!file.empty()) save_party(file, univ); if(!file.empty()) save_party(file, univ);
univ.file = file; univ.file = file;
} }

View File

@@ -457,7 +457,7 @@ void handle_one_event(const sf::Event& event) {
std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show(); std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show();
if(choice == "cancel") break; if(choice == "cancel") break;
if(choice == "save") { if(choice == "save") {
fs::path file = nav_put_party(); fs::path file = nav_put_or_temp_party();
if(!file.empty()) break; if(!file.empty()) break;
save_party(file, univ); save_party(file, univ);
} }
@@ -609,7 +609,7 @@ void handle_menu_choice(eMenu item_hit) {
std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show(); std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show();
if(choice == "cancel") break; if(choice == "cancel") break;
if(choice == "save") { if(choice == "save") {
fs::path file = nav_put_party(); fs::path file = nav_put_or_temp_party();
if(!file.empty()) break; if(!file.empty()) break;
save_party(file, univ); save_party(file, univ);
} }
@@ -623,7 +623,7 @@ void handle_menu_choice(eMenu item_hit) {
break; break;
if(choice == "save") { if(choice == "save") {
if(univ.file.empty()) { if(univ.file.empty()) {
univ.file = nav_put_party(); univ.file = nav_put_or_temp_party();
if(univ.file.empty()) break; if(univ.file.empty()) break;
} }
save_party(univ.file, univ); save_party(univ.file, univ);