[THUG+][PC]Advanced Menus

Tutorials for all THUG+ games goes here.
Forum rules
This forum is only for posting tutorials.
Specify what game it is for, and please take a look at this Template.
Post Reply
Morten1337
Site Admin
Posts: 322
Joined: Mon Mar 01, 2010 2:23 pm
Location: Norway

[THUG+][PC]Advanced Menus

Post by Morten1337 » Sun Mar 14, 2010 9:31 am

Advanced menu items

In this tutorial i will show you how to create advanced menu items;
off/on menu, checkbox menu, number items and and switch items.

NOTE:I assume you have already made a submenu

Off/On Menu:
I will show you two ways,

:i $theme_menu_add_flag_item$:s{
:i $text$ = %s(10,"Something:")
:i $flag$ = $A_GLOBAL_FLAG$
:i $id$ = $OffOn_Item$
:i :s}
This is the text, ex. "Perfect balance:"
The flag is just a integer, see "global_flags.qb" *
This is the Id, it can be whatever you want. Not really necessary, but still... xD

*Setup your own global flags, and how they work in functions:
These integers can be put anywhere in the qb, and looks like this:

Code: Select all

:i $A_GLOBAL_FLAG$ = %i(322,00000142)
If you're gonna add your own, they must start at "322", because the others are already used.

What does a flag do in a function?

Code: Select all

:i function $Example_CheckFlag$
:i if call $GetGlobalFlag$ arguments 
		$flag$ = $A_GLOBAL_FLAG$ 
	:i call $create_console_message$ arguments 
			$text$ = %s(52,"Flag is ON") #/ IF your flag (A_GLOBAL_FLAG) is "On", then it will post message in chat.
:i else
	:i call $create_console_message$ arguments 
			$text$ = %s(52,"Flag is OFF") #/ IF your flag (A_GLOBAL_FLAG) is "Off", then it will post a different message in chat.
:i endif
:i endfunction
Okay that was the easiest way to create an off/on menu item.
This next one will give you more options and is more flexible, but is "bigger" code-wise.

Off/On Menu pt2:
For this menu you can use almost any menu -style/item; theme_menu_add_item, add_roundbar_menu_item... (as long as they have the "extra_text" parameter)
I will be using "theme_menu_add_item" in this example.
:i $theme_menu_add_item$:s{
:i $text$ = %s(10,"Something:")
:i $extra_text$ = %s(3,"off")
:i $id$ = $OffOn_Item$
:i $pad_choose_script$ = $Example_Toggle_OffOn$
:i $pad_choose_params$ = :s{$id$ = $OffOn_Item$$flag$ = $A_GLOBAL_FLAG$:s}
#/ :i $pad_choose_params$ = :s{$id$ = $OffOn_Item$$value$ = $A_VALUE$:s}
:i :s}
This is the text, ex. "Perfect balance:"
This is the text that will be changed, just leave it as the initial state
This is the Id, it can be whatever you want.
This is the link to the function that will change the flag or change a value. *
This is the parameters for the function we will be writing later, (Example_Toggle_OffOn) The line under is commented, its just an alternative parameter.

The function that toggles everything!

Code: Select all

:i function $Example_Toggle_OffOn$
:i if call $GotParam$ arguments #/ This checks if the "flag" parameter is used, See the (pad_choose_params)-part.
		$flag$							#/ if it returns false then we know that we'll be using the alternative, which is "value"

	:i if call $GetGlobalFlag$ arguments #/ GLOBAL means that; "flag" is whatever its referred as, in this case "A_GLOBAL_FLAG". 
			$flag$ = %GLOBAL%$flag$		 #/ See the (pad_choose_params)-part in the menuitem.

		:i call $UnSetGlobalFlag$ arguments /# This toggles Off the flag, since its already On.
			$flag$ = %GLOBAL%$flag$
		:i call $SetScreenElementProps$ arguments #/ This will change the "extra_text"
			$id$ = %GLOBAL%$$id$$extra_text$ = %s(3,"Off") /# GLOBAL Id, is "OffOn_Item", see the "pad_choose_params".

:i else #/ This tells what do do if "GetGlobalFlag" returns false.

		:i call $SetGlobalFlag$ arguments /# This toggles On the flag, since its already Off.
			$flag$ = %GLOBAL%$flag$
		:i call $SetScreenElementProps$ arguments #/ This will change the "extra_text"
			$id$ = %GLOBAL%$$id$$extra_text$ = %s(2,"On")/# GLOBAL Id, is "OffOn_Item", see the "pad_choose_params".
:i endif #/ end of the "GetGlobalFlag"-IF

:i else #/ If "GotParam" returns false! Underneath, the code for changing a "value" will be added.

:i if ((%GLOBAL%$value$) = %i(1,00000001))
	:i call $change$ arguments #/ If the value is 1/"on" then change it to 0/"off"
			(%GLOBAL%$value$) = %i(0,00000000)
		:i call $SetScreenElementProps$ arguments #/ This will change the "extra_text"
			$id$ = %GLOBAL%$id$$extra_text$ = %s(3,"Off") /# GLOBAL Id, is "OffOn_Item", see the "pad_choose_params".
:i else
	:i call $change$ arguments#/ If the value is  0/"off" then change it to 1/"on"
			(%GLOBAL%$value$) = %i(1,00000001)
		:i call $SetScreenElementProps$ arguments #/ This will change the "extra_text"
			$id$ = %GLOBAL%$id$$extra_text$ = %s(2,"On")/# GLOBAL Id, is "OffOn_Item", see the "pad_choose_params".
:i endif #/ end of the "value"-IF
:i endif #/ end of the "GotParam"-IF
:i endfunction
NOTE:This tutorial will be updated when i get the other parts finished... :D
++sorry, i know those function examples are difficult to read... but had to put it in a "code", because thats the only way I could have spacers/tab.

~Morten

Morten1337
Site Admin
Posts: 322
Joined: Mon Mar 01, 2010 2:23 pm
Location: Norway

[TUROTIAL: Thug1++]Advanced Menus; "Checkbox menu"

Post by Morten1337 » Sun Mar 14, 2010 12:18 pm

Checkbox menu:
For this menu you can use almost any menu -style/item; theme_menu_add_item, add_roundbar_menu_item
I will be using "theme_menu_add_item" in this example too.

Checkbox menus will do exactly the same as the 2nd off/on menu, so the toggle function is almost the same as "Example_Toggle_OffOn".
A check box menu consists of 3 items; the menu/text element, checkbox screen element texture, and the checkmark element texture.
:i $theme_menu_add_item$:s{
:i $text$ = %s(10,"Something:")
:i $id$ = $menu_checkbox$
:i $extra_text$ = %s(0,"") #/ nvm
:i $pad_choose_script$ = $Example_toggle_checkbox$
:i $pad_choose_params$ = :s{$flag$ = $A_GLOBAL_FLAGS$$checkm_id$ = $checkmark_id$:s}
:i $no_sound$ #/ nvm
:i :s}
This is the text, ex "Collision: "
This is the Id, can be whatever. Is very important
This is the function that will change the state of a "Flag"
Parameters for "Example_toggle_checkbox",

The code underneath needs to be added inside the same function as the menu item. But it MUST be added under the item code.

Code: Select all

:i call $Theme_GetHighlightedTextColor$ arguments 
		$return_value$ = $check_rgba$
	:i $CreateScreenElement$:s{
		:i $type$ = $SpriteElement$
		:i $parent$ = $menu_checkbox$ #/Here we put the Id of our menu item, in this case "menu_checkbox"
		:i $texture$ = $checkbox$
		:i $pos$ = %vec2(120.000000,-13.000000)
		:i $just$ = :a{call $center$ arguments 
				$top$:a}
		:i $scale$ = %f(0.550000)
		:i $rgba$ = %GLOBAL%$checkbox_rgba$
		:i $z_priority$ = %i(5,00000005)
	:i :s}
	:i if NOT call $GetGlobalFlag$ arguments 
			$flag$ = $A_GLOBAL_FLAGS$ #/ this is for getting the flag, if its true then the "checkmark" will be drawn.
		:i $CreateScreenElement$:s{
			:i $type$ = $SpriteElement$
			:i $parent$ = %GLOBAL%$id$
			:i $id$ = $checkmark_id$ 	#/this is the Id.
			:i $texture$ = $checkmark$
			:i $pos$ = %vec2(15.000000,-9.000000)
			:i $just$ = :a{call $center$ arguments 
					$top$:a}
			:i $rgba$ = %GLOBAL%$check_rgba$
			:i $z_priority$ = %i(6,00000006)
			:i $scale$ = %f(1.400000)
		:i :s}
	:i else 
		:i $CreateScreenElement$:s{
			:i $type$ = $SpriteElement$
			:i $parent$ = %GLOBAL%$id$
			:i $id$ = $checkmark_id$ 	#/this is the Id... no shit, sherlock!
			:i $texture$ = $checkmark$
			:i $pos$ = %vec2(15.000000,-7.000000)
			:i $just$ = :a{call $center$ arguments 
					$top$:a}
			:i $rgba$ = %GLOBAL%$check_rgba$
			:i $z_priority$ = %i(6,00000006)
			:i $scale$ = %f(1.400000)
		:i :s}
	:i endif
Okay here's the function for toggling the flag:
Read the comments on the "Example_Toggle_OffOn" for explanations on "%GLOBAL%, and SetScreenElementProps"

Code: Select all

:i function $Example_toggle_checkbox$
	:i call $Theme_GetHighlightedTextColor$ arguments 
		$return_value$ = $check_rgba$
	:i if NOT call $GetGlobalFlag$ arguments 
			$flag$ = %GLOBAL%$flag$
		:i call $SetScreenElementProps$ arguments 
			$id$ = %GLOBAL%$checkb_id$$rgba$ = :a{%i(0,00000000)%i(0,00000000)%i(0,00000000)%i(0,00000000):a}
		:i call $SetGlobalFlag$ arguments 
			$flag$ = %GLOBAL%$flag$
	:i else 
		:i call $SetScreenElementProps$ arguments 
			$id$ = %GLOBAL%$checkb_id$$rgba$ = %GLOBAL%$check_rgba$
		:i call $UnsetGlobalFlag$ arguments 
			$flag$ = %GLOBAL%$flag$
	:i endif
:i endfunction

Morten1337
Site Admin
Posts: 322
Joined: Mon Mar 01, 2010 2:23 pm
Location: Norway

[TUROTIAL: Thug1++]Advanced Menus; "Number items"

Post by Morten1337 » Mon Mar 15, 2010 11:27 am

Number items:
I will show you how to make a menu item that can change the value of an integer. Similar to the "gamma menu or sound options",
:i $theme_menu_add_number_item$:s{
:i $text$ = %s(11,"Something")
:i $id$ = $menu_number_item$
:i $min$ = %i(0,00000000)
:i $max$ = %i(500,00000000)
:i $step$ = %i(10,0000000a)
#/:i $avoid$ = %i(50,0000000a)

:i $value$ = $A_VALUE$
:i $pad_left_script$ = $Example_update_value$
:i $pad_right_script$ = $Example_update_value$

:i :s}
This is the text, ex "Trick Score:"
This is the Id, can be whatever
"min" is the lowest value, "max" is the highest value, and "step" is the value that will be added, ex (250 + 10)
This means that your menu cannot change the value to "-10" or "510".
"avoid" means that this value should be skipped. I THINK you can add an array with integers if you want to skip more values.

ex.

Code: Select all

:i $avoid$ = :a{%i(20,00000000)%i(50,00000000)%i(150,00000000)%i(250,00000000):a}
The value is the "number" that will be changed, see "physics.qb" for some examples, ex "Rail_Corner_Leave_Angle"
This tells the game to run the "Example_update_value"-function when either left or right is pressed

Okay now lets create the function that will change our value.
It's really simple;

Code: Select all

:i function $Example_update_value$
	:i call $change$ arguments
		$A_VALUE$ = %GLOBAL%$value$ #/ I've explained how "GLOBAL" works before, but this time its referred by the "theme_menu_add_number_item"-function.
												#/ See "A_VALUE", remember that it needs to be the same as in the menuitem-part.
:i endfunction

qwertysind
Posts: 117
Joined: Sun Mar 14, 2010 9:07 am

Re: [TUROTIAL: Thug1++]Advanced Menus

Post by qwertysind » Mon Mar 15, 2010 11:39 am

I can't understand how to create off/on menu =(( man can you do tutorial of off/on menu for thaw, with queen bee, or video :D

Skrillex
Posts: 8
Joined: Thu May 19, 2011 6:38 pm

Re: [THUG+][PC]Advanced Menus

Post by Skrillex » Sun May 29, 2011 8:06 pm

Helped me alotof thx
and do u now where i can find how to make more options(like debug menu) ?
Can someone give me a fuckin' gun to kill me? (:

Morten1337
Site Admin
Posts: 322
Joined: Mon Mar 01, 2010 2:23 pm
Location: Norway

Re: [THUG+][PC]Advanced Menus

Post by Morten1337 » Mon May 30, 2011 4:31 am

Skrillex wrote:Helped me alotof thx
and do u now where i can find how to make more options(like debug menu) ?
i'm not sure if i understand, the function for debug menu is create_test_menu

Post Reply