aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client/mod/scripts/vscripts/ui/menu_ingame.nut
blob: ac617a9c7b7306af76438bb16c825dd38346bde6 (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 InitLobbyStartMenu
global function InitInGameMPMenu
global function InitInGameSPMenu
global function ServerCallback_UI_ObjectiveUpdated
global function ServerCallback_UI_UpdateMissionLog
global function SP_ResetObjectiveStringIndex
global function SCB_SetDoubleXPStatus

global function SCB_SetCompleteMeritState
global function SCB_SetEvacMeritState
global function SCB_SetMeritCount
global function SCB_SetScoreMeritState
global function SCB_SetWinMeritState
global function SCB_SetWeaponMeritCount
global function SCB_SetTitanMeritCount

const DATA_TABLE = $"datatable/sp_difficulty.rpak"

struct
{
	var menuMP
	var menuSP
	var BtnTrackedChallengeBackground
	var BtnTrackedChallengeTitle
	array trackedChallengeButtons
	var BtnLastCheckpoint
	int objectiveStringIndex
	bool SP_displayObjectiveOnClose
	var settingsHeader
	var faqButton
	int titanHeaderIndex
	var titanHeader
	var titanSelectButton
	var titanEditButton

	ComboStruct &comboStruct

	array<var> loadoutButtons
	array<var> loadoutHeaders
} file

void function InitInGameMPMenu()
{
	var menu = GetMenu( "InGameMPMenu" )
	file.menuMP = menu

	SP_ResetObjectiveStringIndex()
	file.SP_displayObjectiveOnClose = true

	AddMenuEventHandler( menu, eUIEvent.MENU_OPEN, OnInGameMPMenu_Open )
	AddMenuEventHandler( menu, eUIEvent.MENU_CLOSE, OnInGameMPMenu_Close )

	AddUICallback_OnLevelInit( OnInGameLevelInit )

	ComboStruct comboStruct = ComboButtons_Create( menu )

	int headerIndex = 0
	int buttonIndex = 0
	var pilotHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_PILOT" )
	file.loadoutHeaders.append( pilotHeader )
	var pilotSelectButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#SELECT" )
	Hud_AddEventHandler( pilotSelectButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "PilotLoadoutsMenu" ) ) )
	file.loadoutButtons.append( pilotSelectButton )
	var pilotEditButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#EDIT" )
	Hud_AddEventHandler( pilotEditButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "EditPilotLoadoutsMenu" ) ) )
	file.loadoutButtons.append( pilotEditButton )

	headerIndex++
	buttonIndex = 0
	var titanHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_TITAN" )
	file.titanHeader = titanHeader
	file.titanHeaderIndex = headerIndex
	file.loadoutHeaders.append( titanHeader )
	var titanSelectButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#SELECT" )
	file.titanSelectButton = titanSelectButton
	file.loadoutButtons.append( titanSelectButton )
	Hud_AddEventHandler( titanSelectButton, UIE_CLICK, TitanSelectButtonHandler )
	var titanEditButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#EDIT" )
	Hud_AddEventHandler( titanEditButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "EditTitanLoadoutsMenu" ) ) )
	file.titanEditButton = titanEditButton
	file.loadoutButtons.append( titanEditButton )

	headerIndex++
	buttonIndex = 0
	var gameHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_GAME" )
	var leaveButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#LEAVE_MATCH" )
	Hud_AddEventHandler( leaveButton, UIE_CLICK, OnLeaveButton_Activate )
	var teamChangeButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#SWITCH_TEAMS" )
	Hud_AddEventHandler( teamChangeButton, UIE_CLICK, OnRequestTeamSwitch )
	thread UpdateTeamSwitchButton_Threaded( teamChangeButton )
	#if DEV
		var devButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "Dev" )
		Hud_AddEventHandler( devButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "DevMenu" ) ) )
	#endif

	headerIndex++
	buttonIndex = 0
	var dummyHeader = AddComboButtonHeader( comboStruct, headerIndex, "" )
	var dummyButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "" )
	Hud_SetVisible( dummyHeader, false )
	Hud_SetVisible( dummyButton, false )

	headerIndex++
	buttonIndex = 0
	file.settingsHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_SETTINGS" )
	var controlsButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#CONTROLS" )
	Hud_AddEventHandler( controlsButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "ControlsMenu" ) ) )
	#if CONSOLE_PROG
		var avButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#AUDIO_VIDEO" )
		Hud_AddEventHandler( avButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "AudioVideoMenu" ) ) )
	#elseif PC_PROG
		var videoButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#AUDIO" )
		Hud_AddEventHandler( videoButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "AudioMenu" ) ) )
		var soundButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#VIDEO" )
		Hud_AddEventHandler( soundButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "VideoMenu" ) ) )
	#endif

	// MOD SETTINGS
	var modSettingsButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "Mod Settings" )
	Hud_AddEventHandler( modSettingsButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "ModSettings" ) ) )

	// Nobody reads the FAQ so we replace it with ModSettings because of the limited combobutton space available
	//file.faqButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#KNB_MENU_HEADER" )
	//Hud_AddEventHandler( file.faqButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "KnowledgeBaseMenu" ) ) )

	//var dataCenterButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#DATA_CENTER" )
	//Hud_AddEventHandler( dataCenterButton, UIE_CLICK, OpenDataCenterDialog )

	ComboButtons_Finalize( comboStruct )

	file.comboStruct = comboStruct

	AddMenuFooterOption( menu, BUTTON_A, "#A_BUTTON_SELECT" )
	AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_CLOSE", "#CLOSE" )
}

void function OnInGameMPMenu_Open()
{
	Lobby_SetFDMode( GetCurrentPlaylistVarInt( "ingame_menu_fd_mode", 0 ) == 1 )
	UI_SetPresentationType( ePresentationType.DEFAULT )

	bool faqIsNew = !GetConVarBool( "menu_faq_viewed" ) || HaveNewPatchNotes() || HaveNewCommunityNotes()
	RuiSetBool( Hud_GetRui( file.settingsHeader ), "isNew", faqIsNew )
	//ComboButton_SetNew( file.faqButton, faqIsNew )

	UpdateLoadoutButtons()
	RefreshCreditsAvailable()
	thread UpdateCachedNewItems()
}

void function OnInGameMPMenu_Close()
{
	UI_SetPresentationType( ePresentationType.INACTIVE )

	if ( IsConnected() && !IsLobby() && IsLevelMultiplayer( GetActiveLevel() ) )
	{
		//printt( "OnInGameMPMenu_Close() uiGlobal.updatePilotSpawnLoadout is:", uiGlobal.updatePilotSpawnLoadout )
		//printt( "OnInGameMPMenu_Close() uiGlobal.updateTitanSpawnLoadout is:", uiGlobal.updateTitanSpawnLoadout )

		string updatePilotSpawnLoadout = uiGlobal.updatePilotSpawnLoadout ? "1" : "0"
		string updateTitanSpawnLoadout = uiGlobal.updateTitanSpawnLoadout ? "1" : "0"

		ClientCommand( "InGameMPMenuClosed " + updatePilotSpawnLoadout + " " + updateTitanSpawnLoadout )

		uiGlobal.updatePilotSpawnLoadout = false
		uiGlobal.updateTitanSpawnLoadout = false

		RunClientScript( "RefreshIntroLoadoutDisplay", GetLocalClientPlayer(), uiGlobal.pilotSpawnLoadoutIndex, uiGlobal.titanSpawnLoadoutIndex )
	}
}

void function UpdateLoadoutButtons()
{
	bool loadoutSelectionEnabled = (GetCurrentPlaylistVarInt( "loadout_selection_enabled", 1 ) == 1)

	SetTitanSelectButtonVisibleState( true )

	foreach ( button in file.loadoutButtons )
	{
		Hud_SetEnabled( button, loadoutSelectionEnabled )
	}

	foreach ( header in file.loadoutHeaders )
	{
		if ( loadoutSelectionEnabled )
			Hud_Show( header )
		else
			Hud_Hide( header )
	}

	entity player = GetUIPlayer()

	if ( GetAvailableTitanRefs( player ).len() > 1 )
	{
		SetComboButtonHeaderTitle( file.menuMP, file.titanHeaderIndex, "#MENU_HEADER_TITAN" )
		ComboButton_SetText( file.titanSelectButton, "#SELECT" )
		Hud_Show( file.titanEditButton )
	}
	else if ( GetAvailableTitanRefs( player ).len() == 1 )
	{
		TitanLoadoutDef loadout = GetCachedTitanLoadout( uiGlobal.titanSpawnLoadoutIndex )

		SetComboButtonHeaderTitle( file.menuMP, file.titanHeaderIndex, GetTitanLoadoutName( loadout ) )
		ComboButton_SetText( file.titanSelectButton, "#EDIT" )

		Hud_Hide( file.titanEditButton )
		ComboButtons_ResetColumnFocus( file.comboStruct )
	}
	else
	{
		SetTitanSelectButtonVisibleState( true )
	}
}

//////////

//////////

void function InitInGameSPMenu()
{
	var menu = GetMenu( "InGameSPMenu" )
	file.menuSP = menu

	AddMenuEventHandler( menu, eUIEvent.MENU_OPEN, OnOpenInGameSPMenu )
	AddMenuEventHandler( menu, eUIEvent.MENU_CLOSE, OnCloseInGameSPMenu )

	ComboStruct comboStruct = ComboButtons_Create( menu )

	int headerIndex = 0
	int buttonIndex = 0

	// MISSION Menu
	var missionHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_MISSION" )
	var resumeButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#RESUME_GAME_SHORT" )
	Hud_AddEventHandler( resumeButton, UIE_CLICK, OnResumeGame_Activate )
	var lastCheckpointButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#LAST_CHECKPOINT" )
	Hud_AddEventHandler( lastCheckpointButton, UIE_CLICK, OnReloadCheckpoint_Activate )
	file.BtnLastCheckpoint = lastCheckpointButton
	var restartButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#RESTART_LEVEL_SHORT" )
	Hud_AddEventHandler( restartButton, UIE_CLICK, OnRestartLevel_Activate )

	// GAME Menu
	// headerIndex++
	// buttonIndex = 0
	// var gameHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_GAME" )
	// var difficultyButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#CHANGE_DIFFICULTY" )
	// Hud_AddEventHandler( difficultyButton, UIE_CLICK, OnChangeDifficulty_Activate )
	// var leaveButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#QUIT" )
	// Hud_AddEventHandler( leaveButton, UIE_CLICK, OnLeaveButton_Activate )

	// SETTINGS Menu
	headerIndex++
	buttonIndex = 0
	var settingsHeader = AddComboButtonHeader( comboStruct, headerIndex, "#MENU_HEADER_SETTINGS" )
	var controlsButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#CONTROLS" )
	Hud_AddEventHandler( controlsButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "ControlsMenu" ) ) )
	#if CONSOLE_PROG
		var avButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#AUDIO_VIDEO" )
		Hud_AddEventHandler( avButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "AudioVideoMenu" ) ) )
	#elseif PC_PROG
		var audioButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#AUDIO" )
		Hud_AddEventHandler( audioButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "AudioMenu" ) ) )
		var videoButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "#VIDEO" )
		Hud_AddEventHandler( videoButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "VideoMenu" ) ) )
	#endif
	
	// MOD SETTINGS
	var modSettingsButton = AddComboButton( comboStruct, headerIndex, buttonIndex++, "Mod Settings" )
	Hud_AddEventHandler( modSettingsButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "ModSettings" ) ) )

	array<var> orderedButtons

	var changeDifficultyBtn = Hud_GetChild( menu, "BtnChangeDifficulty" )

	AddButtonEventHandler( changeDifficultyBtn, UIE_CLICK, OnChangeDifficulty_Activate )
	Hud_Show( changeDifficultyBtn )
	orderedButtons.append( changeDifficultyBtn )

	var quitBtn = Hud_GetChild( menu, "BtnQuit" )
	SetButtonRuiText( quitBtn, "#QUIT" )
	AddButtonEventHandler( quitBtn, UIE_CLICK, OnLeaveButton_Activate )
	Hud_Show( quitBtn )
	orderedButtons.append( quitBtn )

	// DEV button
	var devButton = Hud_GetChild( menu, "BtnDev" )
	#if DEV
		SetButtonRuiText( devButton, "--- Dev" )
		AddButtonEventHandler( devButton, UIE_CLICK, AdvanceMenuEventHandler( GetMenu( "DevMenu" ) ) )
		Hud_Show( devButton )
		orderedButtons.append( devButton )
		comboStruct.navUpButton = devButton
	#else
		Hud_Hide( devButton )
		comboStruct.navUpButton = quitBtn
	#endif // DEV

	SetNavUpDown( orderedButtons )
	comboStruct.navDownButton = changeDifficultyBtn

	ComboButtons_Finalize( comboStruct )

	AddMenuFooterOption( menu, BUTTON_A, "#A_BUTTON_SELECT" )
	AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_CLOSE", "#CLOSE" )
}


void function OnOpenInGameSPMenu()
{
	var collectiblesFoundDesc = Hud_GetChild( file.menuSP, "CollectiblesFoundDesc" )
	var missionLogDesc = Hud_GetChild( file.menuSP, "MissionLogDesc" )
	var changeDifficultyBtn = Hud_GetChild( file.menuSP, "BtnChangeDifficulty" )

	Hud_SetEnabled( file.BtnLastCheckpoint, HasValidSaveGame() )

	int currentDifficulty = GetConVarInt( "sp_difficulty" )
	string newDifficultyString

	switch ( currentDifficulty )
	{
		case 0:
			newDifficultyString = "#CHANGE_DIFFICULTY_EASY"
			break

		case 1:
			newDifficultyString = "#CHANGE_DIFFICULTY_REGULAR"
			break

		case 2:
			newDifficultyString = "#CHANGE_DIFFICULTY_HARD"
			break

		case 3:
			newDifficultyString = "#CHANGE_DIFFICULTY_MASTER"
			break

		default:
			Assert( 0, "Unknown difficulty " + currentDifficulty )
			break
	}
	SetButtonRuiText( changeDifficultyBtn, newDifficultyString )

	string activeLevelName = GetActiveLevel()
	if ( activeLevelName != "" )
	{
		var dataTable = GetDataTable( $"datatable/sp_levels_data.rpak" )

		// Make sure this level actually has data to display.
		bool levelHasData = false
		int numRows = GetDatatableRowCount( dataTable )
		for ( int i = 0; i < numRows; i++ )
		{
			string levelName = GetDataTableString( dataTable, i, GetDataTableColumnByName( dataTable, "level" ) )
			if ( activeLevelName == levelName )
			{
				levelHasData = true
				break
			}
		}

		if ( levelHasData )
		{
			// Mission Log
			int row = GetDataTableRowMatchingStringValue( dataTable, GetDataTableColumnByName( dataTable, "level" ), activeLevelName )
			string missionLog = GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, "missionLog" ) )

			if ( uiGlobal.sp_showAlternateMissionLog )
			{
				string alternateMissionLog = GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, "alternateMissionLog" ) )
				missionLog = alternateMissionLog
			}

			Hud_SetText( missionLogDesc, missionLog )

			// Collectibles
			int foundLions = GetCollectiblesFoundForLevel( activeLevelName )
			int maxLions = GetMaxLionsInLevel( activeLevelName )
			Hud_SetText( collectiblesFoundDesc, "#MENU_SP_COLLECTIBLE_DESC", foundLions, maxLions )
		}
		else
		{
			Hud_SetText( missionLogDesc, "#MENU_SP_OBJECTIVES_NO_ENTRY" )
			Hud_SetText( collectiblesFoundDesc, "#MENU_SP_COLLECTIBLE_DESC", 0, 0 )
		}

		// Make sure trial mode doesn't reveal any spoilers!
		if ( Script_IsRunningTrialVersion() )
			Hud_SetText( missionLogDesc, "#MENU_SP_OBJECTIVES_NO_ENTRY" )
	}

	SPMenu_UpdateReloadCheckpointButton()
}


void function OnCloseInGameSPMenu()
{
	if ( file.SP_displayObjectiveOnClose )
		ClientCommand( "ShowObjective closedSPMenu" )
}

void function SPMenu_UpdateReloadCheckpointButton()
{
	if ( level.ui.playerRunningGauntlet )
		ComboButton_SetText( file.BtnLastCheckpoint, "#GAUNTLET_RESTART" )
	else
		ComboButton_SetText( file.BtnLastCheckpoint, "#LAST_CHECKPOINT" )
}

void function MobilityDifficultyButton_Activate( var button )
{
	OpenMobilityDifficultyMenu()
}

void function OnLeaveButton_Activate( var button )
{
	file.SP_displayObjectiveOnClose = false
	LeaveDialog()
}

void function OnRestartLevel_Activate( var button )
{
	ShowAreYouSureDialog( "#MENU_RESTART_MISSION_CONFIRM", RestartMission, "#WARNING_LOSE_PROGRESS" )
}

void function OnChangeDifficulty_Activate( var button )
{
	SPDifficultyButton_Click( button )
}

void function OnResumeGame_Activate( var button )
{
	CloseActiveMenu()
}

void function OnReloadCheckpoint_Activate( var button )
{
	if ( level.ui.playerRunningGauntlet )
	{
		CloseActiveMenu()
		ClientCommand( "Gauntlet_PlayerRestartedFromMenu" )
	}
	else
	{
		ShowAreYouSureDialog( "#MENU_RESTART_CHECKPOINT_CONFIRM", ReloadLastCheckpoint, "#EMPTY_STRING"  )
	}
}

void function ShowAreYouSureDialog( string header, void functionref() func, string details )
{
	DialogData dialogData
	dialogData.header = header
	dialogData.message = details

	AddDialogButton( dialogData, "#NO" )
	AddDialogButton( dialogData, "#YES", func )

	AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
	AddDialogFooter( dialogData, "#B_BUTTON_BACK" )

	OpenDialog( dialogData )
}

void function RestartMission()
{
	file.SP_displayObjectiveOnClose = false
	ClientCommand( "RestartMission" )
}

void function ReloadLastCheckpoint()
{
	file.SP_displayObjectiveOnClose = false

	printt( "SAVEGAME: Trying to load saveName" )
	if ( HasValidSaveGame() )
	{
		printt( "SAVEGAME: Trying to load checkpoint from menu_ingame" )
		SaveGame_LoadWithStartPointFallback()
		return
	}

	ClientCommand( "RestartFromLevelTransition" )
}

void function SP_ResetObjectiveStringIndex()
{
	file.objectiveStringIndex = -1
}

void function ServerCallback_UI_ObjectiveUpdated( int stringIndex )
{
	file.objectiveStringIndex = stringIndex
}

void function ServerCallback_UI_UpdateMissionLog( bool showAltLog )
{
	uiGlobal.sp_showAlternateMissionLog = showAltLog
}

void function SPDifficultyButton_Click( var button )
{
	DialogData dialogData
	dialogData.header = "#SP_DIFFICULTY_MISSION_SELECT_TITLE"

	int currentDifficulty = GetConVarInt( "sp_difficulty" )
	dialogData.coloredButton[ currentDifficulty ] <- true

	if ( currentDifficulty == DIFFICULTY_EASY )
		AddDialogButton( dialogData, "#SP_DIFFICULTY_EASY_TITLE", SPPickEasy, "#SP_DIFFICULTY_EASY_DESCRIPTION", true )
	else
		AddDialogButton( dialogData, "#SP_DIFFICULTY_EASY_TITLE", SPPickEasy, "#SP_DIFFICULTY_EASY_DESCRIPTION", false )


	if ( currentDifficulty == DIFFICULTY_NORMAL )
		AddDialogButton( dialogData, "#SP_DIFFICULTY_NORMAL_TITLE", SPPickNormal, "#SP_DIFFICULTY_NORMAL_DESCRIPTION", true )
	else
		AddDialogButton( dialogData, "#SP_DIFFICULTY_NORMAL_TITLE", SPPickNormal, "#SP_DIFFICULTY_NORMAL_DESCRIPTION", false )


	if ( currentDifficulty == DIFFICULTY_HARD )
		AddDialogButton( dialogData, "#SP_DIFFICULTY_HARD_TITLE", SPPickHard, "#SP_DIFFICULTY_HARD_DESCRIPTION", true )
	else
		AddDialogButton( dialogData, "#SP_DIFFICULTY_HARD_TITLE", SPPickHard, "#SP_DIFFICULTY_HARD_DESCRIPTION", false )


	if ( currentDifficulty == DIFFICULTY_MASTER )
		AddDialogButton( dialogData, "#SP_DIFFICULTY_MASTER_TITLE", SPPickMaster, "#SP_DIFFICULTY_MASTER_DESCRIPTION", true )
	else
		AddDialogButton( dialogData, "#SP_DIFFICULTY_MASTER_TITLE", SPPickMaster, "#SP_DIFFICULTY_MASTER_DESCRIPTION", false )


	AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
	AddDialogFooter( dialogData, "#B_BUTTON_BACK" )
	AddDialogPCBackButton( dialogData )

	OpenDialog( dialogData )
}

void function SPPickEasy()
{
	RequestSPDifficultyChange( DIFFICULTY_EASY )
	CloseAllMenus()
}

void function SPPickNormal()
{
	RequestSPDifficultyChange( DIFFICULTY_NORMAL )
	CloseAllMenus()
}

void function SPPickHard()
{
	RequestSPDifficultyChange( DIFFICULTY_HARD )
	CloseAllMenus()
}

void function SPPickMaster()
{
	RequestSPDifficultyChange( DIFFICULTY_MASTER )
	CloseAllMenus()
}

void function RequestSPDifficultyChange( int selectedDifficulty )
{
	var dataTable = GetDataTable( DATA_TABLE )
	int difficulty = GetDataTableInt( dataTable, selectedDifficulty, GetDataTableColumnByName( dataTable, "index" ) )

	ClientCommand( "ClientCommand_RequestSPDifficultyChange " + difficulty )
}

void function SCB_SetDoubleXPStatus( int status )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	RuiSetInt( Hud_GetRui( doubleXPWidget ), "doubleXPStatus", status )

	// update this menu too
	TTSUpdateDoubleXPStatus( status )
}

void function OnInGameLevelInit()
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )
	RuiSetInt( rui, "doubleXPStatus", 0 )
	RuiSetBool( rui, "isVisible", false )

	string gameModeScoreHint = expect string( GetCurrentPlaylistVar( "gamemode_score_hint" ) )
	if ( gameModeScoreHint != "" )
	{
		RuiSetString( rui, "scoreMeritText", Localize( gameModeScoreHint ) )
		RuiSetInt( rui, "matchScoreMerit", MERIT_STATE_AVAILABLE )
	}
	else
	{
		RuiSetString( rui, "scoreMeritText", "" )
		RuiSetInt( rui, "matchScoreMerit", MERIT_STATE_HIDDEN )
	}

	Hud_SetVisible( doubleXPWidget, !IsPrivateMatch() )
}
/*
int matchScoreMerit = MERIT_STATE_AVAILABLE
int matchCompleteMerit = MERIT_STATE_AVAILABLE
int matchWinMerit = MERIT_STATE_AVAILABLE
int matchEvacMerit = MERIT_STATE_HIDDEN
int happyHourMerits = MERIT_STATE_HIDDEN

int meritCount = 0
*/

void function SCB_SetScoreMeritState( int meritState )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "matchScoreMerit", meritState )
}

void function SCB_SetCompleteMeritState( int meritState )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "matchCompleteMerit", meritState )
}

void function SCB_SetWinMeritState( int meritState )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "matchWinMerit", meritState )
}

void function SCB_SetEvacMeritState( int meritState )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "matchEvacMerit", meritState )
}

void function SCB_SetMeritCount( int meritCount )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "meritCount", meritCount )
}

void function SCB_SetWeaponMeritCount( int meritCount )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "weaponMeritCount", meritCount )
}

void function SCB_SetTitanMeritCount( int meritCount )
{
	var doubleXPWidget = Hud_GetChild( file.menuMP, "DoubleXP" )
	var rui = Hud_GetRui( doubleXPWidget )

	RuiSetInt( rui, "titanMeritCount", meritCount )
}

void function TitanSelectButtonHandler( var button )
{
	if ( !IsFullyConnected() )
		return

	entity player = GetUIPlayer()
	if ( GetAvailableTitanRefs( player ).len() > 1 )
	{
		AdvanceMenu( GetMenu( "TitanLoadoutsMenu" ) )
	}
	else if ( GetAvailableTitanRefs( player ).len() == 1 )
	{
		uiGlobal.updateTitanSpawnLoadout = false
		SetEditLoadout( "titan", uiGlobal.titanSpawnLoadoutIndex )

		RunMenuClientFunction( "SetEditingTitanLoadoutIndex", uiGlobal.titanSpawnLoadoutIndex )
		AdvanceMenu( GetMenu( "EditTitanLoadoutMenu" ) )
	}
	else
	{
		// HIDE
	}
}

void function SetTitanSelectButtonVisibleState( bool state )
{
	if ( state )
	{
		Hud_Show( file.titanHeader )
		Hud_Show( file.titanEditButton )
		Hud_Show( file.titanSelectButton )
	}
	else
	{
		ComboButtons_ResetColumnFocus( file.comboStruct )
		Hud_Hide( file.titanHeader )
		Hud_Hide( file.titanEditButton )
		Hud_Hide( file.titanSelectButton )
	}
}

void function UpdateTeamSwitchButton_Threaded( var button )
{
	while ( true )
	{
		Hud_SetLocked( button, !GetConVarBool( "ns_allow_team_change" ) )
		wait 0.5
	}
}

void function OnRequestTeamSwitch( var button )
{
	if ( !Hud_IsLocked( button ) )
	{
		ClientCommand( "changeteam" )
		CloseAllMenus()
	}
}