Advertisement
VADemon

unrealsoftware.de/files_show.php?file=10921

Sep 5th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. This is a universal utility script, which allows you to easily create multi-page menus and assign any functions to their buttons. Menus can be created both out of the 'menus' table and dynamically, to allow for changing variables. The documentation is quite extensive and exhaustive, so it should answer most of the how-to questions.
  2.  
  3. [more=Documentation]
  4. :>: A menu table - be it in the menus table or dynamic - must have a title item that determines the title, an items table which determines the menu items and which has tables for each button of the following format in it:
  5. [code]
  6. {ButtonName, ButtonDescription, ButtonData, ButtonFunction}
  7. [/code]
  8.  
  9. ButtonName and ButtonDescription are usually strings while ButtonData is usually a table. But they can also be functions that return specific values.
  10. [more=Documentation on Button Functions]
  11. This only applies if you make it a function and not a string
  12.  
  13. [b]ButtonName[/b]
  14. Arguments: playerID [number], buttonData [table]
  15. Return: must return a string
  16.  
  17. [b]ButtonDescription[/b]
  18. Arguments: playerID [number], buttonData [table]
  19. Return: must return a string
  20.  
  21. [b]ButtonData[/b]
  22. Arguments: playerID [number]
  23. Return: must return a table containing the data
  24.  
  25. [b]ButtonFunction[/b]
  26. Arguments: playerID [number], buttonData [table], menuTitle [string], menuButton [number]
  27. Return: does not matter
  28. [u]Note:[/u] menuTitle and menuButton are passed directly from cs2dhook:menu
  29.  
  30.  
  31. The ButtonName, -Description and -Data functions are called everytime when a menu is constructed.
  32.  
  33. If you use addButton to initialize the functions above (initButtonName and other init* arguments), then playerID equals 0!
  34. Additionally, ButtonData is called only once and before ButtonName and ButtonDescription functions.
  35. [/more]
  36.  
  37. UniMenu's internal menu table looks like this:
  38. [code]
  39. {
  40. title = "Test Title@b",
  41. items = {
  42. {"Test Button", "Test Description", {}, function (id) msg2(id,"Test successful!") end}
  43. }
  44. }
  45. [/code]
  46.  
  47. :>: Menus are opened by calling the [b]unimenu[/b] function. It has the following arguments:
  48.  
  49. :o: [i]id[/i] - player ID to open the menu to. [i]number[/i]
  50. :o: [i]construct[/i] - construct the menu anew or use the cached version? [i]boolean[/i]
  51. :o: [i]targetMenu[/i] - menu to show. [i]table/number/string[/i]
  52. :o: [i]page[/i] - page of the menu to show. [i]number[/i]
  53.  
  54. The most versatile and important argument is [b]targetMenu[/b]:
  55. :o: [i]is a Table[/i] - This table must be a correctly constructed menu table, like other menus in [i]unimenu_menus[/i]
  56. :o: [i]is a Number or String[/i] - a menus table index to open a menu out of that (this menu must exist under unimenu_menus[ targetMenu ])
  57. :o: [i]equals "current"[/i] - Opens the currently opened menu
  58.  
  59. If you have a menu that is extensive but does not change, specify false as construct, so the script wouldn't construct a menu anew, but open the cached page.
  60.  
  61.  
  62. :>: How to make a menu
  63. There are two methods. There're examples for both of them in unimenu_menus.lua
  64.  
  65. 1) You can change the unimenu_menus table directly in the script. But this is slow and produces messy code. Not recommended
  66. 2) With the new method, you call the according functions from anywhere in the code
  67. [more=New method explained]
  68. You must first create a menu:
  69. [code]unimenu_newMenu("my_menu", "My Lovely Menu")[/code]
  70. With this, we created an empty menu without buttons. To open this menu you have to execute the unimenu functions with parameters unimenu(id, true, "my_menu", 1)
  71.  
  72. Now, we'll add a button to it:
  73. [code]
  74. local showMessage = function (id, data)
  75. msg("©100100100This is a gray message from UniMenu!")
  76. end
  77. unimenu_addButton("my_menu", "Show message", "Color: Gray", {}, showMessage)
  78. [/code]
  79. If you now click on this menu button, a gray message will show up. That's all!
  80. [/more]
  81.  
  82. [more=Documentation on newMenu and addButton]
  83. [b]unimenu_newMenu(umid, title, items)[/b]
  84. :o: [i]umid[/i] - Internal identifier, which you will need to open that menu. If you don't specify it, you have to save the returned value and use it instead
  85. :o: [i]title[/i] - Menu's title, may end with @b and @i
  86. :o: [i]items[/i] - (optional) put the ready UniMenu-compatible table with buttons here
  87. :o: [i]return value[/i] - If argument umid was specified then it equals umid, if umid is nil then the return is a number value
  88.  
  89.  
  90. [b]unimenu_addButton(umid, buttonName, buttonDesc, data, func, initButtonName, initButtonDesc, initData)[/b]
  91. :o: [i]umid[/i] - Internal identifier, which you need to open a menu.
  92. :o: [i]buttonName[/i] - (string or function) button text on the left side
  93. :o: [i]buttonDesc[/i] - (string or function) button description, grey text on the right side
  94. :o: [i]data[/i] - (table or nil) This table will be passed as an argument to the func function
  95. :o: [i]func[/i] - function which will be called when the button is pressed
  96.  
  97. :o: [i]initButtonName[/i] - if TRUE, call the function buttonName with id=0 and data and save the returned string value to menu's buttonName
  98. :o: [i]initButtonDesc[/i] - same as initButtonName
  99. :o: [i]initButtonData[/i] - same as initButtonName. Note that this is called before buttonName and ButtonDesc are initialized, so both bName and bDesc are going to have the same data to operate with
  100. [/more]
  101.  
  102. [more=Other variables include:]
  103.  
  104. :o: unimenu_lastOpenedMenu [table] - a table containing the last opened menu of each player (1 layer - pmenu[id])
  105. :o: unimenu_menuPageStrings [table] - a table containing actual menu strings for each page of the menu opened by a player (2 layers - spages[id][page])
  106. :o: unimenu_tempData [table] - a table containing cached results for each button and player if buttonData of a menu is a function
  107. [/more]
  108. [/more]
  109.  
  110. [more=Changelog:]
  111. [b]v2.1[/b]
  112. [ADDED] buttonData can also be a function now (called whenever the menu is constructed)
  113. ~ see [url=https://github.com/VADemon/cs2d-script/blob/cd129fa31c3e333ddae064273c0b0c9f80184ccb/unimenu_menus.lua#L155]this for an example[/url]
  114.  
  115. [ADDED] unimenu_addButton can initialize functions instantly, saving returned string values to the menu table (to prevent tons of function calls during menu construction)
  116. [ADDED] Leave hook to delete temporary data of old players
  117.  
  118. [b]v2.0[/b]
  119. [ADDED] You can now specify menu mode (nothing or "@b" or "@i")
  120. [ADDED] Button name and Button description can be both string or a function returning a string
  121. [ADDED] [i]data[/i] variable which contains additional custom data you can use in any of the menu functions
  122. [ADDED] Arguments [i]menu[/i] and [i]sel[/i] (from CS2D menu hook, menu = title, sel = pressed button) are passed to the onClick function
  123. [ADDED] [i]unimenu_newMenu[/i] and [i]unimenu_addButtion[/i] functions for easier menu creation
  124. [CHANGED] You can't use the old UniMenu menu tables anymore, the syntax of those changed slightly. If you want to update, add [b],{} [/b] after the button description string
  125. + Code refactoring[/more]
  126.  
  127. Leave feedback and [url=https://github.com/VADemon/cs2d-script/issues/new]report bugs[/url], should any be found.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement