Snake: Update snake skin color interactively while picking

The snake now changes color while interacting with `GUI::ColorPicker`
This commit is contained in:
Valtteri Koskivuori 2023-07-21 01:00:36 +03:00 committed by Ali Mohammad Pur
parent 0388bb019f
commit d1f6540196
2 changed files with 6 additions and 4 deletions

View file

@ -34,6 +34,7 @@ public:
Function<bool(u32)> 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<SnakeSkin> skin);

View file

@ -108,11 +108,12 @@ ErrorOr<int> 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();
});