ochess/src/ochess.cpp

89 lines
2.6 KiB
C++
Raw Normal View History

2022-02-23 18:11:55 +01:00
#include "ochess.hpp"
#include "MainWindow.hpp"
2022-12-26 16:23:14 +01:00
#include "base_tab/BaseTab.hpp"
2022-02-23 18:11:55 +01:00
bool MyApp::OnInit() {
wxImage::AddHandler(new wxPNGHandler);
2023-01-31 14:05:28 +01:00
// Check config version
CONFIG_OPEN(conf);
2023-01-31 19:03:33 +01:00
wxString version = conf->Read("version", CONFIG_VERSION);
conf->Write("version", version); // Setup config file version
wxLogDebug("Starting ochess with configuration file version %s", version);
2023-01-31 14:05:28 +01:00
CONFIG_CLOSE(conf);
// Advertise for configuration file version
2023-01-31 19:03:33 +01:00
if (version != CONFIG_VERSION) {
wxMessageDialog *dial = new wxMessageDialog(
NULL,
wxT("Configuration files version missmatch. Expected " +
std::string(CONFIG_VERSION) + " but got " + version +
".\nExisting OChess configuration must be erased.\n" +
"Do you still want to proceed?"),
wxT("Information"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
if (dial->ShowModal() != wxID_YES)
return false;
// First remove everything:
CONFIG_OPEN(conf2);
conf2->DeleteAll();
conf2->Write("version", CONFIG_VERSION);
CONFIG_CLOSE(conf2);
// Now Create new configuration:
CONFIG_OPEN(conf3);
conf3->Write("version", CONFIG_VERSION);
CONFIG_CLOSE(conf3);
}
2023-01-31 14:05:28 +01:00
// Main frame
2022-02-23 18:11:55 +01:00
MainWindow *frame = new MainWindow();
frame->Show(true);
2023-01-31 14:05:28 +01:00
2022-02-23 18:11:55 +01:00
return true;
}
2022-12-25 11:13:05 +01:00
std::vector<TabInfos *> MyApp::ListTabInfos() {
std::vector<TabInfos *> tinfos;
2023-01-31 19:03:33 +01:00
wxAuiNotebook *notebook = ((MainWindow *)this->GetTopWindow())->notebook;
2022-12-25 11:13:05 +01:00
for (int i = 0; i < notebook->GetPageCount(); i++) {
tinfos.push_back(dynamic_cast<TabInfos *>(notebook->GetPage(i)));
}
return (tinfos);
}
2023-02-01 12:00:24 +01:00
void MyApp::FocusOnTab(TabInfos * toFocus){
wxAuiNotebook *notebook = ((MainWindow *)this->GetTopWindow())->notebook;
for (int i = 0; i < notebook->GetPageCount(); i++) {
if(dynamic_cast<TabInfos *>(notebook->GetPage(i))->id== toFocus->id)
notebook->SetSelection(i);
}
}
2023-01-31 19:03:33 +01:00
Openings &MyApp::GetBook() { return Book; }
2023-01-16 14:55:48 +01:00
2023-01-31 19:03:33 +01:00
void MyApp::NewGame(TabInfos *tabsrc, std::shared_ptr<Game> g) {
MainWindow *w = ((MainWindow *)this->GetTopWindow());
TabInfos *i = w->NewGame(g);
2022-12-27 18:33:21 +01:00
i->Link(tabsrc); // Link opened game to tabsrc
}
2023-01-31 19:03:33 +01:00
void MyApp::NewGame(std::shared_ptr<Game> g) {
MainWindow *w = ((MainWindow *)this->GetTopWindow());
2022-12-30 16:24:44 +01:00
w->NewGame(g);
}
2022-02-23 18:11:55 +01:00
wxIMPLEMENT_APP(MyApp);
void Abort(std::string msg) {
wxMessageDialog *dial = new wxMessageDialog(NULL, wxString(msg), wxT("Error"),
wxOK | wxICON_ERROR);
dial->ShowModal();
wxLogFatalError(wxString(msg));
}
2022-12-24 10:26:05 +01:00
2023-01-31 19:03:33 +01:00
long TabInfos::tab_count = 0;
void TabInfos::Link(TabInfos *tab) {
this->is_linked = true;
this->linked_id = tab->id;
2022-12-30 15:58:13 +01:00
this->OnLink();
2022-12-24 10:26:05 +01:00
}