mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
GamesSettings: Add a setting for the card-back image
And also add a couple of images so there's more than one option. :^) (My yak silhouette isn't very good, so please replace that, artists!)
This commit is contained in:
parent
435e53fcfe
commit
deeef8c412
6 changed files with 49 additions and 1 deletions
BIN
Base/res/icons/cards/ladyball-deck.png
Normal file
BIN
Base/res/icons/cards/ladyball-deck.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
Base/res/icons/cards/yak-deck.png
Normal file
BIN
Base/res/icons/cards/yak-deck.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -7,6 +7,9 @@
|
|||
#include "CardSettingsWidget.h"
|
||||
#include <Applications/GamesSettings/CardSettingsWidgetGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGUI/FileSystemModel.h>
|
||||
|
||||
static constexpr StringView default_card_back_image_path = "/res/icons/cards/buggie-deck.png"sv;
|
||||
|
||||
CardSettingsWidget::CardSettingsWidget()
|
||||
{
|
||||
|
@ -16,14 +19,43 @@ CardSettingsWidget::CardSettingsWidget()
|
|||
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); };
|
||||
|
||||
m_card_back_image_view = find_descendant_of_type_named<GUI::IconView>("cards_back_image");
|
||||
m_card_back_image_view->set_model(GUI::FileSystemModel::create("/res/icons/cards"));
|
||||
m_card_back_image_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
||||
if (!set_card_back_image_path(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv)))
|
||||
set_card_back_image_path(default_card_back_image_path);
|
||||
m_card_back_image_view->on_selection_change = [&]() {
|
||||
if (m_card_back_image_view->selection().is_empty())
|
||||
return;
|
||||
set_modified(true);
|
||||
};
|
||||
}
|
||||
|
||||
void CardSettingsWidget::apply_settings()
|
||||
{
|
||||
Config::write_string("Games"sv, "Cards"sv, "BackgroundColor"sv, m_background_color_input->text());
|
||||
Config::write_string("Games"sv, "Cards"sv, "CardBackImage"sv, card_back_image_path());
|
||||
}
|
||||
|
||||
void CardSettingsWidget::reset_default_values()
|
||||
{
|
||||
m_background_color_input->set_color(Gfx::Color::from_rgb(0x008000));
|
||||
set_card_back_image_path(default_card_back_image_path);
|
||||
}
|
||||
|
||||
bool CardSettingsWidget::set_card_back_image_path(String const& path)
|
||||
{
|
||||
auto index = static_cast<GUI::FileSystemModel*>(m_card_back_image_view->model())->index(path, m_card_back_image_view->model_column());
|
||||
if (index.is_valid()) {
|
||||
m_card_back_image_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String CardSettingsWidget::card_back_image_path() const
|
||||
{
|
||||
auto card_back_image_index = m_card_back_image_view->selection().first();
|
||||
return static_cast<GUI::FileSystemModel const*>(m_card_back_image_view->model())->full_path(card_back_image_index);
|
||||
}
|
||||
|
|
|
@ -16,4 +16,15 @@
|
|||
has_alpha_channel: false
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::GroupBox {
|
||||
title: "Card Back"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [8]
|
||||
}
|
||||
|
||||
@GUI::IconView {
|
||||
name: "cards_back_image"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/ColorInput.h>
|
||||
#include <LibGUI/IconView.h>
|
||||
#include <LibGUI/SettingsWindow.h>
|
||||
|
||||
class CardSettingsWidget final : public GUI::SettingsWindow::Tab {
|
||||
|
@ -20,5 +21,9 @@ public:
|
|||
private:
|
||||
CardSettingsWidget();
|
||||
|
||||
bool set_card_back_image_path(String const&);
|
||||
String card_back_image_path() const;
|
||||
|
||||
RefPtr<GUI::ColorInput> m_background_color_input;
|
||||
RefPtr<GUI::IconView> m_card_back_image_view;
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix"));
|
||||
TRY(Core::System::pledge("stdio rpath recvfd sendfd unix thread"));
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
Config::pledge_domain("Games");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue