diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 5705345..dc8838b 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -160,3 +160,10 @@ Release-driven incoming-transfer presenters require a matching press observed inside that modal. An orphan or repeated release from the preceding result table cannot decline an offer or dismiss its confirmation. Repeated presses while a button is held still form one gesture; fresh left/right clicks keep their actions. + +## Host file overwrite confirmation + +The file picker reuses the Original overwrite question and Ja/Nein button +layout. A separate Yes click or Enter confirms; repeated double-clicks do not. +OpenBMH deviates from the original: host file operations use the shared dialog's +system identity because the picker does not own a live manager portrait projection. diff --git a/docs/DIFFERENCES.md b/docs/DIFFERENCES.md index fe0083e..a7fbf9f 100644 --- a/docs/DIFFERENCES.md +++ b/docs/DIFFERENCES.md @@ -37,4 +37,5 @@ describe deliberate changes; they are not a list of every known compatibility li - [src/ui/pitch.cpp](../src/ui/pitch.cpp): supports owner-bound designated set-piece selection in the extended manager record. - [src/ui/save_load.cpp](../src/ui/save_load.cpp): focuses the host save filename on entry and selects an existing name for replacement. - [src/ui/save_load.cpp](../src/ui/save_load.cpp): omits DOS drive and delete buttons in the directory-confined save/load view. +- [src/ui/save_load.cpp](../src/ui/save_load.cpp): the host file picker uses the shared dialog's system identity without a live manager portrait projection. - [src/ui/save_load.cpp](../src/ui/save_load.cpp): permits cancelling host file dialogs with the right mouse button. diff --git a/docs/formats/EXECUTABLE_LAYOUT.md b/docs/formats/EXECUTABLE_LAYOUT.md index efe1ab5..60d68ab 100644 --- a/docs/formats/EXECUTABLE_LAYOUT.md +++ b/docs/formats/EXECUTABLE_LAYOUT.md @@ -1578,6 +1578,7 @@ declarations change. Game text, resort, image and audio fallbacks belong outside | `SaveLoad_Render_RuntimeField` | `0xa2334` | German-compatible image / runtime field | | `SaveLoad_Render_RuntimeField2` | `0xa233f` | German-compatible image / runtime field | | `SaveLoad_Render_RuntimeField3` | `0xa234a` | German-compatible image / runtime field | +| `SaveLoad_OverwriteQuestionPointer` | `0xa21c4` | German-compatible image / runtime field | | `SaveLoad_Render_TextPointer` | `0xa1512` | German-compatible image / runtime field | | `SaveLoad_Render_TextPointer2` | `0xae5f0` | German-compatible image / runtime field | | `SaveLoad_Render_TextPointer3` | `0xae620` | German-compatible image / runtime field | diff --git a/src/formats/executable_layout.hpp b/src/formats/executable_layout.hpp index 5218abe..6edc78b 100644 --- a/src/formats/executable_layout.hpp +++ b/src/formats/executable_layout.hpp @@ -1559,6 +1559,7 @@ inline constexpr auto SaveLoad_Render_ExecutableField = 0xa148f; inline constexpr auto SaveLoad_Render_RuntimeField = 0xa2334; inline constexpr auto SaveLoad_Render_RuntimeField2 = 0xa233f; inline constexpr auto SaveLoad_Render_RuntimeField3 = 0xa234a; +inline constexpr auto SaveLoad_OverwriteQuestionPointer = 0xa21c4; inline constexpr auto SaveLoad_Render_TextPointer = 0xa1512; inline constexpr auto SaveLoad_Render_TextPointer2 = 0xae5f0; inline constexpr auto SaveLoad_Render_TextPointer3 = 0xae620; diff --git a/src/ui/save_load.cpp b/src/ui/save_load.cpp index 2b25aca..7723ff9 100644 --- a/src/ui/save_load.cpp +++ b/src/ui/save_load.cpp @@ -9,6 +9,7 @@ #include #include "ui/manager.hpp" +#include "ui/game_end.hpp" #include "ui/host_path.hpp" #include "ui/setup.hpp" #include "formats/fbm.hpp" @@ -177,11 +178,24 @@ Image SaveLoadScreen::render() const { text(out, 212, y, row.league, 0x6b, -1, footer_font_, true); } } + if (overwrite_confirmation_open_) { + TaxDialogProjection question; + question.kind = TaxDialogKind::question; + question.source_flags = 0x101; // Original overwrite prompt's Ja/Nein selectors. + question.source_system_identity = true; + question.badge_fallback = true; + question.portrait = 14; + question.body = exe_.string_at_pointer(::bmh::layout::SaveLoad_OverwriteQuestionPointer); + // OpenBMH deviates from the original: the host file picker uses the + // shared dialog's system identity without a live manager portrait projection. + draw_source_dialog(out, {widgets_, widgets_, nullptr, footer_font_, font_, exe_, sprite_font_, texts_}, + question, gradient_text_); + } return out; } bool SaveLoadScreen::info_press(int x, int y) { - if (file_kind_ != SaveLoadFileKind::game || pending_ || info_ || x <= 52 || x >= 200 || y <= 40 || + if (file_kind_ != SaveLoadFileKind::game || pending_ || info_ || overwrite_confirmation_open_ || x <= 52 || x >= 200 || y <= 40 || y >= 192 || !select_row(y)) return false; try { const auto saved = load_savegame(entries_.at(size_t(selected_)).path); @@ -316,7 +330,13 @@ void SaveLoadScreen::request_action() { std::error_code ec; const bool exists = std::filesystem::exists(path, ec); if (ec) { feedback_ = "DATEI NICHT PRUEFBAR"; return; } - if (exists && !overwrite_armed_) { overwrite_armed_ = true; feedback_ = "EXISTIERT: ENTER ZUM ERSETZEN"; return; } + if (exists && !overwrite_armed_) { + overwrite_armed_ = true; + overwrite_confirmation_open_ = true; + feedback_.clear(); + return; + } + overwrite_confirmation_open_ = false; pending_ = SaveLoadRequest{SaveLoadAction::save, manager_slot_, revision_, path, exists, file_kind_, origin_item_id_}; } @@ -324,6 +344,26 @@ void SaveLoadScreen::request_action() { bool SaveLoadScreen::click(int x, int y, bool right, bool double_click) { if (info_) { info_.reset(); return true; } if (pending_) return false; + if (overwrite_confirmation_open_) { + if (right) { + overwrite_confirmation_open_ = overwrite_armed_ = false; + close_requested_ = true; + return true; + } + // Only a separate click on the question's buttons can decide. Further + // releases from a double/triple click in the file list cannot accept it. + if (double_click || y < 166 || y > 176) return false; + if (x >= 62 && x <= 137) { + overwrite_confirmation_open_ = false; + request_action(); + return true; + } + if (x >= 175 && x <= 250) { + overwrite_confirmation_open_ = overwrite_armed_ = false; + return true; + } + return false; + } // OpenBMH deviates from the original: permits cancelling host file dialogs with the right mouse button. if (right) { close_requested_ = true; return true; } if (x >= 206 && y >= 60 && y <= 169) @@ -338,7 +378,7 @@ bool SaveLoadScreen::click(int x, int y, bool right, bool double_click) { if (x >= 53 && x <= 199 && select_row(y)) { const int row = scroll_ + (y - 40) / 10; // Row selection clears overwrite confirmation before activation. Even a - // repeated double-click must ask again; only Enter confirms replacement. + // repeated double-click cannot confirm replacement. if (double_click || (mode_ == SaveLoadMode::load && row == last_clicked_row_)) { request_action(); return true; } @@ -355,7 +395,15 @@ bool SaveLoadScreen::click(int x, int y, bool right, bool double_click) { bool SaveLoadScreen::key(std::string_view value) { if (info_) return false; // Centered waits for mouse release, not keyboard. if (pending_) return false; - if (value == "ESC") { close_requested_ = true; return true; } + if (value == "ESC") { + overwrite_confirmation_open_ = overwrite_armed_ = false; + close_requested_ = true; + return true; + } + if (overwrite_confirmation_open_) { + if (value == "ENTER") { request_action(); return true; } + return false; + } if (mode_ == SaveLoadMode::load && !entries_.empty()) { if (value == "UP") { if (selected_ > 0) --selected_; if (selected_ < scroll_) scroll_ = selected_; return true; } if (value == "DOWN") { if (selected_ + 1 < int(entries_.size())) ++selected_; if (selected_ >= scroll_ + 15) scroll_ = selected_ - 14; return true; } @@ -384,7 +432,7 @@ bool SaveLoadScreen::key(std::string_view value) { } bool SaveLoadScreen::text(std::string_view value) { - if (info_ || mode_ != SaveLoadMode::save || !filename_focus_ || pending_ || value.empty()) return false; + if (info_ || overwrite_confirmation_open_ || mode_ != SaveLoadMode::save || !filename_focus_ || pending_ || value.empty()) return false; const std::string next = (filename_selected_ ? std::string{} : filename_) + std::string(value); if (!valid_filename(next)) return false; filename_ = next; filename_selected_ = false; @@ -422,6 +470,7 @@ std::string SaveLoadScreen::state_json() const { << ",\"filename\":" << json_quote(filename_) << ",\"entries\":["; for (size_t i = 0; i < entries_.size(); ++i) { if (i) out << ','; out << json_quote(path_to_utf8(entries_[i].path.filename())); } out << "],\"info_open\":" << (info_ ? "true" : "false") + << ",\"overwrite_confirmation_open\":" << (overwrite_confirmation_open_ ? "true" : "false") << ",\"pending_action\":" << (pending_ ? save_load_request_json(*pending_) : "null") << ",\"feedback\":" << (feedback_.empty() ? "null" : json_quote(feedback_)); if (file_kind_ == SaveLoadFileKind::menu_layout || file_kind_ == SaveLoadFileKind::settings) diff --git a/src/ui/save_load.hpp b/src/ui/save_load.hpp index 156fd7c..5ccb851 100644 --- a/src/ui/save_load.hpp +++ b/src/ui/save_load.hpp @@ -72,7 +72,7 @@ private: int selected_ = 0, scroll_ = 0; std::string filename_, feedback_; bool filename_focus_ = false, filename_selected_ = false; - bool overwrite_armed_ = false, close_requested_ = false; + bool overwrite_armed_ = false, overwrite_confirmation_open_ = false, close_requested_ = false; int last_clicked_row_ = -1; std::optional pending_; struct InfoRow { std::string manager, club, league; }; diff --git a/src/ui/save_load_tests.cpp b/src/ui/save_load_tests.cpp index e5636c9..76a1f25 100644 --- a/src/ui/save_load_tests.cpp +++ b/src/ui/save_load_tests.cpp @@ -42,12 +42,12 @@ int main(int argc, char** argv) { }; SaveLoadScreen overwrite(argv[1], root, SaveLoadMode::save, 2, 17, backdrop, true, kind, 9); check(overwrite.click(70, 45) && overwrite.click(70, 45) && !overwrite.pending() && - overwrite.state_json().find("EXISTIERT") == std::string::npos, + overwrite.state_json().find("\"overwrite_confirmation_open\":false") != std::string::npos, "separate single clicks only select an existing save"); check(overwrite.click(70, 45, false, true) && !overwrite.pending() && - overwrite.state_json().find("ENTER ZUM ERSETZEN") != std::string::npos, + overwrite.state_json().find("\"overwrite_confirmation_open\":true") != std::string::npos, "a true double-click asks for overwrite confirmation without submitting a write"); - check(overwrite.click(70, 45, false, true) && !overwrite.pending(), + check(!overwrite.click(70, 45, false, true) && !overwrite.pending(), "repeated double-clicks cannot confirm an overwrite"); unchanged(); check(overwrite.key("ENTER") && overwrite.pending() && overwrite.pending()->overwrite && @@ -63,6 +63,25 @@ int main(int argc, char** argv) { check(overwrite.close_requested() && !overwrite.pending(), "acknowledgement closes the picker and clears its one request"); unchanged(); + SaveLoadScreen mouse(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind); + const auto list = mouse.render(); + mouse.click(70, 45, false, true); + check(mouse.render().pixels != list.pixels && !mouse.text("IGNORED") && + !mouse.key("BACKSPACE") && !mouse.info_press(70, 45), + "the original overwrite question owns input and renders over the file list"); + check(!mouse.click(100, 171, false, true) && !mouse.pending(), + "double-click releases cannot accept even over the question's Yes button"); + check(mouse.click(210, 171) && !mouse.pending() && !mouse.close_requested() && + mouse.render().pixels == list.pixels, + "No dismisses the question and restores the unchanged picker"); + mouse.click(70, 45, false, true); + check(mouse.click(100, 171) && mouse.pending() && mouse.pending()->overwrite && + mouse.pending()->path == existing, + "double-click followed by a separate Yes click submits an entirely mouse-operated overwrite"); + const auto mouse_request = *mouse.pending(); + check(!mouse.click(100, 171) && *mouse.pending() == mouse_request, + "additional Yes releases preserve one pending write"); + unchanged(); for (bool right : {false, true}) { SaveLoadScreen cancel(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind); cancel.click(70, 45, false, true); @@ -74,16 +93,21 @@ int main(int argc, char** argv) { std::ofstream(second) << fixture; SaveLoadScreen change_row(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind); change_row.click(70, 45, false, true); + check(!change_row.click(70, 55) && change_row.selected() == 0, + "the question prevents the file list from changing its target"); + change_row.click(210, 171); // Decline before selecting another file. check(change_row.click(70, 55) && change_row.key("ENTER") && !change_row.pending() && change_row.key("ENTER") && change_row.pending() && change_row.pending()->path == second, "selecting another row cannot reuse the first file's overwrite confirmation"); SaveLoadScreen reset(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind); reset.click(70, 45, false, true); + reset.click(210, 171); reset.click(70, 45); check(reset.key("ENTER") && !reset.pending() && reset.key("ENTER") && reset.pending(), - "single selection clears confirmation and preserves the existing two-Enter save path"); + "declining and selecting again preserves the existing two-Enter save path"); SaveLoadScreen rename(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind); rename.click(70, 45, false, true); + rename.click(210, 171); check(rename.text("Other") && rename.key("ENTER") && rename.pending() && !rename.pending()->overwrite && rename.pending()->path.filename() == std::string("Other") + extension, "editing an armed overwrite starts an independent new-file save");