aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/left_panel/GameTabLeftPanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_tab/left_panel/GameTabLeftPanel.cpp')
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp
index 1142e99..fd89791 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.cpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp
@@ -21,6 +21,7 @@ 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:
Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY);
@@ -62,12 +63,12 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
wxLogDebug("Game tab received PLAY_MOVE_EVENT");
if (game->Play(event.GetString().ToStdString())) {
+ Notify(true);
// Notify other classes
wxCommandEvent event(GAME_CHANGE, GetId());
event.SetEventObject(this);
ProcessEvent(event);
}
- Notify(true);
}
void GameTabLeftPanel::Notify(bool skip_animation) {
@@ -78,10 +79,26 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
bool animate=false;
HalfMove *m = game->GetCurrentMove();
std::string src,dst;
+
+ // Update capture and check if we should to animations during moves change:
if (m){
captures = m->GetLineCaptures();
+ if(m->HasParent(last_move)){
+ UNPACK_ABSOLUTE_MOVE(m->GetAbsoluteMove(),src,dst);
+ animate=true;
+ }else if(m->HasChild(last_move)){
+ // Accessing last_move here is safe since it is still
+ // in the tree of moves (since HasChild found it so not deleted)
+ UNPACK_ABSOLUTE_MOVE(last_move->GetAbsoluteMove(),dst,src);
+ animate=true;
+ }
+ } else if(game->GetNextMove()){ // First move animation
+ HalfMove *next=game->GetNextMove();
+ if(next==last_move){
+ UNPACK_ABSOLUTE_MOVE(game->GetNextMove()->GetAbsoluteMove(),dst,src);
+ animate=true;
+ }
}
-
// Update board canvas:
if(skip_animation || !animate){
@@ -93,6 +110,8 @@ void GameTabLeftPanel::Notify(bool skip_animation) {
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());
}