1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

2048: Convert to GML

This commit is contained in:
implicitfield 2022-10-17 20:03:09 +03:00 committed by Linus Groh
parent a6ba82fc49
commit 5d77daebf3
5 changed files with 125 additions and 44 deletions

View file

@ -12,6 +12,7 @@
#include <LibGUI/CheckBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/SpinBox.h>
#include <Userland/Games/2048/GameSizeDialogGML.h>
GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t target, bool evil_ai)
: GUI::Dialog(parent)
@ -25,59 +26,43 @@ GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t ta
set_resizable(false);
auto& main_widget = set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
if (!main_widget.load_from_gml(game_size_dialog_gml))
VERIFY_NOT_REACHED();
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
layout.set_margins(4);
auto board_size_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("board_size_spinbox");
board_size_spinbox->set_value(m_board_size);
auto& board_size_box = main_widget.add<GUI::Widget>();
auto& input_layout = board_size_box.set_layout<GUI::HorizontalBoxLayout>();
input_layout.set_spacing(4);
auto tile_value_label = main_widget.find_descendant_of_type_named<GUI::Label>("tile_value_label");
tile_value_label->set_text(String::number(target_tile()));
auto target_spinbox = main_widget.find_descendant_of_type_named<GUI::SpinBox>("target_spinbox");
target_spinbox->set_max(Game::max_power_for_board(m_board_size));
target_spinbox->set_value(m_target_tile_power);
board_size_box.add<GUI::Label>("Board size").set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto& spinbox = board_size_box.add<GUI::SpinBox>();
auto& target_box = main_widget.add<GUI::Widget>();
auto& target_layout = target_box.set_layout<GUI::HorizontalBoxLayout>();
target_layout.set_spacing(4);
spinbox.set_min(2);
spinbox.set_value(m_board_size);
target_box.add<GUI::Label>("Target tile").set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto& tile_value_label = target_box.add<GUI::Label>(String::number(target_tile()));
tile_value_label.set_text_alignment(Gfx::TextAlignment::CenterRight);
auto& target_spinbox = target_box.add<GUI::SpinBox>();
target_spinbox.set_max(Game::max_power_for_board(m_board_size));
target_spinbox.set_min(3);
target_spinbox.set_value(m_target_tile_power);
spinbox.on_change = [&](auto value) {
board_size_spinbox->on_change = [this, target_spinbox](auto value) {
m_board_size = value;
target_spinbox.set_max(Game::max_power_for_board(m_board_size));
target_spinbox->set_max(Game::max_power_for_board(m_board_size));
};
target_spinbox.on_change = [&](auto value) {
target_spinbox->on_change = [this, tile_value_label](auto value) {
m_target_tile_power = value;
tile_value_label.set_text(String::number(target_tile()));
tile_value_label->set_text(String::number(target_tile()));
};
auto& evil_ai_checkbox = main_widget.add<GUI::CheckBox>("Evil AI");
evil_ai_checkbox.set_checked(m_evil_ai);
evil_ai_checkbox.on_checked = [this](auto checked) { m_evil_ai = checked; };
auto evil_ai_checkbox = main_widget.find_descendant_of_type_named<GUI::CheckBox>("evil_ai_checkbox");
evil_ai_checkbox->set_checked(m_evil_ai);
evil_ai_checkbox->on_checked = [this](auto checked) { m_evil_ai = checked; };
auto& temp_checkbox = main_widget.add<GUI::CheckBox>("Temporarily apply changes");
temp_checkbox.set_checked(m_temporary);
temp_checkbox.on_checked = [this](auto checked) { m_temporary = checked; };
auto temporary_checkbox = main_widget.find_descendant_of_type_named<GUI::CheckBox>("temporary_checkbox");
temporary_checkbox->set_checked(m_temporary);
temporary_checkbox->on_checked = [this](auto checked) { m_temporary = checked; };
auto& buttonbox = main_widget.add<GUI::Widget>();
auto& button_layout = buttonbox.set_layout<GUI::HorizontalBoxLayout>();
button_layout.set_spacing(10);
buttonbox.add<GUI::Button>("Cancel").on_click = [this](auto) {
auto cancel_button = main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button->on_click = [this](auto) {
done(ExecResult::Cancel);
};
buttonbox.add<GUI::Button>("OK").on_click = [this](auto) {
auto ok_button = main_widget.find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button->on_click = [this](auto) {
done(ExecResult::OK);
};
}