mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
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. :^)
This commit is contained in:
parent
0737d217cb
commit
a01c4c50d1
Notes:
sideshowbarker
2024-07-17 08:04:40 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/a01c4c50d1 Pull-request: https://github.com/SerenityOS/serenity/pull/14956 Reviewed-by: https://github.com/krkk
5
Base/res/apps/GamesSettings.af
Normal file
5
Base/res/apps/GamesSettings.af
Normal file
@ -0,0 +1,5 @@
|
||||
[App]
|
||||
Name=Games Settings
|
||||
Executable=/bin/GamesSettings
|
||||
Category=Settings
|
||||
Description=Configure games
|
@ -13,6 +13,7 @@ add_subdirectory(Debugger)
|
||||
add_subdirectory(DisplaySettings)
|
||||
add_subdirectory(FileManager)
|
||||
add_subdirectory(FontEditor)
|
||||
add_subdirectory(GamesSettings)
|
||||
add_subdirectory(Help)
|
||||
add_subdirectory(HexEditor)
|
||||
add_subdirectory(ImageViewer)
|
||||
|
17
Userland/Applications/GamesSettings/CMakeLists.txt
Normal file
17
Userland/Applications/GamesSettings/CMakeLists.txt
Normal file
@ -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)
|
29
Userland/Applications/GamesSettings/CardSettingsWidget.cpp
Normal file
29
Userland/Applications/GamesSettings/CardSettingsWidget.cpp
Normal file
@ -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));
|
||||
}
|
19
Userland/Applications/GamesSettings/CardSettingsWidget.gml
Normal file
19
Userland/Applications/GamesSettings/CardSettingsWidget.gml
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
24
Userland/Applications/GamesSettings/CardSettingsWidget.h
Normal file
24
Userland/Applications/GamesSettings/CardSettingsWidget.h
Normal file
@ -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;
|
||||
};
|
39
Userland/Applications/GamesSettings/main.cpp
Normal file
39
Userland/Applications/GamesSettings/main.cpp
Normal file
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user