aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/left_panel/GameTabLeftPanel.cpp
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-01 18:18:27 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-01 18:18:27 +0100
commit4e85af5e08b86fb32d6698836f3a227bc6f086b3 (patch)
treeef802e2c965f64830270494d94ac3f460b8a41ec /src/game_tab/left_panel/GameTabLeftPanel.cpp
parent88430eec2951290633875b0f036a33bbc6ee60a2 (diff)
Update Game tab
Diffstat (limited to 'src/game_tab/left_panel/GameTabLeftPanel.cpp')
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp62
1 files changed, 11 insertions, 51 deletions
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> 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> 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> 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<char, std::uint8_t> 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());
}