diff options
author | F1F7Y <that.fifty@gmail.com> | 2022-01-19 18:05:53 +0100 |
---|---|---|
committer | Barichello <artur@barichello.me> | 2022-01-19 18:37:30 -0300 |
commit | 77b43a9199dd7f739181b487abe678b352fcadcb (patch) | |
tree | 01910a9a562183478aaf3c8c2eb10bab6c00aa33 | |
parent | 4d56ce9de9490bfe95e28f84eca6798a932dcc3b (diff) | |
download | NorthstarMods-77b43a9199dd7f739181b487abe678b352fcadcb.tar.gz NorthstarMods-77b43a9199dd7f739181b487abe678b352fcadcb.zip |
Rework mods menu
-rw-r--r-- | Northstar.Client/mod.json | 4 | ||||
-rw-r--r-- | Northstar.Client/mod/resource/northstar_client_localisation_english.txt | 11 | ||||
-rw-r--r-- | Northstar.Client/mod/resource/ui/menus/modlist.menu | 259 | ||||
-rw-r--r-- | Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut | 315 |
4 files changed, 564 insertions, 25 deletions
diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index d40d7ed0..809a54f6 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -23,6 +23,10 @@ { "Name": "filter_gamemode", "DefaultValue": "0" + }, + { + "Name": "filter_mods", + "DefaultValue": "0" } ], "Scripts": [ diff --git a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt index 96e4f04e..bafc9de9 100644 --- a/Northstar.Client/mod/resource/northstar_client_localisation_english.txt +++ b/Northstar.Client/mod/resource/northstar_client_localisation_english.txt @@ -287,5 +287,14 @@ Press Yes if you agree to this. This choice can be changed in the mods menu at a "CONNECTING" "Connecting..." "INGAME_PLAYERS" "Players:" "TOTAL_SERVERS" "Servers:" + + // Keybinds + "NORTHSTAR" "Northstar" + + // Mods menu + "SHOW" "Show" + "SHOW_ALL" "All" + "SHOW_ONLY_ENABLED" "Only Enabled" + "SHOW_ONLY_DISABLED" "Only Disabled" } -}
\ No newline at end of file +} diff --git a/Northstar.Client/mod/resource/ui/menus/modlist.menu b/Northstar.Client/mod/resource/ui/menus/modlist.menu index 682f643e..9584cf59 100644 --- a/Northstar.Client/mod/resource/ui/menus/modlist.menu +++ b/Northstar.Client/mod/resource/ui/menus/modlist.menu @@ -43,7 +43,16 @@ resource/ui/menus/mods_browse.menu xpos 120 ypos 160 } + + FilterButtonsRowAnchor + { + ControlName Label + labelText "" + xpos 90 + ypos 848 + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BtnMod1 @@ -228,9 +237,132 @@ resource/ui/menus/mods_browse.menu navUp BtnMod14 navDown BtnMod1 } + BtnMod16 + { + ControlName RuiButton + InheritProperties RuiSmallButton + classname ModButton + scriptID 15 + pin_to_sibling BtnMod15 + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + navUp BtnMod15 + navDown BtnMod17 + } + BtnMod17 + { + ControlName RuiButton + InheritProperties RuiSmallButton + classname ModButton + scriptID 16 + pin_to_sibling BtnMod16 + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + navUp BtnMod16 + navDown BtnMod18 + } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + FilterPanel + { + ControlName RuiPanel + wide 800 + tall 112 + xpos -8 + classname FilterPanelChild + rui "ui/knowledgebase_panel.rpak" + + visible 1 + zpos -1 + + pin_to_sibling FilterButtonsRowAnchor + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner TOP_LEFT + } + + BtnSearchLabel + { + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "#SEARCHBAR_LABEL" + textAlignment west + classname FilterPanelChild + + wide 500 + xpos -23 + ypos -16 + + wrap 1 + visible 1 + zpos 0 + + pin_to_sibling FilterButtonsRowAnchor + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner TOP_LEFT + } + + BtnModsSearch + { + ControlName TextEntry + classname FilterPanelChild + zpos 100 // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. + xpos -400 + ypos -5 + wide 390 + tall 30 + textHidden 0 + editable 1 + font Default_21 + allowRightClickMenu 0 + allowSpecialCharacters 0 + unicode 0 + + pin_to_sibling BtnSearchLabel + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner TOP_RIGHT + } + + SwtBtnShowFilter + { + ControlName RuiButton + InheritProperties SwitchButton + labelText "#SHOW" + ConVar "filter_mods" + classname FilterPanelChild + wide 500 + + list + { + "#SHOW_ALL" 0 + "#SHOW_ONLY_ENABLED" 1 + "#SHOW_ONLY_DISABLED" 2 + } + + pin_to_sibling BtnSearchLabel + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + BtnFiltersClear + { + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "#CLEAR_FILTERS" + classname FilterPanelChild + wide 100 + xpos -15 + ypos -55 + zpos 90 + + scriptID 999 + + pin_to_sibling FilterPanel + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner BOTTOM_RIGHT + } + LabelDetails { ControlName RuiPanel @@ -243,6 +375,133 @@ resource/ui/menus/mods_browse.menu visible 1 zpos 1 } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + BtnModListUpArrow + { + ControlName RuiButton + InheritProperties RuiSmallButton + //labelText "A" + wide 40 + tall 40 + xpos 2 + ypos 2 + + image "vgui/hud/white" + drawColor "255 255 255 128" + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + BtnModListUpArrowPanel + { + ControlName RuiPanel + wide 40 + tall 40 + xpos 2 + ypos 2 + + rui "ui/knowledgebase_panel.rpak" + + visible 1 + zpos -1 + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + BtnModListDownArrow + { + ControlName RuiButton + InheritProperties RuiSmallButton + //labelText "V" + wide 40 + tall 40 + xpos 2 + ypos -646 + + image "vgui/hud/white" + drawColor "255 255 255 128" + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + BtnModListDownArrowPanel + { + ControlName RuiPanel + wide 40 + tall 40 + xpos 2 + ypos -646 + + rui "ui/knowledgebase_panel.rpak" + + visible 1 + zpos -1 + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + BtnModListSlider + { + ControlName RuiButton + InheritProperties RuiSmallButton + //labelText "V" + wide 40 + tall 604 + xpos 2 + ypos -40 + zpos 0 + + image "vgui/hud/white" + drawColor "255 255 255 128" + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + BtnModListSliderPanel + { + ControlName RuiPanel + wide 40 + tall 604 + xpos 2 + ypos -40 + + rui "ui/knowledgebase_panel.rpak" + + visible 1 + zpos -1 + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } + + // sh_menu_models.gnut has a global function which gets called when + // left mouse button gets called while hovering and has mouse + // deltaX; deltaY which we can yoink for ourselfes + MouseMovementCapture + { + ControlName CMouseMovementCapturePanel + wide 40 + tall 604 + xpos 2 + ypos -40 + zpos 1 + + pin_to_sibling LabelDetails + pin_corner_to_sibling TOP_RIGHT + pin_to_sibling_corner TOP_LEFT + } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut index 6964c29d..83b92b3c 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut @@ -1,11 +1,38 @@ +untyped + global function AddNorthstarModMenu global function AddNorthstarModMenu_MainMenuFooter global function ReloadMods + +const int BUTTONS_PER_PAGE = 17 + + +struct modStruct { + int modIndex + string modName +} + +enum filterShow { + ALL = 0, + ONLY_ENABLED = 1, + ONLY_DISABLED = 2 +} + +struct { + int deltaX = 0 + int deltaY = 0 +} mouseDeltaBuffer + struct { bool shouldReloadModsOnEnd string currentMod var currentButton + int scrollOffset = 0 + + array<modStruct> modsArrayFiltered + + var menu } file void function AddNorthstarModMenu() @@ -26,40 +53,127 @@ void function AdvanceToModListMenu( var button ) void function InitModMenu() { - var menu = GetMenu( "ModListMenu" ) + file.menu = GetMenu( "ModListMenu" ) + + AddMouseMovementCaptureHandler( file.menu, UpdateMouseDeltaBuffer ) - AddMenuEventHandler( menu, eUIEvent.MENU_OPEN, OnModMenuOpened ) - AddMenuEventHandler( menu, eUIEvent.MENU_CLOSE, OnModMenuClosed ) - AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) + AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnModMenuOpened ) + AddMenuEventHandler( file.menu, eUIEvent.MENU_CLOSE, OnModMenuClosed ) + AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) AddMenuFooterOption( - menu, + file.menu, BUTTON_X, PrependControllerPrompts( BUTTON_X, "#RELOAD_MODS" ), "#RELOAD_MODS", OnReloadModsButtonPressed ) AddMenuFooterOption( - menu, + file.menu, BUTTON_BACK, PrependControllerPrompts( BUTTON_Y, "#AUTHENTICATION_AGREEMENT" ), "#AUTHENTICATION_AGREEMENT", OnAuthenticationAgreementButtonPressed ) - foreach ( var button in GetElementsByClassname( GetMenu( "ModListMenu" ), "ModButton" ) ) + foreach ( var button in GetElementsByClassname( file.menu, "ModButton" ) ) { AddButtonEventHandler( button, UIE_GET_FOCUS, OnModMenuButtonFocused ) AddButtonEventHandler( button, UIE_CLICK, OnModMenuButtonPressed ) } + + AddButtonEventHandler( Hud_GetChild( file.menu, "SwtBtnShowFilter"), UIE_CHANGE, OnFiltersChange ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModsSearch"), UIE_CHANGE, OnFiltersChange ) + + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModListUpArrow"), UIE_CLICK, OnUpArrowSelected ) + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnModListDownArrow"), UIE_CLICK, OnDownArrowSelected ) + + AddButtonEventHandler( Hud_GetChild( file.menu, "BtnFiltersClear"), UIE_CLICK, OnBtnFiltersClear_Activate ) + + // Nuke weird rui on filter switch + RuiSetString( Hud_GetRui( Hud_GetChild( file.menu, "SwtBtnShowFilter")), "buttonText", "") } void function OnModMenuOpened() { file.shouldReloadModsOnEnd = false + file.scrollOffset = 0 + + RegisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp) + RegisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown) + + Hud_SetText( Hud_GetChild( file.menu, "Title" ), "#MENU_TITLE_MODS" ) + + + OnFiltersChange(0) +} + +void function OnModMenuClosed() +{ + try + { + DeregisterButtonPressedCallback(MOUSE_WHEEL_UP , OnScrollUp) + DeregisterButtonPressedCallback(MOUSE_WHEEL_DOWN , OnScrollDown) + } + catch ( ex ) {} + + if ( file.shouldReloadModsOnEnd ) + ReloadMods() +} + +void function OnFiltersChange( var n ) +{ + file.scrollOffset = 0 + + HideAllButtons() + + RefreshModsArray() + + UpdateList() + + UpdateListSliderHeight() +} - Hud_SetText( Hud_GetChild( GetMenu( "ModListMenu" ), "Title" ), "#MENU_TITLE_MODS" ) +void function RefreshModsArray() +{ + string searchTerm = Hud_GetUTF8Text( Hud_GetChild( file.menu, "BtnModsSearch" ) ).tolower() + + file.modsArrayFiltered.clear() + + + bool useSearch = searchTerm != "" + + + array<string> modNames = NSGetModNames() + int modCount = modNames.len() + + foreach ( int index_, mod in modNames ) { + modStruct tempMod + tempMod.modIndex = index_ + tempMod.modName = mod + + int filter = GetConVarInt( "filter_mods" ) + bool enabled = NSIsModEnabled( tempMod.modName ) + + bool containsTerm = tempMod.modName.tolower().find(searchTerm) != null + + if ( filter == filterShow.ALL && (useSearch == true ? containsTerm : true ) ) + { + file.modsArrayFiltered.append( tempMod ) + } + else if ( filter == filterShow.ONLY_ENABLED && enabled && (useSearch == true ? containsTerm : true )) + { + file.modsArrayFiltered.append( tempMod ) + } + else if ( filter == filterShow.ONLY_DISABLED && !enabled && (useSearch == true ? containsTerm : true )) + { + file.modsArrayFiltered.append( tempMod ) + } + } +} - array<var> buttons = GetElementsByClassname( GetMenu( "ModListMenu" ), "ModButton" ) +void function HideAllButtons() +{ + array<var> buttons = GetElementsByClassname( file.menu, "ModButton" ) // disable all buttons, we'll enable the ones we need later foreach ( var button in buttons ) @@ -67,9 +181,16 @@ void function OnModMenuOpened() Hud_SetEnabled( button, false ) Hud_SetVisible( button, false ) } +} + +void function UpdateList() +{ + array<var> buttons = GetElementsByClassname( file.menu, "ModButton" ) - array<string> modNames = NSGetModNames() - for ( int i = 0; i < modNames.len() && i < buttons.len(); i++ ) + + int j = file.modsArrayFiltered.len() > 17 ? 17 : file.modsArrayFiltered.len() + + for ( int i = 0; i < j; i++ ) { Hud_SetEnabled( buttons[ i ], true ) Hud_SetVisible( buttons[ i ], true ) @@ -78,26 +199,20 @@ void function OnModMenuOpened() } } -void function OnModMenuClosed() -{ - if ( file.shouldReloadModsOnEnd ) - ReloadMods() -} - void function SetModMenuNameText( var button ) { - string modName = NSGetModNames()[ int ( Hud_GetScriptID( button ) ) ] + modStruct mod = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ] // should be localisation at some point - if ( NSIsModEnabled( modName ) ) - SetButtonRuiText( button, modName + " v" + NSGetModVersionByModName( modName ) ) + if ( NSIsModEnabled( mod.modName ) ) + SetButtonRuiText( button, mod.modName + " v" + NSGetModVersionByModName( mod.modName ) ) else - SetButtonRuiText( button, modName + " (DISABLED)" ) + SetButtonRuiText( button, mod.modName + " (DISABLED)" ) } void function OnModMenuButtonPressed( var button ) { - string modName = NSGetModNames()[ int ( Hud_GetScriptID( button ) ) ] + string modName = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ].modName if ( ( modName == "Northstar.Client" || modName == "Northstar.Coop" || modName == "Northstar.CustomServers") && NSIsModEnabled( modName ) ) { file.currentMod = modName @@ -141,9 +256,9 @@ void function DisableMod() void function OnModMenuButtonFocused( var button ) { - string modName = NSGetModNames()[ int ( Hud_GetScriptID( button ) ) ] + string modName = file.modsArrayFiltered[ int ( Hud_GetScriptID( button ) ) + file.scrollOffset ].modName - var rui = Hud_GetRui( Hud_GetChild( GetMenu( "ModListMenu" ), "LabelDetails" ) ) + var rui = Hud_GetRui( Hud_GetChild( file.menu, "LabelDetails" ) ) RuiSetGameTime( rui, "startTime", -99999.99 ) // make sure it skips the whole animation for showing this RuiSetString( rui, "headerText", modName ) @@ -212,4 +327,156 @@ void function ReloadMods() void function OnAuthenticationAgreementButtonPressed( var button ) { NorthstarMasterServerAuthDialog() +} + + +void function OnBtnFiltersClear_Activate( var button ) +{ + Hud_SetText( Hud_GetChild( file.menu, "BtnModsSearch" ), "" ) + + SetConVarInt( "filter_mods", 0 ) + + OnFiltersChange(0) +} + +////////////////////////////// +// Slider +////////////////////////////// +void function UpdateMouseDeltaBuffer(int x, int y) +{ + mouseDeltaBuffer.deltaX += x + mouseDeltaBuffer.deltaY += y + + SliderBarUpdate() +} + +void function FlushMouseDeltaBuffer() +{ + mouseDeltaBuffer.deltaX = 0 + mouseDeltaBuffer.deltaY = 0 +} + + +void function SliderBarUpdate() +{ + if ( file.modsArrayFiltered.len() <= 15 ) + { + FlushMouseDeltaBuffer() + return + } + + var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" ) + var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" ) + var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) + + Hud_SetFocused(sliderButton) + + float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0) + float maxHeight = 604.0 * (GetScreenSize()[1] / 1080.0) + float maxYPos = minYPos - (maxHeight - Hud_GetHeight( sliderPanel )) + float useableSpace = (maxHeight - Hud_GetHeight( sliderPanel )) + + float jump = minYPos - (useableSpace / ( float( file.modsArrayFiltered.len()))) + + // 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.modsArrayFiltered.len() - BUTTONS_PER_PAGE) ) + UpdateList() +} + +void function UpdateListSliderHeight() +{ + var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" ) + var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" ) + var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) + + float mods = float ( file.modsArrayFiltered.len() ) + + float maxHeight = 604.0 * (GetScreenSize()[1] / 1080.0) + float minHeight = 80.0 * (GetScreenSize()[1] / 1080.0) + + float height = maxHeight * ( float( BUTTONS_PER_PAGE ) / mods ) + + if ( height > maxHeight ) height = maxHeight + if ( height < minHeight ) height = minHeight + + Hud_SetHeight( sliderButton , height ) + Hud_SetHeight( sliderPanel , height ) + Hud_SetHeight( movementCapture , height ) +} + + +void function UpdateListSliderPosition() +{ + var sliderButton = Hud_GetChild( file.menu , "BtnModListSlider" ) + var sliderPanel = Hud_GetChild( file.menu , "BtnModListSliderPanel" ) + var movementCapture = Hud_GetChild( file.menu , "MouseMovementCapture" ) + + float mods = float ( file.modsArrayFiltered.len() ) + + float minYPos = -40.0 * (GetScreenSize()[1] / 1080.0) + float useableSpace = (604.0 * (GetScreenSize()[1] / 1080.0) - Hud_GetHeight( sliderPanel )) + + float jump = minYPos - (useableSpace / ( mods - 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.modsArrayFiltered.len() <= BUTTONS_PER_PAGE ) return + file.scrollOffset += 1 + if (file.scrollOffset + BUTTONS_PER_PAGE > file.modsArrayFiltered.len()) { + file.scrollOffset = file.modsArrayFiltered.len() - BUTTONS_PER_PAGE + } + UpdateList() + UpdateListSliderPosition() +} + + +void function OnUpArrowSelected( var button ) +{ + file.scrollOffset -= 1 + if (file.scrollOffset < 0) { + file.scrollOffset = 0 + } + UpdateList() + UpdateListSliderPosition() +} + +void function OnScrollDown( var button ) +{ + if ( file.modsArrayFiltered.len() <= BUTTONS_PER_PAGE ) return + file.scrollOffset += 5 + if (file.scrollOffset + BUTTONS_PER_PAGE > file.modsArrayFiltered.len()) { + file.scrollOffset = file.modsArrayFiltered.len() - BUTTONS_PER_PAGE + } + UpdateList() + UpdateListSliderPosition() +} + +void function OnScrollUp( var button ) +{ + file.scrollOffset -= 5 + if (file.scrollOffset < 0) { + file.scrollOffset = 0 + } + UpdateList() + UpdateListSliderPosition() }
\ No newline at end of file |