aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client/mod/scripts/vscripts/ui/menu_pilot_loadouts_shared.nut
blob: f0139e04e4fbae06f8f3f69e84ea60372de64dc1 (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
global function UpdatePilotLoadoutPanel
global function UpdatePilotLoadoutPanelBinds
global function UpdatePilotLoadoutButtons
global function UpdatePilotItemButton

void function UpdatePilotLoadoutButtons( int selectedIndex, var[NUM_PERSISTENT_PILOT_LOADOUTS] buttons, bool focusSelected = true )
{
	entity player = GetUIPlayer()
	if ( player == null )
		return

	int numLoadouts = GetAllCachedPilotLoadouts().len()

	// HACK: num_pilot_loadouts is just used to disable certain loadouts for FNF
	int numLoadoutsForPlaylist = GetCurrentPlaylistVarInt( "num_pilot_loadouts", 0 )
	if ( numLoadoutsForPlaylist > 0 )
		numLoadouts = numLoadoutsForPlaylist

	foreach ( index, button in buttons )
	{
		PilotLoadoutDef loadout = GetCachedPilotLoadout( index )
		RHud_SetText( button, GetPilotLoadoutName( loadout ) )
		Hud_SetPanelAlpha( button, 0 )

		bool isSelected = ( index == selectedIndex ) ? true : false
		Hud_SetSelected( button, isSelected )

		string pilotLoadoutRef = "pilot_loadout_" + ( index + 1 )
		Hud_SetLocked( button, IsItemLocked( player, pilotLoadoutRef ) )

		bool shouldShowNew = ButtonShouldShowNew( eItemTypes.FEATURE, pilotLoadoutRef )
		if ( !shouldShowNew && (RefHasAnyNewSubitem( player, loadout.primary ) || RefHasAnyNewSubitem( player, loadout.secondary ) || RefHasAnyNewSubitem( player, loadout.weapon3 )) )
			shouldShowNew = true

		if ( IsItemLocked( player, pilotLoadoutRef ) )
			shouldShowNew = false

		Hud_SetNew( button, shouldShowNew )

		RefreshButtonCost( button, pilotLoadoutRef )
	}

	if ( focusSelected )
		Hud_SetFocused( buttons[ selectedIndex ] )
}

void function UpdatePilotLoadoutPanel( var loadoutPanel, PilotLoadoutDef loadout )
{
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "TacticalName" ), Localize( GetItemName( loadout.special ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "PrimaryName" ), Localize( GetItemName( loadout.primary ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "SecondaryName" ), Localize( GetItemName( loadout.secondary ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "Weapon3Name" ), Localize( GetItemName( loadout.weapon3 ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "OrdnanceName" ), Localize( GetItemName( loadout.ordnance ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "Kit1Name" ), Localize( GetItemName( loadout.passive1 ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "Kit2Name" ), Localize( GetItemName( loadout.passive2 ) ) )
	SetLabelRuiText( Hud_GetChild( loadoutPanel, "ExecutionName" ), Localize( GetItemName( loadout.execution ) ) )

	UpdatePilotLoadoutPanelBinds( loadoutPanel )

	var menu = Hud_GetParent( loadoutPanel )
	array<var> buttons = GetElementsByClassname( menu, "PilotLoadoutPanelButtonClass" )

	/*if ( button )
	{
		// TEMP disabled since Hud_GetChild( menu, "ButtonTooltip" ) will fail
		//if ( HandleLockedMenuItem( menu, button ) )
		//	return
	}*/
	bool isEdit
	if ( Hud_GetHudName( loadoutPanel ) == "PilotLoadoutButtons" ) // Edit menu
		isEdit = true
	else // Select menu
		isEdit = false

	foreach ( button in buttons )
		UpdatePilotItemButton( button, loadout, isEdit )

	var renameEditBox = Hud_GetChild( loadoutPanel, "RenameEditBox" )

	asset pilotAppearanceImage = loadout.camoIndex > 0 ? CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.camoIndex ) ) : $"rui/menu/common/appearance_button_swatch"

	asset primaryAppearanceImage
	if ( loadout.primarySkinIndex == 0 ) // default skin
		primaryAppearanceImage = $"rui/menu/common/appearance_button_swatch"
	else if ( loadout.primarySkinIndex == 1 ) // camo
		primaryAppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.primaryCamoIndex ) )
	else // warpaint skin
		primaryAppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.primary, loadout.primarySkinIndex, "primarySkinIndex" )

	asset secondaryAppearanceImage
	if ( loadout.secondarySkinIndex == 0 ) // default skin
		secondaryAppearanceImage = $"rui/menu/common/appearance_button_swatch"
	else if ( loadout.secondarySkinIndex == 1 ) // camo
		secondaryAppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.secondaryCamoIndex ) )
	else // warpaint skin
		secondaryAppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.secondary, loadout.secondarySkinIndex, "secondarySkinIndex" )

	asset weapon3AppearanceImage
	if ( loadout.weapon3SkinIndex == 0 ) // default skin
		weapon3AppearanceImage = $"rui/menu/common/appearance_button_swatch"
	else if ( loadout.weapon3SkinIndex == 1 ) // camo
		weapon3AppearanceImage = CamoSkin_GetImage( CamoSkins_GetByIndex( loadout.weapon3CamoIndex ) )
	else // warpaint skin
		weapon3AppearanceImage = GetItemImageFromWeaponRefAndPersistenceValue( loadout.weapon3, loadout.weapon3SkinIndex, "weapon3SkinIndex" )

	RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonPilotCamo" ) ), "camoImage", pilotAppearanceImage )
	RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonPrimarySkin" ) ), "camoImage", primaryAppearanceImage )
	RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonSecondarySkin" ) ), "camoImage", secondaryAppearanceImage )
	RuiSetImage( Hud_GetRui( Hud_GetChild( loadoutPanel, "ButtonWeapon3Skin" ) ), "camoImage", weapon3AppearanceImage )

	array<var> nonItemElements
	nonItemElements.append( Hud_GetChild( loadoutPanel, "ButtonPilotCamo" ) )
	nonItemElements.append( Hud_GetChild( loadoutPanel, "ButtonGender" ) )
	nonItemElements.append( Hud_GetChild( loadoutPanel, "ButtonPrimarySkin" ) )
	nonItemElements.append( Hud_GetChild( loadoutPanel, "ButtonSecondarySkin" ) )
	nonItemElements.append( Hud_GetChild( loadoutPanel, "ButtonWeapon3Skin" ) )
	nonItemElements.append( renameEditBox )

	foreach ( elem in nonItemElements )
	{
		if ( isEdit )
			Hud_Show( elem )
		else
			Hud_Hide( elem )
	}
	Hud_SetEnabled( renameEditBox, isEdit )
}

void function UpdatePilotItemButton( var button, PilotLoadoutDef loadout, bool isEdit )
{
	string propertyName = Hud_GetScriptID( button )
	string itemRef = GetPilotLoadoutValue( loadout, propertyName )
	int itemType = GetItemTypeFromPilotLoadoutProperty( propertyName )
	asset image

	ItemDisplayData parentItem

	if ( itemType == eItemTypes.PILOT_PRIMARY_ATTACHMENT || itemType == eItemTypes.PILOT_PRIMARY_MOD || itemType == eItemTypes.PILOT_SECONDARY_MOD || itemType == eItemTypes.PILOT_WEAPON_MOD3 )
	{
		string parentProperty = GetParentLoadoutProperty( "pilot", propertyName )
		Assert( parentProperty == "primary" || parentProperty == "secondary" || parentProperty == "weapon3" )

		if ( parentProperty == "primary" )
			parentItem = GetItemDisplayData( loadout.primary )
		else if ( parentProperty == "secondary" )
			parentItem = GetItemDisplayData( loadout.secondary )
		else
			parentItem = GetItemDisplayData( loadout.weapon3 )

		bool isHiddenAttachment = false

		if ( itemType == eItemTypes.PILOT_PRIMARY_ATTACHMENT )
		{
			// Disable attachment option for "special" primary weapons
			if ( "menuCategory" in parentItem.i && ( expect int( parentItem.i.menuCategory ) == ePrimaryWeaponCategory.SPECIAL || expect int( parentItem.i.menuCategory ) == ePrimaryWeaponCategory.HANDGUN ) )
			{
				isHiddenAttachment = true

				Hud_SetWidth( button, 0 )
				Hud_SetPos( button, 0, 0 ) // Clear sibling offset
			}
			else
			{
				int defaultButtonWidth = int( ContentScaledX( 72 ) )
				int defaultOffsetX = int( ContentScaledX( 6 ) )

				Hud_SetWidth( button, defaultButtonWidth )
				Hud_SetPos( button, defaultOffsetX, 0 )
			}
		}

		if ( !isHiddenAttachment )
			image = GetImage( itemType, parentItem.ref, itemRef )
	}
	else
	{
		image = GetImage( itemType, itemRef )
	}

	if ( itemType == eItemTypes.PILOT_PRIMARY || itemType == eItemTypes.PILOT_SECONDARY )
	{
		//if ( isEdit )
		//{
		//	RuiSetString( Hud_GetRui( button ), "subText", "" )
		//	RuiSetFloat( Hud_GetRui( button ), "numSegments", 0 )
		//	RuiSetFloat( Hud_GetRui( button ), "filledSegments", 0 )
		//}
		//else
		{
			int currentXP = WeaponGetXP( GetLocalClientPlayer(), itemRef )
			int numPips = WeaponGetNumPipsForXP( itemRef, currentXP )
			int filledPips = WeaponGetFilledPipsForXP( itemRef, currentXP )
			RuiSetString( Hud_GetRui( button ), "subText", WeaponGetDisplayGenAndLevelForXP( itemRef, currentXP ) )
			RuiSetFloat( Hud_GetRui( button ), "numSegments", float( numPips ) )
			RuiSetFloat( Hud_GetRui( button ), "filledSegments", float( filledPips ) )
		}
	}

	var rui = Hud_GetRui( button )

	if ( image == $"" )
	{
		RuiSetBool( rui, "isVisible", false )
		Hud_SetEnabled( button, false )
	}
	else
	{
		RuiSetBool( rui, "isVisible", true )
		RuiSetImage( rui, "buttonImage", image )

		Hud_SetEnabled( button, true )
	}

	bool isLocked = false
	bool shouldShowNew = false

	// For unlock and subitem checks below, treat weapon3 as secondary
	if ( propertyName == "weapon3Mod1" )
		propertyName = "secondaryMod1"
	else if ( propertyName == "weapon3Mod2" )
		propertyName = "secondaryMod2"
	else if ( propertyName == "weapon3Mod3" )
		propertyName = "secondaryMod3"

	string propertyRef = propertyName.tolower()

	if ( !IsSubItemType( itemType ) )
	{
		if ( IsUnlockValid( propertyRef ) && IsItemLocked( GetUIPlayer(), propertyRef ) )
		{
			RefreshButtonCost( button, propertyRef )
			isLocked = true
		}
		shouldShowNew = ButtonShouldShowNew( itemType, itemRef )
	}
	else
	{
		if ( IsUnlockValid( propertyRef, parentItem.ref ) && IsSubItemLocked( GetUIPlayer(), propertyRef, parentItem.ref ) )
		{
			RefreshButtonCost( button, propertyRef )
			isLocked = true
		}
		shouldShowNew = ButtonShouldShowNew( itemType, itemRef, parentItem.ref )
	}

	Hud_SetLocked( button, isLocked )

	if ( !shouldShowNew && IsUnlockValid( propertyRef, parentItem.ref ) )
		shouldShowNew = ButtonShouldShowNew( GetSubitemType( parentItem.ref, propertyRef ), propertyRef, parentItem.ref )
	Hud_SetNew( button, shouldShowNew )

#if HAS_THREAT_SCOPE_SLOT_LOCK
	if ( propertyName == "primaryMod2" )
	{
		string attatchmentRef = GetPilotLoadoutValue( loadout, "primaryAttachment" )
		if ( attatchmentRef == "threat_scope" )
		{
			Hud_SetLocked( button, true )
			RefreshButtonCost( button, propertyRef, "", 0, 0 )
			Hud_SetNew( button, false )
		}
	}
#endif
}

void function UpdatePilotLoadoutPanelBinds( var loadoutPanel )
{
	if ( IsControllerModeActive() )
	{
		//SetLabelRuiText( Hud_GetChild( loadoutPanel, "PrimaryBind" ), "%weaponCycle%" )
		//SetLabelRuiText( Hud_GetChild( loadoutPanel, "SecondaryBind" ), "%weaponCycle%" )
		SetLabelRuiText( Hud_GetChild( loadoutPanel, "Weapon3Bind" ), Localize( "#WEAPON3_HOLD_HINT" ) )
	}
	else
	{
		//SetLabelRuiText( Hud_GetChild( loadoutPanel, "PrimaryBind" ), "%weaponSelectPrimary0%" )
		//SetLabelRuiText( Hud_GetChild( loadoutPanel, "SecondaryBind" ), "%weaponSelectPrimary1%" )
		SetLabelRuiText( Hud_GetChild( loadoutPanel, "Weapon3Bind" ), Localize( "#WEAPON3_PRESS_HINT" ) )
	}

	//SetLabelRuiText( Hud_GetChild( loadoutPanel, "TacticalBind" ), Localize( "%offhand1%" ) )
	//SetLabelRuiText( Hud_GetChild( loadoutPanel, "OrdnanceBind" ), Localize( "%offhand0%" ) )
}

asset function GetItemImageFromWeaponRefAndPersistenceValue(string weaponRef, int persistenceValue, string loadoutProperty)
{
	string skinRef = GetSkinRefFromWeaponRefAndPersistenceValue( weaponRef, persistenceValue )
	if (!IsRefValid(skinRef))
	{
		if (uiGlobal.editingLoadoutIndex != -1)
		{
			printt( "Resetting invalid " + loadoutProperty + " for weapon " + weaponRef )
			SetCachedLoadoutValue(GetUIPlayer(), "pilot", uiGlobal.editingLoadoutIndex, loadoutProperty, "0")
		}
		return $"rui/menu/common/appearance_button_swatch"
	}

	return GetItemImage( skinRef )
}