mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
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:
parent
56a75ec94e
commit
89c6d41e9c
2 changed files with 10 additions and 0 deletions
|
@ -22,6 +22,8 @@ public:
|
||||||
void pause();
|
void pause();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
void set_snake_base_color(Color color) { m_snake_base_color = color; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SnakeGame(NonnullRefPtrVector<Gfx::Bitmap> food_bitmaps);
|
explicit SnakeGame(NonnullRefPtrVector<Gfx::Bitmap> food_bitmaps);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
|
#include <LibGUI/ColorPicker.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Menubar.h>
|
#include <LibGUI/Menubar.h>
|
||||||
|
@ -68,6 +69,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
action.set_icon(pause_icon);
|
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_separator());
|
||||||
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
||||||
GUI::Application::the()->quit();
|
GUI::Application::the()->quit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue