void CHudChatFilterButton::DoClick( void ) { BaseClass::DoClick(); CBaseHudChat *pChat = dynamic_cast < CBaseHudChat * > (GetParent() ); if ( pChat ) { pChat->GetChatInput()->RequestFocus(); if ( pChat->GetChatFilterPanel() ) { if ( pChat->GetChatFilterPanel()->IsVisible() ) { pChat->GetChatFilterPanel()->SetVisible( false ); } else { pChat->GetChatFilterPanel()->SetVisible( true ); pChat->GetChatFilterPanel()->MakePopup(); pChat->GetChatFilterPanel()->SetMouseInputEnabled( true ); } } } }
void ChatEchoPanel::OnThink() { CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat ); if (!pHUDChat) return; // ASWTODO - Unprotect all the hud chat stuff so this code below works - or figure out a better way of showing the chat during the various frames // copying the chat input line CBaseHudChatInputLine *pChatInput = pHUDChat->GetChatInput(); if ( pChatInput) { vgui::TextEntry *pTextEntry = dynamic_cast<vgui::TextEntry*>(pChatInput->GetInputPanel()); vgui::Label *pPrompt = pChatInput->GetPrompt(); if (pTextEntry) { wchar_t buffer[256]; pTextEntry->GetText(buffer, sizeof(buffer)); bool bInputVisible = (pChatInput->IsVisible() && pTextEntry->IsVisible() && pChatInput->GetAlpha() > 200 && pTextEntry->GetAlpha() > 200); //if (Q_strcmp(buffer, m_InputBuffer)) { pTextEntry->GetText(m_InputBuffer, sizeof(m_InputBuffer)); if (bInputVisible) { // grab our prompt (or use a default) wchar_t prompt[64]; if (pPrompt) pPrompt->GetText(prompt, sizeof(prompt)); else { char promptbuffer[8]; Q_snprintf(promptbuffer, sizeof(promptbuffer), "Say: "); g_pVGuiLocalize->ConvertANSIToUnicode(promptbuffer, prompt, sizeof( prompt )); } // copy x chars around the cursor into our echo const int max_copy_chars = 54; int line_length = wcslen(m_InputBuffer); int cursor_pos = 0; if (pTextEntry) cursor_pos = pTextEntry->GetTextCursorPos(); int copy_start = MAX((cursor_pos + 20) - max_copy_chars, 0); int copy_end = copy_start + max_copy_chars; if (copy_end > line_length) { int diff = copy_end - line_length; copy_start = MAX(copy_start - diff, 0); copy_end = MIN(copy_start + max_copy_chars, line_length); } // copy the prompt over int prompt_len = wcslen(prompt); int iCopyCursor = 0; for (int i=0;i<prompt_len;i++) { buffer[iCopyCursor] = prompt[i]; iCopyCursor++; } buffer[iCopyCursor] = L' '; iCopyCursor++; bool bAddedCursor = false; // check for drawing the cursor at the start if (cursor_pos == 0) { bAddedCursor |= AddCursorToBuffer(buffer, iCopyCursor, (cursor_pos == copy_end)); // if cursor is also at the end, we can flash it } // now copy the section of our input line, insert the cursor in the right place for (int i=copy_start;i<copy_end;i++) { if (iCopyCursor >= 253) // make sure we don't go over out limit for safety (never should though) iCopyCursor = 253; buffer[iCopyCursor] = m_InputBuffer[i]; iCopyCursor++; if (i == (cursor_pos-1)) { bAddedCursor |= AddCursorToBuffer(buffer, iCopyCursor, (cursor_pos == copy_end)); // if cursor is at the end, we can flash it } } // make sure we've added the cursor if (!bAddedCursor) AddCursorToBuffer(buffer, iCopyCursor, true); //if (copy_start == copy_end) //{ //if (fabs(gpGlobals->curtime - integer_time) < 0.25f || //(fabs(gpGlobals->curtime - integer_time) > 0.5f //&& fabs(gpGlobals->curtime - integer_time) < 0.75f)) //{ //buffer[iCopyCursor] = L'|'; //iCopyCursor++; //} //} buffer[iCopyCursor] = L'\0'; //if //Q_snprintf(buffer, sizeof(buffer), "%s %s", prompt, m_InputBuffer); //else //Q_snprintf(buffer, sizeof(buffer), "%s %s|", prompt, m_InputBuffer); m_pChatInputLine->SetText(buffer); m_pChatInputLine->SetVisible(true); } else { m_pChatInputLine->SetText(m_InputBuffer); } } if (m_pChatInputLine->IsVisible() != bInputVisible) m_pChatInputLine->SetVisible(bInputVisible); } else { if (m_pChatInputLine->IsVisible()) m_pChatInputLine->SetVisible(false); } } /* // copying the chat history if ( pHUDChat->GetChatHistory() ) { CHudChatHistory *pHistory = pHUDChat->GetChatHistory(); //pHistory->GetText(0, m_InputBuffer, sizeof(m_InputBuffer) * sizeof(wchar_t)); pHistory->GetEndOfText(ASW_CHAT_ECHO_HISTORY_WCHARS-1, m_InputBuffer, ASW_CHAT_ECHO_HISTORY_WCHARS); if (m_pChatHistory) { if (pHistory->IsVisible()) { m_pChatHistory->SetText(m_InputBuffer); m_pChatHistory->SetVisible(true); m_pChatHistory->SetPaintBorderEnabled( false ); m_pChatHistory->GotoTextEnd(); m_pChatHistory->SetMouseInputEnabled( false ); } else { m_pChatHistory->SetVisible(false); } } } */ }