// Handles a key press bool CLTGUIEditCtrl::HandleKeyDown(int key, int rep) { if (CLTGUICtrl::HandleKeyDown(key, rep)) return true; switch (key) { case VK_BACK: if (m_nCaretPos > 0) { m_nCaretPos--; RemoveCharacter(); } break; case VK_DELETE: RemoveCharacter(); break; case VK_HOME: m_nCaretPos = 0; break; case VK_END: m_nCaretPos = LTStrLen(m_Text.GetText()); break; case VK_LEFT: if (m_nCaretPos > 0) m_nCaretPos--; break; case VK_RIGHT: if (m_nCaretPos < LTStrLen(m_Text.GetText())) m_nCaretPos++; break; default: return false; } return true; }
void GetValueRange(CAI* pAI, const char* szValue, float* pfMin, float* pfMax) { HOBJECT hAI = pAI ? pAI->m_hObject : NULL; AIASSERT(szValue[0] == '[' && szValue[LTStrLen(szValue) - 1] == ']', hAI, "GetValueRange: range not in the form [min,max]"); AIASSERT(LTStrLen(szValue) < 64, hAI, "GetValueRange: range is more than 64 characters"); char szTemp[64]; LTStrCpy( szTemp, szValue + 1, LTARRAYSIZE( szTemp )); char* pTok = strtok( szTemp, "," ); *pfMin = (float)atof( pTok ); pTok = strtok( NULL, "," ); *pfMax = (float)atof( pTok ); }
void TeamPopulateEditStringList( char** aszStrings, uint32* pcStrings, const uint32 cMaxStrings, const uint32 cMaxStringLength ) { char szTeam[32] = {0}; LTASSERT(cMaxStrings > (*pcStrings) + 1, "Too many teams for stringlist."); if( *pcStrings < cMaxStrings ) { LTStrCpy( aszStrings[(*pcStrings)++], "NoTeam", cMaxStringLength ); for( int i = 0; i < MAX_TEAMS; ++i ) { LTASSERT(cMaxStrings > (*pcStrings) + 1, "Too many teams for stringlist."); // exit out early if we can't hold any more strings if( *pcStrings >= cMaxStrings ) return; LTSNPrintF( szTeam, ARRAY_LEN(szTeam), "Team%i", i ); if( (LTStrLen( szTeam ) < cMaxStringLength) && ((*pcStrings) + 1 < cMaxStrings) ) { LTStrCpy( aszStrings[(*pcStrings)++], szTeam, cMaxStringLength ); } } } // Sort the list so turret types are easier to find. Skip the first item // since it's the none selection. qsort( aszStrings + 1, *pcStrings - 1, sizeof(char *), CaseInsensitiveCompare ); }
// Remove a character from the end void CLTGUIEditCtrl::RemoveCharacter() { // Check to see have any chars if (m_Text.IsEmpty()) return; LTStrCpy(szString,m_Text.GetText(), LTARRAYSIZE(szString)); uint32 nEnd=LTStrLen(szString); if (nEnd > m_nCaretPos) { uint32 nIndex = m_nCaretPos; while (nIndex < nEnd) { szString[nIndex] = szString[nIndex+1]; nIndex++; } szString[nIndex]=L'\0'; m_Text.SetText(szString); } }
LTRESULT TurretPlugin::PreHook_EditStringList( const char *szRezPath, const char *szPropName, char **aszStrings, uint32 *pcStrings, const uint32 cMaxStrings, const uint32 cMaxStringLen ) { if( !aszStrings || !pcStrings || !g_pWeaponDB ) { LTERROR( "Invalid input parameters" ); return LT_UNSUPPORTED; } if( LTStrEquals( szPropName, "TurretType" )) { // Fill the first string in the list with a <none> selection... LTStrCpy( aszStrings[(*pcStrings)++], SELECTION_NONE, cMaxStringLen ); // Add an entry for each turret type... uint8 nNumTurrets = g_pWeaponDB->GetNumTurrets( ); for( uint8 nTurret = 0; nTurret < nNumTurrets; ++nTurret ) { LTASSERT( cMaxStrings > (*pcStrings) + 1, "Too many turret to fit in the list. Enlarge list size?" ); HTURRET hTurret = g_pWeaponDB->GetTurretRecord( nTurret ); if( !hTurret ) continue; const char *pszTurretName = g_pWeaponDB->GetRecordName( hTurret ); if( !pszTurretName ) continue; if( (LTStrLen( pszTurretName ) < cMaxStringLen) && ((*pcStrings) + 1 < cMaxStrings) ) { LTStrCpy( aszStrings[(*pcStrings)++], pszTurretName, cMaxStringLen ); } } // Sort the list so turret types are easier to find... qsort( aszStrings, *pcStrings, sizeof(char *), CaseInsensitiveCompare ); return LT_OK; } if( m_DestructibleModelPlugin.PreHook_EditStringList( szRezPath, szPropName, aszStrings, pcStrings, cMaxStrings, cMaxStringLen ) == LT_OK) { return LT_OK; } return LT_UNSUPPORTED; }
//called during the creation to extract all the unique glyphs from a string, allocate the //glyph list, and set them up with the characters they reference bool CTextureStringImage::SetupUniqueGlyphList(const wchar_t* pszString) { //determine the length of the string uint32 nStrLen = LTStrLen(pszString); //the first thing to do is build up the unique character list wchar_t* pszUniqueList; LT_MEM_TRACK_ALLOC(pszUniqueList = new wchar_t[nStrLen + 1], MEMORY_CATEGORY); if(!pszUniqueList) return false; //get the unique character list GetUniqueCharList(pszString, pszUniqueList, nStrLen + 1); //determine the number of unique characters uint32 nNumGlyphs = LTStrLen(pszUniqueList); //now allocate our glyph list LT_MEM_TRACK_ALLOC(m_pGlyphList = new CTextureStringGlyph[nNumGlyphs], MEMORY_CATEGORY); //check the allocation if(!m_pGlyphList) { delete [] pszUniqueList; return false; } //now copy over the data m_nNumGlyphs = nNumGlyphs; for(uint32 nCurrGlyph = 0; nCurrGlyph < nNumGlyphs; nCurrGlyph++) { m_pGlyphList[nCurrGlyph].m_cGlyph = pszUniqueList[nCurrGlyph]; } //free up the unique string list delete [] pszUniqueList; pszUniqueList = NULL; //and success return true; }
void LTFileOperations::AdjustPathSeparatorsForLinux(char* pszPath) { // convert backslashes to forwardslashes for (uint32 index = 0; index < LTStrLen(pszPath); ++index) { if (pszPath[index] == '\\') { pszPath[index] = '/'; } } }
LTRESULT TeamClientFXPlugin::PreHook_EditStringList( const char *szRezPath, const char *szPropName, char **aszStrings, uint32 *pcStrings, const uint32 cMaxStrings, const uint32 cMaxStringLen ) { if( !aszStrings || !pcStrings ) { LTERROR( "Invalid input parameters" ); return LT_UNSUPPORTED; } if( LTStrEquals( szPropName, "TeamClientFX" )) { // Fill the first string in the list with a <none> selection... LTStrCpy( aszStrings[(*pcStrings)++], "", cMaxStringLen ); // Add an entry for each flagbase. uint8 nNumRecords = DATABASE_CATEGORY( TeamClientFX ).GetNumRecords(); for( uint8 nRecordIndex = 0; nRecordIndex < nNumRecords; ++nRecordIndex ) { LTASSERT( cMaxStrings > (*pcStrings) + 1, "Too many items's to fit in the list. Enlarge list size?" ); HRECORD hRecord = DATABASE_CATEGORY( TeamClientFX ).GetRecordByIndex( nRecordIndex ); if( !hRecord ) continue; const char *pszRecordName = DATABASE_CATEGORY( TeamClientFX ).GetRecordName( hRecord ); if( !pszRecordName ) continue; if( (LTStrLen( pszRecordName ) < cMaxStringLen) && ((*pcStrings) + 1 < cMaxStrings) ) { LTStrCpy( aszStrings[(*pcStrings)++], pszRecordName, cMaxStringLen ); } } // Sort the list so things are easier to find. Skip the first item, since it's the <none> selection. qsort( aszStrings + 1, *pcStrings - 1, sizeof(char *), CaseInsensitiveCompare ); return LT_OK; } // Handle team... if( LTStrIEquals( "Team", szPropName )) { TeamPopulateEditStringList( aszStrings, pcStrings, cMaxStrings, cMaxStringLen ); return LT_OK; } return LT_UNSUPPORTED; }
// Add a character to the end void CLTGUIEditCtrl::AddCharacter(wchar_t c) { //add 1 for trailing 0 uint32 len = LTStrLen(m_Text.GetText()) + 1; // Check to see are at our buffer limit if (len >= m_nMaxLength) return; // strip out leading whitespace which confuses things if (LTStrEmpty(m_Text.GetText( )) && c == ' ') return; LTStrCpy(szString, m_Text.GetText(), LTARRAYSIZE(szString)); uint32 nIndex = LTStrLen(szString); while (nIndex > m_nCaretPos) { szString[nIndex] = szString[nIndex-1]; nIndex--; } szString[nIndex] = c; m_nCaretPos++; m_Text.SetText(szString); LTRect2n rExt; LTRESULT res = m_Text.GetExtents(rExt); if (res == LT_OK) { if (rExt.GetWidth() > int32(GetWidth()) ) { m_nCaretPos--; RemoveCharacter(); } } }
void CLTGUIEditCtrl::SetMaxLength(uint32 nMaxLength) { if (nMaxLength > kMaxLength) nMaxLength = kMaxLength; LTASSERT(nMaxLength > 0,"Edit ctrl max length set to 0"); if (nMaxLength == 0) nMaxLength = 1; m_nMaxLength = nMaxLength; if (m_nMaxLength <= LTStrLen(m_Text.GetText())) { LTStrCpy(szString,m_Text.GetText(), LTARRAYSIZE(szString)); szString[m_nMaxLength-1] = '\0'; m_Text.SetText(szString); } }
// Render the control void CLTGUIEditCtrl::Render () { if ( !IsVisible()) return; // Render the text m_Text.SetColor(GetCurrentColor()); m_Text.SetGlow(IsSelected()); m_Text.Render( ); g_pDrawPrim->SetRenderMode(eLTDrawPrimRenderMode_Modulate_NoBlend); // draw the caret if (IsCaretOn() && IsEnabled()) { LTRect2n rRect; uint32 len = LTStrLen(GetText()); if (m_nCaretPos > len) m_nCaretPos = len; float x = m_rfRect.Left(); float y = m_rfRect.Top(); float w = 2.0f; float h = GetHeight(); if (m_nCaretPos > 0) { LTRect2n rRect; if (m_Text.GetCharRect(m_nCaretPos-1,rRect) == LT_OK) { x = (float)rRect.Right(); } } DrawPrimSetXYWH(m_Caret,x,y,w,h); g_pDrawPrim->DrawPrim(&m_Caret); } g_pDrawPrim->SetRenderMode(eLTDrawPrimRenderMode_Modulate_Translucent); // draw our frame if (m_bUseFrame) g_pDrawPrim->DrawPrim(m_Frame,4); }
void AISoundUtils::AddToStringList( char** aszStrings, uint32* pcStrings, const uint32 cMaxStrings, const uint32 cMaxStringLength, const char* pszPrefixFilter ) { int nFilterLen = LTStrLen( pszPrefixFilter ); for ( int i = 0; ( ( i<kAIS_Count) && ((*pcStrings)+1<cMaxStrings) ); ++i ) { const char* pszAISoundTypeName = AISoundUtils::String((EnumAISoundType)i); if ( nFilterLen > 0 && !LTSubStrIEquals( pszPrefixFilter, pszAISoundTypeName, nFilterLen ) && ( i != kAIS_None ) ) { continue; } LTStrCpy( aszStrings[(*pcStrings)++], pszAISoundTypeName, cMaxStringLength ); } }
uint8 TeamStringToTeamId( char const* pszTeamString ) { if( !pszTeamString ) return INVALID_TEAM; static char const szTeam[] = "Team"; static int nLen = LTStrLen( szTeam ); uint32 nTeamId = INVALID_TEAM; if( !LTSubStrICmp( pszTeamString, szTeam, nLen )) { nTeamId = atoi( &pszTeamString[ nLen ] ); if( nTeamId >= MAX_TEAMS ) { nTeamId = INVALID_TEAM; } } return nTeamId; }
//called to allocate a string. This will allocate the characters, the string, and handle copying //them over bool CTextureString::AllocateString(const wchar_t* pszString) { //make sure we don't already have a string allocated FreeString(); if(!pszString) return false; //we now want to create a string using the other string as a base. This is done by first allocating //our characters, matching them to the appropriate glyphs, and then ordering them m_nNumCharacters = LTStrLen(pszString); //allocate our main memory block uint32 nMemBlockSize = 0; nMemBlockSize += AlignAllocSize(sizeof(CTextureStringChar) * m_nNumCharacters); nMemBlockSize += AlignAllocSize(sizeof(wchar_t) * m_nNumCharacters + 1); uint8* pMemBlock; LT_MEM_TRACK_ALLOC(pMemBlock = new uint8[nMemBlockSize], MEMORY_CATEGORY); if(!pMemBlock) { FreeString(); return false; } CMemBlockAllocator Allocator(pMemBlock, nMemBlockSize); //allocate the new buffer of characters m_pCharacters = Allocator.AllocateObjects<CTextureStringChar>(m_nNumCharacters); m_pszString = Allocator.AllocateObjects<wchar_t>(m_nNumCharacters + 1); LTStrCpy(m_pszString, pszString, m_nNumCharacters + 1); //sanity check on our memory block if ( !(Allocator.GetAllocationOffset() == Allocator.GetBlockSize())) ASSERT(!"Error: Incorrect usage of texture string memory block"); //success return true; }
bool BanIPMgr_Impl::WriteBans( ) { // If not initialized, we can't write out the bans yet. if( !m_bInitialized ) return false; // build the file name by prepending the user directory char szFilename[MAX_PATH]; LTFileOperations::GetUserDirectory(szFilename, LTARRAYSIZE(szFilename)); LTStrCat(szFilename, szBanFile, LTARRAYSIZE(szFilename)); // remove the existing file LTFileOperations::DeleteFile(szFilename); // open the new file CLTFileWrite cBanFile; if (!cBanFile.Open(szFilename, false)) { return false; } // Look through list of banned ip's. for( BanList::iterator iter = m_BanList.begin( ); iter != m_BanList.end( ); iter++ ) { ClientIP const& bannedIP = *iter; // Convert it to a string. char szClientIP[16] = ""; if( !ConvertClientIPToString( bannedIP, szClientIP, ARRAY_LEN( szClientIP ))) return false; // Write the banned IP. if (!cBanFile.Write(szClientIP, LTStrLen(szClientIP))) { return false; } } return true; }
bool CCheatMgr::Check( CParsedMsgW const &cMsg ) { wchar_t buf[100]; // copy their text LTStrCpy( buf, cMsg.GetArg(0).c_str(), ARRAY_LEN(buf) ); // convert it to cheat compatible text unsigned int i; for ( i = 0; i < LTStrLen(cMsg.GetArg(0).c_str()); i++ ) buf[i] = (((buf[i] ^ 38) + i) ^ 7) % 256; // then compare the converted text for ( i = 0; i < CHEAT_MAX; i++ ) { if ( LTStrCmp( buf, s_CheatInfo[i].pzText ) == 0) { return Process( (CheatCode)i, cMsg ); } } return false; }
void CharacterDisplay::SetText(const wchar_t* szTxt) { if (!m_hDisplayRecord) return; if ( LTStrEquals(m_Text.GetText(),szTxt ) ) { return; } if (szTxt) { m_Text.SetText(szTxt); } uint32 nLen = LTStrLen(szTxt); HRECORD hFont = DATABASE_CATEGORY( CharacterDisplayLayoutDB ).GETRECORDATTRIB( m_hLayoutRecord, Font ); char const* pszFont = DATABASE_CATEGORY( CharacterDisplayLayoutDB ).GetString( hFont, "Face" ); if (nLen <= nTextLimits[0]) { CFontInfo textFont(pszFont,m_nTextSize[0]); textFont.m_nStyle = CFontInfo::kStyle_Bold; m_Text.SetFont(textFont); } else if (nLen <= nTextLimits[1]) { CFontInfo textFont(pszFont,m_nTextSize[1]); textFont.m_nStyle = CFontInfo::kStyle_Bold; m_Text.SetFont(textFont); } else { CFontInfo textFont(pszFont,m_nTextSize[2]); textFont.m_nStyle = CFontInfo::kStyle_Bold; m_Text.SetFont(textFont); } }
//given a string and a buffer, this will fill the buffer with all the unique letters in the //string static void GetUniqueCharList(const wchar_t* pszString, wchar_t* pszBuffer, uint32 nBufferSize) { //bail on an empty bufer if(nBufferSize == 0) return; LTStrCpy(pszBuffer, pszString, nBufferSize); pszBuffer[nBufferSize - 1] = (wchar_t)'\0'; //determint the size of the string we will be modifying uint32 nStrLen = LTStrLen(pszBuffer); //only bother checking for duplicates if we have more than a single character if(nStrLen > 1) { //now sort the characters to place duplicates right next to each other std::sort(pszBuffer, pszBuffer + nStrLen); //the current end of the buffer uint32 nBufferEnd = nStrLen - 1; //now run through starting at the end, and if we find a duplicate, just move the last character over //us and bring in the end line for(uint32 nCurrChar = nBufferEnd; nCurrChar > 0; nCurrChar--) { //see if this is a duplicate character if(pszBuffer[nCurrChar] == pszBuffer[nCurrChar - 1]) { //it is, move the last character over this one, and move the end string back pszBuffer[nCurrChar] = pszBuffer[nBufferEnd]; pszBuffer[nBufferEnd] = '\0'; nBufferEnd--; } } } //we now have the buffer filled with unique characters in only O(2N + lgN) time }
bool CLTGUIEditCtrl::OnLButtonUp(int x, int y) { if (!IsOnMe(x,y)) return false; uint32 nMax = LTStrLen(m_Text.GetText()); uint32 nIndex = 0; bool bFound = false; while (nIndex < nMax && !bFound) { LTRect2n rRect; if (m_Text.GetCharRect(m_nCaretPos-1,rRect) == LT_OK) { bFound = (x < rRect.Left()); } nIndex++; } m_nCaretPos = nIndex; return true; }
bool CHUDSubtitles::Show(const char* szStringId, LTVector vSpeakerPos, float fRadius, float fDuration, bool bSubtitlePriority) { // Only show subtitles if conversations in range... LTVector vListenerPos; bool bListenerInClient; LTRotation rRot; g_pLTClient->GetListener(&bListenerInClient, &vListenerPos, &rRot); LTVector vPos = vSpeakerPos - vListenerPos; float fAdjustedRadius = fRadius * g_vtAdjustedRadius.GetFloat(); float fDist = vPos.Mag(); if (vSpeakerPos == LTVector(0, 0, 0)) fDist = 0.0f; //should we override what ever is already playing? if (m_bVisible) { //if the old one has priority, and the new doesn't, don't play the new if (m_bSubtitlePriority && !bSubtitlePriority) { return false; } //if they have the same priority, check distances if (m_bSubtitlePriority == bSubtitlePriority) { LTVector vOldPos = m_vSpeakerPos - vListenerPos; float fOldDist = vOldPos.Mag(); if (m_vSpeakerPos == LTVector(0, 0, 0)) fOldDist = 0.0f; if (fOldDist < fDist) { return false; } } } const wchar_t *pStr = LoadString(szStringId); if (LTStrEmpty(pStr)) { DebugCPrint(2,"CHUDSubtitles::Show(%s) : No Text",szStringId); return false; } m_Text.SetText(pStr); m_bVisible = true; m_bSubtitlePriority = bSubtitlePriority; m_vSpeakerPos = vSpeakerPos; m_fRadius = fRadius; m_fDuration = fDuration; if (m_fDuration < 0.0f) m_fDuration = 0.04f * (float)LTStrLen(m_Text.GetText()); LTVector2n pos = m_vBasePos; uint32 width = m_nWidth; /* if( g_pPlayerMgr->GetPlayerCamera()->GetCameraMode() == CPlayerCamera::kCM_Cinematic ) { pos = m_CinematicPos; width = m_nCinematicWidth; } */ LTVector2 vfScale = g_pInterfaceResMgr->GetScreenScale(); uint32 x = (uint32)((float)pos.x * vfScale.x); uint32 y = (uint32)((float)pos.y * vfScale.y); width = (uint32 )((float)width * vfScale.x); uint32 height = (2 + m_nMaxLines * m_sTextFont.m_nHeight) ; float fFontHeight = (float)m_sTextFont.m_nHeight; m_Rect.Init(x,y,x+width,y+height); m_Text.WordWrap(m_Rect.GetWidth()); float textX = (float)m_Rect.Left(); float textY = (float)m_Rect.Top(); LTRect2n rExt; m_Text.CreateTexture(); m_Text.GetExtents(rExt); uint32 numLines = (uint32)(rExt.GetHeight() / fFontHeight); if (numLines > m_nMaxLines) { m_bOverflow = true; float fTimePerLine = m_fDuration / ((float)numLines + 1.0f); float fDelay = (float)m_nMaxLines * fTimePerLine; m_fScrollStartTime = fDelay; m_fScrollSpeed = fFontHeight / fTimePerLine; m_fMaxOffset = (float)(rExt.GetHeight() - m_Rect.GetHeight()); } else { m_bOverflow = false; textX += (float)(m_Rect.GetWidth() - width) / 2.0f; m_fOffset = (float)(m_Rect.GetHeight() - height); textY += m_fOffset; m_fScrollSpeed = 0.0f; } m_fEndTime = m_fDuration; //reset our time to the beginning m_fElapsedTime = 0.0f; m_Text.SetPos(LTVector2(textX,textY)); return true; }
void AdjustPathCaseForLinux(char* pszPath) { // attempt to access the file struct stat64 statInfo; if (::stat64(pszPath, &statInfo) == -1) { // walk path components, doing case-insensitive find for each part char szNewPath[MAX_PATH]; char szPathComponent[MAX_PATH]; uint32 nPathIndex = 0; uint32 nNewPathIndex = 0; uint32 nPathComponentIndex = 0; ::memset(szNewPath, 0, MAX_PATH); ::memset(szPathComponent, 0, MAX_PATH); // handle first character specifying root directory if (pszPath[0] == '/') { szPathComponent[nPathComponentIndex++] = pszPath[nPathIndex]; szNewPath[nNewPathIndex++] = pszPath[nPathIndex++]; } for (nPathIndex; nPathIndex <= LTStrLen(pszPath); ++nPathIndex) { if ((pszPath[nPathIndex] == '/') || (pszPath[nPathIndex] == (char)NULL)) { // attempt to find this component szPathComponent[nPathComponentIndex] = (char)NULL; LTFINDFILEINFO cFileInfo; LTFINDFILEHANDLE hFindHandle; if (!LTFileOperations::FindFirst(szPathComponent, hFindHandle, &cFileInfo)) { // directory does not exist even with case insensitive compare return; } else { LTFileOperations::FindClose(hFindHandle); // get the actual file name and add it to new path LTStrCat(szNewPath, cFileInfo.name, MAX_PATH - LTStrLen(szNewPath)); if (cFileInfo.bIsSubdir) { LTStrCat(szNewPath, "/", MAX_PATH - LTStrLen(szNewPath)); } else { // found a leaf node so we're finished break; } // copy the new path to our working buffer as well LTSNPrintF(szPathComponent, LTARRAYSIZE(szPathComponent), "%s", szNewPath); nPathComponentIndex = LTStrLen(szPathComponent); } } else { // add the next character to our path component szPathComponent[nPathComponentIndex++] = pszPath[nPathIndex]; } } // replace with correct case version (new version will be the same length as original) LTStrCpy(pszPath, szNewPath, LTStrLen(szNewPath) + 1); } }
/// // CTimedText::Init() // void CTimedText::Init( TIMED_TEXT_INIT_STRUCT const &initData ) { // initialize the internally needed info InitInternalInfo(); // // extract the data from the initialization struct // // Visual Characteristics ASSERT( initData.text ); m_text = initData.text; m_color = ( initData.color & 0x00FFFFFF ); // get the text's position, cause we may change this // as it scrolls m_text->GetPosition( &m_posX, &m_posY ); // use dropped shadow? if ( initData.useDroppedShadow ) { SETFLAG( m_flags, CTIMEDTEXTFLAG_USE_DROPPED_SHADOW ); } else { CLEARFLAG( m_flags, CTIMEDTEXTFLAG_USE_DROPPED_SHADOW ); } if ( initData.clipRect ) { m_clipRect = *initData.clipRect; SETFLAG( m_flags, CTIMEDTEXTFLAG_USE_CLIP_RECT ); } else { // clear the clip rect if we're not using it m_clipRect.x = m_clipRect.y = m_clipRect.height = m_clipRect.width = 0; CLEARFLAG( m_flags, CTIMEDTEXTFLAG_USE_CLIP_RECT ); } m_textLen = LTStrLen( m_text->GetText() ); m_numberOfLinesBeforeScroll = initData.numberOfLinesBeforeScroll; // Timing Information m_initialDelay = initData.initialDelay; ASSERT( m_initialDelay >= 0 ); m_characterDelay = initData.characterDelay; ASSERT( m_characterDelay >= 0 ); m_lineDelay = initData.lineDelay; ASSERT( m_lineDelay >= 0 ); m_scrollTime = initData.scrollTime; ASSERT( m_scrollTime >= 0 ); m_completeDelay = initData.completeDelay; ASSERT( m_completeDelay >= 0 ); m_fadeTime = initData.fadeTime; ASSERT( m_fadeTime >= 0 ); // // Sound Information // // get character complete sound name (if any) if ( initData.textDisplaySound && initData.textDisplaySound[ 0 ] != '\0' ) { strncpy( m_textDisplaySoundName, initData.textDisplaySound, TIMED_TEXT_SOUND_NAME_LENGTH ); } // get scrolling sound name (if any) if ( initData.scrollSound && initData.scrollSound[ 0 ] != '\0' ) { strncpy( m_scrollSoundName, initData.scrollSound, TIMED_TEXT_SOUND_NAME_LENGTH ); } #ifdef TIMEDTEXT_DEBUG { // make sure strings terminate int i; bool charEndFound = false; bool scrollEndFound = false; for ( i = 0, charEndFound = false, scrollEndFound = false; ( ( i < TIMED_TEXT_SOUND_NAME_LENGTH ) && ( ( !charEndFound ) || ( !scrollEndFound ) ) ); ++i ) { if ( ( !charEndFound ) && ( m_textDisplaySoundName[ i ] == '\0' ) ) { charEndFound = true; } if ( ( !scrollEndFound ) && ( m_scrollSoundName[ i ] == '\0' ) ) { scrollEndFound = true; } } // assert if no end if found ASSERT( charEndFound ); ASSERT( scrollEndFound ); } #endif // TIMEDTEXT_DEBUG // now we're in the text writing phase m_state = CTIMEDTEXT_INITIAL_DELAY; }
// Set the text void CLTGUIEditCtrl::SetText(const wchar_t *pString) { m_Text.SetText(pString); m_nCaretPos = LTStrLen(pString); }
void CHUDDebugInput::Send() { char szPath[MAX_PATH*2]; char szTemp[MAX_PATH]; char szShotname[MAX_PATH + 1]; LTFileOperations::GetUserDirectory(szPath, LTARRAYSIZE(szPath)); LTStrCat(szPath,"DebugLog",LTARRAYSIZE(szPath)); LTStrCat(szPath,FILE_PATH_SEPARATOR,LTARRAYSIZE(szPath)); LTStrCpy(szTemp,g_pMissionMgr->GetCurrentWorldName(),LTARRAYSIZE(szTemp)); char* szWorld = strrchr(szTemp,FILE_PATH_SEPARATOR[0]); if (szWorld) { szWorld++; } else { szWorld = szTemp; } LTStrCat(szPath,szWorld,LTARRAYSIZE(szPath)); if (!CWinUtil::DirExist(szPath)) { CWinUtil::CreateDir(szPath); } LTStrCat(szPath,FILE_PATH_SEPARATOR,LTARRAYSIZE(szPath)); //determine a filename for this. This should start with the screenshot console variable and be //numbered sequentially //an upper cap to make sure that we don't attempt to create screenshots indefinitely, which could //potentially be caused by some file access issues static const uint32 knMaxScreenshotAttempts = 1000; for(uint32 nCurrScreenshotIndex = 0; nCurrScreenshotIndex < knMaxScreenshotAttempts; nCurrScreenshotIndex++) { //build up the filename to use for this screenshot LTSNPrintF(szShotname, LTARRAYSIZE(szShotname), "Screenshot%03d.jpg", nCurrScreenshotIndex); char pszFilename[MAX_PATH]; LTSNPrintF(pszFilename, LTARRAYSIZE(pszFilename), "DebugLog%s%s%s%s", FILE_PATH_SEPARATOR,szWorld,FILE_PATH_SEPARATOR,szShotname); // get the user path to the screenshot file, as we need this to check if the file exists. char pszUserFilename[MAX_PATH]; g_pLTClient->FileMgr()->GetAbsoluteUserFileName( pszFilename, pszUserFilename, LTARRAYSIZE( pszUserFilename ) ); //see if this file already exists - if it does, continue searching for an unused file if ( !LTFileOperations::FileExists( pszUserFilename ) ) { //the filename doesn't exist, so go ahead and try to make the screenshot if(g_pLTClient->GetRenderer()->MakeScreenShot(pszUserFilename) == LT_OK) { g_pLTClient->CPrint("Successfully created screenshot %s", pszUserFilename); } else { g_pLTClient->CPrint("Failed to create screenshot %s", pszUserFilename); } break; } } //report overflow if(nCurrScreenshotIndex >= knMaxScreenshotAttempts) { g_pLTClient->CPrint("Unable to create screenshot. Please make sure that the directory is readable and that there are less than %d screenshots", knMaxScreenshotAttempts); } Show(false); // Ignore empty messages. if( !m_szDebugStr[0] ) return; char szMsg[256]; static bool bUseTime = false; if (bUseTime) { time_t tmSys; time( &tmSys ); struct tm* pTimeDate = NULL; pTimeDate = localtime (&tmSys); if (pTimeDate) { LTSNPrintF(szMsg, LTARRAYSIZE( szMsg ), "<tr><td>%02d/%02d/%02d %02d:%02d:%02d</td>", pTimeDate->tm_mon + 1, pTimeDate->tm_mday, (pTimeDate->tm_year + 1900) % 100, pTimeDate->tm_hour, pTimeDate->tm_min, pTimeDate->tm_sec); } } else { LTSNPrintF(szMsg, LTARRAYSIZE( szMsg ), "<tr>"); } //determine the offset we should use on the positions LTVector vOffset(0, 0, 0); g_pLTClient->GetSourceWorldOffset(vOffset); HLOCALOBJ hPlayerObj = g_pLTClient->GetClientObject(); if (hPlayerObj) { char buf[256]; LTVector vPos; g_pLTClient->GetObjectPos(hPlayerObj, &vPos); //handle the shift from the current world to the source world vPos += vOffset; LTSNPrintF(buf, LTARRAYSIZE(buf), "<td>(pos %0.0f %0.0f %0.0f)</td>", vPos.x, vPos.y, vPos.z); LTStrCat(szMsg,buf,LTARRAYSIZE(szMsg)); } LTSNPrintF(szTemp,LTARRAYSIZE(szTemp),"<td><a href=\"%s\">%s</a></td>",szShotname,MPW2A(m_szDebugStr).c_str()); LTStrCat(szMsg,szTemp,LTARRAYSIZE(szMsg)); LTStrCat(szMsg,"</tr>\r\n",LTARRAYSIZE(szMsg)); CLTFileWrite cFileWrite; LTStrCat( szPath, "debuglog.htm", LTARRAYSIZE( szPath )); bool bNewFile = !CWinUtil::FileExist(szPath); if (cFileWrite.Open(szPath,true)) { if (bNewFile) { char szTmp[128] = "<HTML><BODY>\r\n<table>\r\n"; cFileWrite.Write(szTmp,LTStrLen(szTmp)); } cFileWrite.Write(szMsg,LTStrLen(szMsg)); cFileWrite.Close(); } }
void LTFileOperations::SplitPath(const char* pPath, char* pDirectory, char* pFileName, char* pSuffix) { if (pPath == NULL) { // no data return; } char szPathCopy[MAX_PATH]; LTStrCpy(szPathCopy, pPath, LTARRAYSIZE(szPathCopy)); AdjustPathSeparatorsForLinux(szPathCopy); int nPathLength = LTStrLen(szPathCopy); int nDirectorySeparatorIndex; if (pDirectory) { pDirectory[0] = (char)NULL; } if (pFileName) { pFileName[0] = (char)NULL; } if (pSuffix) { pSuffix[0] = (char)NULL; } bool bFoundParentDirectory = false; // search right-to-left for directory separator for (nDirectorySeparatorIndex = nPathLength - 1; nDirectorySeparatorIndex >= 0; --nDirectorySeparatorIndex) { if (szPathCopy[nDirectorySeparatorIndex] == '/') { // found separator - everything to the left is the path if (pDirectory) { LTSubStrCpy(pDirectory, szPathCopy, _MAX_DIR, nDirectorySeparatorIndex + 1); } bFoundParentDirectory = true; break; } } // break remainder into filename and suffix bool bFoundSuffix = false; int nSuffixSeparatorIndex; for (nSuffixSeparatorIndex = nPathLength - 1; nSuffixSeparatorIndex != nDirectorySeparatorIndex; --nSuffixSeparatorIndex) { if (szPathCopy[nSuffixSeparatorIndex] == '.') { // found separator - everything to the right is the suffix if (pSuffix) { LTSubStrCpy(pSuffix, szPathCopy + nSuffixSeparatorIndex, _MAX_EXT, nPathLength - nSuffixSeparatorIndex); } bFoundSuffix = true; break; } } // copy file name if necessary if (pFileName) { int nStartFileNameIndex = 0; if (bFoundParentDirectory) { // path contained a directory, put filename start after the directory separator nStartFileNameIndex = nDirectorySeparatorIndex + 1; } uint32 nSuffixLength = 0; if (bFoundSuffix) { nSuffixLength = nPathLength - nSuffixSeparatorIndex; } LTSubStrCpy(pFileName, szPathCopy + nStartFileNameIndex, _MAX_FNAME, LTStrLen(szPathCopy + nStartFileNameIndex) - nSuffixLength); } }
ProfileCache::iterator ProcessProfileFile(const char* pszFileName) { ProfileCache::iterator itCachedProfile = g_cProfileCache.end(); // open the file CLTFileRead cFileRead; if (!cFileRead.Open(pszFileName)) { // can't open it return itCachedProfile; } ProfileSections cProfileSections; // process the file line-by-line char pszLine[MAX_PATH]; char pszCurrentSection[MAX_PATH]; char pszKey[MAX_PATH]; char pszValue[MAX_PATH]; bool bIsEOF = false; while (ReadLineFromProfileFile(cFileRead, pszLine, MAX_PATH)) { if ((pszLine[0] == '\n') || (pszLine[0] == '\r') || (pszLine[0] == '#')) { // newline or comment continue; } else if (pszLine[0] == '[') { // section tag - find ending bracket char* pszRightBracket = ::index(pszLine, ']'); LTSubStrCpy(pszCurrentSection, pszLine + 1, MAX_PATH, LTStrLen(pszLine) - LTStrLen(pszRightBracket) - 1); } else { // key and value line - find the equal sign char* pszEqual = ::index(pszLine, '='); if (!pszEqual) { // no equal sign continue; } // extract the key and value LTSubStrCpy(pszKey, pszLine, MAX_PATH, LTStrLen(pszLine) - LTStrLen(pszEqual)); char* pszEOL = ::strpbrk(pszLine, "\r\n"); LTSubStrCpy(pszValue, pszEqual + 1, MAX_PATH, LTStrLen(pszEqual + 1) - LTStrLen(pszEOL)); // add them to the cache SectionMap::iterator itSection = cProfileSections.m_cSectionMap.find(pszCurrentSection); if (itSection == cProfileSections.m_cSectionMap.end()) { // add new section ProfileSectionEntries cNewProfileSectionEntries; cNewProfileSectionEntries.m_cKeyValueMap.insert(std::pair<std::string, std::string>(pszKey, pszValue)); cProfileSections.m_cSectionMap.insert(std::pair<std::string, ProfileSectionEntries>(pszCurrentSection, cNewProfileSectionEntries)); } else { // add to current section (*itSection).second.m_cKeyValueMap.insert(std::pair<std::string, std::string>(pszKey, pszValue)); } } } // add to profile cache return (g_cProfileCache.insert(std::pair<std::string, ProfileSections>(pszFileName, cProfileSections))).first; }