Skip to content

Commit

Permalink
refactor: remove NSIsModEnabled method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alystrasz committed Nov 20, 2024
1 parent e17454f commit 9c85d6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
18 changes: 0 additions & 18 deletions .github/nativefuncs.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
"returnTypeString":"array<ModInfo>",
"argTypes":""
},
{
"name":"NSIsModEnabled",
"helpText":"",
"returnTypeString":"bool",
"argTypes":"string modName"
},
{
"name":"NSSetModEnabled",
"helpText":"",
Expand Down Expand Up @@ -224,12 +218,6 @@
"returnTypeString":"array<string>",
"argTypes":""
},
{
"name":"NSIsModEnabled",
"helpText":"",
"returnTypeString":"bool",
"argTypes":"string modName"
},
{
"name":"NSSetModEnabled",
"helpText":"",
Expand Down Expand Up @@ -400,12 +388,6 @@
"returnTypeString":"array<ModInfo>",
"argTypes":"string modName"
},
{
"name":"NSIsModEnabled",
"helpText":"",
"returnTypeString":"bool",
"argTypes":"string modName"
},
{
"name":"NSSetModEnabled",
"helpText":"",
Expand Down
86 changes: 52 additions & 34 deletions Northstar.Client/mod/scripts/vscripts/ui/menu_ns_modmenu.nut
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void function OnModButtonFocused( var button )
Hud_SetVisible( linkButton, false )
}

SetControlBarColor( modName )
SetControlBarColor( file.lastMod )

bool required = file.lastMod.requiredOnClient
Hud_SetVisible( Hud_GetChild( file.menu, "WarningLegendLabel" ), required )
Expand All @@ -206,18 +206,33 @@ void function OnModButtonPressed( var button )
{
ModInfo mod = file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod
string modName = mod.name
if ( StaticFind( modName ) && NSIsModEnabled( modName ) )
if ( StaticFind( modName ) && mod.enabled )
CoreModToggleDialog( modName )
else
{
NSSetModEnabled( modName, !NSIsModEnabled( modName ) )
var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) - 1 ]
SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName )
SetControlBarColor( modName )
SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName )
// RefreshMods()
UpdateListSliderPosition()
UpdateListSliderHeight()
NSSetModEnabled( modName, !mod.enabled )

// retrieve state of the mod that just got toggled
array<ModInfo> infos = NSGetModInformation( mod.name )
foreach ( modInfo in infos )
{
if ( modInfo.name != modName || modInfo.version != mod.version )
{
continue
}

// Update UI mod state
file.mods[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) + file.scrollOffset - 1 ].mod = modInfo

var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( button ) ) ) - 1 ]
SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modInfo )
SetControlBarColor( modInfo )
SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modInfo )
// RefreshMods()
UpdateListSliderPosition()
UpdateListSliderHeight()
break
}
}
}

Expand Down Expand Up @@ -291,12 +306,23 @@ void function DisableMod()
string modName = mod.name
NSSetModEnabled( modName, false )

var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1]
SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modName )
SetControlBarColor( modName )
SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modName )
// retrieve state of the mod that just got toggled
array<ModInfo> infos = NSGetModInformation( mod.name )
foreach ( modInfo in infos )
{
if ( modInfo.name != modName || modInfo.version != mod.version )
{
continue
}

RefreshMods()
var panel = file.panels[ int ( Hud_GetScriptID( Hud_GetParent( file.currentButton ) ) ) - 1]
SetControlBoxColor( Hud_GetChild( panel, "ControlBox" ), modInfo )
SetControlBarColor( modInfo )
SetModEnabledHelperImageAsset( Hud_GetChild( panel, "EnabledImage" ), modInfo )

RefreshMods()
break
}
}

array<ModInfo> function GetEnabledModsArray()
Expand Down Expand Up @@ -431,53 +457,45 @@ void function DisplayModPanels()

Hud_SetVisible( headerLabel, false )

SetControlBoxColor( box, mod.name )
SetControlBoxColor( box, mod )
Hud_SetVisible( box, true )
Hud_SetVisible( line, false )

Hud_SetVisible( warning, mod.requiredOnClient )

SetModEnabledHelperImageAsset( enabledImage, c.mod.name )
SetModEnabledHelperImageAsset( enabledImage, c.mod )
}
Hud_SetVisible( panel, true )
}
}

void function SetModEnabledHelperImageAsset( var panel, string modName )
void function SetModEnabledHelperImageAsset( var panel, ModInfo mod )
{
if( NSIsModEnabled( modName ) )
if( mod.enabled )
RuiSetImage( Hud_GetRui( panel ), "basicImage", $"rui/menu/common/merit_state_success" )
else
RuiSetImage( Hud_GetRui( panel ), "basicImage", $"rui/menu/common/merit_state_failure" )
RuiSetFloat3(Hud_GetRui( panel ), "basicImageColor", GetControlColorForMod( modName ) )
RuiSetFloat3(Hud_GetRui( panel ), "basicImageColor", GetControlColorForMod( mod ) )
Hud_SetVisible( panel, true )
}

void function SetControlBoxColor( var box, string modName )
void function SetControlBoxColor( var box, ModInfo mod )
{
var rui = Hud_GetRui( box )
// if ( NSIsModEnabled( modName ) )
// RuiSetFloat3(rui, "basicImageColor", <0,1,0>)
// else
// RuiSetFloat3(rui, "basicImageColor", <1,0,0>)
RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( modName ) )
RuiSetFloat3(rui, "basicImageColor", GetControlColorForMod( mod ) )
}

void function SetControlBarColor( string modName )
void function SetControlBarColor( ModInfo mod )
{
var bar_element = Hud_GetChild( file.menu, "ModEnabledBar" )
var bar = Hud_GetRui( bar_element )
// if ( NSIsModEnabled( modName ) )
// RuiSetFloat3(bar, "basicImageColor", <0,1,0>)
// else
// RuiSetFloat3(bar, "basicImageColor", <1,0,0>)
RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( modName ) )
RuiSetFloat3(bar, "basicImageColor", GetControlColorForMod( mod ) )
Hud_SetVisible( bar_element, true )
}

vector function GetControlColorForMod( string modName )
vector function GetControlColorForMod( ModInfo mod )
{
if ( NSIsModEnabled( modName ) )
if ( mod.enabled )
switch ( GetConVarInt( "colorblind_mode" ) )
{
case 1:
Expand Down

0 comments on commit 9c85d6c

Please sign in to comment.