aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
blob: 29daf0a8a97a7c04e4e21853e1838b62e7545143 (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
untyped


global function MenuMapSelect_Init

global function InitMapsMenu

struct {
	int mapsPerPage = 21
	int currentMapPage
} file

// note: this does have a scrolling system in vanilla, but it's honestly really weird and jank and i don't like it
// so for parity with menu_mode_select i'm removing it in favour of a page system

function MenuMapSelect_Init()
{
	RegisterSignal( "OnCloseMapsMenu" )
}

void function InitMapsMenu()
{
	var menu = GetMenu( "MapsMenu" )

	AddMenuEventHandler( menu, eUIEvent.MENU_OPEN, OnOpenMapsMenu )
	AddMenuEventHandler( menu, eUIEvent.MENU_CLOSE, OnCloseMapsMenu )

	AddEventHandlerToButtonClass( menu, "MapButtonClass", UIE_GET_FOCUS, MapButton_Focused )
	AddEventHandlerToButtonClass( menu, "MapButtonClass", UIE_LOSE_FOCUS, MapButton_LostFocus )
	AddEventHandlerToButtonClass( menu, "MapButtonClass", UIE_CLICK, MapButton_Activate )

	AddMenuFooterOption( menu, BUTTON_A, "#A_BUTTON_SELECT" )
	AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
	
	AddMenuFooterOption( menu, BUTTON_SHOULDER_LEFT, "#PRIVATE_MATCH_PAGE_PREV", "#PRIVATE_MATCH_PAGE_PREV", CycleModesBack, IsNorthstarServer )
	AddMenuFooterOption( menu, BUTTON_SHOULDER_RIGHT, "#PRIVATE_MATCH_PAGE_NEXT", "#PRIVATE_MATCH_PAGE_NEXT", CycleModesForward, IsNorthstarServer )
}

void function OnOpenMapsMenu()
{
	if ( IsNorthstarServer() )
		file.mapsPerPage = 15
	else
		file.mapsPerPage = 21

	UpdateVisibleMaps()
}

void function UpdateVisibleMaps()
{
	array<var> buttons = GetElementsByClassname( GetMenu( "MapsMenu" ), "MapButtonClass" )
	array<string> mapsArray = GetPrivateMatchMaps()

	foreach ( button in buttons )
	{
		int buttonID = int( Hud_GetScriptID( button ) )
		int mapID = buttonID + ( file.currentMapPage * file.mapsPerPage )

		if ( buttonID < file.mapsPerPage && mapID < GetPrivateMatchMaps().len() )
		{
			string name = mapsArray[ mapID ]
			
			bool sp = name.find( "sp_" ) == 0
			if ( sp )
				SetButtonRuiText( button, Localize( "#PRIVATE_MATCH_SINGLEPLAYER_LEVEL", Localize( GetMapDisplayName( name ) ) ) )
			else
				SetButtonRuiText( button, GetMapDisplayName( name ) )
			Hud_SetEnabled( button, true )

			if ( IsItemInEntitlementUnlock( name ) && IsValid( GetUIPlayer() ) )
	 		{
	 			if ( IsItemLocked( GetUIPlayer(), name ) && GetCurrentPlaylistVarInt( name + "_available" , 0 ) == 0 )
	 			{
	 				SetButtonRuiText( button, Localize( "#MAP_LOCKED", Localize( GetMapDisplayName( name ) ) ) )
	 			}
	 		}

			bool mapSupportsMode = PrivateMatch_IsValidMapModeCombo( name, PrivateMatch_GetSelectedMode() )
			Hud_SetLocked( button, !mapSupportsMode )

			if ( !mapSupportsMode && !sp )
				SetButtonRuiText( button, Localize( "#PRIVATE_MATCH_UNAVAILABLE", Localize( GetMapDisplayName( name ) ) ) )
		}
		else
		{
			SetButtonRuiText( button, "" )
			Hud_SetEnabled( button, false )
		}

		if ( mapID == level.ui.privatematch_map )
		{
			printt( buttonID, mapsArray[buttonID] )
			Hud_SetFocused( button )
		}
	}
}

void function OnCloseMapsMenu()
{
	Signal( uiGlobal.signalDummy, "OnCloseMapsMenu" )
}

void function MapButton_Focused( var button )
{
	int mapID = int( Hud_GetScriptID( button ) ) + ( file.currentMapPage * file.mapsPerPage )

	var menu = GetMenu( "MapsMenu" )
	var nextMapImage = Hud_GetChild( menu, "NextMapImage" )
	var nextMapName = Hud_GetChild( menu, "NextMapName" )
	var nextMapDesc = Hud_GetChild( menu, "NextMapDesc" )

	array<string> mapsArray = GetPrivateMatchMaps()
	string mapName = mapsArray[ mapID ]

	asset mapImage = GetMapImageForMapName( mapName )
	RuiSetImage( Hud_GetRui( nextMapImage ), "basicImage", mapImage )
	Hud_SetText( nextMapName, GetMapDisplayName( mapName ) )

	string modeName = PrivateMatch_GetSelectedMode()
	bool mapSupportsMode = PrivateMatch_IsValidMapModeCombo( mapName, modeName )
	if ( !mapSupportsMode )
		Hud_SetText( nextMapDesc, Localize( "#PRIVATE_MATCH_MAP_NO_MODE_SUPPORT", Localize( GetMapDisplayName( mapName ) ), Localize( GetGameModeDisplayName( modeName ) ) ) )
	else
		Hud_SetText( nextMapDesc, GetMapDisplayDesc( mapName ) )

}

void function MapButton_LostFocus( var button )
{
	HandleLockedCustomMenuItem( GetMenu( "MapsMenu" ), button, [], true )
}

void function MapButton_Activate( var button )
{
	if ( Hud_IsLocked( button ) )
		return

	if ( !AmIPartyLeader() && GetPartySize() > 1 )
		return

	array<string> mapsArray = GetPrivateMatchMaps()
	int mapID = int( Hud_GetScriptID( button ) )
	string mapName = mapsArray[ mapID + ( file.currentMapPage * file.mapsPerPage ) ]

	printt( mapName, mapID )

	ClientCommand( "SetCustomMap " + mapName )
	CloseActiveMenu()
}

void function CycleModesBack( var button )
{
	if ( file.currentMapPage == 0 )
		return
	
	file.currentMapPage--
	UpdateVisibleMaps()
}

void function CycleModesForward( var button )
{
	if ( ( file.currentMapPage + 1 ) * file.mapsPerPage >= GetPrivateMatchMaps().len() )
		return
	
	file.currentMapPage++
	UpdateVisibleMaps()
}