diff --git a/CHANGELOG.md b/CHANGELOG.md index 0702842b28..8f5074c6ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,17 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Added `plymeta:IsFullySignedOn()` to allow excluding players that have not gotten control yet (by @EntranceJew) - Added hook ENTITY:RemoteUse(ply), which is shared - Return true if only clientside should be used +- Added RemoteUse to radio, you can now directly access it via use button on marker focus ### Changed ### Fixed - Fixed the AFK timer accumulating while player not fully joined (by @EntranceJew) +- +### Removed + +- Removed radio tab in shop UI ## [v0.13.1b](https://github.com/TTT-2/TTT2/tree/v0.13.1b) (2024-02-27) diff --git a/gamemodes/terrortown/entities/entities/ttt_radio.lua b/gamemodes/terrortown/entities/entities/ttt_radio.lua index 3b8577c2a3..24539be7c1 100644 --- a/gamemodes/terrortown/entities/entities/ttt_radio.lua +++ b/gamemodes/terrortown/entities/entities/ttt_radio.lua @@ -362,9 +362,22 @@ if CLIENT then mvData:AddDescriptionLine(ParT("marker_vision_owner", { owner = nick })) mvData:AddDescriptionLine(ParT("marker_vision_distance", { distance = distance })) + mvData:AddDescriptionLine(ParT("use_entity", { usekey = Key("+use", "USE") })) mvData:AddDescriptionLine(TryT(mvObject:GetVisibleForTranslationKey()), COLOR_SLATEGRAY) end) + + --- + -- This is triggered, when you focus a marker of an entity and press 'Use'-Key + -- Opens the radio menu + -- @param Player ply The player that used this entity. Always LocalPlayer here. + -- @return bool True, because this shouldn't be used serverside + -- @realm client + function ENT:RemoteUse(ply) + TRADIO:Toggle(self) + + return true + end end if SERVER then diff --git a/gamemodes/terrortown/gamemode/client/cl_equip.lua b/gamemodes/terrortown/gamemode/client/cl_equip.lua index 49d8d12b66..0292863f6d 100644 --- a/gamemodes/terrortown/gamemode/client/cl_equip.lua +++ b/gamemodes/terrortown/gamemode/client/cl_equip.lua @@ -938,20 +938,6 @@ function TraitorMenuPopup() ) end - -- Weapon/item control - if IsValid(client.radio) or client:HasWeapon("weapon_ttt_radio") then - local dradio = TRADIO.CreateMenu(dsheet) - - dsheet:AddSheet( - GetTranslation("radio_name"), - dradio, - "icon16/transmit.png", - false, - false, - GetTranslation("equip_tooltip_radio") - ) - end - -- Credit transferring if credits > 0 then local dtransfer = CreateTransferMenu(dsheet) diff --git a/gamemodes/terrortown/gamemode/client/cl_tradio.lua b/gamemodes/terrortown/gamemode/client/cl_tradio.lua index ceaa79f3ae..28e18f6f8e 100644 --- a/gamemodes/terrortown/gamemode/client/cl_tradio.lua +++ b/gamemodes/terrortown/gamemode/client/cl_tradio.lua @@ -1,12 +1,11 @@ --- -- Traitor radio controls -- @module TRADIO +TRADIO = TRADIO or {} +TRADIO.sizes = TRADIO.sizes or {} +TRADIO.menuFrame = TRADIO.menuFrame or nil -TRADIO = {} - -local IsValid = IsValid - -local sound_names = { +local sounds = { scream = "radio_button_scream", explosion = "radio_button_expl", pistol = "radio_button_pistol", @@ -21,92 +20,79 @@ local sound_names = { footsteps = "radio_button_steps", } -local smatrix = { - { "scream", "burning", "explosion", "footsteps" }, - { "pistol", "shotgun", "mac10", "deagle" }, - { "m16", "rifle", "huge", "beeps" }, -} - -local function PlayRadioSound(snd) - local r = LocalPlayer().radio - if not IsValid(r) then - return - end - - RunConsoleCommand("ttt_radio_play", tostring(r:EntIndex()), snd) -end - -local function ButtonClickPlay(s) - PlayRadioSound(s.snd) -end - -local function CreateSoundBoard(parent) - local b = vgui.Create("DPanel", parent) - - --b:SetPaintBackground(false) - - local bh, bw = 50, 100 - local m = 5 - local ver = #smatrix - local hor = #smatrix[1] - - local x, y = 0, 0 - - for ri = 1, ver do - local row = smatrix[ri] - local rj = ri - 1 -- easier for computing x, y - - for rk = 1, #row do - local snd = row[rk] - local rl = rk - 1 - - y = rj * m + rj * bh - x = rl * m + rl * bw +--- +-- Calculates and caches the dimensions of the Radio UI. +-- @realm client +function TRADIO:CalculateSizes() + self.sizes.padding = 10 - local but = vgui.Create("DButton", b) - but:SetPos(x, y) - but:SetSize(bw, bh) - but:SetText(LANG.GetTranslation(sound_names[snd])) + self.sizes.heightButton = 45 + self.sizes.widthButton = 160 - but.snd = snd - but.DoClick = ButtonClickPlay - end - end + self.sizes.numWidthButtons = 3 + self.sizes.numHeightButtons = math.ceil(table.Count(sounds) / 3) - b:SetSize(bw * hor + m * (hor - 1), bh * ver + m * (ver - 1)) - b:SetPos(m, 25) - b:CenterHorizontal() + self.sizes.widthMainArea = self.sizes.widthButton * self.sizes.numWidthButtons + + (self.sizes.numWidthButtons - 1) * self.sizes.padding + self.sizes.heightMainArea = self.sizes.heightButton * self.sizes.numHeightButtons + + (self.sizes.numHeightButtons - 1) * self.sizes.padding - return b + self.sizes.width = self.sizes.widthMainArea + 2 * self.sizes.padding + self.sizes.height = self.sizes.heightMainArea + + vskin.GetHeaderHeight() + + vskin.GetBorderSize() + + 2 * self.sizes.padding end --- --- Creates the traitor radio menu --- @param Panel parent --- @return Panel the created DPanel menu +-- Show the radio UI with all sound buttons. Generates the whole UI. +-- @param Entity radioEnt The radio Entity to toggle UI for -- @realm client -function TRADIO.CreateMenu(parent) - local w, h = parent:GetSize() - local client = LocalPlayer() - - local wrap = vgui.Create("DPanel", parent) - wrap:SetSize(w, h) - wrap:SetPaintBackground(false) - - local dhelp = vgui.Create("DLabel", wrap) - dhelp:SetFont("TabLarge") - dhelp:SetText(LANG.GetTranslation("radio_help")) - dhelp:SetTextColor(COLOR_WHITE) - - if IsValid(client.radio) then - CreateSoundBoard(wrap) -- local board - elseif client:HasWeapon("weapon_ttt_radio") then - dhelp:SetText(LANG.GetTranslation("radio_notplaced")) +function TRADIO:Toggle(radioEnt) + self.radio = radioEnt + self.entIndex = tostring(radioEnt:EntIndex()) + + self:CalculateSizes() + + -- IF MENU ELEMENT DOES NOT ALREADY EXIST, CREATE IT + if IsValid(self.menuFrame) then + self.menuFrame:CloseFrame() + else + self.menuFrame = + vguihandler.GenerateFrame(self.sizes.width, self.sizes.height, "radio_name") end - dhelp:SizeToContents() - dhelp:SetPos(10, 5) - dhelp:CenterHorizontal() - - return wrap + self.menuFrame:SetPadding( + self.sizes.padding, + self.sizes.padding, + self.sizes.padding, + self.sizes.padding + ) + + -- any keypress closes the frame + self.menuFrame:SetKeyboardInputEnabled(false) + self.menuFrame.OnKeyCodePressed = util.BasicKeyHandler + + local contentBox = vgui.Create("DPanelTTT2", self.menuFrame) + contentBox:SetSize(self.sizes.widthMainArea, self.sizes.heightMainArea) + contentBox:Dock(TOP) + + local buttonField = vgui.Create("DIconLayout", contentBox) + buttonField:SetSpaceY(self.sizes.padding) + buttonField:SetSpaceX(self.sizes.padding) + buttonField:SetSize(self.sizes.widthContentArea, self.sizes.heightMainArea) + buttonField:Dock(TOP) + + for sound, translationName in pairs(sounds) do + local buttonReport = vgui.Create("DButtonTTT2", buttonField) + buttonReport:SetText(LANG.GetTranslation(translationName)) + buttonReport:SetSize(self.sizes.widthButton, self.sizes.heightButton) + buttonReport.DoClick = function(btn) + if not IsValid(self.radio) then + return + end + + RunConsoleCommand("ttt_radio_play", self.entIndex, sound) + end + end end diff --git a/lua/terrortown/lang/en.lua b/lua/terrortown/lang/en.lua index dd24ade18b..fec26bd914 100644 --- a/lua/terrortown/lang/en.lua +++ b/lua/terrortown/lang/en.lua @@ -130,8 +130,6 @@ L.xfer_received = "{player} has given you {num} credit." -- Radio tab in equipment menu L.radio_name = "Radio" -L.radio_help = "Click a button to make your Radio play that sound." -L.radio_notplaced = "You must place the Radio to play sound on it." -- Radio soundboard buttons L.radio_button_scream = "Scream" @@ -2190,3 +2188,6 @@ L.magneto_stick_help_carry_prop_drop = "Drop prop" -- 2024-02-14 L.throw_no_room = "You have no space here to throw this device" + +-- 2024-03-04 +L.use_entity = "Press [{usekey}] to use"