MeepDarknessMeep

Nice little HUDPaint menu

Jul 8th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.49 KB | None | 0 0
  1. S = {}
  2.  
  3. surface.CreateFont("Font222", {font = "BudgetLabel", size = 30, weight = 500, antialias = false, underline = false, shadow = true, outline = true})
  4. surface.CreateFont("Font333", {font = "BudgetLabel", size = 22, weight = 500, antialias = false, underline = false, shadow = true, outline = true})
  5.  
  6. S.y = 1
  7. S.x = 1
  8. S.enter = false
  9. S.LastTime = CurTime()
  10. S.fadeouttime = 5
  11. local indentx = 4
  12. local indenty = 2
  13.  
  14. function S.insert(name)
  15.     if not S.table or S.table[name] then return false end
  16.     if not type(name) == "string" then return false end
  17.     local i = #S.table + 1
  18.     S.table[i] = {}
  19.     S.table[i].name = name
  20.     S.table[i].options = {}
  21.     return true
  22. end
  23.  
  24. function S.exists(name)
  25.     for i, v in pairs(S.table) do
  26.         if v.name == name then return i end
  27.     end
  28.     return false
  29. end
  30.  
  31. function S.insert2(name, name2, func)
  32.     if not type(name) == "string" or not type(name2) == "string" then return false end
  33.     if not S.table then return false end
  34.     for i = 1, #S.table do
  35.         if S.table[i].name == name then
  36.             local k = #S.table[i].options + 1
  37.             S.table[i].options[k] = {}
  38.             S.table[i].options[k].name = name2
  39.             S.table[i].options[k].func = func
  40.         end
  41.     end
  42. end
  43.  
  44. function S.exists2(name, name2)
  45.     local i = S.exists(name)
  46.     if not i then return false end
  47.     for k = 1, #S.table[i].options do
  48.         if S.table[i].options[k].name == name2 then
  49.             return true, k
  50.         end
  51.     end
  52.     return false
  53. end
  54.  
  55. concommand.Add("left", function()
  56.     if S.x > 1 then
  57.     else
  58.         S.y = S.y - 1
  59.         if S.y < 1 then S.y = #S.table end
  60.     end
  61.     S.LastTime = CurTime()
  62. end)
  63.  
  64. concommand.Add("right", function()
  65.     if S.x > 1 then
  66.     else
  67.         S.y = S.y + 1
  68.         if S.y > #S.table then S.y = 1 end
  69.     end
  70.     S.LastTime = CurTime()
  71. end)
  72.  
  73. concommand.Add("down", function()
  74.     S.x = S.x + 1
  75.     S.LastTime = CurTime()
  76. end)
  77.  
  78. concommand.Add("up", function()
  79.     S.x = S.x - 1
  80.     if S.x < 1 then S.x = 1 end
  81.     S.LastTime = CurTime()
  82. end)
  83.  
  84. concommand.Add("enter", function()
  85.     if S.x > 1 then
  86.         S.enter = true
  87.     end
  88.     S.LastTime = CurTime()
  89. end)
  90.    
  91.  
  92. hook.Add("HUDPaint", "Paintstuff", function()
  93.     surface.SetFont("Font222")
  94.     local fcurtime = S.LastTime + 5
  95.     local acurtime = CurTime()
  96.     local alpha = 255
  97.    
  98.     if acurtime > fcurtime then
  99.         local dif = acurtime - fcurtime
  100.         local numdif = dif / S.fadeouttime
  101.         alpha = (1 - numdif) * 255
  102.         if alpha < 40 then alpha = 40 end
  103.     end
  104.    
  105.     local x = ScrW()
  106.     local y = ScrH()
  107.     local xsides = 0
  108.     local yheight = y / 19
  109.    
  110.     surface.SetDrawColor(15,15,15,alpha)
  111.     surface.DrawRect(0, 0, x, yheight)
  112.     local tbl = S.table
  113.     local tabx = (x - xsides * 2) / #tbl
  114.     local num = 0
  115.     for k,v in pairs(S.table) do
  116.         local color = Color(75,75,75,alpha)
  117.         if k == S.y then
  118.             surface.SetDrawColor(0,0,51,alpha)
  119.             color = Color(0,0,151,alpha)
  120.         else
  121.             surface.SetDrawColor(20,20,20,alpha)
  122.         end
  123.         local x2 = xsides + tabx * num + indentx
  124.         surface.DrawRect(x2, indenty, tabx - indentx, yheight - indenty * 2)
  125.         local w, h = surface.GetTextSize(v.name or "ERROR")
  126.         local y2 = (yheight - indenty * 2) - h
  127.         draw.DrawText(v.name or "ERROR", "Font222", xsides + tabx * num + indentx + tabx / 2, y2, color, TEXT_ALIGN_CENTER)
  128.         surface.SetDrawColor(50,50,50,alpha)
  129.         if k == S.y and S.x > 1 then
  130.             if #v.options < S.x - 1 then
  131.                 S.x = #v.options + 1
  132.             end
  133.             if #v.options > 0 then
  134.                 local opty = yheight * #v.options
  135.                 surface.DrawRect(x2, indenty * 3 + yheight, tabx - indentx, opty)
  136.                 local num2 = 0
  137.                
  138.                 local indentx = indenty
  139.                
  140.                 for i = 1, #v.options do
  141.                     surface.SetDrawColor(20,20,20,alpha)
  142.                     local color = Color(75,75,75,alpha)
  143.                     if S.x - 1 == i then
  144.                         surface.SetDrawColor(0,0,51,alpha)
  145.                         if S.enter then
  146.                             S.enter = false
  147.                             v.options[i].func()
  148.                         end
  149.                     end
  150.                     if S.x - 1 == i then
  151.                         color = Color(0,0,151,alpha)
  152.                     end
  153.                     surface.DrawRect(x2 + indentx, indenty * 4 + yheight * num2 + yheight, tabx - indentx * 4, yheight - indenty * 2)
  154.                     draw.DrawText(v.options[i].name or "ERROR", "Font222", xsides + tabx * num + indentx * 2 + tabx / 2, yheight * num2 + y2 + indenty * 3 + yheight, color, TEXT_ALIGN_CENTER)
  155.                    -- v.options[i].name
  156.                    num2 = num2 + 1
  157.                 end
  158.             end
  159.         end
  160.         num = num + 1
  161.     end
  162.    
  163. end)
  164.  
  165. hook.Add("Think", "Buttons", function()
  166.     if not LocalPlayer() then return end
  167.     if LocalPlayer():KeyPressed(KEY_DOWN) then
  168.         RunConsoleCommand("down")
  169.     end
  170.     if LocalPlayer():KeyPressed(KEY_UP) then
  171.         RunConsoleCommand("up")
  172.     end
  173.     if LocalPlayer():KeyPressed(KEY_LEFT) then
  174.         RunConsoleCommand("left")
  175.     end
  176.     if LocalPlayer():KeyPressed(KEY_ENTER) then
  177.         RunConsoleCommand("enter")
  178.     end
  179.     if LocalPlayer():KeyPressed(KEY_RIGHT) then
  180.         RunConsoleCommand("right")
  181.     end
  182. end)
Advertisement
Add Comment
Please, Sign In to add comment