Snake: Add snake color chooser game menu action

This patch makes use of a new "set_snake_base_color()" function to
change the snake's base color to the picked value.
This commit is contained in:
Baitinq 2022-12-18 21:28:11 +01:00 committed by Tim Flynn
parent 56a75ec94e
commit 89c6d41e9c
2 changed files with 10 additions and 0 deletions

View file

@ -22,6 +22,8 @@ public:
void pause();
void reset();
void set_snake_base_color(Color color) { m_snake_base_color = color; };
private:
explicit SnakeGame(NonnullRefPtrVector<Gfx::Bitmap> food_bitmaps);

View file

@ -13,6 +13,7 @@
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/ColorPicker.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
@ -68,6 +69,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
action.set_icon(pause_icon);
}
})));
TRY(game_menu->try_add_action(GUI::Action::create("&Change snake color", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/color-chooser.png"sv)), [&](auto&) {
game->pause();
auto dialog = GUI::ColorPicker::construct(Gfx::Color::White, window);
if (dialog->exec() == GUI::Dialog::ExecResult::OK)
game->set_snake_base_color(dialog->color());
game->start();
})));
TRY(game_menu->try_add_separator());
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();