void BaseModHybridButton::OnSiblingHybridButtonOpened() { if ( !IsPC() ) return; bool bClosed = false; FlyoutMenu *pActiveFlyout = FlyoutMenu::GetActiveMenu(); if ( pActiveFlyout ) { BaseModHybridButton *button = dynamic_cast< BaseModHybridButton* >( pActiveFlyout->GetNavFrom() ); if ( button && button == this ) { // We need to close the flyout attached to this button FlyoutMenu::CloseActiveMenu(); bClosed = true; } } if ( !bClosed ) { SetClosed(); } m_isNavigateTo = false; }
// 0 = Deprecated CA buttons // 1 = Normal Button // 2 = MainMenu Button or InGameMenu Butto // 3 = Flyout button void BaseModHybridButton::PaintButtonEx() { vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() ); Color blotchColor = pScheme->GetColor( "HybridButton.BlotchColor", Color( 0, 0, 0, 255 ) ); Color borderColor = pScheme->GetColor( "HybridButton.BorderColor", Color( 0, 0, 0, 255 ) ); int x, y; int wide, tall; GetSize( wide, tall ); x = 0; // due to vertical resizing, center within the control y = ( tall - m_originalTall ) / 2; tall = m_originalTall; if ( m_nStyle == BUTTON_GAMEMODE ) { y = 0; } if ( ( m_nStyle == BUTTON_DROPDOWN || m_nStyle == BUTTON_GAMEMODE ) && GetCurrentState() == Open && m_nWideAtOpen ) { wide = m_nWideAtOpen; } bool bAnimateGlow = false; bool bDrawGlow = false; bool bDrawCursor = false; bool bDrawText = true; Color col; State curState = GetCurrentState(); switch ( curState ) { case Enabled: // selectable, just not highlighted if ( m_nStyle == BUTTON_RED || m_nStyle == BUTTON_REDMAIN ) { //col.SetColor( 0, 128, 128, 255 ); col.SetColor( 169, 213, 255, 255 ); } else if ( m_nStyle == BUTTON_ALIENSWARMMENUBUTTON || m_nStyle == BUTTON_ALIENSWARMMENUBUTTONSMALL ) { col.SetColor( 135, 170, 193, 255 ); } else { //col.SetColor( 125, 125, 125, 255 ); col.SetColor( 83, 148, 192, 255 ); } break; case Disabled: //col.SetColor( 88, 97, 104, 255 ); //col.SetColor( 65, 74, 96, 255 ); col.SetColor( 32, 59, 82, 255 ); bDrawText = true; bDrawGlow = false; break; case FocusDisabled: col.SetColor( 182, 189, 194, 255 ); bDrawText = false; bDrawGlow = true; break; case Open: // flyout menu is attached //col.SetColor( 200, 200, 200, 255 ); col.SetColor( 169, 213, 255, 255 ); bDrawGlow = true; bDrawCursor = true; break; case Focus: // active item col.SetColor( 255, 255, 255, 255 ); bDrawGlow = true; bAnimateGlow = true; if ( m_nStyle == BUTTON_SIMPLE || m_nStyle == BUTTON_DROPDOWN || m_nStyle == BUTTON_DIALOG || m_nStyle == BUTTON_RED ) { bDrawCursor = true; } break; } wchar_t szUnicode[512]; GetText( szUnicode, sizeof( szUnicode ) ); int len = V_wcslen( szUnicode ); int textWide, textTall; surface()->GetTextSize( m_hTextFont, szUnicode, textWide, textTall ); textWide = clamp( textWide, 0, wide - m_textInsetX * 2 ); textTall = clamp( textTall, 0, tall - m_textInsetX * 2 ); int textInsetX = m_textInsetX; if ( m_nStyle == BUTTON_DIALOG ) { // dialog buttons are centered textInsetX = ( wide - textWide ) / 2; } if ( FlyoutMenu::GetActiveMenu() && FlyoutMenu::GetActiveMenu()->GetNavFrom() != this ) { bDrawCursor = false; } if ( bDrawCursor ) { // draw backing rectangle if ( curState == Open ) { surface()->DrawSetColor( Color( 0, 0, 0, 255 ) ); surface()->DrawFilledRectFade( x, y, x+wide, y+tall, 0, 255, true ); } // draw blotch surface()->DrawSetColor( blotchColor ); if ( m_nStyle == BUTTON_DIALOG ) { int blotchWide = textWide; int blotchX = x + textInsetX; surface()->DrawFilledRectFade( blotchX, y, blotchX + 0.50f * blotchWide, y+tall, 0, 150, true ); surface()->DrawFilledRectFade( blotchX + 0.50f * blotchWide, y, blotchX + blotchWide, y+tall, 150, 0, true ); } else { int blotchWide = textWide + vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), 40 ); int blotchX = x + textInsetX; surface()->DrawFilledRectFade( blotchX, y, blotchX + 0.25f * blotchWide, y+tall, 0, 150, true ); surface()->DrawFilledRectFade( blotchX + 0.25f * blotchWide, y, blotchX + blotchWide, y+tall, 150, 0, true ); } // draw border lines surface()->DrawSetColor( borderColor ); if ( curState == Open ) { FlyoutMenu *pActiveFlyout = FlyoutMenu::GetActiveMenu(); BaseModHybridButton *button = dynamic_cast< BaseModHybridButton* >( pActiveFlyout ? pActiveFlyout->GetNavFrom() : NULL ); if ( pActiveFlyout && pActiveFlyout->GetOriginalTall() == 0 && button && button == this ) { surface()->DrawFilledRectFade( x, y, x + wide, y+2, 255, 0, true ); } else { // the border lines end at the beginning of the flyout // the flyout will draw to complete the look surface()->DrawFilledRectFade( x, y, x + wide, y+2, 0, 255, true ); surface()->DrawFilledRectFade( x, y+tall-2, x + wide, y+tall, 0, 255, true ); } } else { // top and bottom border lines surface()->DrawFilledRectFade( x, y, x + 0.5f * wide, y+2, 0, 255, true ); surface()->DrawFilledRectFade( x + 0.5f * wide, y, x + wide, y+2, 255, 0, true ); surface()->DrawFilledRectFade( x, y+tall-2, x + 0.5f * wide, y+tall, 0, 255, true ); surface()->DrawFilledRectFade( x + 0.5f * wide, y+tall-2, x + wide, y+tall, 255, 0, true ); } } // assume drawn, unless otherwise shortened with ellipsis int iLabelCharsDrawn = len; // draw the text if ( bDrawText ) { int availableWidth = GetWide() - x - textInsetX; if ( m_bShowDropDownIndicator ) { int textTall = vgui::surface()->GetFontTall( m_hTextFont ); int textLen = 0; int len = wcslen( szUnicode ); for ( int i=0;i<len;i++ ) { textLen += vgui::surface()->GetCharacterWidth( m_hTextFont, szUnicode[i] ); } int imageX = x + textInsetX + textLen + m_iSelectedArrowSize / 2; int imageY = y + ( textTall - m_iSelectedArrowSize ) / 2; if ( ( imageX + m_iSelectedArrowSize ) > GetWide() ) { imageX = GetWide() - m_iSelectedArrowSize; } if ( curState == Open || m_bOverrideDropDownIndicator ) { vgui::surface()->DrawSetTexture( m_iSelectedArrow ); } else { vgui::surface()->DrawSetTexture( m_iUnselectedArrow ); } vgui::surface()->DrawSetColor( col ); vgui::surface()->DrawTexturedRect( imageX, imageY, imageX + m_iSelectedArrowSize, imageY + m_iSelectedArrowSize ); vgui::surface()->DrawSetTexture( 0 ); availableWidth -= m_iSelectedArrowSize * 2; } vgui::surface()->DrawSetTextFont( m_hTextFont ); vgui::surface()->DrawSetTextPos( x + textInsetX, y + m_textInsetY ); vgui::surface()->DrawSetTextColor( col ); if ( textWide > availableWidth ) { // length of 3 dots int ellipsesLen = 3 * vgui::surface()->GetCharacterWidth( m_hTextFont, L'.' ); availableWidth -= ellipsesLen; iLabelCharsDrawn = 0; int charX = x + textInsetX; for ( int i=0; i < len; i++ ) { vgui::surface()->DrawUnicodeChar( szUnicode[i] ); iLabelCharsDrawn++; charX += vgui::surface()->GetCharacterWidth( m_hTextFont, szUnicode[i] ); if ( charX >= ( x + textInsetX + availableWidth ) ) break; } vgui::surface()->DrawPrintText( L"...", 3 ); } else { vgui::surface()->DrawUnicodeString( szUnicode ); } } else if ( GetCurrentState() == Disabled || GetCurrentState() == FocusDisabled ) { Color textcol = col; textcol[ 3 ] = 64; vgui::surface()->DrawSetTextFont( m_hTextFont ); vgui::surface()->DrawSetTextPos( x + textInsetX, y + m_textInsetY ); vgui::surface()->DrawSetTextColor( textcol ); vgui::surface()->DrawPrintText( szUnicode, len ); } // draw the help text if ( m_nStyle == BUTTON_GAMEMODE && curState != Open ) { const char *pHelpText = GetHelpText( IsEnabled() ); wchar_t szHelpUnicode[512]; wchar_t *pUnicodeString; if ( pHelpText && pHelpText[0] == '#' ) { pUnicodeString = g_pVGuiLocalize->Find( pHelpText ); } else { g_pVGuiLocalize->ConvertANSIToUnicode( pHelpText, szHelpUnicode, sizeof( szHelpUnicode ) ); pUnicodeString = szHelpUnicode; } vgui::surface()->DrawSetTextFont( m_hHintTextFont ); vgui::surface()->DrawSetTextPos( x + textInsetX, y + m_textInsetY + m_nTextFontHeight ); vgui::surface()->DrawSetTextColor( col ); vgui::surface()->DrawPrintText( pUnicodeString, wcslen( pUnicodeString ) ); } // draw the pulsing glow if ( bDrawGlow ) { if ( !bDrawText ) { vgui::surface()->DrawSetTextColor( col ); } else { int alpha = bAnimateGlow ? 60.0f + 30.0f * sin( Plat_FloatTime() * 4.0f ) : 30; Color glowColor( 255, 255, 255, alpha ); vgui::surface()->DrawSetTextColor( glowColor ); } vgui::surface()->DrawSetTextFont( m_hTextBlurFont ); vgui::surface()->DrawSetTextPos( x + textInsetX, y + m_textInsetY ); for ( int i=0; i<len && i < iLabelCharsDrawn; i++ ) { vgui::surface()->DrawUnicodeChar( szUnicode[i] ); } } if ( m_nStyle == BUTTON_DROPDOWN && curState != Open ) { // draw right justified item wchar_t *pUnicodeString = g_pVGuiLocalize->Find( m_DropDownSelection.String() ); if ( !pUnicodeString ) { g_pVGuiLocalize->ConvertANSIToUnicode( m_DropDownSelection.String(), szUnicode, sizeof( szUnicode ) ); pUnicodeString = szUnicode; } int len = V_wcslen( pUnicodeString ); int textWide, textTall; surface()->GetTextSize( m_hSelectionFont, pUnicodeString, textWide, textTall ); // horizontal right justify int xx = wide - textWide - textInsetX; // vertical center within int yy = ( tall - textTall )/2; // draw the drop down selection text vgui::surface()->DrawSetTextFont( m_hSelectionFont ); vgui::surface()->DrawSetTextPos( xx, yy ); vgui::surface()->DrawSetTextColor( col ); vgui::surface()->DrawPrintText( pUnicodeString, len ); if ( bDrawGlow ) { int alpha = bAnimateGlow ? 60.0f + 30.0f * sin( Plat_FloatTime() * 4.0f ) : 30; vgui::surface()->DrawSetTextColor( Color( 255, 255, 255, alpha ) ); vgui::surface()->DrawSetTextFont( m_hSelectionBlurFont ); vgui::surface()->DrawSetTextPos( xx, yy ); vgui::surface()->DrawPrintText( pUnicodeString, len ); } } }