void IBattle::OnUnitsyncReloaded( GlobalEvents::GlobalEventData /*data*/ ) { if ( !m_host_mod.hash.IsEmpty() && m_host_mod.hash != '0' ) m_mod_exists = usync().ModExists( m_host_mod.name, m_host_mod.hash); else m_mod_exists = usync().ModExists( m_host_mod.name ); if ( !m_host_map.hash.IsEmpty() && m_host_map.hash != '0' ) m_map_exists = usync().MapExists( m_host_map.name, m_host_map.hash ); else m_map_exists = usync().MapExists( m_host_map.name ); }
/** @brief NoGuiSinglePlayerBattle * * @todo: document this function */ NoGuiSinglePlayerBattle::NoGuiSinglePlayerBattle() : m_me( User( usync().IsLoaded() ? usync().GetDefaultNick() : _T("invalid") ) ) { OnUserAdded( m_me ); m_me.BattleStatus().colour = sett().GetBattleLastColour(); SetFounder( m_me.GetNick() ); }
settings_frame::settings_frame(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& pa_size) : wxFrame(parent, id, title, position, pa_size), WindowAttributesPickle( _T("SETTINGSFRAME"), this, wxSize( DEFSETT_SW_WIDTH, DEFSETT_SW_HEIGHT ) ) { alreadyCalled = false; parentWindow = parent; if ( !usync().IsLoaded() ) usync().ReloadUnitSyncLib(); notebook = new wxNotebook(this, ID_OPTIONS, wxPoint(0,0),TAB_SIZE, wxNB_TOP|wxNB_NOPAGETHEME); notebook->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, _T("Tahoma"))); settingsIcon = new wxIcon(springsettings_xpm); if (abstract_panel::loadValuesIntoMap()) { CreateGUIControls(); initMenuBar(); } else { notebook->AddPage(new PathOptionPanel(notebook,this),_("Error!")); SetTitle(_T("SpringSettings")); } SetIcon(*settingsIcon); Layout(); Center(); }
SinglePlayerBattle::SinglePlayerBattle( MainSinglePlayerTab& msptab ): m_sptab(msptab), m_me( User( usync().IsLoaded() ? usync().GetDefaultNick() : _T("invalid") ) ) { OnUserAdded( m_me ); m_me.BattleStatus().side = sett().GetBattleLastSideSel( GetHostModName() ); m_me.BattleStatus().colour = sett().GetBattleLastColour(); CustomBattleOptions().setSingleOption( _T("startpostype"), wxFormat(_T("%d") ) % ST_Pick, OptionsWrapper::EngineOption ); }
void IBattle::SetLocalMod( const UnitSyncMod& mod ) { if ( mod.name != m_local_mod.name || mod.hash != m_local_mod.hash ) { m_previous_local_mod_name = m_local_mod.name; m_local_mod = mod; m_mod_loaded = true; if ( !m_host_mod.hash.IsEmpty() && m_host_mod.hash != '0' ) m_mod_exists = usync().ModExists( m_host_mod.name, m_host_mod.hash ); else m_mod_exists = usync().ModExists( m_host_mod.name ); } }
void IBattle::SetHostMod( const wxString& modname, const wxString& hash ) { if ( m_host_mod.name != modname || m_host_mod.hash != hash ) { m_mod_loaded = false; m_host_mod.name = modname; m_host_mod.hash = hash; if ( !m_host_mod.hash.IsEmpty() && m_host_mod.hash != '0' ) m_mod_exists = usync().ModExists( m_host_mod.name, m_host_mod.hash ); else m_mod_exists = usync().ModExists( m_host_mod.name ); } }
void SinglePlayerBattle::RemoveUnfittingBots() { wxArrayString old_ais = usync().GetAIList( m_previous_local_mod_name ); wxArrayString new_ais = usync().GetAIList( m_local_mod.name ); for ( size_t i = 0; i < old_ais.GetCount(); ++i) { if ( new_ais.Index(old_ais[i]) == wxNOT_FOUND ) { for( size_t j = 0; j < GetNumUsers(); ++j ) { User& u = GetUser( j ); if ( u.GetBattleStatus().airawname == old_ais[i] ) KickPlayer( u ); } } } }
void BattleroomListCtrl::SetBattle( IBattle* battle ) { m_battle = battle; for ( unsigned int i = 0; i < side_vector.size(); i++ ) { wxMenuItem* side = side_vector[i]; m_popup->Destroy( side ); // delete side; Disconnect( BRLIST_SIDE + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BattleroomListCtrl::OnSideSelect ) ); } m_data.clear(); side_vector.clear(); if ( m_battle && m_sides ) { try { wxArrayString sides = usync().GetSides( m_battle->GetHostModName() ); for ( unsigned int i = 0; i < sides.GetCount(); i++ ) { wxMenuItem* side = new wxMenuItem( m_sides, BRLIST_SIDE + i, sides[i], wxEmptyString, wxITEM_NORMAL ); m_sides->Append( side ); side_vector.push_back( side ); Connect( BRLIST_SIDE + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BattleroomListCtrl::OnSideSelect ) ); } } catch (...) {} } }
void IBattle::OnSelfLeftBattle() { GetMe().BattleStatus().spectator = false; // always reset back yourself to player when rejoining if ( m_timer ) m_timer->Stop(); delete m_timer; m_timer = 0; m_is_self_in = false; for( size_t j = 0; j < GetNumUsers(); ++j ) { User& u = GetUser( j ); if ( u.GetBattleStatus().IsBot() ) { OnUserRemoved( u ); ui().OnUserLeftBattle( *this, u, true ); j--; } } ClearStartRects(); m_teams_sizes.clear(); m_ally_sizes.clear(); m_players_ready = 0; m_players_sync = 0; m_players_ok = 0; usync().UnSetCurrentMod(); //left battle }
wxString AddBotDialog::GetAIShortName() { wxArrayString infos = usync().GetAIInfos( m_ai->GetSelection() ); int namepos = infos.Index( _T("shortName") ); if ( namepos == wxNOT_FOUND ) return m_ais[ m_ai->GetSelection() ]; return infos[namepos +1]; }
wxString AddBotDialog::GetAIVersion() { wxArrayString infos = usync().GetAIInfos( m_ai->GetSelection() ); int namepos = infos.Index( _T("version") ); if ( namepos == wxNOT_FOUND ) return _T(""); return infos[namepos +1]; }
bool OptionsWrapper::loadOptions(Enum::GameOption modmapFlag, const std::string& name) { unLoadOptions(modmapFlag); GameOptions opt; switch (modmapFlag) { default: break; case Enum::MapOption: try { opt = usync().GetMapOptions(name); } catch (...) { LslError("Could not load map options"); usync().FetchUnitsyncErrors(name); return false; } break; case Enum::ModOption: try { opt = usync().GetGameOptions(name); } catch (...) { LslError("Could not load game options"); usync().FetchUnitsyncErrors(name); return false; } break; case Enum::EngineOption: { //TODO Fixed,random and so forth are intls mmOptionList startpos("Start Position Type", "startpostype", "How players will select where to be spawned in the map\n0: fixed map positions\n1: random map positions\n2: choose in game\n3: choose in the lobby before starting", "0"); startpos.addItem("0", "Fixed", "Use the start positions defined in the map, the positions will be assigned incrementally from the team with lowest number to highest"); startpos.addItem("1", "Random", "Use the start positions defined in the map, the positions will be assigned randomly"); startpos.addItem("2", "Choose in-game", "Players will be able to pick their own starting point right before the game starts, optionally limited by a bounding box defined by the host"); startpos.addItem("3", "Choose before game", "The host will place each player's start position in the map preview before the game is launched"); opt.list_map["startpostype"] = startpos; break; } case Enum::PrivateOptions: { opt.string_map["restrictions"] = mmOptionString("List of restricted units", "restrictedunits", "Units in this list won't be available in game", "", 0); // tab separated list opt.string_map["mapname"] = mmOptionString("Map name", "mapname", "Map name", "", 0); break; } } m_opts[modmapFlag] = opt; return true; }
void IBattle::SetHostMap(const wxString& mapname, const wxString& hash) { if ( mapname != m_host_map.name || hash != m_host_map.hash ) { m_map_loaded = false; m_host_map.name = mapname; m_host_map.hash = hash; if ( !m_host_map.hash.IsEmpty() && m_host_map.hash != '0' ) m_map_exists = usync().MapExists( m_host_map.name, m_host_map.hash ); else m_map_exists = usync().MapExists( m_host_map.name ); #ifndef __WXMSW__ //!TODO why not on win? if ( m_map_exists && !spring().IsRunning() ) usync().PrefetchMap( m_host_map.name ); #endif } }
//////////////////////////////////////////////////////// //// private functions to interface with the system //// //////////////////////////////////////////////////////// void TorrentWrapper::HandleCompleted() { int num_completed = 0; { ScopedLocker<TorrenthandleInfoMap> l_torrent_table(m_handleInfo_map); const TorrenthandleInfoMap& infomap = l_torrent_table.Get(); TorrenthandleInfoMap::const_iterator it = infomap.begin(); for ( ; it != infomap.end(); ++it ) { PlasmaResourceInfo info = it->first; libtorrent::torrent_handle handle = it->second; if ( handle.is_valid() && handle.is_seed() ) { wxString dest_filename = sett().GetCurrentUsedDataDir() + getDataSubdirForType( convertMediaType( info.m_type ) ) + wxFileName::GetPathSeparator() + TowxString( handle.get_torrent_info().file_at( 0 ).path.string() ); if ( !wxFileExists( dest_filename ) ) { wxString source_path = TowxString( handle.save_path().string() ) + wxFileName::GetPathSeparator() + TowxString( handle.get_torrent_info().file_at( 0 ).path.string() ); wxString dest_path = wxPathOnly( dest_filename ); if ( !wxDirExists( dest_path ) ) wxMkdir( dest_path ); bool ok = wxCopyFile( source_path, dest_filename ); if ( !ok ) { wxString msg = wxString::Format( _("File copy from %s to %s failed.\nPlease copy manually and reload maps/mods afterwards"), source_path.c_str(), dest_filename.c_str() ); wxLogError( _T("DL: File copy from %s to %s failed."), source_path.c_str(), dest_filename.c_str() ); #ifdef __WXMSW__ UiEvents::StatusData data( msg, 1 ); UiEvents::GetStatusEventSender( UiEvents::addStatusMessage ).SendEvent( data ); #else customMessageBoxNoModal( SL_MAIN_ICON, msg, _("Copy failed") ); #endif //this basically invalidates the handle for further use m_torr->remove_torrent( handle ); } else { wxRemoveFile( source_path ); wxLogDebug( _T("DL complete: %s"), info.m_name.c_str() ); UiEvents::StatusData data( wxString::Format( _("Download completed: %s"), info.m_name.c_str() ), 1 ); UiEvents::GetStatusEventSender( UiEvents::addStatusMessage ).SendEvent( data ); num_completed++; } } } } } if ( num_completed > 0 ) { usync().AddReloadEvent(); } }
int NoGuiSinglePlayerBattle::GetSideIndex( const wxString& name ) { wxArrayString sides = usync().GetSides( m_host_mod.name ); for ( int i = 0; i < (int)sides.Count(); ++i ) { if ( name.CmpNoCase( sides[i] ) == 0 ) return i; } return -1; }
bool Widget::GetFileInfos() { bool success = false; unsigned int file_present_count = 0; wxString sep ( wxFileName::GetPathSeparator() ); wxHTTP http; http.SetTimeout(6); http.Connect(widgetDownloader_baseUrl); wxString query_url = _T("/lua_manager.php?m=1&id=") + TowxString( w_id ); // PHP file sending XML content wxInputStream *httpStream = http.GetInputStream( query_url ); if (http.GetError() == wxPROTO_NOERR) { // will crash here, if xml content is not formatted PERFECTLY wxXmlDocument xml(*httpStream); wxXmlNode *node = xml.GetRoot() ? xml.GetRoot()->GetChildren() : NULL; while (node) { int id = FromwxString<long>( node->GetPropVal( _T("ID"), TowxString( invalid_id ) ) ); if ( id != invalid_id ) { WidgetFile file; file.id = id; wxXmlNode* item = node->GetChildren(); while( item ) { wxString item_name = item->GetName(); if ( item_name == _T("Url") ) { file.url = item->GetNodeContent(); } else if ( item_name == _T("MD5") ) { file.md5 = item->GetNodeContent(); } else if ( item_name == _T("LocalPath") ) { file.local_path = item->GetNodeContent(); file_present_count += usync().FileExists( file.local_path ); } item = item->GetNext(); } extendedinfo.files.push_back( file ); } node = node->GetNext(); success = true; } } http.Close(); wxDELETE(httpStream); if ( file_present_count == extendedinfo.files.size() ) is_installed = true; return success; }
void AddBotDialog::ShowAIInfo() { m_add_btn->Enable( m_ai->GetStringSelection() != wxEmptyString ); if ( !usync().VersionSupports( IUnitSync::USYNC_GetSkirmishAI ) ) return; m_ai_infos_lst->DeleteAllItems(); wxArrayString info = usync().GetAIInfos( GetAIType() ); int count = info.GetCount(); for ( int i = 0; i < count; i = i + 3 ) { long index = m_ai_infos_lst->InsertItem( i, info[i] ); m_ai_infos_lst->SetItem( index, 0, info[i] ); m_ai_infos_lst->SetItem( index, 1, info[i+1] ); } m_ai_infos_lst->SetColumnWidth( 0, wxLIST_AUTOSIZE ); m_ai_infos_lst->SetColumnWidth( 1, wxLIST_AUTOSIZE ); Layout(); SetSize( wxDefaultSize ); }
bool Customizations::GetBitmap( const wxString& key, wxBitmap& bitmap ) { if ( Provides( key ) ) { const wxString path = m_customs.getSingleValue( key ); #ifdef SL_QT_MODE wxBitmap icon_bmp ( wxQtConvertImage( usync().GetQImage( m_modname, path, false ) ) ); #else wxBitmap icon_bmp (usync().GetImage( m_modname, path, false ) ); #endif if( icon_bmp.IsOk() ) { bitmap = icon_bmp; return true; } } return false;//either loaded bmp was kaput or key not found }
void IBattle::SetLocalMap(const UnitSyncMap& map) { if ( map.name != m_local_map.name || map.hash != m_local_map.hash ) { m_local_map = map; m_map_loaded = true; if ( !m_host_map.hash.IsEmpty() && m_host_map.hash != '0' ) m_map_exists = usync().MapExists( m_host_map.name, m_host_map.hash ); else m_map_exists = usync().MapExists( m_host_map.name ); #ifndef __WXMSW__ if ( m_map_exists && !spring().IsRunning() ) usync().PrefetchMap( m_host_map.name ); #endif if ( IsFounderMe() ) // save all rects infos { } } }
void BattleRoomTab::SetMap( int index ) { if ( !m_battle ) return; try { UnitSyncMap map = usync().GetMapEx( index ); m_battle->SetLocalMap( map ); m_battle->SendHostInfo( IBattle::HI_Map ); } catch ( ... ) {} }
void BattleroomListCtrl::UpdateUser( User& user ) { if ( !user.BattleStatus().spectator ) icons().SetColourIcon( user.BattleStatus().team, user.BattleStatus().colour ); wxArrayString sides = usync().GetSides( m_battle->GetHostModName() ); ASSERT_EXCEPTION( user.BattleStatus().side < (long)sides.GetCount(), _T("Side index too high") ); user.SetSideiconIndex( icons().GetSideIcon( m_battle->GetHostModName(), user.BattleStatus().side ) ); int index = GetIndexFromData( &user ); UpdateUser( index ); }
wxString BattleroomListCtrl::GetItemText(long item, long column) const { if ( item == -1 || item >= (long)m_data.size()) return _T(""); const User& user = *GetDataFromIndex( item ); bool is_bot = user.BattleStatus().IsBot(); bool is_spec = user.BattleStatus().spectator; if ( column == m_faction_column_index ) { try { wxArrayString sides = usync().GetSides( m_battle->GetHostModName() ); ASSERT_EXCEPTION( user.BattleStatus().side < (long)sides.GetCount(), _T("Side index too high") ); } catch ( ... ) { return wxString::Format( _T("s%d"), user.BattleStatus().side + 1 ); } return _T(""); } if ( column == m_nick_column_index ) return is_bot ? user.GetNick() + _T(" (") + user.BattleStatus().owner + _T(")") : user.GetNick(); if ( column == m_team_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d"), user.BattleStatus().team + 1 ); if ( column == m_ally_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d"), user.BattleStatus().ally + 1 ); if ( column == m_cpu_column_index ) { if (!is_bot ) return wxString::Format( _T("%.1f GHz"), user.GetCpu() / 1000.0 ); else { //!TODO could prolly be cached wxString botname = user.BattleStatus().aishortname; if ( !user.BattleStatus().aiversion.IsEmpty() ) botname += _T(" ") + user.BattleStatus().aiversion; if ( !usync().VersionSupports( IUnitSync::USYNC_GetSkirmishAI ) ) { if ( botname.Find(_T('.')) != wxNOT_FOUND ) botname = botname.BeforeLast(_T('.')); if ( botname.Find(_T('/')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('/')); if ( botname.Find(_T('\\')) != wxNOT_FOUND ) botname = botname.AfterLast(_T('\\')); if ( botname.Find(_T("LuaAI:")) != wxNOT_FOUND ) botname = botname.AfterFirst(_T(':')); } return botname; } } if ( column == m_resourcebonus_column_index ) return is_spec ? _T("") : wxString::Format( _T("%d%%"), user.BattleStatus().handicap ); if ( column == m_country_column_index ) return _T(""); return _T(""); }
void BattleMapTab::ReloadMaplist() { if ( !m_battle ) return; m_map_combo->Clear(); wxArrayString maplist = usync().GetMapList(); // maplist.Sort(CompareStringIgnoreCase); size_t nummaps = maplist.Count(); for ( size_t i = 0; i < nummaps; i++ ) m_map_combo->Insert( maplist[i], i ); }
int IconImageList::GetSideIcon( const wxString& modname, int side ) { wxArrayString sides = usync().GetSides( modname ); wxString sidename; if( side < (int)sides.GetCount() ) sidename = sides[side]; wxString cachestring = modname + _T("_") + sidename; if (m_cached_side_icons.find(cachestring) == m_cached_side_icons.end()){ try { int IconPosition = Add(wxBitmap( usync().GetSidePicture( modname , sidename ) ), wxNullBitmap); m_cached_side_icons[cachestring] = IconPosition; return IconPosition; } catch (...) { if ( side == 0 ) m_cached_side_icons[cachestring] = ICON_SIDEPIC_0; else m_cached_side_icons[cachestring] = ICON_SIDEPIC_1; } } return m_cached_side_icons[cachestring]; }
void SpringOptionsTab::SetupUserFolders() { wxString sep = wxFileName::GetPathSeparator(); wxString defaultdir = wxFileName::GetHomeDir() + sep + _T( ".spring" ); int result = wxMessageBox( _( "Do you want to change spring's datadir location? (select yes only if you know what you're doing)" ), _( "Data dir wizard" ), wxICON_QUESTION | wxYES_NO, &ui().mw() ); if ( result != wxYES ) return; wxString dir = wxDirSelector( _( "Choose a folder" ), defaultdir ); if ( dir.IsEmpty() || ( !tryCreateDirectory( dir, 0775 ) || ( !tryCreateDirectory( dir + sep + _T( "mods" ), 0775 ) || !tryCreateDirectory( dir + sep + _T( "maps" ), 0775 ) || !tryCreateDirectory( dir + sep + _T( "base" ), 0775 ) || !tryCreateDirectory( dir + sep + _T( "demos" ), 0775 ) || !tryCreateDirectory( dir + sep + _T( "screenshots" ), 0775 ) ) ) ) { if ( dir.IsEmpty() ) dir = defaultdir; wxMessageBox( _( "Something went wrong when creating the directories\nPlease create manually the following folders:" ) + wxString( _T( "\n" ) ) + dir + _T( "\n" ) + dir + sep + _T( "mods\n" ) + dir + sep + _T( "maps\n" ) + dir + sep + _T( "base\n" ) ); return; } if ( usync().IsLoaded() ) { usync().SetSpringDataPath( dir ); } // copy uikeys.txt wxPathList pl; pl.AddEnvList( _T( "%ProgramFiles%" ) ); pl.AddEnvList( _T( "XDG_DATA_DIRS" ) ); pl = sett().GetAdditionalSearchPaths( pl ); wxString uikeyslocation = pl.FindValidPath( _T( "uikeys.txt" ) ); if ( !uikeyslocation.IsEmpty() ) { wxCopyFile( uikeyslocation, sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T( "uikeys.txt" ), false ); } }
void AddBotDialog::ShowAIOptions() { if ( !usync().VersionSupports( IUnitSync::USYNC_GetSkirmishAI ) ) return; m_opts_list->DeleteAllItems(); m_opt_list_map.clear(); m_battle.CustomBattleOptions().loadAIOptions( m_battle.GetHostModName(), GetAIType(), GetNick() ); AddMMOptionsToList( 0, m_battle.CustomBattleOptions().GetAIOptionIndex( GetNick() ) ); m_opts_list->SetColumnWidth( 0, wxLIST_AUTOSIZE ); m_opts_list->SetColumnWidth( 1, wxLIST_AUTOSIZE ); Layout(); SetSize( wxDefaultSize ); }
QImage MinimapImageProvider::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; const wxImage h = usync().GetMinimap( TowxString( id ), width, height ); if (size) *size = QSize(width,height); const QImage q = wxQtConvertImage( h ); assert( !q.isNull() ); return q.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); }
void SpringDebugReport::AddVFSFile( const wxString& fn, const wxString& id ) { wxString dir = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator(); AddFile( dir + fn, id ); return;//TODO: wtf is there a return here? wxArrayString res = usync().FindFilesVFS( fn ); if ( res.Count() > 0 ) { AddFile( res[0], id ); wxLogError( _T("SpringDebugReport: file found: "), res[0].c_str() ); } else wxLogError( _T("SpringDebugReport: file not found: "), fn.c_str() ); }
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 }
const UnitSyncMod& IBattle::LoadMod() { if ( !m_mod_loaded ) { try { ASSERT_EXCEPTION( m_mod_exists, _T("Mod does not exist.") ); m_local_mod = usync().GetMod( m_host_mod.name ); bool options_loaded = CustomBattleOptions().loadOptions( OptionsWrapper::ModOption, m_host_mod.name ); ASSERT_EXCEPTION( options_loaded, _T("couldn't load the mod options") ); m_mod_loaded = true; } catch (...) {} } return m_local_mod; }