feat(announcement): add client-side announcement menu with simple and loader styles

Implement announcement display system with HUD integration supporting two visual styles:
- Simple: centered text announcement with logo
- Loader: announcement with progress bar showing remaining display time

Features:
- Server to client message handling via net.Receive
- Configurable display duration
- Persistent state across hot-reloads
- Integration with rndx drawing library for styled UI elements
This commit is contained in:
nocode committed 2026-07-20 12:47:08 +02:00
1 parent 8685d739f3
commit 9501bfa6f8
1 file changed
+74
@@ -0,0 +1,74 @@
local rndx = include("lib/rndx.lua")
local logo = Material("nocode/announcement/logo.png")
-- client/ se charge avant shared/ (ordre alphabétique du loader) : on garantit la table
BladW = BladW or {}
BladW.Announcement = BladW.Announcement or {}
-- Largeur du fond de la barre "loader" (doit rester synchro avec le rndx.Draw plus bas)
local BAR_WIDTH = 200
-- État de l'annonce en cours (persiste au hot-reload)
BladW.Announcement.Active = BladW.Announcement.Active or false
BladW.Announcement.Title = BladW.Announcement.Title or "Annonce"
BladW.Announcement.Text = BladW.Announcement.Text or ""
BladW.Announcement.StartTime = BladW.Announcement.StartTime or 0
-- Déclenche l'affichage d'une annonce pour la durée configurée
function BladW.Announcement.Show(title, text)
BladW.Announcement.Title = title ~= "" and title or "Annonce"
BladW.Announcement.Text = text or ""
BladW.Announcement.StartTime = CurTime()
BladW.Announcement.Active = true
end
-- Serveur -> client : une annonce a été diffusée
net.Receive("bladWShowAnnouncement", function()
local title = net.ReadString()
local text = net.ReadString()
BladW.Announcement.Show(title, text)
end)
hook.Add("HUDPaint", "BladeWin:Announcement", function()
if not BladW.Announcement.Active then return end
local ply = LocalPlayer()
if not IsValid(ply) then return end
local Conf = BladW.Announcement.Conf
local duration = Conf.announcement_duration or 10
local elapsed = CurTime() - BladW.Announcement.StartTime
-- Temps d'affichage écoulé -> on masque l'annonce
if elapsed >= duration then
BladW.Announcement.Active = false
return
end
local title = BladW.Announcement.Title
local text = BladW.Announcement.Text
if Conf.announcement_style == "simple" then
rndx.Draw(14, 788, 38, 343, 133, nil, rndx.SHAPE_FIGMA + rndx.BLUR)
rndx.Draw(14, 788, 38, 343, 133, Color(0,0,0, 200), rndx.SHAPE_FIGMA)
rndx.DrawOutlined(14, 788, 38, 343, 133, Color(255, 255, 255), 3, rndx.SHAPE_FIGMA)
rndx.DrawMaterial(0, 910, 20, 100, 100, color_white, logo)
draw.SimpleText(title, "bladw_text", 960, 113, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(text, "bladw_text_Medium", 960, 140, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
if Conf.announcement_style == "loader" then
-- La barre représente le temps d'affichage restant : elle se vide sur la durée
local remaining = math.Clamp(1 - (elapsed / duration), 0, 1)
local loaderBar = remaining * BAR_WIDTH
rndx.Draw(14, 788, 38, 343, 133, nil, rndx.SHAPE_FIGMA + rndx.BLUR)
rndx.Draw(14, 788, 38, 343, 133, Color(0,0,0, 200), rndx.SHAPE_FIGMA)
rndx.DrawOutlined(14, 788, 38, 343, 133, Color(255, 255, 255), 3, rndx.SHAPE_FIGMA)
rndx.DrawMaterial(0, 788, 20, 100, 100, color_white, logo)
draw.SimpleText(title, "bladw_text", 960, 113, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(text, "bladw_text_Medium", 960, 140, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
rndx.Draw(14, 880, 60, BAR_WIDTH, 20, Color(54,54,54, 200), rndx.SHAPE_FIGMA)
rndx.Draw(14, 880, 60, loaderBar, 20, Color(76, 119, 200), rndx.SHAPE_FIGMA)
end
end)