aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Client/mod/scripts/vscripts
diff options
context:
space:
mode:
authorF1F7Y <64418963+F1F7Y@users.noreply.github.com>2022-02-16 23:28:00 +0100
committerGitHub <noreply@github.com>2022-02-16 19:28:00 -0300
commit41a3025396e05c960ce972ed83e9c9e0a9c70e9e (patch)
tree65d9e829340db8813fd4581ad93761c9457d9e34 /Northstar.Client/mod/scripts/vscripts
parent8c26a0b08d8327d6db14718754ff1b44e476acd2 (diff)
downloadNorthstarMods-41a3025396e05c960ce972ed83e9c9e0a9c70e9e.tar.gz
NorthstarMods-41a3025396e05c960ce972ed83e9c9e0a9c70e9e.zip
Update private match map select menu (#194)
Diffstat (limited to 'Northstar.Client/mod/scripts/vscripts')
-rw-r--r--Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut442
1 files changed, 346 insertions, 96 deletions
diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
index 29daf0a8..edaf582e 100644
--- a/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
+++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_map_select.nut
@@ -5,163 +5,413 @@ global function MenuMapSelect_Init
global function InitMapsMenu
+
+const int BUTTONS_PER_PAGE = 4
+
+
+struct {
+ int deltaX = 0
+ int deltaY = 0
+} mouseDeltaBuffer
+
struct {
int mapsPerPage = 21
int currentMapPage
+
+ array< var > gridButtons
+ array< string > mapsArrayFiltered
+
+ int scrollOffset = 0
+
+ var menu
} 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()
+
+
+
+void function MenuMapSelect_Init()
{
RegisterSignal( "OnCloseMapsMenu" )
}
void function InitMapsMenu()
{
- var menu = GetMenu( "MapsMenu" )
+ file.menu = GetMenu( "MapsMenu" )
+
+ AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer )
+
+
+ AddMenuEventHandler( file.menu, eUIEvent.MENU_CLOSE, OnCloseMapsMenu )
+ AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnOpenMapsMenu )
+
+
+
+ AddMenuFooterOption( file.menu, BUTTON_A, "#A_BUTTON_SELECT" )
+ AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
+
+ AddButtonEventHandler( Hud_GetChild( file.menu, "BtnMapGridUpArrow"), UIE_CLICK, OnUpArrowSelected )
+ AddButtonEventHandler( Hud_GetChild( file.menu, "BtnMapGridDownArrow"), UIE_CLICK, OnDownArrowSelected )
+
+ AddButtonEventHandler( Hud_GetChild( file.menu, "BtnFiltersClear"), UIE_CLICK, OnBtnFiltersClear_Activate )
+
+ AddButtonEventHandler( Hud_GetChild( file.menu, "SwtBtnHideLocked"), UIE_CHANGE, OnFiltersChanged )
+ AddButtonEventHandler( Hud_GetChild( file.menu, "BtnMapsSearch"), UIE_CHANGE, OnFiltersChanged )
+
+ RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnhideLocked")), "buttonText", "")
+
+ file.gridButtons = GetElementsByClassname( file.menu, "MapGridButtons" )
+
+ // uhh
+ foreach ( var mapButton in file.gridButtons )
+ {
+ var button = Hud_GetChild( mapButton, "MapButton" )
+ AddButtonEventHandler( button, UIE_CLICK, MapButton_Activate )
+ AddButtonEventHandler( button, UIE_GET_FOCUS, MapButton_Focus )
+ }
+
+
+ FilterMapsArray()
+}
- 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 )
+// https://youtu.be/VHi2wKBKBc4
- AddMenuFooterOption( menu, BUTTON_A, "#A_BUTTON_SELECT" )
- AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
+void function OnCloseMapsMenu()
+{
+ Signal( uiGlobal.signalDummy, "OnCloseMapsMenu" )
- 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 )
+ try
+ {
+ DeregisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp)
+ DeregisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown)
+ //DeregisterButtonPressedCallback(KEY_TAB , OnKeyTabPressed)
+ }
+ catch ( ex ) {}
}
void function OnOpenMapsMenu()
{
- if ( IsNorthstarServer() )
- file.mapsPerPage = 15
- else
- file.mapsPerPage = 21
+ RefreshList()
+
+ RegisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp)
+ RegisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown)
+ //RegisterButtonPressedCallback(KEY_TAB , OnKeyTabPressed)
+}
- UpdateVisibleMaps()
+void function RefreshList()
+{
+ file.scrollOffset = 0
+ FilterMapsArray()
+ UpdateMapsGrid()
+ if ( file.mapsArrayFiltered.len() != 0 )
+ UpdateMapsInfo( file.mapsArrayFiltered[0] )
+ UpdateListSliderHeight()
+ UpdateListSliderPosition()
+ UpdateNextMapInfo()
}
-void function UpdateVisibleMaps()
+void function OnFiltersChanged( var button )
{
- array<var> buttons = GetElementsByClassname( GetMenu( "MapsMenu" ), "MapButtonClass" )
- array<string> mapsArray = GetPrivateMatchMaps()
+ FilterMapsArray()
+ RefreshList()
+}
+
+void function MapButton_Activate( var button )
+{
+ if ( !AmIPartyLeader() && GetPartySize() > 1 )
+ return
+
+ int mapID = int( Hud_GetScriptID( Hud_GetParent( button ) ) )
+ string mapName = file.mapsArrayFiltered[ mapID + file.scrollOffset * 3 ]
+
+ if ( IsLocked( mapName ) )
+ return
+
+ printt( mapName, mapID )
- foreach ( button in buttons )
+ UpdateMapsInfo( mapName )
+ ClientCommand( "SetCustomMap " + mapName )
+ CloseActiveMenu()
+}
+
+void function MapButton_Focus( var button )
+{
+ int mapID = int( Hud_GetScriptID( Hud_GetParent( button ) ) )
+ string mapName = file.mapsArrayFiltered[ mapID + file.scrollOffset * 3 ]
+
+ UpdateMapsInfo( mapName )
+}
+
+void function OnBtnFiltersClear_Activate( var button )
+{
+ Hud_SetText( Hud_GetChild( file.menu, "BtnMapsSearch" ), "" )
+
+ SetConVarInt( "filter_map_hide_locked", 0 )
+
+ RefreshList()
+}
+
+void function UpdateMapsInfo( string map )
+{
+ RuiSetImage( Hud_GetRui( Hud_GetChild( file.menu, "NextMapImage" ) ), "basicImage", GetMapImageForMapName( map ) )
+ Hud_SetText( Hud_GetChild( file.menu, "NextMapDescription" ), GetMapDisplayDesc( map ) )
+ Hud_SetText( Hud_GetChild( file.menu, "NextMapName" ), GetMapDisplayName( map ) )
+}
+
+void function UpdateNextMapInfo()
+{
+ array< string > mapsArray = file.mapsArrayFiltered
+
+ if( !mapsArray.len() )
+ return
+
+ var nextMapName = Hud_GetChild( file.menu, "NextMapName" )
+ Hud_SetText( nextMapName, GetMapDisplayName( mapsArray[ 0 ] ) )
+}
+
+void function UpdateMapsGrid()
+{
+ HideAllMapButtons()
+
+ array< string > mapsArray = file.mapsArrayFiltered
+
+
+ int trueOffset = file.scrollOffset * 3
+
+ foreach ( int _index, var element in file.gridButtons )
{
- int buttonID = int( Hud_GetScriptID( button ) )
- int mapID = buttonID + ( file.currentMapPage * file.mapsPerPage )
+ if ( ( _index + trueOffset ) >= mapsArray.len() ) return
+
+ var mapImage = Hud_GetChild( element, "MapImage" )
+ var mapName = Hud_GetChild( element, "MapName" )
+
+ string name = mapsArray[ _index + trueOffset ]
+
+ RuiSetImage( Hud_GetRui( mapImage ), "basicImage", GetMapImageForMapName( name ) )
+ Hud_SetText( mapName, GetMapDisplayName( name ) )
+
+ if ( IsLocked( name ) )
+ LockMapButton( element )
+
+ MakeMapButtonVisible( element )
+ }
+}
- 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
+void function FilterMapsArray()
+{
+ file.mapsArrayFiltered.clear()
+
+ string searchTerm = Hud_GetUTF8Text( Hud_GetChild( file.menu, "BtnMapsSearch" ) )
+
+ bool useSearch = searchTerm != ""
+
+ bool hideLocked = bool( GetConVarInt( "filter_map_hide_locked" ) )
+
+ foreach ( string map in GetPrivateMatchMaps() )
+ {
+ bool containsTerm = Localize( GetMapDisplayName( map ) ).tolower().find( searchTerm.tolower() ) == null ? false : true
+
+ if ( hideLocked && !IsLocked( map ) && ( useSearch == true ? containsTerm : true ) )
{
- SetButtonRuiText( button, "" )
- Hud_SetEnabled( button, false )
+ file.mapsArrayFiltered.append( map )
}
-
- if ( mapID == level.ui.privatematch_map )
+ else if ( !hideLocked && ( useSearch == true ? containsTerm : true ) )
{
- printt( buttonID, mapsArray[buttonID] )
- Hud_SetFocused( button )
+ file.mapsArrayFiltered.append( map )
}
}
}
-void function OnCloseMapsMenu()
+void function HideAllMapButtons()
{
- Signal( uiGlobal.signalDummy, "OnCloseMapsMenu" )
+ foreach ( var element in file.gridButtons )
+ {
+ Hud_SetVisible( element, false )
+
+ var mapButton = Hud_GetChild( element, "MapButton" )
+ var mapFG = Hud_GetChild( element, "MapNameLockedForeground" )
+
+ Hud_SetLocked( mapButton, false )
+ Hud_SetVisible( mapFG, false )
+ }
}
-void function MapButton_Focused( var button )
+// :trol:
+void function MakeMapButtonVisible( var element )
{
- int mapID = int( Hud_GetScriptID( button ) ) + ( file.currentMapPage * file.mapsPerPage )
+ Hud_SetVisible( element, true )
+}
- var menu = GetMenu( "MapsMenu" )
- var nextMapImage = Hud_GetChild( menu, "NextMapImage" )
- var nextMapName = Hud_GetChild( menu, "NextMapName" )
- var nextMapDesc = Hud_GetChild( menu, "NextMapDesc" )
+void function LockMapButton( var element )
+{
+ var mapButton = Hud_GetChild( element, "MapButton" )
+ var mapFG = Hud_GetChild( element, "MapNameLockedForeground" )
+
+ Hud_SetVisible( mapButton, true )
+ Hud_SetVisible( mapFG, true )
+}
- array<string> mapsArray = GetPrivateMatchMaps()
- string mapName = mapsArray[ mapID ]
+bool function IsLocked( string map )
+{
+
+ bool sp = map.find( "sp_" ) == 0
+ if ( sp )
+ return true
- asset mapImage = GetMapImageForMapName( mapName )
- RuiSetImage( Hud_GetRui( nextMapImage ), "basicImage", mapImage )
- Hud_SetText( nextMapName, GetMapDisplayName( mapName ) )
+ if ( IsItemInEntitlementUnlock( map ) && IsValid( GetUIPlayer() ) )
+ {
+ if ( IsItemLocked( GetUIPlayer(), map ) && GetCurrentPlaylistVarInt( map + "_available" , 0 ) == 0 )
+ {
+ return true
+ }
+ }
+
+ return false
+}
- 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 ) )
+//////////////////////////////
+// Slider
+//////////////////////////////
+void function UpdateMouseDeltaBuffer(int x, int y)
+{
+ mouseDeltaBuffer.deltaX += x
+ mouseDeltaBuffer.deltaY += y
+ SliderBarUpdate()
}
-void function MapButton_LostFocus( var button )
+void function FlushMouseDeltaBuffer()
{
- HandleLockedCustomMenuItem( GetMenu( "MapsMenu" ), button, [], true )
+ mouseDeltaBuffer.deltaX = 0
+ mouseDeltaBuffer.deltaY = 0
}
-void function MapButton_Activate( var button )
+
+void function SliderBarUpdate()
{
- if ( Hud_IsLocked( button ) )
+ if ( file.mapsArrayFiltered.len() <= BUTTONS_PER_PAGE || file.mapsArrayFiltered.len() <= 12 )
+ {
+ FlushMouseDeltaBuffer()
return
+ }
- if ( !AmIPartyLeader() && GetPartySize() > 1 )
- return
+ var sliderButton = Hud_GetChild( file.menu , "BtnMapGridSlider" )
+ var sliderPanel = Hud_GetChild( file.menu , "BtnMapGridSliderPanel" )
+ var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
- array<string> mapsArray = GetPrivateMatchMaps()
- int mapID = int( Hud_GetScriptID( button ) )
- string mapName = mapsArray[ mapID + ( file.currentMapPage * file.mapsPerPage ) ]
+ Hud_SetFocused(sliderButton)
- printt( mapName, mapID )
+ float minYPos = -42.0 * (GetScreenSize()[1] / 1080.0)
+ float maxHeight = 582.0 * (GetScreenSize()[1] / 1080.0)
+ float maxYPos = minYPos - (maxHeight - Hud_GetHeight( sliderPanel ))
+ float useableSpace = ( maxHeight - Hud_GetHeight( sliderPanel ))
- ClientCommand( "SetCustomMap " + mapName )
- CloseActiveMenu()
+ float jump = minYPos - ( useableSpace / ( file.mapsArrayFiltered.len() / 3 + 1 ))
+
+ // got local from official respaw scripts, without untyped throws an error
+ local pos = Hud_GetPos(sliderButton)[1]
+ local newPos = pos - mouseDeltaBuffer.deltaY
+ FlushMouseDeltaBuffer()
+
+ if ( newPos < maxYPos ) newPos = maxYPos
+ if ( newPos > minYPos ) newPos = minYPos
+
+ Hud_SetPos( sliderButton , 2, newPos )
+ Hud_SetPos( sliderPanel , 2, newPos )
+ Hud_SetPos( movementCapture , 2, newPos )
+
+ file.scrollOffset = -int( ( (newPos - minYPos) / useableSpace ) * ( file.mapsArrayFiltered.len() / 3 + 1 - BUTTONS_PER_PAGE) )
+ UpdateMapsGrid()
}
-void function CycleModesBack( var button )
+void function UpdateListSliderHeight()
{
- if ( file.currentMapPage == 0 )
- return
+ var sliderButton = Hud_GetChild( file.menu , "BtnMapGridSlider" )
+ var sliderPanel = Hud_GetChild( file.menu , "BtnMapGridSliderPanel" )
+ var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
- file.currentMapPage--
- UpdateVisibleMaps()
+ float maps = float ( file.mapsArrayFiltered.len() / 3 )
+
+ float maxHeight = 582.0 * (GetScreenSize()[1] / 1080.0)
+ float minHeight = 80.0 * (GetScreenSize()[1] / 1080.0)
+
+ float height = maxHeight * ( float( BUTTONS_PER_PAGE ) / maps )
+
+ if ( height > maxHeight ) height = maxHeight
+ if ( height < minHeight ) height = minHeight
+
+ Hud_SetHeight( sliderButton , height )
+ Hud_SetHeight( sliderPanel , height )
+ Hud_SetHeight( movementCapture , height )
}
-void function CycleModesForward( var button )
+
+void function UpdateListSliderPosition()
{
- if ( ( file.currentMapPage + 1 ) * file.mapsPerPage >= GetPrivateMatchMaps().len() )
+ if ( file.mapsArrayFiltered.len() == 12 )
return
- file.currentMapPage++
- UpdateVisibleMaps()
+ var sliderButton = Hud_GetChild( file.menu , "BtnMapGridSlider" )
+ var sliderPanel = Hud_GetChild( file.menu , "BtnMapGridSliderPanel" )
+ var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" )
+
+ float maps = float ( file.mapsArrayFiltered.len() / 3 + 1 )
+
+ float minYPos = -42.0 * (GetScreenSize()[1] / 1080.0)
+ float useableSpace = (582.0 * (GetScreenSize()[1] / 1080.0) - Hud_GetHeight( sliderPanel ))
+
+ float jump = minYPos - ( useableSpace / ( maps - float( BUTTONS_PER_PAGE ) ) * file.scrollOffset )
+
+ //jump = jump * (GetScreenSize()[1] / 1080.0)
+
+ if ( jump > minYPos ) jump = minYPos
+
+ Hud_SetPos( sliderButton , 2, jump )
+ Hud_SetPos( sliderPanel , 2, jump )
+ Hud_SetPos( movementCapture , 2, jump )
+}
+
+void function OnDownArrowSelected( var button )
+{
+ if ( file.mapsArrayFiltered.len() <= BUTTONS_PER_PAGE || file.mapsArrayFiltered.len() <= 12 ) return
+ file.scrollOffset += 1
+ if ((file.scrollOffset + BUTTONS_PER_PAGE) * 3 > file.mapsArrayFiltered.len()) {
+ file.scrollOffset = (file.mapsArrayFiltered.len() - BUTTONS_PER_PAGE * 3) / 3 + 1
+ }
+ UpdateMapsGrid()
+ UpdateListSliderPosition()
+ printt(file.scrollOffset)
}
+
+
+void function OnUpArrowSelected( var button )
+{
+ file.scrollOffset -= 1
+ if (file.scrollOffset < 0) {
+ file.scrollOffset = 0
+ }
+ UpdateMapsGrid()
+ UpdateListSliderPosition()
+}
+
+void function OnScrollDown( var button )
+{
+ if ( file.mapsArrayFiltered.len() <= BUTTONS_PER_PAGE || file.mapsArrayFiltered.len() <= 12 ) return
+ file.scrollOffset += 2
+ if ((file.scrollOffset + BUTTONS_PER_PAGE) * 3 > file.mapsArrayFiltered.len()) {
+ file.scrollOffset = (file.mapsArrayFiltered.len() - BUTTONS_PER_PAGE * 3) / 3 + 1
+ }
+ UpdateMapsGrid()
+ UpdateListSliderPosition()
+}
+
+void function OnScrollUp( var button )
+{
+ file.scrollOffset -= 2
+ if (file.scrollOffset < 0) {
+ file.scrollOffset = 0
+ }
+ UpdateMapsGrid()
+ UpdateListSliderPosition()
+} \ No newline at end of file