mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-06 01:56:28 +02:00
Refactoring game tab
This commit is contained in:
parent
7178f18ab8
commit
bf485fa577
16 changed files with 68 additions and 69 deletions
|
@ -11,8 +11,8 @@ GameTab::GameTab(wxFrame *parent, Game *game)
|
|||
|
||||
// Panels
|
||||
game->BuildAndVerify();
|
||||
board_panel = new BoardPanel((wxFrame *)splitter, game);
|
||||
editor_panel = new EditorPanel((wxFrame *)splitter, game);
|
||||
board_panel = new GameTabLeftPanel((wxFrame *)splitter, game);
|
||||
editor_panel = new GameTabRightPanel((wxFrame *)splitter, game);
|
||||
splitter->SplitVertically(board_panel, editor_panel);
|
||||
|
||||
// Setup splitter
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#include "ChessArbiter.hpp"
|
||||
#include "Game.hpp"
|
||||
#include "HalfMove.hpp"
|
||||
#include "board/BoardPanel.hpp"
|
||||
#include "editor/EditorPanel.hpp"
|
||||
#include "left_panel/GameTabLeftPanel.hpp"
|
||||
#include "right_panel/GameTabRightPanel.hpp"
|
||||
#include "ochess.hpp"
|
||||
#include <utility>
|
||||
#include <wx/collpane.h>
|
||||
|
@ -14,8 +14,8 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
|||
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
||||
|
||||
class GameTab : public wxPanel, public TabInfos {
|
||||
EditorPanel *editor_panel;
|
||||
BoardPanel *board_panel;
|
||||
GameTabRightPanel *editor_panel;
|
||||
GameTabLeftPanel *board_panel;
|
||||
Game *game;
|
||||
void RefreshLabel();
|
||||
void OnRefreshTabTitle(wxCommandEvent &event);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "BoardPanel.hpp"
|
||||
#include "GameTabLeftPanel.hpp"
|
||||
#include <wx/clipbrd.h>
|
||||
|
||||
BoardPanel::BoardPanel(wxFrame *parent, Game *game)
|
||||
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, Game *game)
|
||||
: wxPanel(parent), game(game) {
|
||||
|
||||
wxBoxSizer *board_panel_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
@ -21,44 +21,44 @@ BoardPanel::BoardPanel(wxFrame *parent, Game *game)
|
|||
board_panel_sizer->Add(board_panel_button_sizer, 0);
|
||||
this->SetSizer(board_panel_sizer);
|
||||
|
||||
Bind(PLAY_MOVE_EVENT, &BoardPanel::OnPlay, this, wxID_ANY);
|
||||
Bind(PREVIOUS_MOVE_EVENT, &BoardPanel::OnPreviousMove, this, wxID_ANY);
|
||||
Bind(NEXT_MOVE_EVENT, &BoardPanel::OnNextMove, this, wxID_ANY);
|
||||
Bind(wxEVT_BUTTON, &BoardPanel::OnSwap, this, SWAP_BTN);
|
||||
Bind(wxEVT_BUTTON, &BoardPanel::OnZoomIn, this, ZOOM_IN_BTN);
|
||||
Bind(wxEVT_BUTTON, &BoardPanel::OnZoomOut, this, ZOOM_OUT_BTN);
|
||||
Bind(wxEVT_BUTTON, &BoardPanel::OnCopyFEN, this, COPY_FEN_BTN);
|
||||
Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY);
|
||||
Bind(PREVIOUS_MOVE_EVENT, &GameTabLeftPanel::OnPreviousMove, this, wxID_ANY);
|
||||
Bind(NEXT_MOVE_EVENT, &GameTabLeftPanel::OnNextMove, this, wxID_ANY);
|
||||
Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnSwap, this, SWAP_BTN);
|
||||
Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnZoomIn, this, ZOOM_IN_BTN);
|
||||
Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnZoomOut, this, ZOOM_OUT_BTN);
|
||||
Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnCopyFEN, this, COPY_FEN_BTN);
|
||||
}
|
||||
|
||||
void BoardPanel::OnPreviousMove(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) {
|
||||
game->Previous();
|
||||
Notify();
|
||||
NotifyEditor();
|
||||
}
|
||||
|
||||
void BoardPanel::OnZoomIn(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnZoomIn(wxCommandEvent &event) {
|
||||
wxLogDebug("Clicked on zoom in");
|
||||
board_canvas->Zoom(10);
|
||||
}
|
||||
|
||||
void BoardPanel::OnZoomOut(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnZoomOut(wxCommandEvent &event) {
|
||||
wxLogDebug("Clicked on zoom out");
|
||||
board_canvas->Zoom(-10);
|
||||
}
|
||||
|
||||
void BoardPanel::OnSwap(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnSwap(wxCommandEvent &event) {
|
||||
wxLogDebug("Clicked on swap");
|
||||
board_canvas->Swap();
|
||||
}
|
||||
|
||||
void BoardPanel::OnNextMove(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) {
|
||||
wxLogDebug("Game tab received NEXT_MOVE_EVENT");
|
||||
game->Next();
|
||||
Notify();
|
||||
NotifyEditor();
|
||||
}
|
||||
|
||||
void BoardPanel::OnPlay(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
||||
wxLogDebug("Game tab received PLAY_MOVE_EVENT");
|
||||
if (game->Play(event.GetString().ToStdString())) {
|
||||
NotifyEditor();
|
||||
|
@ -66,7 +66,7 @@ void BoardPanel::OnPlay(wxCommandEvent &event) {
|
|||
Notify();
|
||||
}
|
||||
|
||||
void BoardPanel::OnCopyFEN(wxCommandEvent &event) {
|
||||
void GameTabLeftPanel::OnCopyFEN(wxCommandEvent &event) {
|
||||
wxLogDebug("Clicked on copy fen");
|
||||
if (wxTheClipboard->Open()) {
|
||||
wxTheClipboard->SetData(new wxTextDataObject(game->GetFen()));
|
||||
|
@ -74,7 +74,7 @@ void BoardPanel::OnCopyFEN(wxCommandEvent &event) {
|
|||
}
|
||||
}
|
||||
|
||||
void BoardPanel::Notify() {
|
||||
void GameTabLeftPanel::Notify() {
|
||||
std::string fen = game->GetFen();
|
||||
std::map<char, std::uint8_t> captures;
|
||||
HalfMove *m = game->GetCurrentMove();
|
||||
|
@ -85,12 +85,12 @@ void BoardPanel::Notify() {
|
|||
game->IsBlackToPlay(), captures);
|
||||
}
|
||||
|
||||
void BoardPanel::NotifyEditor() {
|
||||
void GameTabLeftPanel::NotifyEditor() {
|
||||
wxCommandEvent previousEvent(GAME_CHANGE, GetId());
|
||||
previousEvent.SetEventObject(this);
|
||||
ProcessEvent(previousEvent);
|
||||
}
|
||||
|
||||
void BoardPanel::ApplyPreferences() {
|
||||
void GameTabLeftPanel::ApplyPreferences() {
|
||||
board_canvas->ApplyPreferences();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Game.hpp"
|
||||
#include "BoardCanvas.hpp"
|
||||
#include "board/BoardCanvas.hpp"
|
||||
#include "ochess.hpp"
|
||||
|
||||
// Foreign events
|
||||
|
@ -9,13 +9,13 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
|||
|
||||
enum { COPY_FEN_BTN = wxID_HIGHEST + 1, ZOOM_IN_BTN, ZOOM_OUT_BTN, SWAP_BTN };
|
||||
|
||||
class BoardPanel : public wxPanel {
|
||||
class GameTabLeftPanel : public wxPanel {
|
||||
Game *game;
|
||||
BoardCanvas *board_canvas;
|
||||
void NotifyEditor();
|
||||
|
||||
public:
|
||||
BoardPanel(wxFrame *parent, Game *game);
|
||||
GameTabLeftPanel(wxFrame *parent, Game *game);
|
||||
void Notify();
|
||||
void OnPlay(wxCommandEvent &event);
|
||||
void OnGotoMove(wxCommandEvent &event);
|
|
@ -1,4 +1,4 @@
|
|||
#include "EditorPanel.hpp"
|
||||
#include "GameTabRightPanel.hpp"
|
||||
#include "LiveEngineDialog.hpp"
|
||||
|
||||
wxDEFINE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
|
||||
|
@ -8,7 +8,7 @@ wxDEFINE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent);
|
|||
wxDEFINE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent);
|
||||
wxDEFINE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent);
|
||||
|
||||
EditorPanel::EditorPanel(wxFrame *parent, Game *game)
|
||||
GameTabRightPanel::GameTabRightPanel(wxFrame *parent, Game *game)
|
||||
: TabGameRightPanel(parent), game(game), selected_item(-1) {
|
||||
editor_canvas = new EditorCanvas((wxFrame *)editor_page);
|
||||
editor_canvas_sizer->Add(editor_canvas, 1, wxEXPAND);
|
||||
|
@ -24,28 +24,28 @@ EditorPanel::EditorPanel(wxFrame *parent, Game *game)
|
|||
RefreshTagsList();
|
||||
|
||||
// Bind events
|
||||
this->Bind(wxEVT_TEXT, &EditorPanel::OnCommentChange, this,
|
||||
this->Bind(wxEVT_TEXT, &GameTabRightPanel::OnCommentChange, this,
|
||||
COMMENT_INPUT_BOX);
|
||||
this->Bind(GOTO_MOVE_EVENT, &EditorPanel::OnGotoMove, this, wxID_ANY);
|
||||
this->Bind(DELETE_MOVE_EVENT, &EditorPanel::OnMoveDelete, this, wxID_ANY);
|
||||
this->Bind(PROMOTE_MOVE_EVENT, &EditorPanel::OnMovePromote, this, wxID_ANY);
|
||||
this->Bind(SET_AS_MAINLINE_EVENT, &EditorPanel::OnMoveSetAsMainline, this,
|
||||
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, &EditorPanel::OnNextMove, this, wxID_ANY);
|
||||
this->Bind(PREVIOUS_MOVE_EVENT, &EditorPanel::OnPreviousMove, this, wxID_ANY);
|
||||
this->Bind(wxEVT_LIST_ITEM_SELECTED, &EditorPanel::OnTagSelected, this,
|
||||
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, &EditorPanel::OnTagDeselected, this,
|
||||
this->Bind(wxEVT_LIST_ITEM_DESELECTED, &GameTabRightPanel::OnTagDeselected, this,
|
||||
wxID_ANY);
|
||||
this->Bind(wxEVT_BUTTON, &EditorPanel::OnApply, this, UPDATE_BTN);
|
||||
this->Bind(wxEVT_BUTTON, &EditorPanel::OnDelete, this, DELETE_BTN);
|
||||
this->Bind(wxEVT_BUTTON, &EditorPanel::OnLiveAnalysis, this,
|
||||
this->Bind(wxEVT_BUTTON, &GameTabRightPanel::OnApply, this, UPDATE_BTN);
|
||||
this->Bind(wxEVT_BUTTON, &GameTabRightPanel::OnDelete, this, DELETE_BTN);
|
||||
this->Bind(wxEVT_BUTTON, &GameTabRightPanel::OnLiveAnalysis, this,
|
||||
LIVE_ANALYSIS_GAME_BUTTON);
|
||||
|
||||
ApplyPreferences();
|
||||
}
|
||||
|
||||
void EditorPanel::OnLiveAnalysis(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnLiveAnalysis(wxCommandEvent &event) {
|
||||
int selection = engine_list->GetSelection();
|
||||
if (selection != wxNOT_FOUND) {
|
||||
LiveEngineDialog *diag = new LiveEngineDialog(this, engine_list->GetString(selection).ToStdString());
|
||||
|
@ -54,7 +54,7 @@ void EditorPanel::OnLiveAnalysis(wxCommandEvent &event) {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPanel::OnTagSelected(wxListEvent &event) {
|
||||
void GameTabRightPanel::OnTagSelected(wxListEvent &event) {
|
||||
wxListItem item = event.GetItem();
|
||||
std::string key = item.GetText().ToStdString();
|
||||
tagTextCtrl->ChangeValue(key);
|
||||
|
@ -65,19 +65,19 @@ void EditorPanel::OnTagSelected(wxListEvent &event) {
|
|||
delete_button->Enable(true);
|
||||
}
|
||||
|
||||
void EditorPanel::OnTagDeselected(wxListEvent &event) {
|
||||
void GameTabRightPanel::OnTagDeselected(wxListEvent &event) {
|
||||
selected_item = -1;
|
||||
delete_button->Enable(false);
|
||||
}
|
||||
|
||||
void EditorPanel::NotifyBoard() {
|
||||
void GameTabRightPanel::NotifyBoard() {
|
||||
wxCommandEvent previousEvent(GAME_CHANGE, GetId());
|
||||
previousEvent.SetEventObject(this);
|
||||
ProcessEvent(previousEvent);
|
||||
}
|
||||
|
||||
void EditorPanel::OnCommentChange(wxCommandEvent &event) {
|
||||
wxLogDebug("EditorPanel: comment input change");
|
||||
void GameTabRightPanel::OnCommentChange(wxCommandEvent &event) {
|
||||
wxLogDebug("GameTabRightPanel: comment input change");
|
||||
HalfMove *m = game->GetCurrentMove();
|
||||
if (m != NULL) {
|
||||
m->SetComment(event.GetString().ToStdString());
|
||||
|
@ -85,7 +85,7 @@ void EditorPanel::OnCommentChange(wxCommandEvent &event) {
|
|||
editor_canvas->Refresh();
|
||||
}
|
||||
|
||||
void EditorPanel::OnApply(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnApply(wxCommandEvent &event) {
|
||||
std::string key = tagTextCtrl->GetValue().ToStdString();
|
||||
if (key == "FEN") {
|
||||
SHOW_DIALOG_ERROR("Editing the FEN tag is forbidden");
|
||||
|
@ -101,7 +101,7 @@ void EditorPanel::OnApply(wxCommandEvent &event) {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPanel::OnDelete(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnDelete(wxCommandEvent &event) {
|
||||
if (selected_item >= 0) {
|
||||
wxListItem item;
|
||||
item.SetColumn(0);
|
||||
|
@ -118,34 +118,34 @@ void EditorPanel::OnDelete(wxCommandEvent &event) {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPanel::OnGotoMove(wxCommandEvent &event) {
|
||||
wxLogDebug("EditorPanel: received GOTO_MOVE_EVENT");
|
||||
void GameTabRightPanel::OnGotoMove(wxCommandEvent &event) {
|
||||
wxLogDebug("GameTabRightPanel: received GOTO_MOVE_EVENT");
|
||||
game->SetCurrent((HalfMove *)event.GetClientData());
|
||||
NotifyBoard();
|
||||
editor_canvas->Refresh();
|
||||
}
|
||||
|
||||
void EditorPanel::OnMoveDelete(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnMoveDelete(wxCommandEvent &event) {
|
||||
game->DeleteMove((HalfMove *)event.GetClientData());
|
||||
NotifyBoard();
|
||||
editor_canvas->Refresh();
|
||||
}
|
||||
|
||||
void EditorPanel::OnMovePromote(wxCommandEvent &event) {
|
||||
wxLogDebug("EditorPanel: promote move called");
|
||||
void GameTabRightPanel::OnMovePromote(wxCommandEvent &event) {
|
||||
wxLogDebug("GameTabRightPanel: promote move called");
|
||||
game->PromoteMove((HalfMove *)event.GetClientData());
|
||||
NotifyBoard();
|
||||
editor_canvas->Refresh();
|
||||
}
|
||||
|
||||
void EditorPanel::OnMoveSetAsMainline(wxCommandEvent &event) {
|
||||
wxLogDebug("EditorPanel: set move as mainline called");
|
||||
void GameTabRightPanel::OnMoveSetAsMainline(wxCommandEvent &event) {
|
||||
wxLogDebug("GameTabRightPanel: set move as mainline called");
|
||||
game->SetMoveAsMainline((HalfMove *)event.GetClientData());
|
||||
NotifyBoard();
|
||||
editor_canvas->Refresh();
|
||||
}
|
||||
|
||||
void EditorPanel::Notify() {
|
||||
void GameTabRightPanel::Notify() {
|
||||
HalfMove *m = game->GetCurrentMove();
|
||||
if (m != NULL) {
|
||||
comment_input->ChangeValue(
|
||||
|
@ -154,7 +154,7 @@ void EditorPanel::Notify() {
|
|||
editor_canvas->SetMoves(game->GetMoves(), m);
|
||||
}
|
||||
|
||||
void EditorPanel::ApplyPreferences() {
|
||||
void GameTabRightPanel::ApplyPreferences() {
|
||||
engine_list->Clear();
|
||||
CONFIG_OPEN(conf);
|
||||
conf->SetPath("engines/");
|
||||
|
@ -169,7 +169,7 @@ void EditorPanel::ApplyPreferences() {
|
|||
CONFIG_CLOSE(conf);
|
||||
}
|
||||
|
||||
void EditorPanel::RefreshTagsList() {
|
||||
void GameTabRightPanel::RefreshTagsList() {
|
||||
tags_list->DeleteAllItems();
|
||||
for (std::string s : game->ListTags()) {
|
||||
long index = tags_list->InsertItem(0, s);
|
||||
|
@ -180,13 +180,13 @@ void EditorPanel::RefreshTagsList() {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorPanel::OnPreviousMove(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnPreviousMove(wxCommandEvent &event) {
|
||||
game->Previous();
|
||||
Notify();
|
||||
NotifyBoard();
|
||||
}
|
||||
|
||||
void EditorPanel::OnNextMove(wxCommandEvent &event) {
|
||||
void GameTabRightPanel::OnNextMove(wxCommandEvent &event) {
|
||||
game->Next();
|
||||
Notify();
|
||||
NotifyBoard();
|
|
@ -1,5 +1,5 @@
|
|||
#include "../Game.hpp"
|
||||
#include "EditorCanvas.hpp"
|
||||
#include "editor/EditorCanvas.hpp"
|
||||
#include "ochess.hpp"
|
||||
#include <wx/listctrl.h>
|
||||
#include <wx/notebook.h>
|
||||
|
@ -14,13 +14,13 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
|||
// Foreign events
|
||||
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
||||
|
||||
class EditorPanel : public TabGameRightPanel {
|
||||
class GameTabRightPanel : public TabGameRightPanel {
|
||||
Game *game;
|
||||
EditorCanvas *editor_canvas;
|
||||
long selected_item;
|
||||
|
||||
public:
|
||||
EditorPanel(wxFrame *parent, Game *game);
|
||||
GameTabRightPanel(wxFrame *parent, Game *game);
|
||||
void NotifyBoard();
|
||||
void Notify();
|
||||
void OnCommentChange(wxCommandEvent &event);
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "../HalfMove.hpp"
|
||||
#include "../../HalfMove.hpp"
|
||||
#include "CGEditor.hpp"
|
||||
#include "ochess.hpp"
|
||||
#include "../board/Theme.hpp"
|
||||
#include "../../left_panel/board/Theme.hpp"
|
||||
|
||||
// Foreign events
|
||||
wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
|
|
@ -1,4 +1,4 @@
|
|||
#include "game_tab/board/BoardCanvas.hpp"
|
||||
#include "game_tab/left_panel/board/BoardCanvas.hpp"
|
||||
#include "ochess.hpp"
|
||||
#include <wx/combobox.h>
|
||||
#include <wx/dir.h>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "game_tab/board/BoardCanvas.hpp"
|
||||
#include "ochess.hpp"
|
||||
#include <wx/combobox.h>
|
||||
#include <wx/dir.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue