wxString mapSelectDialog(bool hidden, wxWindow* parent){ wxString mapname = wxEmptyString; assert( (hidden && parent!=NULL) || (!hidden && parent==NULL)); //at the first call, the window is created hidden static MapSelectDialog* m = new MapSelectDialog(parent); if ( (!hidden) && (m->ShowModal() == wxID_OK) && (m->GetSelectedMap() != NULL) ) { mapname = TowxString(m->GetSelectedMap()->name); } return mapname; }
wxString ChatLog::GetCurrentLogfilePath() const { #ifdef TEST return wxFileName::GetTempDir() + _T("/sltest.log"); #else const wxString serverdir = SlPaths::SantinizeFilename(STD_STRING(sett().GetDefaultServer())); return TowxString(SlPaths::GetChatLogLoc()) + serverdir + wxFileName::GetPathSeparator() + m_logname + _T( ".txt" ); #endif }
SinglePlayerBattle::SinglePlayerBattle(MainSinglePlayerTab& msptab) : m_sptab(msptab) , m_me(STD_STRING(cfg().ReadString("/Spring/DefaultName"))) { OnUserAdded(m_me); m_me.BattleStatus().side = sett().GetBattleLastSideSel(TowxString(GetHostGameName())); m_me.BattleStatus().colour = wxColourTolsl(sett().GetBattleLastColour()); CustomBattleOptions().setSingleOption("startpostype", LSL::Util::ToIntString(ST_Pick), LSL::Enum::EngineOption); }
wxString AddBotDialog::Get(const std::string& section) { const auto sel = m_ai->GetSelection(); const auto infos = LSL::usync().GetAIInfos(sel); const auto namepos = LSL::Util::IndexInSequence(infos, section); if (namepos == LSL::lslNotFound) return m_ais[sel]; return TowxString(infos[namepos + 1]); }
void DownloadOptionsPanel::OnNewDirectory(wxCommandEvent&) { wxDirDialog pick(this, _("Choose a directory for downloading"), wxPathOnly(TowxString(SlPaths::GetDownloadDir())), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (pick.ShowModal() == wxID_OK) { m_DownloadDirectoryTextCtrl->SetValue(pick.GetPath()); } }
void UserActions::SetPeopleList( const wxArrayString& friends, const wxString& group ) { unsigned int friendsCount = friends.GetCount(); cfg().DeleteGroup( _T( "/Groups/" ) + group + _T( "/Members/" ) ); for ( unsigned int i = 0; i < friendsCount ; i++ ) { cfg().Write( _T( "/Groups/" ) + group + _T( "/Members/" ) + TowxString( i ), friends[i] ); } }
void BattleMapTab::ReloadMaplist() { if ( !m_battle ) return; m_map_combo->Clear(); LSL::StringVector maps = LSL::usync().GetMapList(); for (const std::string map: maps) { m_map_combo->Append(TowxString(map)); } }
static std::string FixPresetName( const std::string& name ) { // look name up case-insensitively const wxArrayString& presetList = sett().GetPresetList(); int index = presetList.Index( TowxString(name), false /*case insensitive*/ ); if ( index == -1 ) return ""; // set preset to the actual name, with correct case return STD_STRING(presetList[index]); }
int AddFlagImages( wxImageList& imgs ) { int poszero = 0; for ( int i = 0; flag_xpm[i]; ++i ) { const int index = imgs.Add( wxBitmap( const_cast<const char**>( flag_xpm[i] ) ) ); if ( i == 0 ) poszero = index; m_name_to_pos[TowxString( flag_str[i] )] = i; } return poszero; }
void BattleroomMMOptionsTab::UpdateOptControls(const wxString& controlName) { if (!m_battle) return; long gameoption; controlName.BeforeFirst(sep).ToLong(&gameoption); const auto optKey = STD_STRING(controlName.AfterFirst(sep)); if (gameoption == LSL::Enum::PrivateOptions) { if (optKey == "mapname") OnReloadControls(LSL::Enum::MapOption); if (optKey == "gamename") OnReloadControls(LSL::Enum::ModOption); return; } if (m_chkbox_map.find(controlName) != m_chkbox_map.end()) { const long value = LSL::Util::FromIntString( m_battle->CustomBattleOptions().getSingleValue(optKey, (LSL::Enum::GameOption)gameoption)); wxCheckBox* cur = m_chkbox_map[controlName]; cur->SetValue(value); } if (m_combox_map.find(controlName) != m_combox_map.end()) { wxComboBox* cur = m_combox_map[controlName]; cur->SetValue(TowxString((m_battle->CustomBattleOptions() .GetNameListOptValue(optKey, (LSL::Enum::GameOption)gameoption)))); } if (m_textctrl_map.find(controlName) != m_textctrl_map.end()) { const wxString value = TowxString(m_battle->CustomBattleOptions() .getSingleValue(optKey, (LSL::Enum::GameOption)gameoption)); wxTextCtrl* cur = m_textctrl_map[controlName]; cur->SetValue(value); } if (m_spinctrl_map.find(controlName) != m_spinctrl_map.end()) { const long value = LSL::Util::FromIntString( m_battle->CustomBattleOptions().getSingleValue(optKey, (LSL::Enum::GameOption)gameoption)); wxSpinCtrlDouble* cur = m_spinctrl_map[controlName]; cur->SetValue(value); } }
void BattleRoomTab::OnSetModDefaultPreset(wxCommandEvent& /*unused*/) { if (!m_battle) return; wxArrayString choices = lslTowxArrayString(m_battle->GetPresetList()); int result = wxGetSingleChoiceIndex(_("Pick an existing option set from the list"), _("Set game default preset"), choices); if (result < 0) return; sett().SetModDefaultPresetName(TowxString(m_battle->GetHostModName()), choices[result]); }
void Battle::RingNotSyncedAndNotReadyPlayers() { for (user_map_t::size_type i = 0; i < GetNumUsers(); i++) { User& u = GetUser(i); UserBattleStatus& bs = u.BattleStatus(); if ( bs.IsBot() ) continue; if ( ( !bs.sync || !bs.ready ) && !bs.spectator ) m_serv.Ring( TowxString(u.GetNick())); } }
void ChatPanelMenu::OnUserMenuAddToGroup(wxCommandEvent& event) { int id = event.GetId(); if (m_user_menu) { wxString groupname = m_user_menu->GetGroupByEvtID(id); const User* user = m_chatpanel->GetSelectedUser(); if (user) useractions().AddUserToGroup(groupname, TowxString(user->GetNick())); } }
bool Widget::GetImageInfos() { bool success = false; wxHTTP http; http.SetTimeout(6); http.Connect(widgetDownloader_baseUrl); wxString query_url = _T("/lua_manager.php?m=4&id=") + TowxString( n_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 ) { WidgetImage file; file.id = id; wxXmlNode* item = node->GetChildren(); while( item ) { wxString item_name = item->GetName(); if ( item_name == _T("Url") ) { file.url = item->GetNodeContent(); } item = item->GetNext(); } extendedinfo.images.push_back( file ); } node = node->GetNext(); success = true; } } http.Close(); wxDELETE(httpStream); return success; }
SinglePlayerBattle::SinglePlayerBattle(MainSinglePlayerTab& msptab ): m_sptab(msptab), m_me( User(STD_STRING(sett().GetDefaultNick()))) { OnUserAdded( m_me ); m_me.BattleStatus().side = sett().GetBattleLastSideSel(TowxString(GetHostModName())); m_me.BattleStatus().colour = sett().GetBattleLastColour(); CustomBattleOptions().setSingleOption( "startpostype", LSL::Util::ToString(ST_Pick), LSL::OptionsWrapper::EngineOption ); ConnectGlobalEvent(this, GlobalEvent::OnUnitsyncReloaded, wxObjectEventFunction(&SinglePlayerBattle::OnUnitsyncReloaded)); }
void NickListCtrl::SetTipWindowText(const long item_hit, const wxPoint& position) { int column = getColumnFromPosition(position); if (column > (int)m_colinfovec.size() || column < 0 || item_hit < 0 || item_hit > (long)m_data.size() || m_data[item_hit] == NULL) { m_tiptext = wxEmptyString; return; } const User& user = *m_data[item_hit]; switch (column) { case 0: // status m_tiptext = _T( "This " ); if (user.GetStatus().bot) m_tiptext << _T( "bot " ); else if (user.GetStatus().moderator) m_tiptext << _T( "moderator " ); else m_tiptext << _T( "player " ); if (user.GetStatus().in_game) m_tiptext << _T( "is ingame" ); else if (user.GetStatus().away) m_tiptext << _T( "is away" ); else m_tiptext << _T( "is available" ); break; case 1: // country m_tiptext = GetFlagNameFromCountryCode(TowxString(user.GetCountry()).Upper()); break; case 2: // rank m_tiptext = TowxString(user.GetRankName(user.GetStatus().rank)); break; case 3: // nickname m_tiptext = TowxString(user.GetNick()); break; default: m_tiptext = m_colinfovec[column].tip; break; } }
void Channel::Left( User& who, const std::string& reason ) { RemoveUser(who.GetNick()); //wxLogDebugFunc( wxEmptyString ); if ( uidata.panel == 0 ) { wxLogError( _T("OnUserLeftChannel: ud->panel NULL") ); return; } uidata.panel->Parted( who, TowxString(reason)); }
void ServerEvents::OnBattleOpened(int id, BattleType type, NatType nat, const std::string& nick, const std::string& host, int port, int maxplayers, bool haspass, int rank, const std::string& maphash, const std::string& engineName, const std::string& engineVersion, const std::string& map, const std::string& title, const std::string& mod) { slLogDebugFunc(""); try { ASSERT_EXCEPTION(!m_serv.BattleExists(id), _T("New battle from server, but already exists!")); IBattle& battle = m_serv._AddBattle(id); User& user = m_serv.GetUser(nick); battle.OnUserAdded(user); battle.SetBattleType(type); battle.SetNatType(nat); battle.SetFounder(nick); battle.SetHostIp(host); battle.SetHostPort(port); battle.SetMaxPlayers(maxplayers); battle.SetIsPassworded(haspass); battle.SetRankNeeded(rank); battle.SetHostMap(map, maphash); battle.SetDescription(title); battle.SetHostGame(mod, ""); battle.SetEngineName(engineName); battle.SetEngineVersion(engineVersion); if (useractions().DoActionOnUser(UserActions::ActNotifBattle, TowxString(user.GetNick()))) { actNotifBox(SL_MAIN_ICON, TowxString(user.GetNick()) + _(" opened battle ") + TowxString(title)); } if (!m_serv.IsOnline()) { //login info isn't complete yet return; } ui().OnBattleOpened(battle); if (user.Status().in_game) { battle.SetInGame(true); battle.StartSpring(); } } catch (std::runtime_error& except) { } }
InfoDialog::InfoDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, _("Paths"), wxDefaultPosition, wxSize(620, 400), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxCLOSE_BOX) { m_main_sizer = new wxBoxSizer(wxVERTICAL); typedef std::vector<std::pair<std::string, wxString> > Paths; Paths paths; paths.push_back(std::make_pair(SlPaths::GetLobbyWriteDir(), _T("LobbyWriteDir"))); paths.push_back(std::make_pair(SlPaths::GetCachePath(), _T("CachePath"))); paths.push_back(std::make_pair(SlPaths::GetExecutableFolder(), _T("ExecutableFolder"))); paths.push_back(std::make_pair(SlPaths::GetDownloadDir(), _T("DownloadDir"))); paths.push_back(std::make_pair(SlPaths::GetDataDir(), _T("Current SpringData:"))); wxTextCtrl* out = new wxTextCtrl(this, wxNewId(), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_AUTO_URL); *out << TowxString(getSpringlobbyAgent()) + _T("\n"); *out << wxString::Format(_T("SpringLobby config file: %s (%s writable)\n"), TowxString(SlPaths::GetConfigPath()).c_str(), BtS(wxFileName::IsFileWritable(TowxString(SlPaths::GetConfigPath())), "", "not").c_str()); for (size_t i = 0; i < paths.size(); ++i) { const wxString path = TowxString(paths[i].first); *out << wxString::Format(_T("%s (%s)\n"), paths[i].second.c_str(), path.c_str()); const bool wx = wxFileName::IsDirWritable(path); const bool posix = access(STD_STRING(path).c_str(), WRITABLE) == 0; bool tried = false; try { std::ofstream of; const wxString dummy_fn = path + wxFileName::GetPathSeparator() + _T("dummy.txt"); of.open(STD_STRING(dummy_fn).c_str()); if (of.is_open()) { of << "fhreuohgeiuhguie"; of.flush(); of.close(); tried = wxRemoveFile(dummy_fn); } } catch (...) { } *out << wxString::Format(_T("\tWX: %s POSIX: %s TRY: %s\n"), BtS(wx).c_str(), BtS(posix).c_str(), BtS(tried).c_str()); } *out << wxString::Format(_T("Current unitsync: %s\n"), TowxString(SlPaths::GetUnitSync()).c_str()); *out << wxString::Format(_T("Current spring executable: %s\n"), TowxString(SlPaths::GetSpringBinary()).c_str()); *out << wxString::Format(_T("Current uikeys.txt: %s\n"), TowxString(SlPaths::GetUikeys()).c_str()); *out << wxString::Format(_T("Portable mode: %s\n"), BtS(SlPaths::IsPortableMode()).c_str()); *out << wxString::Format(_T("Compiled with wxWidgets %d.%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, wxSUBRELEASE_NUMBER) + _T("\n"); *out << _T("Started with: \n"); for (int i = 0; i < wxTheApp->argc; ++i) *out << wxTheApp->argv[i] << _T(" "); m_main_sizer->Add(out, 1, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0); SetSizer(m_main_sizer); Layout(); }
void SingleOptionDialog::OnOk(wxCommandEvent& /*unused*/) { const auto optFlag = (LSL::Enum::GameOption)FromwxString(m_tag.BeforeFirst('_')); const std::string key = STD_STRING(m_tag.AfterFirst('_')); wxString value; if (m_textctrl) value = m_textctrl->GetValue(); else if (m_combobox) value = TowxString(m_battle.CustomBattleOptions() .GetNameListOptItemKey(key, STD_STRING(m_combobox->GetValue()), optFlag)); else if (m_spinctrl) { double d = m_spinctrl->GetValue(); value = wxString::Format(_T("%f"), d); wxLogMessage(_T("Got VALUE: %s -- %f"), value.c_str(), d); } else if (m_checkbox) value = TowxString(m_checkbox->GetValue()); m_battle.CustomBattleOptions().setSingleOption(key, STD_STRING(value), optFlag); m_battle.SendHostInfo(STD_STRING(m_tag)); EndModal(wxID_OK); }
void ServerEvents::OnNewUser(const std::string& nick, const std::string& country, int cpu, int id) { slLogDebugFunc(""); if (m_serv.UserExists(nick)) { wxLogWarning("New user from server, but already exists: %s", nick.c_str()); return; } User& user = m_serv._AddUser(nick); user.SetCountry(country); user.SetCpu(cpu); user.SetID(id); if (!m_serv.IsOnline()) { //login info isn't complete yet return; } ui().OnUserOnline(user); if (useractions().DoActionOnUser(UserActions::ActNotifLogin, TowxString(nick))) { actNotifBox(SL_MAIN_ICON, TowxString(nick) + _(" just connected")); } }
std::string _GetHandle() { std::vector<unsigned char> mac; std::string res; if (GetMac(mac)) { res.assign(mac.begin(), mac.end()); wxLogDebug(_T("Found mac: %s"), TowxString(MacToString(mac)).c_str()); return std::string(mac.begin(), mac.end()); } return res; }
Statusbar::Statusbar( wxWindow* parent ) :wxStatusBar( parent, wxNewId() ), m_addMessageSink( this, &GetStatusEventSender(UiEvents::addStatusMessage) ), m_removeMessageSink( this, &GetStatusEventSender(UiEvents::removeStatusMessage) ) { int w[3] = {460,-1,120}; SetFieldsCount( 3, w ); PushStatusText( TowxString(getSpringlobbyVersion()), 1 ); taskBar = new TaskBar(this); }
// ------------------------------------------------------------------------------------------------------------------------ /// /// Read out Host's CPU Speed /// /// \return Sum of each CPU's Speed of this Computer /// /// // ------------------------------------------------------------------------------------------------------------------------ wxString GetHostCPUSpeed() { int cpu_count = 0; int max_cpu_speed=0; #ifdef __WXMSW__ //afaik there is no way to determine the number of sub keys for a given key //so i'll hardcode some value here and hope bd doesn't hit me with a stick :P for (int i = 0; i< 16; ++i) { wxRegKey programreg( _T("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\")+ wxFormat(_T("%d") ) % i); long tmp; if ( programreg.QueryValue( _T("~MHz"), &tmp ) ) { if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; cpu_count++; } } #else wxTextFile file( _T("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq") ); if ( file.Exists() ) { file.Open(); wxString line = file.GetFirstLine(); cpu_count++; int tmp = s2l( line ); tmp /= 1000; if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; } else { wxTextFile file( _T("/proc/cpuinfo") ); if ( file.Exists() ) { file.Open(); for ( wxString line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine() ) { if ( line.Left(7) == _T("cpu MHz") ) { line = line.AfterLast( _T(' ') ).BeforeLast( _T('.') ); cpu_count++; int tmp = s2l( line ); if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; } } } } #endif return TowxString( LSL::Util::Clamp( max_cpu_speed,0,max_cpu_speed ) ); }
void MapGridCtrl::SelectMap(MapData* map) { if ((map != NULL) && (m_selected_map != map)) { m_selected_map = map; wxCommandEvent evt(MapSelectedEvt, GetId()); evt.SetEventObject(this); evt.SetString(TowxString(m_selected_map->name)); wxPostEvent(this, evt); Refresh(); } }
GameOptions SpringUnitSync::GetAIOptions( const wxString& modname, int index ) { wxLogDebugFunc( TowxString(index) ); GameOptions ret; int count = susynclib().GetAIOptionCount(modname, index); for (int i = 0; i < count; ++i) { GetOptionEntry( i, ret ); } return ret; }
void ChatPanelMenu::OnChannelMenuRegister(wxCommandEvent& /*unused*/) { if (!HasChanserv()) return; wxString text = TowxString(m_chatpanel->m_channel->GetMe().GetNick()); if (!ui().AskText(_("Register Channel"), _("Who should be appointed founder of this channel?"), text)) return; SayChanserv("!REGISTER #" + m_chatpanel->m_channel->GetName() + " " + STD_STRING(text)); }
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 BattleRoomTab::ReloadMaplist() { if (!m_battle) return; m_map_combo->Clear(); const wxArrayString maplist = lslTowxArrayString(LSL::usync().GetMapList()); size_t nummaps = maplist.Count(); for (size_t i = 0; i < nummaps; i++) m_map_combo->Insert(maplist[i], i); m_map_combo->SetValue(TowxString(m_battle->GetHostMapName())); }
wxArrayString UserActions::GetPeopleList(const wxString& group) const { wxArrayString list; slConfig::PathGuard pathGuard(&cfg(), _T( "/Groups/" ) + group + _T( "/Members/" )); unsigned int friendsCount = cfg().GetNumberOfEntries(false); for (unsigned int i = 0; i < friendsCount; i++) { wxString ToAdd; if (cfg().Read(_T( "/Groups/" ) + group + _T( "/Members/" ) + TowxString(i), &ToAdd)) list.Add(ToAdd); } return list; }