aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-24 12:46:59 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-24 12:46:59 +0100
commit2d9730e216976103daea64a8df047d5f0dffd5f7 (patch)
tree894454165b388167c077619c0a0388338c828c05 /src
parent273610cb0f848fd99f9b9769f0d60b6e2df590ed (diff)
Update tab management system
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.cpp9
-rw-r--r--src/MainWindow.hpp2
-rw-r--r--src/base_tab/BaseGameTab.cpp11
-rw-r--r--src/base_tab/BaseGameTab.hpp2
-rw-r--r--src/base_tab/BaseManageTab.cpp1
-rw-r--r--src/base_tab/BaseTab.cpp11
-rw-r--r--src/base_tab/BaseTab.hpp10
-rw-r--r--src/ochess.hpp2
8 files changed, 35 insertions, 13 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 2243f86..8b6e0fe 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -191,9 +191,9 @@ void MainWindow::NewGame(bool useFen) {
}
void MainWindow::OnNewGame(wxCommandEvent &event) {
- std::shared_ptr<Game> *g = (std::shared_ptr<Game>*)event.GetClientData();
- NewGame(*g);
- delete g;
+ TabInfos *tab = (TabInfos*)event.GetClientData();
+ TabInfos *i=NewGame(tab->GetGame());
+ i->Link(tab);
}
void MainWindow::OnPageChange(wxAuiNotebookEvent &event) {
@@ -215,8 +215,9 @@ void MainWindow::OnRefreshTabTitle(wxCommandEvent &event) {
}
}
-void MainWindow::NewGame(std::shared_ptr<Game> game) {
+TabInfos* MainWindow::NewGame(std::shared_ptr<Game> game) {
GameTab *gt = new GameTab((wxFrame *)notebook, game);
notebook->AddPage(gt, gt->GetLabel());
notebook->SetSelection(notebook->GetPageIndex(gt));
+ return(gt);
}
diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp
index bd33ad7..d809736 100644
--- a/src/MainWindow.hpp
+++ b/src/MainWindow.hpp
@@ -23,7 +23,7 @@ class MainWindow : public MainFrame {
void OpenFile();
void OnPageChange(wxAuiNotebookEvent &event);
void OnRefreshTabTitle(wxCommandEvent &event);
- void NewGame(std::shared_ptr<Game> game);
+ TabInfos* NewGame(std::shared_ptr<Game> game);
void OpenSettings();
void NewEngine();
void OnCloseTabEvent(wxCommandEvent &event);
diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp
index 79f28c1..dafa71a 100644
--- a/src/base_tab/BaseGameTab.cpp
+++ b/src/base_tab/BaseGameTab.cpp
@@ -2,6 +2,9 @@
#include "AppendGameDialog.hpp"
#include <wx/filename.h>
+wxDEFINE_EVENT(OPEN_GAME_EVENT, wxCommandEvent);
+
+
BaseGameTab::BaseGameTab(wxFrame *parent, std::string base_file)
: TabBase_TabGames(parent), base_file(base_file),
base(NULL) {
@@ -72,10 +75,10 @@ void BaseGameTab::OnOpenGame(wxListEvent &event) {
edited.push_back(*g);
deleted.push_back(id);
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
- wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
- newGameEvent.SetEventObject(this);
- newGameEvent.SetClientData(g);
- ProcessEvent(newGameEvent);
+ wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId());
+ openGameEvent.SetEventObject(this);
+ openGameEvent.SetClientData(g);
+ ProcessEvent(openGameEvent);
}
}
diff --git a/src/base_tab/BaseGameTab.hpp b/src/base_tab/BaseGameTab.hpp
index d90163f..f93903c 100644
--- a/src/base_tab/BaseGameTab.hpp
+++ b/src/base_tab/BaseGameTab.hpp
@@ -4,7 +4,7 @@
#include "ochess.hpp"
// Foreign events
-wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
+wxDECLARE_EVENT(OPEN_GAME_EVENT, wxCommandEvent);
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
class BaseGameTab : public TabBase_TabGames {
diff --git a/src/base_tab/BaseManageTab.cpp b/src/base_tab/BaseManageTab.cpp
index 46306df..db42b8b 100644
--- a/src/base_tab/BaseManageTab.cpp
+++ b/src/base_tab/BaseManageTab.cpp
@@ -6,3 +6,4 @@ TabBase_TabManage(parent)
{
}
+
diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp
index a76ba38..a2b7207 100644
--- a/src/base_tab/BaseTab.cpp
+++ b/src/base_tab/BaseTab.cpp
@@ -16,6 +16,17 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
notebook->AddPage(manage_tab, "Manage database");
RefreshLabel();
+ this->Bind(OPEN_GAME_EVENT, &BaseTab::OnNewGame, this, wxID_ANY);
+}
+
+
+void BaseTab::OnNewGame(wxCommandEvent &event){
+ std::shared_ptr<Game> *g = (std::shared_ptr<Game>*)event.GetClientData();
+ this->game=*g;
+ wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
+ newGameEvent.SetEventObject(this);
+ newGameEvent.SetClientData((TabInfos*)this);
+ ProcessEvent(newGameEvent);
}
void BaseTab::ApplyPreferences() {}
diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp
index 6136eed..788ba45 100644
--- a/src/base_tab/BaseTab.hpp
+++ b/src/base_tab/BaseTab.hpp
@@ -5,16 +5,22 @@
#include "BaseImportTab.hpp"
#include "BaseManageTab.hpp"
+wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
+
+
class BaseTab : public TabBase, public TabInfos {
std::shared_ptr<GameBase> base;
+ std::shared_ptr<Game> game;
BaseGameTab *games_tab;
BaseImportTab *import_tab;
- BaseManageTab * manage_tab;
+ BaseManageTab *manage_tab;
+
+ void OnNewGame(wxCommandEvent &event);
public:
BaseTab(wxFrame *parent, std::string base_file);
void ApplyPreferences();
void RefreshLabel();
- std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(NULL)); }
+ std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(game)); }
std::shared_ptr<GameBase> GetBase() { return (std::shared_ptr<GameBase>(base)); };
}; \ No newline at end of file
diff --git a/src/ochess.hpp b/src/ochess.hpp
index 805de31..47e08e4 100644
--- a/src/ochess.hpp
+++ b/src/ochess.hpp
@@ -63,7 +63,7 @@ public:
long linked_id;
/// @brief Set to true if this tab is attach to another one (c.f linked_id)
bool is_linked;
- TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false) { tab_count++; }
+ TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false) { tab_count++; wxLogDebug("Tabid=%d",(int)id); }
void Link(TabInfos *tab);
virtual void ApplyPreferences() = 0;
virtual std::shared_ptr<Game> GetGame() = 0;