PDA

View Full Version : css style radio(hud element part)


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

softboysxp
06-03-2007, 01:11 AM
Process the keypress message or you can define a console command or console varible and bind a key to it.

razvan252
06-03-2007, 01:13 AM
Process the keypress message
hmm? how?
or you can define a console command or console varible and bind a key to it.
yeah i can do that but i think its better to use a key

razvan252
06-03-2007, 02:05 AM
ah. nvm its working. thx a lot

razvan252
06-03-2007, 03:39 AM
ok now for the second part. for now it will just have to emit a sound when a key is pressed.
to add 9 keys is hell and you will be running out of keys on the keyboard so ill just use the weapon slots. the weapon slots are commands not keys so thats goin to be a prob. then when the radio menu is activated, the weapon selection cant be activated(we dont want to emit a sound and change the weapon too :D ) thats going to be a prob too.

soooo

i need to set something like this in weapon_selection

void CBaseHudWeaponSelection::UserCmd_Slot1(void)
{
if( HUDTYPE_CAROUSEL == hud_fastswitch.GetInt() )
{
UserCmd_LastWeapon();
}
else
{
if ( something like radio menu is visible)
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
pPlayer->EmitSound( "HL2Player.Copythat" );
}
else
{
//if not select slot
SelectSlot( 1 );
}
}
}

am i on the right track?
if so what no i need to set in the if ( something like radio menu is visible)

thx for any help

softboysxp
06-03-2007, 04:18 AM
Try this (haven't tested yet) :

bool IsRadioMenuVisible() {
CHudElement *pElement = gHUD.FindElement("HudRadio");
vgui::Panel *pRadioPanel = dynamic_cast<vgui::Panel*> (pElement);
if (pRadioPanel) {
return pRadioPanel->IsVisible();
}

return false;
}

lodle
06-03-2007, 05:21 AM
the weapon slots are not commands. They are key events and can be picked up in the button mapping for that player. do a search for IN_ATTACK and see how they work.

razvan252
06-04-2007, 05:06 AM
nope it doesnt. also tried

CHudElement *pElement = gHUD.FindElement("HudRadio");
vgui::Panel *pRadioPanel = dynamic_cast<vgui::Panel*> (pElement);

if ( pRadioPanel->IsVisible() )
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

engine->ClientCmd( "cl_showradio 0\n" );
pPlayer->EmitSound( "HL2Player.Copythat" );
}
else
{
SelectSlot( 1 );
}

lodle
06-04-2007, 06:17 AM
what the hell are you trying to do? What you need to do is in your panel you need to check to see if the player has pressed the keys (i.e. my suggestion above). Now to stop selecting guns while selecting voice comms add a check in the weapon select class to see if the radio panel is open.

razvan252
06-04-2007, 06:25 AM
what?

lol jk couldnt stop myself :P
ok ill do that

razvan252
06-04-2007, 06:33 AM
ok so to stop selecting guns while selecting voice comms add a check in the weapon select class to see if the radio panel is open. that ain hard right? i just need something like
if ( [radioisvisible] )
{
if ( IsInSelectionMode() )
{
CancelWeaponSelection();
}
}
in CBaseHudWeaponSelection::OnThink right?
but the prob is the if ( [radioisvisible] )
...
how do i add a bool that will "know" if the panel is on or off and that will work in CBaseHudWeaponSelection?

softboysxp
06-04-2007, 09:19 AM
Sorry for a mistake in my previous code, it should be "CHudRadio", so I think the code :

CHudElement *pElement = gHUD.FindElement("CHudRadio");
vgui::Panel *pRadioPanel = dynamic_cast<vgui::Panel*> (pElement);

if ( pRadioPanel->IsVisible() )
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

engine->ClientCmd( "cl_showradio 0\n" );
pPlayer->EmitSound( "HL2Player.Copythat" );
}
else
{
SelectSlot( 1 );
}

should work.

razvan252
06-04-2007, 09:35 AM
yeeaahhhh!!! its working! THX!!

gamehk
06-07-2007, 08:04 PM
full version is 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
*/
}
CHudElement *pElement = gHUD.FindElement("CHudRadio");
vgui::Panel *pRadioPanel = dynamic_cast<vgui::Panel*> (pElement);

if ( pRadioPanel->IsVisible() )
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

engine->ClientCmd( "cl_showradio 0\n" );
pPlayer->EmitSound( "HL2Player.Copythat" );
}
else
{
SelectSlot( 1 );
}

razvan252
06-08-2007, 02:32 AM
nope. use the first code to draw a simple text.
add a concommand to toggle it.(look for a "creating a panel" tutorial)
then in weapon_selection.cpp replace SelectSlot( # ); with

CHudElement *pElement = gHUD.FindElement("CHudRadio");
vgui::Panel *pRadioPanel = dynamic_cast<vgui::Panel*> (pElement);

if ( pRadioPanel->IsVisible() )
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

//toggle the menu off
engine->ClientCmd( "[concommand 0]\n" );
//emit sound
pPlayer->EmitSound( "[sound]" );
}
else
{
SelectSlot( # );
}

gamehk
06-10-2007, 11:13 PM
thanks ~ but where have css style radio (server part) ?