diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/cstrike/VGUI/buymouseoverpanelbutton.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/cstrike/VGUI/buymouseoverpanelbutton.h')
| -rw-r--r-- | game/client/cstrike/VGUI/buymouseoverpanelbutton.h | 397 |
1 files changed, 397 insertions, 0 deletions
diff --git a/game/client/cstrike/VGUI/buymouseoverpanelbutton.h b/game/client/cstrike/VGUI/buymouseoverpanelbutton.h new file mode 100644 index 0000000..9e5abbf --- /dev/null +++ b/game/client/cstrike/VGUI/buymouseoverpanelbutton.h @@ -0,0 +1,397 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef BUYMOUSEOVERPANELBUTTON_H +#define BUYMOUSEOVERPANELBUTTON_H +#ifdef _WIN32 +#pragma once +#endif + +#include <KeyValues.h> +#include <filesystem.h> +#include "mouseoverpanelbutton.h" +#include "hud.h" +#include "c_cs_player.h" +#include "cs_gamerules.h" +#include "cstrike/bot/shared_util.h" +#include <vgui/ISurface.h> +#include <vgui/ILocalize.h> +#include <vgui_controls/ImagePanel.h> + +using namespace vgui; + +//----------------------------------------------------------------------------- +// Purpose: Triggers a new panel when the mouse goes over the button +//----------------------------------------------------------------------------- +class BuyMouseOverPanelButton : public MouseOverPanelButton +{ +private: + typedef MouseOverPanelButton BaseClass; +public: + BuyMouseOverPanelButton(vgui::Panel *parent, const char *panelName, vgui::EditablePanel *panel) : + MouseOverPanelButton( parent, panelName, panel) + { + m_iPrice = 0; + m_iPreviousPrice = 0; + m_iASRestrict = 0; + m_iDEUseOnly = 0; + m_command = NULL; + m_bIsBargain = false; + + m_pBlackMarketPrice = NULL;//new EditablePanel( parent, "BlackMarket_Labels" ); + if ( m_pBlackMarketPrice ) + { + m_pBlackMarketPrice->LoadControlSettings( "Resource/UI/BlackMarket_Labels.res" ); + + int x,y,wide,tall; + GetClassPanel()->GetBounds( x, y, wide, tall ); + m_pBlackMarketPrice->SetBounds( x, y, wide, tall ); + int px, py; + GetClassPanel()->GetPinOffset( px, py ); + int rx, ry; + GetClassPanel()->GetResizeOffset( rx, ry ); + // Apply pin settings from template, too + m_pBlackMarketPrice->SetAutoResize( GetClassPanel()->GetPinCorner(), GetClassPanel()->GetAutoResize(), px, py, rx, ry ); + } + } + + virtual void ApplySettings( KeyValues *resourceData ) + { + BaseClass::ApplySettings( resourceData ); + + KeyValues *kv = resourceData->FindKey( "cost", false ); + if( kv ) // if this button has a cost defined for it + { + m_iPrice = kv->GetInt(); // save the price away + } + + kv = resourceData->FindKey( "as_restrict", false ); + if( kv ) // if this button has a map limitation for it + { + m_iASRestrict = kv->GetInt(); // save the as_restrict away + } + + kv = resourceData->FindKey( "de_useonly", false ); + if( kv ) // if this button has a map limitation for it + { + m_iDEUseOnly = kv->GetInt(); // save the de_useonly away + } + + if ( m_command ) + { + delete[] m_command; + m_command = NULL; + } + kv = resourceData->FindKey( "command", false ); + if ( kv ) + { + m_command = CloneString( kv->GetString() ); + } + + SetPriceState(); + SetMapTypeState(); + } + + int GetASRestrict() { return m_iASRestrict; } + + int GetDEUseOnly() { return m_iDEUseOnly; } + + virtual void PerformLayout() + { + BaseClass::PerformLayout(); + SetPriceState(); + SetMapTypeState(); + +#ifndef CS_SHIELD_ENABLED + if ( !Q_stricmp( GetName(), "shield" ) ) + { + SetVisible( false ); + SetEnabled( false ); + } +#endif + } + + virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) + { + BaseClass::ApplySchemeSettings( pScheme ); + + m_avaliableColor = pScheme->GetColor( "Label.TextColor", Color( 0, 0, 0, 0 ) ); + m_unavailableColor = pScheme->GetColor( "Label.DisabledFgColor2", Color( 0, 0, 0, 0 ) ); + m_bargainColor = Color( 0, 255, 0, 192 ); + + SetPriceState(); + SetMapTypeState(); + } + + void SetPriceState() + { + if ( CSGameRules() && CSGameRules()->IsBlackMarket() ) + { + SetMarketState(); + } + else + { + if ( GetParent() ) + { + Panel *pPanel = dynamic_cast< Panel * >(GetParent()->FindChildByName( "MarketSticker" ) ); + + if ( pPanel ) + { + pPanel->SetVisible( false ); + } + } + + m_bIsBargain = false; + } + + C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer(); + + if ( m_iPrice && ( pPlayer && m_iPrice > pPlayer->GetAccount() ) ) + { + SetFgColor( m_unavailableColor ); + SetCommand( "buy_unavailable" ); + } + else + { + if ( m_bIsBargain == false ) + { + SetFgColor( m_avaliableColor ); + } + else + { + SetFgColor( m_bargainColor ); + } + + SetCommand( m_command ); + } + } + + void SetMarketState( void ) + { + Panel *pClassPanel = GetClassPanel(); + if ( pClassPanel ) + { + pClassPanel->SetVisible( false ); + } + + if ( m_pBlackMarketPrice ) + { + Label *pLabel = dynamic_cast< Label * >(m_pBlackMarketPrice->FindChildByName( "pricelabel" ) ); + + if ( pLabel ) + { + const int BufLen = 2048; + wchar_t wbuf[BufLen] = L""; + const wchar_t *formatStr = g_pVGuiLocalize->Find("#Cstrike_MarketPreviousPrice"); + + if ( !formatStr ) + formatStr = L"%s1"; + + char strPrice[16]; + wchar_t szPrice[64]; + Q_snprintf( strPrice, sizeof( strPrice ), "%d", m_iPreviousPrice ); + + g_pVGuiLocalize->ConvertANSIToUnicode( strPrice, szPrice, sizeof(szPrice)); + + g_pVGuiLocalize->ConstructString( wbuf, sizeof(wbuf), formatStr, 1, szPrice ); + pLabel->SetText( wbuf ); + pLabel->SetVisible( true ); + } + + pLabel = dynamic_cast< Label * >(m_pBlackMarketPrice->FindChildByName( "price" ) ); + + if ( pLabel ) + { + const int BufLen = 2048; + wchar_t wbuf[BufLen] = L""; + const wchar_t *formatStr = g_pVGuiLocalize->Find("#Cstrike_MarketCurrentPrice"); + + if ( !formatStr ) + formatStr = L"%s1"; + + char strPrice[16]; + wchar_t szPrice[64]; + Q_snprintf( strPrice, sizeof( strPrice ), "%d", m_iPrice ); + + g_pVGuiLocalize->ConvertANSIToUnicode( strPrice, szPrice, sizeof(szPrice)); + + g_pVGuiLocalize->ConstructString( wbuf, sizeof(wbuf), formatStr, 1, szPrice ); + pLabel->SetText( wbuf ); + pLabel->SetVisible( true ); + } + + pLabel = dynamic_cast< Label * >(m_pBlackMarketPrice->FindChildByName( "difference" ) ); + + if ( pLabel ) + { + const int BufLen = 2048; + wchar_t wbuf[BufLen] = L""; + const wchar_t *formatStr = g_pVGuiLocalize->Find("#Cstrike_MarketDeltaPrice"); + + if ( !formatStr ) + formatStr = L"%s1"; + + char strPrice[16]; + wchar_t szPrice[64]; + + int iDifference = m_iPreviousPrice - m_iPrice; + + if ( iDifference >= 0 ) + { + pLabel->SetFgColor( m_bargainColor ); + } + else + { + pLabel->SetFgColor( Color( 192, 28, 0, 255 ) ); + } + + Q_snprintf( strPrice, sizeof( strPrice ), "%d", abs( iDifference ) ); + + g_pVGuiLocalize->ConvertANSIToUnicode( strPrice, szPrice, sizeof(szPrice)); + + g_pVGuiLocalize->ConstructString( wbuf, sizeof(wbuf), formatStr, 1, szPrice ); + pLabel->SetText( wbuf ); + pLabel->SetVisible( true ); + } + + ImagePanel *pImage = dynamic_cast< ImagePanel * >(m_pBlackMarketPrice->FindChildByName( "classimage" ) ); + + if ( pImage ) + { + ImagePanel *pClassImage = dynamic_cast< ImagePanel * >(GetClassPanel()->FindChildByName( "classimage" ) ); + + if ( pClassImage ) + { + pImage->SetSize( pClassImage->GetWide(), pClassImage->GetTall() ); + pImage->SetImage( pClassImage->GetImage() ); + } + } + + if ( GetParent() ) + { + Panel *pPanel = dynamic_cast< Panel * >(GetParent()->FindChildByName( "MarketSticker" ) ); + + if ( pPanel ) + { + if ( m_bIsBargain ) + { + pPanel->SetVisible( true ); + } + else + { + pPanel->SetVisible( false ); + } + } + } + } + } + + void SetMapTypeState() + { + CCSGameRules *pRules = CSGameRules(); + + if ( pRules ) + { + if( pRules->IsVIPMap() ) + { + if ( m_iASRestrict ) + { + SetFgColor( m_unavailableColor ); + SetCommand( "buy_unavailable" ); + } + } + + if ( !pRules->IsBombDefuseMap() ) + { + if ( m_iDEUseOnly ) + { + SetFgColor( m_unavailableColor ); + SetCommand( "buy_unavailable" ); + } + } + } + } + + void SetBargainButton( bool state ) + { + m_bIsBargain = state; + } + + void SetCurrentPrice( int iPrice ) + { + m_iPrice = iPrice; + } + + void SetPreviousPrice( int iPrice ) + { + m_iPreviousPrice = iPrice; + } + + const char *GetBuyCommand( void ) + { + return m_command; + } + + virtual void ShowPage() + { + if ( g_lastPanel ) + { + for( int i = 0; i< g_lastPanel->GetParent()->GetChildCount(); i++ ) + { + MouseOverPanelButton *buyButton = dynamic_cast<MouseOverPanelButton *>(g_lastPanel->GetParent()->GetChild(i)); + + if ( buyButton ) + { + buyButton->HidePage(); + } + } + } + + BaseClass::ShowPage(); + + if ( !Q_stricmp( m_command, "vguicancel" ) ) + return; + + if ( CSGameRules() && CSGameRules()->IsBlackMarket() ) + { + if ( m_pBlackMarketPrice && !m_pBlackMarketPrice->IsVisible() ) + { + m_pBlackMarketPrice->SetVisible( true ); + } + } + } + + virtual void HidePage() + { + BaseClass::HidePage(); + + if ( m_pBlackMarketPrice && m_pBlackMarketPrice->IsVisible() ) + { + m_pBlackMarketPrice->SetVisible( false ); + } + } + +private: + + int m_iPrice; + int m_iPreviousPrice; + int m_iASRestrict; + int m_iDEUseOnly; + bool m_bIsBargain; + + Color m_avaliableColor; + Color m_unavailableColor; + Color m_bargainColor; + + char *m_command; + +public: + vgui::EditablePanel *m_pBlackMarketPrice; +}; + + +#endif // BUYMOUSEOVERPANELBUTTON_H |