1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

Solitaire: Convert Solitaire window to be created from GML

No functionial change here, but this more easily allows for adding GUI
elements to the Solitaire window. This nests the SolitaireWidget as a
child of the main window's widget so that the SolitaireWidget does not
color the entire window green when it paints its background.
This commit is contained in:
Timothy Flynn 2021-05-05 09:54:52 -04:00 committed by Andreas Kling
parent e1492e9a62
commit 0ff4eec8a8
5 changed files with 33 additions and 12 deletions

View file

@ -8,17 +8,16 @@
#include <LibGUI/Painter.h>
#include <time.h>
REGISTER_WIDGET(Solitaire, Game);
namespace Solitaire {
static const Color s_background_color { Color::from_rgb(0x008000) };
static constexpr uint8_t new_game_animation_delay = 5;
static constexpr int s_timer_interval_ms = 1000 / 60;
Game::Game(Function<void(uint32_t)>&& on_score_update)
: m_on_score_update(move(on_score_update))
Game::Game()
{
set_fill_with_background_color(false);
m_stacks[Stock] = CardStack({ 10, 10 }, CardStack::Type::Stock);
m_stacks[Waste] = CardStack({ 10 + Card::width + 10, 10 }, CardStack::Type::Waste);
m_stacks[Foundation4] = CardStack({ Game::width - Card::width - 10, 10 }, CardStack::Type::Foundation);
@ -120,7 +119,9 @@ void Game::setup()
void Game::update_score(int to_add)
{
m_score = max(static_cast<int>(m_score) + to_add, 0);
m_on_score_update(m_score);
if (on_score_update)
on_score_update(m_score);
}
void Game::keydown_event(GUI::KeyEvent& event)