Hearts: Port to GML compiler
This commit is contained in:
parent
27339fe6e7
commit
343d6b001f
Notes:
sideshowbarker
2024-07-16 20:31:50 +09:00
Author: https://github.com/notSanil 🔰 Commit: https://github.com/SerenityOS/serenity/commit/343d6b001f Pull-request: https://github.com/SerenityOS/serenity/pull/22648 Reviewed-by: https://github.com/kemzeb Reviewed-by: https://github.com/timschumi ✅
5 changed files with 30 additions and 13 deletions
Userland/Games/Hearts
|
@ -5,7 +5,7 @@ serenity_component(
|
|||
TARGETS Hearts
|
||||
)
|
||||
|
||||
stringify_gml(Hearts.gml HeartsGML.h hearts_gml)
|
||||
compile_gml(Hearts.gml HeartsGML.cpp)
|
||||
|
||||
set(SOURCES
|
||||
Game.cpp
|
||||
|
@ -13,10 +13,7 @@ set(SOURCES
|
|||
Player.cpp
|
||||
ScoreCard.cpp
|
||||
SettingsDialog.cpp
|
||||
)
|
||||
|
||||
set(GENERATED_SOURCES
|
||||
HeartsGML.h
|
||||
HeartsGML.cpp
|
||||
)
|
||||
|
||||
serenity_app(Hearts ICON app-hearts)
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
REGISTER_WIDGET(Hearts, Game);
|
||||
|
||||
namespace Hearts {
|
||||
|
||||
Game::Game()
|
||||
|
@ -598,7 +596,7 @@ void Game::play_card(Player& player, size_t card_index)
|
|||
card->set_upside_down(false);
|
||||
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 + 15, height / 2 - Card::height / 2 - 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
|
||||
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 "MainWidget.h"
|
||||
#include "SettingsDialog.h"
|
||||
#include <AK/URL.h>
|
||||
#include <Games/Hearts/HeartsGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibCore/Timer.h>
|
||||
|
@ -25,7 +25,6 @@
|
|||
#include <LibGUI/Statusbar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <stdio.h>
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
|
@ -50,8 +49,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = GUI::Window::construct();
|
||||
window->set_title("Hearts");
|
||||
|
||||
auto widget = window->set_main_widget<GUI::Widget>();
|
||||
TRY(widget->load_from_gml(hearts_gml));
|
||||
auto widget = TRY(Hearts::MainWidget::try_create());
|
||||
window->set_main_widget(widget);
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Hearts::Game>("game");
|
||||
game.set_focus(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue