razvan252
06-03-2007, 12:25 AM
ok so after some hours spent on making a hud element for the radio i came up with this:
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//================================================== ===========================//
#include "cbase.h"
#include "hud.h"
#include "text_message.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "view.h"
#include "KeyValues.h"
#include "vgui_controls/AnimationController.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "vguimatsurface/IMatSystemSurface.h"
#include "materialsystem/IMaterial.h"
#include "materialsystem/IMesh.h"
#include "materialsystem/imaterialvar.h"
#include "ieffects.h"
#include "hudelement.h"
#include "in_buttons.h"
using namespace vgui;
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose: HDU Damage indication
//-----------------------------------------------------------------------------
class CHudRadio : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudRadio, vgui::Panel );
public:
CHudRadio( const char *pElementName );
private:
virtual void Paint();
virtual void OnThink();
void Reset( void );
private:
CPanelAnimationVar( vgui::HFont, m_hTextFont, "TextFont", "Default" );
CPanelAnimationVar( Color, m_TextColor, "TextColor", "FgColor" );
CPanelAnimationVarAliasType( float, text_xpos, "text_xpos", "8", "proportional_float" );
CPanelAnimationVarAliasType( float, text_ypos, "text_ypos", "10", "proportional_float" );
bool m_bRadioIsVisible;
};
DECLARE_HUDELEMENT( CHudRadio );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudRadio::CHudRadio( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudRadio")
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudRadio::Reset( void )
{
m_bRadioIsVisible = false;
}
//-----------------------------------------------------------------------------
// Purpose: updates poison damage
//-----------------------------------------------------------------------------
void CHudRadio::OnThink()
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
//ok this works now for the key
if ( m_bRadioIsVisible == true )
{
SetVisible(true);
}
else
{
SetVisible(false);
}
}
//-----------------------------------------------------------------------------
// Purpose: Paints the damage display
//-----------------------------------------------------------------------------
void CHudRadio::Paint()
{
//set the text color, font and position
vgui::surface()->DrawSetTextColor(m_TextColor);
vgui::surface()->DrawSetTextFont(m_hTextFont);
vgui::surface()->DrawSetTextPos(text_xpos, text_ypos);
//set the text
vgui::surface()->DrawPrintText(L"Test Text 01", wcslen(L"Test Text 01"));
/*
2. Cover me
3. Stand by
4. Stay alert
5. Ready weapons
6. Move in
7. Heavy Resistance
8. One down
9. Sector clear
*/
}
so now i have a bool that toggles the state. problem is now i need a trigger something like this
//if we press a button when toggle states
if ( pPlayer->m_afButtonPressed & IN_RADIO )
{
if ( m_bRadioIsVisible == true )
{
m_bRadioIsVisible = false;
}
else
{
m_bRadioIsVisible = true;
}
}
these things usually sit in itempostframe but hud elements dont have that.
so where do i need to put it?
so can someone pls help?
tx in advance,
adrian
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//================================================== ===========================//
#include "cbase.h"
#include "hud.h"
#include "text_message.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "view.h"
#include "KeyValues.h"
#include "vgui_controls/AnimationController.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "vguimatsurface/IMatSystemSurface.h"
#include "materialsystem/IMaterial.h"
#include "materialsystem/IMesh.h"
#include "materialsystem/imaterialvar.h"
#include "ieffects.h"
#include "hudelement.h"
#include "in_buttons.h"
using namespace vgui;
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose: HDU Damage indication
//-----------------------------------------------------------------------------
class CHudRadio : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudRadio, vgui::Panel );
public:
CHudRadio( const char *pElementName );
private:
virtual void Paint();
virtual void OnThink();
void Reset( void );
private:
CPanelAnimationVar( vgui::HFont, m_hTextFont, "TextFont", "Default" );
CPanelAnimationVar( Color, m_TextColor, "TextColor", "FgColor" );
CPanelAnimationVarAliasType( float, text_xpos, "text_xpos", "8", "proportional_float" );
CPanelAnimationVarAliasType( float, text_ypos, "text_ypos", "10", "proportional_float" );
bool m_bRadioIsVisible;
};
DECLARE_HUDELEMENT( CHudRadio );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudRadio::CHudRadio( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudRadio")
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudRadio::Reset( void )
{
m_bRadioIsVisible = false;
}
//-----------------------------------------------------------------------------
// Purpose: updates poison damage
//-----------------------------------------------------------------------------
void CHudRadio::OnThink()
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
//ok this works now for the key
if ( m_bRadioIsVisible == true )
{
SetVisible(true);
}
else
{
SetVisible(false);
}
}
//-----------------------------------------------------------------------------
// Purpose: Paints the damage display
//-----------------------------------------------------------------------------
void CHudRadio::Paint()
{
//set the text color, font and position
vgui::surface()->DrawSetTextColor(m_TextColor);
vgui::surface()->DrawSetTextFont(m_hTextFont);
vgui::surface()->DrawSetTextPos(text_xpos, text_ypos);
//set the text
vgui::surface()->DrawPrintText(L"Test Text 01", wcslen(L"Test Text 01"));
/*
2. Cover me
3. Stand by
4. Stay alert
5. Ready weapons
6. Move in
7. Heavy Resistance
8. One down
9. Sector clear
*/
}
so now i have a bool that toggles the state. problem is now i need a trigger something like this
//if we press a button when toggle states
if ( pPlayer->m_afButtonPressed & IN_RADIO )
{
if ( m_bRadioIsVisible == true )
{
m_bRadioIsVisible = false;
}
else
{
m_bRadioIsVisible = true;
}
}
these things usually sit in itempostframe but hud elements dont have that.
so where do i need to put it?
so can someone pls help?
tx in advance,
adrian