Advertisement
wifiboost

Untitled

Apr 10th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.29 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. local currentPlayerSteamID64 = LocalPlayer():SteamID64()
  124. local ownRequestOnly = false
  125.  
  126. local function createOutlinedButton(parent, x, y, w, h, text, onClick)
  127. local button = vgui.Create("XeninUI.Button", parent)
  128. button:SetPos(x, y)
  129. button:SetSize(w, h)
  130. button:SetText(text)
  131. button:SetFont("CustomFont") -- Set custom font
  132. button:SetTextColor( Color(227, 227, 227))
  133. button.Paint = function(self, w, h)
  134. draw.RoundedBox(4, 0, 0, w, h, Color(29, 29, 29, 255))
  135. draw.RoundedBox(4, 1, 1, w - 2, h - 2, Color(54, 54, 54, 255))
  136. end
  137. button.DoClick = onClick
  138. return button
  139. end
  140. local function hasKeyboardFocus(panel)
  141. return vgui.GetKeyboardFocus() == panel
  142. end
  143.  
  144.  
  145. local buttonWidth = 280 * SCALE_FACTOR
  146. local buttonHeight = 30 * SCALE_FACTOR
  147.  
  148. for _, requestData in ipairs(requests) do
  149. if not requestData.claimed and currentPlayerSteamID64 ~= requestData.steamID64 then
  150. table.insert(unclaimedRequests, requestData)
  151.  
  152. local requestPanel = vgui.Create("DPanel", requestLayout)
  153. requestPanel:SetSize(480 * SCALE_FACTOR, 100 * SCALE_FACTOR)
  154. requestLayout:Add(requestPanel)
  155.  
  156. -- Set a custom background color for requestPanel
  157. local bgColor = Color(54, 54, 54, 255)
  158. requestPanel.Paint = function(self, w, h)
  159. draw.RoundedBox(4, 0, 0, w, h, bgColor)
  160. end
  161.  
  162. -- Add user avatar
  163. local avatar = vgui.Create("AvatarImage", requestPanel)
  164. avatar:SetSize(64 * SCALE_FACTOR, 64 * SCALE_FACTOR)
  165. avatar:SetPos(10 * SCALE_FACTOR, 28 * SCALE_FACTOR) -- Move the avatar down a bit
  166. avatar:SetSteamID(requestData.steamID64, 64)
  167.  
  168. -- Add user name
  169. local nameLabel = vgui.Create("DLabel", requestPanel)
  170. nameLabel:SetFont("CustomFont2") -- Set custom font
  171. nameLabel:SetTextColor(Color(227, 227, 227))
  172. nameLabel:SetText(requestData.name)
  173. nameLabel:SetPos(12 * SCALE_FACTOR, 5 * SCALE_FACTOR) -- Place the nameLabel above the avatar
  174. nameLabel:SizeToContents()
  175.  
  176.  
  177. -- Add request message
  178. -- Add request message
  179. local messageLabel = vgui.Create("DLabel", requestPanel)
  180. messageLabel:SetFont("CustomFont2") -- Set custom font
  181. messageLabel:SetTextColor(Color(227, 227, 227))
  182. messageLabel:SetText(requestData.message)
  183. messageLabel:SetPos(84 * SCALE_FACTOR, 29 * SCALE_FACTOR)
  184. messageLabel:SetSize(280 * SCALE_FACTOR, 44 * SCALE_FACTOR) -- Set width and maximum height
  185. messageLabel:SetWrap(true) -- Enable text wrapping
  186. messageLabel:SetAutoStretchVertical(true) -- Allow the label to expand vertically
  187.  
  188.  
  189. -- Claim case button for each request
  190. local claimButton = vgui.Create("XeninUI.Button", requestPanel)
  191. claimButton:SetFont("CustomFont2") -- Set custom font
  192. claimButton:SetTextColor(Color(227, 227, 227))
  193. claimButton:SetPos(370 * SCALE_FACTOR, 35 * SCALE_FACTOR)
  194. claimButton:SetSize(100 * SCALE_FACTOR, 30 * SCALE_FACTOR)
  195. claimButton:SetText("Claim")
  196. claimButton.DoClick = function()
  197. requestData.claimed = true
  198. requestData.claimedBy = LocalPlayer():SteamID64()
  199. claimButton:SetText("Claimed")
  200. claimButton:SetDisabled(true)
  201. createClaimedRequestUI(requestData)
  202.  
  203. -- Remove the admin request menu
  204. if IsValid(mainPanel) then
  205. mainPanel:Remove()
  206. end
  207.  
  208. net.Start("AdminRequestClaim")
  209. net.WriteTable(requestData)
  210. net.SendToServer()
  211.  
  212. -- Remove the claimed request from the list and move the rest up
  213. for i, panel in ipairs(requestLayout:GetChildren()) do
  214. if panel == requestPanel then
  215. requestLayout:Remove(panel)
  216. break
  217. end
  218. end
  219. -- Remove the claimed request from the requests table
  220. for i, req in ipairs(requests) do
  221. if req == requestData then
  222. table.remove(requests, i)
  223. break
  224. end
  225. end
  226. end
  227. elseif currentPlayerSteamID64 == requestData.steamID64 then
  228. ownRequestOnly = true
  229. end
  230. if ownRequestOnly and #unclaimedRequests == 0 then
  231. if IsValid(mainPanel) then
  232. mainPanel:Remove()
  233. end
  234. return
  235. end
  236. end
  237. if #unclaimedRequests == 0 then
  238. if IsValid(mainPanel) then
  239. mainPanel:Remove()
  240. end
  241. return
  242. end
  243. -- Update the list of admin requests with the unclaimed requests
  244. adminRequests = unclaimedRequests
  245. end
  246.  
  247. local function showClaimDataPanel(claimData)
  248. local function secondsToHMS(seconds)
  249. local hours = math.floor(seconds / 3600)
  250. local mins = math.floor((seconds % 3600) / 60)
  251. local secs = seconds % 60
  252.  
  253. return string.format("%02d:%02d:%02d", hours, mins, secs)
  254. end
  255.  
  256. local frame = vgui.Create("XeninUI.Frame")
  257. frame:SetSize(800, 400)
  258. frame:Center()
  259. frame:SetTitle("Claim Data")
  260. frame:MakePopup()
  261.  
  262. local searchBox = vgui.Create("DTextEntry", frame)
  263. searchBox:SetSize(300, 25)
  264. searchBox:SetPos(10, 40)
  265. searchBox:SetPlaceholderText("Search by SteamID or Last Known Name")
  266.  
  267. local list = vgui.Create("DPanelList", frame)
  268. list:SetSize(frame:GetWide() - 20, frame:GetTall() - 85)
  269. list:SetPos(10, 75)
  270. list:SetSpacing(5)
  271. list:EnableVerticalScrollbar()
  272.  
  273. local function populateList(filter)
  274. list:Clear()
  275. for adminID, data in pairs(claimData) do
  276. if not filter or string.match(adminID, filter) or string.match(string.lower(data.name), string.lower(filter)) then
  277. local line = vgui.Create("DPanel")
  278. line:SetSize(list:GetWide() - 25, 64)
  279. line.Paint = function(self, w, h)
  280. draw.RoundedBox(4, 0, 0, w, h, Color(70, 70, 70))
  281. end
  282.  
  283. local avatar = vgui.Create("AvatarImage", line)
  284. avatar:SetSize(64, 64)
  285. avatar:SetPos(0, 0)
  286. avatar:SetSteamID(adminID, 64)
  287.  
  288. local nameLabel = vgui.Create("DLabel", line)
  289. nameLabel:SetText(data.name)
  290. nameLabel:SetPos(74, 10)
  291. nameLabel:SetFont("DermaDefaultBold")
  292. nameLabel:SizeToContents()
  293.  
  294. local steamIDLabel = vgui.Create("DLabel", line)
  295. steamIDLabel:SetText(adminID)
  296. steamIDLabel:SetPos(74, 30)
  297. steamIDLabel:SizeToContents()
  298.  
  299. local weeklyCountLabel = vgui.Create("DLabel", line)
  300. weeklyCountLabel:SetText("Weekly Sits: " .. data.weeklyCount)
  301. weeklyCountLabel:SetPos(300, 10) -- Adjust the position
  302. weeklyCountLabel:SizeToContents()
  303.  
  304. local totalCountLabel = vgui.Create("DLabel", line)
  305. totalCountLabel:SetText("Total Sits: " .. data.totalCount)
  306. totalCountLabel:SetPos(300, 30) -- Adjust the position
  307. totalCountLabel:SizeToContents()
  308.  
  309. -- Add Last Connected Date label
  310. local lastConnectedLabel = vgui.Create("DLabel", line)
  311. lastConnectedLabel:SetText("Last Connected: " .. data.lastConnected)
  312. lastConnectedLabel:SetPos(500, 10) -- Adjust the position
  313. lastConnectedLabel:SizeToContents()
  314.  
  315. -- Add Time Online label
  316. local timeOnlineLabel = vgui.Create("DLabel", line)
  317. local formattedTimeOnline = secondsToHMS(data.timeOnline) -- Convert seconds to Hours:Minutes:Seconds format
  318. timeOnlineLabel:SetText("Time Online: " .. formattedTimeOnline)
  319. timeOnlineLabel:SetPos(500, 30)
  320. timeOnlineLabel:SizeToContents()
  321.  
  322. list:AddItem(line)
  323. end
  324. end
  325. end
  326. searchBox.OnChange = function()
  327. local filter = searchBox:GetValue()
  328. populateList(filter == "" and nil or filter)
  329. end
  330.  
  331. populateList() -- Removed the parenthesis causing the error
  332. end
  333. net.Receive("AdminRequest", function(len)
  334. local requestData = net.ReadTable()
  335. requestData.ply = player.GetBySteamID64(requestData.steamID64)
  336. if not requestData.ply then return end -- Ensure the player entity exists before proceeding
  337.  
  338. if not adminRequests then
  339. adminRequests = {}
  340. end
  341.  
  342. table.insert(adminRequests, requestData)
  343. createAdminRequestUI(adminRequests)
  344. end)
  345.  
  346. net.Receive("AdminRequestClaimData", function(len)
  347. local claimData = net.ReadTable()
  348. showClaimDataPanel(claimData)
  349. end)
  350.  
  351. net.Receive("UpdatedAdminRequests", function(len)
  352. local updatedRequests = net.ReadTable()
  353.  
  354. -- Check if there are any unclaimed requests
  355. local hasUnclaimedRequests = false
  356. for _, requestData in ipairs(updatedRequests) do
  357. if not requestData.claimed then
  358. hasUnclaimedRequests = true
  359. break
  360. end
  361. end
  362.  
  363. -- Only create the admin request UI if there are unclaimed requests
  364. if hasUnclaimedRequests then
  365. createAdminRequestUI(updatedRequests)
  366. end
  367. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement