Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wave = Material("vgui/wave.png", "noclamp smooth")
- surface.CreateFont("CustomInputFont", {
- font = "Arial", -- Use the desired font name here
- size = 16, -- Set the font size (change this value as needed)
- weight = 500,
- antialias = true
- })
- net.Receive("ERPPollAdminPanel", function()
- -- Base frame content
- local frame = ExUI:Frame("Poll - Admin Menu")
- frame:SetSize(ScrH()*1, ScrH()*0.8)
- frame:Center()
- frame.sidebar = ExUI:Sidebar(Color(16, 23, 28), frame)
- frame.container = ExUI:Container(frame, FILL)
- frame.sidebar:SetContainer(frame.container)
- -- Creating a poll
- frame.dashboard = ExUI:Container(frame.container, FILL)
- frame.dashboard.header = ExUI:Header("Dashboard", "Edit settings here", Color(230, 75, 50), frame.dashboard)
- frame.dashboard.endPoll = ExUI:Button("End active poll (If one)", frame.dashboard, TOP)
- frame.dashboard.endPoll:Margin(8)
- frame.dashboard.endPoll:SetColor(Color(175, 0, 50))
- frame.dashboard.endPoll.DoClick = function()
- net.Start("ERPPollEndPoll")
- net.SendToServer()
- end
- local a = frame.sidebar:AddOption("Dashboard", false, frame.dashboard)
- if a then
- local oldPaint = a.Paint
- a.Paint = function(self, w, h)
- oldPaint(self, w, h)
- ExUI:DrawText("D", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- end
- -- Creating a poll
- frame.createPoll = ExUI:Container(frame.container, FILL)
- frame.createPoll.header = ExUI:Header("Create Poll", "Create a new poll", Color(230, 75, 50), frame.createPoll)
- -- The question input
- frame.createPoll.question = ExUI:Card(false, frame.createPoll, TOP)
- frame.createPoll.question:Margin(8)
- frame.createPoll.question:SetTall(80)
- frame.createPoll.question:SetPadding(4)
- frame.createPoll.question.title = vgui.Create("DPanel", frame.createPoll.question)
- frame.createPoll.question.title:SetTall(32)
- frame.createPoll.question.title:Dock(TOP)
- frame.createPoll.question.title.Paint = function(self, w, h)
- ExUI:DrawText("The Question", 28, 8, 8, Color(235, 235, 235))
- end
- frame.createPoll.question.entry = ExUI:TextEntry("Who is the best developer?", false, false, frame.createPoll.question, TOP)
- frame.createPoll.question:Margin(8)
- -- The answers
- frame.createPoll.answers = ExUI:Card(false, frame.createPoll, TOP)
- frame.createPoll.answers:Margin(8)
- frame.createPoll.answers:SetTall(120)
- frame.createPoll.answers:SetPadding(4)
- frame.createPoll.answers.title = vgui.Create("DPanel", frame.createPoll.answers)
- frame.createPoll.answers.title:SetTall(32)
- frame.createPoll.answers.title:Dock(TOP)
- frame.createPoll.answers.title.Paint = function(self, w, h)
- ExUI:DrawText("The Answers", 28, 8, 8, Color(235, 235, 235))
- end
- frame.createPoll.answers.tbl = {}
- local presetAnswers = {"Owain", "R4K0", "Saturday", "Gonzo", "Tyler", "Nykez", "Charles"}
- local function newAnswer()
- local answer = ExUI:Card(false, frame.createPoll.answers, TOP)
- answer:SetTall(40)
- answer.entry = ExUI:TextEntry(table.Random(presetAnswers), false, false, answer, FILL)
- answer.delete = ExUI:Button("DELETE", answer, RIGHT)
- answer.delete:SetColor(Color(175, 50, 0))
- answer.delete:SetWide(100)
- answer.delete:DockMargin(0, 8, 8, 0)
- answer.delete.DoClick = function()
- answer:Remove()
- frame.createPoll.answers:SetTall(frame.createPoll.answers:GetTall()-40)
- end
- table.insert(frame.createPoll.answers.tbl, answer.entry)
- end
- newAnswer()
- frame.createPoll.answers.newEntry = ExUI:Button("Add another option", frame.createPoll.answers, BOTTOM)
- frame.createPoll.answers.newEntry:Margin(8)
- frame.createPoll.answers.newEntry:SetColor(Color(50, 0, 175))
- frame.createPoll.answers.newEntry.DoClick = function()
- newAnswer()
- frame.createPoll.answers:SetTall(frame.createPoll.answers:GetTall()+40)
- end
- frame.createPoll.submit = ExUI:Button("Submit new poll", frame.createPoll, TOP)
- frame.createPoll.submit:Margin(8)
- frame.createPoll.submit:SetColor(Color(50, 175, 0))
- frame.createPoll.submit.DoClick = function()
- if frame.createPoll.question.entry.textentry:GetText() == "" then return end
- -- Clear the answers
- local toSendAnswers = {}
- for k, v in pairs(frame.createPoll.answers.tbl) do
- if not IsValid(v) then continue end
- table.insert(toSendAnswers, v.textentry:GetText())
- end
- if not toSendAnswers[2] then return end
- net.Start("ERPPollAdminPanelStartPoll")
- net.WriteString(frame.createPoll.question.entry.textentry:GetText())
- net.WriteTable(toSendAnswers)
- net.SendToServer()
- frame:Close()
- end
- local a = frame.sidebar:AddOption("Create Poll", false, frame.createPoll)
- if a then
- local oldPaint = a.Paint
- a.Paint = function(self, w, h)
- oldPaint(self, w, h)
- ExUI:DrawText("C", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- end
- -- Viewing existing poll answers
- local allPolls = net.ReadTable()
- frame.viewPolls = ExUI:Container(frame.container, FILL)
- frame.viewPolls.header = ExUI:Header("View Polls", "View poll answers", Color(230, 75, 50), frame.viewPolls)
- for k, v in pairs(allPolls) do
- local poll = ExUI:Card(false, frame.viewPolls, TOP)
- poll:SetTall(40)
- poll:DockMargin(8, 8, 8, 4)
- poll.title = vgui.Create("DPanel", poll)
- poll.title:Dock(FILL)
- poll.title.Paint = function(self, w, h)
- ExUI:DrawText(v.question, 28, 8, 6, Color(235, 235, 235))
- end
- poll.view = ExUI:Button("VIEW", poll, RIGHT)
- poll.view:SetColor(Color(50, 175, 0))
- poll.view:SetWide(75)
- poll.view.DoClick = function()
- local resultsFrame = ExUI:Frame(v.question)
- --resultsFrame:SetSize(ScrH()*0.4, 46)
- resultsFrame:SetSize(ScrH()*0.4, 86)
- resultsFrame:Center()
- resultsFrame:DockPadding(0, 48, 0, 0)
- resultsFrame.container = ExUI:Container(resultsFrame, FILL)
- resultsFrame.container.loading = vgui.Create("DPanel", resultsFrame.container)
- resultsFrame.container.loading:Dock(FILL)
- resultsFrame.container.loading.Paint = function(self, w, h)
- ExUI:DrawText("Loading data...", 28, w/2, 0, Color(235, 235, 235), TEXT_ALIGN_CENTER)
- end
- net.Start("ERPPollGetResults")
- net.WriteInt(v.id, 32)
- net.SendToServer()
- net.Receive("ERPPollSendResults", function()
- local options = net.ReadTable()
- local results = net.ReadTable()
- resultsFrame.container.loading:Remove()
- if results.err then
- resultsFrame.container.error = vgui.Create("DPanel", resultsFrame.container)
- resultsFrame.container.error:Dock(FILL)
- resultsFrame.container.error.Paint = function(self, w, h)
- ExUI:DrawText(results.err, 28, w / 2, 0, Color(235, 235, 235), TEXT_ALIGN_CENTER)
- end
- return
- end
- local formattedResults = {}
- for k, v in pairs(results) do
- if not formattedResults[v.answer] then
- formattedResults[v.answer] = 0
- end
- formattedResults[v.answer] = formattedResults[v.answer] + 1
- end
- -- Set the frame size
- resultsFrame:SetSize(ScrH()*0.4, 46+(40*#options)+200) -- Increased height to accommodate the pie chart
- local pieRadius = 100
- local pieCenterX = resultsFrame:GetWide() / 2
- local pieCenterY = pieRadius + 40
- -- Draw the pie chart
- local function drawPieSegment(percentage, color, startAngle)
- local segmentAngle = percentage * 360
- local poly = {
- {x = pieCenterX, y = pieCenterY},
- {x = pieCenterX + pieRadius * math.cos(math.rad(startAngle)), y = pieCenterY + pieRadius * math.sin(math.rad(startAngle))}
- }
- for i = startAngle, (startAngle + segmentAngle), 1 do
- local x = pieCenterX + pieRadius * math.cos(math.rad(i))
- local y = pieCenterY + pieRadius * math.sin(math.rad(i))
- table.insert(poly, {x = x, y = y})
- end
- draw.NoTexture()
- surface.SetDrawColor(color)
- surface.DrawPoly(poly)
- return startAngle + segmentAngle
- end
- resultsFrame.container.Paint = function(self, w, h)
- local startAngle = 0
- for k, v in pairs(options) do
- local option = v.option
- local percentage = (formattedResults[v.id] or 0) / #results
- local color = Color(v.clr.r, v.clr.g, v.clr.b)
- startAngle = drawPieSegment(percentage, color, startAngle)
- end
- end
- for k, v in pairs(options) do
- local option = vgui.Create("DPanel", resultsFrame.container)
- option:Dock(TOP)
- option:SetTall(40)
- math.randomseed(math.random(100, 200))
- option.clr = {r = math.random(100, 175), g = math.random(100, 175), b = math.random(100, 175)}
- option.perc = (formattedResults[v.id] or 0) / #results
- option.Paint = function(self, w, h)
- draw.RoundedBox(4, 4, h / 2 - 4, 8, 8, Color(option.clr.r, option.clr.g, option.clr.b))
- 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)
- end
- end
- end
- end
- end
- local a = frame.sidebar:AddOption("View Polls", false, frame.viewPolls)
- if a then
- local oldPaint = a.Paint
- a.Paint = function(self, w, h)
- oldPaint(self, w, h)
- ExUI:DrawText("V", 40, w/2, h/2, Color(235, 235, 235), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- end
- -- Set active page
- frame.sidebar:SetActive("Dashboard")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement