mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
Hearts: Port to GML compiler
This commit is contained in:
parent
27339fe6e7
commit
343d6b001f
5 changed files with 30 additions and 13 deletions
|
@ -5,7 +5,7 @@ serenity_component(
|
||||||
TARGETS Hearts
|
TARGETS Hearts
|
||||||
)
|
)
|
||||||
|
|
||||||
stringify_gml(Hearts.gml HeartsGML.h hearts_gml)
|
compile_gml(Hearts.gml HeartsGML.cpp)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
Game.cpp
|
Game.cpp
|
||||||
|
@ -13,10 +13,7 @@ set(SOURCES
|
||||||
Player.cpp
|
Player.cpp
|
||||||
ScoreCard.cpp
|
ScoreCard.cpp
|
||||||
SettingsDialog.cpp
|
SettingsDialog.cpp
|
||||||
)
|
HeartsGML.cpp
|
||||||
|
|
||||||
set(GENERATED_SOURCES
|
|
||||||
HeartsGML.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(Hearts ICON app-hearts)
|
serenity_app(Hearts ICON app-hearts)
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
#include <LibGfx/Font/Font.h>
|
#include <LibGfx/Font/Font.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
REGISTER_WIDGET(Hearts, Game);
|
|
||||||
|
|
||||||
namespace Hearts {
|
namespace Hearts {
|
||||||
|
|
||||||
Game::Game()
|
Game::Game()
|
||||||
|
@ -598,7 +596,7 @@ void Game::play_card(Player& player, size_t card_index)
|
||||||
card->set_upside_down(false);
|
card->set_upside_down(false);
|
||||||
m_trick.append(*card);
|
m_trick.append(*card);
|
||||||
|
|
||||||
const Gfx::IntPoint trick_card_positions[] = {
|
Gfx::IntPoint const trick_card_positions[] = {
|
||||||
{ width / 2 - Card::width / 2, height / 2 - 30 },
|
{ width / 2 - Card::width / 2, height / 2 - 30 },
|
||||||
{ width / 2 - Card::width + 15, height / 2 - Card::height / 2 - 15 },
|
{ width / 2 - Card::width + 15, height / 2 - Card::height / 2 - 15 },
|
||||||
{ width / 2 - Card::width / 2 + 15, height / 2 - Card::height + 15 },
|
{ width / 2 - Card::width / 2 + 15, height / 2 - Card::height + 15 },
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@GUI::Widget {
|
@Hearts::MainWidget {
|
||||||
fill_with_background_color: true
|
fill_with_background_color: true
|
||||||
layout: @GUI::VerticalBoxLayout {}
|
layout: @GUI::VerticalBoxLayout {}
|
||||||
|
|
||||||
|
|
23
Userland/Games/Hearts/MainWidget.h
Normal file
23
Userland/Games/Hearts/MainWidget.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
|
namespace Hearts {
|
||||||
|
|
||||||
|
class MainWidget : public GUI::Widget {
|
||||||
|
C_OBJECT_ABSTRACT(MainWidget)
|
||||||
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<MainWidget>> try_create();
|
||||||
|
virtual ~MainWidget() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MainWidget() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -8,9 +8,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "MainWidget.h"
|
||||||
#include "SettingsDialog.h"
|
#include "SettingsDialog.h"
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <Games/Hearts/HeartsGML.h>
|
|
||||||
#include <LibConfig/Client.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
|
@ -25,7 +25,6 @@
|
||||||
#include <LibGUI/Statusbar.h>
|
#include <LibGUI/Statusbar.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
|
@ -50,8 +49,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto window = GUI::Window::construct();
|
auto window = GUI::Window::construct();
|
||||||
window->set_title("Hearts");
|
window->set_title("Hearts");
|
||||||
|
|
||||||
auto widget = window->set_main_widget<GUI::Widget>();
|
auto widget = TRY(Hearts::MainWidget::try_create());
|
||||||
TRY(widget->load_from_gml(hearts_gml));
|
window->set_main_widget(widget);
|
||||||
|
|
||||||
auto& game = *widget->find_descendant_of_type_named<Hearts::Game>("game");
|
auto& game = *widget->find_descendant_of_type_named<Hearts::Game>("game");
|
||||||
game.set_focus(true);
|
game.set_focus(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue