Advertisement
wifiboost

Untitled

Mar 27th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. --lua/autorun/client/admin_requests_ui.lua
  2. if not XeninUI then return end -- Check if XeninUI is installed
  3. local XeninUI = XeninUI
  4. local messageLabel
  5. local function sendAdminRequestAction(action, target)
  6. net.Start("AdminRequestAction")
  7. net.WriteString(action)
  8. net.WriteEntity(target)
  9. net.SendToServer()
  10. end
  11. local function sendAdminRequestClaim()
  12. net.Start("AdminRequestClaim")
  13. net.SendToServer()
  14. end
  15.  
  16.  
  17. local function createClaimedRequestUI(requestData)
  18. local screenWidth, screenHeight = ScrW(), ScrH()
  19. -- Create a new panel with three customizable buttons
  20. surface.CreateFont("CustomFont", {
  21. font = "Arial",
  22. size = 18,
  23. weight = 1000,
  24. antialias = true,
  25. shadow = false,
  26. })
  27. local claimPanel = vgui.Create("XeninUI.Frame")
  28. claimPanel:SetSize(300, 200)
  29. claimPanel:SetPos(0, (screenHeight - claimPanel:GetTall()) / 2)
  30. claimPanel:SetTitle("Useful Commands")
  31. claimPanel:ShowCloseButton(false)
  32. claimPanel:MakePopup()
  33.  
  34. local function createOutlinedButton(parent, x, y, w, h, text, onClick)
  35. local button = vgui.Create("XeninUI.Button", parent)
  36. button:SetPos(x, y)
  37. button:SetSize(w, h)
  38. button:SetText(text)
  39. button:SetFont("CustomFont") -- Set custom font
  40. button:SetTextColor( Color(227, 227, 227))
  41. button.Paint = function(self, w, h)
  42. draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
  43. draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
  44. end
  45. button.DoClick = onClick
  46. return button
  47. end
  48.  
  49. local buttonWidth = 280
  50. local buttonHeight = 30
  51. local spacing = 7
  52.  
  53. createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing + 42, buttonWidth, buttonHeight, "Bring", function()
  54. sendAdminRequestAction("bring", requestData.ply)
  55. end)
  56.  
  57. createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 2 + buttonHeight + 42, buttonWidth, buttonHeight, "Goto", function()
  58. sendAdminRequestAction("goto", requestData.ply)
  59. end)
  60.  
  61. createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 3 + buttonHeight * 2 + 42, buttonWidth, buttonHeight, "Return", function()
  62. sendAdminRequestAction("return", requestData.ply)
  63. end)
  64.  
  65. local closeClaimButton = createOutlinedButton(claimPanel, (claimPanel:GetWide() - buttonWidth) / 2, spacing * 4 + buttonHeight * 3 + 42, buttonWidth, buttonHeight, "Close Claim", function()
  66. claimPanel:Remove()
  67.  
  68. -- Add this code to send the "AdminRequestClose" message
  69. net.Start("AdminRequestClose")
  70. net.WriteTable(requestData)
  71. net.SendToServer()
  72.  
  73. -- Request updated admin requests from the server
  74. net.Start("RequestUpdatedAdminRequests")
  75. net.SendToServer()
  76. end)
  77. end
  78. SCALE_FACTOR = 0.8
  79. local function createAdminRequestUI(requests)
  80. if not IsValid(mainPanel) then
  81. -- Create the main panel using Xenin F4 framework
  82. surface.CreateFont("CustomFont", {
  83. font = "Arial",
  84. size = 18 * SCALE_FACTOR,
  85. weight = 1000,
  86. antialias = true,
  87. shadow = false,
  88. })
  89. mainPanel = vgui.Create("XeninUI.Frame")
  90. mainPanel:SetSize(500 * SCALE_FACTOR, 600 * SCALE_FACTOR)
  91. local screenWidth, screenHeight = ScrW(), ScrH()
  92. mainPanel:SetPos(0, (screenHeight - mainPanel:GetTall()) / 2)
  93. mainPanel:SetTitle("Admin Requests")
  94. mainPanel:MakePopup()
  95. end
  96. local requestList = vgui.Create("DPanelList", mainPanel)
  97. requestList:SetPos(10 * SCALE_FACTOR, 50 * SCALE_FACTOR)
  98. requestList:SetSize(480 * SCALE_FACTOR, 520 * SCALE_FACTOR)
  99. requestList:SetSpacing(10 * SCALE_FACTOR) -- Change this value to increase the spacing between the panels
  100. requestList:EnableVerticalScrollbar(true)
  101.  
  102. local unclaimedRequests = {}
  103.  
  104. local function createOutlinedButton(parent, x, y, w, h, text, onClick)
  105. local button = vgui.Create("XeninUI.Button", parent)
  106. button:SetPos(x, y)
  107. button:SetSize(w, h)
  108. button:SetText(text)
  109. button:SetFont("CustomFont") -- Set custom font
  110. button:SetTextColor( Color(227, 227, 227))
  111. button.Paint = function(self, w, h)
  112. draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
  113. draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
  114. end
  115. button.DoClick = onClick
  116. return button
  117. end
  118.  
  119. local buttonWidth = 280 * SCALE_FACTOR
  120. local buttonHeight = 30 * SCALE_FACTOR
  121.  
  122. for i, requestData in ipairs(requests) do
  123. if not requestData.claimed then
  124. table.insert(unclaimedRequests, requestData)
  125.  
  126. local requestPanel = vgui.Create("DPanel", requestList)
  127. requestPanel:SetSize(480 * SCALE_FACTOR, 100 * SCALE_FACTOR)
  128. requestPanel.Paint = function(self, w, h)
  129. draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
  130. draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
  131. end
  132. requestList:AddItem(requestPanel)
  133.  
  134. -- Add user avatar
  135. local avatar = vgui.Create("AvatarImage", requestPanel)
  136. avatar:SetSize(64 * SCALE_FACTOR, 64 * SCALE_FACTOR)
  137. avatar:SetPos(10 * SCALE_FACTOR, 18 * SCALE_FACTOR)
  138. avatar:SetSteamID(requestData.steamID64, 64)
  139.  
  140. -- Add user name
  141. local nameLabel = vgui.Create("DLabel", requestPanel)
  142. nameLabel:SetFont("CustomFont") -- Set custom font
  143. nameLabel:SetTextColor( Color(227, 227, 227))
  144. nameLabel:SetText(requestData.name)
  145. nameLabel:SetPos(84 * SCALE_FACTOR, 18 * SCALE_FACTOR)
  146. nameLabel:SizeToContents()
  147.  
  148. -- Add request message
  149. local messageLabel = vgui.Create("DLabel", requestPanel)
  150. messageLabel:SetFont("CustomFont") -- Set custom font
  151. messageLabel:SetTextColor( Color(227, 227, 227))
  152. messageLabel:SetText(requestData.message)
  153. messageLabel:SetPos(84 * SCALE_FACTOR, 48 * SCALE_FACTOR)
  154. messageLabel:SizeToContents()
  155.  
  156. -- Claim case button for each request
  157. local claimButton = vgui.Create("XeninUI.Button", requestPanel)
  158. claimButton:SetFont("CustomFont") -- Set custom font
  159. claimButton:SetTextColor( Color(227, 227, 227))
  160. claimButton:SetPos(370 * SCALE_FACTOR, 35 * SCALE_FACTOR)
  161. claimButton:SetSize(100 * SCALE_FACTOR, 30 * SCALE_FACTOR)
  162. claimButton:SetText("Claim Case")
  163. claimButton.DoClick = function()
  164. requestData.claimed = true
  165. requestData.claimedBy = LocalPlayer():SteamID64()
  166. claimButton:SetText("Claimed")
  167. claimButton:SetDisabled(true)
  168. createClaimedRequestUI(requestData)
  169.  
  170. -- Remove the admin request menu
  171. if IsValid(mainPanel) then
  172. mainPanel:Remove()
  173. end
  174.  
  175. net.Start("AdminRequestClaim")
  176. net.WriteTable(requestData)
  177. net.SendToServer()
  178.  
  179. -- Remove the claimed request from the list and move the rest up
  180. for i, panel in ipairs(requestList:GetItems()) do
  181. if panel == requestPanel then
  182. requestList:RemoveItem(requestPanel)
  183. table.remove(requestList:GetItems(), i)
  184. break
  185. end
  186. end
  187. -- Remove the claimed request from the requests table
  188. for i, req in ipairs(requests) do
  189. if req == requestData then
  190. table.remove(requests, i)
  191. break
  192. end
  193. end
  194. end
  195. end
  196. end
  197.  
  198. -- Update the list of admin requests with the unclaimed requests
  199. adminRequests = unclaimedRequests
  200. end
  201.  
  202. local function showClaimDataPanel(adminClaimData)
  203. local frame = vgui.Create("XeninUI.Frame")
  204. frame:SetSize(600, 400)
  205. frame:Center()
  206. frame:SetTitle("Claim Data")
  207. frame:MakePopup()
  208.  
  209. local searchBox = vgui.Create("DTextEntry", frame)
  210. searchBox:SetSize(300, 25)
  211. searchBox:SetPos(10, 40)
  212. searchBox:SetPlaceholderText("Search by SteamID or Last Known Name")
  213.  
  214. local list = vgui.Create("DPanelList", frame)
  215. list:SetSize(frame:GetWide() - 20, frame:GetTall() - 85)
  216. list:SetPos(10, 75)
  217. list:SetSpacing(5)
  218. list:EnableVerticalScrollbar()
  219.  
  220. local function populateList(filter)
  221. list:Clear()
  222. for adminID, data in pairs(adminClaimData) do
  223. if not filter or string.match(adminID, filter) or string.match(string.lower(data.name), string.lower(filter)) then
  224. local line = vgui.Create("DPanel")
  225. line:SetSize(list:GetWide() - 25, 64)
  226. line.Paint = function(self, w, h)
  227. draw.RoundedBox(4, 0, 0, w, h, Color(70, 70, 70))
  228. end
  229.  
  230. local avatar = vgui.Create("AvatarImage", line)
  231. avatar:SetSize(64, 64)
  232. avatar:SetPos(0, 0)
  233. avatar:SetSteamID(adminID, 64)
  234.  
  235. local nameLabel = vgui.Create("DLabel", line)
  236. nameLabel:SetText(data.name)
  237. nameLabel:SetPos(74, 10)
  238. nameLabel:SetFont("DermaDefaultBold")
  239. nameLabel:SizeToContents()
  240.  
  241. local steamIDLabel = vgui.Create("DLabel", line)
  242. steamIDLabel:SetText(adminID)
  243. steamIDLabel:SetPos(74, 30)
  244. steamIDLabel:SizeToContents()
  245.  
  246. local weeklyCountLabel = vgui.Create("DLabel", line)
  247. weeklyCountLabel:SetText("Weekly Sits: " .. data.weeklyCount)
  248. weeklyCountLabel:SetPos(350, 10)
  249. weeklyCountLabel:SizeToContents()
  250.  
  251. local totalCountLabel = vgui.Create("DLabel", line)
  252. totalCountLabel:SetText("Total Sits: " .. data.totalCount)
  253. totalCountLabel:SetPos(350, 30)
  254. totalCountLabel:SizeToContents()
  255.  
  256. list:AddItem(line)
  257. end
  258. end
  259. end
  260.  
  261. searchBox.OnChange = function()
  262. local filter = searchBox:GetValue()
  263. populateList(filter == "" and nil or filter)
  264. end
  265.  
  266. populateList() -- Removed the parenthesis causing the error
  267. end
  268. net.Receive("AdminRequest", function(len)
  269. local requestData = net.ReadTable()
  270. requestData.ply = player.GetBySteamID64(requestData.steamID64)
  271. if not requestData.ply then return end -- Ensure the player entity exists before proceeding
  272.  
  273. if not adminRequests then
  274. adminRequests = {}
  275. end
  276.  
  277. table.insert(adminRequests, requestData)
  278. createAdminRequestUI(adminRequests)
  279. end)
  280.  
  281. net.Receive("AdminRequestClaimData", function(len)
  282. local adminClaimData = net.ReadTable()
  283. showClaimDataPanel(adminClaimData)
  284. end)
  285.  
  286. net.Receive("UpdatedAdminRequests", function(len)
  287. local updatedRequests = net.ReadTable()
  288.  
  289. -- Check if there are any unclaimed requests
  290. local hasUnclaimedRequests = false
  291. for _, requestData in ipairs(updatedRequests) do
  292. if not requestData.claimed then
  293. hasUnclaimedRequests = true
  294. break
  295. end
  296. end
  297.  
  298. -- Only create the admin request UI if there are unclaimed requests
  299. if hasUnclaimedRequests then
  300. createAdminRequestUI(updatedRequests)
  301. end
  302. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement