Advertisement
davedumas0

Credit = Ideo-gui.lua

Aug 14th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.81 KB | None | 0 0
  1. -- Credit : Ideo
  2.  
  3. --------------------------------------------------------------------------------------------------------------------
  4. -- Graphic Functions
  5. --------------------------------------------------------------------------------------------------------------------
  6.  
  7. Keys = {
  8.     ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  9.     ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  10.     ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  11.     ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  12.     ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  13.     ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  14.     ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  15.     ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  16.     ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
  17. }
  18.  
  19.  
  20.  
  21. Menu = {}
  22. Menu.GUI = {}
  23. Menu.buttonCount = 0
  24. Menu.selection = 0
  25. Menu.hidden = true
  26. MenuTitle = "Menu"
  27.  
  28. function Menu.addButton(name, func,args)
  29.  
  30.     local yoffset = 0.3
  31.     local xoffset = 0
  32.     local xmin = 0.0
  33.     local xmax = 0.2
  34.     local ymin = 0.05
  35.     local ymax = 0.05
  36.     Menu.GUI[Menu.buttonCount+1] = {}
  37.     Menu.GUI[Menu.buttonCount+1]["name"] = name
  38.     Menu.GUI[Menu.buttonCount+1]["func"] = func
  39.     Menu.GUI[Menu.buttonCount+1]["args"] = args
  40.     Menu.GUI[Menu.buttonCount+1]["active"] = false
  41.     Menu.GUI[Menu.buttonCount+1]["xmin"] = xmin + xoffset
  42.     Menu.GUI[Menu.buttonCount+1]["ymin"] = ymin * (Menu.buttonCount + 0.01) +yoffset
  43.     Menu.GUI[Menu.buttonCount+1]["xmax"] = xmax
  44.     Menu.GUI[Menu.buttonCount+1]["ymax"] = ymax
  45.     Menu.buttonCount = Menu.buttonCount+1
  46. end
  47.  
  48.  
  49. function Menu.updateSelection()
  50.     if IsControlJustPressed(1, Keys["DOWN"]) then
  51.         if(Menu.selection < Menu.buttonCount -1 ) then
  52.             Menu.selection = Menu.selection +1
  53.         else
  54.             Menu.selection = 0
  55.         end    
  56.         PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
  57.     elseif IsControlJustPressed(1, Keys["TOP"]) then
  58.         if(Menu.selection > 0)then
  59.             Menu.selection = Menu.selection -1
  60.         else
  61.             Menu.selection = Menu.buttonCount-1
  62.         end
  63.         PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
  64.     elseif IsControlJustPressed(1, Keys["NENTER"])  then
  65.         MenuCallFunction(Menu.GUI[Menu.selection +1]["func"], Menu.GUI[Menu.selection +1]["args"])
  66.         PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
  67.     --elseif IsControlJustPressed(1, Keys["BACKSPACE"])  then
  68.     --      MenuCallFunction(Menu.GUI[Menu.selection -1]["func"], Menu.GUI[Menu.selection -1]["args"])
  69.     --      PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)
  70.     end
  71.     local iterator = 0
  72.     for id, settings in ipairs(Menu.GUI) do
  73.         Menu.GUI[id]["active"] = false
  74.         if(iterator == Menu.selection ) then
  75.             Menu.GUI[iterator +1]["active"] = true
  76.         end
  77.         iterator = iterator +1
  78.     end
  79. end
  80.  
  81. function Menu.renderGUI(options)
  82.     if not Menu.hidden then
  83.         Menu.renderButtons(options)
  84.         Menu.updateSelection()
  85.     end
  86. end
  87.  
  88. function Menu.renderBox(xMin,xMax,yMin,yMax,color1,color2,color3,color4)
  89.     DrawRect(xMin, yMin,xMax, yMax, color1, color2, color3, color4);
  90. end
  91.  
  92. function Menu:setTitle(options)
  93.     SetTextFont(1)
  94.     SetTextProportional(0)
  95.     SetTextScale(1.0, 1.0)
  96.     SetTextColour(255, 255, 255, 255)
  97.     SetTextDropShadow(0, 0, 0, 0,255)
  98.     SetTextEdge(1, 0, 0, 0, 255)
  99.     SetTextDropShadow()
  100.     SetTextOutline()
  101.     SetTextCentre(1)
  102.     SetTextEntry("STRING")
  103.     AddTextComponentString(options.menu_title)
  104.     DrawText(options.x, options.y)
  105. end
  106.  
  107. function Menu:setSubTitle(options)
  108.     SetTextFont(2)
  109.     SetTextProportional(0)
  110.     SetTextScale(options.scale +0.1, options.scale +0.1)
  111.     SetTextColour(255, 255, 255, 255)
  112.     SetTextEntry("STRING")
  113.     AddTextComponentString(options.menu_subtitle)
  114.     DrawRect(options.x,(options.y +0.08),options.width,options.height,options.color_r,options.color_g,options.color_b,150)
  115.     DrawText(options.x - options.width/2 + 0.005, (options.y+ 0.08) - options.height/2 + 0.0028)
  116.  
  117.     SetTextFont(0)
  118.     SetTextProportional(0)
  119.     SetTextScale(options.scale, options.scale)
  120.     SetTextColour(255, 255, 255, 255)
  121.     SetTextDropShadow(0, 0, 0, 0,255)
  122.     SetTextEdge(1, 0, 0, 0, 255)
  123.     SetTextDropShadow()
  124.     SetTextOutline()
  125.     SetTextCentre(0)
  126.     SetTextEntry("STRING")
  127.     AddTextComponentString(options.rightText)
  128.     DrawText((options.x + options.width/2 - 0.0385) , options.y + 0.067)
  129. end
  130.  
  131. function Menu:drawButtons(options)
  132.     local y = options.y + 0.12
  133.  
  134.     for id, settings in pairs(Menu.GUI) do
  135.         SetTextFont(0)
  136.         SetTextProportional(0)
  137.         SetTextScale(options.scale, options.scale)
  138.         if(settings["active"]) then
  139.             SetTextColour(0, 0, 0, 255)
  140.         else
  141.             SetTextColour(255, 255, 255, 255)
  142.         end
  143.         SetTextCentre(0)
  144.         SetTextEntry("STRING")
  145.         AddTextComponentString(settings["name"])
  146.         if(settings["active"]) then
  147.             DrawRect(options.x,y,options.width,options.height,255,255,255,255)
  148.         else
  149.             DrawRect(options.x,y,options.width,options.height,0,0,0,150)
  150.         end
  151.         DrawText(options.x - options.width/2 + 0.005, y - 0.04/2 + 0.0028)
  152.         y = y + 0.04
  153.     end
  154. end
  155.  
  156. function Menu.renderButtons(options)
  157.  
  158.     Menu:setTitle(options)
  159.     Menu:setSubTitle(options)
  160.     Menu:drawButtons(options)
  161.  
  162. end
  163.  
  164. --------------------------------------------------------------------------------------------------------------------
  165.  
  166. function ClearMenu()
  167.     --Menu = {}
  168.     Menu.GUI = {}
  169.     Menu.buttonCount = 0
  170.     Menu.selection = 0
  171. end
  172.  
  173. function MenuCallFunction(fnc, arg)
  174.     _G[fnc](arg)
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement