Skip to content

Commit b1f5478

Browse files
authored
Merge branch 'master' into feature/add-GUI-mute
2 parents 2aae5dd + 362f23c commit b1f5478

File tree

9 files changed

+199
-31
lines changed

9 files changed

+199
-31
lines changed

[editor]/editor_gui/client/browser/browser.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ function createBrowser()
2020
browserGUI.window = guiCreateWindow ( 0, 0, 0.25, 1, "Browse...", true )
2121
guiSetVisible ( browserGUI.window, false )
2222
browserGUI.dropdown = editingControl.dropdown:create{["x"]=12,["y"]=25,["width"]=screenX*0.25,["height"]=20,["dropWidth"]=screenX*0.25,["dropHeight"]=200,["relative"]=false,["parent"]=browserGUI.window,["rows"]={"All categories", "Favourites"}}
23-
browserGUI.list = browserList:create( 12, 85, screenX*0.25, screenY*1-112, { {["Element"]=0.95-(60/(screenX*0.25))},{["[ID]"]=40/(screenX*0.25)}},false, browserGUI.window )
23+
browserGUI.list = browserList:create( 12, 85, screenX*0.25, screenY*1-140, { {["Element"]=0.95-(60/(screenX*0.25))},{["[ID]"]=40/(screenX*0.25)}},false, browserGUI.window )
2424
browserGUI.search = guiCreateEdit ( 12, 50, screenX*0.25, 30, "Search...", false, browserGUI.window )
2525
browserGUI.ok = guiCreateButton ( 12, screenY-24, screenX*0.125 - 2, 40, "OK", false, browserGUI.window )
2626
browserGUI.cancel = guiCreateButton ( screenX*0.125 + 12 + 2, screenY-24, screenX*0.125 - 2, 40, "Cancel", false, browserGUI.window )
2727
browserGUI.searchProgress = guiCreateLabel ( 0, 0, 1, 0.1, "", true )
2828
browserGUI.searchModel = guiCreateLabel ( 0, 0, 1, 0.1, "", true )
29+
browserGUI.doubleside = guiCreateCheckBox ( 12, screenY-50, 110, 20, "Set doublesided", false, false, browserGUI.window )
2930
guiSetVisible ( browserGUI.searchProgress, false )
3031
guiSetVisible ( browserGUI.searchModel, false )
3132
guiLabelSetColor ( browserGUI.searchProgress,0,0,0 )
@@ -37,6 +38,7 @@ function createBrowser()
3738

3839
addEventHandler ("onClientGUIClick",browserGUI.ok,browser.browserSelected,false)
3940
addEventHandler ("onClientGUIClick",browserGUI.cancel,browser.browserCancelled,false)
41+
addEventHandler ("onClientGUIClick",browserGUI.doubleside,browser.setDoublesided,false)
4042
end
4143

4244
function browser.initiate ( theType, initialCat, initialModel )
@@ -67,6 +69,8 @@ function browser.initiate ( theType, initialCat, initialModel )
6769
setPlayerHudComponentVisible ( "radar", false )
6870
setSkyGradient(112,112,112,112,112,112)
6971
setCameraInterior ( 14 )
72+
setFarClipDistance(700)
73+
setFogDistance(700)
7074
guiSetVisible ( browserGUI.window, true )
7175
--Output a default search
7276
local results = elementSearch ( catNodes[initialCat],"" )
@@ -135,6 +139,8 @@ function browser.close()
135139
removeEventHandler ( "onClientRender", root, rotateMesh )
136140
setCameraInterior ( returnInterior )
137141
resetSkyGradient()
142+
resetFarClipDistance()
143+
resetFogDistance()
138144
setPlayerHudComponentVisible ( "radar", true )
139145
if isElement ( browser.mainElement ) then
140146
setElementAlpha(browser.mainElement, 255)
@@ -330,6 +336,11 @@ function browser.browserCancelled(button)
330336
browser.close()
331337
end
332338

339+
function browser.setDoublesided(button)
340+
if button ~= "left" then return end
341+
setElementDoubleSided(browser.mainElement, guiCheckBoxGetSelected(browserGUI.doubleside))
342+
end
343+
333344
function setProgressText ( text )
334345
guiSetText ( browserGUI.searchProgress, text )
335346
local length = guiLabelGetTextExtent ( browserGUI.searchProgress )

[editor]/editor_gui/client/browser/freelook.lua

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ browserElementLookOptions = {
1919
distance = 4,
2020
minDistance = 2,
2121
maxDistance = 40,
22-
scrollUnits = 2,
22+
scrollUnits = 5,
2323
scrollSpeed = 0.1,
2424
up = "mouse_wheel_up",
2525
down = "mouse_wheel_down",
@@ -40,8 +40,8 @@ function elementLookFrame ()
4040
local camAngleY = browserElementLookOptions.invertedY * rotY / 120
4141

4242
-- get the position of the target
43-
local camTargetX, camTargetY, camTargetZ = getElementPosition ( browserElementLookOptions.target ) -- tx, ty, tz
44-
camTargetZ = camTargetZ + browserElementLookOptions.camZOffset
43+
local camTargetX, camTargetY, camTargetZ = tx, ty, tz
44+
4545
-- calculate a new positions for the camera
4646
local distX = math.cos ( camAngleY ) * cameraDistance
4747
local camPosX = camTargetX + ( ( math.cos ( camAngleX ) ) * distX )
@@ -86,11 +86,9 @@ function resetCamDist()
8686
if cameraDistance < browserElementLookOptions.distance then
8787
if cameraDistance + newDistance < browserElementLookOptions.distance then
8888
cameraDistance = cameraDistance + newDistance
89-
else cameraDistance = browserElementLookOptions.distance
9089
end
9190
elseif cameraDistance - newDistance > browserElementLookOptions.distance then
92-
cameraDistance = cameraDistance - newDistance
93-
else cameraDistance = browserElementLookOptions.distance
91+
cameraDistance = cameraDistance - newDistance
9492
end
9593
end
9694

@@ -120,10 +118,7 @@ function math.round ( value )
120118
end
121119

122120
function scrollDown()
123-
if browserElementLookOptions.distance + browserElementLookOptions.scrollUnits < browserElementLookOptions.maxDistance
124-
then browserElementLookOptions.distance = browserElementLookOptions.distance + browserElementLookOptions.scrollUnits
125-
else browserElementLookOptions.distance = browserElementLookOptions.maxDistance
126-
end
121+
browserElementLookOptions.distance = browserElementLookOptions.distance + browserElementLookOptions.scrollUnits
127122
end
128123

129124
function scrollUp()

[editor]/editor_gui/client/browser/previewelement.lua

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tx,ty,tz = 91,100,502 --The position of the element
1+
tx,ty,tz = 100,100,15000 --The position of the element
22
local hideX,hideY,hideZ = 0,0,0 --where to hide the local player
33
local rz = 0 -- The current rotation
44
local maxRadius = 5
@@ -23,6 +23,7 @@ function browserSetElementModel ( elemID, model )
2323
setModel[elemID](model)
2424
end
2525
end
26+
2627
function setModel.vehicleID ( model )
2728
local randomOffset = ((getTickCount() % 20) / 100) + 0.001
2829

@@ -60,26 +61,31 @@ function setModel.vehicleID ( model )
6061
setCameraMatrix ( tx - realDistance, ty, tz + elevation + randomOffset,
6162
tx, ty + moveLeft, tz + randomOffset)
6263
end
64+
6365
function setModel.objectID ( model )
6466
local randomOffset = ((getTickCount() % 20) / 100) + 0.001
6567

6668
if not browser.mainElement then
67-
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz)
69+
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz, true)
70+
setElementDoubleSided(browser.mainElement, guiCheckBoxGetSelected(browserGUI.doubleside))
6871
setElementDimension ( browser.mainElement, BROWSER_DIMENSION )
6972
setElementInterior(browser.mainElement, 14)
7073
else
7174
setElementModel(browser.mainElement, model)
7275
end
7376

74-
setElementPosition(browser.mainElement, tx, ty, tz + randomOffset)
77+
setElementPosition(browser.mainElement, tx, ty, tz)
7578
setElementAlpha(browser.mainElement, 255)
7679

77-
local radius = getElementRadius(browser.mainElement)
78-
browserElementLookOptions.distance = 14
79-
setObjectScale ( browser.mainElement, maxRadius / radius )
80-
setCameraMatrix ( tx - 17, ty, tz + 3 + randomOffset,
81-
tx, ty + 2, tz + randomOffset)
80+
local a,b,c,d,e,f = getElementBoundingBox(browser.mainElement)
81+
local radius = math.max(7, getElementRadius(browser.mainElement)*2.1)
82+
radius = math.max(radius, math.sqrt((c*c)+(f*f))*2)
83+
browserElementLookOptions.distance = radius
84+
local offset = radius * 0.2
85+
setCameraMatrix ( tx - radius - offset, ty + offset, tz + radius * 0.25,
86+
tx - offset, ty + offset, tz)
8287
end
88+
8389
function setModel.skinID ( model )
8490
local randomOffset = (getTickCount() % 20) / 100
8591

@@ -108,9 +114,27 @@ function rotateMesh ()
108114
if ( initiatedType ) == "vehicleID" then
109115
setElementRotation ( browser.mainElement,0,0,newRotation)
110116
elseif ( initiatedType ) == "objectID" then
111-
setElementRotation ( browser.mainElement,0,0,newRotation)
117+
_previewRotate ( browser.mainElement,newRotation)
112118
elseif ( initiatedType ) == "skinID" then
113-
setPedRotation ( browser.mainElement,newRotation )
119+
setPedRotation ( browser.mainElement,newRotation)
114120
end
115121
end
116122

123+
function _previewRotate(object, rotation)
124+
-- https://github.com/multitheftauto/mtasa-resources/commit/117759a6df540c21515d2666794e05dcf9c76254
125+
local a,b,c,d,e,f = getElementBoundingBox(object)
126+
127+
local halfCenterX = (a + d) * 0.25
128+
local halfCenterY = (b + e) * 0.25
129+
local halfCenterZ = (c + f) * 0.25
130+
131+
local rad = math.rad(rotation)
132+
local cZ, sZ = math.cos(rad), math.sin(rad)
133+
134+
local oX = halfCenterX*cZ - halfCenterY*sZ
135+
local oY = halfCenterX*sZ + halfCenterY*cZ
136+
local oZ = halfCenterZ
137+
138+
setElementPosition(object, tx - oX, ty - oY, tz - oZ)
139+
setElementRotation(object, 0, 0, rotation)
140+
end

[gameplay]/internetradio/config/ShRadioConfig.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-- #######################################
66

77
RADIO_CREATE_SPEAKER_DELAY = 1000
8+
RADIO_VOLUME_DELAY = 200
89
RADIO_TOGGLE_SPEAKER_DELAY = 1500
910
RADIO_DESTROY_SPEAKER_DELAY = 1500
1011
RADIO_ALLOW_CUSTOM_URLS = true

[gameplay]/internetradio/logic/gui/CRadioGUI.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ local function initializeRadioGUI()
2020
RADIO_GUI["Radio window"] = guiCreateWindow(radioWindowPosX, radioWindowPosY, radioWindowSizeX, radioWindowSizeY, "SPEAKER MUSIC (RADIO/MP3)", false)
2121
RADIO_GUI["Stream URLs gridlist"] = guiCreateGridList(10, 54, 304, 139, false, RADIO_GUI["Radio window"])
2222
RADIO_GUI["Stream URL edit"] = guiCreateEdit(10, 25, 304, 26, "http://stream.antenne.de:80/80er-kulthits", false, RADIO_GUI["Radio window"])
23-
RADIO_GUI["Create speaker button"] = guiCreateButton(10, 200, 150, 30, "CREATE SPEAKER", false, RADIO_GUI["Radio window"])
24-
RADIO_GUI["Destroy speaker button"] = guiCreateButton(162, 200, 150, 30, "DESTROY SPEAKER", false, RADIO_GUI["Radio window"])
25-
RADIO_GUI["Play/pause button"] = guiCreateButton(10, 235, 150, 30, "Play - Pause", false, RADIO_GUI["Radio window"])
26-
RADIO_GUI["Close button"] = guiCreateButton(162, 235, 150, 30, "Close", false, RADIO_GUI["Radio window"])
23+
RADIO_GUI["Volume"] = guiCreateScrollBar(10, 200, 302, 20, true, false, RADIO_GUI["Radio window"])
24+
RADIO_GUI["Create speaker button"] = guiCreateButton(10, 230, 150, 30, "CREATE SPEAKER", false, RADIO_GUI["Radio window"])
25+
RADIO_GUI["Destroy speaker button"] = guiCreateButton(162, 230, 150, 30, "DESTROY SPEAKER", false, RADIO_GUI["Radio window"])
26+
RADIO_GUI["Play/pause button"] = guiCreateButton(10, 265, 150, 30, "Play - Pause", false, RADIO_GUI["Radio window"])
27+
RADIO_GUI["Close button"] = guiCreateButton(162, 265, 150, 30, "Close", false, RADIO_GUI["Radio window"])
2728

2829
RADIO_GUI["Toggle remote speakers checkbox"] = guiCreateCheckBox(15, 345, 180, 17, "Allow other players speakers", allowRemoteSpeakers, false, RADIO_GUI["Radio window"])
2930
RADIO_GUI["Toggle remote speakers label"] = guiCreateLabel(167, 345, 150, 17, "", false, RADIO_GUI["Radio window"])
@@ -33,10 +34,12 @@ local function initializeRadioGUI()
3334
guiEditSetMaxLength(RADIO_GUI["Stream URL edit"], RADIO_STREAM_URL_MAX_LENGTH)
3435
guiWindowSetSizable(RADIO_GUI["Radio window"], false)
3536
guiGridListSetSortingEnabled(RADIO_GUI["Stream URLs gridlist"], false)
37+
guiScrollBarSetScrollPosition(RADIO_GUI["Volume"], 100)
3638

3739
loadRadioStations()
3840

3941
addEventHandler("onClientGUIClick", RADIO_GUI["Stream URLs gridlist"], onClientGUIClickLoadStationStreamURL, false)
42+
addEventHandler("onClientGUIScroll", RADIO_GUI["Volume"], onClientGUIScrollVolume, false)
4043
addEventHandler("onClientGUIClick", RADIO_GUI["Create speaker button"], onClientGUIClickCreateSpeaker, false)
4144
addEventHandler("onClientGUIClick", RADIO_GUI["Play/pause button"], onClientGUIClickToggleSpeaker, false)
4245
addEventHandler("onClientGUIClick", RADIO_GUI["Destroy speaker button"], onClientGUIClickDestroySpeaker, false)

[gameplay]/internetradio/logic/handle_radio/CHandleRadio.lua

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
local speakerSounds = {}
88
local playerSpeakers = {}
9+
local speakerVolumeSyncTimer = false
910

1011
local function getStreamURLFromEdit()
1112
local streamURL = guiGetText(RADIO_GUI["Stream URL edit"])
@@ -46,6 +47,38 @@ local function handleSpeakerOnStreamInOut(speakerElement, toggleOn)
4647
return false
4748
end
4849

50+
local function getLocalSpeakerVolume()
51+
local speakerVolume = guiScrollBarGetScrollPosition(RADIO_GUI["Volume"])
52+
local speakerVolumeValue = (speakerVolume/100)
53+
54+
return speakerVolumeValue
55+
end
56+
57+
local function syncSpeakerVolume()
58+
local speakerVolume = getLocalSpeakerVolume()
59+
60+
triggerServerEvent("onServerSetSpeakerVolume", localPlayer, speakerVolume)
61+
speakerVolumeSyncTimer = false
62+
63+
return true
64+
end
65+
66+
local function requestSpeakerVolumeSync()
67+
local speakerVolume = getLocalSpeakerVolume()
68+
69+
setPlayerSpeakerVolume(localPlayer, speakerVolume) -- set volume locally so localPlayer could adjust it without any delay (this will be sanity corrected by server later on)
70+
71+
if (speakerVolumeSyncTimer) then
72+
resetTimer(speakerVolumeSyncTimer)
73+
else
74+
local speakerTimerInterval = (RADIO_VOLUME_DELAY + 50) -- extra time to let server catch up
75+
76+
speakerVolumeSyncTimer = setTimer(syncSpeakerVolume, speakerTimerInterval, 1)
77+
end
78+
79+
return true
80+
end
81+
4982
function loadRadioStations()
5083
for stationID = 1, #RADIO_STATIONS do
5184
local radioStationData = RADIO_STATIONS[stationID]
@@ -91,6 +124,7 @@ function toggleSpeakerSounds(playerElement, toggleOn)
91124
local speakerDimension = getElementDimension(speakerBox)
92125
local speakerSoundMaxDistance = speakerData.speakerSoundMaxDistance
93126
local speakerStreamURL = speakerData.speakerStreamURL
127+
local speakerVolume = speakerData.speakerVolume
94128
local speakerNewSound = playSound3D(speakerStreamURL, speakerBoxPosX, speakerBoxPosY, speakerBoxPosZ, true, false)
95129

96130
if (not speakerNewSound) then
@@ -106,7 +140,7 @@ function toggleSpeakerSounds(playerElement, toggleOn)
106140

107141
setSoundPaused(speakerNewSound, speakerPaused)
108142
setSoundMaxDistance(speakerNewSound, speakerSoundMaxDistance)
109-
setSoundVolume(speakerNewSound, 1)
143+
setSoundVolume(speakerNewSound, speakerVolume)
110144
attachElements(speakerNewSound, speakerBox)
111145
end
112146

@@ -130,6 +164,7 @@ end
130164

131165
function onClientGUIClickCreateSpeaker()
132166
local streamURL, errorCode = getStreamURLFromEdit()
167+
local speakerVolume = getLocalSpeakerVolume()
133168

134169
if (not streamURL) then
135170
local textToDisplay = errorCode or "SPEAKER: Invalid URL, please check your input!"
@@ -145,7 +180,11 @@ function onClientGUIClickCreateSpeaker()
145180
return false
146181
end
147182

148-
triggerServerEvent("onServerCreateSpeaker", localPlayer, streamURL)
183+
triggerServerEvent("onServerCreateSpeaker", localPlayer, streamURL, speakerVolume)
184+
end
185+
186+
function onClientGUIScrollVolume()
187+
requestSpeakerVolumeSync()
149188
end
150189

151190
function onClientGUIClickToggleSpeaker()
@@ -194,7 +233,7 @@ function setPlayerSpeakerData(playerElement, speakerData)
194233
local speakerBox = speakerData.speakerBox
195234
local speakerDummy = createObject(1337, 0, 0, 3)
196235
local speakerBoxDimension = getElementDimension(speakerBox)
197-
setElementDimension(speakerDummy, speakerBoxDimension)
236+
198237

199238
speakerData.speakerDummy = speakerDummy
200239
playerSpeakers[playerElement] = speakerData
@@ -203,11 +242,25 @@ function setPlayerSpeakerData(playerElement, speakerData)
203242

204243
setElementAlpha(speakerDummy, 0)
205244
setElementCollisionsEnabled(speakerDummy, false)
245+
setElementDimension(speakerDummy, speakerBoxDimension)
206246
attachElements(speakerDummy, speakerBox, -0.32, -0.22, 0.8)
207247

208248
return true
209249
end
210250

251+
function setPlayerSpeakerVolume(playerElement, speakerVolume)
252+
local validElement = isElement(playerElement)
253+
local speakerSound = speakerSounds[playerElement]
254+
255+
if (not validElement or not speakerSound) then
256+
return false
257+
end
258+
259+
setSoundVolume(speakerSound, speakerVolume)
260+
261+
return true
262+
end
263+
211264
function setPlayerSpeakerPaused(playerElement, pauseState)
212265
local playerSpeakerData = getPlayerSpeakerData(playerElement)
213266

@@ -319,6 +372,12 @@ end
319372
addEvent("onClientCreateSpeaker", true)
320373
addEventHandler("onClientCreateSpeaker", root, onClientCreateSpeaker)
321374

375+
function onClientSetSpeakerVolume(speakerVolume)
376+
setPlayerSpeakerVolume(source, speakerVolume)
377+
end
378+
addEvent("onClientSetSpeakerVolume", true)
379+
addEventHandler("onClientSetSpeakerVolume", root, onClientSetSpeakerVolume)
380+
322381
function onClientToggleSpeaker(pauseState)
323382
setPlayerSpeakerPaused(source, pauseState)
324383
end
@@ -339,4 +398,4 @@ function clearSpeakersOnDestroyQuit()
339398
clearPlayerSpeaker(source)
340399
end
341400
addEventHandler("onClientPlayerQuit", root, clearSpeakersOnDestroyQuit)
342-
addEventHandler("onClientElementDestroy", resourceRoot, clearSpeakersOnDestroyQuit)
401+
addEventHandler("onClientElementDestroy", resourceRoot, clearSpeakersOnDestroyQuit)

0 commit comments

Comments
 (0)