diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp index 8205788..32534fd 100644 --- a/src/game_tab/GameTab.cpp +++ b/src/game_tab/GameTab.cpp @@ -21,7 +21,7 @@ GameTab::GameTab(wxFrame *parent, std::shared_ptr game) // Refresh panels RefreshTabTitle(); - board_panel->Notify(false, false); + board_panel->Notify(); editor_panel->Notify(); board_panel->Bind(wxEVT_TOOL,&GameTab::OnToolClick,this); diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index 7f19480..a78eb0d 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -177,6 +177,18 @@ void HalfMove::Promote() { } } +bool HalfMove::HasChild(HalfMove *m){ + if(m!=mainline){ + for(auto var: variations){ + if(m== var){ + return(true); + } + } + return false; + } + return true; +} + bool HalfMove::IsVariation() { HalfMove *m = this; HalfMove *p = HalfMove::parent; diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 3d5177e..7bc8b22 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -45,6 +45,8 @@ public: void Promote(); /// @brief Check if current half move is within a variation bool IsVariation(); + /// @brief Return true if current moves has m as mainline or variation + bool HasChild(HalfMove *m); /// @brief Get the root of a variation HalfMove *GetRoot(); /// @brief Get parent of the current move diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 8b44e28..e986653 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -21,7 +21,6 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) // Configure FEN field fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger()); - last_move=game->GetCurrentMove(); // Bind events: @@ -33,11 +32,11 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) Bind(wxEVT_KEY_DOWN, [p=this](wxKeyEvent &e){ if(e.GetKeyCode() == WXK_RIGHT){ p->game->Next(); - p->Notify(true,false); + p->Notify(); p->repeat=true; } else if(e.GetKeyCode() == WXK_LEFT){ p->game->Previous(); - p->Notify(true,true); + p->Notify(); p->repeat=true; } // Notify other classes @@ -48,10 +47,10 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) Bind(wxEVT_MOUSEWHEEL, [p=this](wxMouseEvent& e){ if(e.GetWheelRotation()<0){ p->game->Next(); - p->Notify(true,false); + p->Notify(); }else { p->game->Previous(); - p->Notify(true,true); + p->Notify(); } // Notify other classes wxCommandEvent event(GAME_CHANGE, p->GetId()); @@ -69,71 +68,32 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { event.SetEventObject(this); ProcessEvent(event); } - // Refresh board canvas: - Notify(); } -void GameTabLeftPanel::Notify(bool animate, bool backward) { +void GameTabLeftPanel::Notify(bool skip_animation) { wxLogDebug("Called!"); // Update fen and captures std::string fen = game->GetFen(); std::map captures; + bool animate=false; HalfMove *m = game->GetCurrentMove(); std::string src,dst; - animate=false; - backward=false; - if (m != nullptr) { + if (m) captures = m->GetLineCaptures(); - // Check if we should animate - if(m->GetParent()==last_move){ - wxLogDebug("Animate animate next"); - std::string absolute_move= m->GetAbsoluteMove(); - animate=true; - src=absolute_move.substr(0,2); - dst=absolute_move.substr(2,2); - } else if (m->GetMainline()==last_move){ - wxLogDebug("Animate Previous"); - std::string absolute_move= last_move->GetAbsoluteMove(); - animate=true; - backward=true; - src=absolute_move.substr(2,2); - dst=absolute_move.substr(0,2); - } else { - std::string absolute_move= last_move->GetAbsoluteMove(); - wxLogDebug("Animate Previous"); - for(auto v: m->GetVariations()){ - if(v==last_move){ - animate=true; - backward=true; - src=absolute_move.substr(2,2); - dst=absolute_move.substr(0,2); - } - } - } - }else if(last_move!=nullptr) { - if(last_move->GetParent()==nullptr){ - wxLogDebug("Animate Previous"); - std::string absolute_move= last_move->GetAbsoluteMove(); - animate=true; - backward=true; - src=absolute_move.substr(2,2); - dst=absolute_move.substr(0,2); - } - } + // Update board canvas: - if(!animate){ + if(!skip_animation || animate){ board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, game->IsBlackToPlay(), captures, game->GetTag("White"),game->GetTag("Black")); -} + } else{ board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, game->IsBlackToPlay(), captures,src,dst,repeat); } - + // Update last move last_move=m; - // Update fen field: fen_text_field->SetValue(game->GetFen()); } diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp index e2fd7bc..5073e9c 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.hpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp @@ -17,7 +17,7 @@ class GameTabLeftPanel : public TabGameLeftPanel { public: GameTabLeftPanel(wxFrame *parent, std::shared_ptr game); - void Notify(bool animate=false,bool backward=false); + void Notify(bool skip_animation=false); void OnPlay(wxCommandEvent &event); void OnGotoMove(wxCommandEvent &event); void OnRefreshBoard(wxCommandEvent &event);