Advertisement
wifiboost

Untitled

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