Advertisement
wifiboost

Untitled

Mar 29th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.34 KB | None | 0 0
  1. local wave = Material("vgui/wave.png", "noclamp smooth")
  2. surface.CreateFont("CustomInputFont", {
  3. font = "Arial", -- Use the desired font name here
  4. size = 16, -- Set the font size (change this value as needed)
  5. weight = 500,
  6. antialias = true
  7. })
  8. net.Receive("ERPPollAdminPanel", function()
  9. -- Base frame content
  10. local frame = ExUI:Frame("Poll - Admin Menu")
  11. frame:SetSize(ScrH()*1, ScrH()*0.8)
  12. frame:Center()
  13. frame.sidebar = ExUI:Sidebar(Color(16, 23, 28), frame)
  14. frame.container = ExUI:Container(frame, FILL)
  15. frame.sidebar:SetContainer(frame.container)
  16.  
  17. -- Creating a poll
  18. frame.dashboard = ExUI:Container(frame.container, FILL)
  19. frame.dashboard.header = ExUI:Header("Dashboard", "Edit settings here", Color(230, 75, 50), frame.dashboard)
  20.  
  21. frame.dashboard.endPoll = ExUI:Button("End active poll (If one)", frame.dashboard, TOP)
  22. frame.dashboard.endPoll:Margin(8)
  23. frame.dashboard.endPoll:SetColor(Color(175, 0, 50))
  24. frame.dashboard.endPoll.DoClick = function()
  25. net.Start("ERPPollEndPoll")
  26. net.SendToServer()
  27. end
  28.  
  29. local a = frame.sidebar:AddOption("Dashboard", false, frame.dashboard)
  30. if a then
  31. local oldPaint = a.Paint
  32. a.Paint = function(self, w, h)
  33. oldPaint(self, w, h)
  34. ExUI:DrawText("D", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  35. end
  36. end
  37.  
  38.  
  39. -- Creating a poll
  40. frame.createPoll = ExUI:Container(frame.container, FILL)
  41. frame.createPoll.header = ExUI:Header("Create Poll", "Create a new poll", Color(230, 75, 50), frame.createPoll)
  42.  
  43. -- The question input
  44. frame.createPoll.question = ExUI:Card(false, frame.createPoll, TOP)
  45. frame.createPoll.question:Margin(8)
  46. frame.createPoll.question:SetTall(80)
  47. frame.createPoll.question:SetPadding(4)
  48.  
  49. frame.createPoll.question.title = vgui.Create("DPanel", frame.createPoll.question)
  50. frame.createPoll.question.title:SetTall(32)
  51. frame.createPoll.question.title:Dock(TOP)
  52. frame.createPoll.question.title.Paint = function(self, w, h)
  53. ExUI:DrawText("The Question", 28, 8, 8, Color(235, 235, 235))
  54. end
  55.  
  56. frame.createPoll.question.entry = ExUI:TextEntry("Who is the best developer?", false, false, frame.createPoll.question, TOP)
  57. frame.createPoll.question:Margin(8)
  58.  
  59. -- The answers
  60. frame.createPoll.answers = ExUI:Card(false, frame.createPoll, TOP)
  61. frame.createPoll.answers:Margin(8)
  62. frame.createPoll.answers:SetTall(120)
  63. frame.createPoll.answers:SetPadding(4)
  64.  
  65. frame.createPoll.answers.title = vgui.Create("DPanel", frame.createPoll.answers)
  66. frame.createPoll.answers.title:SetTall(32)
  67. frame.createPoll.answers.title:Dock(TOP)
  68. frame.createPoll.answers.title.Paint = function(self, w, h)
  69. ExUI:DrawText("The Answers", 28, 8, 8, Color(235, 235, 235))
  70. end
  71.  
  72. frame.createPoll.answers.tbl = {}
  73. local presetAnswers = {"Owain", "R4K0", "Saturday", "Gonzo", "Tyler", "Nykez", "Charles"}
  74. local function newAnswer()
  75. local answer = ExUI:Card(false, frame.createPoll.answers, TOP)
  76. answer:SetTall(40)
  77. answer.entry = ExUI:TextEntry(table.Random(presetAnswers), false, false, answer, FILL)
  78. answer.delete = ExUI:Button("DELETE", answer, RIGHT)
  79. answer.delete:SetColor(Color(175, 50, 0))
  80. answer.delete:SetWide(100)
  81. answer.delete:DockMargin(0, 8, 8, 0)
  82. answer.delete.DoClick = function()
  83. answer:Remove()
  84. frame.createPoll.answers:SetTall(frame.createPoll.answers:GetTall()-40)
  85. end
  86. table.insert(frame.createPoll.answers.tbl, answer.entry)
  87. end
  88. newAnswer()
  89.  
  90. frame.createPoll.answers.newEntry = ExUI:Button("Add another option", frame.createPoll.answers, BOTTOM)
  91. frame.createPoll.answers.newEntry:Margin(8)
  92. frame.createPoll.answers.newEntry:SetColor(Color(50, 0, 175))
  93. frame.createPoll.answers.newEntry.DoClick = function()
  94. newAnswer()
  95. frame.createPoll.answers:SetTall(frame.createPoll.answers:GetTall()+40)
  96. end
  97.  
  98.  
  99. frame.createPoll.submit = ExUI:Button("Submit new poll", frame.createPoll, TOP)
  100. frame.createPoll.submit:Margin(8)
  101. frame.createPoll.submit:SetColor(Color(50, 175, 0))
  102. frame.createPoll.submit.DoClick = function()
  103.  
  104. if frame.createPoll.question.entry.textentry:GetText() == "" then return end
  105.  
  106. -- Clear the answers
  107. local toSendAnswers = {}
  108. for k, v in pairs(frame.createPoll.answers.tbl) do
  109. if not IsValid(v) then continue end
  110. table.insert(toSendAnswers, v.textentry:GetText())
  111. end
  112.  
  113. if not toSendAnswers[2] then return end
  114. net.Start("ERPPollAdminPanelStartPoll")
  115. net.WriteString(frame.createPoll.question.entry.textentry:GetText())
  116. net.WriteTable(toSendAnswers)
  117. net.SendToServer()
  118.  
  119. frame:Close()
  120. end
  121.  
  122. local a = frame.sidebar:AddOption("Create Poll", false, frame.createPoll)
  123. if a then
  124. local oldPaint = a.Paint
  125. a.Paint = function(self, w, h)
  126. oldPaint(self, w, h)
  127. ExUI:DrawText("C", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  128. end
  129. end
  130.  
  131.  
  132. -- Viewing existing poll answers
  133. local allPolls = net.ReadTable()
  134.  
  135. frame.viewPolls = ExUI:Container(frame.container, FILL)
  136. frame.viewPolls.header = ExUI:Header("View Polls", "View poll answers", Color(230, 75, 50), frame.viewPolls)
  137. for k, v in pairs(allPolls) do
  138. local poll = ExUI:Card(false, frame.viewPolls, TOP)
  139. poll:SetTall(40)
  140. poll:DockMargin(8, 8, 8, 4)
  141.  
  142. poll.title = vgui.Create("DPanel", poll)
  143. poll.title:Dock(FILL)
  144. poll.title.Paint = function(self, w, h)
  145. ExUI:DrawText(v.question, 28, 8, 6, Color(235, 235, 235))
  146. end
  147.  
  148. poll.view = ExUI:Button("VIEW", poll, RIGHT)
  149. poll.view:SetColor(Color(50, 175, 0))
  150. poll.view:SetWide(75)
  151. poll.view.DoClick = function()
  152. local resultsFrame = ExUI:Frame(v.question)
  153. --resultsFrame:SetSize(ScrH()*0.4, 46)
  154. resultsFrame:SetSize(ScrH()*0.4, 86)
  155. resultsFrame:Center()
  156. resultsFrame:DockPadding(0, 48, 0, 0)
  157. resultsFrame.container = ExUI:Container(resultsFrame, FILL)
  158. resultsFrame.container.loading = vgui.Create("DPanel", resultsFrame.container)
  159. resultsFrame.container.loading:Dock(FILL)
  160. resultsFrame.container.loading.Paint = function(self, w, h)
  161. ExUI:DrawText("Loading data...", 28, w/2, 0, Color(235, 235, 235), TEXT_ALIGN_CENTER)
  162. end
  163.  
  164. net.Start("ERPPollGetResults")
  165. net.WriteInt(v.id, 32)
  166. net.SendToServer()
  167.  
  168. net.Receive("ERPPollSendResults", function()
  169. local options = net.ReadTable()
  170. local results = net.ReadTable()
  171.  
  172. resultsFrame.container.loading:Remove()
  173.  
  174. if results.err then
  175. resultsFrame.container.error = vgui.Create("DPanel", resultsFrame.container)
  176. resultsFrame.container.error:Dock(FILL)
  177. resultsFrame.container.error.Paint = function(self, w, h)
  178. ExUI:DrawText(results.err, 28, w / 2, 0, Color(235, 235, 235), TEXT_ALIGN_CENTER)
  179. end
  180. return
  181. end
  182.  
  183. local formattedResults = {}
  184. for k, v in pairs(results) do
  185. if not formattedResults[v.answer] then
  186. formattedResults[v.answer] = 0
  187. end
  188. formattedResults[v.answer] = formattedResults[v.answer] + 1
  189. end
  190.  
  191. -- Set the frame size
  192. resultsFrame:SetSize(ScrH()*0.4, 46+(40*#options)+200) -- Increased height to accommodate the pie chart
  193.  
  194. local pieRadius = 100
  195. local pieCenterX = resultsFrame:GetWide() / 2
  196. local pieCenterY = pieRadius + 40
  197.  
  198. -- Draw the pie chart
  199. local function drawPieSegment(percentage, color, startAngle)
  200. local segmentAngle = percentage * 360
  201. local poly = {
  202. {x = pieCenterX, y = pieCenterY},
  203. {x = pieCenterX + pieRadius * math.cos(math.rad(startAngle)), y = pieCenterY + pieRadius * math.sin(math.rad(startAngle))}
  204. }
  205. for i = startAngle, (startAngle + segmentAngle), 1 do
  206. local x = pieCenterX + pieRadius * math.cos(math.rad(i))
  207. local y = pieCenterY + pieRadius * math.sin(math.rad(i))
  208. table.insert(poly, {x = x, y = y})
  209. end
  210.  
  211. draw.NoTexture()
  212. surface.SetDrawColor(color)
  213. surface.DrawPoly(poly)
  214.  
  215. return startAngle + segmentAngle
  216. end
  217.  
  218. resultsFrame.container.Paint = function(self, w, h)
  219. local startAngle = 0
  220. for k, v in pairs(options) do
  221. local option = v.option
  222. local percentage = (formattedResults[v.id] or 0) / #results
  223. local color = Color(v.clr.r, v.clr.g, v.clr.b)
  224.  
  225. startAngle = drawPieSegment(percentage, color, startAngle)
  226. end
  227. end
  228.  
  229. for k, v in pairs(options) do
  230. local option = vgui.Create("DPanel", resultsFrame.container)
  231. option:Dock(TOP)
  232. option:SetTall(40)
  233. math.randomseed(math.random(100, 200))
  234. option.clr = {r = math.random(100, 175), g = math.random(100, 175), b = math.random(100, 175)}
  235. option.perc = (formattedResults[v.id] or 0) / #results
  236. option.Paint = function(self, w, h)
  237. draw.RoundedBox(4, 4, h / 2 - 4, 8, 8, Color(option.clr.r, option.clr.g, option.clr.b))
  238. ExUI:DrawText(v.option .. " | " .. math.Round(option.perc * 100) .. "% (" .. (formattedResults[v.id] or 0) .. ")", 28, 20, h / 2, Color(235, 235, 235), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
  239. end
  240. end
  241. end
  242. end
  243. end
  244. local a = frame.sidebar:AddOption("View Polls", false, frame.viewPolls)
  245. if a then
  246. local oldPaint = a.Paint
  247. a.Paint = function(self, w, h)
  248. oldPaint(self, w, h)
  249. ExUI:DrawText("V", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  250. end
  251. end
  252. -- Set active page
  253. frame.sidebar:SetActive("Dashboard")
  254. end)
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement