Advertisement
wifiboost

Untitled

Mar 28th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.78 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.  
  5. local messageLabel
  6. local function sendAdminRequestAction(action, target)
  7. net.Start("AdminRequestAction")
  8. net.WriteString(action)
  9. net.WriteEntity(target)
  10. net.SendToServer()
  11. end
  12. local function sendAdminRequestClaim()
  13. net.Start("AdminRequestClaim")
  14. net.SendToServer()
  15. end
  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.75
  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 = 15,
  85. weight = 400,
  86. antialias = true,
  87. shadow = false,
  88. })
  89. surface.CreateFont("CustomFont2", {
  90. font = "Arial",
  91. size = 18,
  92. weight = 1000,
  93. antialias = true,
  94. shadow = false,
  95. })
  96. mainPanel = vgui.Create("XeninUI.Frame")
  97. mainPanel:SetSize(500 * SCALE_FACTOR, 600 * SCALE_FACTOR)
  98.  
  99. local screenWidth, screenHeight = ScrW(), ScrH()
  100. mainPanel:SetPos(0, (screenHeight - mainPanel:GetTall()) / 2)
  101. mainPanel:SetTitle("Admin Requests")
  102. mainPanel:ShowCloseButton(false)
  103. --mainPanel:MakePopup()
  104. end
  105. local requestList = vgui.Create("DScrollPanel", mainPanel)
  106. requestList:SetPos(10 * SCALE_FACTOR, 50 * SCALE_FACTOR + 12)
  107. requestList:SetSize(500 * SCALE_FACTOR, 520 * SCALE_FACTOR) -- Increase the width of the requestList
  108.  
  109. local requestLayout = vgui.Create("DIconLayout", requestList)
  110. requestLayout:SetSize(480 * SCALE_FACTOR, requestList:GetTall())
  111. requestLayout:SetSpaceX(0) -- Horizontal spacing between items
  112. requestLayout:SetSpaceY(7) -- Vertical spacing between items
  113. requestList:AddItem(requestLayout)
  114.  
  115. -- Hide the scrollbar
  116. requestList.VBar.Paint = function() end
  117. requestList.VBar.btnUp.Paint = function() end
  118. requestList.VBar.btnDown.Paint = function() end
  119. requestList.VBar.btnGrip.Paint = function() end
  120.  
  121.  
  122. local unclaimedRequests = {}
  123.  
  124. local function createOutlinedButton(parent, x, y, w, h, text, onClick)
  125. local button = vgui.Create("XeninUI.Button", parent)
  126. button:SetPos(x, y)
  127. button:SetSize(w, h)
  128. button:SetText(text)
  129. button:SetFont("CustomFont") -- Set custom font
  130. button:SetTextColor( Color(227, 227, 227))
  131. button.Paint = function(self, w, h)
  132. draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
  133. draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
  134. end
  135. button.DoClick = onClick
  136. return button
  137. end
  138. local function hasKeyboardFocus(panel)
  139. return vgui.GetKeyboardFocus() == panel
  140. end
  141.  
  142.  
  143. local buttonWidth = 280 * SCALE_FACTOR
  144. local buttonHeight = 30 * SCALE_FACTOR
  145.  
  146. for i, requestData in ipairs(requests) do
  147. if not requestData.claimed then
  148. table.insert(unclaimedRequests, requestData)
  149.  
  150. local requestPanel = vgui.Create("DPanel", requestLayout)
  151. requestPanel:SetSize(480 * SCALE_FACTOR, 100 * SCALE_FACTOR)
  152. requestLayout:Add(requestPanel)
  153.  
  154. -- Set a custom background color for requestPanel
  155. local bgColor = Color(54, 54, 54, 255)
  156. requestPanel.Paint = function(self, w, h)
  157. draw.RoundedBox(4, 0, 0, w, h, bgColor)
  158. end
  159.  
  160. -- Add user avatar
  161. local avatar = vgui.Create("AvatarImage", requestPanel)
  162. avatar:SetSize(64 * SCALE_FACTOR, 64 * SCALE_FACTOR)
  163. avatar:SetPos(10 * SCALE_FACTOR, 28 * SCALE_FACTOR) -- Move the avatar down a bit
  164. avatar:SetSteamID(requestData.steamID64, 64)
  165.  
  166. -- Add user name
  167. local nameLabel = vgui.Create("DLabel", requestPanel)
  168. nameLabel:SetFont("CustomFont2") -- Set custom font
  169. nameLabel:SetTextColor(Color(227, 227, 227))
  170. nameLabel:SetText(requestData.name)
  171. nameLabel:SetPos(12 * SCALE_FACTOR, 5 * SCALE_FACTOR) -- Place the nameLabel above the avatar
  172. nameLabel:SizeToContents()
  173.  
  174.  
  175. -- Add request message
  176. -- Add request message
  177. local messageLabel = vgui.Create("DLabel", requestPanel)
  178. messageLabel:SetFont("CustomFont2") -- Set custom font
  179. messageLabel:SetTextColor(Color(227, 227, 227))
  180. messageLabel:SetText(requestData.message)
  181. messageLabel:SetPos(84 * SCALE_FACTOR, 29 * SCALE_FACTOR)
  182. messageLabel:SetSize(280 * SCALE_FACTOR, 44 * SCALE_FACTOR) -- Set width and maximum height
  183. messageLabel:SetWrap(true) -- Enable text wrapping
  184. messageLabel:SetAutoStretchVertical(true) -- Allow the label to expand vertically
  185.  
  186.  
  187. -- Claim case button for each request
  188. local claimButton = vgui.Create("XeninUI.Button", requestPanel)
  189. claimButton:SetFont("CustomFont2") -- Set custom font
  190. claimButton:SetTextColor(Color(227, 227, 227))
  191. claimButton:SetPos(370 * SCALE_FACTOR, 35 * SCALE_FACTOR)
  192. claimButton:SetSize(100 * SCALE_FACTOR, 30 * SCALE_FACTOR)
  193. claimButton:SetText("Claim")
  194. claimButton.DoClick = function()
  195. requestData.claimed = true
  196. requestData.claimedBy = LocalPlayer():SteamID64()
  197. claimButton:SetText("Claimed")
  198. claimButton:SetDisabled(true)
  199. createClaimedRequestUI(requestData)
  200.  
  201. -- Remove the admin request menu
  202. if IsValid(mainPanel) then
  203. mainPanel:Remove()
  204. end
  205.  
  206. net.Start("AdminRequestClaim")
  207. net.WriteTable(requestData)
  208. net.SendToServer()
  209.  
  210. -- Remove the claimed request from the list and move the rest up
  211. for i, panel in ipairs(requestLayout:GetChildren()) do
  212. if panel == requestPanel then
  213. requestLayout:Remove(panel)
  214. break
  215. end
  216. end
  217. -- Remove the claimed request from the requests table
  218. for i, req in ipairs(requests) do
  219. if req == requestData then
  220. table.remove(requests, i)
  221. break
  222. end
  223. end
  224. end
  225. end
  226. end
  227. -- Update the list of admin requests with the unclaimed requests
  228. adminRequests = unclaimedRequests
  229. end
  230. net.Receive("SendClaimDataToClient", function()
  231. local fetchedData = net.ReadTable()
  232. showClaimDataPanel(fetchedData)
  233. end)
  234. local function showClaimDataPanel(fetchedData)
  235. local frame = vgui.Create("XeninUI.Frame")
  236. frame:SetSize(600, 400)
  237. frame:Center()
  238. frame:SetTitle("Claim Data")
  239. frame:MakePopup()
  240.  
  241. local searchBox = vgui.Create("DTextEntry", frame)
  242. searchBox:SetSize(300, 25)
  243. searchBox:SetPos(10, 40)
  244. searchBox:SetPlaceholderText("Search by SteamID or Last Known Name")
  245.  
  246. local list = vgui.Create("DPanelList", frame)
  247. list:SetSize(frame:GetWide() - 20, frame:GetTall() - 85)
  248. list:SetPos(10, 75)
  249. list:SetSpacing(5)
  250. list:EnableVerticalScrollbar()
  251.  
  252. local function populateList(filter)
  253. list:Clear()
  254. for adminID, data in pairs(fetchedData) do
  255. if not filter or string.match(adminID, filter) or string.match(string.lower(data.name), string.lower(filter)) then
  256. local line = vgui.Create("DPanel")
  257. line:SetSize(list:GetWide() - 25, 64)
  258. line.Paint = function(self, w, h)
  259. draw.RoundedBox(4, 0, 0, w, h, Color(70, 70, 70))
  260. end
  261.  
  262. local avatar = vgui.Create("AvatarImage", line)
  263. avatar:SetSize(64, 64)
  264. avatar:SetPos(0, 0)
  265. avatar:SetSteamID(adminID, 64)
  266.  
  267. local nameLabel = vgui.Create("DLabel", line)
  268. nameLabel:SetText(data.name)
  269. nameLabel:SetPos(74, 10)
  270. nameLabel:SetFont("DermaDefaultBold")
  271. nameLabel:SizeToContents()
  272.  
  273. local steamIDLabel = vgui.Create("DLabel", line)
  274. steamIDLabel:SetText(adminID)
  275. steamIDLabel:SetPos(74, 30)
  276. steamIDLabel:SizeToContents()
  277.  
  278. local weeklyCountLabel = vgui.Create("DLabel", line)
  279. weeklyCountLabel:SetText("Weekly Sits: " .. data.weeklyCount)
  280. weeklyCountLabel:SetPos(350, 10)
  281. weeklyCountLabel:SizeToContents()
  282.  
  283. local totalCountLabel = vgui.Create("DLabel", line)
  284. totalCountLabel:SetText("Total Sits: " .. data.totalCount)
  285. totalCountLabel:SetPos(350, 30)
  286. totalCountLabel:SizeToContents()
  287.  
  288. list:AddItem(line)
  289. end
  290. end
  291. end
  292.  
  293. searchBox.OnChange = function()
  294. local filter = searchBox:GetValue()
  295. populateList(filter == "" and nil or filter)
  296. end
  297.  
  298. populateList()
  299. end
  300.  
  301. net.Receive("AdminRequest", function(len)
  302. local requestData = net.ReadTable()
  303. requestData.ply = player.GetBySteamID64(requestData.steamID64)
  304. if not requestData.ply then return end -- Ensure the player entity exists before proceeding
  305.  
  306. if not adminRequests then
  307. adminRequests = {}
  308. end
  309.  
  310. table.insert(adminRequests, requestData)
  311. createAdminRequestUI(adminRequests)
  312. end)
  313.  
  314. net.Receive("AdminRequestClaimData", function(len)
  315. local fetchedData = net.ReadTable()
  316. showClaimDataPanel(fetchedData)
  317. end)
  318.  
  319. net.Receive("UpdatedAdminRequests", function(len)
  320. local updatedRequests = net.ReadTable()
  321.  
  322. -- Check if there are any unclaimed requests
  323. local hasUnclaimedRequests = false
  324. for _, requestData in ipairs(updatedRequests) do
  325. if not requestData.claimed then
  326. hasUnclaimedRequests = true
  327. break
  328. end
  329. end
  330.  
  331. -- Only create the admin request UI if there are unclaimed requests
  332. if hasUnclaimedRequests then
  333. createAdminRequestUI(updatedRequests)
  334. end
  335. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement