[ Converted text/html to text/plain ]
In the GameMenu.res file, each option has a "command" parameter. My question
is, how do I make my panel appear using one of these?
I created an OnCommand function and at the moment works by using the console
to enable and disable. In my GameMenu.res file, I have to use the command
"engine ToggleNewGame" because "ToggleNewGame" doesn't work.
So, there must be an easier way to do what I am trying to accomplish than what
I have now, see:
NOTE: For buttons, the "command" ToggleNewGame works fine... but for some
reason the menu option "command" doesn't work.
My code is as follows:
//-----------------------------------------------------------------------------
// Purpose: Displays the New Game panel
//-----------------------------------------------------------------------------
class CNewGamePanel : public vgui::Frame
{
DECLARE_CLASS_SIMPLE(CNewGamePanel, vgui::Frame);
public:
CNewGamePanel( vgui::VPANEL parent );
~CNewGamePanel();
virtual void OnTick();
virtual void OnCommand(const char *command);
virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
}
private:
};
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CNewGamePanel::CNewGamePanel( vgui::VPANEL parent ) : BaseClass( NULL,
"CNewGamePanel" )
{
SetKeyBoardInputEnabled( true );
SetMouseInputEnabled( true );
SetProportional( true );
SetTitleBarVisible( true );
SetMinimizeButtonVisible( false );
SetMaximizeButtonVisible( false );
SetCloseButtonVisible( false );
SetSizeable( false );
SetMoveable( true );
SetVisible( true );
SetScheme(vgui::scheme()->LoadSchemeFromFile("resource/SourceScheme.res",
"SourceScheme"));
// Loading the .res file.
LoadControlSettings( "resource/UI/NewGamePanel.res" );
vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
// center the panel
int wide, tall;
GetSize( wide, tall );
SetPos( ( ScreenWidth() - wide ) / 2, ( ScreenHeight() - tall ) / 2 ); //
SetPos(width from left, height from top)
}
// Declare Console Commands
ConVar cl_shownewgamepanel("cl_shownewgamepanel", "0", FCVAR_CLIENTDLL, "Sets
the state of NewGamePanel <state>");
CON_COMMAND(ToggleNewGame, "Toggles NewGamePanel on or off")
{
cl_shownewgamepanel.SetValue(cl_shownewgamepanel.GetBool()==true?false:true);
};
void CNewGamePanel::OnTick()
{
BaseClass::OnTick();
SetVisible(cl_shownewgamepanel.GetBool()); //CL_SHOWMYPANEL / 0 BY DEFAULT
// Focus if it is activated
if (cl_shownewgamepanel.GetBool()==true) {
Activate();
}
}
void CNewGamePanel::OnCommand(const char *command)
{
if (!stricmp(command, "ToggleNewGame"))
{
cl_shownewgamepanel.SetValue(0);
}
// User wants to start a new game, loading intro map
if (!stricmp(command, "StartNewGame"))
{
// Set up loading bar, disable panel, and load the map
engine->ClientCmd("progress_enable");
cl_shownewgamepanel.SetValue(0);
engine->ClientCmd("map d1_trainstation_03");
}
}
And in the res file:
"command" "engine ToggleNewGame"
"notmulti" "1"
Also, if you see anything I can shorten, please advise! (Such as loading a new
map... I have to enable the progress bar, hide the panel so it doesn't show up
when I start a new game, and then load the map... easier way?).
--
Kamran A
Get Firefox! Safer, Faster, Better.[1]
Down with Internet Explorer! Say "NO!" to Spyware! Use Firefox
===References:===
1. http://www.spreadfirefox.com/?q=affiliates&id=0&t=85
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders