CustomizedFrame::CustomizedFrame( wxWindow* parent ) : wxFrame(parent, wxID_ANY, _T(""), wxDefaultPosition, wxSize( -1,-1 ), wxCAPTION|wxCLOSE_BOX|wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ) { SetIcon( SLcustomizations().GetAppIcon() ); SetTitle( SLcustomizations().GetModname() ); this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetExtraStyle( wxFRAME_EX_METAL ); SetSize( SLcustomizations().GetBackgroundSize() ); Layout(); PushEventHandler( new wxBackgroundBitmap( SLcustomizations().GetBackground() ) ); }
QImage SideImageProvider::requestImage ( const QString & id, QSize * size, const QSize & requestedSize ) { int width = requestedSize.width() > 0 ? requestedSize.width() : 16; int height = requestedSize.height() > 0 ? requestedSize.height() : 16; if (size) *size = QSize(width,height); QImage img; if ( !img.load( SLcustomizations().GraphicsDir() + "/sidepics/" + id + ".png" ) ) img.load( SLcustomizations().GraphicsDir() + "/sidepics/" + id.toLower() + ".png" ); return img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); }
QImage GraphicsProvider::requestImage ( const QString & id, QSize * size, const QSize & requestedSize ) { QImage img( SLcustomizations().GraphicsDir() + "/" + id );//.scaled( requestedSize ); int width = requestedSize.width() > 0 ? requestedSize.width() : img.width(); int height = requestedSize.height() > 0 ? requestedSize.height() : img.height(); if (size) *size = QSize(width,height); return img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); }
AutocloseMessageBox::AutocloseMessageBox( wxWindow *parent, const wxString& message, const wxString& caption , unsigned int delay, long style, const wxPoint& pos ) : TimedMessageBox( new wxIcon( SLcustomizations().GetAppIcon() ), parent, message, caption, delay, style, pos ) { wxWindowID delay_timerID = wxNewId(); m_delay_timer.SetOwner( this, delay_timerID ); Connect( delay_timerID, wxEVT_TIMER, wxTimerEventHandler( AutocloseMessageBox::OnUnlock) ); }
SkirmishModel::SkirmishModel(QObject *parent) : QAbstractListModel(parent), m_mod_customs( SLcustomizations().GetCustomizations() ) { m_battle.SetHostMod( SLcustomizations().Archive(), wxEmptyString ); bool loaded = m_battle.CustomBattleOptions().loadOptions( OptionsWrapper::ModOption, SLcustomizations().Archive() ); assert ( loaded ); //this block populates the radiobox and loads the skirmish options into the map std::string md = SLcustomizations().DataBasePath().append( "/skirmish/" ).toStdString(); wxArrayString skirmishes = susynclib().DirListVFS( TowxString(md), _T("*.lua"), _T("r") );//only raw vfs part foreach ( const wxString skirmish_file, skirmishes ) { wxString skirmish_name = skirmish_file.AfterLast('/').BeforeLast('.'); OptionsWrapper temp; loaded = temp.loadOptions( OptionsWrapper::SkirmishOptions, SLcustomizations().Archive(), wxString(_T("skirmish/")) + skirmish_name + wxString(_T(".lua")) ); assert( loaded ); m_skirmishes.push_back( std::make_pair( skirmish_name, temp ) ); }
void mutelistWindow( const wxString& message, const wxString& caption, long style, const int x, const int y ) { wxWindow* parent = CustomMessageBoxBase::getLobbypointer(); wxIcon* icon = new wxIcon( SLcustomizations().GetAppIcon() ); if ( s_mutelistWindow != 0 && s_mutelistWindow->IsShown() ) { s_mutelistWindow->AppendMessage(message); } else { s_mutelistWindow = new MutelistWindow(icon,parent,wxEmptyString,caption,style,wxPoint(x,y)); s_mutelistWindow->AppendMessage(message); s_mutelistWindow->Show(true); } }
QImage VfsImageProvider::requestImage ( const QString & id, QSize * size, const QSize & requestedSize ) { int width = requestedSize.width() > 0 ? requestedSize.width() : 1024; int height = requestedSize.height() > 0 ? requestedSize.height() : 1024; wxImage h; try { h = usync().GetImage( SLcustomizations().GetModname(), TowxString( id ), false ); } catch ( std::exception& e ) { } if (size) *size = QSize(width,height); const QImage q = wxQtConvertImage( h ); return q.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); }
void getIcon( int whichIcon, wxIcon* icon, wxWindow* parent ) { switch (whichIcon) { case SL_MAIN_ICON: icon = new wxIcon( SLcustomizations().GetAppIcon() ); parent = CustomMessageBoxBase::getLobbypointer(); break; case SS_MAIN_ICON: icon = new wxIcon(springsettings_xpm); parent = CustomMessageBoxBase::getSettingspointer(); break; default: icon = new wxIcon(wxNullIcon); parent = 0; break; } assert( icon ); }
settings_frame::settings_frame(wxWindow *parent, const wxString &title, wxWindowID id) : wxFrame(parent, id, title ), WindowAttributesPickle( _T("SETTINGSFRAME"), this, wxSize( DEFSETT_SW_WIDTH, DEFSETT_SW_HEIGHT ) ), simpleTab(0), uiTab(0), audioTab(0), detailTab(0), qualityTab(0), hotkeyTab(0), settingsIcon( new wxIcon(springsettings_xpm) ), m_has_focus(true) { SetIcons( SLcustomizations().GetAppIconBundle() ); alreadyCalled = false; parentWindow = parent; if ( !usync().IsLoaded() ) usync().ReloadUnitSyncLib(); notebook = new wxNotebook(this, ID_OPTIONS); // notebook->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, _T("Tahoma"))); if (abstract_panel::loadValuesIntoMap()) { CreateGUIControls(); initMenuBar(); } else { notebook->AddPage(new PathOptionPanel(notebook,this),_("Error!")); } Layout(); Center(); if ( !parentWindow ) UpdateMainAppHasFocus(m_has_focus); // only do if not being a slave of main SL app }
//! @brief Initializes the application. //! //! It will open the main window and connect default to server or open the connect window. bool SpringLobbyApp::OnInit() { wxSetEnv( _T("UBUNTU_MENUPROXY"), _T("0") ); //this triggers the Cli Parser amongst other stuff if (!wxApp::OnInit()) return false; SetAppName( m_appname ); if (!m_crash_handle_disable) { #if wxUSE_ON_FATAL_EXCEPTION wxHandleFatalExceptions( true ); #endif #if defined(__WXMSW__) && defined(ENABLE_DEBUG_REPORT) //this undocumented function acts as a workaround for the dysfunctional // wxUSE_ON_FATAL_EXCEPTION on msw when mingw is used (or any other non SEH-capable compiler ) SetUnhandledExceptionFilter(filter); #endif } //initialize all loggers, we'll use the returned pointer to set correct parent window later wxLogChain* logchain = 0; wxLogWindow *loggerwin = InitializeLoggingTargets( 0, m_log_console, m_log_file_path, m_log_window_show, !m_crash_handle_disable, m_log_verbosity, logchain ); //this needs to called _before_ mainwindow instance is created wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); wxSocketBase::Initialize(); #ifdef __WXMSW__ wxString path = wxPathOnly( wxStandardPaths::Get().GetExecutablePath() ) + wxFileName::GetPathSeparator() + _T("locale"); #else #if defined(LOCALE_INSTALL_DIR) wxString path ( _T(LOCALE_INSTALL_DIR) ); #else // use a dummy name here, we're only interested in the base path wxString path = wxStandardPaths::Get().GetLocalizedResourcesDir(_T("noneWH"),wxStandardPaths::ResourceCat_Messages); path = path.Left( path.First(_T("noneWH") ) ); #endif #endif m_translationhelper = new wxTranslationHelper( *( (wxApp*)this ), path ); m_translationhelper->Load(); if ( !wxDirExists( GetConfigfileDir() ) ) wxMkdir( GetConfigfileDir() ); #ifdef __WXMSW__ sett().SetSearchSpringOnlyInSLPath( sett().GetSearchSpringOnlyInSLPath() ); #endif sett().SetSpringBinary( sett().GetCurrentUsedSpringIndex(), sett().GetCurrentUsedSpringBinary() ); sett().SetUnitSync( sett().GetCurrentUsedSpringIndex(), sett().GetCurrentUsedUnitSync() ); if ( sett().DoResetPerspectives() ) { //we do this early on and reset the config var a little later so we can save a def. perps once mw is created sett().RemoveLayouts(); sett().SetDoResetPerspectives( false ); ui().mw().SavePerspectives( _T("SpringLobby-default") ); } sett().RefreshSpringVersionList(); //this should take off the firstload time considerably *ie nil it :P ) mapSelectDialog(); if ( !m_customizer_archive_name.IsEmpty() ) {//this needsto happen before usync load sett().SetForcedSpringConfigFilePath( GetCustomizedEngineConfigFilePath() ); } //unitsync first load, NEEDS to be blocking const bool usync_loaded = usync().ReloadUnitSyncLib(); if ( !sett().IsFirstRun() && !usync_loaded ) { customMessageBox( SL_MAIN_ICON, _("Please check that the file given in Preferences->Spring is a proper, readable unitsync library"), _("Coulnd't load required unitsync library"), wxOK ); } #ifndef DISABLE_SOUND //sound sources/buffer init sound(); #endif CacheAndSettingsSetup(); if ( !m_customizer_archive_name.IsEmpty() ) { if ( SLcustomizations().Init( m_customizer_archive_name ) ) { ui().mw().SetIcons( SLcustomizations().GetAppIconBundle() ); } else { customMessageBox( SL_MAIN_ICON, _("Couldn't load customizations for ") + m_customizer_archive_name + _("\nPlease check that that is the correct name, passed in qoutation"), _("Fatal error"), wxOK ); // wxLogError( _("Couldn't load customizations for ") + m_customizer_archive_name + _("\nPlease check that that is the correct name, passed in qoutation"), _("Fatal error") ); exit( OnExit() );//for some twisted reason returning false here does not terminate the app } } notificationManager(); //needs to be initialized too ui().ShowMainWindow(); SetTopWindow( &ui().mw() ); if ( sett().DoResetPerspectives() ) { //now that mainwindow is shown, we can save what is the default layout and remove the flag to reset sett().SetDoResetPerspectives( false ); ui().mw().SavePerspectives( _T("SpringLobby-default") ); } //interim fix for resize crashes on metacity and kwin #ifdef __WXMSW__ mapSelectDialog().Reparent( &ui().mw() ); #endif ui().FirstRunWelcome(); m_timer->Start( TIMER_INTERVAL ); ui().mw().SetLogWin( loggerwin, logchain ); #ifndef NO_TORRENT_SYSTEM plasmaInterface(); // plasmaInterface().InitResourceList(); // plasmaInterface().FetchResourceList(); #endif return true; }
int SasiApp::exec() { QSplashScreen* splash = 0; QPixmap splash_pixmap; QWidget* show_screen = desktop()->screen( 0 ); if ( splash_pixmap.load( SLcustomizations().GraphicsDir() + "/splash.png" ) ) { splash = new QSplashScreen(show_screen,splash_pixmap); splash->show(); } wxLogChain* logchain = 0; wxLog::SetActiveTarget( new wxLogChain( new wxLogStream( &std::cout ) ) ); //this needs to called _before_ mainwindow instance is created wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); wxSocketBase::Initialize(); usync().FastLoadUnitSyncLibInit( ); QDeclarativeView view(show_screen); QString qmldir; try { qmldir = SLcustomizations().QmlDir(); } catch ( Customizations::DataException& e ) { //for some f****d up reason the strings get internally f****d up w/o the hardcopy QList<QString> copy = e.errors_; QErrorWindow error_win ( copy ); return error_win.exec(); } AudioManager audio_manager (this); audio_manager.start(); view.engine()->addImportPath( qmldir ); #ifdef __WXMSW__ //for webkit declarative plugin view.engine()->addImportPath( QDir( QCoreApplication::applicationDirPath() + "/imports").absolutePath() ); #endif // Visual initialization view.engine()->addImageProvider("minimaps", new MinimapImageProvider); view.engine()->addImageProvider("graphics", new GraphicsProvider); view.engine()->addImageProvider("sides", new SideImageProvider); #if USE_OPENGL QGLFormat format = QGLFormat::defaultFormat(); #ifdef Q_WS_MAC format.setSampleBuffers(true); #else format.setSampleBuffers(false); #endif QGLWidget *glWidget = new QGLWidget(format, &view); view.setViewport(glWidget); view.setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); #endif view.setAttribute(Qt::WA_OpaquePaintEvent); view.setAttribute(Qt::WA_NoSystemBackground); view.setResizeMode(QDeclarativeView::SizeRootObjectToView); MaplistModel maplist_model( usync().GetMapList() ); SkirmishModel skirmish_model; SideModel side_model( SLcustomizations().GetModname() ); PresetModel preset_model(this); ScreenResolutionModel screenres_model(this); spring().connect( &spring(), SIGNAL(springStarted()), &audio_manager, SLOT(pause())); spring().connect( &spring(), SIGNAL(springStopped()), &audio_manager, SLOT(resume())); QObject::connect((QObject*)view.engine(), SIGNAL(quit()), this, SLOT(quit())); QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &audio_manager, SLOT(doQuit())); QDeclarativeContext* ctxt = view.rootContext(); ctxt->setContextProperty("maplistModel", &maplist_model ); ctxt->setContextProperty("skirmishModel", &skirmish_model ); ctxt->setContextProperty("sideModel", &side_model ); ctxt->setContextProperty("audioManager", &audio_manager ); ctxt->setContextProperty("presetModel", &preset_model ); ctxt->setContextProperty("screenresModel", &screenres_model ); const int sleep_seconds = -1; for ( int i = sleep_seconds; splash && i > 0; i-- ) { splash->showMessage( QString("sleeping for %1 seconds, just to show you this").arg( i ), Qt::AlignHCenter | Qt::AlignBottom ); processEvents(); sleep( 1 ); } // view.showFullScreen(); if ( splash ) splash->finish(&view); view.setSource(QUrl(qmldir + "/main.qml")); QObject::connect(this, SIGNAL(appLoaded()), (QObject*)view.rootObject(), SLOT(onAppLoaded())); QList<QDeclarativeError> errors = view.errors(); if ( errors.size() ) { QErrorWindow error_window ( errors ); return error_window.exec(); } view.show(); view.setFocus(); emit appLoaded(); int ret = QApplication::exec(); audio_manager.wait( 5 /*seconds*/ ); return ret; }
SimpleFront::SimpleFront( wxWindow* parent ) : CustomizedFrame( parent ), m_settings_frame( 0 ), m_skirmish( 0 ) { bSizer1 = new wxBoxSizer( wxVERTICAL ); bSizer1->Add( 0, 0, 1, wxEXPAND, 5 ); m_button_sizer = new wxBoxSizer( wxHORIZONTAL ); m_sp = new wxGradientButton( this, wxID_ANY, _("Skirmish"), wxDefaultPosition, wxDefaultSize, 0 ); // m_sp->SetDefault(); m_button_sizer->Add( m_sp, 0, wxALL, 5 ); m_mp = new wxGradientButton( this, wxID_ANY, _("Multiplayer"), wxDefaultPosition, wxDefaultSize, 0 ); m_button_sizer->Add( m_mp, 0, wxALL, 5 ); m_settings = new wxGradientButton( this, wxID_ANY, _("Settings"), wxDefaultPosition, wxDefaultSize, 0 ); m_button_sizer->Add( m_settings, 0, wxALL, 5 ); m_help = new wxGradientButton( this, wxID_ANY, _("Help"), wxDefaultPosition, wxDefaultSize, 0 ); m_button_sizer->Add( m_help, 0, wxALL, 5 ); m_help->Show( !SLcustomizations().GetHelpUrl().IsEmpty() ); m_exit = new wxGradientButton( this, wxID_ANY, _("Exit"), wxDefaultPosition, wxDefaultSize, 0 ); m_button_sizer->Add( m_exit, 0, wxALL, 5 ); bSizer1->Add( m_button_sizer, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); m_sp_button_sizer = new wxBoxSizer( wxHORIZONTAL ); m_back = new wxGradientButton( this, wxID_ANY, _("Back"), wxDefaultPosition, wxDefaultSize, 0 ); m_sp_button_sizer->Add( m_back, 0, wxALL, 5 ); m_advanced = new wxGradientButton( this, wxID_ANY, _("Advanced setup"), wxDefaultPosition, wxDefaultSize, 0 ); m_sp_button_sizer->Add( m_advanced, 0, wxALL, 5 ); m_start = new wxGradientButton( this, wxID_ANY, _("Start"), wxDefaultPosition, wxDefaultSize, 0 ); m_sp_button_sizer->Add( m_start, 0, wxALL, 5 ); m_sp_button_sizer->Show( false ); bSizer1->Add( m_sp_button_sizer, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); m_skirmish_sizer = new wxBoxSizer( wxHORIZONTAL ); m_skirmish = new SkirmishDialog( this, -1 ); m_skirmish_sizer->Add( m_skirmish, 0, wxALIGN_BOTTOM, 0 ); m_skirmish_sizer->Show( false ); bSizer1->Add( 0, 0, 1, wxEXPAND, 5 ); this->SetSizer( bSizer1 ); this->Layout(); this->Centre( wxBOTH ); // Connect Events m_sp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SimpleFront::OnSingleplayer ), NULL, this ); m_mp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SimpleFront::OnMultiplayer ), NULL, this ); m_settings->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SimpleFront::OnSettings ), NULL, this ); m_help->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SimpleFront::OnHelp ), NULL, this ); m_exit->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SimpleFront::OnExit ), NULL, this ); m_back->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SkirmishDialog::OnBack ), NULL, m_skirmish ); m_advanced->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SkirmishDialog::OnAdvanced ), NULL, m_skirmish ); m_start->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SkirmishDialog::OnStart ), NULL, m_skirmish ); Layout(); }
void SimpleFront::OnHelp( wxCommandEvent& ) { OpenWebBrowser( SLcustomizations().GetHelpUrl() ); }