#include "cbase.h" #include "hudelement.h" #include "hud_macros.h" #include #include #include #include "c_baseplayer.h" #include "voice_status.h" #include "clientmode_shared.h" #include "c_playerresource.h" class CHudRadio : public CHudElement, public vgui::Panel { public: DECLARE_CLASS_SIMPLE( CHudRadio, vgui::Panel ); CHudRadio( const char *name ); virtual bool ShouldDraw(); virtual void Paint(); virtual void VidInit(); virtual void Init( void ); virtual void ApplySchemeSettings(vgui::IScheme *pScheme); virtual void OnKeyCodeTyped( vgui::KeyCode code ); virtual void OnKeyCodePressed( vgui::KeyCode code ); virtual void DisplayTeam( int team ); void MsgFunc_PlayRadioSound( bf_read &msg ); private: // bool showing; vgui::Label *m_pTitle, *m_p1tauri, *m_p2tauri, *m_p3tauri, *m_p4tauri, *m_p5tauri, *m_p6tauri, *m_p7tauri, *m_p8tauri, *m_p9tauri, *m_p10tauri, *m_p1goa, *m_p2goa, *m_p3goa, *m_p4goa, *m_p5goa, *m_p6goa, *m_p7goa, *m_p8goa, *m_p9goa, *m_p10goa; }; DECLARE_HUDELEMENT( CHudRadio ); DECLARE_HUD_MESSAGE( CHudRadio, PlayRadioSound ); bool g_ShowingRadio; CON_COMMAND( toggleradio, "Opens radio" ) { if (g_ShowingRadio) g_ShowingRadio = false; else g_ShowingRadio = true; } CHudRadio::CHudRadio( const char *pName ) : vgui::Panel( NULL, "HUDRadio" ), CHudElement( pName ) { SetParent( g_pClientMode->GetViewport() ); SetHiddenBits( 0 ); g_ShowingRadio = false; SetKeyBoardInputEnabled( true ); SetMouseInputEnabled( false ); } void CHudRadio::MsgFunc_PlayRadioSound( bf_read &msg ) { char szString[256]; msg.ReadString( szString, sizeof(szString) ); engine->ClientCmd( UTIL_VarArgs("play /radio/%s.wav" ,szString) ); } #define SETUP_RADIO_LABEL( controlname, z, text, ypos ) \ controlname = new vgui::Label( this, z, text ); \ controlname->SizeToContents(); \ controlname->SetPos( 5, ypos ); void CHudRadio::ApplySchemeSettings(vgui::IScheme *pScheme) { BaseClass::ApplySchemeSettings( pScheme ); SetBgColor( Color( 0, 0, 0, 200 ) ); SetPaintBackgroundType (2); // Rounded corner box //LoadControlSettings( "Resource/hud_radio.res" ); SETUP_RADIO_LABEL( m_p1tauri, "Tauri1", "#SGL_RADIO_1_T", 5 ) SETUP_RADIO_LABEL( m_p2tauri, "Tauri2", "#SGL_RADIO_2_T", 20 ) SETUP_RADIO_LABEL( m_p3tauri, "Tauri3", "#SGL_RADIO_3_T", 40 ) SETUP_RADIO_LABEL( m_p4tauri, "Tauri4", "#SGL_RADIO_4_T", 60 ) SETUP_RADIO_LABEL( m_p5tauri, "Tauri5", "#SGL_RADIO_5_T", 80 ) SETUP_RADIO_LABEL( m_p6tauri, "Tauri6", "#SGL_RADIO_6_T", 100 ) SETUP_RADIO_LABEL( m_p7tauri, "Tauri7", "#SGL_RADIO_7_T", 120 ) SETUP_RADIO_LABEL( m_p8tauri, "Tauri8", "#SGL_RADIO_8_T", 140 ) SETUP_RADIO_LABEL( m_p9tauri, "Tauri9", "#SGL_RADIO_9_T", 160 ) SETUP_RADIO_LABEL( m_p10tauri, "Tauri10", "#SGL_RADIO_10_T", 180 ) SETUP_RADIO_LABEL( m_p1goa, "Goa1", "#SGL_RADIO_1_G", 5 ) SETUP_RADIO_LABEL( m_p2goa, "Goa2", "#SGL_RADIO_2_G", 20 ) SETUP_RADIO_LABEL( m_p3goa, "Goa3", "#SGL_RADIO_3_G", 40 ) SETUP_RADIO_LABEL( m_p4goa, "Goa4", "#SGL_RADIO_4_G", 60 ) SETUP_RADIO_LABEL( m_p5goa, "Goa5", "#SGL_RADIO_5_G", 80 ) SETUP_RADIO_LABEL( m_p6goa, "Goa6", "#SGL_RADIO_6_G", 100 ) SETUP_RADIO_LABEL( m_p7goa, "Goa7", "#SGL_RADIO_7_G", 120 ) SETUP_RADIO_LABEL( m_p8goa, "Goa8", "#SGL_RADIO_8_G", 140 ) SETUP_RADIO_LABEL( m_p9goa, "Goa9", "#SGL_RADIO_9_G", 160 ) SETUP_RADIO_LABEL( m_p10goa, "Goa10", "#SGL_RADIO_10_G", 180 ) SETUP_RADIO_LABEL( m_pTitle, "Radio",UTIL_VarArgs( "%s. Exit", engine->Key_LookupBinding("toggleradio")), 200 ) SetSize( 200, 230 ); SetPos( (ScreenWidth() - (GetWide() + 20)) , ScreenHeight() / 2 ); } void CHudRadio::DisplayTeam( int team ) { if (team == 2 ) { m_p1tauri->SetVisible( false ); m_p2tauri->SetVisible( false ); m_p3tauri->SetVisible( false ); m_p4tauri->SetVisible( false ); m_p5tauri->SetVisible( false ); m_p6tauri->SetVisible( false ); m_p7tauri->SetVisible( false ); m_p8tauri->SetVisible( false ); m_p9tauri->SetVisible( false ); m_p10tauri->SetVisible( false ); m_p1goa->SetVisible( true ); m_p2goa->SetVisible( true ); m_p3goa->SetVisible( true ); m_p4goa->SetVisible( true ); m_p5goa->SetVisible( true ); m_p6goa->SetVisible( true ); m_p7goa->SetVisible( true ); m_p8goa->SetVisible( true ); m_p9goa->SetVisible( true ); m_p10goa->SetVisible( true ); } else { m_p1tauri->SetVisible( true ); m_p2tauri->SetVisible( true ); m_p3tauri->SetVisible( true ); m_p4tauri->SetVisible( true ); m_p5tauri->SetVisible( true ); m_p6tauri->SetVisible( true ); m_p7tauri->SetVisible( true ); m_p8tauri->SetVisible( true ); m_p9tauri->SetVisible( true ); m_p10tauri->SetVisible( true ); m_p1goa->SetVisible( false ); m_p2goa->SetVisible( false ); m_p3goa->SetVisible( false ); m_p4goa->SetVisible( false ); m_p5goa->SetVisible( false ); m_p6goa->SetVisible( false ); m_p7goa->SetVisible( false ); m_p8goa->SetVisible( false ); m_p9goa->SetVisible( false ); m_p10goa->SetVisible( false ); } } void CHudRadio::Init( void ) { HOOK_HUD_MESSAGE( CHudRadio, PlayRadioSound ); //BaseClass::Init(); } void CHudRadio::VidInit( void ) { } bool CHudRadio::ShouldDraw() { return g_ShowingRadio; } void CHudRadio::Paint() { C_BasePlayer *pPlayer = (C_BasePlayer *) C_BasePlayer::GetLocalPlayer(); if (!pPlayer) return; DisplayTeam( pPlayer->GetTeamNumber() ); if (pPlayer->GetTeamNumber() == 2) SetBgColor( Color( 200, 0, 0, 200 ) ); else SetBgColor( Color( 0, 200, 0, 200 ) ); if (g_ShowingRadio) { MoveToFront(); RequestFocus(); SetVisible(true); SetEnabled( true ); } else { SetVisible(false); SetEnabled( false ); } int x, y, w, h; GetBounds( x, y, w, h ); } void CHudRadio::OnKeyCodeTyped( vgui::KeyCode code ) { Msg("hi"); } void CHudRadio::OnKeyCodePressed( vgui::KeyCode code) { if (!g_ShowingRadio) return; //C_BasePlayer *pPlayer = (C_BasePlayer *) C_BasePlayer::GetLocalPlayer(); //if (!pPlayer) // return; if ( code == KEY_0 ) { Msg("HI"); } //if (pPlayer->m_nButtons & IN_ATTACK) //int iLastTrappedKey = engine->GetLastPressedEngineKey(); //engine->las //if( iLastTrappedKey == m_iOneillKey ) }