//----------------------------------------------------------------------------- // Purpose: Add an item to the drop down // Input : char *itemText - name of dropdown menu item //----------------------------------------------------------------------------- int ComboBox::AddItem(const wchar_t *itemText, const KeyValues *userData) { // add the element to the menu // when the menu item is selected it will send the custom message "SetText" KeyValues *kv = new KeyValues("SetText"); kv->SetWString("text", itemText); // get an ansi version for the menuitem name char ansi[128]; g_pVGuiLocalize->ConvertUnicodeToANSI(itemText, ansi, sizeof(ansi)); return m_pDropDown->AddMenuItem(ansi, kv, this, userData); }
//----------------------------------------------------------------------------- // Purpose: Updates a current item to the drop down // Input : wchar_t *itemText - name of dropdown menu item //----------------------------------------------------------------------------- bool ComboBox::UpdateItem(int itemID, const wchar_t *itemText, const KeyValues *userData) { if ( !m_pDropDown->IsValidMenuID(itemID)) return false; // when the menu item is selected it will send the custom message "SetText" KeyValues *kv = new KeyValues("SetText"); kv->SetWString("text", itemText); m_pDropDown->UpdateMenuItem(itemID, itemText, kv, userData); InvalidateLayout(); return true; }
void CQCGenerator::OnNewLODText() { KeyValues *pEditItem = m_pLODPanel->GetItem( m_nSelectedSequence ); KeyValues *pListItem = pEditItem; wchar_t szEditText[MAX_PATH]; pEditItem = pEditItem->GetFirstValue(); const char *name = pEditItem->GetName(); for( int i = 0; i < m_nSelectedColumn; i++ ) { pEditItem = pEditItem->GetNextValue(); name = pEditItem->GetName(); } m_pLODEdit->GetText( szEditText, MAX_PATH ); pListItem->SetWString( name, szEditText ); m_pLODPanel->LeaveEditMode(); m_pLODPanel->InvalidateLayout(); return; }
//----------------------------------------------------------------------------- // Add a file to the file list. //----------------------------------------------------------------------------- int PerforceFileList::AddFileToFileList( const char *pFullPath, bool bExistsOnDisk ) { bool bIsFileWriteable = bExistsOnDisk ? g_pFullFileSystem->IsFileWritable( pFullPath, NULL ) : true; // add the file to the list KeyValues *kv = new KeyValues("item"); const char *pRelativePath = Q_UnqualifiedFileName( pFullPath ); kv->SetString( "text", pRelativePath ); kv->SetString( "fullpath", pFullPath ); kv->SetInt( "image", 1 ); IImage *pImage = surface()->GetIconImageForFullPath( pFullPath ); if ( pImage ) { kv->SetPtr( "iconImage", (void *)pImage ); } kv->SetInt( "imageSelected", 1 ); kv->SetInt( "directory", 0 ); // These are computed by Refresh kv->SetInt( "in_perforce", 0 ); kv->SetInt( "synched", 0 ); kv->SetInt( "checked_out", 0 ); kv->SetInt( "deleted", 0 ); wchar_t pFileType[ 80 ]; g_pFullFileSystem->GetFileTypeForFullPath( pFullPath, pFileType, sizeof( pFileType ) ); kv->SetWString( "type", pFileType ); kv->SetString( "attributes", bIsFileWriteable ? "" : "R" ); int nItemID = AddItem( kv, 0, false, false ); kv->deleteThis(); AddItemToDirectoryList( pFullPath, nItemID, false ); return nItemID; }
//----------------------------------------------------------------------------- // Purpose: applies only the game filter to the current list //----------------------------------------------------------------------------- void CBaseGamesPage::ApplyGameFilters() { #ifndef NO_STEAM if ( !SteamMatchmakingServers() ) return; // loop through all the servers checking filters FOR_EACH_MAP_FAST( m_mapServers, i ) { serverdisplay_t &server = m_mapServers[ i ]; gameserveritem_t *pServer = SteamMatchmakingServers()->GetServerDetails( m_eMatchMakingType, server.m_iServerID ); if ( !pServer ) continue; if (!CheckPrimaryFilters( *pServer ) || !CheckSecondaryFilters( *pServer )) { // server failed filtering, remove it server.m_bDoNotRefresh = true; if ( m_pGameList->IsValidItemID( server.m_iListID) ) { // don't remove the server from list, just hide since this is a lot faster m_pGameList->SetItemVisible( server.m_iListID, false ); } } else if ( BShowServer( server ) ) { // server passed filters, so it can be refreshed again server.m_bDoNotRefresh = false; gameserveritem_t *pServer = SteamMatchmakingServers()->GetServerDetails( m_eMatchMakingType, server.m_iServerID ); // re-add item to list if ( !m_pGameList->IsValidItemID( server.m_iListID ) ) { KeyValues *kv = new KeyValues("Server"); kv->SetString("name", pServer->GetName()); kv->SetString("map", pServer->m_szMap); kv->SetString("GameDir", pServer->m_szGameDir); if ( pServer->m_szGameDescription[0] ) { kv->SetString("GameDesc", pServer->m_szGameDescription ); } else { kv->SetWString("GameDesc", g_pVGuiLocalize->Find("#ServerBrowser_PendingPing")); } int nAdjustedForBotsPlayers = max( 0, pServer->m_nPlayers - pServer->m_nBotPlayers ); int nAdjustedForBotsMaxPlayers = max( 0, pServer->m_nMaxPlayers - pServer->m_nBotPlayers ); char buf[256]; Q_snprintf(buf, sizeof(buf), "%d / %d", nAdjustedForBotsPlayers, nAdjustedForBotsMaxPlayers); kv->SetString( "Players", buf); kv->SetInt( "Ping", pServer->m_nPing ); kv->SetInt( "password", pServer->m_bPassword ? 1 : 0); if ( pServer->m_nBotPlayers > 0 ) kv->SetInt("bots", pServer->m_nBotPlayers); else kv->SetString("bots", ""); server.m_iListID = m_pGameList->AddItem(kv, server.m_iServerID, false, false); kv->deleteThis(); } // make sure the server is visible m_pGameList->SetItemVisible( server.m_iListID, true ); } }
//----------------------------------------------------------------------------- // Purpose: Handles incoming server refresh data // updates the server browser with the refreshed information from the server itself //----------------------------------------------------------------------------- void CBaseGamesPage::ServerResponded( int iServer, gameserveritem_t *pServerItem ) { int iServerMap = m_mapServers.Find( iServer ); if ( iServerMap == m_mapServers.InvalidIndex() ) { netadr_t netAdr( pServerItem->m_NetAdr.GetIP(), pServerItem->m_NetAdr.GetQueryPort() ); int iServerIP = m_mapServerIP.Find( netAdr ); if ( iServerIP != m_mapServerIP.InvalidIndex() ) { // if we already had this entry under another index remove the old entry int iServerMap = m_mapServers.Find( m_mapServerIP[ iServerIP ] ); if ( iServerMap != m_mapServers.InvalidIndex() ) { serverdisplay_t &server = m_mapServers[ iServerMap ]; if ( m_pGameList->IsValidItemID( server.m_iListID ) ) m_pGameList->RemoveItem( server.m_iListID ); m_mapServers.RemoveAt( iServerMap ); } m_mapServerIP.RemoveAt( iServerIP ); } serverdisplay_t serverFind; serverFind.m_iListID = -1; serverFind.m_bDoNotRefresh = false; iServerMap = m_mapServers.Insert( iServer, serverFind ); m_mapServerIP.Insert( netAdr, iServer ); } serverdisplay_t *pServer = &m_mapServers[ iServerMap ]; pServer->m_iServerID = iServer; Assert( pServerItem->m_NetAdr.GetIP() != 0 ); // check filters bool removeItem = false; if ( !CheckPrimaryFilters( *pServerItem ) ) { // server has been filtered at a primary level // remove from lists pServer->m_bDoNotRefresh = true; // remove from UI list removeItem = true; } else if (!CheckSecondaryFilters( *pServerItem )) { // we still ping this server in the future; however it is removed from UI list removeItem = true; } if (removeItem) { if ( m_pGameList->IsValidItemID( pServer->m_iListID ) ) { m_pGameList->RemoveItem( pServer->m_iListID ); pServer->m_iListID = GetInvalidServerListID(); } return; } // update UI KeyValues *kv; if ( m_pGameList->IsValidItemID( pServer->m_iListID ) ) { // we're updating an existing entry kv = m_pGameList->GetItem( pServer->m_iListID ); m_pGameList->SetUserData( pServer->m_iListID, pServer->m_iServerID ); } else { // new entry kv = new KeyValues("Server"); } kv->SetString("name", pServerItem->GetName()); kv->SetString("map", pServerItem->m_szMap); kv->SetString("GameDir", pServerItem->m_szGameDir); kv->SetString("GameDesc", pServerItem->m_szGameDescription); kv->SetInt("password", pServerItem->m_bPassword ? 1 : 0); if ( pServerItem->m_nBotPlayers > 0 ) kv->SetInt("bots", pServerItem->m_nBotPlayers); else kv->SetString("bots", ""); if ( pServerItem->m_bSecure ) { // show the denied icon if banned from secure servers, the secure icon otherwise kv->SetInt("secure", ServerBrowser().IsVACBannedFromGame( pServerItem->m_nAppID ) ? 4 : 3); } else { kv->SetInt("secure", 0); } kv->SetString( "IPAddr", pServerItem->m_NetAdr.GetConnectionAddressString() ); int nAdjustedForBotsPlayers = max( 0, pServerItem->m_nPlayers - pServerItem->m_nBotPlayers ); int nAdjustedForBotsMaxPlayers = max( 0, pServerItem->m_nMaxPlayers - pServerItem->m_nBotPlayers ); char buf[32]; Q_snprintf(buf, sizeof(buf), "%d / %d", nAdjustedForBotsPlayers, nAdjustedForBotsMaxPlayers); kv->SetString("Players", buf); kv->SetInt("Ping", pServerItem->m_nPing); kv->SetString("Tags", pServerItem->m_szGameTags ); if ( pServerItem->m_ulTimeLastPlayed ) { // construct a time string for last played time struct tm *now; now = localtime( (time_t*)&pServerItem->m_ulTimeLastPlayed ); if ( now ) { char buf[64]; strftime(buf, sizeof(buf), "%a %d %b %I:%M%p", now); Q_strlower(buf + strlen(buf) - 4); kv->SetString("LastPlayed", buf); } } if ( pServer->m_bDoNotRefresh ) { // clear out the vars kv->SetString("Ping", ""); kv->SetWString("GameDesc", g_pVGuiLocalize->Find("#ServerBrowser_NotResponding")); kv->SetString("Players", ""); kv->SetString("map", ""); } if ( !m_pGameList->IsValidItemID( pServer->m_iListID ) ) { // new server, add to list pServer->m_iListID = m_pGameList->AddItem(kv, pServer->m_iServerID, false, false); if ( m_bAutoSelectFirstItemInGameList && m_pGameList->GetItemCount() == 1 ) { m_pGameList->AddSelectedItem( pServer->m_iListID ); } kv->deleteThis(); } else { // tell the list that we've changed the data m_pGameList->ApplyItemChanges( pServer->m_iListID ); m_pGameList->SetItemVisible( pServer->m_iListID, true ); } UpdateStatus(); m_iServerRefreshCount++; }
void CLeaderboardsStats::OnPlayerStats(KeyValues* kv) { KeyValues *pData = kv->FindKey("data"); KeyValues *pErr = kv->FindKey("error"); if (pData) { // int mtotal = -1; // MOM_TODO // int grank = -1; // MOM_TODO // int gtotal = -1; // MOM_TODO KeyValues *pMapRank = pData->FindKey("mapRank"); if (pMapRank) { int iMapRank = pMapRank->GetInt("rank", -1); if (iMapRank == -1) pMapRank->SetWString("mRank", g_pVGuiLocalize->Find("MOM_NotApplicable")); else pMapRank->SetInt("mRank", iMapRank); const auto iRankXP = pMapRank->GetInt("rankXP", -1); if (iRankXP == -1) pMapRank->SetWString("rankXP", g_pVGuiLocalize->Find("MOM_NotApplicable")); else pMapRank->SetInt("rankXP", iRankXP); pMapRank->SetWString("time", g_pVGuiLocalize->Find("MOM_NotApplicable")); KeyValues *pRun = pMapRank->FindKey("run"); if (pRun) { float seconds = pRun->GetFloat("time"); if (seconds > 0.0f) { char sPersonalBestTime[BUFSIZETIME]; MomUtil::FormatTime(seconds, sPersonalBestTime); pMapRank->SetString("time", sPersonalBestTime); } } } KeyValues *pUserStats = pData->FindKey("stats"); if (pUserStats) { // MOM_TODO: fill in these // grank = static_cast<int>(pExperience->GetFloat("rank")); // gtotal = static_cast<int>(pExperience->GetFloat("total")); m_pPlayerLevel->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_Level"), pUserStats)); m_pPlayerCosXP->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_CosXP"), pUserStats)); m_pMapsCompleted->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_MapsCompleted"), pUserStats)); m_pRunsSubmitted->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_RunsSubmitted"), pUserStats)); m_pTotalJumps->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_TotalJumps"), pUserStats)); m_pTotalStrafes->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_TotalStrafes"), pUserStats)); } m_pPlayerMapRank->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_MapRank"), pMapRank)); m_pPlayerRankXP->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_RankXP"), pMapRank)); m_pPlayerPersonalBest->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_PersonalBestTime"), pMapRank)); /*if (grank > -1 && gtotal > -1) { char p_sGlobalRank[BUFSIZELOCL]; char p_sLocalized[BUFSIZELOCL]; LOCALIZE_TOKEN(p_wcGlobalRank, "MOM_GlobalRank", p_sGlobalRank); Q_snprintf(p_sLocalized, BUFSIZELOCL, "%s: %i/%i", p_sGlobalRank, grank, gtotal); m_pPlayerGlobalRank->SetText(p_sLocalized); }*/ } else if (pErr) { // MOM_TODO: Handle errors } }
void CKeyBindingHelpDialog::PopulateList() { m_pList->DeleteAllItems(); int i, j; CUtlVector< ListInfo_t > maps; vgui2::Panel *pPanel = m_hPanel; while ( pPanel->IsKeyBindingChainToParentAllowed() ) { PanelKeyBindingMap *map = pPanel->GetKBMap(); while ( map ) { int k; int c = maps.Count(); for ( k = 0; k < c; ++k ) { if ( maps[k].m_pMap == map ) break; } if ( k == c ) { int mapIndex = maps.AddToTail( ); maps[mapIndex].m_pMap = map; maps[mapIndex].m_pPanel = pPanel; } map = map->baseMap; } pPanel = pPanel->GetParent(); if ( !pPanel ) break; } CUtlRBTree< KeyValues *, int > sorted( 0, 0, BindingLessFunc ); // add header item int c = maps.Count(); for ( i = 0; i < c; ++i ) { PanelKeyBindingMap *m = maps[ i ].m_pMap; Panel *pMapPanel = maps[i].m_pPanel; Assert( m ); int bindings = m->boundkeys.Count(); for ( j = 0; j < bindings; ++j ) { BoundKey_t *kbMap = &m->boundkeys[ j ]; Assert( kbMap ); // Create a new: blank item KeyValues *item = new KeyValues( "Item" ); // Fill in data char loc[ 128 ]; Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname ); char ansi[ 256 ]; AnsiText( loc, ansi, sizeof( ansi ) ); item->SetString( "Action", ansi ); item->SetWString( "Binding", Panel::KeyCodeModifiersToDisplayString( (KeyCode)kbMap->keycode, kbMap->modifiers ) ); // Find the binding KeyBindingMap_t *bindingMap = pMapPanel->LookupBinding( kbMap->bindingname ); if ( bindingMap && bindingMap->helpstring ) { AnsiText( bindingMap->helpstring, ansi, sizeof( ansi ) ); item->SetString( "Description", ansi ); } item->SetPtr( "Item", kbMap ); sorted.Insert( item ); } // Now try and find any "unbound" keys... int mappings = m->entries.Count(); for ( j = 0; j < mappings; ++j ) { KeyBindingMap_t *kbMap = &m->entries[ j ]; // See if it's bound CUtlVector< BoundKey_t * > list; pMapPanel->LookupBoundKeys( kbMap->bindingname, list ); if ( list.Count() > 0 ) continue; // Not bound, add a placeholder entry // Create a new: blank item KeyValues *item = new KeyValues( "Item" ); // fill in data char loc[ 128 ]; Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname ); char ansi[ 256 ]; AnsiText( loc, ansi, sizeof( ansi ) ); item->SetString( "Action", ansi ); item->SetWString( "Binding", L"" ); if ( kbMap->helpstring ) { AnsiText( kbMap->helpstring, ansi, sizeof( ansi ) ); item->SetString( "Description", ansi ); } item->SetPtr( "Unbound", kbMap ); sorted.Insert( item ); } } for ( j = sorted.FirstInorder() ; j != sorted.InvalidIndex(); j = sorted.NextInorder( j ) ) { KeyValues *item = sorted[ j ]; // Add to list m_pList->AddItem( item, 0, false, false ); item->deleteThis(); } sorted.RemoveAll(); }