diff --git a/TODO.md b/TODO.md index 2f063cf..b908670 100644 --- a/TODO.md +++ b/TODO.md @@ -19,4 +19,5 @@ - [ ] Be able to play against an engine - [ ] Implement full chess engine game analyzer/annotator - [ ] Handle .si4 databases - - [ ] Implement a page system for large databases (load massive databases per pages instead of entirely) \ No newline at end of file + - [ ] Implement a page system for large databases (load massive databases per pages instead of entirely) + - [ ] Add a tool in the toolbar of GameTabLeftPanel to run the live engine analysis using the last engine \ No newline at end of file diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7a8c27f..e379319 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -78,7 +78,7 @@ void MainWindow::OnAuiNotebookPageCheck(wxAuiNotebookEvent& event){ } void MainWindow::AddPage(wxWindow* window, TabInfos* infos){ - window->SetClientData(infos); + window->SetClientData(infos); // Allows to have safer cast in this class notebook->AddPage(window, window->GetLabel()); notebook->SetSelection(notebook->GetPageIndex(window)); // Refresh tab that require knowledge on other tabs @@ -121,10 +121,9 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) { for (wxMenuItem *item : items) { if (item->GetId() == id) { wxLogDebug("Selected %s", item->GetItemLabel()); - EngineTab *bt = new EngineTab((wxWindow *)notebook, + EngineTab *et = new EngineTab((wxWindow *)notebook, item->GetItemLabel().ToStdString()); - notebook->AddPage(bt, bt->GetLabel()); - notebook->SetSelection(notebook->GetPageIndex(bt)); + AddPage(et,et); } } } else if (id == 1) { // Settings @@ -185,7 +184,7 @@ void MainWindow::OnRefreshEngineList(wxCommandEvent &event) { } while (conf->GetNextGroup(engine_name, index)); } CONFIG_CLOSE(conf); - ApplyPreferences(); // Propagate motifications + ApplyPreferences(); // Propagate informations to the tabs that require it } void MainWindow::NewEngine() { @@ -257,7 +256,7 @@ void MainWindow::OnPageChange(wxAuiNotebookEvent &event) { } void MainWindow::OnRefreshTabTitle(wxCommandEvent &event) { - GameTab *win = dynamic_cast(event.GetEventObject()); + GameTab *win = (GameTab*)event.GetEventObject(); int page = notebook->GetPageIndex(win); if (page != wxNOT_FOUND) { notebook->SetPageText(page, win->GetLabel()); diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp index 91886ee..1f82218 100644 --- a/src/engine_tab/EngineTab.cpp +++ b/src/engine_tab/EngineTab.cpp @@ -27,6 +27,7 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine, Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON); Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON); + Bind(wxEVT_PG_CHANGED, [p=this](wxPropertyGridEvent& event){p->is_dirty=true;}); } EngineTab::EngineTab(wxWindow *parent, std::string name) @@ -107,6 +108,12 @@ void EngineTab::OnSave(wxCommandEvent &event) { engineName = new_engine_name; confGroup = "engines/" + engineName; conf2->SetPath(".."); + SetLabel(new_engine_name); + // First refresh tab title + wxCommandEvent refreshTitle(REFRESH_TAB_TITLE, GetId()); + refreshTitle.SetEventObject(this); + wxLogDebug("New engine name is %s",this->GetLabel()); + ProcessEvent(refreshTitle); } long index; std::string optsPath = confGroup + "/options"; @@ -128,6 +135,7 @@ void EngineTab::OnSave(wxCommandEvent &event) { } while (conf2->GetNextGroup(opt_name, index)); } CONFIG_CLOSE(conf2); + // Notify all other tabs about this new configuration RefreshItemList(); } diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp index 0daa404..711c3c7 100644 --- a/src/engine_tab/EngineTab.hpp +++ b/src/engine_tab/EngineTab.hpp @@ -4,6 +4,7 @@ // Foreign event wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent); wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent); +wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); class EngineTab : public TabEngine, public TabInfos { uciadapter::UCI *engine; diff --git a/src/game_tab/Game.hpp b/src/game_tab/Game.hpp index ddf5cf6..6f9bbb7 100644 --- a/src/game_tab/Game.hpp +++ b/src/game_tab/Game.hpp @@ -5,13 +5,19 @@ #include "ochess.hpp" #include +/** + * @brief Hold an entire chess game + * Used in many places in the projects. + */ class Game { + /// @brief 64 char string that contains all the pieces on the board (used in BoardCanvas) std::string board; std::string initial_fen; std::string result; std::unordered_map tags; HalfMove *moves; HalfMove *current; + /// @brief Used by various methods of the class chessarbiter::ChessArbiter arbiter; public: @@ -29,12 +35,15 @@ public: HalfMove *GetMoves(); std::string GetFen(); std::string GetResult(); + /// @brief Play the given absolute move bool Play(std::string move,char promotion='q'); bool IsBlackToPlay(); bool IsCheckmate(bool forBlack); + /// @brief Check if a given absolute move consists in a pawn promotion bool IsPromotionMove(std::string absolute_move); void Previous(); void Next(); + /// @brief Delete a move (its mainline and variations recursively) void DeleteMove(HalfMove *m); void PromoteMove(HalfMove *m); void SetMoveAsMainline(HalfMove *m); diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 9775c3e..0666f38 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -7,11 +7,7 @@ #include /** - * @brief Create your custom half move class - * - * The implementation of the class should give you - * an overview of how to keep your move sync with the one of CGEditor - * + * @brief This class extends CGEHalfMove (to be displayed in the game editor) */ class HalfMove : public cgeditor::CGEHalfMove { HalfMove *parent = nullptr; @@ -19,8 +15,10 @@ class HalfMove : public cgeditor::CGEHalfMove { chessarbiter::ChessArbiter arbiter; std::vector variations; std::string fen; + /// @brief Used in to retrieve captured pieces (see GetLineCaptures()) char capture; void BuildAndVerify(HalfMove *m, std::string fen); + /// @brief Store the source and destination square of the current move (mainly used for pieces animation) std::string src,dst; public: diff --git a/src/game_tab/right_panel/LiveEngineDialog.hpp b/src/game_tab/right_panel/LiveEngineDialog.hpp index fa4ea83..b7be674 100644 --- a/src/game_tab/right_panel/LiveEngineDialog.hpp +++ b/src/game_tab/right_panel/LiveEngineDialog.hpp @@ -16,6 +16,7 @@ class LiveEngineDialog : public DialogLiveEngine { uciadapter::UCI *engine; std::string engine_name; wxTimer timer; + /// @brief The following time interval definitely need to be configure in the user settings (set to 1s for now) std::uint32_t interval; public: