mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-06 01:56:28 +02:00
Update animation trigger
This commit is contained in:
parent
679c735596
commit
0cb695a22b
2 changed files with 30 additions and 35 deletions
|
@ -22,6 +22,8 @@ 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);
|
||||
Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Zoom(10);}, ZOOM_IN_BTN);
|
||||
|
@ -77,58 +79,50 @@ void GameTabLeftPanel::Notify(bool animate, bool backward) {
|
|||
std::string fen = game->GetFen();
|
||||
std::map<char, std::uint8_t> captures;
|
||||
HalfMove *m = game->GetCurrentMove();
|
||||
//animate=false;
|
||||
//backward=false;
|
||||
std::string src,dst;
|
||||
animate=false;
|
||||
backward=false;
|
||||
if (m != nullptr) {
|
||||
captures = m->GetLineCaptures();
|
||||
/*HalfMove *parent=m->GetParent();
|
||||
if(!parent){
|
||||
std::string absolute_move= m->GetAbsoluteMove();
|
||||
// Check if we should animate
|
||||
if(m->GetParent()==last_move){
|
||||
wxLogDebug("Animate animate next");
|
||||
animate=true;
|
||||
}
|
||||
if(last_absolute_move == parent->GetAbsoluteMove()){
|
||||
wxLogDebug("Next true!");
|
||||
animate=true;
|
||||
} else if(m->GetAbsoluteMove() == last_absolute_move){
|
||||
src=absolute_move.substr(0,2);
|
||||
dst=absolute_move.substr(2,2);
|
||||
} else if (m->GetMainline()==last_move){
|
||||
wxLogDebug("Animate Previous");
|
||||
animate=true;
|
||||
backward=true;
|
||||
}*/
|
||||
src=absolute_move.substr(2,2);
|
||||
dst=absolute_move.substr(0,2);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update board canvas:
|
||||
if(!animate){
|
||||
if(m){
|
||||
last_absolute_move=m->GetAbsoluteMove();
|
||||
}
|
||||
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
||||
game->IsBlackToPlay(), captures,
|
||||
game->GetTag("White"),game->GetTag("Black"));
|
||||
}
|
||||
else{
|
||||
if(backward && last_absolute_move.size()>0){
|
||||
std::string dst=last_absolute_move.substr(0,2);
|
||||
std::string src=last_absolute_move.substr(2,2);
|
||||
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
||||
game->IsBlackToPlay(), captures,src,dst,repeat);
|
||||
if(m){
|
||||
last_absolute_move=m->GetAbsoluteMove();
|
||||
}
|
||||
}
|
||||
else if(!backward && m){
|
||||
std::string new_absolute_move=m->GetAbsoluteMove();
|
||||
if(last_absolute_move!=new_absolute_move){
|
||||
last_absolute_move=new_absolute_move;
|
||||
std::string src=last_absolute_move.substr(0,2);
|
||||
std::string dst=last_absolute_move.substr(2,2);
|
||||
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
||||
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
||||
game->IsBlackToPlay(), captures,src,dst,repeat);
|
||||
}
|
||||
}
|
||||
// If m undefined
|
||||
if(!m){
|
||||
last_absolute_move="";
|
||||
}
|
||||
}
|
||||
|
||||
last_move=m;
|
||||
|
||||
// Update fen field:
|
||||
fen_text_field->SetValue(game->GetFen());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class GameTabLeftPanel : public TabGameLeftPanel {
|
|||
BoardCanvas *board_canvas;
|
||||
std::string last_absolute_move;
|
||||
bool repeat;
|
||||
HalfMove *last_move;
|
||||
|
||||
public:
|
||||
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
||||
|
|
Loading…
Add table
Reference in a new issue