-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcl_gfx.lua
294 lines (251 loc) · 9.07 KB
/
cl_gfx.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
-- Golf minigame graphics.
-- @author Elio
-- @version 2.0
-- This file was written thanks to decompiled scripts and (regarding scaleforms) :
-- https://www.vespura.com/fivem/scaleform/
-- https://github.com/DevTestingPizza/FiveMGolf/blob/master/FiveMGolf/Gfx.cs
gfx = {} -- *Static class*
-- Scaleforms stuff
local sHud = nil -- Hole, wind, scoreboard ...
local sFloating = nil -- Ball informations
local sButtons = nil -- Instructional buttons
local sMessage = nil -- Big message
local holeBlip = nil -- Hole blip
-- Camera animation stuff
local holeCam = nil
local holeDict = 'mini@golfhole_preview'
-- @section Classic stuff
-- @desc Draw help text for a frame
-- @param label label of the text
function gfx:helpTextFrame(label)
DisplayHelpTextThisFrame(label, 0)
end
-- @desc Apply options to the specific blip
-- @param blip blip handle
-- @param sprite sprite
-- @param color table = { color, alpha }
-- @param scale scale
-- @param display display type
function gfx:applyBlipOptions(blip, sprite, color, scale, display)
SetBlipSprite(blip, sprite)
SetBlipColour(blip, color[1])
SetBlipAlpha(blip, color[2])
SetBlipScale(blip, scale)
SetBlipDisplay(blip, display)
end
-- @desc Add a blip to a specific location
-- @param pos position
-- @param sprite sprite
-- @param color table = { color, alpha }
-- @param scale scale
-- @param display display type
-- @return blip handle
function gfx:addBlipForPos(pos, sprite, color, scale, display)
local blip = AddBlipForCoord(pos)
gfx:applyBlipOptions(blip, sprite, color, scale, display)
return blip
end
-- @desc Add a blip to a specific entity
-- @param ent entity
-- @param sprite sprite
-- @param color table = { color, alpha }
-- @param scale scale
-- @param display display type
-- @return blip handle
function gfx:addBlipForEntity(ent, sprite, color, scale, display)
local blip = AddBlipForEntity(ent)
gfx:applyBlipOptions(blip, sprite, color, scale, display)
return blip
end
-- @desc Do a screen fade in
-- @param ms milliseconds
function gfx:fadeIn(ms, sync)
DoScreenFadeIn(ms)
if sync then Wait(ms + 100) end
end
-- @desc Do a screen fade out
-- @param ms milliseconds
function gfx:fadeOut(ms, sync)
DoScreenFadeOut(ms)
if sync then Wait(ms + 100) end
end
-- @section Golf specific stuff
-- @desc Initialize the scaleforms
function gfx:init()
-- Scaleform stuff
sHud = Scaleform('GOLF')
sFloating = Scaleform('GOLF_FLOATING_UI')
sButtons = Scaleform('INSTRUCTIONAL_BUTTONS')
sMessage = Scaleform('MIDSIZED_MESSAGE')
-- Camera stuff
holeCam = CreateCamera(964613260, 0)
RequestAnimDict(holeDict)
end
-- @desc Clear everything that was requested
function gfx:clear()
-- Scaleform stuff
sHud:Destroy()
sFloating:Destroy()
sButtons:Destroy()
sMessage:Destroy()
gfx:clearMinimap()
-- Camera stuff
DestroyCam(holeCam, false)
holeCam = nil
end
-- @desc Render the global HUD
function gfx:renderHud()
sHud:Render2D()
end
-- @desc Render the floating UI
function gfx:renderFloatingUI()
sFloating:Render2D()
end
-- @desc Render the instructional buttons
function gfx:renderButtons()
sButtons:Render2D()
end
-- @desc Render the message
function gfx:renderMessage()
sMessage:Render2D()
end
-- @desc Set the display of the UI
-- @param id display identifier
-- -1 = all
-- 0 = nothing
-- 1 = map
-- 2 = top right
-- 3 = top right + map
-- 8 = player list
-- 9 = player list + map
-- 10 = player list + top right
-- 11 = player list + map + top right
-- 16 = scoreboard
-- 17 = scoreboard + map
-- 18 = scoreboard + top right
-- 19 = scoreboard + top right + map
-- 24 = scoreboard + player list
-- 25 = scoreboard + player list + map
-- 26 = scoreboard + player list + top right
-- 27 = scoreboard + player list + top right + map
function gfx:display(id)
sHud:CallFunction('SET_DISPLAY', { id })
end
-- @desc Set the informations of the current shot
-- @param surface surface informations
-- @param wind wind informations
-- @param club club informations
-- @param hole hole informations
function gfx:setSwingDisplay(display, surface, windForce, windDirection, club, shots)
local s = surfaces[surface]
local c = clubs[club]
sHud:CallFunction('SET_SWING_DISPLAY', {
display, -- Display type (47 = display lot of stuff)
{ s.label }, s.icon, -- Surface informations
{ 'GOLF_WIND_PLUS', windForce }, windDirection, -- Wind informations
{ c.label }, c.icon, -- Club informations
{ 'collision_9b95m6d' }, false, -- Power types (not used atm)
{ 'GOLF_SPIN' }, 0, 0.0, -- Ball spin infos (nerver displayed)
{ 'SHOT_NUM', shots }, -- Hole number of shots : IT IS WRONG ATM
})
end
-- @desc Set the informations of the current hole
-- @param id hole number
function gfx:setHoleDisplay(id)
local c = holes[id]
sHud:CallFunction('SET_HOLE_DISPLAY', {
{ 'GOLF_HOLE_NUM', id }, -- Hole number
{ 'GOLF_PAR_NUM', c.par }, -- Hole par
{ 'DIST_METER', c.distance }, -- Hole initial distance
})
end
-- @desc Enable of disable informations of the current swing
-- @param enable toggle
function gfx:enableSwingPreview(enable)
if enable then
sHud:CallFunction("SWING_METER_TRANSITION_IN", {}); -- Display the swing meter
sHud:CallFunction("SWING_METER_POSITION", { 0.6, 0.6, 0.5 }); -- Position of swing meter
else
sHud:CallFunction("SWING_METER_TRANSITION_OUT", { 200 }); -- Remove the swing meter
end
end
-- @desc Set the swing preview informations
-- @param markerPos marker position
-- @param targetPos target position
function gfx:setSwingPreview(markerPos, targetPos)
sHud:CallFunction("SWING_METER_SET_MARKER", { true, markerPos, true, 0.0 }); -- Marker position
sHud:CallFunction("SWING_METER_SET_TARGET", { 0.25, targetPos }); -- Target position
end
-- @desc Set the informations of the current shot
-- @param dist distance of the shot
-- @param distFlag distance from the flag
-- @param strength strength of the shot
-- @param height height of the shot
function gfx:setShotPreview(dist, distFlag, strength, height)
sFloating:CallFunction('SET_SWING_DISTANCE', { { 'PREVIEW_DIST' }, { 'DIST_METER', dist } }) -- Distance shooting
sFloating:CallFunction('SET_PIN_DISTANCE', { { 'PREVIEW_PIN' }, { 'DIST_METER', distFlag } }) -- Distance from the flag
sFloating:CallFunction('SET_STRENGTH', { { 'PREVIEW_PCT' }, { 'STRENGTH_PER', strength } }) -- Force
sFloating:CallFunction('SET_HEIGHT', { { 'PREVIEW_HT' }, { 'DIST_CM', height } }) -- Max height
end
-- @desc Set the current instructional buttons
-- @param buttons buttons to display
function gfx:setButtons(buttons)
sButtons:CallFunction('CLEAR_ALL', {})
local index = 0
for i = 1, #buttons do
local button = buttons[i]
if button.display ~= nil then
sButtons:CallFunction('SET_DATA_SLOT', {
index,
button.display,
button.desc
})
index = index + 1
end
end
sButtons:CallFunction('DRAW_INSTRUCTIONAL_BUTTONS', { -1 })
end
-- @desc Set the minimap hole
-- @param id hole id
function gfx:setMinimapHole(id)
local c = holes[id]
SetRadarZoom(c.mapZoom)
SetMinimapGolfCourse(id)
LockMinimapPosition(c.mapCenter)
LockMinimapAngle(c.mapAngle)
ToggleStealthRadar(false)
if holeBlip ~= nil then RemoveBlip(holeBlip) end
holeBlip = AddBlipForCoord(c.holeCoords)
SetBlipSprite(holeBlip, 358)
end
-- @desc Clear the minimap display
function gfx:clearMinimap()
SetMinimapGolfCourseOff()
UnlockMinimapAngle()
UnlockMinimapPosition()
SetRadarZoom(0)
if holeBlip ~= nil then
RemoveBlip(holeBlip)
holeBlip = nil
end
end
function gfx:playHoleAnim(id, during)
local c = holes[id].anim
gfx:fadeOut(250, true)
PlayCamAnim(holeCam, c.clip, holeDict, -1317.17, 60.494, 53.56, 0.0, 0.0, 0.0, 0, 2)
SetCamActiveWithInterp(holeCam, GetRenderingCam(), c.time, 1, 1)
RenderScriptCams(1, 0, 3000, 1, 0, 0)
gfx:fadeIn(250, false)
local currentTime = GetGameTimer()
local endTime = currentTime + (GetAnimDuration(holeDict, c.clip) * 1000)
while currentTime < endTime do
currentTime = GetGameTimer()
HideHudAndRadarThisFrame()
Wait(0)
end
gfx:fadeOut(250, true)
SetCamActive(holeCam, false)
RenderScriptCams(0, 0, 0, 1, 0, 0)
if during ~= nil then during() end
gfx:fadeIn(250, false)
end