summaryrefslogtreecommitdiff
path: root/Userland/Applications/GamesSettings
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-08-20 14:14:48 +0100
committerAndreas Kling <kling@serenityos.org>2022-08-22 12:50:41 +0200
commita01c4c50d1a6d1892ded89e57373e109a22171e0 (patch)
treec543205f72688c07bce663ec3839eaa1c4b0e573 /Userland/Applications/GamesSettings
parent0737d217cbb55aa5c7e5f8f8ef1132fb9c26550d (diff)
downloadserenity-a01c4c50d1a6d1892ded89e57373e109a22171e0.zip
GamesSettings: Introduce a new GamesSettings application :^)
This currently has exactly one setting: The background colour for card games. My thinking is, it's better to not have a Settings application for each individual game we include in the system, since most will only have a small number of settings, all Settings windows have tabs anyway, and I don't want to flood the Settings app list unnecessarily. As for having a single setting for all the card games: it's nice when things match. :^)
Diffstat (limited to 'Userland/Applications/GamesSettings')
-rw-r--r--Userland/Applications/GamesSettings/CMakeLists.txt17
-rw-r--r--Userland/Applications/GamesSettings/CardSettingsWidget.cpp29
-rw-r--r--Userland/Applications/GamesSettings/CardSettingsWidget.gml19
-rw-r--r--Userland/Applications/GamesSettings/CardSettingsWidget.h24
-rw-r--r--Userland/Applications/GamesSettings/main.cpp39
5 files changed, 128 insertions, 0 deletions
diff --git a/Userland/Applications/GamesSettings/CMakeLists.txt b/Userland/Applications/GamesSettings/CMakeLists.txt
new file mode 100644
index 0000000000..3793d46ebf
--- /dev/null
+++ b/Userland/Applications/GamesSettings/CMakeLists.txt
@@ -0,0 +1,17 @@
+serenity_component(
+ GamesSettings
+ REQUIRED
+ TARGETS GamesSettings
+)
+
+compile_gml(CardSettingsWidget.gml CardSettingsWidgetGML.h card_settings_widget_gml)
+
+set(SOURCES
+ main.cpp
+ CardSettingsWidgetGML.h
+ CardSettingsWidget.cpp
+ CardSettingsWidget.h
+ )
+
+serenity_app(GamesSettings ICON games)
+target_link_libraries(GamesSettings LibGUI LibMain)
diff --git a/Userland/Applications/GamesSettings/CardSettingsWidget.cpp b/Userland/Applications/GamesSettings/CardSettingsWidget.cpp
new file mode 100644
index 0000000000..cf13e413f3
--- /dev/null
+++ b/Userland/Applications/GamesSettings/CardSettingsWidget.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "CardSettingsWidget.h"
+#include <Applications/GamesSettings/CardSettingsWidgetGML.h>
+#include <LibConfig/Client.h>
+
+CardSettingsWidget::CardSettingsWidget()
+{
+ load_from_gml(card_settings_widget_gml);
+
+ m_background_color_input = find_descendant_of_type_named<GUI::ColorInput>("cards_background_color");
+ auto background_color = Gfx::Color::from_string(Config::read_string("Games"sv, "Cards"sv, "BackgroundColor"sv)).value_or(Gfx::Color::from_rgb(0x008000));
+ m_background_color_input->set_color(background_color, GUI::AllowCallback::No);
+ m_background_color_input->on_change = [&]() { set_modified(true); };
+}
+
+void CardSettingsWidget::apply_settings()
+{
+ Config::write_string("Games"sv, "Cards"sv, "BackgroundColor"sv, m_background_color_input->text());
+}
+
+void CardSettingsWidget::reset_default_values()
+{
+ m_background_color_input->set_color(Gfx::Color::from_rgb(0x008000));
+}
diff --git a/Userland/Applications/GamesSettings/CardSettingsWidget.gml b/Userland/Applications/GamesSettings/CardSettingsWidget.gml
new file mode 100644
index 0000000000..6cc6a6e2dd
--- /dev/null
+++ b/Userland/Applications/GamesSettings/CardSettingsWidget.gml
@@ -0,0 +1,19 @@
+@GUI::Frame {
+ fill_with_background_color: true
+ layout: @GUI::VerticalBoxLayout {
+ margins: [8]
+ }
+
+ @GUI::GroupBox {
+ title: "Background Color"
+ max_height: "shrink"
+ layout: @GUI::VerticalBoxLayout {
+ margins: [8]
+ }
+
+ @GUI::ColorInput {
+ name: "cards_background_color"
+ has_alpha_channel: false
+ }
+ }
+}
diff --git a/Userland/Applications/GamesSettings/CardSettingsWidget.h b/Userland/Applications/GamesSettings/CardSettingsWidget.h
new file mode 100644
index 0000000000..503a445eed
--- /dev/null
+++ b/Userland/Applications/GamesSettings/CardSettingsWidget.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGUI/ColorInput.h>
+#include <LibGUI/SettingsWindow.h>
+
+class CardSettingsWidget final : public GUI::SettingsWindow::Tab {
+ C_OBJECT(CardSettingsWidget)
+public:
+ virtual ~CardSettingsWidget() override = default;
+
+ virtual void apply_settings() override;
+ virtual void reset_default_values() override;
+
+private:
+ CardSettingsWidget();
+
+ RefPtr<GUI::ColorInput> m_background_color_input;
+};
diff --git a/Userland/Applications/GamesSettings/main.cpp b/Userland/Applications/GamesSettings/main.cpp
new file mode 100644
index 0000000000..6753f9355d
--- /dev/null
+++ b/Userland/Applications/GamesSettings/main.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "CardSettingsWidget.h"
+#include <LibConfig/Client.h>
+#include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
+#include <LibGUI/Application.h>
+#include <LibGUI/Icon.h>
+#include <LibGUI/SettingsWindow.h>
+#include <LibMain/Main.h>
+
+ErrorOr<int> serenity_main(Main::Arguments arguments)
+{
+ TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
+ auto app = TRY(GUI::Application::try_create(arguments));
+ Config::pledge_domain("Games");
+
+ StringView selected_tab;
+ Core::ArgsParser args_parser;
+ args_parser.add_option(selected_tab, "Tab, must be 'cards'", "open-tab", 't', "tab");
+ args_parser.parse(arguments);
+
+ TRY(Core::System::unveil("/res", "r"));
+ TRY(Core::System::unveil(nullptr, nullptr));
+
+ auto app_icon = GUI::Icon::default_icon("games"sv);
+
+ auto window = TRY(GUI::SettingsWindow::create("Games Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
+ window->set_icon(app_icon.bitmap_for_size(16));
+ (void)TRY(window->add_tab<CardSettingsWidget>("Cards"sv, "cards"sv));
+ window->set_active_tab(selected_tab);
+
+ window->show();
+ return app->exec();
+}