mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +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
|
// Configure FEN field
|
||||||
fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger());
|
fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger());
|
||||||
|
|
||||||
|
last_move=game->GetCurrentMove();
|
||||||
|
|
||||||
// Bind events:
|
// Bind events:
|
||||||
Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY);
|
Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY);
|
||||||
Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Zoom(10);}, ZOOM_IN_BTN);
|
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::string fen = game->GetFen();
|
||||||
std::map<char, std::uint8_t> captures;
|
std::map<char, std::uint8_t> captures;
|
||||||
HalfMove *m = game->GetCurrentMove();
|
HalfMove *m = game->GetCurrentMove();
|
||||||
//animate=false;
|
std::string src,dst;
|
||||||
//backward=false;
|
animate=false;
|
||||||
|
backward=false;
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
captures = m->GetLineCaptures();
|
captures = m->GetLineCaptures();
|
||||||
/*HalfMove *parent=m->GetParent();
|
std::string absolute_move= m->GetAbsoluteMove();
|
||||||
if(!parent){
|
// Check if we should animate
|
||||||
|
if(m->GetParent()==last_move){
|
||||||
|
wxLogDebug("Animate animate next");
|
||||||
animate=true;
|
animate=true;
|
||||||
}
|
src=absolute_move.substr(0,2);
|
||||||
if(last_absolute_move == parent->GetAbsoluteMove()){
|
dst=absolute_move.substr(2,2);
|
||||||
wxLogDebug("Next true!");
|
} else if (m->GetMainline()==last_move){
|
||||||
animate=true;
|
wxLogDebug("Animate Previous");
|
||||||
} else if(m->GetAbsoluteMove() == last_absolute_move){
|
|
||||||
animate=true;
|
animate=true;
|
||||||
backward=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:
|
// Update board canvas:
|
||||||
if(!animate){
|
if(!animate){
|
||||||
if(m){
|
|
||||||
last_absolute_move=m->GetAbsoluteMove();
|
|
||||||
}
|
|
||||||
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
||||||
game->IsBlackToPlay(), captures,
|
game->IsBlackToPlay(), captures,
|
||||||
game->GetTag("White"),game->GetTag("Black"));
|
game->GetTag("White"),game->GetTag("Black"));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(backward && last_absolute_move.size()>0){
|
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
||||||
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,
|
|
||||||
game->IsBlackToPlay(), captures,src,dst,repeat);
|
game->IsBlackToPlay(), captures,src,dst,repeat);
|
||||||
}
|
|
||||||
}
|
|
||||||
// If m undefined
|
|
||||||
if(!m){
|
|
||||||
last_absolute_move="";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_move=m;
|
||||||
|
|
||||||
// Update fen field:
|
// Update fen field:
|
||||||
fen_text_field->SetValue(game->GetFen());
|
fen_text_field->SetValue(game->GetFen());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class GameTabLeftPanel : public TabGameLeftPanel {
|
||||||
BoardCanvas *board_canvas;
|
BoardCanvas *board_canvas;
|
||||||
std::string last_absolute_move;
|
std::string last_absolute_move;
|
||||||
bool repeat;
|
bool repeat;
|
||||||
|
HalfMove *last_move;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
||||||
|
|
Loading…
Add table
Reference in a new issue