Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --lua/autorun/client/admin_requests_ui.lua
- if not XeninUI then return end -- Check if XeninUI is installed
- local XeninUI = XeninUI
- local messageLabel
- local function sendAdminRequestAction(action, target)
- net.Start("AdminRequestAction")
- net.WriteString(action)
- net.WriteEntity(target)
- net.SendToServer()
- end
- local function sendAdminRequestClaim()
- net.Start("AdminRequestClaim")
- net.SendToServer()
- end
- local function createClaimedRequestUI(requestData)
- local screenWidth, screenHeight = ScrW(), ScrH()
- -- Create a new panel with three customizable buttons
- surface.CreateFont("CustomFont", {
- font = "Arial",
- size = 18,
- weight = 1000,
- antialias = true,
- shadow = false,
- })
- local claimPanel = vgui.Create("XeninUI.Frame")
- claimPanel:SetSize(300, 200)
- claimPanel:SetPos(0, (screenHeight - claimPanel:GetTall()) / 2)
- claimPanel:SetTitle("Useful Commands")
- claimPanel:ShowCloseButton(false)
- --claimPanel:MakePopup()
- local function createOutlinedButton(parent, x, y, w, h, text, onClick)
- local button = vgui.Create("XeninUI.Button", parent)
- button:SetPos(x, y)
- button:SetSize(w, h)
- button:SetText(text)
- button:SetFont("CustomFont") -- Set custom font
- button:SetTextColor( Color(227, 227, 227))
- button.Paint = function(self, w, h)
- draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
- draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
- end
- button.DoClick = onClick
- return button
- end
- local buttonWidth = 280
- local buttonHeight = 30
- local spacing = 7
- createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing + 42, buttonWidth, buttonHeight, "Bring", function()
- sendAdminRequestAction("bring", requestData.ply)
- end)
- createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 2 + buttonHeight + 42, buttonWidth, buttonHeight, "Goto", function()
- sendAdminRequestAction("goto", requestData.ply)
- end)
- createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 3 + buttonHeight * 2 + 42, buttonWidth, buttonHeight, "Return", function()
- sendAdminRequestAction("return", requestData.ply)
- end)
- local closeClaimButton = createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 4 + buttonHeight * 3 + 42, buttonWidth, buttonHeight, "Close Claim", function()
- claimPanel:Remove()
- -- Add this code to send the "AdminRequestClose" message
- net.Start("AdminRequestClose")
- net.WriteTable(requestData)
- net.SendToServer()
- -- Request updated admin requests from the server
- net.Start("RequestUpdatedAdminRequests")
- net.SendToServer()
- end)
- end
- SCALE_FACTOR = 0.75
- local function createAdminRequestUI(requests)
- if not IsValid(mainPanel) then
- -- Create the main panel using Xenin F4 framework
- surface.CreateFont("CustomFont", {
- font = "Arial",
- size = 15,
- weight = 400,
- antialias = true,
- shadow = false,
- })
- surface.CreateFont("CustomFont2", {
- font = "Arial",
- size = 18,
- weight = 1000,
- antialias = true,
- shadow = false,
- })
- mainPanel = vgui.Create("XeninUI.Frame")
- mainPanel:SetSize(500 * SCALE_FACTOR, 600 * SCALE_FACTOR)
- local screenWidth, screenHeight = ScrW(), ScrH()
- mainPanel:SetPos(0, (screenHeight - mainPanel:GetTall()) / 2)
- mainPanel:SetTitle("Admin Requests")
- mainPanel:ShowCloseButton(false)
- --mainPanel:MakePopup()
- end
- local requestList = vgui.Create("DScrollPanel", mainPanel)
- requestList:SetPos(10 * SCALE_FACTOR, 50 * SCALE_FACTOR + 12)
- requestList:SetSize(500 * SCALE_FACTOR, 520 * SCALE_FACTOR) -- Increase the width of the requestList
- local requestLayout = vgui.Create("DIconLayout", requestList)
- requestLayout:SetSize(480 * SCALE_FACTOR, requestList:GetTall())
- requestLayout:SetSpaceX(0) -- Horizontal spacing between items
- requestLayout:SetSpaceY(7) -- Vertical spacing between items
- requestList:AddItem(requestLayout)
- -- Hide the scrollbar
- requestList.VBar.Paint = function() end
- requestList.VBar.btnUp.Paint = function() end
- requestList.VBar.btnDown.Paint = function() end
- requestList.VBar.btnGrip.Paint = function() end
- local unclaimedRequests = {}
- local function createOutlinedButton(parent, x, y, w, h, text, onClick)
- local button = vgui.Create("XeninUI.Button", parent)
- button:SetPos(x, y)
- button:SetSize(w, h)
- button:SetText(text)
- button:SetFont("CustomFont") -- Set custom font
- button:SetTextColor( Color(227, 227, 227))
- button.Paint = function(self, w, h)
- draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
- draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
- end
- button.DoClick = onClick
- return button
- end
- local function hasKeyboardFocus(panel)
- return vgui.GetKeyboardFocus() == panel
- end
- local buttonWidth = 280 * SCALE_FACTOR
- local buttonHeight = 30 * SCALE_FACTOR
- for i, requestData in ipairs(requests) do
- if not requestData.claimed then
- table.insert(unclaimedRequests, requestData)
- local requestPanel = vgui.Create("DPanel", requestLayout)
- requestPanel:SetSize(480 * SCALE_FACTOR, 100 * SCALE_FACTOR)
- requestLayout:Add(requestPanel)
- -- Set a custom background color for requestPanel
- local bgColor = Color(54, 54, 54, 255)
- requestPanel.Paint = function(self, w, h)
- draw.RoundedBox(4, 0, 0, w, h, bgColor)
- end
- -- Add user avatar
- local avatar = vgui.Create("AvatarImage", requestPanel)
- avatar:SetSize(64 * SCALE_FACTOR, 64 * SCALE_FACTOR)
- avatar:SetPos(10 * SCALE_FACTOR, 28 * SCALE_FACTOR) -- Move the avatar down a bit
- avatar:SetSteamID(requestData.steamID64, 64)
- -- Add user name
- local nameLabel = vgui.Create("DLabel", requestPanel)
- nameLabel:SetFont("CustomFont2") -- Set custom font
- nameLabel:SetTextColor(Color(227, 227, 227))
- nameLabel:SetText(requestData.name)
- nameLabel:SetPos(12 * SCALE_FACTOR, 5 * SCALE_FACTOR) -- Place the nameLabel above the avatar
- nameLabel:SizeToContents()
- -- Add request message
- -- Add request message
- local messageLabel = vgui.Create("DLabel", requestPanel)
- messageLabel:SetFont("CustomFont2") -- Set custom font
- messageLabel:SetTextColor(Color(227, 227, 227))
- messageLabel:SetText(requestData.message)
- messageLabel:SetPos(84 * SCALE_FACTOR, 29 * SCALE_FACTOR)
- messageLabel:SetSize(280 * SCALE_FACTOR, 44 * SCALE_FACTOR) -- Set width and maximum height
- messageLabel:SetWrap(true) -- Enable text wrapping
- messageLabel:SetAutoStretchVertical(true) -- Allow the label to expand vertically
- -- Claim case button for each request
- local claimButton = vgui.Create("XeninUI.Button", requestPanel)
- claimButton:SetFont("CustomFont2") -- Set custom font
- claimButton:SetTextColor(Color(227, 227, 227))
- claimButton:SetPos(370 * SCALE_FACTOR, 35 * SCALE_FACTOR)
- claimButton:SetSize(100 * SCALE_FACTOR, 30 * SCALE_FACTOR)
- claimButton:SetText("Claim")
- claimButton.DoClick = function()
- requestData.claimed = true
- requestData.claimedBy = LocalPlayer():SteamID64()
- claimButton:SetText("Claimed")
- claimButton:SetDisabled(true)
- createClaimedRequestUI(requestData)
- -- Remove the admin request menu
- if IsValid(mainPanel) then
- mainPanel:Remove()
- end
- net.Start("AdminRequestClaim")
- net.WriteTable(requestData)
- net.SendToServer()
- -- Remove the claimed request from the list and move the rest up
- for i, panel in ipairs(requestLayout:GetChildren()) do
- if panel == requestPanel then
- requestLayout:Remove(panel)
- break
- end
- end
- -- Remove the claimed request from the requests table
- for i, req in ipairs(requests) do
- if req == requestData then
- table.remove(requests, i)
- break
- end
- end
- end
- end
- end
- -- Update the list of admin requests with the unclaimed requests
- adminRequests = unclaimedRequests
- end
- net.Receive("SendClaimDataToClient", function()
- local fetchedData = net.ReadTable()
- showClaimDataPanel(fetchedData)
- end)
- local function showClaimDataPanel(fetchedData)
- local frame = vgui.Create("XeninUI.Frame")
- frame:SetSize(600, 400)
- frame:Center()
- frame:SetTitle("Claim Data")
- frame:MakePopup()
- local searchBox = vgui.Create("DTextEntry", frame)
- searchBox:SetSize(300, 25)
- searchBox:SetPos(10, 40)
- searchBox:SetPlaceholderText("Search by SteamID or Last Known Name")
- local list = vgui.Create("DPanelList", frame)
- list:SetSize(frame:GetWide() - 20, frame:GetTall() - 85)
- list:SetPos(10, 75)
- list:SetSpacing(5)
- list:EnableVerticalScrollbar()
- local function populateList(filter)
- list:Clear()
- for adminID, data in pairs(fetchedData) do
- if not filter or string.match(adminID, filter) or string.match(string.lower(data.name), string.lower(filter)) then
- local line = vgui.Create("DPanel")
- line:SetSize(list:GetWide() - 25, 64)
- line.Paint = function(self, w, h)
- draw.RoundedBox(4, 0, 0, w, h, Color(70, 70, 70))
- end
- net.Start("RequestClaimData")
- net.SendToServer()
- net.Receive("ReceiveClaimData", function()
- local fetchedData = net.ReadTable()
- showClaimDataPanel(fetchedData)
- end)
- fetchClaimData(function(fetchedData)
- showClaimDataPanel(fetchedData)
- end)
- local avatar = vgui.Create("AvatarImage", line)
- avatar:SetSize(64, 64)
- avatar:SetPos(0, 0)
- avatar:SetSteamID(adminID, 64)
- local nameLabel = vgui.Create("DLabel", line)
- nameLabel:SetText(data.name)
- nameLabel:SetPos(74, 10)
- nameLabel:SetFont("DermaDefaultBold")
- nameLabel:SizeToContents()
- local steamIDLabel = vgui.Create("DLabel", line)
- steamIDLabel:SetText(adminID)
- steamIDLabel:SetPos(74, 30)
- steamIDLabel:SizeToContents()
- local weeklyCountLabel = vgui.Create("DLabel", line)
- weeklyCountLabel:SetText("Weekly Sits: " .. data.weeklyCount)
- weeklyCountLabel:SetPos(350, 10)
- weeklyCountLabel:SizeToContents()
- local totalCountLabel = vgui.Create("DLabel", line)
- totalCountLabel:SetText("Total Sits: " .. data.totalCount)
- totalCountLabel:SetPos(350, 30)
- totalCountLabel:SizeToContents()
- list:AddItem(line)
- end
- end
- end
- searchBox.OnChange = function()
- local filter = searchBox:GetValue()
- populateList(filter == "" and nil or filter)
- end
- populateList() -- Removed the parenthesis causing the error
- end
- net.Receive("AdminRequest", function(len)
- local requestData = net.ReadTable()
- requestData.ply = player.GetBySteamID64(requestData.steamID64)
- if not requestData.ply then return end -- Ensure the player entity exists before proceeding
- if not adminRequests then
- adminRequests = {}
- end
- table.insert(adminRequests, requestData)
- createAdminRequestUI(adminRequests)
- end)
- net.Receive("AdminRequestClaimData", function(len)
- local fetchedData = net.ReadTable()
- showClaimDataPanel(fetchedData)
- end)
- net.Receive("UpdatedAdminRequests", function(len)
- local updatedRequests = net.ReadTable()
- -- Check if there are any unclaimed requests
- local hasUnclaimedRequests = false
- for _, requestData in ipairs(updatedRequests) do
- if not requestData.claimed then
- hasUnclaimedRequests = true
- break
- end
- end
- -- Only create the admin request UI if there are unclaimed requests
- if hasUnclaimedRequests then
- createAdminRequestUI(updatedRequests)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement