aboutsummaryrefslogtreecommitdiff
path: root/bobthebob.testing/scripts/vscripts/ui/menu_team_titan_select.nut
blob: d0ee5f0f64b81ceac925c084cf4c32bad15d30bd (plain)
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
global function InitTeamTitanSelectMenu
global function TeamTitanSelectMenuIsOpen
global function ServerCallback_OpenTeamTitanMenu
global function ServerCallback_CloseTeamTitanMenu
global function ServerCallback_UpdateTeamTitanMenuTime
global function ServerCallback_RegisterTeamTitanMenuButtons
global function TTSUpdateDoubleXP
global function TTSUpdateDoubleXPStatus
global function TTSMenuModeFD
global function TTSMenuModeDefault
global function TTSMenu_UpdateGameMode
global function EnableDoubleXP

const float SELECT_DELAY = 0.2

enum eTTSMenuMode
{
	DEFAULT,
	FD
}

struct
{
	var menu
	bool allowManualClose = false
	bool isReady = false
	bool menuOpened = false
	bool allowSelection = false

	array<var> titanButtons
	array<var> titanUpgradeButtons
	var editButton
	var readyPanel
	var cover
	var doubleXPButton
	var chatBox

	bool buttonsRegistered = false

	int menuMode

	float nextAllowSoundTime = 0.0
} file

void function InitTeamTitanSelectMenu()
{
	file.menu = GetMenu( "TeamTitanSelectMenu" )

	AddMenuEventHandler( file.menu, eUIEvent.MENU_NAVIGATE_BACK, OnTeamTitanSelectMenu_NavigateBack )
	AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnTeamTitanSelectMenu_Open )
	AddMenuEventHandler( file.menu, eUIEvent.MENU_SHOW, OnTeamTitanSelectMenu_Open )
	AddMenuEventHandler( file.menu, eUIEvent.MENU_HIDE, OnTeamTitanSelectMenu_Hide )
	AddMenuEventHandler( file.menu, eUIEvent.MENU_CLOSE, OnTeamTitanSelectMenu_Close )

	RegisterSignal( "TTSMenuClosed" )
	RegisterSignal( "Delayed_RequestTitanLoadout" )

	float margin = 10.0
	float totalWidth = 0.0
	for ( int i=0; i<NUM_PERSISTENT_TITAN_LOADOUTS; i++ )
	{
		var button = Hud_GetChild( file.menu, "TitanButton" + i )
		file.titanButtons.append( button )
		float xPos = totalWidth * -1
		totalWidth += Hud_GetWidth( button ) + margin
		Hud_SetPos( button, xPos, Hud_GetY( button ) )
	}

	var bg = Hud_GetChild( file.menu, "BG" )
	totalWidth -= margin
	float bgWidth = float( Hud_GetWidth( bg ) )
	float startPos = (bgWidth*0.5 - totalWidth*0.5) * -1
	for ( int i=0; i<NUM_PERSISTENT_TITAN_LOADOUTS; i++ )
	{
		var button = file.titanButtons[i]
		Hud_SetPos( button, startPos + Hud_GetX( button ), Hud_GetY( button ) )

		Hud_AddEventHandler( button, UIE_CLICK, TitanButton_OnClick )
		Hud_AddEventHandler( button, UIE_GET_FOCUS, TitanButton_OnFocused )
	}

	for ( int i=0; i<7; i++ )
	{
		var button = Hud_GetChild( file.menu, "BtnSub" + i )

		Hud_AddEventHandler( button, UIE_LOSE_FOCUS, TitanUpgradeButton_OnLoseFocus )
		Hud_AddEventHandler( button, UIE_GET_FOCUS, TitanUpgradeButton_OnFocused )
	}

	SetNavLeftRight( file.titanButtons, true )

	//file.editButton = Hud_GetChild( file.menu, "EditTitanButton" )
	//Hud_AddEventHandler( file.editButton, UIE_CLICK, EditTitanButton_OnClick )
	file.readyPanel = Hud_GetChild( file.menu, "ReadyRui" )
	file.cover = Hud_GetChild( file.menu, "Cover" )

	#if PC_PROG
	file.chatBox = Hud_GetChild( file.menu, "LobbyChatBox" )
	#endif // PC_PROG

	file.doubleXPButton = Hud_GetChild( file.menu, "DoubleXP" )

	AddMenuFooterOption( file.menu, BUTTON_A, "#A_BUTTON_SELECT", "", null, TeamTitanSelect_IsNotReady )
	AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
	AddMenuFooterOption( file.menu, BUTTON_X, "#MENU_X_BUTTON_EDIT_TITAN", "#MENU_EDIT_TITAN", EditTitanButton_OnClick, TeamTitanSelect_IsReady )
	AddMenuFooterOption( file.menu, BUTTON_Y, "#MENU_Y_BUTTON_EDIT_PILOT", "#MENU_EDIT_PILOT", EditPilotButton_OnClick, CoverIsOff )
}

void function TTSUpdateDoubleXP( int count, bool avialable, float status )
{
	var rui = Hud_GetRui( file.doubleXPButton )
	RuiSetInt( rui, "doubleXPCount", count )
	RuiSetBool( rui, "doubleXPAvailable", avialable )
	RuiSetFloat( rui, "doubleXPStatus", status )
}

void function TTSUpdateDoubleXPStatus( int status )
{
	var rui = Hud_GetRui( file.doubleXPButton )
	RuiSetFloat( rui, "doubleXPStatus", float( status ) )
}

void function ServerCallback_UpdateTeamTitanMenuTime( float endTime )
{
	Signal( uiGlobal.signalDummy, "TTSMenuClosed" )

	file.allowSelection = true

	if ( file.nextAllowSoundTime < Time() )
	{
		EmitUISound( "ui_ctf_1p_playerscore" )
		file.nextAllowSoundTime = Time() + 5.0
	}

	Hud_SetEnabled( file.cover, false )
	Hud_Hide( file.cover )
	Hud_SetAlpha( file.cover, 0 )

	if ( endTime > 5 )
		file.allowSelection = true

	thread UpdateSubText( Time() + endTime )
}

void function ServerCallback_OpenTeamTitanMenu( float endTime )
{
	if ( TeamTitanSelectMenuIsOpen() )
		return

	if ( uiGlobal.activeMenu != null )
		CloseAllMenus()

	RunClientScript( "PlayTTSMusic" )

	file.allowManualClose = false
	file.allowSelection = true
	file.isReady = true // set to true so selection mode kicks in
	thread MenuFadeIn()
	BeginSelectionMode()
	AdvanceMenu( file.menu )
	thread UpdateSubText( Time() + endTime )
}

void function MenuFadeIn()
{
	Hud_SetEnabled( file.cover, true )
	Hud_SetAlpha( file.cover, 255 )
	Hud_Show( file.cover )
	wait 1.0
	Hud_FadeOverTime( file.cover, 0, 1.0 )
	wait 1.0
	Hud_Hide( file.cover )
	Hud_SetEnabled( file.cover, false )
}

void function UpdateSubText( float endTime )
{
	EndSignal( uiGlobal.signalDummy, "TTSMenuClosed" )

	var subText = Hud_GetChild( file.menu, "MenuSubTitle" )
	var rui = Hud_GetRui( file.readyPanel )
	RuiSetBool( rui, "isReady", true )

	thread Countdown( endTime )
	while ( Time() < endTime )
	{
		int countdownTime = int( ceil( endTime - Time() ) )
		Hud_SetText( subText, Localize( "#MENU_STARTS_IN", countdownTime ) )
		RuiSetInt( rui, "timer", countdownTime )
		WaitFrame()
	}

	Hud_SetText( subText, Localize( "#MENU_STARTS_IN", 0 ) )
	RuiSetInt( rui, "timer", 0 )
}

void function Countdown( float endTime )
{
	EndSignal( uiGlobal.signalDummy, "TTSMenuClosed" )

	float countdownTime = 5.0
	float startCountdownTime = endTime - countdownTime

	if ( Time() > startCountdownTime )
		return

	wait startCountdownTime - Time()

	while ( Time() < endTime )
	{
		EmitUISound( "UI_InGame_MarkedForDeath_CountdownToMarked" )
		wait 1.0
	}

	file.allowSelection = false
	BeginEditMode(null)

	Hud_SetAlpha( file.cover, 0 )
	Hud_SetEnabled( file.cover, true )
	Hud_Show( file.cover )
	Hud_FadeOverTime( file.cover, 255, 1.0 )

	float soundTime = DoPrematchWarpSound() ? PICK_LOADOUT_SOUND_TIME : 1.5
	wait soundTime

	thread ServerCallback_CloseTeamTitanMenu()
}

void function ServerCallback_CloseTeamTitanMenu()
{
	if ( TeamTitanSelectMenuIsOpen() )
	{
		file.allowManualClose = true
		UI_SetPresentationType( ePresentationType.INACTIVE )
		CloseAllMenus()
		OnTeamTitanSelectMenu_Close()
	}
}

void function OnTeamTitanSelectMenu_NavigateBack()
{
	if ( file.allowManualClose )
	{
		CloseActiveMenu()
		return
	}

	if ( file.isReady && file.allowSelection )
	{
		BeginSelectionMode()
		return
	}

	LeaveDialog()
	return
}

void function TTSMenu_UpdateGameMode( string modeName )
{
	var title = Hud_GetChild( file.menu, "MenuTitle" )
	Hud_SetText( title, Localize( modeName ) )
}

void function ServerCallback_RegisterTeamTitanMenuButtons()
{
	RegisterButtonCallbacks()
}

void function RegisterButtonCallbacks()
{
	if ( file.buttonsRegistered )
		return

	file.buttonsRegistered = true
	RegisterButtonPressedCallback( BUTTON_BACK, EnableDoubleXP )
	RegisterButtonPressedCallback( KEY_RSHIFT, EnableDoubleXP )
}

void function OnTeamTitanSelectMenu_Open()
{
	file.menuOpened = true

	var dataTable = GetDataTable( $"datatable/titan_properties.rpak" )
	int loadoutIconCol = GetDataTableColumnByName( dataTable, "loadoutIconFD" )
	int titanCol = GetDataTableColumnByName( dataTable, "titanRef" )

	entity player = GetUIPlayer()

	var nextMapImage = Hud_GetChild( file.menu, "NextMapImage" )
	string mapName = GetActiveLevel()
	asset mapImage = GetMapImageForMapName( mapName )

	RefreshCreditsAvailable()

	RuiSetImage( Hud_GetRui( nextMapImage ), "basicImage", mapImage )
	Hud_Show( nextMapImage )
	Hud_SetText( Hud_GetChild( file.menu, "NextMapName" ), GetMapDisplayName( mapName ) )
	Hud_Show( Hud_GetChild( file.menu, "NextMapName" ) )

	var buttonToFocus

	for ( int i=0; i<NUM_PERSISTENT_TITAN_LOADOUTS; i++ )
	{
		var button = file.titanButtons[i]
		TitanLoadoutDef loadout = GetCachedTitanLoadout( i )
		int row = GetDataTableRowMatchingStringValue( dataTable, titanCol,  loadout.titanClass )

		asset icon = GetDataTableAsset( dataTable, row, loadoutIconCol )
		var rui = Hud_GetRui( button )

		RuiSetImage( rui, "buttonImage", icon )
		Hud_SetLocked( button, true )

		if ( !IsTitanLoadoutAvailable( player, loadout.titanClass ) )
		{
			Hud_SetLocked( button, true )
			if ( !IsItemLocked( player, loadout.titanClass ) )
				RefreshButtonCost( button, loadout.titanClass, "", 0, 0 )
		}
		else
		{
			Hud_SetLocked( button, IsItemLocked( player, loadout.titanClass ) )
			RefreshButtonCost( button, loadout.titanClass )

			if ( uiGlobal.titanSpawnLoadoutIndex == i )
			{
				buttonToFocus = button
			}
		}
	}

	if ( buttonToFocus == null )
		buttonToFocus = FindValidTitanButton()
	thread HACK_DelayedSetFocus_BecauseWhy( buttonToFocus )

	TitanLoadoutDef loadout = GetCachedTitanLoadout( uiGlobal.titanSpawnLoadoutIndex )

	for ( int i=0; i<7; i++ )
	{
		var button = Hud_GetChild( file.menu, "BtnSub"+i )
		file.titanUpgradeButtons.append( button )

		if ( file.menuMode == eTTSMenuMode.FD )
		{
			Hud_Show( button )
		}
		else
		{
			Hud_Hide( button )
		}
	}
	SetNavLeftRight( file.titanUpgradeButtons, true )

	SetBlurEnabled( false )
	var title = Hud_GetChild( file.menu, "MenuTitle" )
	string name = expect string( GetCurrentPlaylistVar( "name" ) )
	Hud_SetText( title, Localize( name ) )
	RunMenuClientFunction( "ShowTTSPanel" )

	if ( file.isReady )
		UI_SetPresentationType( ePresentationType.STORE_CAMO_PACKS )
	else
		UI_SetPresentationType( ePresentationType.STORE_CAMO_PACKS )


	RunClientScript( "TTS_UpdateLocalPlayerTitan", loadout.setFile, loadout.primary, loadout.passive1, loadout.passive2 )
}

void function EnableDoubleXP( var button )
{
	#if PC_PROG
	if ( Hud_IsFocused( file.chatBox ) )
		return
	#endif // PC_PROG

	if ( CanRunClientScript() )
	{
		EmitUISound( "Menu_Email_Sent" )
		RunClientScript( "UseDoubleXP" )
	}
}

void function OnTeamTitanSelectMenu_Hide()
{
	RunMenuClientFunction( "HideTTSPanel" )

	DeregisterButtonCallbacks()
}

void function DeregisterButtonCallbacks()
{
	if ( !file.buttonsRegistered )
		return

	file.buttonsRegistered = false

	DeregisterButtonPressedCallback( BUTTON_BACK, EnableDoubleXP )
	DeregisterButtonPressedCallback( KEY_RSHIFT, EnableDoubleXP )
}

void function OnTeamTitanSelectMenu_Close()
{
	RunMenuClientFunction( "ClearAllPilotPreview" )
	Signal( uiGlobal.signalDummy, "TTSMenuClosed" )
	file.menuOpened = false
	UI_SetPresentationType( ePresentationType.INACTIVE )

	DeregisterButtonCallbacks()
}

void function TitanButton_OnClick( var button )
{
	int scriptID = int( Hud_GetScriptID( button ) )
	if ( Hud_IsLocked( button ) )
	{
		TitanLoadoutDef loadout = GetCachedTitanLoadout( scriptID )
		if ( !IsTitanLoadoutAvailable( GetUIPlayer(), loadout.titanClass ) )
			return

		OpenBuyItemDialog( file.titanButtons, button, GetItemName( loadout.titanClass ), loadout.titanClass )
		return
	}

	if ( file.isReady )
	{
		BeginSelectionMode()
		return
	}

	uiGlobal.titanSpawnLoadoutIndex = scriptID
	Signal( uiGlobal.signalDummy, "Delayed_RequestTitanLoadout" )
	ClientCommand( "RequestTitanLoadout " + uiGlobal.titanSpawnLoadoutIndex )
	BeginEditMode( button )
}

void function TitanButton_OnFocused( var button )
{
	int scriptID = int( Hud_GetScriptID( button ) )

	var rui = Hud_GetRui( Hud_GetChild( file.menu, "TitanName" ) )

	TitanLoadoutDef loadout = GetCachedTitanLoadout( scriptID )

	RuiSetString( rui, "titanName", GetTitanLoadoutName( loadout ) )
	RuiSetString( rui, "titanLevelString", "" )
	RuiSetString( rui, "titanRole", "" )

	entity player = GetUIPlayer()

	var dataTable = GetDataTable( $"datatable/titan_properties.rpak" )
	int row = GetDataTableRowMatchingStringValue( dataTable, GetDataTableColumnByName( dataTable, "titanRef" ), loadout.titanClass )
	string role = GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, "fdRole" ) )
	int titanLevel = FD_TitanGetLevelForXP( loadout.titanClass, FD_TitanGetXP( GetUIPlayer(), loadout.titanClass ) )
	array<ItemDisplayData> titanUpgrades = FD_GetUpgradesForTitanClass( loadout.titanClass )

	if ( file.menuMode == eTTSMenuMode.FD )
	{
		RuiSetString( rui, "titanLevelString", Localize( "#FD_TITAN_LEVEL", titanLevel ) )
		RuiSetString( rui, "titanRole", Localize( "#FD_ROLE", Localize(role) ) )

		foreach ( index, item in titanUpgrades )
		{
			var button = file.titanUpgradeButtons[index]
			var upgradeRui = Hud_GetRui( button )

			bool locked = IsSubItemLocked( GetUIPlayer(), item.ref, item.parentRef )

			if ( locked )
				RuiSetImage( upgradeRui, "buttonImage", expect asset( item.i.lockedImage ) )
			else
				RuiSetImage( upgradeRui, "buttonImage", item.image )

			Hud_SetLocked( button, locked )
		}
	}

	if ( !Hud_IsLocked( button ) )
	{
		uiGlobal.titanSpawnLoadoutIndex = scriptID
		thread Delayed_RequestTitanLoadout( uiGlobal.titanSpawnLoadoutIndex )
		SetLabelRuiText( Hud_GetChild( file.menu, "TitanSelectTitle" ), "#MENU_TITAN_SELECT" )
	}
	else
	{
		RuiSetString( rui, "titanLevelString", GetItemUnlockReqText( loadout.titanClass ) )
	}

	SetLabelRuiText( Hud_GetChild( file.menu, "TitanSelectTitle" ), GetTitanAvailableText( player, loadout.titanClass) )

	RunMenuClientFunction( "UpdateTitanModel", scriptID )
	RunClientScript( "TTS_UpdateLocalPlayerTitan", loadout.setFile, loadout.primary, loadout.passive1, loadout.passive2 )
}

string function GetTitanAvailableText( entity player, string titanClass )
{
	int titanAvailableState = GetTitanLoadAvailableState( player, titanClass )

	if ( titanAvailableState == TITAN_CLASS_LOCK_STATE_AVAILABLE )
		return "#MENU_TITAN_SELECT_HINT"

	if ( titanAvailableState == TITAN_CLASS_LOCK_STATE_LEVELREQUIRED || titanAvailableState == TITAN_CLASS_LOCK_STATE_LEVELRECOMMENDED )
	{
		int difficultyLevel = GetCurrentPlaylistVarInt( "fd_difficulty", 0 )
		int requiredTitanLevel = 0
		switch ( difficultyLevel )
		{
			case eFDDifficultyLevel.EASY:
				if ( GetItemUnlockType( "fd_easy" ) == eUnlockType.STAT )
					requiredTitanLevel = int( GetStatUnlockStatVal( "fd_easy" ) )
				break
			case eFDDifficultyLevel.NORMAL:
				if ( GetItemUnlockType( "fd_normal" ) == eUnlockType.STAT )
					requiredTitanLevel = int( GetStatUnlockStatVal( "fd_normal" ) )
				break
			case eFDDifficultyLevel.HARD:
				if ( GetItemUnlockType( "fd_hard" ) == eUnlockType.STAT )
					requiredTitanLevel = int( GetStatUnlockStatVal( "fd_hard" ) )
				break
			case eFDDifficultyLevel.MASTER:
				if ( GetItemUnlockType( "fd_master" ) == eUnlockType.STAT )
					requiredTitanLevel = int( GetStatUnlockStatVal( "fd_master" ) )
				break
			case eFDDifficultyLevel.INSANE:
				if ( GetItemUnlockType( "fd_insane" ) == eUnlockType.STAT )
					requiredTitanLevel = int( GetStatUnlockStatVal( "fd_insane" ) )
				break
		}

		if ( titanAvailableState == TITAN_CLASS_LOCK_STATE_LEVELREQUIRED )
			return Localize( "#MENU_TITAN_SELECT_LEVELREQUIRED", requiredTitanLevel )
		else
			return Localize( "#MENU_TITAN_SELECT_LEVELRECOMMENDED", requiredTitanLevel )
	}

	if ( titanAvailableState == TITAN_CLASS_LOCK_STATE_INUSE )
		return "#MENU_TITAN_SELECT_INUSE"

	if ( titanAvailableState == TITAN_CLASS_LOCK_STATE_LOCKED )
		return "#MENU_TITAN_SELECT_LOCKED"

	return "#MENU_TITAN_SELECT_HINT"
}

void function Delayed_RequestTitanLoadout( int index )
{
	Signal( uiGlobal.signalDummy, "Delayed_RequestTitanLoadout" )
	EndSignal( uiGlobal.signalDummy, "Delayed_RequestTitanLoadout" )
	wait 0.5
	ClientCommand( "RequestTitanLoadout " + uiGlobal.titanSpawnLoadoutIndex )
}

void function TitanUpgradeButton_OnFocused( var button )
{
	if ( file.menuMode == eTTSMenuMode.DEFAULT )
		return

	int scriptID = int( Hud_GetScriptID( button ) )
	TitanLoadoutDef loadout = GetCachedTitanLoadout( uiGlobal.titanSpawnLoadoutIndex )
	array<ItemDisplayData> titanUpgrades = FD_GetUpgradesForTitanClass( loadout.titanClass )

	ItemDisplayData item = titanUpgrades[ scriptID ]
	var panel = Hud_GetChild( file.menu, "UpgradeName" )
	Hud_Show( panel )
	var rui = Hud_GetRui( panel )
	RuiSetString( rui, "upgradeName", item.name )
	RuiSetString( rui, "upgradeDesc", item.desc )
	RuiSetBool( rui, "isLocked", IsSubItemLocked( GetUIPlayer(), item.ref, item.parentRef ) )
}

void function TitanUpgradeButton_OnLoseFocus( var button )
{
	Hud_Hide( Hud_GetChild( file.menu, "UpgradeName" ) )
}

void function BeginEditMode( var button )
{
	if ( file.isReady )
		return

	file.isReady = true

	EmitUISound( "UI_InGame_FD_TitanSelected" )
	SetLabelRuiText( Hud_GetChild( file.menu, "TitanSelectTitle" ), "#MENU_TITAN_SELECTED" )
	Hud_Hide( Hud_GetChild( file.menu, "TitanSelectTitle" ) )
	Hud_Show( file.readyPanel )
	var rui = Hud_GetRui( file.readyPanel )
	RuiSetBool( rui, "isReady", true )

	foreach ( b in file.titanButtons )
	{
		Hud_Hide( b )
	}

	//Hud_Show( file.editButton )
	//Hud_SetFocused( file.editButton )
	Hud_SetFocused( file.titanUpgradeButtons[0] )

	TitanLoadoutDef loadout = GetCachedTitanLoadout( uiGlobal.titanSpawnLoadoutIndex )
	string primeTitanString = ""

	if ( loadout.isPrime == "titan_is_prime" )
		primeTitanString = "_prime"

	string modifiedAlias = "diag_gs_titan" + loadout.titanClass + primeTitanString + "_embark"
	EmitUISound( modifiedAlias )

	if ( uiGlobal.activeMenu == file.menu )
		UI_SetPresentationType( ePresentationType.TITAN_CENTER_SELECTED )

	Signal( uiGlobal.signalDummy, "Delayed_RequestTitanLoadout" )
	ClientCommand( "RequestTitanLoadout " + uiGlobal.titanSpawnLoadoutIndex )
	RunMenuClientFunction( "UpdateTitanModel", uiGlobal.titanSpawnLoadoutIndex )

	var subText = Hud_GetChild( file.menu, "MenuSubTitle" )
	// Hud_Hide( subText )
}

void function BeginSelectionMode()
{
	if ( !file.isReady )
		return

	file.isReady = false
	//Hud_Hide( file.editButton )

	SetLabelRuiText( Hud_GetChild( file.menu, "TitanSelectTitle" ), "#MENU_TITAN_SELECT_HINT" )
	Hud_Show( Hud_GetChild( file.menu, "TitanSelectTitle" ) )
	Hud_Hide( file.readyPanel )
	var rui = Hud_GetRui( file.readyPanel )
	RuiSetBool( rui, "isReady", false )

	Hud_SetFocused( FindValidTitanButton() )

	for ( int i=0; i<file.titanButtons.len(); i++ )
	{
		var b = file.titanButtons[i]
		Hud_Show( b )
		if ( i == uiGlobal.titanSpawnLoadoutIndex && !Hud_IsLocked( b ) )
		{
			Hud_SetFocused( b )
		}
	}

	Hud_Hide( Hud_GetChild( file.menu, "UpgradeName" ) )

	UI_SetPresentationType( ePresentationType.TITAN_CENTER )
	RunMenuClientFunction( "UpdateTitanModel", uiGlobal.titanSpawnLoadoutIndex )

	var subText = Hud_GetChild( file.menu, "MenuSubTitle" )
	// Hud_Show( subText )
}

void function EditPilotButton_OnClick( var button )
{
	// SetEditLoadout( "pilot", uiGlobal.pilotSpawnLoadoutIndex )
	// RunMenuClientFunction( "SetEditingPilotLoadoutIndex", uiGlobal.pilotSpawnLoadoutIndex )
	AdvanceMenu( GetMenu( "EditPilotLoadoutsMenu" ) )
	RunMenuClientFunction( "HideTTSPanel" )
}

void function EditTitanButton_OnClick( var button )
{
	SetEditLoadout( "titan", uiGlobal.titanSpawnLoadoutIndex )
	RunMenuClientFunction( "SetEditingTitanLoadoutIndex", uiGlobal.titanSpawnLoadoutIndex )
	AdvanceMenu( GetMenu( "EditTitanLoadoutMenu" ) )
	RunMenuClientFunction( "HideTTSPanel" )
}

bool function CoverIsOff()
{
	return !Hud_IsEnabled( file.cover )
}

bool function TeamTitanSelectMenuIsOpen()
{
	return file.menuOpened
}

bool function TeamTitanSelect_IsReady()
{
	return file.isReady
}

bool function TeamTitanSelect_IsNotReady()
{
	return !file.isReady
}

void function TTSMenuModeFD()
{
	file.menuMode = eTTSMenuMode.FD

	foreach ( button in file.titanUpgradeButtons )
	{
		Hud_Show( button )
	}
}

void function TTSMenuModeDefault()
{
	file.menuMode = eTTSMenuMode.DEFAULT

	foreach ( button in file.titanUpgradeButtons )
	{
		Hud_Hide( button )
	}

	var panel = Hud_GetChild( file.menu, "UpgradeName" )
	Hud_Hide( panel )
}

var function FindValidTitanButton()
{
	foreach ( button in file.titanButtons )
	{
		if ( Hud_IsLocked( button ) )
			continue

		return button
	}

	return file.titanButtons[0]
}