From d1f65401966bcd64bf2009e3abad24d5e976bccb Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Fri, 21 Jul 2023 01:00:36 +0300 Subject: [PATCH] Snake: Update snake skin color interactively while picking The snake now changes color while interacting with `GUI::ColorPicker` --- Userland/Games/Snake/Game.h | 1 + Userland/Games/Snake/main.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Games/Snake/Game.h b/Userland/Games/Snake/Game.h index e6255706587f0b..413001dca9e094 100644 --- a/Userland/Games/Snake/Game.h +++ b/Userland/Games/Snake/Game.h @@ -34,6 +34,7 @@ class Game Function on_score_update; void set_skin_color(Color); + Gfx::Color get_skin_color() const { return m_snake_color; } void set_skin_name(DeprecatedString); void set_skin(NonnullOwnPtr skin); diff --git a/Userland/Games/Snake/main.cpp b/Userland/Games/Snake/main.cpp index d6a3c6a604cced..7ff0efb749634f 100644 --- a/Userland/Games/Snake/main.cpp +++ b/Userland/Games/Snake/main.cpp @@ -108,11 +108,12 @@ ErrorOr serenity_main(Main::Arguments arguments) auto was_paused = game.is_paused(); if (!was_paused) game.pause(); - auto dialog = GUI::ColorPicker::construct(Gfx::Color::White, window); - if (dialog->exec() == GUI::Dialog::ExecResult::OK) { + auto dialog = GUI::ColorPicker::construct(game.get_skin_color(), window); + dialog->on_color_changed = [&game](Gfx::Color color) { + game.set_skin_color(color); + }; + if (dialog->exec() == GUI::Dialog::ExecResult::OK) Config::write_u32("Snake"sv, "Snake"sv, "BaseColor"sv, dialog->color().value()); - game.set_skin_color(dialog->color()); - } if (!was_paused) game.start(); });