mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09:00
Pong: Add 'New Game' action
This declares Game::reset() public and lets the menu action invoke it.
This commit is contained in:
parent
a4639fced9
commit
740beea5ce
Notes:
sideshowbarker
2024-07-19 17:06:32 +09:00
Author: https://github.com/juni2k 🔰
Commit: 740beea5ce
Pull-request: https://github.com/SerenityOS/serenity/pull/13446
2 changed files with 10 additions and 2 deletions
|
@ -28,6 +28,8 @@ public:
|
||||||
|
|
||||||
virtual ~Game() override = default;
|
virtual ~Game() override = default;
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
|
@ -37,7 +39,6 @@ private:
|
||||||
virtual void timer_event(Core::TimerEvent&) override;
|
virtual void timer_event(Core::TimerEvent&) override;
|
||||||
virtual void track_mouse_move(Gfx::IntPoint const&) override;
|
virtual void track_mouse_move(Gfx::IntPoint const&) override;
|
||||||
|
|
||||||
void reset();
|
|
||||||
void reset_ball(int serve_to_player);
|
void reset_ball(int serve_to_player);
|
||||||
void reset_paddles();
|
void reset_paddles();
|
||||||
void tick();
|
void tick();
|
||||||
|
|
|
@ -37,10 +37,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
window->set_title("Pong");
|
window->set_title("Pong");
|
||||||
window->set_double_buffering_enabled(false);
|
window->set_double_buffering_enabled(false);
|
||||||
(void)TRY(window->try_set_main_widget<Pong::Game>());
|
auto game = TRY(window->try_set_main_widget<Pong::Game>());
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
|
|
||||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||||
|
|
||||||
|
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||||
|
game->reset();
|
||||||
|
})));
|
||||||
|
|
||||||
|
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