<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.splashdamage.com/index.php?action=history&amp;feed=atom&amp;title=GUIs%3A_Templates</id>
	<title>GUIs: Templates - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.splashdamage.com/index.php?action=history&amp;feed=atom&amp;title=GUIs%3A_Templates"/>
	<link rel="alternate" type="text/html" href="https://wiki.splashdamage.com/index.php?title=GUIs:_Templates&amp;action=history"/>
	<updated>2026-04-07T17:08:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.splashdamage.com/index.php?title=GUIs:_Templates&amp;diff=1486&amp;oldid=prev</id>
		<title>192.168.0.142 at 10:33, 16 October 2007</title>
		<link rel="alternate" type="text/html" href="https://wiki.splashdamage.com/index.php?title=GUIs:_Templates&amp;diff=1486&amp;oldid=prev"/>
		<updated>2007-10-16T10:33:53Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Templates can be used for reducing the size of GUIs and improving the readability of them.&amp;lt;includeonly&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{main|GUIs: Templates}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
Templates are very useful and the use of them is essential in creating some of the more complex GUIs like the main menu, server browser and the limbo menu. It increases the readability of the scripts a lot since often used script code can be hidden away in the templates and it can guarantee that for example buttons in the main menu all behave and look the same way.&lt;br /&gt;
&lt;br /&gt;
Basic example of a GUI template:&lt;br /&gt;
 $template simpleTemplate&lt;br /&gt;
 	[put text here]&lt;br /&gt;
 $endtemplate&lt;br /&gt;
All occurrences of ''simpleTemplate'' in any GUIs will be replaced with the ''[put text here]'' keywords when parsing the GUIs.&lt;br /&gt;
&lt;br /&gt;
== Naming convention ==&lt;br /&gt;
Templates that are generic and could/is being used several places should have one underscore. Templates or &amp;quot;helper templates&amp;quot; that are only used in a GUI should have two underscores.&lt;br /&gt;
&lt;br /&gt;
Both these templates are from ''guis/common/utility.include''. ''__right'' is only used as a helper template for ''_right'' and should have two underscores:&lt;br /&gt;
 $template __right( windowName, padding )&lt;br /&gt;
 	( ( gui.windowName.rect.width - rect.width ) - padding )&lt;br /&gt;
 $endtemplate&lt;br /&gt;
 &lt;br /&gt;
 $template _right( windowName )&lt;br /&gt;
 	__right( windowName, PADDING )&lt;br /&gt;
 $endtemplate&lt;br /&gt;
There are hundreds of places where ''_right'' is used since you just about always want to have padding between windows, while ''__right'' is not used outside the include file (except for one case).&lt;br /&gt;
&lt;br /&gt;
== Simple Templates ==&lt;br /&gt;
The simplest templates have no parameters and replaces the parameter name throughout the GUIs with the contents of the template during parsing:&lt;br /&gt;
&lt;br /&gt;
Found in ''guis/common/utility.include'' and used in the main menu:&lt;br /&gt;
 $template _monitor_music_volume&lt;br /&gt;
 	events {&lt;br /&gt;
 		onCVarChanged &amp;quot;s_volumeMusic_dB&amp;quot; {&lt;br /&gt;
 			gui.fadeSoundClass( 1, gui.getCVarFloat( &amp;quot;s_volumeMusic_dB&amp;quot; ), 500 );&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 $endtemplate&lt;br /&gt;
&lt;br /&gt;
Main Menu line ~85:&lt;br /&gt;
 ...&lt;br /&gt;
 _menu_icons&lt;br /&gt;
 _crosshair_materials&lt;br /&gt;
 _monitor_music_volume&lt;br /&gt;
 &lt;br /&gt;
 // init window classes&lt;br /&gt;
 _btn_init&lt;br /&gt;
 _dlg_init&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
== Templates With Parameters ==&lt;br /&gt;
Often templates have arguments, for example the _bottom and _center templates found in ''guis/common/utility.include'', useful for placing a windows in relation to other windows:&lt;br /&gt;
 $template _bottom( windowName )&lt;br /&gt;
 	( ( gui.windowName.rect.height - rect.h ) - PADDING )&lt;br /&gt;
 $endtemplate&lt;br /&gt;
&lt;br /&gt;
 $template _center( windowName, orientation )&lt;br /&gt;
 	( ( gui.windowName.rect.orientation * 0.5 ) - ( rect.orientation * 0.5 ) )&lt;br /&gt;
 $endtemplate&lt;br /&gt;
&lt;br /&gt;
A window at this position:&lt;br /&gt;
 rect rect = ( ( gui.desktop.rect.orientation * 0.5 ) - ( rect.width * 0.5 ) ), ( ( gui.desktop.rect.height - rect.h ) - PADDING ), SCREEN_WIDTH/2, 32;&lt;br /&gt;
is equal to a window at this position using templates:&lt;br /&gt;
 rect rect = _center( desktop, width ), _bottom( desktop ), SCREEN_WIDTH/2, 32;&lt;br /&gt;
The example will place the window at the center of the screen, just above the bottom edge of the GUI. The second version is much easier to read and you can be sure that no spelling mistakes have been made for it since the template is most likely being used in several other places.&lt;br /&gt;
&lt;br /&gt;
A more commpliated template with the use of multiple parameters:&lt;br /&gt;
 $template _horizontal_line( NameParm, XPos, YPos, WidthParm, HeightParm )&lt;br /&gt;
 	windowDef div##NameParm {&lt;br /&gt;
 		properties {&lt;br /&gt;
 			rect 	rect 		= XPos, YPos, WidthParm, HeightParm;&lt;br /&gt;
 			color	backColor 	= COLOR_MED;&lt;br /&gt;
 			string	material	= &amp;quot;window_line_t&amp;quot;;&lt;br /&gt;
 		}&lt;br /&gt;
 $endtemplate&lt;br /&gt;
For many templates like buttons/edit boxes/lists/sliders/etc. there is a closing template which allows you to include the start template then add some additional scripting if needed before closing the window with a _end_&amp;lt;template name&amp;gt;:&lt;br /&gt;
 $template _end_horizontal_line&lt;br /&gt;
 	}&lt;br /&gt;
 $endtemplate&lt;br /&gt;
&lt;br /&gt;
Notice the two ''##'' which means it will concatenate div and the name NameParm. If you create a horizontal line like this for example:&lt;br /&gt;
 _horizontal_line( Horizontal1, 0, 0, SREEN_WIDTH, 4 )&lt;br /&gt;
 _end_horizontal_line&lt;br /&gt;
After parsing it will expand to:&lt;br /&gt;
 windowDef divHorizontal1 {&lt;br /&gt;
 	properties {&lt;br /&gt;
 		rect 	rect 		= 0, 0, SREEN_WIDTH, 4;&lt;br /&gt;
 		color	backColor 	= COLOR_MED;&lt;br /&gt;
 		string	material	= &amp;quot;window_line_t&amp;quot;;&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Names can be made literal with a single # as a prefix. If a template parameter is ''MaterialName'' and the value of ''MaterialName'' is window_line_t then using ''#MaterialName'' will expand to ''&amp;quot;window_line_t&amp;quot;'' after parsing.&lt;br /&gt;
&lt;br /&gt;
== Game Settings Template ==&lt;br /&gt;
The Game Settings dialog in the main menu is actually a template itself so only a single line needs to be included in ''guis/mainmenu/mainmenu.gui'' to include the dialog. It heavily uses templates itself which makes it a lot more readable.&lt;br /&gt;
&lt;br /&gt;
Here's the advanced vehicles section of the game settings, found in ''guis/mainmenu/dialogs/gamesettings.include'':&lt;br /&gt;
 _label_localized( GameSettings_AdvVehicles, localize( &amp;quot;guis/mainmenu/vehicles&amp;quot; ), PADDING, PADDING, 100, BUTTON_HEIGHT, COLOR_WHITE )&lt;br /&gt;
 	properties {&lt;br /&gt;
 		vec2 textAlignment = TA_LEFT, TA_VCENTER;&lt;br /&gt;
 	}&lt;br /&gt;
 _end_label&lt;br /&gt;
 _check( GameSettings_AdvFlight, localize( &amp;quot;guis/mainmenu/advflight&amp;quot; ), $evalfloat( 2 * PADDING ), 0, 120 )&lt;br /&gt;
 	_cvar_bool( ui_advancedFlightControls )&lt;br /&gt;
 _end_check&lt;br /&gt;
		&lt;br /&gt;
To really understand this you just have to look up the template and see what the parameters do.&lt;br /&gt;
&lt;br /&gt;
''guis/mainmenu/components/label.include'':&lt;br /&gt;
 $template _label_localized( NameParm, TextParm, XPos, YPos, Width, Height, ColorParm )&lt;br /&gt;
NameParm is the name of the window. Draw a localized label at XPos/YPos with the Width/Height where TextParm is the text handle with a color of ColorParm.&lt;br /&gt;
&lt;br /&gt;
''guis/mainmenu/components/lines.include'':&lt;br /&gt;
 $template _check( NameParm, TextParm, xPos, yPos, WidthParm )&lt;br /&gt;
NameParm is the name of the window. Draw a check box with the localized text handle TextParm at xPos/yPos with the specified width.&lt;br /&gt;
&lt;br /&gt;
''guis/mainmenu/cvars.include'':&lt;br /&gt;
 $template _cvar_bool( CVarParm )&lt;br /&gt;
This template ties the value of the checkbox with the CVar specified.&lt;br /&gt;
&lt;br /&gt;
Now it is really easy to add another checkbox here if we would want to, here's an example that adds an advanced driving controls checkbox:&lt;br /&gt;
 _check( GameSettings_AdvDriving, localize( &amp;quot;guis/mainmenu/advdriving&amp;quot; ), $evalfloat( 2 * PADDING ), 0, 120 )&lt;br /&gt;
 	_cvar_bool( ui_advancedDrivingControls )&lt;br /&gt;
 _end_check&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:GUIs]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.0.142</name></author>
		
	</entry>
</feed>