From 89d7d29d68afe071531e8675ac28041052dc2cf5 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 1 Feb 2023 21:33:31 +0000 Subject: [PATCH] Chess: Automatically update and repaint when the config changes --- Userland/Games/Chess/ChessWidget.cpp | 25 +++++++++++++++++++++++++ Userland/Games/Chess/ChessWidget.h | 9 ++++++++- Userland/Games/Chess/main.cpp | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp index 9cab866254..6606a58c5d 100644 --- a/Userland/Games/Chess/ChessWidget.cpp +++ b/Userland/Games/Chess/ChessWidget.cpp @@ -699,3 +699,28 @@ int ChessWidget::resign() return 0; } + +void ChessWidget::config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value) +{ + if (domain != "Games"sv && group != "Chess"sv) + return; + + if (key == "PieceSet"sv) { + set_piece_set(value); + update(); + } else if (key == "BoardTheme"sv) { + set_board_theme(value); + update(); + } +} + +void ChessWidget::config_bool_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value) +{ + if (domain != "Games"sv && group != "Chess"sv) + return; + + if (key == "ShowCoordinates"sv) { + set_coordinates(value); + update(); + } +} diff --git a/Userland/Games/Chess/ChessWidget.h b/Userland/Games/Chess/ChessWidget.h index e0c5eb7a27..9550e11995 100644 --- a/Userland/Games/Chess/ChessWidget.h +++ b/Userland/Games/Chess/ChessWidget.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2022, the SerenityOS developers. + * Copyright (c) 2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,10 +12,13 @@ #include #include #include +#include #include #include -class ChessWidget final : public GUI::Frame { +class ChessWidget final + : public GUI::Frame + , public Config::Listener { C_OBJECT(ChessWidget); public: @@ -107,6 +111,9 @@ public: private: ChessWidget(); + virtual void config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value) override; + virtual void config_bool_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value) override; + Chess::Board m_board; Chess::Board m_board_playback; bool m_playback { false }; diff --git a/Userland/Games/Chess/main.cpp b/Userland/Games/Chess/main.cpp index c9bde1d7a6..830eec9bd8 100644 --- a/Userland/Games/Chess/main.cpp +++ b/Userland/Games/Chess/main.cpp @@ -27,6 +27,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::try_create(arguments)); Config::pledge_domain("Games"); + Config::monitor_domain("Games"); TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man6/Chess.md") })); TRY(Desktop::Launcher::seal_allowlist());