From 4e85af5e08b86fb32d6698836f3a227bc6f086b3 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 18:18:27 +0100 Subject: Update Game tab --- src/game_tab/left_panel/GameTabLeftPanel.cpp | 62 +++++----------------------- src/game_tab/left_panel/GameTabLeftPanel.hpp | 2 +- 2 files changed, 12 insertions(+), 52 deletions(-) (limited to 'src/game_tab/left_panel') 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); -- cgit v1.2.3