CUtlString CUtlString::Slice( int32 nStart, int32 nEnd ) const { int length = Length(); if ( length == 0 ) { return CUtlString(); } if ( nStart < 0 ) nStart = length - (-nStart % length); else if ( nStart >= length ) nStart = length; if ( nEnd == INT32_MAX ) nEnd = length; else if ( nEnd < 0 ) nEnd = length - (-nEnd % length); else if ( nEnd >= length ) nEnd = length; if ( nStart >= nEnd ) return CUtlString(); const char *pIn = String(); CUtlString ret; ret.SetDirect( pIn + nStart, nEnd - nStart ); return ret; }
bool Unserialize( CUtlBuffer &buf, CUtlString &dest ) { int nLen = buf.PeekDelimitedStringLength( s_pConv ); dest.SetLength( nLen - 1 ); // -1 because the length returned includes space for \0 buf.GetDelimitedString( s_pConv, dest.Get(), nLen ); return buf.IsValid(); }
//============================================================================= void DownloadCampaign::OnCommand(const char *command) { if ( Q_stricmp( command, "Continue" ) == 0 ) { CUtlString dest; if ( V_strnicmp( "http:", m_webSite.Get(), 4 ) != 0 || V_strnicmp( "https:", m_webSite.Get(), 4 ) != 0 ) { dest = "http://"; dest += m_webSite; } else { dest = m_webSite; } system()->ShellExecute("open", dest.Get() ); NavigateBack(); } else if ( Q_stricmp( command, "Back" ) == 0 ) { CBaseModPanel::GetSingleton().PlayUISound( UISOUND_BACK ); NavigateBack(); } else { BaseClass::OnCommand( command ); } }
void CBaseGameStats_Driver::PossibleMapChange( void ) { #ifdef GAME_DLL //detect and copy map changes if ( Q_stricmp( m_PrevMapName.String(), STRING( gpGlobals->mapname ) ) ) { MEM_ALLOC_CREDIT(); CUtlString PrevMapBackup = m_PrevMapName; m_PrevMapName = STRING( gpGlobals->mapname ); gamestats->Event_MapChange( PrevMapBackup.String(), STRING( gpGlobals->mapname ) ); if ( gamestats->UseOldFormat() ) { if( gamestats->AutoSave_OnMapChange() ) gamestats->SaveToFileNOW(); if( gamestats->AutoUpload_OnMapChange() ) gamestats->UploadStatsFileNOW(); } } #endif }
void C_HudMapInfo::LevelInitPostEntity() { KeyValuesAD mapInfo("MapInfo"); MapData *pData = g_pMapCache->GetCurrentMapData(); if (pData) { mapInfo->SetString("mapName", pData->m_szMapName); CUtlString authors; if (pData->GetCreditString(&authors, CREDIT_AUTHOR)) { mapInfo->SetString("authors", authors.Get()); m_pMapAuthorLabel->SetText(CConstructLocalizedString(m_wMapAuthors, (KeyValues*)mapInfo)); } mapInfo->SetInt("difficulty", pData->m_MainTrack.m_iDifficulty); m_pMapDifficultyLabel->SetText(CConstructLocalizedString(m_wMapDifficulty, (KeyValues*)mapInfo)); } else { mapInfo->SetString("mapName", g_pGameRules->MapName()); m_pMapAuthorLabel->SetText(""); m_pMapDifficultyLabel->SetText(""); } m_pMapNameLabel->SetText(CConstructLocalizedString(m_wMapName, (KeyValues*)mapInfo)); }
CUtlString CUtlString::Replace( const char *pszFrom, const char *pszTo ) const { Assert( pszTo ); // Can be 0 length, but not null Assert( pszFrom && *pszFrom ); // Must be valid and have one character. const char *pos = V_strstr( String(), pszFrom ); if ( !pos ) { return *this; } const char *pFirstFound = pos; // count number of search string int nSearchCount = 0; int nSearchLength = V_strlen( pszFrom ); while ( pos ) { nSearchCount++; int nSrcOffset = ( pos - String() ) + nSearchLength; pos = V_strstr( String() + nSrcOffset, pszFrom ); } // allocate the new string int nReplaceLength = V_strlen( pszTo ); int nAllocOffset = nSearchCount * ( nReplaceLength - nSearchLength ); size_t srcLength = Length(); CUtlString strDest; size_t destLength = srcLength + nAllocOffset; strDest.SetLength( destLength ); // find and replace the search string pos = pFirstFound; int nDestOffset = 0; int nSrcOffset = 0; while ( pos ) { // Found an instance int nCurrentSearchOffset = pos - String(); int nCopyLength = nCurrentSearchOffset - nSrcOffset; V_strncpy( strDest.GetForModify() + nDestOffset, String() + nSrcOffset, nCopyLength + 1 ); nDestOffset += nCopyLength; V_strncpy( strDest.GetForModify() + nDestOffset, pszTo, nReplaceLength + 1 ); nDestOffset += nReplaceLength; nSrcOffset = nCurrentSearchOffset + nSearchLength; pos = V_strstr( String() + nSrcOffset, pszFrom ); } // making sure that the left over string from the source is the same size as the left over dest buffer Assert( destLength - nDestOffset == srcLength - nSrcOffset ); if ( destLength - nDestOffset > 0 ) { V_strncpy( strDest.GetForModify() + nDestOffset, String() + nSrcOffset, destLength - nDestOffset + 1 ); } return strDest; }
CUtlString CUtlString::StripFilename() const { const char *pFilename = V_UnqualifiedFileName( Get() ); // NOTE: returns 'Get()' on failure, never NULL int nCharsToCopy = pFilename - Get(); CUtlString result; result.SetDirect( Get(), nCharsToCopy ); result.StripTrailingSlash(); return result; }
CUtlString CUtlString::Replace( char cFrom, char cTo ) { CUtlString ret = *this; int len = ret.Length(); for ( int i=0; i < len; i++ ) { if ( ret.m_Storage[i] == cFrom ) ret.m_Storage[i] = cTo; } return ret; }
bool GameModes::GetLastActiveNameId( char *pOutBuffer, int nOutBufferSize ) { if ( g_CurrentModeIdSave.IsEmpty() ) return false; int nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() ); if ( nActive == -1 ) return false; V_strncpy( pOutBuffer, g_CurrentModeIdSave.String(), nOutBufferSize ); return true; }
pfnConditionsMet CInstructor::GetBaseConditions(const CUtlString& sConditions) { if (sConditions == "WhoCares") return WhoCaresConditions; else if (sConditions == "ValidPlayer") return ValidPlayerConditions; else if (sConditions == "PlayerAlive") return PlayerAliveConditions; else if (sConditions == "PlayerDead") return PlayerDeadConditions; else if (sConditions == "PlayerCanReload") return PlayerCanReloadConditions; else if (sConditions == "PlayerOutOfAmmoAndMultipleWeapons") return PlayerOutOfAmmoAndMultipleWeaponsConditions; else if (sConditions == "PlayerHasMultipleWeapons") return PlayerHasMultipleWeaponsConditions; else if (sConditions == "PlayerActiveWeaponHasAimIn") return PlayerActiveWeaponHasAimInConditions; else if (sConditions == "PlayerHasGrenades") return PlayerHasGrenadesConditions; else if (sConditions == "PlayerHasSlowMo") return PlayerHasSlowMoConditions; else if (sConditions == "PlayerInThirdPerson") return PlayerInThirdPersonConditions; Assert(false); Error(std::string("Couldn't find lesson condition '").append(sConditions.Get()).append("'\n").c_str()); return NULL; }
CUtlString CUtlString::Replace( char cFrom, char cTo ) const { if (!m_pString) { return CUtlString(); } CUtlString ret = *this; int len = ret.Length(); for ( int i=0; i < len; i++ ) { if ( ret.m_pString[i] == cFrom ) ret.m_pString[i] = cTo; } return ret; }
bool CAnimateSpecificTexture::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { char const* pszAnimateOnTexture = pKeyValues->GetString( "onlyAnimateOnTexture" ); if( !pszAnimateOnTexture ) return false; m_OnlyAnimateOnTexture.Set( pszAnimateOnTexture ); return CBaseAnimatedTextureProxy::Init( pMaterial, pKeyValues ); }
bool CUtlString::operator==( const CUtlString &src ) const { if ( IsEmpty() ) { if ( src.IsEmpty() ) { return true; } return false; } else { if ( src.IsEmpty() ) { return false; } return Q_strcmp( m_pString, src.m_pString ) == 0; } }
//----------------------------------------------------------------------------- // Paints the overlay text //----------------------------------------------------------------------------- void CMiniViewportEngineRenderArea::PaintOverlayText( ) { if ( !m_OverlayText.Length() ) return; int cw, ch; GetSize( cw, ch ); int nTextWidth, nTextHeight; int nBufLen = m_OverlayText.Length()+1; wchar_t *pTemp = (wchar_t*)_alloca( nBufLen * sizeof(wchar_t) ); ::MultiByteToWideChar( CP_UTF8, 0, m_OverlayText.Get(), -1, pTemp, nBufLen ); g_pMatSystemSurface->GetTextSize( m_OverlayTextFont, pTemp, nTextWidth, nTextHeight ); int lx = (cw - nTextWidth) / 2; if ( lx < 10 ) { lx = 10; } int ly = ch - 10 - nTextHeight; g_pMatSystemSurface->DrawColoredTextRect( m_OverlayTextFont, lx, ly, cw - lx, ch - ly, 255, 255, 255, 255, m_OverlayText.Get() ); }
static HANDLE CreateTempFile( CUtlString &WritePath, CUtlString &FileName ) { char tempFileName[MAX_PATH]; if ( WritePath.IsEmpty() ) { // use a safe name in the cwd char *pBuffer = tmpnam( NULL ); if ( !pBuffer ) { return INVALID_HANDLE_VALUE; } if ( pBuffer[0] == '\\' ) { pBuffer++; } if ( pBuffer[strlen( pBuffer )-1] == '.' ) { pBuffer[strlen( pBuffer )-1] = '\0'; } V_snprintf( tempFileName, sizeof( tempFileName ), "_%s.tmp", pBuffer ); } else { // generate safe name at the desired prefix char uniqueFilename[MAX_PATH]; SYSTEMTIME sysTime; \ GetLocalTime( &sysTime ); sprintf( uniqueFilename, "%d_%d_%d_%d_%d.tmp", sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds ); \ V_ComposeFileName( WritePath.String(), uniqueFilename, tempFileName, sizeof( tempFileName ) ); } FileName = tempFileName; HANDLE hFile = CreateFile( tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); return hFile; }
static HANDLE CreateTempFile( CUtlString &WritePath, CUtlString &FileName ) { char tempFileName[MAX_PATH]; if ( WritePath.IsEmpty() ) { // use a safe name in the cwd char *pBuffer = tmpnam( NULL ); if ( !pBuffer ) { return INVALID_HANDLE_VALUE; } if ( pBuffer[0] == '\\' ) { pBuffer++; } if ( pBuffer[strlen( pBuffer )-1] == '.' ) { pBuffer[strlen( pBuffer )-1] = '\0'; } V_snprintf( tempFileName, sizeof( tempFileName ), "_%s.tmp", pBuffer ); } else { char uniqueFilename[MAX_PATH]; static int counter = 0; time_t now = time( NULL ); struct tm *tm = localtime( &now ); sprintf( uniqueFilename, "%d_%d_%d_%d_%d.tmp", tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec, ++counter ); \ V_ComposeFileName( WritePath.String(), uniqueFilename, tempFileName, sizeof( tempFileName ) ); } FileName = tempFileName; FILE *hFile = fopen( tempFileName, "rw+" ); return (HANDLE)hFile; }
void CInstructor::DisplayLesson(const CUtlString& sLesson) { if (!lesson_enable.GetBool()) return; if (!m_bActive) return; if (sLesson.Length() == 0 || m_apLessons.Find(sLesson) == -1) { int iLesson = m_apLessons.Find(m_sCurrentLesson); if (m_apLessons[iLesson] && m_apLessons[iLesson]->m_bKillOnFinish) SetActive(false); HideLesson(); return; } HideLesson(); m_sCurrentLesson = sLesson; m_sLastLesson = m_sCurrentLesson; CLesson* pLesson = m_apLessons[m_apLessons.Find(sLesson)]; C_SDKPlayer *pLocalPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if (pLesson->m_iLearningMethod == CLesson::LEARN_DISPLAYING) pLocalPlayer->Instructor_LessonLearned(sLesson); pLocalPlayer->Instructor_LessonShowed(sLesson); int iLessonTrainings = pLocalPlayer->Instructor_GetLessonTrainings(sLesson); if (pLesson->m_sSideHintText.Length() && iLessonTrainings == 0) { CHudElement* pLessonPanel = gHUD.FindElement("CHudSideHintPanel"); static_cast<CHudSideHintPanel*>(pLessonPanel)->SetLesson(pLesson); m_bSideHintShowing = true; } else { CHudElement* pLessonPanel = gHUD.FindElement("CHudLessonPanel"); static_cast<CHudLessonPanel*>(pLessonPanel)->SetLesson(pLesson); } }
virtual void OnTick() { BaseClass::OnTick(); double ultotal = 0.0; double ulnow = 0.0; if ( YouTube_GetUploadProgress( m_uploadHandle, ultotal, ulnow ) == false ) { Close(); ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Failure", "#GameUI_OK" ); } else if ( YouTube_IsUploadFinished( m_uploadHandle ) ) { bool bSuccess = true; CUtlString strURLToVideo; CUtlString strURLToVideoStats; if ( YouTube_GetUploadResults( m_uploadHandle, bSuccess, strURLToVideo, strURLToVideoStats ) && bSuccess ) { // mark movie uploaded m_pMovie->SetUploaded( true ); m_pMovie->SetUploadURL( strURLToVideoStats.Get() ); g_pReplayMovieManager->FlagMovieForFlush( m_pMovie, true ); // update the UI CReplayDetailsPanel *pDetailsPanel = dynamic_cast< CReplayDetailsPanel *>( GetParent() ); if ( pDetailsPanel ) { pDetailsPanel->InvalidateLayout( true, false ); } ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Success", "#GameUI_OK", NULL, GetParent() ); // notify the GC uint64 uSessionId = g_pClientReplayContext->GetServerSessionId( m_pMovie->GetReplayHandle() ); if ( uSessionId != 0 ) { GCSDK::CProtoBufMsg< CMsgReplayUploadedToYouTube > msg( k_EMsgGCReplay_UploadedToYouTube ); msg.Body().set_youtube_url( strURLToVideoStats.Get() ); msg.Body().set_youtube_account_name( YouTube_GetLoginName() ); msg.Body().set_session_id( uSessionId ); GCClientSystem()->BSendMessage( msg ); } surface()->PlaySound( "replay\\youtube_uploadfinished.wav" ); UploadOgsData( m_pMovie, true, "completed" ); // share on Steam Community if ( steamapicontext && steamapicontext->SteamRemoteStorage() ) { CUtlString strPreviewFileName; AppId_t nConsumerAppId = steamapicontext->SteamUtils()->GetAppID(); ERemoteStoragePublishedFileVisibility eVisibility = k_ERemoteStoragePublishedFileVisibilityPublic; SteamParamStringArray_t tags; tags.m_ppStrings = NULL; tags.m_nNumStrings = 0; // don't bother waiting for result SteamAPICall_t hSteamAPICall = steamapicontext->SteamRemoteStorage()->PublishVideo( k_EWorkshopVideoProviderNone, "", strURLToVideo.Get(), strPreviewFileName.Get(), nConsumerAppId, m_strTitle.Get(), m_strDescription.Get(), eVisibility, &tags ); hSteamAPICall; } } else { ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Failure", "#GameUI_OK" ); surface()->PlaySound( "replay\\youtube_uploadfailed.wav" ); UploadOgsData( m_pMovie, true, "failed" ); } // close wait dialog YouTube_ClearUploadResults( m_uploadHandle ); Close(); } else { float flProgress = MIN( ulnow / MAX( ultotal, 1.0 ), 1.0f ); int iProgress = int( 100.0 * flProgress ); int ulnow_kb = uint32( ulnow / 1024 ); int ultotal_kb = uint32( ultotal / 1024 ); if ( ulnow_kb == ultotal_kb ) { // we tick at 500 ms, so this should be ok m_iTick = ( m_iTick + 1 ) % 4; switch ( m_iTick ) { case 0: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing1" ) ); break; case 1: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing2" ) ); break; case 2: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing3" ) ); break; case 3: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing4" ) ); break; } } else { wchar_t wszProgress[1024]; wchar_t wszPercentage[32]; wchar_t wszNow[32]; wchar_t wszTotal[32]; _snwprintf( wszPercentage, ARRAYSIZE( wszPercentage ), L"%u", iProgress ); _snwprintf( wszNow, ARRAYSIZE( wszNow ), L"%u", ulnow_kb ); _snwprintf( wszTotal, ARRAYSIZE( wszTotal ), L"%u", ultotal_kb ); g_pVGuiLocalize->ConstructString( wszProgress,sizeof( wszProgress ), g_pVGuiLocalize->Find( "#YouTube_UploadProgress" ), 3, wszPercentage, wszNow, wszTotal ); SetDialogVariable( "duration", wszProgress ); } if ( m_pProgressBar ) { m_pProgressBar->SetProgress( flProgress ); } } }
/* ============== GetToken ============== */ qboolean GetToken (qboolean crossline) { char *token_p; if (tokenready) // is a token allready waiting? { tokenready = false; return true; } // printf("script_p %x (%x)\n", script->script_p, script->end_p ); fflush( stdout ); if (script->script_p >= script->end_p) { return EndOfScript (crossline); } tokenready = false; // skip space, ctrl chars skipspace: while (*script->script_p <= 32) { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } if (*(script->script_p++) == '\n') { if (!crossline) { Error ("Line %i is incomplete\n",scriptline); } scriptline = ++script->line; } } if (script->script_p >= script->end_p) { return EndOfScript (crossline); } // strip single line comments if (*script->script_p == ';' || *script->script_p == '#' || // semicolon and # is comment field (*script->script_p == '/' && *((script->script_p)+1) == '/')) // also make // a comment field { if (!crossline) Error ("Line %i is incomplete\n",scriptline); while (*script->script_p++ != '\n') { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } } scriptline = ++script->line; goto skipspace; } // strip out matching /* */ comments if (*script->script_p == '/' && *((script->script_p)+1) == '*') { script->script_p += 2; while (*script->script_p != '*' || *((script->script_p)+1) != '/') { if (*script->script_p++ != '\n') { if (script->script_p >= script->end_p) { return EndOfScript (crossline); } scriptline = ++script->line; } } script->script_p += 2; goto skipspace; } // copy token to buffer token_p = token; if (*script->script_p == '"') { // quoted token script->script_p++; while (*script->script_p != '"') { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &token[MAXTOKEN]) Error ("Token too large on line %i\n",scriptline); } script->script_p++; } else if ( g_bCheckSingleCharTokens && !g_sSingleCharTokens.IsEmpty() && strchr( g_sSingleCharTokens.String(), *script->script_p ) != NULL ) { *token_p++ = *script->script_p++; } else // regular token while ( *script->script_p > 32 && *script->script_p != ';') { if ( !ExpandMacroToken( token_p ) ) { if ( !ExpandVariableToken( token_p ) ) { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &token[MAXTOKEN]) Error ("Token too large on line %i\n",scriptline); } } } // add null to end of token *token_p = 0; // check for other commands if ( !stricmp( token, "$include" ) ) { GetToken( false ); bool bFallbackToToken = true; CUtlVector< CUtlString > expandedPathList; if ( CmdLib_ExpandWithBasePaths( expandedPathList, token ) > 0 ) { for ( int i = 0; i < expandedPathList.Count(); ++i ) { CUtlVector< CUtlString > findFileList; FindFileAbsoluteList( findFileList, expandedPathList[i].String() ); if ( findFileList.Count() > 0 ) { bFallbackToToken = false; // Only add the first set of glob matches from the first base path for ( int j = 0; j < findFileList.Count(); ++j ) { AddScriptToStack( const_cast< char * >( findFileList[j].String() ) ); } break; } } } if ( bFallbackToToken ) { AddScriptToStack( token ); } return GetToken( crossline ); } else if (!stricmp (token, "$definemacro")) { GetToken (false); DefineMacro(token); return GetToken (crossline); } else if (!stricmp (token, "$definevariable")) { GetToken (false); DefineVariable(token); return GetToken (crossline); } else if (AddMacroToStack( token )) { return GetToken (crossline); } return true; }
void GameModes::ApplySettings( KeyValues *pInResourceData ) { BaseClass::ApplySettings( pInResourceData ); vgui::HScheme hScheme = vgui::scheme()->GetScheme( "SwarmScheme" ); vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( hScheme ); if ( !pScheme ) return; const char *pImageName = pInResourceData->GetString( "borderimage", "" ); m_nBorderImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nBorderImageId == -1 ) { m_nBorderImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nBorderImageId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "leftarrow", "" ); m_nLeftArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nLeftArrowId == -1 ) { m_nLeftArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nLeftArrowId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "rightarrow", "" ); m_nRightArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nRightArrowId == -1 ) { m_nRightArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nRightArrowId, pImageName, true, false ); } m_nPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picoffsetx", 0 ) ); m_nPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picwidth", 0 ) ); m_nPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picheight", 0 ) ); m_nMenuTitleX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlex", 0 ) ); m_nMenuTitleY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitley", 0 ) ); m_nMenuTitleWide = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlewide", 0 ) ); m_nMenuTitleTall = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitletall", 0 ) ); m_nSubPics = pInResourceData->GetInt( "subpics", 0 ); m_nSubPicGap = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicgap", 0 ) ); m_nSubPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsetx", 0 ) ); m_nSubPicOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsety", 0 ) ); m_nSubPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicwidth", 0 ) ); m_nSubPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicheight", 0 ) ); m_bHideLabels = !!vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "hidelabels", 0 ) ); m_nArrowWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowwidth", 0 ) ); m_nArrowHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowheight", 0 ) ); m_nArrowOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowoffsety", 0 ) ); m_nRightArrowOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "rightarrowoffsetx", 0 ) ); m_hNameFont = pScheme->GetFont( pInResourceData->GetString( "subpicnamefont", "" ), true ); m_nNameFontHeight = vgui::surface()->GetFontTall( m_hNameFont ); const char *pNavUp = pInResourceData->GetString( "navUp", "" ); const char *pNavDown = pInResourceData->GetString( "navDown", "" ); int wideAtOpen = pInResourceData->GetInt( "wideatopen", 0 ); // need to reset due to video mode change, alt+tab, etc m_GameModeInfos.Purge(); // find all modes for ( KeyValues *pModeKey = pInResourceData->GetFirstTrueSubKey(); pModeKey; pModeKey = pModeKey->GetNextTrueSubKey() ) { pImageName = pModeKey->GetString( "image", "" ); int nImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( nImageId == -1 ) { nImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( nImageId, pImageName, true, false ); } int iIndex = m_GameModeInfos.AddToTail(); m_GameModeInfos[iIndex].m_NameId = pModeKey->GetString( "id", "" ); m_GameModeInfos[iIndex].m_NameText = pModeKey->GetString( "name", "" ); m_GameModeInfos[iIndex].m_CommandText = pModeKey->GetString( "command", "" ); m_GameModeInfos[iIndex].m_TitleText = pModeKey->GetString( "menutitle", "" ); m_GameModeInfos[iIndex].m_HintText = pModeKey->GetString( "menuhint", "" ); m_GameModeInfos[iIndex].m_HintTextDisabled = pModeKey->GetString( "menuhintdisabled", "" ); m_GameModeInfos[iIndex].m_nImageId = nImageId; m_GameModeInfos[iIndex].m_bEnabled = pModeKey->GetBool( "enabled", true ); m_GameModeInfos[iIndex].m_pHybridButton = new BaseModHybridButton( this, m_GameModeInfos[iIndex].m_NameId, m_GameModeInfos[iIndex].m_TitleText, this->GetParent(), m_GameModeInfos[iIndex].m_CommandText ); KeyValues *pKV = new KeyValues( "BtnGameMode" ); int buttonX = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleX ); int buttonY = vgui::scheme()->GetProportionalNormalizedValue( m_nPicHeight + m_nMenuTitleY ); int buttonW = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleWide ); int buttonH = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleTall ); pKV->SetInt( "xpos", buttonX ); pKV->SetInt( "ypos", buttonY ); pKV->SetInt( "wide", buttonW ); pKV->SetInt( "tall", buttonH ); pKV->SetInt( "autoResize", 1 ); pKV->SetInt( "pinCorner", 0 ); pKV->SetInt( "visible", 0 ); pKV->SetInt( "enabled", m_GameModeInfos[iIndex].m_bEnabled ); pKV->SetInt( "tabPosition", 0 ); if ( IsX360() ) { pKV->SetString( "navUp", pNavUp ); pKV->SetString( "navDown", pNavDown ); } pKV->SetString( "tooltiptext", m_GameModeInfos[iIndex].m_HintText ); pKV->SetString( "disabled_tooltiptext", m_GameModeInfos[iIndex].m_HintTextDisabled ); pKV->SetString( "style", "GameModeButton" ); pKV->SetInt( "ActivationType", 1 ); pKV->SetString( "EnableCondition", pModeKey->GetString( "EnableCondition", "" ) ); pKV->SetInt( "wideatopen", wideAtOpen ); m_GameModeInfos[iIndex].m_pHybridButton->ApplySettings( pKV ); pKV->deleteThis(); } m_nMenuTitleActualTall = m_nMenuTitleTall; if ( m_GameModeInfos.Count() ) { // get the real size m_nMenuTitleActualTall = m_GameModeInfos[0].m_pHybridButton->GetTall(); // fixup the number of subpics to what we actually have // one active plus any subpics can only show the modes with no repeat m_nSubPics = MIN( m_nSubPics, m_GameModeInfos.Count() - 1 ); } else { m_nSubPics = 0; } // exact size fixup width to get hardware clipping on rhs int panelWidth, panelHeight; GetSize( panelWidth, panelHeight ); panelWidth = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX + ( m_nSubPics + 1 ) * m_nSubPicWidth + m_nSubPics * m_nSubPicGap; panelHeight = m_nPicHeight + m_nMenuTitleY + ( m_nMenuTitleActualTall - m_nMenuTitleTall )/2 + m_nMenuTitleTall; SetSize( panelWidth, panelHeight ); // calc the arrow position for drawing and hit testing m_nSubPicX = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX; m_nSubPicY = ( m_nPicHeight + m_nMenuTitleY + m_nMenuTitleTall - m_nSubPicHeight )/2 + m_nSubPicOffsetY; m_nLeftArrowX = m_nPicOffsetX - m_nSubPicGap - m_nArrowWidth; m_nLeftArrowY = m_nSubPicY + m_nSubPicHeight - m_nArrowHeight + m_nArrowOffsetY; if ( m_nRightArrowOffsetX ) { m_nRightArrowX = m_nPicOffsetX + m_nPicWidth + m_nSubPicGap + m_nRightArrowOffsetX; } else { m_nRightArrowX = m_nSubPicX + m_nSubPics * ( m_nSubPicWidth + m_nSubPicGap ); } m_nRightArrowY = m_nLeftArrowY; // try to put back our last known game mode // this is to solve the navigation to children when the navigation has been lost // or alt+tab, video mode resize m_nActive = 0; if ( !g_CurrentModeIdSave.IsEmpty() ) { m_nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() ); if ( m_nActive == -1 ) { // no longer available g_CurrentModeIdSave = NULL; m_nActive = 0; } } SetActiveGameMode( m_nActive, true ); }
static bool ModelNamesLessFunc( CUtlString const &pLHS, CUtlString const &pRHS ) { return CaselessStringLessThan( pLHS.Get(), pRHS.Get() ); }
bool CUtlString::MatchesPattern( const CUtlString &Pattern, int nFlags ) { const char *pszSource = String(); const char *pszPattern = Pattern.String(); bool bExact = true; while( 1 ) { if ( ( *pszPattern ) == 0 ) { return ( (*pszSource ) == 0 ); } if ( ( *pszPattern ) == '*' ) { pszPattern++; if ( ( *pszPattern ) == 0 ) { return true; } bExact = false; continue; } int nLength = 0; while( ( *pszPattern ) != '*' && ( *pszPattern ) != 0 ) { nLength++; pszPattern++; } while( 1 ) { const char *pszStartPattern = pszPattern - nLength; const char *pszSearch = pszSource; for( int i = 0; i < nLength; i++, pszSearch++, pszStartPattern++ ) { if ( ( *pszSearch ) == 0 ) { return false; } if ( ( *pszSearch ) != ( *pszStartPattern ) ) { break; } } if ( pszSearch - pszSource == nLength ) { break; } if ( bExact == true ) { return false; } if ( ( nFlags & PATTERN_DIRECTORY ) != 0 ) { if ( ( *pszPattern ) != '/' && ( *pszSource ) == '/' ) { return false; } } pszSource++; } pszSource += nLength; } }
CUtlString::CUtlString( const CUtlString& string ) { Set( string.Get() ); }
//----------------------------------------------------------------------------- // String attribute //----------------------------------------------------------------------------- bool Serialize( CUtlBuffer &buf, const CUtlString &src ) { buf.PutDelimitedString( s_pConv, src.Get() ); return buf.IsValid(); }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void CDmxEditApp::PrintHelp( bool bWiki /* = false */ ) { const CDmxEditLua::LuaFunc_s *pLuaFuncs = CDmxEditLua::GetFunctionList(); if ( bWiki && pLuaFuncs ) { lua_State *pLuaState = lua_open(); if ( pLuaState ) { luaL_openlibs( pLuaState ); CUtlString wikiString; for ( int i = 0; i < CDmxEditLua::FunctionCount(); ++i ) { if ( i != 0 ) { Msg( "\n" ); } Msg( ";%s( %s );\n", pLuaFuncs[ i ].m_pFuncName, pLuaFuncs[ i ].m_pFuncPrototype ); Msg( ":%s\n", Wikize( pLuaState, pLuaFuncs[ i ].m_pFuncDesc ) ); } return; } } Msg( "\n" ); Msg( "NAME\n" ); Msg( " dmxedit - Edit dmx files\n" ); Msg( "\n" ); Msg( "SYNOPSIS\n" ); Msg( " dmxedit [ -h | -help ] [ -game <$game> ] [ -set $var=val ] [ script.lua ]\n" ); Msg( "\n" ); Msg( " -h | -help : Prints this information\n" ); Msg( " -g | -game <$game> : Sets the VPROJECT environment variable to the specified game.\n" ); Msg( " -s | -set <$var=val> : Sets the lua variable var to the specified val before the script is run.\n" ); Msg( "\n" ); Msg( "DESCRIPTION\n" ); Msg( " Edits dmx files by executing a lua script of dmx editing functions\n" ); Msg( "\n" ); if ( !pLuaFuncs ) return; Msg( "FUNCTIONS\n" ); const char *pWhitespace = " \t"; for ( int i = 0; i < CDmxEditLua::FunctionCount(); ++i ) { Msg( " %s( %s );\n", pLuaFuncs[ i ].m_pFuncName, pLuaFuncs[ i ].m_pFuncPrototype ); Msg( " * " ); CUtlString tmpStr; const char *pWordBegin = pLuaFuncs[ i ].m_pFuncDesc + strspn( pLuaFuncs[ i ].m_pFuncDesc, pWhitespace ); const char *pWhiteSpaceBegin = pWordBegin; const char *pWordEnd = pWordBegin + strcspn( pWordBegin, pWhitespace ); bool bNewline = false; while ( *pWordBegin ) { if ( pWordEnd - pWhiteSpaceBegin + tmpStr.Length() > 70 ) { if ( bNewline ) { Msg( " " ); } else { bNewline = true; } Msg( "%s\n", tmpStr ); tmpStr.Set( "" ); } if ( tmpStr.Length() ) { tmpStr += CUtlString( pWhiteSpaceBegin, pWordEnd - pWhiteSpaceBegin + 1); } else { tmpStr += CUtlString( pWordBegin, pWordEnd - pWordBegin + 1 ); } pWhiteSpaceBegin = pWordEnd; pWordBegin = pWhiteSpaceBegin + strspn( pWhiteSpaceBegin, pWhitespace ); pWordEnd = pWordBegin + strcspn( pWordBegin, pWhitespace ); } if ( tmpStr.Length() ) { if ( bNewline ) { Msg( " " ); } Msg( "%s\n", tmpStr ); } Msg( "\n" ); } Msg( "CREDITS\n" ); Msg( " Lua Copyright © 1994-2006 Lua.org, PUC-Rio.\n "); Msg( "\n" ); }
static bool Str_LessFunc( CUtlString const &a, CUtlString const &b ) { return strcmp(a.Get(), b.Get()) < 0; }
static bool ReslistLessFunc( CUtlString const &pLHS, CUtlString const &pRHS ) { return CaselessStringLessThan( pLHS.Get(), pRHS.Get() ); }
// add a binding to the list. Calls should be in the form: // AddBinding( "left", "button_press", "start", "+dota_camera_follow", "" ); // // args: // hand_str = "left" or "right" // action_str = 'button_press' 'trigger_press' 'tilt_gesture' 'point_gesture' 'velocity_gesture' or 'joystick_move' // argument_str depends on action_str, see below for details // press_command_str is the concommand executed on start of the action (ie button press) and release_command_str on stop (ie button release) // release_command_str can be the empty string if no stop action is desired // if the press_command_str begins with "+", an equivalent "-" is set to the release_command automatically void SixenseGestureBindings::AddBinding( CUtlString hand_str, CUtlString action_str, CUtlString argument_str, CUtlString press_command_str, CUtlString release_command_str ) { GestureBinding binding; // Convert from strings to enums sixenseUtils::IButtonStates::ActionType action; if( !ActionFromString( action_str, &action ) ) { return; } binding.m_Action = action; int hand; if( !HandFromString( hand_str, &hand ) ) { return; } binding.m_iHand = hand; // handle argument_str per-action type if( action == sixenseUtils::IButtonStates::ACTION_BUTTON_PRESS ) { // button_press takes a button argument unsigned short button_token; if( !ButtonMaskFromString( argument_str, &button_token ) ) { return; } binding.m_iArgument = button_token; } else if( action == sixenseUtils::IButtonStates::ACTION_TRIGGER_PRESS ) { // trigger press has no argument binding.m_iArgument = 0; } else { // all other actions take a direction sixenseUtils::IButtonStates::Direction dir; if( !DirectionFromString( argument_str, &dir ) ) { return; } binding.m_iArgument = dir; } // copy the activate command binding.m_pActivateCommand = strdup( press_command_str.String() ); binding.m_bAutoMirrored = false; // if there is an explicit release_command, use it if ( !release_command_str.IsEmpty() ) { binding.m_pDeactivateCommand = strdup( release_command_str.String() ); } else { // otherwise try to generate a release command // see if it starts with a +, if so, add an off command if( press_command_str[0] == '+' ) { binding.m_pDeactivateCommand = strdup( press_command_str.String() ); binding.m_pDeactivateCommand[0] = '-'; binding.m_bAutoMirrored = true; } else { // Just leave release command null binding.m_pDeactivateCommand = NULL; } } // Try to keep a single binding per 'action' 'hand' 'arg' pair, ie one per button. // We may want to allow multiple if people think it would be useful... FOR_EACH_LL( m_GestureBindingList, it ) { GestureBinding existing_binding = m_GestureBindingList[it]; if( binding.m_Action == existing_binding.m_Action && binding.m_iArgument == existing_binding.m_iArgument && binding.m_iHand == existing_binding.m_iHand ) { // Already the same binding active, delete it FreeStrings( existing_binding ); m_GestureBindingList.Remove( it ); break; } }
//----------------------------------------------------------------------------- // The application object //----------------------------------------------------------------------------- int CDmxEditApp::Main() { // This bit of hackery allows us to access files on the harddrive g_pFullFileSystem->AddSearchPath( "", "LOCAL", PATH_ADD_TO_HEAD ); if ( CommandLine()->CheckParm( "-h" ) || CommandLine()->CheckParm( "-help" ) ) { PrintHelp(); return 0; } if ( CommandLine()->CheckParm( "-wiki" ) ) { PrintHelp( true ); return 0; } CUtlStringMap< CUtlString > setVars; CUtlString sGame; const int nParamCount = CommandLine()->ParmCount(); for ( int i = 0; i < nParamCount - 1; ++i ) { const char *pCmd = CommandLine()->GetParm( i ); const char *pArg = CommandLine()->GetParm( i + 1 ); if ( StringHasPrefix( pCmd, "-s" ) ) { const char *const pEquals = strchr( pArg, '=' ); if ( !pEquals ) { Warning( "Warning: Invalid command line args, no ='s in -set argument: %s %s\n", pCmd, pArg ); } char buf[ BUFSIZ ]; Q_strncpy( buf, pArg, pEquals - pArg + 1 ); const CUtlString sKey( buf ); CUtlString sVal( pEquals + 1 ); if ( !isdigit( *sVal.Get() ) && *sVal.Get() != '-' && *sVal.Get() != '"' ) { CUtlString sqVal( "\"" ); sqVal += sVal; sqVal += "\""; sVal = sqVal; } setVars[ sKey ] = sVal; if ( !Q_stricmp( sKey.Get(), "game" ) && sGame.IsEmpty() ) { sGame = sKey; } ++i; } else if ( StringHasPrefix( pCmd, "-g" ) ) { if ( *pArg == '"' ) { sGame = pArg; } else { sGame = ( "\"" ); sGame += pArg; sGame += "\""; } } else if ( StringHasPrefix( pCmd, "-nop4" ) ) { // Don't issue warning on -nop4 } else if ( StringHasPrefix( pCmd, "-" ) ) { Warning( "Warning: Unknown command line argument: %s\n", pCmd ); } } // Do Perforce Stuff if ( CommandLine()->FindParm( "-nop4" ) ) g_p4factory->SetDummyMode( true ); g_p4factory->SetOpenFileChangeList( "dmxedit" ); for ( int i = CommandLine()->ParmCount() - 1; i >= 1; --i ) { const char *pParam = CommandLine()->GetParm( i ); if ( _access( pParam, 04 ) == 0 ) { CDmxEditLua dmxEditLua; for ( int i = 0; i < setVars.GetNumStrings(); ++i ) { dmxEditLua.SetVar( setVars.String( i ), setVars[ i ] ); } if ( !sGame.IsEmpty() ) { dmxEditLua.SetGame( sGame ); } return dmxEditLua.DoIt( pParam ); } } Error( "Cannot find any file to execute from passed command line arguments\n\n" ); PrintHelp(); return -1; }