diff options
Diffstat (limited to 'src/game_tab/left_panel/GameTabLeftPanel.cpp')
| -rw-r--r-- | src/game_tab/left_panel/GameTabLeftPanel.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 65d77f0..cfe0de8 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -25,7 +25,6 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game) // Bind events: Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY); - Bind(PLAY_PROMOTE, &GameTabLeftPanel::OnPromote,this); 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_OUT_BTN); Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Swap();}, SWAP_BTN); @@ -60,19 +59,28 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game) }); } -void GameTabLeftPanel::OnPromote(wxCommandEvent &event){ - char piece=event.GetString()[0]; - wxLogDebug("Promote to %c",piece); -} - void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { std::string move=event.GetString().ToStdString(); - if (game->Play(move)) { - // Notify other classes - wxCommandEvent event(GAME_CHANGE, GetId()); - event.SetEventObject(this); - ProcessEvent(event); + int size=move.size(); + char promote=(char)event.GetInt(); + // First check if it is a promotion move (to prompt the user for a piece) + if(size>0 && game->IsPromotionMove(move)){ + promote_on=move.substr(2,2); // Will trigger the piece prompt on next Notify() + promotion_move=move; // Save the move that should be played for the promotion + } else { + if(size==0){ // It is a promotion move? + move=promotion_move; // Play the save promotion move + promote_on.clear(); // Clear user prompte (cf. Notify()) + promotion_move.clear(); + } + if(game->Play(move,promote)){ + // Notify other classes + wxCommandEvent event(GAME_CHANGE, GetId()); + event.SetEventObject(this); + ProcessEvent(event); + } } + Notify(true); // Redraw event is move failed! Otherwise piece not resets to it initial position after dragging } @@ -127,6 +135,7 @@ void GameTabLeftPanel::Notify(bool skip_animation) { gs.mat_black=game->IsCheckmate(true); gs.mat_white=game->IsCheckmate(false); gs.arrows=engine_arrows; + gs.promotion=promote_on; if(m){ // There should be a valid src_hl or dst_hl ortherwise it explode: std::string src_hl, dst_hl; |
