Update tab management system

This commit is contained in:
Loic Guegan 2022-12-24 12:46:59 +01:00
parent 273610cb0f
commit 2d9730e216
8 changed files with 35 additions and 13 deletions

View file

@ -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);
}
}

View file

@ -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 {

View file

@ -6,3 +6,4 @@ TabBase_TabManage(parent)
{
}

View file

@ -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() {}

View file

@ -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)); };
};