BrickGame: Remember the "Show Shadow Piece" setting between executions

by using the ConfigServer.
This commit is contained in:
Karol Baraniecki 2023-04-08 01:49:21 +02:00 committed by Jelle Raaijmakers
parent 439076df8a
commit f532f9d279
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00
3 changed files with 12 additions and 2 deletions

View file

@ -477,6 +477,11 @@ void BrickGame::set_show_shadow_hint(bool should_show)
repaint();
}
bool BrickGame::show_shadow_hint()
{
return m_show_shadow_hint;
}
void BrickGame::timer_event(Core::TimerEvent&)
{
switch (m_brick_game->state()) {

View file

@ -27,6 +27,7 @@ public:
void reset();
void toggle_pause();
void set_show_shadow_hint(bool);
bool show_shadow_hint();
private:
BrickGame(StringView app_name);

View file

@ -59,10 +59,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_action(GUI::Action::create("Toggle &Pause", { Mod_None, Key_P }, [&](auto&) {
game->toggle_pause();
})));
auto show_shadow_piece_action = TRY(GUI::Action::try_create_checkable("&Show Shadow Piece", GUI::Shortcut {}, [&](auto& action) {
auto show_shadow_piece_action = TRY(GUI::Action::try_create_checkable("Show Shadow Piece", GUI::Shortcut {}, [&](auto& action) {
game->set_show_shadow_hint(action.is_checked());
Config::write_bool(app_name, app_name, "ShowShadowPiece"sv, action.is_checked());
}));
show_shadow_piece_action->set_checked(true);
game->set_show_shadow_hint(Config::read_bool(app_name, app_name, "ShowShadowPiece"sv, true));
show_shadow_piece_action->set_checked(game->show_shadow_hint());
TRY(game_menu->try_add_action(show_shadow_piece_action));
TRY(game_menu->try_add_separator());
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {