From 17b77792717f7d77a6740c04a6ec97733aa0892a Mon Sep 17 00:00:00 2001 From: lucastarche Date: Sat, 27 Mar 2021 18:07:52 -0300 Subject: [PATCH] Chess: Added option to toggle showing moves --- Userland/Games/Chess/ChessWidget.h | 3 +++ Userland/Games/Chess/main.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/Userland/Games/Chess/ChessWidget.h b/Userland/Games/Chess/ChessWidget.h index c2d4320cce..5b4008d88d 100644 --- a/Userland/Games/Chess/ChessWidget.h +++ b/Userland/Games/Chess/ChessWidget.h @@ -66,6 +66,9 @@ public: void set_drag_enabled(bool e) { m_drag_enabled = e; } RefPtr get_piece_graphic(const Chess::Piece& piece) const; + bool show_available_moves() const { return m_show_available_moves; } + void set_show_available_moves(bool e) { m_show_available_moves = e; } + String get_fen() const; bool import_pgn(const StringView& import_path); bool export_pgn(const StringView& export_path) const; diff --git a/Userland/Games/Chess/main.cpp b/Userland/Games/Chess/main.cpp index 2cf90b73e9..c2a3a2de78 100644 --- a/Userland/Games/Chess/main.cpp +++ b/Userland/Games/Chess/main.cpp @@ -94,6 +94,7 @@ int main(int argc, char** argv) widget.set_piece_set(config->read_entry("Style", "PieceSet", "stelar7")); widget.set_board_theme(config->read_entry("Style", "BoardTheme", "Beige")); widget.set_coordinates(config->read_bool_entry("Style", "Coordinates", true)); + widget.set_show_available_moves(config->read_bool_entry("Style", "ShowAvailableMoves", true)); auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Game"); @@ -199,6 +200,15 @@ int main(int argc, char** argv) coordinates_action->set_checked(widget.coordinates()); style_menu.add_action(coordinates_action); + auto show_available_moves_action = GUI::Action::create_checkable("Show Available Moves", [&](auto& action) { + widget.set_show_available_moves(action.is_checked()); + widget.update(); + config->write_bool_entry("Style", "ShowAvailableMoves", action.is_checked()); + config->sync(); + }); + show_available_moves_action->set_checked(widget.show_available_moves()); + style_menu.add_action(show_available_moves_action); + auto& engine_menu = menubar->add_menu("Engine"); GUI::ActionGroup engines_action_group;