From c734fd5e3cb70e3b21d9ef860e0dad300c4f19a8 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 31 Oct 2023 20:42:46 -0400 Subject: [PATCH] Add ban details widget --- [admin]/admin2/client/main/admin_bans.lua | 10 +- .../client/widgets/admin_ban_details.lua | 107 ++++++++++++++++++ [admin]/admin2/meta.xml | 1 + [admin]/admin2/shared/utils.lua | 24 ++++ 4 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 [admin]/admin2/client/widgets/admin_ban_details.lua diff --git a/[admin]/admin2/client/main/admin_bans.lua b/[admin]/admin2/client/main/admin_bans.lua index 5ae4089c8..21865af2d 100644 --- a/[admin]/admin2/client/main/admin_bans.lua +++ b/[admin]/admin2/client/main/admin_bans.lua @@ -44,8 +44,9 @@ function aBansTab.onClientClick(button) if (guiGridListGetSelectedItem(aBansTab.BansList) == -1) then messageBox("No ban selected!", MB_ERROR, MB_OK) else - local ip = guiGridListGetItemText(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 2) - aBanDetails(ip) + local banID = + guiGridListGetItemData(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 1) + aBanDetails.Show(banID, false) end elseif source == aBansTab.Ban then aBan.Show() @@ -55,10 +56,7 @@ function aBansTab.onClientClick(button) else local banID = guiGridListGetItemData(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 1) - -- TODO: use aBanDetails widget (also TODO) to display more information - if (messageBox("Are you sure you want to remove this ban?", MB_QUESTION, MB_YESNO ) == true) then - triggerServerEvent(EVENT_BAN, localPlayer, "unban", banID) - end + aBanDetails.Show(banID, true) end elseif (source == aBansTab.BansRefresh) then guiGridListClear(aBansTab.BansList) diff --git a/[admin]/admin2/client/widgets/admin_ban_details.lua b/[admin]/admin2/client/widgets/admin_ban_details.lua new file mode 100644 index 000000000..a2f733c75 --- /dev/null +++ b/[admin]/admin2/client/widgets/admin_ban_details.lua @@ -0,0 +1,107 @@ +--[[********************************** +* +* Multi Theft Auto - Admin Panel +* +* client\widgets\admin_ban_details.lua +* +**************************************]] +aBanDetails = { + Form = nil, + banID = nil +} + +function aBanDetails.Show(banID, showUnban) + if not aBanDetails.Form then + aBanDetails.Create() + end + + aBanDetails.banID = banID + local data = aBansTab.List[banID] + guiSetText(aBanDetails.NickText, "Player name: "..(data.nick or "Unknown")) + guiSetText(aBanDetails.IPText, "IP: "..(data.ip or "None")) + guiSetText(aBanDetails.SerialText, "Serial: "..(data.serial or "None")) + guiSetText(aBanDetails.ReasonText, "Reason: "..(data.reason or "None")) + guiSetText(aBanDetails.AdminText, "Responsible admin: "..(data.banner or "Unknown")) + if data.unban then + guiSetText(aBanDetails.ExpireText, "Expire time: "..formatDate("m/d/y h:m", nil, data.unban)) + else + guiSetText(aBanDetails.ExpireText, "Expire time: Never") + end + + addEventHandler("onClientGUIClick", aBanDetails.Form, aBanDetails.onClick) + guiSetVisible(aBanDetails.Form, true) + + -- Toggle visibilty of certain elements if this is being opened as a confimration dialog for unban action + if showUnban then + guiSetText(aBanDetails.ConfirmationText, "Are you sure you want to remove this ban?") + guiSetVisible(aBanDetails.CloseButton, false) + guiSetVisible(aBanDetails.SubmitButton, true) + guiSetVisible(aBanDetails.CancelButton, true) + end + guiBringToFront(aBanDetails.Form) +end + +function aBanDetails.Close(destroy) + if destroy then + destroyElement(aBanDetails.Form) + aBanDetails.Form = nil + else + removeEventHandler("onClientGUIClick", aBanDetails.Form, aBanDetails.onClick) + guiSetVisible(aBanDetails.Form, false) + aBanDetails.Reset() + end + aBanDetails.banID = nil +end + +function aBanDetails.Create() + local sx, sy = guiGetScreenSize() + aBanDetails.Form = guiCreateWindow(sx / 2 - 175, sy / 2 - 135, 350, 250, "Ban Details", false) + aBanDetails.ConfirmationText = guiCreateLabel(25, 40, 300, 20, "Ban details:", false, aBanDetails.Form) + aBanDetails.NickText = guiCreateLabel(50, 70, 300, 20, "Player name: Unknown", false, aBanDetails.Form) + aBanDetails.IPText = guiCreateLabel(50, 90, 300, 20, "IP: None", false, aBanDetails.Form) + aBanDetails.SerialText = guiCreateLabel(50, 110, 300, 20, "Serial: None", false, aBanDetails.Form) + aBanDetails.ReasonText = guiCreateLabel(50, 130, 300, 20, "Reason: None", false, aBanDetails.Form) + aBanDetails.AdminText = guiCreateLabel(50, 150, 300, 20, "Responsible admin: Unknown", false, aBanDetails.Form) + aBanDetails.ExpireText = guiCreateLabel(50, 170, 300, 20, "Expire time: Never", false, aBanDetails.Form) + + aBanDetails.SubmitButton = guiCreateButton(105, 200, 60, 40, "Submit", false, aBanDetails.Form) + aBanDetails.CancelButton = guiCreateButton(185, 200, 60, 40, "Cancel", false, aBanDetails.Form) + aBanDetails.CloseButton = guiCreateButton(145, 200, 60, 40, "Close", false, aBanDetails.Form) + guiSetVisible(aBanDetails.CloseButton, true) + guiSetVisible(aBanDetails.SubmitButton, false) + guiSetVisible(aBanDetails.CancelButton, false) + aRegister("Ban Details", aBanDetails.Form, aBanDetails.Show, aBanDetails.Close) + guiSetVisible(aBanDetails.Form, false) +end + +function aBanDetails.Reset() + outputDebugString("reset") + guiSetText(aBanDetails.Form, "Ban Details") + guiSetText(aBanDetails.ConfirmationText, "Ban details:") + guiSetText(aBanDetails.NickText, "Player name: Unknown") + guiSetText(aBanDetails.IPText, "IP: None") + guiSetText(aBanDetails.SerialText, "Serial: None") + guiSetText(aBanDetails.ReasonText, "Reason: None") + guiSetText(aBanDetails.AdminText, "Responsible admin: Unknown") + guiSetText(aBanDetails.ExpireText, "Expire time: Never") + guiSetVisible(aBanDetails.CloseButton, true) + guiSetVisible(aBanDetails.SubmitButton, false) + guiSetVisible(aBanDetails.CancelButton, false) +end + +function aBanDetails.onClick(button, state) + if not (button == "left" and state == "up") then + return + end + + -- Handle cancel button first + if source == aBanDetails.CancelButton or source == aBanDetails.CloseButton then + aBanDetails.Close() + return + end + + if source == aBanDetails.SubmitButton then + triggerServerEvent(EVENT_BAN, localPlayer, "unban", aBanDetails.banID) + return + end +end \ No newline at end of file diff --git a/[admin]/admin2/meta.xml b/[admin]/admin2/meta.xml index 20d65581a..29cfcc24d 100644 --- a/[admin]/admin2/meta.xml +++ b/[admin]/admin2/meta.xml @@ -66,6 +66,7 @@