Skip to content

Commit

Permalink
Snake: Update snake skin color interactively while picking
Browse files Browse the repository at this point in the history
The snake now changes color while interacting with `GUI::ColorPicker`
  • Loading branch information
vkoskiv authored and alimpfard committed Jul 24, 2023
1 parent 0388bb0 commit d1f6540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Userland/Games/Snake/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Game
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);

Expand Down
9 changes: 5 additions & 4 deletions Userland/Games/Snake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit d1f6540

Please sign in to comment.