Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internetradio: add ability to show speaker owner #526

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions [gameplay]/internetradio/config/CRadioConfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RADIO_TRACK_COLOR = tocolor(150, 50, 150, 255)
RADIO_TRACK_BACKGROUND_COLOR = tocolor(0, 0, 0, 255)

RADIO_TOGGLE_KEY = "F3"
RADIO_SHOW_SPEAKER_OWNER_KEY = "lalt"
RADIO_SHOW_ON_START = false
RADIO_COMMANDS = {"sound", "music", "musica", "song", "radio", "speaker"}
RADIO_SETTINGS_PATH = "settings.json"
Expand Down
2 changes: 1 addition & 1 deletion [gameplay]/internetradio/handle_radio/CHandleRadio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function isObjectSpeaker(objectElement)
local speakerSound = speakerSounds[playerElement]
local speakerDummy = speakerData.speakerDummy

return true, speakerSound, speakerDummy
return true, speakerSound, speakerDummy, playerElement
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions [gameplay]/internetradio/handle_radio/ShHandleRadio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ function getPlayerFromPartialName(partialName)
return false
end

function removeHex(stringToRemoveHexFrom)
local removedHex = string.gsub(stringToRemoveHexFrom, "#%x%x%x%x%x%x", "")

return removedHex
end

function getOrSetPlayerDelay(playerElement, delayID, delayTime)
local validElement = isElement(playerElement)

Expand Down
17 changes: 14 additions & 3 deletions [gameplay]/internetradio/track_name/CRadioTrackName.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ function checkForNearbySpeakers()

for objectID = 1, #nearbyObjects do
local nearbyObject = nearbyObjects[objectID]
local _, speakerSound, speakerDummy = isObjectSpeaker(nearbyObject)
local _, speakerSound, speakerDummy, speakerOwner = isObjectSpeaker(nearbyObject)
local trackName = getSpeakerTrackName(speakerSound)

if (speakerDummy and trackName) then
NEARBY_SPEAKERS[speakerDummy] = trackName
NEARBY_SPEAKERS[speakerDummy] = {trackName, speakerOwner}
end
end

Expand All @@ -89,7 +89,7 @@ setTimer(checkForNearbySpeakers, 1000, 0)
function onClientRenderRadioTrackName()
local cameraX, cameraY, cameraZ = getCameraMatrix()

for nearbySpeaker, trackName in pairs(NEARBY_SPEAKERS) do
for nearbySpeaker, speakerData in pairs(NEARBY_SPEAKERS) do
local speakerX, speakerY, speakerZ = getElementPosition(nearbySpeaker)
local distanceToSpeaker = getDistanceBetweenPoints3D(speakerX, speakerY, speakerZ, cameraX, cameraY, cameraZ)
local closeToSpeaker = (distanceToSpeaker <= RADIO_MAX_SOUND_DISTANCE)
Expand All @@ -99,6 +99,17 @@ function onClientRenderRadioTrackName()
local screenX, screenY = getScreenFromWorldPosition(speakerX, speakerY, speakerOffsetZ, 0, false)

if (screenX and screenY) then
local trackName = speakerData[1]
local displaySpeakerOwner = getKeyState(RADIO_SHOW_SPEAKER_OWNER_KEY)

if (displaySpeakerOwner) then
local speakerOwner = speakerData[2]
local speakerName = getPlayerName(speakerOwner)
local speakerPlayerName = removeHex(speakerName)

trackName = "(Owner: "..speakerPlayerName..") "..trackName
end

local textWidth = dxGetTextWidth(trackName, RADIO_TRACK_SCALE, RADIO_TRACK_FONT, trackNameColorCoded)
local textPosX = (screenX - textWidth / 2)
local textBackgroundPosX = (textPosX - 5)
Expand Down