Skip to content

Commit

Permalink
Radio: Create new UI for remote useable radio (TTT-2#1437)
Browse files Browse the repository at this point in the history
Before this you had to navigate to the shop tabs to use it, which is
really unintuitive and currently blocks our idea to do a new shop.

![grafik](https://github.com/TTT-2/TTT2/assets/72046466/cf56c6e4-3d36-4e77-9ea8-94eceba39173)

Now you can use the 'Use'-Key from any distance on the focussed radio
marker

![grafik](https://github.com/TTT-2/TTT2/assets/72046466/7c4d6c30-d48b-40c1-b799-934fd09d7aad)
and get the following new UI, which triggers the sounds in the same way
as before

![grafik](https://github.com/TTT-2/TTT2/assets/72046466/a9fa7cd5-e929-4878-9e54-3f63aba65737)

This will be waiting for the approval of the remote trigger feature in
TTT-2#1436

---------

Co-authored-by: Tim Goll <[email protected]>
Co-authored-by: Histalek <[email protected]>
  • Loading branch information
3 people authored Mar 6, 2024
1 parent 1d4abf5 commit 270a8a3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 99 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions gamemodes/terrortown/entities/entities/ttt_radio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions gamemodes/terrortown/gamemode/client/cl_equip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
152 changes: 69 additions & 83 deletions gamemodes/terrortown/gamemode/client/cl_tradio.lua
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
5 changes: 3 additions & 2 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

0 comments on commit 270a8a3

Please sign in to comment.