[THUG1+][PC]Advanced Menus

Tutorial forum for Tony Hawk games.
Forum rules
No requests, use other sections for that. TAG your titles [THAW][THUG2] etc.
Morten1337
Posts: 132
Joined: Tue Jun 08, 2010 11:11 pm
Contact:

[THUG1+][PC]Advanced Menus

Postby Morten1337 » Fri Dec 24, 2010 1:45 am

Morten1337@thmods.com/forum/ wrote: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@thmods.com/forum/ wrote: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

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 30 guests