From 679c735596168228ad0df4e42a3768c61c809a40 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 14:12:57 +0100 Subject: [PATCH] Improve game tab --- src/game_tab/GameTab.cpp | 1 + src/game_tab/left_panel/GameTabLeftPanel.cpp | 16 +++++- src/game_tab/left_panel/board/BoardCanvas.cpp | 9 +--- src/game_tab/left_panel/board/BoardCanvas.hpp | 6 --- .../right_panel/GameTabRightPanel.cpp | 54 +------------------ .../right_panel/GameTabRightPanel.hpp | 7 --- .../right_panel/editor/EditorCanvas.cpp | 40 ++++---------- .../right_panel/editor/EditorCanvas.hpp | 12 ++--- 8 files changed, 31 insertions(+), 114 deletions(-) diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp index 20196f3..8205788 100644 --- a/src/game_tab/GameTab.cpp +++ b/src/game_tab/GameTab.cpp @@ -57,6 +57,7 @@ void GameTab::OnGameChange(wxCommandEvent &event) { else { editor_panel->Notify(); board_panel->Notify(); + RefreshTabTitle(); } } diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 50919c0..b1bf516 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -72,14 +72,28 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { } void GameTabLeftPanel::Notify(bool animate, bool backward) { + wxLogDebug("Called!"); // Update fen and captures std::string fen = game->GetFen(); std::map captures; HalfMove *m = game->GetCurrentMove(); + //animate=false; + //backward=false; if (m != nullptr) { captures = m->GetLineCaptures(); + /*HalfMove *parent=m->GetParent(); + if(!parent){ + animate=true; + } + if(last_absolute_move == parent->GetAbsoluteMove()){ + wxLogDebug("Next true!"); + animate=true; + } else if(m->GetAbsoluteMove() == last_absolute_move){ + animate=true; + backward=true; + }*/ } - + // Update board canvas: if(!animate){ if(m){ diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 7f2c38d..1a85176 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -75,10 +75,6 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) { adata.src.y + adata.frame*(adata.transVect.y/adata.frames), false); // end drawing adata.frame++; - if(adata.frame>=adata.frames){ - adata.reuseBuffer=false; - SetupBoard(adata.final_board, adata.final_is_black_turn, adata.final_captures,white_player,black_player); - } } } @@ -116,10 +112,6 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn, } void BoardCanvas::Animate(const std::string &board, bool is_black_turn, std::map captures, std::string src, std::string dst,bool faster){ - adata.final_board=board; - adata.final_is_black_turn=is_black_turn; - adata.final_captures=captures; - std::uint8_t pfile = src[0]-'a'; std::uint8_t prank = src[1]-'1'; adata.piece_moved = this->board[pfile + 8 * (7-prank)]; // Piece to move @@ -172,6 +164,7 @@ void BoardCanvas::Animate(const std::string &board, bool is_black_turn, std::map } adata.duration=faster ? duration_backup : duration_backup; adata.reuseBuffer=false; + SetupBoard(board, is_black_turn, captures,white_player,black_player); } void BoardCanvas::DrawBoard(wxDC &dc) { diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 30f0d06..b26526f 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -50,12 +50,6 @@ typedef struct AnimState { int duration,duration_fast; /// @brief Animation FPS std::uint8_t fps; - /// @brief Board to draw at the end of the animation - std::string final_board; - /// @brief Which player is to move at the end of the animation - bool final_is_black_turn; - /// @brief Final state of captured pieces at the end of the animation - std::map final_captures; /// @brief Current animated piece char piece_moved; /// @brief Starting point of the animated piece diff --git a/src/game_tab/right_panel/GameTabRightPanel.cpp b/src/game_tab/right_panel/GameTabRightPanel.cpp index c88202b..3a46f59 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.cpp +++ b/src/game_tab/right_panel/GameTabRightPanel.cpp @@ -10,7 +10,7 @@ wxDEFINE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent); GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr game) : TabGameRightPanel(parent), game(game), selected_item(-1), live_engine(nullptr) { - editor_canvas = new EditorCanvas((wxFrame *)editor_page); + editor_canvas = new EditorCanvas((wxFrame *)editor_page,game); editor_canvas_sizer->Add(editor_canvas, 1, wxEXPAND); tags_list->InsertColumn(0, L"Name", wxLIST_FORMAT_LEFT, 200); tags_list->InsertColumn(1, L"Value", wxLIST_FORMAT_LEFT, 500); @@ -22,16 +22,6 @@ GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr game // Bind events this->Bind(wxEVT_TEXT, &GameTabRightPanel::OnCommentChange, this, COMMENT_INPUT_BOX); - this->Bind(GOTO_MOVE_EVENT, &GameTabRightPanel::OnGotoMove, this, wxID_ANY); - this->Bind(DELETE_MOVE_EVENT, &GameTabRightPanel::OnMoveDelete, this, - wxID_ANY); - this->Bind(PROMOTE_MOVE_EVENT, &GameTabRightPanel::OnMovePromote, this, - wxID_ANY); - this->Bind(SET_AS_MAINLINE_EVENT, &GameTabRightPanel::OnMoveSetAsMainline, - this, wxID_ANY); - /*this->Bind(NEXT_MOVE_EVENT, &GameTabRightPanel::OnNextMove, this, wxID_ANY); - this->Bind(PREVIOUS_MOVE_EVENT, &GameTabRightPanel::OnPreviousMove, this, - wxID_ANY);*/ this->Bind(wxEVT_LIST_ITEM_SELECTED, &GameTabRightPanel::OnTagSelected, this, wxID_ANY); this->Bind(wxEVT_LIST_ITEM_DESELECTED, &GameTabRightPanel::OnTagDeselected, @@ -90,12 +80,6 @@ void GameTabRightPanel::OnTagDeselected(wxListEvent &event) { delete_button->Enable(false); } -void GameTabRightPanel::NotifyBoard() { - wxCommandEvent previousEvent(GAME_CHANGE, GetId()); - previousEvent.SetEventObject(this); - ProcessEvent(previousEvent); -} - void GameTabRightPanel::OnLiveEngineClose(wxCloseEvent &e) { live_engine = nullptr; e.Skip(); @@ -143,29 +127,6 @@ void GameTabRightPanel::OnDelete(wxCommandEvent &event) { } } -void GameTabRightPanel::OnGotoMove(wxCommandEvent &event) { - wxLogDebug("GameTabRightPanel: received GOTO_MOVE_EVENT"); - game->SetCurrent((HalfMove *)event.GetClientData()); - Notify(); -} - -void GameTabRightPanel::OnMoveDelete(wxCommandEvent &event) { - game->DeleteMove((HalfMove *)event.GetClientData()); - Notify(); -} - -void GameTabRightPanel::OnMovePromote(wxCommandEvent &event) { - wxLogDebug("GameTabRightPanel: promote move called"); - game->PromoteMove((HalfMove *)event.GetClientData()); - Notify(); -} - -void GameTabRightPanel::OnMoveSetAsMainline(wxCommandEvent &event) { - wxLogDebug("GameTabRightPanel: set move as mainline called"); - game->SetMoveAsMainline((HalfMove *)event.GetClientData()); - Notify(); -} - void GameTabRightPanel::Notify() { HalfMove *m = game->GetCurrentMove(); if (m != nullptr) { @@ -177,7 +138,6 @@ void GameTabRightPanel::Notify() { if (live_engine != nullptr) { live_engine->SetFEN(game->GetFen()); } - NotifyBoard(); } void GameTabRightPanel::ApplyPreferences() { @@ -206,18 +166,6 @@ void GameTabRightPanel::RefreshTagsList() { } } -void GameTabRightPanel::OnPreviousMove(wxCommandEvent &event) { - game->Previous(); - Notify(); - NotifyBoard(); -} - -void GameTabRightPanel::OnNextMove(wxCommandEvent &event) { - game->Next(); - Notify(); - NotifyBoard(); -} - std::string GameTabRightPanel::GetNagFromStr(std::string str){ // TODO: Bind more NAG! if(str=="!") diff --git a/src/game_tab/right_panel/GameTabRightPanel.hpp b/src/game_tab/right_panel/GameTabRightPanel.hpp index 0a353b6..aa28f17 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.hpp +++ b/src/game_tab/right_panel/GameTabRightPanel.hpp @@ -23,20 +23,13 @@ class GameTabRightPanel : public TabGameRightPanel { public: GameTabRightPanel(wxFrame *parent, std::shared_ptr game); - void NotifyBoard(); void Notify(); void OnCommentChange(wxCommandEvent &event); - void OnGotoMove(wxCommandEvent &event); - void OnMoveDelete(wxCommandEvent &event); - void OnMovePromote(wxCommandEvent &event); - void OnMoveSetAsMainline(wxCommandEvent &event); void RefreshTagsList(); void OnTagSelected(wxListEvent &event); void OnTagDeselected(wxListEvent &event); void OnApply(wxCommandEvent &event); void OnDelete(wxCommandEvent &event); - void OnPreviousMove(wxCommandEvent &event); - void OnNextMove(wxCommandEvent &event); void OnLiveAnalysis(wxCommandEvent &event); void ApplyPreferences(); void OnLiveEngineClose(wxCloseEvent &e); diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index ae0c096..8a1c745 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -1,7 +1,7 @@ #include "EditorCanvas.hpp" -EditorCanvas::EditorCanvas(wxFrame *parent) - : wxPanel(parent), NeedRedraw(false) { +EditorCanvas::EditorCanvas(wxFrame *parent, std::shared_ptr game) + : wxPanel(parent), game(game), NeedRedraw(false) { hide_icon = LoadPNG("hide", wxSize(CGEditor::status.MoveIconWidth, CGEditor::status.MoveIconWidth)); t.ResizePieces(CGEditor::status.MoveIconWidth); @@ -173,28 +173,18 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { } } void EditorCanvas::HandleEvent(const cgeditor::Event &e) { - wxLogDebug("Editor event!"); if (e.type == cgeditor::Event::Goto) { - wxCommandEvent event(GOTO_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->SetCurrent((HalfMove *)e.move); } else if (e.type == cgeditor::Event::Delete) { - wxCommandEvent event(DELETE_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->DeleteMove((HalfMove *)e.move); } else if (e.type == cgeditor::Event::Promote) { - wxCommandEvent event(PROMOTE_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->PromoteMove((HalfMove *)e.move); } else if (e.type == cgeditor::Event::SetAsMainline) { - wxCommandEvent event(SET_AS_MAINLINE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->SetMoveAsMainline((HalfMove *)e.move); } + wxCommandEvent event(GAME_CHANGE, GetId()); + event.SetEventObject(this); + ProcessEvent(event); } void EditorCanvas::MouseEvent(wxMouseEvent &event) { @@ -234,17 +224,5 @@ void EditorCanvas::SetMoves(HalfMove *moves, HalfMove *current) { Refresh(); } -void EditorCanvas::OnKeyEvent(wxKeyEvent &event) { - /*if (event.GetKeyCode() == WXK_LEFT) { - wxCommandEvent previousEvent(PREVIOUS_MOVE_EVENT, GetId()); - previousEvent.SetEventObject(this); - ProcessEvent(previousEvent); - } else if (event.GetKeyCode() == WXK_RIGHT) { - wxCommandEvent nextEvent(NEXT_MOVE_EVENT, GetId()); - nextEvent.SetEventObject(this); - ProcessEvent(nextEvent); - }*/ -} - wxBEGIN_EVENT_TABLE(EditorCanvas, wxPanel) EVT_PAINT(EditorCanvas::OnPaint) EVT_MOUSE_EVENTS(EditorCanvas::MouseEvent) wxEND_EVENT_TABLE() diff --git a/src/game_tab/right_panel/editor/EditorCanvas.hpp b/src/game_tab/right_panel/editor/EditorCanvas.hpp index 05d6258..7ee56d3 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.hpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.hpp @@ -4,14 +4,10 @@ #include "CGEditor.hpp" #include "ochess.hpp" #include "../../left_panel/board/Theme.hpp" +#include "game_tab/Game.hpp" // Foreign events -wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent); -wxDECLARE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent); +wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); class EditorCanvas : public wxPanel, public cgeditor::CGEditor { wxPaintDC *dc; @@ -20,6 +16,7 @@ class EditorCanvas : public wxPanel, public cgeditor::CGEditor { wxBitmap hide_icon; Theme t; wxFont default_font; + std::shared_ptr game; wxColour color_scrollbar_bg; wxColour color_scrollbar; @@ -29,13 +26,12 @@ class EditorCanvas : public wxPanel, public cgeditor::CGEditor { wxColour color_menu_item_bg; public: - EditorCanvas(wxFrame *parent); + EditorCanvas(wxFrame *parent, std::shared_ptr game); void OnPaint(wxPaintEvent &event); void MouseEvent(wxMouseEvent &event); void DrawElement(const cgeditor::Element &e); void HandleEvent(const cgeditor::Event &e); void SetMoves(HalfMove *moves, HalfMove *current); - void OnKeyEvent(wxKeyEvent &event); DECLARE_EVENT_TABLE() };