BrickGame: Add a menu option to disable the shadow drop hint

This commit is contained in:
Karol Baraniecki 2023-04-08 01:37:25 +02:00 committed by Jelle Raaijmakers
parent f3f14a7ef1
commit 439076df8a
Notes: sideshowbarker 2024-07-17 02:06:40 +09:00
3 changed files with 14 additions and 1 deletions

View File

@ -471,6 +471,12 @@ void BrickGame::toggle_pause()
update();
}
void BrickGame::set_show_shadow_hint(bool should_show)
{
m_show_shadow_hint = should_show;
repaint();
}
void BrickGame::timer_event(Core::TimerEvent&)
{
switch (m_brick_game->state()) {
@ -547,7 +553,7 @@ void BrickGame::paint_cell(GUI::Painter& painter, Gfx::IntRect rect, BrickGame::
break;
case BrickGame::BoardSpace::ShadowHint:
inside_color = m_shadow_color;
outside_color = m_hint_block_color;
outside_color = m_show_shadow_hint ? m_hint_block_color : m_shadow_color;
break;
case BrickGame::BoardSpace::Off:
inside_color = m_shadow_color;

View File

@ -26,6 +26,7 @@ public:
void reset();
void toggle_pause();
void set_show_shadow_hint(bool);
private:
BrickGame(StringView app_name);
@ -48,6 +49,7 @@ private:
GameState m_state {};
NonnullOwnPtr<Bricks> m_brick_game;
unsigned m_high_score {};
bool m_show_shadow_hint { true };
Color m_back_color { Color::from_rgb(0x8fbc8f) };
Color m_front_color { Color::Black };

View File

@ -59,6 +59,11 @@ 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) {
game->set_show_shadow_hint(action.is_checked());
}));
show_shadow_piece_action->set_checked(true);
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&) {
GUI::Application::the()->quit();