record and replay fake fancy file picker

This commit is contained in:
2025-03-02 19:20:08 -06:00
committed by Celtic Minstrel
parent d54c61f982
commit b7a647c489
4 changed files with 46 additions and 9 deletions

View File

@@ -37,7 +37,7 @@ const std::set<fs::path> save_extensions = {".exg", ".boe", ".SAV", ".mac"};
// Return a directory's files sorted by last modified time // Return a directory's files sorted by last modified time
std::vector<std::pair<fs::path, std::time_t>> sorted_file_mtimes(fs::path dir, std::set<fs::path> valid_extensions = save_extensions); std::vector<std::pair<fs::path, std::time_t>> sorted_file_mtimes(fs::path dir, std::set<fs::path> valid_extensions = save_extensions);
bool load_party(fs::path file_to_load, cUniverse& univ); bool load_party(fs::path file_to_load, cUniverse& univ, bool record = true);
bool save_party(cUniverse& univ, bool save_as = false); bool save_party(cUniverse& univ, bool save_as = false);
bool save_party_force(cUniverse& univ, fs::path file); bool save_party_force(cUniverse& univ, fs::path file);

View File

@@ -61,7 +61,7 @@ fs::path os_file_picker(bool saving) {
return nav_get_or_decode_party(); return nav_get_or_decode_party();
} }
bool load_party(fs::path file_to_load, cUniverse& univ){ bool load_party(fs::path file_to_load, cUniverse& univ, bool record){
bool town_restore = false; bool town_restore = false;
bool maps_there = false; bool maps_there = false;
bool in_scen = false; bool in_scen = false;
@@ -167,7 +167,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
break; break;
} }
if(recording && result){ if(recording && record && result){
record_action("load_party", encode_file(file_to_load), true); record_action("load_party", encode_file(file_to_load), true);
} }

View File

@@ -1838,7 +1838,24 @@ class cFilePicker {
me["auto" + suffix + "-more-recent"].hide(); me["auto" + suffix + "-more-recent"].hide();
} }
void dummy_slot(int idx) {
std::string suffix = std::to_string(idx+1);
me["file" + suffix].setText("<Replay placeholder>");
me["pc" + suffix + "a"].hide();
me["pc" + suffix + "b"].hide();
me["pc" + suffix + "c"].hide();
me["pc" + suffix + "d"].hide();
me["pc" + suffix + "e"].hide();
me["pc" + suffix + "f"].hide();
me["info" + suffix].hide();
me["auto" + suffix + "-more-recent"].hide();
}
void populate_slot(int idx, fs::path file, std::time_t mtime, cUniverse& party_univ) { void populate_slot(int idx, fs::path file, std::time_t mtime, cUniverse& party_univ) {
if(replaying){
dummy_slot(idx);
return;
}
std::string suffix = std::to_string(idx+1); std::string suffix = std::to_string(idx+1);
me["file" + suffix].setText(file.filename().string()); me["file" + suffix].setText(file.filename().string());
@@ -1928,7 +1945,7 @@ class cFilePicker {
while(saves_loaded < parties_needed){ while(saves_loaded < parties_needed){
fs::path next_file = save_file_mtimes[saves_loaded].first; fs::path next_file = save_file_mtimes[saves_loaded].first;
cUniverse party_univ; cUniverse party_univ;
if(!load_party(next_file, save_files[saves_loaded])){ if(!load_party(next_file, save_files[saves_loaded], false)){
// TODO show error, fatal? Show corrupted party? // TODO show error, fatal? Show corrupted party?
} }
saves_loaded++; saves_loaded++;
@@ -2013,7 +2030,14 @@ class cFilePicker {
} }
bool doFileBrowser() { bool doFileBrowser() {
fs::path from_browser = nav_get_party(); fs::path from_browser = "";
if(replaying){
if(has_next_action("load_party")){
from_browser = "DUMMY";
}
}else{
from_browser = nav_get_party();
}
if(!from_browser.empty()){ if(!from_browser.empty()){
me.setResult(from_browser); me.setResult(from_browser);
me.toast(false); me.toast(false);
@@ -2059,17 +2083,24 @@ public:
} }
me["cancel"].attachClickHandler(std::bind(&cFilePicker::doCancel, this)); me["cancel"].attachClickHandler(std::bind(&cFilePicker::doCancel, this));
me["find"].attachClickHandler(std::bind(&cFilePicker::doFileBrowser, this));
// Since it would be crazy to record and replay the metadata shown on a player's save picker // Since it would be crazy to record and replay the metadata shown on a player's save picker
// dialog (which is what we do for the scenario picker), // dialog (which is what we do for the scenario picker),
// when replaying, basically make every part of the picker no-op except cancel and view autosaves. // when replaying, basically make Left/Right buttons no-op.
// Load buttons should do the same thing as cancel. // Load/Save buttons should send a dummy result.
if(!replaying){ if(!replaying){
me["next"].attachClickHandler(std::bind(&cFilePicker::doSelectPage, this, 1)); me["next"].attachClickHandler(std::bind(&cFilePicker::doSelectPage, this, 1));
me["prev"].attachClickHandler(std::bind(&cFilePicker::doSelectPage, this, -1)); me["prev"].attachClickHandler(std::bind(&cFilePicker::doSelectPage, this, -1));
init_pages(); init_pages();
me["find"].attachClickHandler(std::bind(&cFilePicker::doFileBrowser, this));
}else{ }else{
me["load"].attachClickHandler(std::bind(&cFilePicker::doCancel, this)); for(int i = 0; i < SLOTS_PER_PAGE; ++i){
std::string suffix = std::to_string(i+1);
// When replaying, a click on a load or save button means the dummy file picker can go away:
me["load" + suffix].attachClickHandler(std::bind(&cFilePicker::doLoad, this, "DUMMY"));
me["save" + suffix].attachClickHandler(std::bind(&cFilePicker::doSave, this, "DUMMY"));
// A click on an autosave button means another dummy file picker should open:
me["auto" + suffix].attachClickHandler(std::bind(&cFilePicker::showAuto, this, ""));
}
} }
// Hide the prev button and populate the first page // Hide the prev button and populate the first page
@@ -2091,6 +2122,9 @@ fs::path run_autosave_picker(fs::path auto_folder, cDialog* parent) {
} }
fs::path fancy_file_picker(bool saving) { fs::path fancy_file_picker(bool saving) {
if(recording){
record_action("fancy_file_picker", bool_to_str(saving));
}
// TODO this is set up to be configurable, but not yet exposed in preferences. // TODO this is set up to be configurable, but not yet exposed in preferences.
fs::path save_folder = get_string_pref("SaveFolder", saveDir.string()); fs::path save_folder = get_string_pref("SaveFolder", saveDir.string());

View File

@@ -596,6 +596,9 @@ static void replay_action(Element& action) {
new_fps = boost::lexical_cast<int>(action.GetText()); new_fps = boost::lexical_cast<int>(action.GetText());
} }
replay_fps_limit.emplace(new_fps); replay_fps_limit.emplace(new_fps);
}else if(t == "fancy_file_picker"){
bool saving = str_to_bool(action.GetText());
fancy_file_picker(saving);
}else if(t == "load_party"){ }else if(t == "load_party"){
decode_file(action.GetText(), tempDir / "temp.exg"); decode_file(action.GetText(), tempDir / "temp.exg");
load_party(tempDir / "temp.exg", univ); load_party(tempDir / "temp.exg", univ);