From 4adb5ff056d4a5a35cd7f76a9785c5cab57fdc03 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 25 Feb 2022 09:21:26 +0100 Subject: [PATCH] Improve game base panel --- src/MainWindow.cpp | 30 +- src/base_tab/BasePanelBF.cpp | 31 +- src/base_tab/BasePanelBF.h | 12 +- src/base_tab/BaseTab.cpp | 15 +- src/base_tab/BaseTab.hpp | 3 +- tools/wxframebuilder/BasePanel.fbp | 508 ++++++++++++++++++++--------- 6 files changed, 401 insertions(+), 198 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5c1a87f..afca91e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -51,12 +51,6 @@ MainWindow::MainWindow() notebook = new wxAuiNotebook(this, wxID_ANY); NewGame(new Game()); - // Test base tab - BaseTab *bt = new BaseTab((wxFrame *)notebook); - bt->SetLabel("New Base"); - notebook->AddPage(bt, bt->GetLabel()); - notebook->SetSelection(notebook->GetPageIndex(bt)); - Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this, wxID_ANY); Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); @@ -112,26 +106,10 @@ void MainWindow::OnOpen(wxCommandEvent &event) { wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (openFileDialog.ShowModal() != wxID_CANCEL) { std::string path = openFileDialog.GetPath().ToStdString(); - pgnp::PGN pgn; - try { - pgn.FromFile(path); - pgn.ParseNextGame(); - pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove(); - pgn.GetMoves(pgnp_moves); - std::string fen = - "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; - if (pgn.HasTag("FEN")) { - fen = pgn.GetTagValue("FEN"); - } - HalfMove *m = new HalfMove(pgnp_moves, fen); - Game *g = new Game(m, fen); - for (std::string &s : pgn.GetTagList()) { - g->SetTag(s, pgn.GetTagValue(s)); - } - NewGame(g); - } catch (std::exception &e) { - SHOW_DIALOG_ERROR("Invalid PGN file: " + std::string(e.what())); - } + // Test base tab + BaseTab *bt = new BaseTab((wxFrame *)notebook, path); + notebook->AddPage(bt, bt->GetLabel()); + notebook->SetSelection(notebook->GetPageIndex(bt)); } } diff --git a/src/base_tab/BasePanelBF.cpp b/src/base_tab/BasePanelBF.cpp index c6b8381..e179ec0 100644 --- a/src/base_tab/BasePanelBF.cpp +++ b/src/base_tab/BasePanelBF.cpp @@ -17,13 +17,8 @@ BasePanelBF::BasePanelBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c wxBoxSizer* top_sizer; top_sizer = new wxBoxSizer( wxHORIZONTAL ); - current_base_label = new wxStaticText( this, wxID_ANY, wxT("Current base:"), wxDefaultPosition, wxDefaultSize, 0 ); - current_base_label->Wrap( -1 ); - top_sizer->Add( current_base_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - current_base = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - current_base->Enable( false ); - + current_base = new wxStaticText( this, wxID_ANY, wxT("unknown"), wxDefaultPosition, wxDefaultSize, 0 ); + current_base->Wrap( -1 ); top_sizer->Add( current_base, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); save_button = new wxButton( this, wxID_ANY, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -35,18 +30,36 @@ BasePanelBF::BasePanelBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c main_sizer->Add( top_sizer, 0, wxEXPAND, 5 ); - game_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxLC_REPORT ); - main_sizer->Add( game_list, 1, wxALL|wxEXPAND, 5 ); + separator_1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + main_sizer->Add( separator_1, 0, wxEXPAND | wxALL, 5 ); wxBoxSizer* bottom_sizer; bottom_sizer = new wxBoxSizer( wxHORIZONTAL ); + append_choice_label = new wxStaticText( this, wxID_ANY, wxT("Import games from:"), wxDefaultPosition, wxDefaultSize, 0 ); + append_choice_label->Wrap( -1 ); + bottom_sizer->Add( append_choice_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + wxArrayString append_choiceChoices; + append_choice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, append_choiceChoices, 0 ); + append_choice->SetSelection( 0 ); + bottom_sizer->Add( append_choice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + append_button = new wxButton( this, wxID_ANY, wxT("Append"), wxDefaultPosition, wxDefaultSize, 0 ); + bottom_sizer->Add( append_button, 0, wxALL, 5 ); + + + bottom_sizer->Add( 0, 0, 1, wxEXPAND, 5 ); + delete_button = new wxButton( this, wxID_ANY, wxT("Delete selection"), wxDefaultPosition, wxDefaultSize, 0 ); bottom_sizer->Add( delete_button, 0, wxALL, 5 ); main_sizer->Add( bottom_sizer, 0, wxEXPAND, 5 ); + game_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxLC_REPORT ); + main_sizer->Add( game_list, 1, wxALL|wxEXPAND, 5 ); + this->SetSizer( main_sizer ); this->Layout(); diff --git a/src/base_tab/BasePanelBF.h b/src/base_tab/BasePanelBF.h index 63c4939..1bbbea1 100644 --- a/src/base_tab/BasePanelBF.h +++ b/src/base_tab/BasePanelBF.h @@ -15,12 +15,13 @@ #include #include #include -#include #include #include #include #include #include +#include +#include #include #include @@ -35,12 +36,15 @@ class BasePanelBF : public wxPanel private: protected: - wxStaticText* current_base_label; - wxTextCtrl* current_base; + wxStaticText* current_base; wxButton* save_button; wxButton* export_button; - wxListCtrl* game_list; + wxStaticLine* separator_1; + wxStaticText* append_choice_label; + wxChoice* append_choice; + wxButton* append_button; wxButton* delete_button; + wxListCtrl* game_list; public: diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index 95a1a8d..82a0db0 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -1,7 +1,7 @@ #include "BaseTab.hpp" #include -BaseTab::BaseTab(wxFrame *parent) +BaseTab::BaseTab(wxFrame *parent, std::string base_file) : BasePanelBF(parent), TabInfos(TabInfos::BASE), base(NULL) { game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50); @@ -14,11 +14,11 @@ BaseTab::BaseTab(wxFrame *parent) this->Bind(wxEVT_BUTTON, &BaseTab::OnBim, this, wxID_ANY); this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY); + current_base->SetLabel(base_file); + LoadFile(base_file); } -void BaseTab::OnBim(wxCommandEvent &event) { - LoadFile("/home/loic/hartwig.pgn"); -} +void BaseTab::OnBim(wxCommandEvent &event) {} void BaseTab::OnOpenGame(wxListEvent &event) { wxLogDebug("Open!"); @@ -39,6 +39,7 @@ void BaseTab::LoadFile(std::string path) { wxString ext = file.GetExt().Lower(); if (ext == "pgn") { base = new PGNGameBase(path); + SetLabel(file.GetName()+ "(PGN)"); } if (base != NULL) { @@ -51,8 +52,12 @@ void BaseTab::LoadFile(std::string path) { game_list->SetItem(index, 3, base->GetTag("Event")); game_list->SetItem(index, 4, base->GetTag("Round")); game_list->SetItem(index, 5, base->GetTag("Result")); - game_list->SetItem(index, 5, base->GetTag("ECO")); + game_list->SetItem(index, 6, base->GetTag("ECO")); id++; } } + + wxCommandEvent event(REFRESH_TAB_TITLE, GetId()); + event.SetEventObject(this); + ProcessEvent(event); } \ No newline at end of file diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index 26ee8c1..3283102 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -6,12 +6,13 @@ // Foreign events wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent); +wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); class BaseTab : public BasePanelBF, public TabInfos { GameBase *base; public: - BaseTab(wxFrame *parent); + BaseTab(wxFrame *parent, std::string base_file); void ApplyPreferences(); void LoadFile(std::string path); void OnBim(wxCommandEvent &event); diff --git a/tools/wxframebuilder/BasePanel.fbp b/tools/wxframebuilder/BasePanel.fbp index 14d0031..9b07ebd 100644 --- a/tools/wxframebuilder/BasePanel.fbp +++ b/tools/wxframebuilder/BasePanel.fbp @@ -66,11 +66,11 @@ top_sizer wxHORIZONTAL none - + 5 wxALIGN_CENTER_VERTICAL|wxALL - 0 - + 1 + 1 1 1 @@ -98,7 +98,7 @@ 0 0 wxID_ANY - Current base: + unknown 0 0 @@ -107,66 +107,6 @@ 0 1 - current_base_label - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - - - 5 - wxALIGN_CENTER_VERTICAL|wxALL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 0 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - - 0 - - 1 current_base 1 @@ -181,14 +121,10 @@ ; ; forward_declare 0 - - wxFILTER_NONE - wxDefaultValidator - - + -1 @@ -339,6 +275,356 @@ + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + separator_1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxEXPAND + 0 + + + bottom_sizer + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Import games from: + 0 + + 0 + + + 0 + + 1 + append_choice_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + append_choice + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Append + + 0 + + 0 + + + 0 + + 1 + append_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Delete selection + + 0 + + 0 + + + 0 + + 1 + delete_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 wxALL|wxEXPAND @@ -401,90 +687,6 @@ - - 5 - wxEXPAND - 0 - - - bottom_sizer - wxHORIZONTAL - none - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - 0 - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Delete - - 0 - - 0 - - - 0 - - 1 - delete_button - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - -