mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Chess: Automatically update and repaint when the config changes
This commit is contained in:
parent
05913b853a
commit
89d7d29d68
3 changed files with 34 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -11,10 +12,13 @@
|
|||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <LibChess/Chess.h>
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
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 };
|
||||
|
|
|
@ -27,6 +27,7 @@ ErrorOr<int> 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());
|
||||
|
|
Loading…
Add table
Reference in a new issue