diff --git a/TODO.md b/TODO.md index 22c7139..2f063cf 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ - [ ] Make PGNGameBase use GotoNextGame() instead of ParseNextGame() in the NextGame() method to improve performance - [x] Clean and debug DragNDrop in BoardCanvas - [ ] Disable the "Analyze entire game" button (Not Yet Implemented) - - [ ] Keep engine evaluation bar visible (and best move arrows) as long as the live engine dialog is open + - [x] Keep engine evaluation bar visible (and best move arrows) as long as the live engine dialog is open ## Additional Features - [x] Add a live evaluation bar to the BoardCanvas diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp index ef71048..e9ce482 100644 --- a/src/game_tab/GameTab.cpp +++ b/src/game_tab/GameTab.cpp @@ -33,6 +33,9 @@ GameTab::GameTab(wxFrame *parent, std::shared_ptr game) p->board_panel->SetEngineEvaluation(*eval); free(eval); }); + Bind(LIVE_ANALYSIS_STATUS, [p=this](wxCommandEvent &event){ + p->board_panel->SetLiveEngineState((bool)event.GetInt()); + }); } void GameTab::OnToolClick(wxCommandEvent &event){ diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 5a1ae44..c4d8764 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -2,7 +2,7 @@ #include GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) - : TabGameLeftPanel(parent), game(game), repeat(false) { + : TabGameLeftPanel(parent), game(game), repeat(false), is_engine_on(false) { // Configure toolbar (note that toolbar events are processed into the GameTab class) game_toolbar->AddTool(0, wxT("Save As"), @@ -86,20 +86,32 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { } void GameTabLeftPanel::SetEngineEvaluation(EngineEvaluation eval){ - engine_arrows.clear(); - float scale=1; - unsigned char color=0; - for(auto const &arrow: eval.best_lines){ - std::string src=arrow.substr(0,2); - std::string dst=arrow.substr(2,2); - engine_arrows.push_back({src,dst,wxColour(color,color,color),scale}); - scale=std::max(0.1,scale-0.25); - color=std::min(255,color+70); + if(is_engine_on){ + engine_arrows.clear(); + float scale=1; + unsigned char color=0; + for(auto const &arrow: eval.best_lines){ + std::string src=arrow.substr(0,2); + std::string dst=arrow.substr(2,2); + engine_arrows.push_back({src,dst,wxColour(color,color,color),scale}); + scale=std::max(0.1,scale-0.25); + color=std::min(255,color+70); + } + eval_cp=eval.eval; + Notify(true); } - eval_cp=eval.eval; - Notify(true); } +void GameTabLeftPanel::SetLiveEngineState(bool isOn){ + is_engine_on=isOn; + if(!is_engine_on){ + engine_arrows.clear(); + eval_cp=0; + Notify(true); + } +} + + void GameTabLeftPanel::Notify(bool skip_animation) { // Update fen and captures std::string fen = game->GetFen(); @@ -138,7 +150,7 @@ void GameTabLeftPanel::Notify(bool skip_animation) { gs.mat_white=game->IsCheckmate(false); gs.arrows=engine_arrows; gs.promotion=promote_on; - gs.show_evalbar=engine_arrows.size()>0; + gs.show_evalbar=is_engine_on; gs.eval=eval_cp/100; if(m){ // There should be a valid src_hl or dst_hl ortherwise it explode: diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp index d438dc6..fe4176e 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.hpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp @@ -18,6 +18,7 @@ class GameTabLeftPanel : public TabGameLeftPanel { std::string promote_on; std::string promotion_move; float eval_cp; + bool is_engine_on; public: GameTabLeftPanel(wxFrame *parent, std::shared_ptr game); @@ -28,4 +29,5 @@ public: void ApplyPreferences(); void SetSaveToolEnable(bool state){game_toolbar->EnableTool(0,state);}; void SetEngineEvaluation(EngineEvaluation eval); + void SetLiveEngineState(bool isOn); }; \ No newline at end of file diff --git a/src/game_tab/right_panel/GameTabRightPanel.cpp b/src/game_tab/right_panel/GameTabRightPanel.cpp index f421228..29f91b7 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.cpp +++ b/src/game_tab/right_panel/GameTabRightPanel.cpp @@ -1,11 +1,6 @@ #include "GameTabRightPanel.hpp" -wxDEFINE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent); -wxDEFINE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent); -wxDEFINE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent); -wxDEFINE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent); -wxDEFINE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent); -wxDEFINE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent); +wxDEFINE_EVENT(LIVE_ANALYSIS_STATUS, wxCommandEvent); GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr game) : TabGameRightPanel(parent), game(game), selected_item(-1), @@ -53,6 +48,12 @@ void GameTabRightPanel::OnLiveAnalysis(wxCommandEvent &event) { if (live_engine == nullptr) { int selection = engine_list->GetSelection(); if (selection != wxNOT_FOUND) { + // Notify about the state of the LiveEngine + wxCommandEvent notifyEvent(LIVE_ANALYSIS_STATUS,GetId()); + notifyEvent.SetEventObject(this); + notifyEvent.SetInt(1); + ProcessEvent(notifyEvent); + live_engine = new LiveEngineDialog( this, engine_list->GetString(selection).ToStdString()); live_engine->SetFEN(game->GetFen()); @@ -87,6 +88,12 @@ void GameTabRightPanel::OnTagDeselected(wxListEvent &event) { } void GameTabRightPanel::OnLiveEngineClose(wxCloseEvent &e) { + // Notify about the state of the LiveEngine + wxCommandEvent notifyEvent(LIVE_ANALYSIS_STATUS,GetId()); + notifyEvent.SetEventObject(this); + notifyEvent.SetInt(0); + ProcessEvent(notifyEvent); + // Refresh pointer live_engine = nullptr; e.Skip(); } diff --git a/src/game_tab/right_panel/GameTabRightPanel.hpp b/src/game_tab/right_panel/GameTabRightPanel.hpp index 1b94e86..903b83d 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.hpp +++ b/src/game_tab/right_panel/GameTabRightPanel.hpp @@ -7,16 +7,10 @@ #include #include -// Local events -wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); - // Foreign events wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent); +wxDECLARE_EVENT(LIVE_ANALYSIS_STATUS, wxCommandEvent); class GameTabRightPanel : public TabGameRightPanel { std::shared_ptr game;