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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
untyped
globalize_all_functions
global const NUM_EOG_CHALLENGE_BOXES = 6
global const WEBBROWSER_FLAG_NONE = 0
global const WEBBROWSER_FLAG_MUTEGAME = 0x0001
function UtilityUI_Init()
{
level.getPersistentVarWrapper <- class
{
function GetPersistentVar( variable )
{
// This looks up the code function GetPersistentVar
return GetPersistentVar( variable )
}
function GetPersistentVarAsInt( string variable )
{
return GetPersistentVarAsInt( variable )
}
}
}
int[2] function GetScreenSize()
{
var screenSize = Hud_GetSize( GetMenu( "MainMenu" ) )
int[2] returnSize
returnSize[0] = expect int( screenSize[0] )
returnSize[1] = expect int( screenSize[1] )
return returnSize
}
float[2] function GetContentScaleFactor( var menu )
{
local screenSize = menu.GetSize()
float screenSizeX = expect int( screenSize[0] ).tofloat()
float screenSizeY = expect int( screenSize[1] ).tofloat()
float aspectRatio = screenSizeX / screenSizeY
float[2] scaleFactor
scaleFactor[0] = screenSizeX / ( 1080.0 * aspectRatio )
scaleFactor[1] = screenSizeY / 1080.0
return scaleFactor
}
float function ContentScaledX( int val )
{
return (val * GetContentScaleFactor( GetMenu( "MainMenu" ) )[0])
}
float function ContentScaledY( int val )
{
return (val * GetContentScaleFactor( GetMenu( "MainMenu" ) )[1])
}
int function ContentScaledXAsInt( int val )
{
float fVal = val * GetContentScaleFactor( GetMenu( "MainMenu" ) )[0]
return int( fVal + 0.5 )
}
int function ContentScaledYAsInt( int val )
{
float fVal = val * GetContentScaleFactor( GetMenu( "MainMenu" ) )[1]
return int( fVal + 0.5 )
}
// Returns string or null
function GetLobbyTeamImage( int team )
{
Assert( IsConnected() )
if ( !GetLobbyTeamsShowAsBalanced() )
return null
if ( GetLobbyTypeScript() == eLobbyType.MATCH || GetLobbyTypeScript() == eLobbyType.PRIVATE_MATCH )
return GetTeamImage( team )
return null
}
// Returns string or null
function GetLobbyTeamName( int team )
{
Assert( IsConnected() )
if ( !GetLobbyTeamsShowAsBalanced() )
return null
if ( GetLobbyTypeScript() == eLobbyType.MATCH || GetLobbyTypeScript() == eLobbyType.PRIVATE_MATCH )
return GetTeamName( team )
return null
}
asset function GetTeamImage( int team )
{
Assert( team == TEAM_IMC || team == TEAM_MILITIA )
if ( team == TEAM_IMC )
return $"ui/scoreboard_imc_logo"
return $"ui/scoreboard_mcorp_logo"
}
function RefreshPersistentFunc( func )
{
for ( int i = 0; i < 5; i++ )
{
// cause who knows when persistent data changes
delaythread( i * 0.1 ) RunFuncWithConnectedCheck( func )
}
}
function RunFuncWithConnectedCheck( func )
{
if ( !IsConnected() )
return
func()
}
string function GetActiveLevel()
{
// The level load callbacks overlap with the level init/shutdown callbacks, so we track each one separately.
if ( uiGlobal.loadedLevel != "" )
return uiGlobal.loadedLevel
return uiGlobal.loadingLevel
}
function HandleLockedMenuItem( menu, button, hideTip = false )
{
/*array<var> elements = GetElementsByClassname( menu, "HideWhenLocked" )
var buttonTooltip = Hud_GetChild( menu, "ButtonTooltip" )
//var buttonTooltip = GetElementsByClassname( menu, "ButtonTooltip" )[0]
var toolTipLabel = Hud_GetChild( buttonTooltip, "Label" )
entity player = GetUIPlayer()
if ( player == null )
return
if ( "ref" in button.s && button.s.ref != null && IsItemLocked( player, expect string( button.s.ref ) ) && !hideTip )
{
foreach( elem in elements )
Hud_Hide( elem )
Hud_SetText( toolTipLabel, "#UNLOCKED_AT_LEVEL", g_unlocks[ expect string( button.s.ref ) ].unlockLevel, "" )
local buttonPos = Hud_GetAbsPos( button )
local buttonHeight = Hud_GetHeight( button )
local tooltipHeight = Hud_GetHeight( buttonTooltip )
local yOffset = ( tooltipHeight - buttonHeight ) / 2.0
Hud_SetPos( buttonTooltip, buttonPos[0] + Hud_GetWidth( button ) * 0.9, buttonPos[1] - yOffset )
Hud_Show( buttonTooltip )
return true
}
else
{
foreach( elem in elements )
Hud_Show( elem )
Hud_Hide( buttonTooltip )
}
return false*/
}
// No way to test a named element exists so this is a workaround
var function GetSingleElementByClassname( var menu, string classname )
{
array<var> elems = GetElementsByClassname( menu, classname )
if ( elems.len() )
{
Assert( elems.len() == 1 )
return elems[0]
}
return null
}
array function GetElementsByClassnameForMenus( string classname, array menus )
{
array elements = []
foreach ( menu in menus )
elements.extend( GetElementsByClassname( menu, classname ) )
return elements
}
function WaitFrameOrUntilLevelLoaded()
{
WaitFrame()
while ( uiGlobal.loadedLevel == "" )
WaitFrame()
}
bool function IsPlayerAlone()
{
int myTeam = GetTeam()
if ( GetTeamSize( myTeam ) <= 1 )
return true
return false
}
bool function PartyHasMembers()
{
if ( GetPartySize() > 1 )
return true
return false
}
bool function AmIPartyMember()
{
return ( PartyHasMembers() && !AmIPartyLeader() )
}
string function GetGameModeDisplayName( string mode )
{
string displayName = GetGamemodeVarOrUseValue( mode, "name", (mode in GAMETYPE_TEXT) ? GAMETYPE_TEXT[mode] : "" )
// modification to support playlists too
if ( displayName == "" )
return GetPlaylistVarOrUseValue( mode, "name", "" )
return displayName
}
string function GetGameModeDisplayDesc( string mode ) //TODO: Make this support attack/defend descriptions
{
string displayDesc = GetGamemodeVarOrUseValue( mode, "description", (mode in GAMETYPE_DESC) ? GAMETYPE_DESC[mode] : "" )
// modification to support playlists too
if ( displayDesc == "" )
{
displayDesc = Localize( GetPlaylistVarOrUseValue( mode, "description", "" ) )
if ( displayDesc.find( "^" ) != null )
displayDesc = displayDesc.slice( 0, displayDesc.find( "^" ) )
}
return displayDesc
}
string function GetGameModeDisplayHint( string mode ) //TODO: Make this support attack/defend descriptions
{
string displayDesc = GetGamemodeVarOrUseValue( mode, "hint", GetGameModeDisplayDesc( mode ) )
return displayDesc
}
asset function GetGameModeDisplayImage( string mode )
{
return GAMETYPE_ICON[ mode ]
}
array<int> function ColorStringToArray( string colorString )
{
array<string> tokens = split( colorString, " " )
Assert( tokens.len() >= 3 && tokens.len() <= 4 )
array<int> colorArray
foreach ( token in tokens )
colorArray.append( int( token ) )
return colorArray
}
array<int> function GetGameModeDisplayColor( string mode )
{
array<int> displayColor = ColorStringToArray( GetGamemodeVarOrUseValue( mode, "color", "" ) )
if ( displayColor.len() == 0 )
displayColor = GameMode_GetColor( mode )
return displayColor
}
float function GetCurrentPlaylistVarFloat( val, useVal )
{
expect string( val )
expect float( useVal )
local result = GetCurrentPlaylistVarOrUseValue( val, useVal )
if ( result == null )
return 0.0
return float( result )
}
// ???: player not used
bool function PlayerProgressionAllowed( player = null )
{
if ( IsPrivateMatch() )
return false
return true
}
entity function GetUIPlayer()
{
if ( !IsFullyConnected() )
return null
return GetLocalClientPlayer()
}
int function GetLobbyTypeScript()
{
if ( GetLobbyType() == "game" )
{
if ( IsPrivateMatch() )
return eLobbyType.PRIVATE_MATCH
else
return eLobbyType.MATCH
}
else
{
if ( AmIPartyLeader() )
{
if ( IsPlayerAlone() ) // TODO: This function was changed to only check your team size, not the true player count, so you'll probably now have access to some menus you shouldn't be able to.
return eLobbyType.SOLO
else
return eLobbyType.PARTY_LEADER
}
else
{
return eLobbyType.PARTY_MEMBER
}
}
unreachable
}
function AddMenu( blockName, asset resourceFile, void functionref() initFunc = null, string displayName = "" )
{
local menu = CreateMenu( "menu_" + blockName, resourceFile )
uiGlobal.menus[blockName] <- menu
menu.SetHudName( blockName )
if ( displayName != "" )
menu.SetDisplayName( displayName )
else
menu.SetDisplayName( blockName )
uiGlobal.allMenus.append( menu )
MenuDef defaultMenuData
uiGlobal.menuData[ menu ] <- defaultMenuData
if ( initFunc != null )
uiGlobal.menuData[ menu ].initFunc = initFunc
return menu
}
function AddMenu_WithCreateFunc( blockName, asset resourceFile, void functionref() initFunc, createMenuFunc )
{
local menu = createMenuFunc( "menu_" + blockName, resourceFile )
uiGlobal.menus[blockName] <- menu
menu.SetHudName( blockName )
uiGlobal.allMenus.append( menu )
MenuDef defaultMenuData
uiGlobal.menuData[ menu ] <- defaultMenuData
if ( initFunc != null )
uiGlobal.menuData[ menu ].initFunc = initFunc
return menu
}
function AddPanel( var menu, string panelName, void functionref() initFunc = null )
{
//printt( "AddPanel called, panelName:", panelName )
var panel = Hud_GetChild( menu, panelName )
uiGlobal.panels[ panelName ] <- panel
uiGlobal.allPanels.append( panel )
PanelDef defaultPanelData
uiGlobal.panelData[ panel ] <- defaultPanelData
if ( initFunc != null )
uiGlobal.panelData[ panel ].initFunc = initFunc
return panel
}
function AddSubmenu( blockName, asset resourceFile, void functionref() initFunc = null )
{
local menu = CreateMenu( "menu_" + blockName, resourceFile )
uiGlobal.menus[blockName] <- menu
menu.SetHudName( blockName )
menu.SetType( "submenu" )
menu.s.newFocusRef <- null
uiGlobal.allMenus.append( menu )
MenuDef defaultMenuData
uiGlobal.menuData[ menu ] <- defaultMenuData
if ( initFunc != null )
uiGlobal.menuData[ menu ].initFunc = initFunc
return menu
}
function ClearButton( button )
{
Hud_SetText( button, "" )
Hud_SetEnabled( button, false )
Hud_SetLocked( button, false )
Hud_SetNew( button, false )
Hud_SetSelected( button, false )
}
void function HudElem_SetText( var hudelem, string text )
{
hudelem.SetText( text )
}
void function SetButtonRuiText( var elem, string text )
{
var rui = Hud_GetRui( elem )
RuiSetString( rui, "buttonText", text )
}
void function SetLabelRuiText( var elem, string text )
{
var rui = Hud_GetRui( elem )
RuiSetString( rui, "labelText", text )
}
void function SetNamedRuiText( var elem, string name, string text )
{
var rui = Hud_GetRui( elem )
RuiSetString( rui, name, text )
}
void function SetNamedRuiBool( var elem, string name, bool state )
{
var rui = Hud_GetRui( elem )
RuiSetBool( rui, name, state )
}
void function SetNamedRuiImage( var elem, string name, asset assetName )
{
var rui = Hud_GetRui( elem )
RuiSetImage( rui, name, assetName )
}
// Should be using Hud_GetChild() instead of this
var function GetMenuChild( var elem, string name )
{
return elem.GetChild( name )
}
bool function IsWeaponButton( var button )
{
array<var> weaponButtons = GetElementsByClassname( GetParentMenu( button ), "WeaponSelectClass" )
foreach ( weaponButton in weaponButtons )
{
if ( button == weaponButton )
return true
}
return false
}
void function SetPanelTabTitle( var panel, string title )
{
uiGlobal.panelData[ panel ].tabTitle = title
}
string function GetPanelTabTitle( var panel )
{
return uiGlobal.panelData[ panel ].tabTitle
}
void function ScriptCallback_UnlockAchievement( int achievementID )
{
Assert( achievementID > 0 && achievementID < achievements.MAX_ACHIVEMENTS, "Tried to unlock achievement with invalid enum value" )
#if DEV
string ref
foreach( string _ref, int val in achievements )
{
if ( val != achievementID )
continue
ref = _ref
break
}
printt( "#############################################" )
printt( "UNLOCKED ACHIEVEMENT:", ref, "(" + achievementID + ")" )
printt( "#############################################" )
#endif //DEV
if ( Script_IsRunningTrialVersion() )
{
printt( "Achievements not awarded in trial version" )
return
}
Plat_UnlockAchievementByID( achievementID )
}
void function TryUnlockCollectiblesAchievement()
{
int totalLionsCollectedForGame = GetTotalLionsCollected()
if ( totalLionsCollectedForGame >= GetTotalLionsInGame() )
ScriptCallback_UnlockAchievement( achievements.COLLECTIBLES_3 )
if ( totalLionsCollectedForGame >= ACHIEVEMENT_COLLECTIBLES_2_COUNT )
ScriptCallback_UnlockAchievement( achievements.COLLECTIBLES_2 )
if ( totalLionsCollectedForGame >= ACHIEVEMENT_COLLECTIBLES_1_COUNT )
ScriptCallback_UnlockAchievement( achievements.COLLECTIBLES_1 )
}
void function TryUnlockCompletedGameAchievements()
{
if ( Script_IsRunningTrialVersion() )
return
var dataTable = GetDataTable( $"datatable/sp_levels.rpak" )
int numRows = GetDatatableRowCount( dataTable )
// Check Completed All Levels Achievement
int normalCompleted = 0
int hardCompleted = 0
int masterCompleted = 0
for ( int i=0; i<numRows; i++ )
{
int levelNum = GetDataTableInt( dataTable, i, GetDataTableColumnByName( dataTable, "levelNum" ) )
// always count training as master completed
if ( GetCompletedDifficultyForBSPNum( i, "sp_missionMasterCompletion" ) || levelNum == 0 )
masterCompleted++
if ( GetCompletedDifficultyForBSPNum( i, "sp_missionHardCompletion" ) || levelNum == 0 )
hardCompleted++
if ( GetCompletedDifficultyForBSPNum( i, "sp_missionNormalCompletion" ) || levelNum == 0 )
normalCompleted++
}
if ( normalCompleted >= numRows )
ScriptCallback_UnlockAchievement( achievements.COMPLETE_NORMAL )
if ( hardCompleted >= numRows )
ScriptCallback_UnlockAchievement( achievements.COMPLETE_HARD )
if ( masterCompleted >= numRows )
ScriptCallback_UnlockAchievement( achievements.COMPLETE_MASTER )
}
void function PopUpOriginOverlayDisabledDialog()
{
DialogData dialogData
dialogData.header = "#ORIGIN_OVERLAY_DISABLED"
AddDialogButton( dialogData, "#OK" )
OpenDialog( dialogData )
}
void function PrintPartyData()
{
Party partyData = GetParty()
printt( "PARTY DATA:" )
if ( partyData.numSlots == 0 )
{
printt( " INVALID, numSlots: 0" )
return
}
printt( " partyType: ", partyData.partyType )
printt( " playlistName: ", partyData.playlistName )
printt( " originatorName: ", partyData.originatorName )
printt( " originatorUID: ", partyData.originatorUID )
printt( " numSlots: ", partyData.numSlots )
printt( " numClaimedSlots:", partyData.numClaimedSlots )
printt( " numFreeSlots: ", partyData.numFreeSlots )
printt( " timeLeft: ", partyData.timeLeft )
printt( " amIInThis: ", partyData.amIInThis )
printt( " amILeader: ", partyData.amILeader )
printt( " searching: ", partyData.searching )
print( " members: " )
foreach ( index, member in partyData.members )
{
if ( index != 0 )
print( " " )
printt( member.name, "uid:", member.uid, "callsignIdx:", member.callsignIdx, "skillMu:", member.skillMu )
}
}
void function PlayVideoFullScreen( string video, bool showCaptions = false )
{
PlayVideo( video, 0, 0, 0, 0, showCaptions )
}
void function PlayVideoUsingPanelRect( string video, var panel )
{
int xPos = Hud_GetX( panel )
int yPos = Hud_GetY( panel )
int width = Hud_GetWidth( panel )
int height = Hud_GetHeight( panel )
PlayVideo( video, xPos, yPos, width, height, false )
}
void function Hud_SetNavUp( var buttonFrom, var buttonTo )
{
buttonFrom.SetNavUp( buttonTo )
}
void function Hud_SetNavDown( var buttonFrom, var buttonTo )
{
buttonFrom.SetNavDown( buttonTo )
}
|