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 ) ;
wxString version = conf - > Read ( " version " , CONFIG_VERSION ) ;
conf - > Write ( " version " , version ) ; // Setup config file version
wxLogDebug ( " Starting ochess with configuration file version %s " , version ) ;
CONFIG_CLOSE ( conf ) ;
// Advertise for configuration file version
if ( version ! = CONFIG_VERSION )
SHOW_DIALOG_INFO ( " Configuration files version missmatch. Expected " + std : : string ( CONFIG_VERSION ) + " but got " + version + " . \n Please remove the current configuration file as it may crash the application. " ) ;
// 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 ;
wxAuiNotebook * notebook = ( ( MainWindow * ) this - > GetTopWindow ( ) ) - > notebook ;
for ( int i = 0 ; i < notebook - > GetPageCount ( ) ; i + + ) {
tinfos . push_back ( dynamic_cast < TabInfos * > ( notebook - > GetPage ( i ) ) ) ;
}
return ( tinfos ) ;
}
2023-01-16 14:55:48 +01:00
Openings & MyApp : : GetBook ( ) { return Book ; }
2022-12-27 18:33:21 +01:00
void MyApp : : NewGame ( TabInfos * tabsrc , std : : shared_ptr < Game > g ) {
MainWindow * w = ( ( MainWindow * ) this - > GetTopWindow ( ) ) ;
TabInfos * i = w - > NewGame ( g ) ;
i - > Link ( tabsrc ) ; // Link opened game to tabsrc
}
2022-12-30 16:24:44 +01:00
void MyApp : : NewGame ( std : : shared_ptr < Game > g ) {
MainWindow * w = ( ( MainWindow * ) this - > GetTopWindow ( ) ) ;
w - > NewGame ( g ) ;
}
2022-12-26 16:23:14 +01:00
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
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
}