Difference between revisions of "Toggleable Scoreboard"

From Valve Developer Community
Jump to: navigation, search
(Created page with 'To replace the default behaviour of scoreboards (where one would need to hold down a button to make the scoreboard appear), the following change would make it so the scoreboard b…')
 
m (Formatting/Cleanup)
 
Line 1: Line 1:
To replace the default behaviour of scoreboards (where one would need to hold down a button to make the scoreboard appear), the following change would make it so the scoreboard becomes Toggleable.  
+
== Overview ==
 +
This article will show you how to modify the default behavior of the scoreboard. Instead of requiring the player to hold down the scoreboard key (+showscores) to show the scoreboard, we'll modify it so that it toggles on and off.
 +
 
 +
'''This has been tested on SDK Template technology and may or may not work on other engine branches!'''
 +
 
 +
== Code ==
 +
 
 +
Open '''in_main.cpp''', and modify the '''IN_ScoreDown''' (Lines 503-510), and the '''IN_ScoreUp''' (Lines 512-520) functions.
  
Open the file in_main.cpp and modify the IN_ScoreDown and IN_ScoreUp functions to the following:
 
 
<source lang=cpp>
 
<source lang=cpp>
 +
//Replace the old function entirely with this
 
void IN_ScoreDown( const CCommand &args )
 
void IN_ScoreDown( const CCommand &args )
 
{
 
{
Line 20: Line 27:
 
}
 
}
  
 +
//Replace the old function entirely with this
 
void IN_ScoreUp( const CCommand &args )
 
void IN_ScoreUp( const CCommand &args )
 
{
 
{
Line 25: Line 33:
 
}
 
}
 
</source>
 
</source>
 +
 +
== Conclusion ==
 +
With this simple change, the scoreboard will go from the button having to be held down, to having the scoreboard be toggled on or off each time the button is pressed.
 +
 +
 
[[Category:VGUI]] [[Category:Programming]]
 
[[Category:VGUI]] [[Category:Programming]]

Latest revision as of 19:55, 10 April 2011

Overview

This article will show you how to modify the default behavior of the scoreboard. Instead of requiring the player to hold down the scoreboard key (+showscores) to show the scoreboard, we'll modify it so that it toggles on and off.

This has been tested on SDK Template technology and may or may not work on other engine branches!

Code

Open in_main.cpp, and modify the IN_ScoreDown (Lines 503-510), and the IN_ScoreUp (Lines 512-520) functions.

//Replace the old function entirely with this
void IN_ScoreDown( const CCommand &args )
{
	KeyDown( &in_score, args[1] );

	if(gViewPortInterface)
	{
		if ((gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD ))->IsVisible())
		{
			gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, false );
		}
		else 
		{
			gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true );
		}
	}
}

//Replace the old function entirely with this
void IN_ScoreUp( const CCommand &args )
{

}

Conclusion

With this simple change, the scoreboard will go from the button having to be held down, to having the scoreboard be toggled on or off each time the button is pressed.