diff --git a/libs/chessarbiter b/libs/chessarbiter index 975ad84..90050da 160000 --- a/libs/chessarbiter +++ b/libs/chessarbiter @@ -1 +1 @@ -Subproject commit 975ad849d1d1474e601ad2f4bf48ea0e4405251c +Subproject commit 90050da015f3988ab3188eb19629aed262454fef diff --git a/libs/pgnp b/libs/pgnp index 43434b1..5d17969 160000 --- a/libs/pgnp +++ b/libs/pgnp @@ -1 +1 @@ -Subproject commit 43434b170c2725d74f2d91f4cc86b85303893f08 +Subproject commit 5d1796920e7c20e8f99f106935e10b8ec9296aba diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 0a79bc2..5dbbf28 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -4,6 +4,7 @@ #include "preferences/preferences.hpp" wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); +wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent); /// ---------- MainWindow ---------- @@ -52,6 +53,7 @@ MainWindow::MainWindow() Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this, wxID_ANY); Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); + Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame2, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); } @@ -142,6 +144,11 @@ void MainWindow::OnNewGame(wxCommandEvent &event) { } } +void MainWindow::OnNewGame2(wxCommandEvent &event) { + Game *g=(Game*)event.GetClientData(); + NewGame(g); +} + void MainWindow::OnPageChange(wxAuiNotebookEvent &event) { TabInfos *infos = dynamic_cast(notebook->GetCurrentPage()); if (infos->type != TabInfos::GAME) { diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 87cf015..e827df3 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -1,12 +1,13 @@ -#include "game_tab/GameTab.hpp" #include "base_tab/BaseTab.hpp" +#include "game_tab/GameTab.hpp" #include "ochess.hpp" #include #include -#include #include +#include wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); +wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent); class MainWindow : public wxFrame { wxAuiNotebook *notebook; @@ -17,6 +18,7 @@ class MainWindow : public wxFrame { void OnExit(wxCommandEvent &event); void OnClose(wxCloseEvent &e); void OnNewGame(wxCommandEvent &event); + void OnNewGame2(wxCommandEvent &event); void OnOpen(wxCommandEvent &event); void OnPageChange(wxAuiNotebookEvent &event); void OnRefreshTabTitle(wxCommandEvent &event); diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index f1fd107..29b6fc3 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -22,10 +22,13 @@ void BaseTab::OnBim(wxCommandEvent &event) { void BaseTab::OnOpenGame(wxListEvent &event) { wxLogDebug("Open!"); - long id=std::stoi(event.GetItem().GetText().ToStdString()); + long id = std::stoi(event.GetItem().GetText().ToStdString()); Game *g = base->GetGame(id); if (g != NULL) { - wxLogDebug("Open game: %s", g->GetTag("White")); + wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId()); + newGameEvent.SetEventObject(this); + newGameEvent.SetClientData(g); + ProcessEvent(newGameEvent); } } @@ -41,7 +44,8 @@ void BaseTab::LoadFile(std::string path) { if (base != NULL) { long id = 0; while (base->NextGame()) { - long index = game_list->InsertItem(0, std::to_string(id)); // want this for col. 1 + long index = + game_list->InsertItem(0, std::to_string(id)); // want this for col. 1 game_list->SetItem(index, 1, base->GetTag("White")); game_list->SetItem(index, 2, base->GetTag("Black")); game_list->SetItem(index, 3, base->GetTag("Event")); diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index 5a71cd7..26ee8c1 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -4,6 +4,9 @@ #include "gamebase/PGNGameBase.hpp" #include "ochess.hpp" +// Foreign events +wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent); + class BaseTab : public BasePanelBF, public TabInfos { GameBase *base; diff --git a/src/base_tab/gamebase/PGNGameBase.cpp b/src/base_tab/gamebase/PGNGameBase.cpp index 08c8803..8f9974d 100644 --- a/src/base_tab/gamebase/PGNGameBase.cpp +++ b/src/base_tab/gamebase/PGNGameBase.cpp @@ -32,7 +32,7 @@ void PGNGameBase::Reset() { Game *PGNGameBase::GetGame(std::uint32_t id) { Reset(); std::uint32_t curid = 0; - while(NextGame()) { + while (NextGame()) { if (id == curid) { pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove(); pgn->GetMoves(pgnp_moves); @@ -41,7 +41,7 @@ Game *PGNGameBase::GetGame(std::uint32_t id) { if (pgn->HasTag("FEN")) { fen = pgn->GetTagValue("FEN"); } - HalfMove *m = new HalfMove(pgnp_moves, 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)); diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index e59794b..1a6b5aa 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -118,7 +118,10 @@ HalfMove *HalfMove::GetMainline() { return (mainline); } HalfMove::HalfMove(pgnp::HalfMove *m, std::string initial_fen): capture(' ') { chessarbiter::ChessArbiter arbiter; arbiter.Setup(initial_fen); - arbiter.Play(arbiter.ParseSAN(m->move)); + bool work=arbiter.Play(arbiter.ParseSAN(m->move)); + if(!work){ + wxLogDebug("Bug! %s",m->move); + } char capture=arbiter.GetCapture(); if(capture != ' '){ this->capture=capture;