mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Prepare for pieces animation step2
This commit is contained in:
parent
c451c63aaa
commit
7187e6d6ee
4 changed files with 22 additions and 19 deletions
|
@ -26,7 +26,7 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
|
|
||||||
void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) {
|
void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) {
|
||||||
game->Previous();
|
game->Previous();
|
||||||
Notify();
|
Notify(true);
|
||||||
NotifyEditor();
|
NotifyEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ void GameTabLeftPanel::OnSwap(wxCommandEvent &event) {
|
||||||
void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) {
|
void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) {
|
||||||
wxLogDebug("Game tab received NEXT_MOVE_EVENT");
|
wxLogDebug("Game tab received NEXT_MOVE_EVENT");
|
||||||
game->Next();
|
game->Next();
|
||||||
Notify();
|
Notify(true);
|
||||||
NotifyEditor();
|
NotifyEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,26 +59,30 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
Notify();
|
Notify();
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
if (m != NULL) {
|
if (m != NULL) {
|
||||||
captures = m->GetLineCaptures();
|
captures = m->GetLineCaptures();
|
||||||
}
|
}
|
||||||
/*board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
|
||||||
game->IsBlackToPlay(), captures,"a1","a2"); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTabLeftPanel::Notify() {
|
void GameTabLeftPanel::Notify(bool animate) {
|
||||||
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();
|
||||||
if (m != NULL) {
|
if (m != NULL) {
|
||||||
captures = m->GetLineCaptures();
|
captures = m->GetLineCaptures();
|
||||||
}
|
}
|
||||||
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
|
||||||
game->IsBlackToPlay(), captures);
|
if(!animate){
|
||||||
|
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
||||||
|
game->IsBlackToPlay(), captures);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board,
|
||||||
|
game->IsBlackToPlay(), captures,"a1","a2");
|
||||||
|
}
|
||||||
|
|
||||||
fen_text_field->SetValue(game->GetFen());
|
fen_text_field->SetValue(game->GetFen());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class GameTabLeftPanel : public TabGameLeftPanel {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
||||||
void Notify();
|
void Notify(bool animate=false);
|
||||||
void OnPlay(wxCommandEvent &event);
|
void OnPlay(wxCommandEvent &event);
|
||||||
void OnGotoMove(wxCommandEvent &event);
|
void OnGotoMove(wxCommandEvent &event);
|
||||||
void OnPreviousMove(wxCommandEvent &event);
|
void OnPreviousMove(wxCommandEvent &event);
|
||||||
|
|
|
@ -15,15 +15,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
ApplyPreferences();
|
ApplyPreferences();
|
||||||
// The following should be called when using an EVT_PAINT handler
|
// The following should be called when using an EVT_PAINT handler
|
||||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||||
timer.Bind(wxEVT_TIMER, &BoardCanvas::OnTimerTick, this);
|
timer.Bind(wxEVT_TIMER, [p=this](wxTimerEvent &e){p->Refresh();});
|
||||||
duration=500;
|
duration=500;
|
||||||
fps=30;
|
fps=30;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::OnTimerTick(wxTimerEvent &event) {
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
BoardCanvas::~BoardCanvas() {
|
BoardCanvas::~BoardCanvas() {
|
||||||
delete t;
|
delete t;
|
||||||
delete t_captures;
|
delete t_captures;
|
||||||
|
@ -64,7 +60,9 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
||||||
else {
|
else {
|
||||||
// Otherwise reuse buffer and animate. TEST CODE FOR NOW:
|
// Otherwise reuse buffer and animate. TEST CODE FOR NOW:
|
||||||
dc.DrawBitmap(*buffer, 0, 0, true);
|
dc.DrawBitmap(*buffer, 0, 0, true);
|
||||||
dc.DrawRectangle(wxRect(0+frame,0+frame,50,50));
|
// Draw piece
|
||||||
|
dc.DrawBitmap(*t->Get(piece_moved), 0+frame, 0+frame, false);
|
||||||
|
// end drawing
|
||||||
frame++;
|
frame++;
|
||||||
if(frame*fps>=duration){
|
if(frame*fps>=duration){
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
@ -105,6 +103,7 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn,
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst){
|
void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst){
|
||||||
|
return; // Shortcut this method for now
|
||||||
this->final_board=board;
|
this->final_board=board;
|
||||||
this->final_is_black_turn=is_black_turn;
|
this->final_is_black_turn=is_black_turn;
|
||||||
this->final_captures=captures;
|
this->final_captures=captures;
|
||||||
|
@ -113,7 +112,7 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char,
|
||||||
|
|
||||||
std::uint8_t pfile = src[0]-'a';
|
std::uint8_t pfile = src[0]-'a';
|
||||||
std::uint8_t prank = src[1]-'1';
|
std::uint8_t prank = src[1]-'1';
|
||||||
char piece_moved = this->board[(7 - pfile) + 8 * (7-prank)]; // Piece to move
|
this->piece_moved = this->board[(7 - pfile) + 8 * (7-prank)]; // Piece to move
|
||||||
// Animate piece here
|
// Animate piece here
|
||||||
reuseBuffer=true;
|
reuseBuffer=true;
|
||||||
frame=0;
|
frame=0;
|
||||||
|
|
|
@ -67,6 +67,7 @@ class BoardCanvas : public wxPanel {
|
||||||
std::map<char, std::uint8_t> final_captures;
|
std::map<char, std::uint8_t> final_captures;
|
||||||
std::string src;
|
std::string src;
|
||||||
std::string dst;
|
std::string dst;
|
||||||
|
char piece_moved;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoardCanvas(wxFrame *parent);
|
BoardCanvas(wxFrame *parent);
|
||||||
|
@ -79,7 +80,6 @@ public:
|
||||||
void MouseEvent(wxMouseEvent &event);
|
void MouseEvent(wxMouseEvent &event);
|
||||||
void Zoom(std::int32_t zoom);
|
void Zoom(std::int32_t zoom);
|
||||||
void Swap();
|
void Swap();
|
||||||
void OnTimerTick(wxTimerEvent &event);
|
|
||||||
void SetupBoard(std::string board, bool is_black_turn,
|
void SetupBoard(std::string board, bool is_black_turn,
|
||||||
std::map<char, std::uint8_t> captures);
|
std::map<char, std::uint8_t> captures);
|
||||||
void Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst);
|
void Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst);
|
||||||
|
|
Loading…
Add table
Reference in a new issue