From 113d99c0907598b9605c0a4a129b83815a4a3af6 Mon Sep 17 00:00:00 2001 From: nocode Date: Mon, 20 Jul 2026 12:46:23 +0200 Subject: [PATCH] feat(admin_menu): add client-side admin menu for announcements Add a new admin menu interface that allows admins to create and send announcements. The menu features: - Styled DFrame with logo and title - Input fields for announcement title and message - Send button that transmits announcement data to server via net message - Close button and automatic closing when game UI is opened - Consistent theming with announcement display (colors, rounded corners, blur effect) - Prevents multiple menu instances from stacking --- .../client/admin_menu/cl_menu.lua | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 lua/bladw_announcement/client/admin_menu/cl_menu.lua diff --git a/lua/bladw_announcement/client/admin_menu/cl_menu.lua b/lua/bladw_announcement/client/admin_menu/cl_menu.lua new file mode 100644 index 0000000..c658c5a --- /dev/null +++ b/lua/bladw_announcement/client/admin_menu/cl_menu.lua @@ -0,0 +1,110 @@ +local rndx = include("lib/rndx.lua") +local logo = Material("nocode/announcement/logo.png") + +-- Palette identique au thème des annonces +local COL_BG = Color(0, 0, 0, 200) +local COL_PANEL = Color(0, 0, 0, 160) +local COL_ACCENT = Color(76, 119, 200) +local COL_ACCENT_DIM = Color(60, 90, 150) +local COL_TEXT = Color(255, 255, 255) +local COL_RED = Color(255, 80, 80) +local COL_GRAY = Color(54, 54, 54, 255) + +-- Applique le style thème à un DTextEntry +local function StyleEntry(entry, placeholder, default) + entry:SetFont("bladw_text_Medium") + entry:SetText(default or "") + entry:SetPlaceholderText(placeholder or "") + entry:SetTextColor(COL_TEXT) + entry:SetPaintBackground(false) + entry.Paint = function(self, w, h) + rndx.Draw(10, 0, 0, w, h, COL_PANEL, rndx.SHAPE_FIGMA) + local outline = self:IsEditing() and COL_ACCENT or Color(255, 255, 255, 60) + rndx.DrawOutlined(10, 0, 0, w, h, outline, 2, rndx.SHAPE_FIGMA) + self:DrawTextEntryText(COL_TEXT, COL_ACCENT, COL_TEXT) + end +end + +local function OpenAAdminMenu() + + -- Évite d'empiler plusieurs fenêtres si on rouvre le menu + if IsValid(BladW_AdminMenu) then BladW_AdminMenu:Remove() end + + local frame = vgui.Create("DFrame") + BladW_AdminMenu = frame + frame:SetSize(500, 380) + frame:Center() + frame:SetTitle("") + frame:ShowCloseButton(false) + frame:MakePopup() + + frame.Paint = function(self, w, h) + -- Fond flouté + sombre + contour blanc (comme la box d'annonce) + rndx.Draw(20, 0, 0, w, h, nil, rndx.SHAPE_FIGMA + rndx.BLUR) + rndx.Draw(20, 0, 0, w, h, COL_BG, rndx.SHAPE_FIGMA) + rndx.DrawOutlined(20, 0, 0, w, h, COL_TEXT, 3, rndx.SHAPE_FIGMA) + + -- Logo + titre + rndx.DrawMaterial(0, w * 0.5 - 32, 22, 64, 64, COL_TEXT, logo) + draw.SimpleText("Envoyer une annonce", "bladw_text", w * 0.5, 100, COL_TEXT, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + end + + -- ⚠️ ESC est captée par le moteur (bind du menu pause) AVANT la lib input, + -- donc input.IsKeyDown(KEY_ESCAPE) est toujours false → indétectable ici. + -- On détecte plutôt l'ouverture du menu pause, que ESC provoque. + frame.Think = function(self) + if gui.IsGameUIVisible() then + self:Remove() + end + end + + -- Bouton fermer + local close = vgui.Create("DButton", frame) + close:SetSize(30, 30) + close:SetPos(frame:GetWide() - 42, 14) + close:SetText("") + close.Paint = function(self, w, h) + rndx.Draw(8, 0, 0, w, h, self:IsHovered() and COL_RED or COL_GRAY, rndx.SHAPE_FIGMA) + draw.SimpleText("X", "bladw_text_Medium", w * 0.5, h * 0.5, COL_TEXT, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + end + close.DoClick = function() frame:Remove() end + + -- Champ : titre de l'annonce + local titleEntry = vgui.Create("DTextEntry", frame) + titleEntry:SetPos(40, 140) + titleEntry:SetSize(420, 42) + StyleEntry(titleEntry, "Titre de l'annonce", "Annonce") + + -- Champ : message de l'annonce + local msgEntry = vgui.Create("DTextEntry", frame) + msgEntry:SetPos(40, 196) + msgEntry:SetSize(420, 42) + StyleEntry(msgEntry, "Message de l'annonce") + + -- Bouton d'envoi + local send = vgui.Create("DButton", frame) + send:SetPos(40, 300) + send:SetSize(420, 50) + send:SetText("") + send.Paint = function(self, w, h) + rndx.Draw(12, 0, 0, w, h, self:IsHovered() and COL_ACCENT or COL_ACCENT_DIM, rndx.SHAPE_FIGMA) + draw.SimpleText("Envoyer", "bladw_text", w * 0.5, h * 0.5, COL_TEXT, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + end + send.DoClick = function() + local text = msgEntry:GetValue() + if text == "" then + surface.PlaySound("buttons/button10.wav") + return + end + + net.Start("bladWSendAnnouncement") + net.WriteString(titleEntry:GetValue()) + net.WriteString(text) + net.SendToServer() + + frame:Remove() + end + +end + +return OpenAAdminMenu