Advertisement
Guest User

Untitled

a guest
Mar 14th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. local ments
  2.  
  3. local radialOpen = false
  4. local prevSelected, prevSelectedVertex
  5.  
  6. function GM:OpenRadialMenu(elements)
  7.     radialOpen = true
  8.     gui.EnableScreenClicker(true)
  9.     ments = elements or {}
  10.     prevSelected = nil
  11. end
  12.  
  13. function GM:CloseRadialMenu()
  14.     radialOpen = false
  15.     gui.EnableScreenClicker(false)
  16. end
  17.  
  18. local function getSelected()
  19.     local mx, my = gui.MousePos()
  20.     local sw,sh = ScrW(), ScrH()
  21.     local total = #ments
  22.     local w = math.min(sw * 0.45, sh * 0.45)
  23.     local h = w
  24.     local sx, sy = sw / 2, sh / 2
  25.     local x2,y2 = mx - sx, my - sy
  26.     local ang = 0
  27.     local dis = math.sqrt(x2 ^ 2 + y2 ^ 2)
  28.     if dis / w <= 1 then
  29.         if y2 <= 0 && x2 <= 0 then
  30.             ang = math.acos(x2 / dis)
  31.         elseif x2 > 0 && y2 <= 0 then
  32.             ang = -math.asin(y2 / dis)
  33.         elseif x2 <= 0 && y2 > 0 then
  34.             ang = math.asin(y2 / dis) + math.pi
  35.         else
  36.             ang = math.pi * 2 - math.acos(x2 / dis)
  37.         end
  38.         return math.floor((1 - (ang - math.pi / 2 - math.pi / total) / (math.pi * 2) % 1) * total) + 1
  39.     end
  40. end
  41.  
  42. function GM:RadialMousePressed(code, vec)
  43.     if radialOpen then
  44.         local selected = getSelected()
  45.         if selected && selected > 0 && code == MOUSE_LEFT then
  46.             if selected && ments[selected] then
  47.                 RunConsoleCommand("mu_taunt", ments[selected].Code)
  48.             end
  49.         end
  50.         self:CloseRadialMenu()
  51.     end
  52. end
  53.  
  54. local elements
  55. local function addElement(transCode, code)
  56.     local t = {}
  57.     t.TransCode = transCode
  58.     t.Code = code
  59.     table.insert(elements, t)
  60. end
  61.  
  62. concommand.Add("+menu", function (client, com, args, full)
  63.     if client:Alive() && client:Team() == 2 then
  64.         elements = {}
  65.         addElement("Help", "help")
  66.         addElement("Funny", "funny")
  67.         addElement("Scream", "scream")
  68.         addElement("Morose", "morose")
  69.         GAMEMODE:OpenRadialMenu(elements)
  70.     end
  71. end)
  72.  
  73. concommand.Add("-menu", function (client, com, args, full)
  74.     GAMEMODE:RadialMousePressed(MOUSE_LEFT)
  75. end)
  76.  
  77. local tex = surface.GetTextureID("VGUI/white.vmt")
  78.  
  79. local function drawShadow(n,f,x,y,color,pos)
  80.     draw.DrawText(n,f,x + 1,y + 1,color_black,pos)
  81.     draw.DrawText(n,f,x,y,color,pos)
  82. end
  83.  
  84. local circleVertex
  85.  
  86. local fontHeight = draw.GetFontHeight("MersRadial")
  87. function GM:DrawRadialMenu()
  88.     if radialOpen then
  89.         local sw,sh = ScrW(), ScrH()
  90.         local total = #ments
  91.         local w = math.min(sw * 0.45, sh * 0.45)
  92.         local h = w
  93.         local sx, sy = sw / 2, sh / 2
  94.  
  95.         local selected = getSelected() or -1
  96.  
  97.  
  98.         if !circleVertex then
  99.             circleVertex = {}
  100.             local max = 50
  101.             for i = 0, max do
  102.                 local vx, vy = math.cos((math.pi * 2) * i / max), math.sin((math.pi * 2) * i / max)
  103.  
  104.                 table.insert(circleVertex, {x = sx + w* 1 * vx, y= sy + h* 1 * vy})
  105.             end
  106.         end
  107.  
  108.         surface.SetTexture(tex)
  109.         local defaultTextCol = color_white
  110.         if selected <= 0 || selected ~= selected then
  111.             surface.SetDrawColor(20,20,20,180)
  112.         else
  113.             surface.SetDrawColor(20,20,20,120)
  114.             defaultTextCol = Color(150,150,150)
  115.         end
  116.         surface.DrawPoly(circleVertex)
  117.  
  118.         local add = math.pi * 1.5 + math.pi / total
  119.         local add2 = math.pi * 1.5 - math.pi / total
  120.  
  121.         for k,ment in pairs(ments) do
  122.             local x,y = math.cos((k - 1) / total * math.pi * 2 + math.pi * 1.5), math.sin((k - 1) / total * math.pi * 2 + math.pi * 1.5)
  123.  
  124.             local lx, ly = math.cos((k - 1) / total * math.pi * 2 + add), math.sin((k - 1) / total * math.pi * 2 + add)
  125.  
  126.             local textCol = defaultTextCol
  127.             if selected == k then
  128.                 local vertexes = prevSelectedVertex
  129.  
  130.                 if prevSelected != selected then
  131.                     prevSelected = selected
  132.                     vertexes = {}
  133.                     prevSelectedVertex = vertexes
  134.                     local lx2, ly2 = math.cos((k - 1) / total * math.pi * 2 + add2), math.sin((k - 1) / total * math.pi * 2 + add2)
  135.  
  136.                     table.insert(vertexes, {x = sx, y = sy})
  137.  
  138.                     table.insert(vertexes, {x = sx + w* 1 * lx2, y= sy + h* 1 * ly2})
  139.  
  140.                     local max = math.floor(50 / total)
  141.                     for i = 0, max do
  142.                         local addv = (add - add2) * i / max + add2
  143.                         local vx, vy = math.cos((k - 1) / total * math.pi * 2 + addv), math.sin((k - 1) / total * math.pi * 2 + addv)
  144.  
  145.                         table.insert(vertexes, {x = sx + w* 1 * vx, y= sy + h* 1 * vy})
  146.                     end
  147.  
  148.                     table.insert(vertexes, {x = sx + w* 1 * lx, y= sy + h* 1 * ly})
  149.  
  150.                 end
  151.  
  152.                 surface.SetTexture(tex)
  153.                 surface.SetDrawColor(20,120,255,120)
  154.                 surface.DrawPoly(vertexes)
  155.  
  156.                 textCol = color_white
  157.             end
  158.  
  159.             drawShadow(translate["voice" .. ment.TransCode], "MersRadial", sx + w * 0.6 * x, sy + h * 0.6 * y - fontHeight / 3,textCol, 1)
  160.             drawShadow(translate["voice" .. ment.TransCode .. "Description"], "MersRadialSmall", sx + w * 0.6 * x, sy + h * 0.6 * y + fontHeight / 2, textCol, 1)
  161.  
  162.         end
  163.     end
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement