Confirm application exits in German and English (by Codex)
Route window-close events, animation polls, Escape and desktop exit through a native confirmation with Cancel selected by default. Preserve the current owner when cancelled. Refs #11.
This commit is contained in:
1 parent
7eff8a34f8
commit
e1d17d8f81
7 files changed
+206
-50
No files matched your search
@@ -1081,6 +1081,14 @@ if(MSVC)
|
||||
endif()
|
||||
add_test(NAME host_path_display_unit_tests COMMAND host_path_display_unit_tests)
|
||||
|
||||
add_executable(quit_confirmation_unit_tests tests/quit_confirmation_unit_tests.cpp)
|
||||
target_include_directories(quit_confirmation_unit_tests PRIVATE src)
|
||||
target_link_libraries(quit_confirmation_unit_tests PRIVATE ${BMH_SDL_TARGET})
|
||||
if(MSVC)
|
||||
target_compile_options(quit_confirmation_unit_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME quit_confirmation_unit_tests COMMAND quit_confirmation_unit_tests)
|
||||
|
||||
add_executable(fixture_table_tests tests/fixture_table_tests.cpp)
|
||||
target_link_libraries(fixture_table_tests PRIVATE bmhcore)
|
||||
add_test(NAME fixture_table_unit_tests COMMAND fixture_table_tests)
|
||||
|
||||
@@ -12,6 +12,17 @@ Intentional changes in code should use the marker `OpenBMH deviates from the ori
|
||||
|
||||
The [generated differences catalogue](DIFFERENCES.md) lists these markers with links to their source files.
|
||||
|
||||
## Application exit confirmation
|
||||
|
||||
Closing the window, exiting with Escape or confirming the desktop's exit control
|
||||
opens a native confirmation dialog. BMH data uses German text and Football
|
||||
Limited data uses English. Enter, Escape and closing the confirmation cancel the
|
||||
exit; only the explicit Quit/Beenden button permits normal shutdown. Cancelling
|
||||
keeps the current dialog or match owner alive without a turn or implicit save.
|
||||
An unavailable native message box also cancels the request. This applies to
|
||||
voluntary application exits, including quit events received during animations;
|
||||
normal completed-career handling remains separate.
|
||||
|
||||
## Environment and presentation in 0.1.2
|
||||
|
||||
The desktop environment provides three youth teams and three staff
|
||||
|
||||
@@ -6,6 +6,7 @@ See [Compatibility decisions](COMPATIBILITY.md) for the overall policy. These en
|
||||
describe deliberate changes; they are not a list of every known compatibility limit.
|
||||
|
||||
- [src/app/career_session.cpp](../src/app/career_session.cpp): supports designated set-piece record initialization and validation.
|
||||
- [src/app/quit_confirmation.hpp](../src/app/quit_confirmation.hpp): confirms application exit with a localized native dialog, with cancellation selected by default.
|
||||
- [src/formats/le.hpp](../src/formats/le.hpp): applies a shared supported rule profile when loading editions with different rule-table values.
|
||||
- [src/formats/rule_base.cpp](../src/formats/rule_base.cpp): normalizes live-scene defaults, league strength ranges, option defaults, stadium prices and capacities, betting limits, and the foreign-player limit across supported editions.
|
||||
- [src/formats/rule_base.hpp](../src/formats/rule_base.hpp): normalizes live-scene options, league strength ranges, option defaults, stadium prices and capacities, betting limits, and the foreign-player limit.
|
||||
|
||||
@@ -4,6 +4,10 @@ OpenBMH reconstructs the Bundesliga Manager Hattrick engine in C++20. The graphi
|
||||
|
||||
## Unreleased corrections
|
||||
|
||||
- Application exits ask for confirmation in a native German/English message
|
||||
box, with Cancel selected by default, including window close events during
|
||||
matches and dialogs ([#11](https://github.com/Weyoune/openbmh/issues/11)).
|
||||
|
||||
- Football Limited uses the correct enabled/disabled setup sprites, positive
|
||||
balance colour and outside controls of the desktop shortcut bar ([#7](https://github.com/Weyoune/openbmh/issues/7)).
|
||||
Its cached data is regenerated automatically for the corrected mapping.
|
||||
|
||||
+59
-50
@@ -25,6 +25,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "app/controller.hpp"
|
||||
#include "app/quit_confirmation.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/file_dialog.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
@@ -219,6 +220,8 @@ int main(int argc, char** argv) {
|
||||
ui::SportschauTeamInfo sportschau_team_info(data);
|
||||
ui::CompetitionWinnerScreen competition_winner(data);
|
||||
const auto season_exe = load_le(ui::asset_path(data, "BMH.exe"));
|
||||
english_game = english_game || season_exe.u8(layout::LeagueSizes) == 20;
|
||||
app::QuitConfirmation quit_confirmation(window, english_game);
|
||||
try {
|
||||
if (!playback.initialize_original(app::original_audio_assets(data, season_exe), audio_error))
|
||||
std::fprintf(stderr, "audio: %s\n", audio_error.c_str());
|
||||
@@ -358,7 +361,7 @@ int main(int argc, char** argv) {
|
||||
if (screen.close_requested()) return renewed_expired_player ? 1 : 0;
|
||||
SDL_Event event;
|
||||
bool changed = false;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
running = false;
|
||||
staged = before;
|
||||
@@ -460,7 +463,7 @@ int main(int argc, char** argv) {
|
||||
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
|
||||
while (running) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) return;
|
||||
@@ -474,7 +477,7 @@ int main(int argc, char** argv) {
|
||||
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
|
||||
while (running) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) return;
|
||||
@@ -487,7 +490,7 @@ int main(int argc, char** argv) {
|
||||
SDL_Delay(20); // Source timer unit used by the traced intro path.
|
||||
SDL_PumpEvents();
|
||||
SDL_Event close;
|
||||
while (SDL_PeepEvents(&close, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0)
|
||||
while (quit_confirmation.peep(&close, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0)
|
||||
running = false; // platform close is the only intro-loop escape
|
||||
}
|
||||
};
|
||||
@@ -501,7 +504,7 @@ int main(int argc, char** argv) {
|
||||
while (running && SDL_GetPerformanceCounter() - started < ticks_per_wait) {
|
||||
SDL_PumpEvents();
|
||||
SDL_Event close;
|
||||
while (SDL_PeepEvents(&close, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0)
|
||||
while (quit_confirmation.peep(&close, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0)
|
||||
running = false; // platform close is the only animation-loop escape
|
||||
if (running) SDL_Delay(1);
|
||||
}
|
||||
@@ -551,7 +554,7 @@ int main(int argc, char** argv) {
|
||||
bool skipped = false;
|
||||
while (running && !skipped && SDL_GetTicks() - start < duration) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) running = false;
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN && input.button.button == SDL_BUTTON_LEFT)
|
||||
skipped = true;
|
||||
@@ -574,14 +577,14 @@ int main(int argc, char** argv) {
|
||||
bool skip = false;
|
||||
SDL_Event input;
|
||||
if (step.minute_wait) {
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) running = false;
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN && input.button.button == SDL_BUTTON_LEFT)
|
||||
skip = true;
|
||||
}
|
||||
} else {
|
||||
SDL_PumpEvents();
|
||||
while (SDL_PeepEvents(&input, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) running = false;
|
||||
while (quit_confirmation.peep(&input, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) running = false;
|
||||
}
|
||||
if (!running) return true;
|
||||
const std::string title = "OpenBMH - sportschau_replay_" + std::to_string(fixture.group) +
|
||||
@@ -696,7 +699,7 @@ int main(int argc, char** argv) {
|
||||
auto pressed = ui::GameEndTaxDialog::Button::none;
|
||||
while (running) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return false; }
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event.kind != SeasonTaxEventKind::question &&
|
||||
@@ -735,7 +738,7 @@ int main(int argc, char** argv) {
|
||||
const auto started = SDL_GetTicks();
|
||||
while (running && Uint32(SDL_GetTicks() - started) < animation.wait_milliseconds()) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) if (input.type == SDL_QUIT) running = false;
|
||||
while (quit_confirmation.poll(&input)) if (input.type == SDL_QUIT) running = false;
|
||||
// Source param4=0: clicks/keys cannot change this script or RNG.
|
||||
SDL_Delay(10);
|
||||
}
|
||||
@@ -752,7 +755,7 @@ int main(int argc, char** argv) {
|
||||
// events for the next Original input boundary; only handle SDL exit.
|
||||
SDL_PumpEvents();
|
||||
SDL_Event quit;
|
||||
if (SDL_PeepEvents(&quit, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) running = false;
|
||||
if (quit_confirmation.peep(&quit, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) running = false;
|
||||
if (running) SDL_Delay(10);
|
||||
}
|
||||
};
|
||||
@@ -807,7 +810,7 @@ int main(int argc, char** argv) {
|
||||
if (timed && Uint32(SDL_GetTicks() - started) >= 70 * 3 * 20)
|
||||
return complete(PendingOfferAnswer::yes);
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return PendingOfferAnswer::unsupported; }
|
||||
const bool question_deadline = question && poll_process_timer(true,true);
|
||||
if (question_deadline && pressed == ui::GameEndTaxDialog::Button::none)
|
||||
@@ -877,7 +880,7 @@ int main(int argc, char** argv) {
|
||||
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP); // DecodeTaxAnimationScript/SDLFlushEvents redraw boundary
|
||||
while (running) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return PendingOfferTransferChoice{}; }
|
||||
std::optional<int> bid;
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN &&
|
||||
@@ -906,7 +909,7 @@ int main(int argc, char** argv) {
|
||||
bool acknowledged=false;
|
||||
while(running && !acknowledged) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
while(quit_confirmation.poll(&event)) {
|
||||
if(event.type==SDL_QUIT){running=false;break;}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN &&
|
||||
(event.button.button==SDL_BUTTON_LEFT || event.button.button==SDL_BUTTON_RIGHT)) {
|
||||
@@ -969,7 +972,7 @@ int main(int argc, char** argv) {
|
||||
draw();
|
||||
while (running) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return -1; }
|
||||
ui::OutgoingTransferRequest action;
|
||||
if (event.type == SDL_MOUSEMOTION) continue;
|
||||
@@ -1086,7 +1089,7 @@ int main(int argc, char** argv) {
|
||||
while (running) {
|
||||
if (deadline_expired()) return true; //ClubInfoFromGame event8 returns to its owning caller.
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return false; }
|
||||
if (deadline_expired()) return true;
|
||||
ui::ClubInfoRequest request;
|
||||
@@ -1187,7 +1190,7 @@ int main(int argc, char** argv) {
|
||||
SDL_PumpEvents();
|
||||
while (running && (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON_LMASK)) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input))
|
||||
while (quit_confirmation.poll(&input))
|
||||
if (input.type == SDL_QUIT) { running = false; return; }
|
||||
SDL_PumpEvents();
|
||||
if (running) SDL_Delay(10);
|
||||
@@ -1255,7 +1258,7 @@ int main(int argc, char** argv) {
|
||||
while (running) {
|
||||
if (const auto complete = expire_card()) return *complete;
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return std::nullopt; }
|
||||
if (const auto complete = expire_card()) return *complete;
|
||||
bool changed = false;
|
||||
@@ -1317,7 +1320,7 @@ int main(int argc, char** argv) {
|
||||
while (running) {
|
||||
if (deadline_expired()) return; //LeagueCalculations frees its child before4f548 polls again.
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return; }
|
||||
if (deadline_expired()) return;
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN && input.button.button == SDL_BUTTON_RIGHT)
|
||||
@@ -1401,7 +1404,7 @@ int main(int argc, char** argv) {
|
||||
while(running&&!outcome) {
|
||||
if(expire_range())break;
|
||||
SDL_Event input;
|
||||
while(SDL_PollEvent(&input)) {
|
||||
while(quit_confirmation.poll(&input)) {
|
||||
if(input.type==SDL_QUIT){running=false;break;}
|
||||
if(expire_range())break;
|
||||
bool changed=false;
|
||||
@@ -1457,7 +1460,7 @@ int main(int argc, char** argv) {
|
||||
while(running) {
|
||||
if(deadline_expired())return std::nullopt;
|
||||
SDL_Event input;
|
||||
while(SDL_PollEvent(&input)) {
|
||||
while(quit_confirmation.poll(&input)) {
|
||||
if(input.type==SDL_QUIT){running=false;break;}
|
||||
if(deadline_expired())return std::nullopt;
|
||||
bool changed=false;
|
||||
@@ -1551,7 +1554,7 @@ int main(int argc, char** argv) {
|
||||
// Source ignores the first OriginalMouseSound poll's gameplay result, then
|
||||
// presents the starting scene before its ten option-delay polls.
|
||||
SDL_Event initial;
|
||||
if (SDL_PollEvent(&initial) && initial.type == SDL_QUIT) { running = false; return; }
|
||||
if (quit_confirmation.poll(&initial) && initial.type == SDL_QUIT) { running = false; return; }
|
||||
show_draw();
|
||||
while (running && screen.advance_step()) {
|
||||
if (screen.present_needed()) show_draw();
|
||||
@@ -1559,7 +1562,7 @@ int main(int argc, char** argv) {
|
||||
if (!running) return;
|
||||
if (screen.input_poll_needed()) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return; }
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(input.button.button == SDL_BUTTON_LEFT || input.button.button == SDL_BUTTON_RIGHT)) {
|
||||
@@ -1594,7 +1597,7 @@ int main(int argc, char** argv) {
|
||||
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
|
||||
while (running) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; return; }
|
||||
if (input.type != SDL_MOUSEBUTTONDOWN) continue;
|
||||
if (input.button.button == SDL_BUTTON_RIGHT) return;
|
||||
@@ -1631,7 +1634,7 @@ int main(int argc, char** argv) {
|
||||
while (running && screen.phase() == ui::AlternateScorePhase::Calculator) {
|
||||
SDL_Event event;
|
||||
bool changed = false;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) {
|
||||
right_cancel = true;
|
||||
@@ -1696,6 +1699,11 @@ int main(int argc, char** argv) {
|
||||
std::optional<Uint64> timed_notice_presented_at;
|
||||
std::optional<Uint8> timed_notice_release;
|
||||
auto handle = [&](const ui::FlowResult& r) {
|
||||
if (r.request == ui::FlowRequest::end_session && !quit_confirmation.confirm()) {
|
||||
flow.reject_desk_action(english_game ? "Quit cancelled." : "Beenden abgebrochen.");
|
||||
dirty = true;
|
||||
return;
|
||||
}
|
||||
if (const auto* desk = flow.desktop())
|
||||
for (const auto id : desk->take_sound_ids()) app::original_audio_command(playback, id);
|
||||
if (r.request == ui::FlowRequest::kickoff || r.request == ui::FlowRequest::end_session) {
|
||||
@@ -1818,7 +1826,7 @@ int main(int argc, char** argv) {
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Event modal;
|
||||
bool redrawn = false;
|
||||
while (SDL_PollEvent(&modal)) {
|
||||
while (quit_confirmation.poll(&modal)) {
|
||||
if (modal.type == SDL_QUIT) { running = false; closed = true; break; }
|
||||
if (modal.type == SDL_KEYDOWN && modal.key.keysym.sym == SDLK_ESCAPE) {
|
||||
screen.key("ESC"); closed = true; break;
|
||||
@@ -1988,7 +1996,7 @@ int main(int argc, char** argv) {
|
||||
show_dialog();
|
||||
while (running && !outcome) {
|
||||
SDL_Event input;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; break; }
|
||||
bool changed = false;
|
||||
if (input.type == SDL_TEXTINPUT) {
|
||||
@@ -2088,7 +2096,7 @@ int main(int argc, char** argv) {
|
||||
while (running && !closed) {
|
||||
SDL_Event input;
|
||||
bool redrawn = false;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; break; }
|
||||
if (input.type == SDL_MOUSEMOTION) {
|
||||
const bool changed = table_screen ? table_screen->move(input.motion.x, input.motion.y)
|
||||
@@ -2198,7 +2206,7 @@ int main(int argc, char** argv) {
|
||||
offer_dirty = false;
|
||||
}
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return -1; }
|
||||
std::optional<int> answer;
|
||||
if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
@@ -2267,7 +2275,7 @@ int main(int argc, char** argv) {
|
||||
rendered_phase = phase;
|
||||
}
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT))
|
||||
@@ -2295,7 +2303,7 @@ int main(int argc, char** argv) {
|
||||
bool dismissed = false;
|
||||
while (running && !dismissed) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) {
|
||||
@@ -2449,7 +2457,7 @@ int main(int argc, char** argv) {
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Event modal;
|
||||
bool redrawn = false;
|
||||
while (SDL_PollEvent(&modal)) {
|
||||
while (quit_confirmation.poll(&modal)) {
|
||||
if (modal.type == SDL_QUIT) { running = false; closed = true; break; }
|
||||
if (modal.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(modal.button.button == SDL_BUTTON_LEFT || modal.button.button == SDL_BUTTON_RIGHT))
|
||||
@@ -2514,7 +2522,7 @@ int main(int argc, char** argv) {
|
||||
bool resumed = false;
|
||||
while (running && !resumed) {
|
||||
SDL_Event paused_event;
|
||||
while (SDL_PollEvent(&paused_event)) {
|
||||
while (quit_confirmation.poll(&paused_event)) {
|
||||
if (paused_event.type == SDL_QUIT) {
|
||||
quit = true;
|
||||
live_skipped = true;
|
||||
@@ -2632,7 +2640,7 @@ int main(int argc, char** argv) {
|
||||
while (running && !finished) {
|
||||
SDL_Event file_input;
|
||||
bool file_changed = false;
|
||||
while (SDL_PollEvent(&file_input)) {
|
||||
while (quit_confirmation.poll(&file_input)) {
|
||||
if (file_input.type == SDL_QUIT) { running = false; break; }
|
||||
if (file_input.type == SDL_MOUSEBUTTONUP &&
|
||||
(file_input.button.button == SDL_BUTTON_LEFT ||
|
||||
@@ -2692,7 +2700,7 @@ int main(int argc, char** argv) {
|
||||
while (running && !closed) {
|
||||
SDL_Event input;
|
||||
bool changed = false;
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; break; }
|
||||
if (readme) {
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN &&
|
||||
@@ -2806,7 +2814,7 @@ int main(int argc, char** argv) {
|
||||
const bool source_phase_start = minute == 1 ||
|
||||
(state.indoor ? minute == 21 : (minute == 46 || minute == 91 || minute == 106));
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { quit = true; live_skipped = true; }
|
||||
else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
|
||||
live_skipped = true;
|
||||
@@ -2927,7 +2935,7 @@ int main(int argc, char** argv) {
|
||||
present(live_screen.render_ball(frame, event.displacement, index, chance));
|
||||
SDL_PumpEvents();
|
||||
SDL_Event quit_event;
|
||||
if (SDL_PeepEvents(&quit_event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
if (quit_confirmation.peep(&quit_event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
@@ -2964,7 +2972,7 @@ int main(int argc, char** argv) {
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_PumpEvents();
|
||||
SDL_Event quit_event;
|
||||
if (SDL_PeepEvents(&quit_event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
if (quit_confirmation.peep(&quit_event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
running = false;
|
||||
live_chance_context.reset();
|
||||
return;
|
||||
@@ -2996,7 +3004,7 @@ int main(int argc, char** argv) {
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_PumpEvents();
|
||||
SDL_Event input;
|
||||
if (SDL_PeepEvents(&input, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
if (quit_confirmation.peep(&input, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) > 0) {
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
@@ -3018,7 +3026,7 @@ int main(int argc, char** argv) {
|
||||
SDL_Event input;
|
||||
bool acknowledged = false;
|
||||
while (running && !acknowledged) {
|
||||
while (SDL_PollEvent(&input)) {
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; break; }
|
||||
if (input.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(input.button.button == SDL_BUTTON_LEFT || input.button.button == SDL_BUTTON_RIGHT)) {
|
||||
@@ -3053,7 +3061,7 @@ int main(int argc, char** argv) {
|
||||
SDL_UpdateTexture(texture,nullptr,pixels.data(),320*4);
|
||||
SDL_RenderClear(renderer);SDL_RenderCopy(renderer,texture,nullptr,nullptr);SDL_RenderPresent(renderer);
|
||||
SDL_PumpEvents();SDL_Event input;
|
||||
if (SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
if (quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
// FirstThen holds the first frame for 40 retraces; later frames
|
||||
// use saved Main_FormatError_RuntimeField2. Keyboard/mouse input remains for the minute hook.
|
||||
const int retraces=index==0?40:(state.memory.has(::bmh::layout::Main_FormatError_RuntimeField2)?state.memory.u8(::bmh::layout::Main_FormatError_RuntimeField2):0);
|
||||
@@ -3079,7 +3087,7 @@ int main(int argc, char** argv) {
|
||||
if (event.kind != 2 && app::match_sound_enabled(state))
|
||||
app::original_audio_command(playback, 17); // EventImpl/SDLPumpEvents, no injury whistle.
|
||||
SDL_PumpEvents();SDL_Event input;
|
||||
if (SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
if (quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
const int pause=event.kind==0?3:4;
|
||||
const uint32_t address=::bmh::layout::Main_FormatError_ExecutableFieldUnsigned+uint32_t(pause*9);
|
||||
const int saved=state.memory.has(address)?state.memory.u8(address):0;
|
||||
@@ -3103,7 +3111,7 @@ int main(int argc, char** argv) {
|
||||
SDL_UpdateTexture(texture,nullptr,pixels.data(),320*4);
|
||||
SDL_RenderClear(renderer);SDL_RenderCopy(renderer,texture,nullptr,nullptr);SDL_RenderPresent(renderer);
|
||||
SDL_PumpEvents();SDL_Event input;
|
||||
if (SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
if (quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) { running=false;return; }
|
||||
const int repeats=event.stage==LiveShootoutStage::preview?4:2;
|
||||
const int saved=state.memory.has(::bmh::layout::Main_FormatError_RuntimeField6)?state.memory.u8(::bmh::layout::Main_FormatError_RuntimeField6):0;
|
||||
const int delay=live_frame_ms_explicit?live_frame_ms:(saved<6?saved/2:saved)*20;
|
||||
@@ -3167,16 +3175,16 @@ int main(int argc, char** argv) {
|
||||
present(reality_surface,reality_colors,"OpenBMH - live_reality_report_"+round_identity);
|
||||
}
|
||||
SDL_PumpEvents();SDL_Event input;
|
||||
if (SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) {running=false;return true;}
|
||||
if (quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_QUIT,SDL_QUIT)>0) {running=false;return true;}
|
||||
// Consume only the Source exit for this scene. Other input remains
|
||||
// queued for the existing live-minute/manager intervention boundary.
|
||||
if (SDL_PeepEvents(&input,1,SDL_PEEKEVENT,SDL_KEYDOWN,SDL_KEYDOWN)>0 &&
|
||||
if (quit_confirmation.peep(&input,1,SDL_PEEKEVENT,SDL_KEYDOWN,SDL_KEYDOWN)>0 &&
|
||||
input.key.keysym.sym==SDLK_ESCAPE) {
|
||||
SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_KEYDOWN,SDL_KEYDOWN);return true;
|
||||
quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_KEYDOWN,SDL_KEYDOWN);return true;
|
||||
}
|
||||
if (SDL_PeepEvents(&input,1,SDL_PEEKEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN)>0 &&
|
||||
if (quit_confirmation.peep(&input,1,SDL_PEEKEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN)>0 &&
|
||||
input.button.button==SDL_BUTTON_RIGHT) {
|
||||
SDL_PeepEvents(&input,1,SDL_GETEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN);return true;
|
||||
quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN);return true;
|
||||
}
|
||||
return false;
|
||||
}, [&](const PhaseResultRequest& request, const std::vector<MatchGroup>& groups,
|
||||
@@ -3601,7 +3609,7 @@ int main(int argc, char** argv) {
|
||||
service_process_timer();
|
||||
if (!running) break;
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
while (quit_confirmation.poll(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
running = false;
|
||||
break;
|
||||
@@ -3680,7 +3688,8 @@ int main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE &&
|
||||
!flow.in_preparation_menu() && !flow.in_results_view() && !flow.in_readonly_view())
|
||||
!flow.in_preparation_menu() && !flow.in_results_view() && !flow.in_readonly_view() &&
|
||||
quit_confirmation.confirm())
|
||||
running = false;
|
||||
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
|
||||
press = Press{e.button.x, e.button.y, SDL_GetTicks(), flow.screen_name(),
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
|
||||
#include <SDL.h>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace bmh::app {
|
||||
|
||||
// OpenBMH deviates from the original: confirms application exit with a localized native dialog, with cancellation selected by default.
|
||||
// All event retrieval remains on the UI thread. An event filter/watch could run
|
||||
// on SDL's event thread and must not own a native modal dialog.
|
||||
class QuitConfirmation {
|
||||
public:
|
||||
using Presenter = std::function<int(const SDL_MessageBoxData*, int*)>;
|
||||
QuitConfirmation(SDL_Window* window, bool english, Presenter presenter = SDL_ShowMessageBox)
|
||||
: window_(window), english_(english), presenter_(std::move(presenter)) {}
|
||||
|
||||
bool confirm() {
|
||||
if (confirmed_) return true;
|
||||
const SDL_MessageBoxButtonData buttons[] = {
|
||||
{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT | SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
|
||||
0, english_ ? "Cancel" : "Abbrechen"},
|
||||
{0, 1, english_ ? "Quit" : "Beenden"}
|
||||
};
|
||||
const SDL_MessageBoxData dialog{SDL_MESSAGEBOX_WARNING, window_,
|
||||
english_ ? "Quit OpenBMH?" : "OpenBMH beenden?",
|
||||
english_ ? "Do you really want to quit OpenBMH?\nUnsaved changes will be lost." :
|
||||
"OpenBMH wirklich beenden?\nNicht gespeicherte Änderungen gehen verloren.",
|
||||
2, buttons, nullptr};
|
||||
int selected = 0;
|
||||
if (presenter_(&dialog, &selected) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Cannot show quit confirmation: %s", SDL_GetError());
|
||||
return false; // A failed dialog must not silently discard the session.
|
||||
}
|
||||
confirmed_ = selected == 1;
|
||||
return confirmed_;
|
||||
}
|
||||
|
||||
int poll(SDL_Event* event) {
|
||||
if (!event) return SDL_PollEvent(nullptr);
|
||||
while (SDL_PollEvent(event)) {
|
||||
if (event->type != SDL_QUIT || confirm()) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int peep(SDL_Event* events, int count, SDL_eventaction action, Uint32 first, Uint32 last) {
|
||||
const int received = SDL_PeepEvents(events, count, action, first, last);
|
||||
if (received <= 0 || !events || action != SDL_GETEVENT) return received;
|
||||
int kept = 0;
|
||||
for (int i = 0; i < received; ++i)
|
||||
if (events[i].type != SDL_QUIT || confirm()) events[kept++] = events[i];
|
||||
return kept;
|
||||
}
|
||||
|
||||
private:
|
||||
SDL_Window* window_;
|
||||
bool english_, confirmed_ = false;
|
||||
Presenter presenter_;
|
||||
};
|
||||
|
||||
} // namespace bmh::app
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "app/quit_confirmation.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); }
|
||||
void push(Uint32 type) {
|
||||
SDL_Event event{}; event.type = type;
|
||||
check(SDL_PushEvent(&event) == 1, "cannot enqueue authored event");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
using bmh::app::QuitConfirmation;
|
||||
try {
|
||||
check(SDL_Init(SDL_INIT_EVENTS) == 0, "SDL events initialization");
|
||||
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
||||
int presentations = 0, answer = 0;
|
||||
const auto present = [&](const SDL_MessageBoxData* data, int* selected) {
|
||||
++presentations;
|
||||
check(std::string(data->title) == "OpenBMH beenden?", "German prompt");
|
||||
check(std::string(data->message).find("gespeicherte") != std::string::npos, "unsaved-state warning");
|
||||
check(data->numbuttons == 2 && std::string(data->buttons[0].text) == "Abbrechen", "German buttons");
|
||||
check((data->buttons[0].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) &&
|
||||
(data->buttons[0].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT), "Enter and Escape must default to cancellation");
|
||||
*selected = answer; return 0;
|
||||
};
|
||||
QuitConfirmation german(nullptr, false, present);
|
||||
push(SDL_QUIT); push(SDL_USEREVENT);
|
||||
SDL_Event event{};
|
||||
check(german.poll(&event) == 1 && event.type == SDL_USEREVENT && presentations == 1,
|
||||
"cancelled window close must preserve subsequent UI input");
|
||||
push(SDL_QUIT);
|
||||
check(german.peep(&event, 1, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT) == 1 && presentations == 1,
|
||||
"peeking must not open or consume a dialog");
|
||||
check(german.peep(&event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) == 0 && presentations == 2,
|
||||
"cancelled animation/live close must not abort its owner");
|
||||
answer = 1; push(SDL_QUIT);
|
||||
check(german.peep(&event, 1, SDL_GETEVENT, SDL_QUIT, SDL_QUIT) == 1 && event.type == SDL_QUIT,
|
||||
"confirmed close must reach existing shutdown handling");
|
||||
check(german.confirm() && presentations == 3, "confirmed shutdown must not ask twice");
|
||||
bool english_seen = false;
|
||||
QuitConfirmation english(nullptr, true, [&](const SDL_MessageBoxData* data, int* selected) {
|
||||
english_seen = std::string(data->title) == "Quit OpenBMH?" &&
|
||||
std::string(data->buttons[0].text) == "Cancel" && std::string(data->buttons[1].text) == "Quit";
|
||||
*selected = 1; return 0;
|
||||
});
|
||||
check(english.confirm() && english_seen, "Football Limited uses English confirmation");
|
||||
QuitConfirmation failed(nullptr, false, [](const SDL_MessageBoxData*, int*) { return -1; });
|
||||
check(!failed.confirm(), "failed native dialog must keep the application alive");
|
||||
SDL_Quit();
|
||||
std::cout << "Quit confirmation language, defaults, cancel, accept and event ownership passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
SDL_Quit(); std::cerr << error.what() << '\n'; return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user