From e9b00c561e51b58d0c484371a1e698e24829d673 Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Thu, 17 Oct 2024 22:48:27 +0800 Subject: [PATCH 01/11] upload --- .../resource/ui/menus/panels/mainmenu.res | 20 + Northstar.Client/mod.json | 11 + .../mod/resource/ui/menus/colorsliders.menu | 587 ++++++++++++++++++ .../resource/ui/menus/panels/mod_setting.res | 43 ++ .../scripts/vscripts/ui/menu_mod_settings.nut | 176 +++++- .../vscripts/ui/menu_ns_color_picker.nut | 310 +++++++++ 6 files changed, 1146 insertions(+), 1 deletion(-) create mode 100644 Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res create mode 100644 Northstar.Client/mod/resource/ui/menus/colorsliders.menu create mode 100644 Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut diff --git a/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res b/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res new file mode 100644 index 000000000..5798ac1e3 --- /dev/null +++ b/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res @@ -0,0 +1,20 @@ +#base "../combo_buttons.res" +"resource/ui/menus/panels/mainmenu.res" +{ + // Quit Button + MainMenuButton0 + { + ControlName RuiButton + InheritProperties RuiSmallButton + classname MainMenuButtonClass + scriptID 0 + visible 0 + + navUp MainMenuButton6 + navDown MainMenuButton1 + + pin_to_sibling ButtonRow3x0 + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } +} \ No newline at end of file diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index 0d0cfc169..80a2c6063 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -50,6 +50,10 @@ { "Name": "modemenu_mode_filter", "DefaultValue": "-1" + }, + { + "Name": "modemenu_current_color_convar", + "DefaultValue": "" } ], "Scripts": [ @@ -130,6 +134,13 @@ "Path": "ui/ns_slider.nut", "RunOn": "UI" }, + { + "Path": "ui/menu_ns_color_picker.nut.nut", + "RunOn": "UI", + "UICallback": { + "After": "AddColorPickerMenu" + } + }, { "Path": "ui/menu_mod_settings.nut", "RunOn": "UI", diff --git a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu new file mode 100644 index 000000000..d3a48d18b --- /dev/null +++ b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu @@ -0,0 +1,587 @@ +resource/ui/menus/colorsliders.menu +{ + + menu + { + ControlName Frame + xpos 0 + ypos 0 + zpos 3 + wide f0 + tall f0 + autoResize 0 + pinCorner 0 + visible 1 + enabled 1 + tabPosition 0 + PaintBackgroundType 0 + infocus_bgcolor_override "0 0 0 0" + outoffocus_bgcolor_override "0 0 0 0" + modal 1 + + DarkenBackground + { + ControlName RuiButton + rui "ui/basic_image.rpak" + + wide %100 + tall %100 + bgcolor_override "0 0 0 255" + fgcolor_override "0 0 0 255" + visible 1 + scaleImage 1 + + } + + DialogFrame + { + ControlName RuiPanel + wide 600 + tall 400 + rui "ui/basic_image.rpak" + visible 1 + + pin_to_sibling DarkenBackground + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER + } + + DialogHeader + { + ControlName Label + xpos 130 + ypos -50 + labelText "#COLOR_MODE" + + wide 764 + tall 41 + visible 1 + labelText "" + font DefaultBold_41 + allcaps 1 + fgcolor_override "255 255 255 255" + + pin_to_sibling DialogFrame + pin_corner_to_sibling CENTER + pin_to_sibling_corner TOP + } + + Color + { + "ControlName" "ImagePanel" + "image" "vgui/white" + "scaleImage" "1" + "drawColor" "180 180 180 255" // vanilla label color + "visible" "1" + "wide" "600" + "tall" "20" + "enabled" "0" + + + "pin_to_sibling" DialogFrame + "pin_corner_to_sibling" TOP + "pin_to_sibling_corner" TOP + } + + DialogMessage + { + ControlName Label + classname DialogMessageClass + ypos 0 + wide 736 + auto_tall_tocontents 1 + visible 1 + labelText "Pink is my new favorite color." + font Default_28 + textAlignment north-west + wrap 1 + + pin_to_sibling DialogHeader + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + LabelR // A label that is placed in the middle of the screen + { + Classname LabelClass + + ControlName Label + xpos -15 + ypos 35 + labelText "R" + "scriptID" "0" + + auto_wide_tocontents 1 // Set width automatically relative to the label content + + pin_to_sibling DialogMessage + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + SliderR + { + Classname SliderClass + xpos 15 + "ControlName" "SliderControl" + "scriptID" "0" + + minValue 0 + maxValue 255 + stepSize 1 + drawColor "255 0 0 255" + + pin_to_sibling LabelR + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + //"navRight" "ResetModToDefault" + //"navLeft" "TextEntrySetting" + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide "320" + tall "45" + "labelText" "" + "auto_wide_tocontents" "0" + } + + "wide" "320" + "tall" "45" + } + + TextEntrySettingR + { + "ControlName" "TextEntry" + Classname TextEntrySettingClass + + "xpos" 20 + "ypos" "-5" + "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. + "wide" 30 + "tall" "30" + "scriptID" "0" + "textHidden" "0" + "editable" "1" + NumericInputOnly 1 + "font" "Default_21" + "allowRightClickMenu" "0" + "allowSpecialCharacters" "1" + "unicode" "0" + "scriptID" "0" + + pin_to_sibling SliderR + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + + + ResetModToDefaultR + { + Classname ResetModToDefaultClass + "ControlName" "RuiButton" + "InheritProperties" "RuiSmallButton" + "labelText" "" + "zpos" "0" + "xpos" "-100" + "wide" "45" + "tall" "45" + "scriptID" "0" + "pin_to_sibling" TextEntrySettingR + "pin_corner_to_sibling" "RIGHT" + "pin_to_sibling_corner" "LEFT" + + "enabled" "1" + + } + ResetModImageR + { + "ControlName" "ImagePanel" + "image" "vgui/reset" + "scaleImage" "1" + "drawColor" "180 180 180 255" // vanilla label color + "visible" "1" + "wide" "30" + "tall" "30" + "enabled" "0" + + "pin_to_sibling" ResetModToDefaultR + "pin_corner_to_sibling" "CENTER" + "pin_to_sibling_corner" "CENTER" + } + + + + + + + + + + + + + + + + LabelG // A label that is placed in the middle of the screen + { + Classname LabelClass + + ControlName Label + "scriptID" "1" + + ypos 25 + labelText "G" + + auto_wide_tocontents 1 // Set width automatically relative to the label content + + pin_to_sibling LabelR + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + SliderG + { + Classname SliderClass + + xpos 15 + "ControlName" "SliderControl" + "scriptID" "1" + + minValue 0 + maxValue 255 + stepSize 1 + drawColor "255 0 0 255" + + pin_to_sibling LabelG + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + //"navRight" "ResetModToDefault" + //"navLeft" "TextEntrySetting" + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide "320" + tall "45" + "labelText" "" + "auto_wide_tocontents" "0" + } + + "wide" "320" + "tall" "45" + } + + + TextEntrySettingG + { + "ControlName" "TextEntry" + Classname TextEntrySettingClass + + "xpos" 20 + "ypos" "-5" + "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. + "wide" 30 + "tall" "30" + "scriptID" "1" + + "textHidden" "0" + "editable" "1" + NumericInputOnly 1 + "font" "Default_21" + "allowRightClickMenu" "0" + "allowSpecialCharacters" "1" + "unicode" "0" + + pin_to_sibling SliderG + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + + ResetModToDefaultG + { + Classname ResetModToDefaultClass + + "enabled" "1" + + "ControlName" "RuiButton" + "InheritProperties" "RuiSmallButton" + "labelText" "" + "zpos" "0" + "xpos" "-100" + "wide" "45" + "tall" "45" + "scriptID" "1" + + "pin_to_sibling" TextEntrySettingG + "pin_corner_to_sibling" "RIGHT" + "pin_to_sibling_corner" "LEFT" + } + ResetModImageG + { + "ControlName" "ImagePanel" + "image" "vgui/reset" + "scaleImage" "1" + "drawColor" "180 180 180 255" // vanilla label color + "visible" "1" + "wide" "30" + "tall" "30" + "enabled" "1" + + "pin_to_sibling" ResetModToDefaultG + "pin_corner_to_sibling" "CENTER" + "pin_to_sibling_corner" "CENTER" + } + + + + + + + LabelB // A label that is placed in the middle of the screen + { + Classname LabelClass + + + ControlName Label + "scriptID" "2" + + ypos 25 + labelText "B" + + auto_wide_tocontents 1 // Set width automatically relative to the label content + + pin_to_sibling LabelG + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + SliderB + { + Classname SliderClass + + xpos 15 + "ControlName" "SliderControl" + "scriptID" "2" + + minValue 0 + maxValue 255 + stepSize 1 + drawColor "255 0 0 255" + + pin_to_sibling LabelB + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + //"navRight" "ResetModToDefault" + //"navLeft" "TextEntrySetting" + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide "320" + tall "45" + "labelText" "" + "auto_wide_tocontents" "0" + } + + "wide" "320" + "tall" "45" + } + + TextEntrySettingB + { + Classname TextEntrySettingClass + + "ControlName" "TextEntry" + "xpos" 20 + "ypos" "-5" + "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. + "wide" 30 + "tall" "30" + "scriptID" "2" + + "textHidden" "0" + "editable" "1" + NumericInputOnly 1 + "font" "Default_21" + "allowRightClickMenu" "0" + "allowSpecialCharacters" "1" + "unicode" "0" + + pin_to_sibling SliderB + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + ResetModToDefaultB + { + Classname ResetModToDefaultClass + + "enabled" "1" + + "ControlName" "RuiButton" + "InheritProperties" "RuiSmallButton" + "labelText" "" + "zpos" "0" + "xpos" "-100" + "wide" "45" + "tall" "45" + "scriptID" "2" + + "pin_to_sibling" TextEntrySettingB + "pin_corner_to_sibling" "RIGHT" + "pin_to_sibling_corner" "LEFT" + } + ResetModImageB + { + "ControlName" "ImagePanel" + "image" "vgui/reset" + "scaleImage" "1" + "drawColor" "180 180 180 255" // vanilla label color + "visible" "1" + "wide" "30" + "tall" "30" + "enabled" "0" + + "pin_to_sibling" ResetModToDefaultB + "pin_corner_to_sibling" "CENTER" + "pin_to_sibling_corner" "CENTER" + } + + + + LabelA // A label that is placed in the middle of the screen + { + Classname LabelClass + + + ControlName Label + "scriptID" "3" + + ypos 25 + labelText "A" + + auto_wide_tocontents 1 // Set width automatically relative to the label content + + pin_to_sibling LabelB + pin_corner_to_sibling TOP_LEFT + pin_to_sibling_corner BOTTOM_LEFT + } + + SliderA + { + Classname SliderClass + + xpos 15 + "ControlName" "SliderControl" + "scriptID" "3" + + minValue 0 + maxValue 255 + stepSize 1 + drawColor "255 0 0 255" + + pin_to_sibling LabelA + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + //"navRight" "ResetModToDefault" + //"navLeft" "TextEntrySetting" + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide "320" + tall "45" + "labelText" "" + "auto_wide_tocontents" "0" + } + + "wide" "320" + "tall" "45" + } + + TextEntrySettingA + { + Classname TextEntrySettingClass + + "ControlName" "TextEntry" + "xpos" 20 + "ypos" "-5" + "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. + "wide" 30 + "tall" "30" + "scriptID" "3" + + "textHidden" "0" + "editable" "1" + NumericInputOnly 1 + "font" "Default_21" + "allowRightClickMenu" "0" + "allowSpecialCharacters" "1" + "unicode" "0" + + pin_to_sibling SliderA + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + ResetModToDefaultA + { + Classname ResetModToDefaultClass + + "enabled" "1" + + "ControlName" "RuiButton" + "InheritProperties" "RuiSmallButton" + "labelText" "" + "zpos" "0" + "xpos" "-100" + "wide" "45" + "tall" "45" + "scriptID" "3" + + "pin_to_sibling" TextEntrySettingA + "pin_corner_to_sibling" "RIGHT" + "pin_to_sibling_corner" "LEFT" + } + ResetModImageA + { + "ControlName" "ImagePanel" + "image" "vgui/reset" + "scaleImage" "1" + "drawColor" "180 180 180 255" // vanilla label color + "visible" "1" + "wide" "30" + "tall" "30" + "enabled" "0" + + "pin_to_sibling" ResetModToDefaultA + "pin_corner_to_sibling" "CENTER" + "pin_to_sibling_corner" "CENTER" + } + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + } + +} \ No newline at end of file diff --git a/Northstar.Client/mod/resource/ui/menus/panels/mod_setting.res b/Northstar.Client/mod/resource/ui/menus/panels/mod_setting.res index 92dce922d..b862caec5 100644 --- a/Northstar.Client/mod/resource/ui/menus/panels/mod_setting.res +++ b/Northstar.Client/mod/resource/ui/menus/panels/mod_setting.res @@ -94,6 +94,47 @@ "navLeft" "ResetModToDefault" "navRight" "TextEntrySetting" } + "ColorPickerButton" + { + "ControlName" "RuiButton" + "InheritProperties" "RuiSmallButton" + "labelText" "#EDIT" + "zpos" "0" + "xpos" "10" + // ypos -10 + "wide" "320" + "tall" "45" + "scriptID" "0" + "pin_to_sibling" "BtnMod" + "pin_corner_to_sibling" "TOP_LEFT" + "pin_to_sibling_corner" "TOP_RIGHT" + + "navRight" "ResetModToDefault" + "navLeft" "TextEntrySetting" + + "visible" "0" + FocusColor "0 0 0 0" + textAlignment center + font Default_23 + wrap 0 + } + "ColorPickerImage" + { + "ControlName" "ImagePanel" + "image" "vgui/white" + "scaleImage" "1" + "drawColor" "255 255 255 255" // vanilla label color + "visible" "0" + "wide" "320" + "tall" "45" + "enabled" "0" + + ypos 0 + + "pin_to_sibling" "ColorPickerButton" + "pin_corner_to_sibling" RIGHT + "pin_to_sibling_corner" LEFT + } "ResetModToDefault" { "ControlName" "RuiButton" @@ -109,6 +150,8 @@ "pin_to_sibling_corner" "LEFT" "navLeft" "Slider" "navRight" "TextEntrySetting" + "navLeft" "ColorPickerButton" + } "ResetModImage" { diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index 8c13955cc..417cad55c 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -8,6 +8,10 @@ global function ModSettings_AddModTitle global function ModSettings_AddModCategory global function PureModulo +global function ModSettings_AddColorSetting +global function ModSettings_AddAlphaSetting +global function TryUpdateModSettingLists + // Legacy functions for backwards compatability. These will be removed eventually global function AddConVarSetting global function AddConVarSettingEnum @@ -154,6 +158,13 @@ void function InitModMenu() Hud_AddEventHandler( child, UIE_CLICK, ResetConVar ) file.resetModButtons.append(child) + // color nav + child = Hud_GetChild( panel, "ColorPickerButton" ) + Hud_AddEventHandler( child, UIE_CLICK, ColorButtonPressed ) + child.SetNavUp( Hud_GetChild( file.modPanels[ int( PureModulo( i - 1, len ) ) ], "ColorPickerButton" ) ) + child.SetNavDown( Hud_GetChild( file.modPanels[ int( PureModulo( i + 1, len ) ) ], "ColorPickerButton" ) ) + + // text field nav child = Hud_GetChild( panel, "TextEntrySetting" ) @@ -520,9 +531,17 @@ void function SetModMenuNameText( var button ) var modTitle = Hud_GetChild( panel, "ModTitle" ) var customMenuButton = Hud_GetChild( panel, "OpenCustomMenu") var slider = Hud_GetChild( panel, "Slider" ) + + var colorButton = Hud_GetChild( panel, "ColorPickerButton" ) + var colorVGUI = Hud_GetChild( panel, "ColorPickerImage" ) + + Hud_SetVisible( slider, false ) Hud_SetEnabled( slider, true ) - + Hud_SetVisible( colorButton, false ) + Hud_SetVisible( colorVGUI, false ) + Hud_SetEnabled( colorButton, false ) + Hud_SetEnabled( colorVGUI, false ) if ( conVar.isEmptySpace ) { @@ -631,6 +650,54 @@ void function SetModMenuNameText( var button ) Hud_SetVisible( textField, true ) Hud_SetVisible( resetButton, true ) Hud_SetVisible( resetVGUI, true ) + + // color + if (conVar.type == "color") + { + try { + table color = StringToColors( GetConVarString(conVar.conVar) ) + Hud_SetVisible( colorButton, true ) + Hud_SetVisible( colorVGUI, true ) + Hud_SetEnabled( colorButton, true ) + Hud_SetEnabled( colorVGUI, true ) + Hud_SetSize( label, int(scaleX * (375 + 85)), int(scaleY * 40) ) + Hud_SetSize( colorVGUI, int( scaleX * ( 50 ) ), int( scaleY * 20 ) ) + Hud_SetSize( colorButton, int( scaleX * ( 300 ) ), int( scaleY * 35 ) ) + + Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + // Hud_ColorOverTime(colorVGUI, color.r, color.g, color.b, color.a, 1, 1) + } + catch ( ex ) + { + printt(ex) + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") + + Hud_SetSize( colorVGUI, 0, int( 45 * scaleY ) ) + Hud_SetSize( colorButton, 0, int( 45 * scaleY ) ) + Hud_SetEnabled( colorButton, false ) + Hud_SetEnabled( colorVGUI, false ) + Hud_SetColor(colorVGUI, 0, 0, 0, 0) + } + } + else if (conVar.type == "alpha") { + Hud_SetVisible( colorVGUI, true ) + Hud_SetEnabled( colorVGUI, true ) + Hud_SetSize( colorVGUI, int( scaleX * ( 20 ) ), int( scaleY * 20 ) ) + + float alpha = GetConVarFloat(conVar.conVar) + Hud_SetColor(colorVGUI, 124, 252, 0, 255) + Hud_SetAlpha(colorVGUI, int(alpha * 255)) + + } + else + { + Hud_SetSize( colorVGUI, 0, int( 45 * scaleY ) ) + Hud_SetSize( colorButton, 0, int( 45 * scaleY ) ) + Hud_SetEnabled( colorButton, false ) + Hud_SetEnabled( colorVGUI, false ) + Hud_SetColor(colorVGUI, 0, 0, 0, 0) + + } } } @@ -848,6 +915,45 @@ void function AddConVarSetting( string conVar, string displayName, string type = ModSettings_AddSetting( conVar, displayName, type, stackPos + 1 ) } +void function ModSettings_AddColorSetting(string conVar, string buttonLabel, void functionref() onPress = null, int stackPos = 2) +{ + if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) || !file.setFuncs[ expect string( getstackinfos( stackPos )[ "func" ] ) ] ) + throw getstackinfos( stackPos )[ "src" ] + " #" + getstackinfos( stackPos )[ "line" ] + "\nCannot add a button before a category and mod title!" + + ConVarData data + + + data.conVar = conVar + data.type = "color" + data.displayName = buttonLabel + data.modName = file.currentMod + data.catName = file.currentCat + data.onPress = onPress + + file.conVarList.append( data ) +} + +void function ModSettings_AddAlphaSetting(string conVar, string displayName, int stackPos = 2) +{ + if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) || !file.setFuncs[ expect string( getstackinfos( stackPos )[ "func" ] ) ] ) + throw getstackinfos( stackPos )[ "src" ] + " #" + getstackinfos( stackPos )[ "line" ] + "\nCannot add a button before a category and mod title!" + + ConVarData data + + data.catName = file.currentCat + data.conVar = conVar + data.modName = file.currentMod + data.displayName = displayName + data.type = "alpha" + data.sliderEnabled = true + data.forceClamp = false + data.min = 0 + data.max = 1 + data.stepSize = 0.05 + + file.conVarList.append( data ) +} + void function ModSettings_AddSliderSetting( string conVar, string displayName, float min = 0.0, float max = 1.0, float stepSize = 0.1, bool forceClamp = false, int stackPos = 2 ) { if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) || !file.setFuncs[ expect string( getstackinfos( stackPos )[ "func" ] ) ] ) @@ -926,11 +1032,22 @@ void function OnSliderChange( var button ) MS_Slider_SetValue( file.sliders[ int( Hud_GetScriptID( Hud_GetParent( textPanel ) ) ) ], val ) Hud_SetText( textPanel, string( GetConVarFloat( c.conVar ) ) ) + + if (c.type == "alpha") { + var colorVGUI = Hud_GetChild( Hud_GetParent( textPanel ), "ColorPickerImage" ) + + float alpha = GetConVarFloat(c.conVar) + Hud_SetAlpha(colorVGUI, int(alpha * 255)) + // Hud_SetColor(colorVGUI, 255, 255, 255, 255) + } } void function SendTextPanelChanges( var textPanel ) { ConVarData c = file.filteredList[ int( Hud_GetScriptID( Hud_GetParent( textPanel ) ) ) + file.scrollOffset ] + var colorButton = Hud_GetChild( Hud_GetParent( textPanel ), "ColorPickerButton" ) + var colorVGUI = Hud_GetChild( Hud_GetParent( textPanel ), "ColorPickerImage" ) + if ( c.conVar == "" ) return // enums don't need to do this if ( !c.isEnumSetting ) @@ -1022,6 +1139,37 @@ void function SendTextPanelChanges( var textPanel ) Hud_SetText( textPanel, GetConVarString( c.conVar ) ) } break + case "color": + try { + table color = StringToColors( GetConVarString(c.conVar) ) + Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + } + catch ( ex ) + { + printt(ex) + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") + Hud_SetColor(colorVGUI, 0, 0, 0, 0) + } + break + case "alpha": + try + { + SetConVarFloat( c.conVar, newSetting.tofloat() ) + } + catch ( ex ) + { + printt( ex ) + ThrowInvalidValue( "This setting is a float, and only accepts a number - we could not parse this!\n\n( Use \".\" for the floating point, not \",\". )" ) + } + if ( c.sliderEnabled ) + { + var panel = Hud_GetParent( textPanel ) + MS_Slider s = file.sliders[ int ( Hud_GetScriptID( panel ) ) ] + + MS_Slider_SetValue( s, GetConVarFloat( c.conVar ) ) + } + Hud_SetAlpha(colorVGUI, int(newSetting * 255)) + break default: SetConVarString( c.conVar, newSetting ) break; @@ -1104,3 +1252,29 @@ string function SanitizeDisplayName( string displayName ) } return result } + +// nothing in the game uses the format "Table.r/g/b/a"... wtf is the point of this function +table function StringToColors( string colorString, string delimiter = " " ) +{ + PerfStart( PerfIndexShared.StringToColors + SharedPerfIndexStart ) + array tokens = split( colorString, delimiter ) + + Assert( tokens.len() >= 3 ) + + table Table = {} + Table.r <- int( tokens[0] ) + Table.g <- int( tokens[1] ) + Table.b <- int( tokens[2] ) + + if ( tokens.len() == 4 ) + Table.a <- int( tokens[3] ) + else + Table.a <- 255 + + PerfEnd( PerfIndexShared.StringToColors + SharedPerfIndexStart ) + return Table +} + +void function TryUpdateModSettingLists() { + UpdateList() +} \ No newline at end of file diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut new file mode 100644 index 000000000..4c8de4fca --- /dev/null +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -0,0 +1,310 @@ +untyped +global function AddColorPickerMenu + + + +struct { + var menu + + + array sliders + array labels + array textFields + array resets + + array color + + var colorPicker + var colorImage +} file + +void function AddColorPickerMenu() +{ + AddSubmenu( "ColorPicker", $"resource/ui/menus/colorsliders.menu" ) + + + file.colorPicker = GetMenu( "ColorPicker" ) + file.colorImage = Hud_GetChild( file.colorPicker, "Color" ) + + var frameElem = Hud_GetChild( file.colorPicker, "DialogFrame" ) + RuiSetImage( Hud_GetRui( frameElem ), "basicImage", $"rui/menu/common/dialog_gradient" ) + RuiSetFloat3( Hud_GetRui( frameElem ), "basicImageColor", < 1, 1, 1 > ) + + // AddMenuFooterOption( file.colorPicker, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) + + var screen = Hud_GetChild( file.colorPicker, "DarkenBackground" ) + Hud_AddEventHandler( screen, UIE_CLICK, OnScreen_BGActivate ) + var rui = Hud_GetRui( screen ) + RuiSetFloat( rui, "basicImageAlpha", 0.0 ) + + + + AddMenuEventHandler( file.colorPicker, eUIEvent.MENU_OPEN, OnColorPickerOpen ) + AddMenuEventHandler( file.colorPicker, eUIEvent.MENU_CLOSE, OnColorPickerClose ) + // AddMenuEventHandler( file.colorPicker, eUIEvent.MENU_NAVIGATE_BACK, OnColorPickerClose ) + + file.labels = GetElementsByClassname( file.colorPicker, "LabelClass" ) + + file.sliders = [] + foreach (child in GetElementsByClassname( file.colorPicker, "SliderClass" )) { + + MS_Slider slider = MS_Slider_Setup( child ) + MS_Slider_SetMin( slider, 0 ) + MS_Slider_SetMax( slider, 255 ) + MS_Slider_SetStepSize( slider, 1 ) + + file.sliders.append(slider) + Hud_AddEventHandler( child, UIE_CHANGE, OnSliderChange ) + } + + + file.textFields = GetElementsByClassname( file.colorPicker, "TextEntrySettingClass" ) + foreach (value in file.textFields) { + Hud_AddEventHandler( value, UIE_LOSE_FOCUS, SendTextPanelChanges ) + } + + file.resets = GetElementsByClassname( file.colorPicker, "ResetModToDefaultClass" ) + foreach (value in file.resets) { + Hud_AddEventHandler( value, UIE_CLICK, void function (var _button) { + int index = int(Hud_GetScriptID(_button)) + ResetColor(index) + printt("Try to reset color", index) + } ) + } + +} + + +void function OnColorPickerOpen() { + array < int > c = ColorsFromConvar() + if (c.len() >= 3) { + + for (int i = 0; i < c.len(); i++) { + MS_Slider slider = file.sliders[i] + var textPanel = file.textFields[i] + MS_Slider_SetValue(slider, c[i].tofloat()) + Hud_SetText( textPanel, string(c[i]) ) + } + + int alpha = c.len() == 4 ? c[3] : 255 + Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + file.color = c + printt("ColorPicker Read ConVar", GetConVarString("ModSettings.current_color_convar"), "With Value:", GetConVarString(GetConVarString("ModSettings.current_color_convar")), ",Parsed To:", + c[0], c[1], c[2], alpha) + + } +} + +void function OnColorPickerClose() { + printt("Trying to close Color Picker") + + ColorsToConvar() + // SetConVarString("ModSettings.current_color_convar", "") + // printt(uiGlobal.activeMenu) + // PrintMenuStack() + // CloseColorPicker() + file.color = [] + TryUpdateModSettingLists() + // if (uiGlobal.menuStack[0] == GetActiveMenu() || file.colorPicker == GetActiveMenu()) { + // { + // CloseMenu( file.colorPicker ) + // uiGlobal.menuStack.pop() + // printt(1) + // OpenMenuWrapper( GetMenu( "ModSettings" ), false ) + // printt(2) + + // // if ( uiGlobal.menuStack.len() ) + // // uiGlobal.activeMenu = uiGlobal.menuStack.top() + // // else + // // uiGlobal.activeMenu = null + + // // if (uiGlobal.activeMenu && uiGlobal.activeMenu == GetMenu( "ModSettings" )) + // // { + // // if ( uiGlobal.activeMenu.GetType() == "submenu" ) + // // { + // // Hud_SetFocused( uiGlobal.menuData[ uiGlobal.activeMenu ].lastFocus ) + // // } + // // else if ( openStackMenu ) + // // { + // // OpenMenuWrapper( uiGlobal.activeMenu, false ) + + // // if ( updateBlur && !IsLobby() && !uiGlobal.mapSupportsMenuModels ) + // // SetBlurEnabled( true ) + // // } + // // } + + // // Signal( uiGlobal.signalDummy, "ActiveMenuChanged" ) + + + // } + + + // // CloseActiveMenu() + // } +} + +void function SendTextPanelChanges( var textPanel ) +{ + array < int > c = ColorsFromConvar() + + try { + int index = int(Hud_GetScriptID(textPanel)) + MS_Slider slider = file.sliders[index] + + int val = int(Hud_GetUTF8Text( textPanel )) + c[index] = val + + MS_Slider_SetValue(slider, c[index].tofloat()) + + UpdateColor() + } catch (ex){ + printt("Failed to SendTextPanelChanges", ex) + ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + + } + +} + +void function OnSliderChange( var button ) +{ + int index = int(Hud_GetScriptID(button)) + array < int > c = ColorsFromConvar() + + + try { + var textPanel = file.textFields[index] + + int val = int(Hud_SliderControl_GetCurrentValue( button )) + c[index] = val + + Hud_SetText( textPanel, string( val ) ) + UpdateColor() + } catch (exception){ + printt("Failed to OnSliderChange", exception, index, file.textFields.len(), c.len(), file.sliders.len(), button) + ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + + CloseActiveMenu() + } +} + +// write to convar +void function UpdateColor() +{ + + try { + ColorsToConvar() + + array < int > c = ColorsFromConvar() + int alpha = c.len() == 4 ? c[3] : 255 + + Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + } + catch ( ex ) + { + printt("Failed to UpdateColor", ex) + ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + } +} +void function ResetColors() { + for (int i = 0; i < 4; i++) { + ResetColor(i) + } +} + +void function ResetColor(int index) +{ + array < int > c = file.color + if (c.len() >= 3) { + var textPanel = file.textFields[index] + MS_Slider slider = file.sliders[index] + + Hud_SetText( textPanel, string(c[index]) ) + MS_Slider_SetValue(slider, c[index].tofloat()) + + int alpha = c.len() == 4 ? c[3] : 255 + Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + + UpdateColor() + + } +} + + + + +array function ColorsFromConvar() +{ + string convar = GetConVarString("ModSettings.current_color_convar") + array c + if (convar != "") { + try { + array tokens = split( GetConVarString(convar), " " ) + + // Assert(tokens.len() == 3) + if (tokens.len() < 3) { + throw "Convar " + convar + ": " + GetConVarString(convar) + "is not a trio/four of numbers" + printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar)) + + } + + for (int i = 0; i < tokens.len(); i++) { + c.append(tokens[i].tointeger()) + } + + } + catch ( ex ) + { + printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar) , ex) + ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + } + } + + return c +} + +void function ColorsToConvar() +{ + string convar = GetConVarString("ModSettings.current_color_convar") + if (convar != "") { + try { + string str = "" + for (int i = 0; i < 4; i++) { + str += "" + int(Hud_GetUTF8Text( file.textFields[i] )) + if (i != 3) { + str += " " + } + } + + SetConVarString(convar, str) + printt("ColorPicker write ConVar", GetConVarString("ModSettings.current_color_convar"), "With " + str) + + } + catch ( ex ) + { + printt("Failed to ColorsToConvar. With Convar", convar, ":",GetConVarString(convar) , ex) + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + } + } +} + + + +void function ThrowInvalidValue( string desc ) +{ + DialogData dialogData + dialogData.header = "Invalid Value" + dialogData.image = $"ui/menu/common/dialog_error" + dialogData.message = desc + AddDialogButton( dialogData, "#OK" ) + OpenDialog( dialogData ) +} + +void function CloseColorPicker() { + CloseAllToTargetMenu(GetMenu("ModSettings")) +} + +void function OnScreen_BGActivate( var button ) +{ + CloseSubmenu() + printt("Close ColorPicker") +} From b678c9fc444d788880d5b62eada52c191eda378f Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Thu, 17 Oct 2024 23:00:55 +0800 Subject: [PATCH 02/11] remove mainmenus.res --- .../resource/ui/menus/panels/mainmenu.res | 20 ------------------- .../mod/resource/ui/menus/colorsliders.menu | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res diff --git a/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res b/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res deleted file mode 100644 index 5798ac1e3..000000000 --- a/Northstar.Client/keyvalues/resource/ui/menus/panels/mainmenu.res +++ /dev/null @@ -1,20 +0,0 @@ -#base "../combo_buttons.res" -"resource/ui/menus/panels/mainmenu.res" -{ - // Quit Button - MainMenuButton0 - { - ControlName RuiButton - InheritProperties RuiSmallButton - classname MainMenuButtonClass - scriptID 0 - visible 0 - - navUp MainMenuButton6 - navDown MainMenuButton1 - - pin_to_sibling ButtonRow3x0 - pin_corner_to_sibling TOP_LEFT - pin_to_sibling_corner BOTTOM_LEFT - } -} \ No newline at end of file diff --git a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu index d3a48d18b..dd56327d8 100644 --- a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu +++ b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu @@ -91,7 +91,7 @@ resource/ui/menus/colorsliders.menu wide 736 auto_tall_tocontents 1 visible 1 - labelText "Pink is my new favorite color." + labelText "" font Default_28 textAlignment north-west wrap 1 From 0a7ddef612af8b944b36716bb638e516a33e57cc Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Fri, 18 Oct 2024 19:51:50 +0800 Subject: [PATCH 03/11] remove dup suffix --- Northstar.Client/mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index 80a2c6063..3042231e7 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -135,7 +135,7 @@ "RunOn": "UI" }, { - "Path": "ui/menu_ns_color_picker.nut.nut", + "Path": "ui/menu_ns_color_picker.nut", "RunOn": "UI", "UICallback": { "After": "AddColorPickerMenu" From 643583b97b83f2ef41ae38508aabed1403591a38 Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Fri, 18 Oct 2024 19:58:31 +0800 Subject: [PATCH 04/11] repair --- .../scripts/vscripts/ui/menu_mod_settings.nut | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index 417cad55c..a69701a3d 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -650,7 +650,7 @@ void function SetModMenuNameText( var button ) Hud_SetVisible( textField, true ) Hud_SetVisible( resetButton, true ) Hud_SetVisible( resetVGUI, true ) - + // color if (conVar.type == "color") { @@ -708,6 +708,19 @@ void function CustomButtonPressed( var button ) c.onPress() } +void function ColorButtonPressed( var button ) +{ + var panel = Hud_GetParent( button ) + ConVarData c = file.filteredList[ int( Hud_GetScriptID( panel ) ) + file.scrollOffset ] + // c.onPress() + // printt(c.displayName, c.type, c.conVar) + + SetConVarString("ModSettings.current_color_convar", c.conVar) + OpenSubmenu(GetMenu("ColorPicker"), false) + + // UpdateList() +} + void function OnScrollDown( var button ) { if ( file.filteredList.len() <= BUTTONS_PER_PAGE ) return @@ -849,7 +862,7 @@ void function ModSettings_AddModCategory( string catName, int stackPos = 2 ) { if ( !( getstackinfos( stackPos )[ "func" ] in file.setFuncs ) ) throw getstackinfos( stackPos )[ "src" ] + " #" + getstackinfos( stackPos )[ "line" ] + "\nCannot add a category before a mod title!" - + ConVarData space space.isEmptySpace = true space.modName = file.currentMod From 15a35153cb87178484a08819a579383e2ae2768b Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Fri, 18 Oct 2024 20:01:35 +0800 Subject: [PATCH 05/11] Update menu_mod_settings.nut --- Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index a69701a3d..42d68b28d 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -1181,7 +1181,8 @@ void function SendTextPanelChanges( var textPanel ) MS_Slider_SetValue( s, GetConVarFloat( c.conVar ) ) } - Hud_SetAlpha(colorVGUI, int(newSetting * 255)) + float alpha = GetConVarFloat(c.conVar) + Hud_SetAlpha(colorVGUI, int(alpha * 255)) break default: SetConVarString( c.conVar, newSetting ) From 955a76a5266b2747642851bc32784ddd2b01f372 Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Fri, 18 Oct 2024 20:30:31 +0800 Subject: [PATCH 06/11] rename convar --- .../mod/scripts/vscripts/ui/menu_mod_settings.nut | 2 +- .../mod/scripts/vscripts/ui/menu_ns_color_picker.nut | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index 42d68b28d..5fde6f19f 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -715,7 +715,7 @@ void function ColorButtonPressed( var button ) // c.onPress() // printt(c.displayName, c.type, c.conVar) - SetConVarString("ModSettings.current_color_convar", c.conVar) + SetConVarString("modemenu_current_color_convar", c.conVar) OpenSubmenu(GetMenu("ColorPicker"), false) // UpdateList() diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut index 4c8de4fca..66d687690 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -89,7 +89,7 @@ void function OnColorPickerOpen() { int alpha = c.len() == 4 ? c[3] : 255 Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) file.color = c - printt("ColorPicker Read ConVar", GetConVarString("ModSettings.current_color_convar"), "With Value:", GetConVarString(GetConVarString("ModSettings.current_color_convar")), ",Parsed To:", + printt("ColorPicker Read ConVar", GetConVarString("modemenu_current_color_convar"), "With Value:", GetConVarString(GetConVarString("modemenu_current_color_convar")), ",Parsed To:", c[0], c[1], c[2], alpha) } @@ -99,7 +99,7 @@ void function OnColorPickerClose() { printt("Trying to close Color Picker") ColorsToConvar() - // SetConVarString("ModSettings.current_color_convar", "") + // SetConVarString("modemenu_current_color_convar", "") // printt(uiGlobal.activeMenu) // PrintMenuStack() // CloseColorPicker() @@ -234,7 +234,7 @@ void function ResetColor(int index) array function ColorsFromConvar() { - string convar = GetConVarString("ModSettings.current_color_convar") + string convar = GetConVarString("modemenu_current_color_convar") array c if (convar != "") { try { @@ -264,7 +264,7 @@ array function ColorsFromConvar() void function ColorsToConvar() { - string convar = GetConVarString("ModSettings.current_color_convar") + string convar = GetConVarString("modemenu_current_color_convar") if (convar != "") { try { string str = "" @@ -276,7 +276,7 @@ void function ColorsToConvar() } SetConVarString(convar, str) - printt("ColorPicker write ConVar", GetConVarString("ModSettings.current_color_convar"), "With " + str) + printt("ColorPicker write ConVar", GetConVarString("modemenu_current_color_convar"), "With " + str) } catch ( ex ) From ed6f04b8e3cad40065e609f2efefbe1dd1ebd3ea Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Sat, 19 Oct 2024 14:44:14 +0800 Subject: [PATCH 07/11] Bugfix - Improve ColorPicker layout - Add clamp to values - Remove dialog while ColorPicker open which cause CTM - Fix ConVar not updated due to textfield --- .../mod/resource/ui/menus/colorsliders.menu | 53 +++++--- .../scripts/vscripts/ui/menu_mod_settings.nut | 79 ++++++++---- .../vscripts/ui/menu_ns_color_picker.nut | 117 +++++------------- 3 files changed, 125 insertions(+), 124 deletions(-) diff --git a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu index dd56327d8..d2dce026e 100644 --- a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu +++ b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu @@ -160,7 +160,7 @@ resource/ui/menus/colorsliders.menu "xpos" 20 "ypos" "-5" "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 30 + "wide" 50 "tall" "30" "scriptID" "0" "textHidden" "0" @@ -185,14 +185,16 @@ resource/ui/menus/colorsliders.menu "InheritProperties" "RuiSmallButton" "labelText" "" "zpos" "0" - "xpos" "-100" - "wide" "45" + "xpos" "10" + "wide" "75" "tall" "45" "scriptID" "0" "pin_to_sibling" TextEntrySettingR - "pin_corner_to_sibling" "RIGHT" - "pin_to_sibling_corner" "LEFT" + "pin_corner_to_sibling" "LEFT" + "pin_to_sibling_corner" "RIGHT" + "navLeft" "TextEntrySettingR" + "navRight" "SliderG" "enabled" "1" } @@ -287,7 +289,7 @@ resource/ui/menus/colorsliders.menu "xpos" 20 "ypos" "-5" "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 30 + "wide" 50 "tall" "30" "scriptID" "1" @@ -314,14 +316,18 @@ resource/ui/menus/colorsliders.menu "InheritProperties" "RuiSmallButton" "labelText" "" "zpos" "0" - "xpos" "-100" - "wide" "45" + "xpos" "10" + "wide" "75" "tall" "45" "scriptID" "1" "pin_to_sibling" TextEntrySettingG - "pin_corner_to_sibling" "RIGHT" - "pin_to_sibling_corner" "LEFT" + "pin_corner_to_sibling" "LEFT" + "pin_to_sibling_corner" "RIGHT" + + "navLeft" "TextEntrySettingG" + "navRight" "SliderB" + "enabled" "1" } ResetModImageG { @@ -405,7 +411,7 @@ resource/ui/menus/colorsliders.menu "xpos" 20 "ypos" "-5" "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 30 + "wide" 50 "tall" "30" "scriptID" "2" @@ -431,14 +437,18 @@ resource/ui/menus/colorsliders.menu "InheritProperties" "RuiSmallButton" "labelText" "" "zpos" "0" - "xpos" "-100" - "wide" "45" + "xpos" "10" + "wide" "75" "tall" "45" "scriptID" "2" "pin_to_sibling" TextEntrySettingB - "pin_corner_to_sibling" "RIGHT" - "pin_to_sibling_corner" "LEFT" + "pin_corner_to_sibling" "LEFT" + "pin_to_sibling_corner" "RIGHT" + + "navLeft" "TextEntrySettingB" + "navRight" "SliderA" + "enabled" "1" } ResetModImageB { @@ -519,7 +529,7 @@ resource/ui/menus/colorsliders.menu "xpos" 20 "ypos" "-5" "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 30 + "wide" 50 "tall" "30" "scriptID" "3" @@ -545,14 +555,17 @@ resource/ui/menus/colorsliders.menu "InheritProperties" "RuiSmallButton" "labelText" "" "zpos" "0" - "xpos" "-100" - "wide" "45" + "xpos" "10" + "wide" "75" "tall" "45" "scriptID" "3" "pin_to_sibling" TextEntrySettingA - "pin_corner_to_sibling" "RIGHT" - "pin_to_sibling_corner" "LEFT" + "pin_corner_to_sibling" "LEFT" + "pin_to_sibling_corner" "RIGHT" + + "navLeft" "TextEntrySettingA" + "enabled" "1" } ResetModImageA { diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index 5fde6f19f..945b68dbc 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -1154,26 +1154,64 @@ void function SendTextPanelChanges( var textPanel ) break case "color": try { - table color = StringToColors( GetConVarString(c.conVar) ) - Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + array split = split( newSetting, " " ) + if ( split.len() < 3 || split.len() > 4) + { + throw "" } - catch ( ex ) + + array color + string clampedNewSetting = "" + foreach (string val in split) { + int c = int(clamp(val.tointeger(), 0 ,255)) + color.append(c) + + clampedNewSetting += c + " " + } + + if (split.len() == 3) { - printt(ex) - ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") - Hud_SetColor(colorVGUI, 0, 0, 0, 0) + color.append(255) + clampedNewSetting += " 255" } + + Hud_SetColor(colorVGUI, color[0], color[1], color[2], color[3]) + Hud_SetText( textPanel, clampedNewSetting ) + SetConVarString( c.conVar, clampedNewSetting ) + + // table color = StringToColors( newSetting ) + // Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + // Hud_SetText( textPanel, newSetting ) + // SetConVarString( c.conVar, newSetting ) + } + catch ( ex ) + { + printt("Failed to send textField change, because:" + ex) + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") + + table color = StringToColors( GetConVarString( c.conVar ) ) + Hud_SetText( textPanel, GetConVarString( c.conVar ) ) + Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) // Hud_SetColor(colorVGUI, 0, 0, 0, 0) + } break case "alpha": try { - SetConVarFloat( c.conVar, newSetting.tofloat() ) + float alpha = clamp(newSetting.tofloat(), 0, 1.0) + + // if ( alpha < 0 || alpha > 1) { + // Hud_SetText( textPanel, GetConVarString( c.conVar ) ) + // throw "Alpha should be a float bewteen 0..1." + // } + Hud_SetAlpha(colorVGUI, int(alpha * 255)) + SetConVarFloat( c.conVar, alpha ) } catch ( ex ) { printt( ex ) - ThrowInvalidValue( "This setting is a float, and only accepts a number - we could not parse this!\n\n( Use \".\" for the floating point, not \",\". )" ) + ThrowInvalidValue( "This setting is a alpha(float), and only accepts a number - we could not parse this!\n\n( Use \".\" for the floating point, not \",\". )" ) } + if ( c.sliderEnabled ) { var panel = Hud_GetParent( textPanel ) @@ -1181,8 +1219,6 @@ void function SendTextPanelChanges( var textPanel ) MS_Slider_SetValue( s, GetConVarFloat( c.conVar ) ) } - float alpha = GetConVarFloat(c.conVar) - Hud_SetAlpha(colorVGUI, int(alpha * 255)) break default: SetConVarString( c.conVar, newSetting ) @@ -1270,22 +1306,23 @@ string function SanitizeDisplayName( string displayName ) // nothing in the game uses the format "Table.r/g/b/a"... wtf is the point of this function table function StringToColors( string colorString, string delimiter = " " ) { - PerfStart( PerfIndexShared.StringToColors + SharedPerfIndexStart ) - array tokens = split( colorString, delimiter ) - - Assert( tokens.len() >= 3 ) - table Table = {} - Table.r <- int( tokens[0] ) - Table.g <- int( tokens[1] ) - Table.b <- int( tokens[2] ) - + array tokens = split( colorString, " " ) + if ( tokens.len() < 3 || tokens.len() > 4) + { + throw "The length of tokens should be 3 or 4, but it is " + tokens.len() + } + + Table.r <- int( clamp(int( tokens[0] ),0,255) ) + Table.g <- int( clamp(int( tokens[1] ),0,255) ) + Table.b <- int( clamp(int( tokens[2] ),0,255) ) + if ( tokens.len() == 4 ) - Table.a <- int( tokens[3] ) + Table.a <- int( clamp(int( tokens[3] ),0,255) ) else Table.a <- 255 + - PerfEnd( PerfIndexShared.StringToColors + SharedPerfIndexStart ) return Table } diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut index 66d687690..41a7ea7ba 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -80,13 +80,16 @@ void function OnColorPickerOpen() { if (c.len() >= 3) { for (int i = 0; i < c.len(); i++) { - MS_Slider slider = file.sliders[i] + _MS_Slider slider = file.sliders[i] var textPanel = file.textFields[i] - MS_Slider_SetValue(slider, c[i].tofloat()) - Hud_SetText( textPanel, string(c[i]) ) + + + int val = int(clamp(c[i], 0, 255)) + _MS_Slider_SetValue(slider, val.tofloat()) + Hud_SetText( textPanel, string(val) ) } - int alpha = c.len() == 4 ? c[3] : 255 + int alpha = int(clamp(c.len() == 4 ? c[3] : 255, 0, 255)) Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) file.color = c printt("ColorPicker Read ConVar", GetConVarString("modemenu_current_color_convar"), "With Value:", GetConVarString(GetConVarString("modemenu_current_color_convar")), ",Parsed To:", @@ -99,92 +102,40 @@ void function OnColorPickerClose() { printt("Trying to close Color Picker") ColorsToConvar() - // SetConVarString("modemenu_current_color_convar", "") - // printt(uiGlobal.activeMenu) - // PrintMenuStack() - // CloseColorPicker() + file.color = [] TryUpdateModSettingLists() - // if (uiGlobal.menuStack[0] == GetActiveMenu() || file.colorPicker == GetActiveMenu()) { - // { - // CloseMenu( file.colorPicker ) - // uiGlobal.menuStack.pop() - // printt(1) - // OpenMenuWrapper( GetMenu( "ModSettings" ), false ) - // printt(2) - - // // if ( uiGlobal.menuStack.len() ) - // // uiGlobal.activeMenu = uiGlobal.menuStack.top() - // // else - // // uiGlobal.activeMenu = null - - // // if (uiGlobal.activeMenu && uiGlobal.activeMenu == GetMenu( "ModSettings" )) - // // { - // // if ( uiGlobal.activeMenu.GetType() == "submenu" ) - // // { - // // Hud_SetFocused( uiGlobal.menuData[ uiGlobal.activeMenu ].lastFocus ) - // // } - // // else if ( openStackMenu ) - // // { - // // OpenMenuWrapper( uiGlobal.activeMenu, false ) - - // // if ( updateBlur && !IsLobby() && !uiGlobal.mapSupportsMenuModels ) - // // SetBlurEnabled( true ) - // // } - // // } - - // // Signal( uiGlobal.signalDummy, "ActiveMenuChanged" ) - - - // } - - - // // CloseActiveMenu() - // } } void function SendTextPanelChanges( var textPanel ) { - array < int > c = ColorsFromConvar() - - try { - int index = int(Hud_GetScriptID(textPanel)) - MS_Slider slider = file.sliders[index] - - int val = int(Hud_GetUTF8Text( textPanel )) - c[index] = val + int newSetting = int(Hud_GetUTF8Text( textPanel )) + int index = int(Hud_GetScriptID(textPanel)) + try + { + newSetting = int(clamp(newSetting, 0, 255)) - MS_Slider_SetValue(slider, c[index].tofloat()) + _MS_Slider slider = file.sliders[index] + _MS_Slider_SetValue(slider, newSetting.tofloat()) UpdateColor() - } catch (ex){ - printt("Failed to SendTextPanelChanges", ex) - ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") - } - + catch ( ex ) + { + // ThrowInvalidValue( "This part of color is an integer, and only accepts whole numbers(0..1..255)." ) + ResetColor(index) + + } } void function OnSliderChange( var button ) { int index = int(Hud_GetScriptID(button)) - array < int > c = ColorsFromConvar() - - - try { - var textPanel = file.textFields[index] + int val = int(Hud_SliderControl_GetCurrentValue( button )) - int val = int(Hud_SliderControl_GetCurrentValue( button )) - c[index] = val - - Hud_SetText( textPanel, string( val ) ) - UpdateColor() - } catch (exception){ - printt("Failed to OnSliderChange", exception, index, file.textFields.len(), c.len(), file.sliders.len(), button) - ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") - - CloseActiveMenu() - } + var textPanel = file.textFields[index] + Hud_SetText( textPanel, string( val ) ) + UpdateColor() } // write to convar @@ -202,7 +153,7 @@ void function UpdateColor() catch ( ex ) { printt("Failed to UpdateColor", ex) - ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } } void function ResetColors() { @@ -243,19 +194,22 @@ array function ColorsFromConvar() // Assert(tokens.len() == 3) if (tokens.len() < 3) { throw "Convar " + convar + ": " + GetConVarString(convar) + "is not a trio/four of numbers" - printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar)) + // printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar)) } for (int i = 0; i < tokens.len(); i++) { - c.append(tokens[i].tointeger()) + c.append(int(clamp(tokens[i].tointeger(), 0, 255))) } + if (tokens.len() == 3) { + c.append(255) + } } catch ( ex ) { printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar) , ex) - ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } } @@ -276,13 +230,13 @@ void function ColorsToConvar() } SetConVarString(convar, str) - printt("ColorPicker write ConVar", GetConVarString("modemenu_current_color_convar"), "With " + str) + // printt("ColorPicker write ConVar", GetConVarString("modemenu_current_color_convar"), "With " + str) } catch ( ex ) { printt("Failed to ColorsToConvar. With Convar", convar, ":",GetConVarString(convar) , ex) - ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + // ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } } } @@ -299,9 +253,6 @@ void function ThrowInvalidValue( string desc ) OpenDialog( dialogData ) } -void function CloseColorPicker() { - CloseAllToTargetMenu(GetMenu("ModSettings")) -} void function OnScreen_BGActivate( var button ) { From f7d6674b242045d1468c4da0228a677d53f5000e Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Sat, 19 Oct 2024 14:48:26 +0800 Subject: [PATCH 08/11] Update menu_ns_color_picker.nut --- .../mod/scripts/vscripts/ui/menu_ns_color_picker.nut | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut index 41a7ea7ba..1d55e45ec 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -80,12 +80,12 @@ void function OnColorPickerOpen() { if (c.len() >= 3) { for (int i = 0; i < c.len(); i++) { - _MS_Slider slider = file.sliders[i] + MS_Slider slider = file.sliders[i] var textPanel = file.textFields[i] int val = int(clamp(c[i], 0, 255)) - _MS_Slider_SetValue(slider, val.tofloat()) + MS_Slider_SetValue(slider, val.tofloat()) Hud_SetText( textPanel, string(val) ) } @@ -115,8 +115,8 @@ void function SendTextPanelChanges( var textPanel ) { newSetting = int(clamp(newSetting, 0, 255)) - _MS_Slider slider = file.sliders[index] - _MS_Slider_SetValue(slider, newSetting.tofloat()) + MS_Slider slider = file.sliders[index] + MS_Slider_SetValue(slider, newSetting.tofloat()) UpdateColor() } From e9f0bfd90601b3214d5af6882b732463b8f3f6bb Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Mon, 21 Oct 2024 20:49:37 +0800 Subject: [PATCH 09/11] Use function parameters instead ConVar --- Northstar.Client/mod.json | 4 - .../mod/resource/ui/menus/colorsliders.menu | 16 ++ .../scripts/vscripts/ui/menu_mod_settings.nut | 14 +- .../vscripts/ui/menu_ns_color_picker.nut | 139 +++++++++++------- 4 files changed, 107 insertions(+), 66 deletions(-) diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index 3042231e7..eb96e79ab 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -50,10 +50,6 @@ { "Name": "modemenu_mode_filter", "DefaultValue": "-1" - }, - { - "Name": "modemenu_current_color_convar", - "DefaultValue": "" } ], "Scripts": [ diff --git a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu index d2dce026e..59c076333 100644 --- a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu +++ b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu @@ -33,6 +33,20 @@ resource/ui/menus/colorsliders.menu } + + DialogFrameButton + { + ControlName Label + wide 600 + tall 400 + // rui "ui/basic_image.rpak" + visible 1 + + pin_to_sibling DarkenBackground + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER + } + DialogFrame { ControlName RuiPanel @@ -46,6 +60,8 @@ resource/ui/menus/colorsliders.menu pin_to_sibling_corner CENTER } + + DialogHeader { ControlName Label diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index 945b68dbc..a6b251343 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -715,8 +715,8 @@ void function ColorButtonPressed( var button ) // c.onPress() // printt(c.displayName, c.type, c.conVar) - SetConVarString("modemenu_current_color_convar", c.conVar) - OpenSubmenu(GetMenu("ColorPicker"), false) + thread OpenColorPickerMenu(c.conVar, c.displayName) + // UpdateList() } @@ -1159,7 +1159,7 @@ void function SendTextPanelChanges( var textPanel ) { throw "" } - + array color string clampedNewSetting = "" foreach (string val in split) { @@ -1168,7 +1168,7 @@ void function SendTextPanelChanges( var textPanel ) clampedNewSetting += c + " " } - + if (split.len() == 3) { color.append(255) @@ -1312,16 +1312,16 @@ table function StringToColors( string colorString, string delimiter = " " ) { throw "The length of tokens should be 3 or 4, but it is " + tokens.len() } - + Table.r <- int( clamp(int( tokens[0] ),0,255) ) Table.g <- int( clamp(int( tokens[1] ),0,255) ) Table.b <- int( clamp(int( tokens[2] ),0,255) ) - + if ( tokens.len() == 4 ) Table.a <- int( clamp(int( tokens[3] ),0,255) ) else Table.a <- 255 - + return Table } diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut index 1d55e45ec..8fbf93130 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -1,10 +1,11 @@ untyped global function AddColorPickerMenu +global function OpenColorPickerMenu struct { - var menu + var subTitle array sliders @@ -16,6 +17,9 @@ struct { var colorPicker var colorImage + + string conVar + string displayName } file void function AddColorPickerMenu() @@ -25,6 +29,7 @@ void function AddColorPickerMenu() file.colorPicker = GetMenu( "ColorPicker" ) file.colorImage = Hud_GetChild( file.colorPicker, "Color" ) + file.subTitle = Hud_GetChild( file.colorPicker, "DialogMessage" ) var frameElem = Hud_GetChild( file.colorPicker, "DialogFrame" ) RuiSetImage( Hud_GetRui( frameElem ), "basicImage", $"rui/menu/common/dialog_gradient" ) @@ -32,11 +37,14 @@ void function AddColorPickerMenu() // AddMenuFooterOption( file.colorPicker, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) + // RuiButton here due to close action var screen = Hud_GetChild( file.colorPicker, "DarkenBackground" ) - Hud_AddEventHandler( screen, UIE_CLICK, OnScreen_BGActivate ) - var rui = Hud_GetRui( screen ) - RuiSetFloat( rui, "basicImageAlpha", 0.0 ) - + Hud_AddEventHandler( screen, UIE_CLICK, void function( var _button ) + { + CloseSubmenu() + printt("Close ColorPicker By Clicking Outside The ColorPicker Menu") + } ) + RuiSetFloat( Hud_GetRui( screen ), "basicImageAlpha", 0.0 ) AddMenuEventHandler( file.colorPicker, eUIEvent.MENU_OPEN, OnColorPickerOpen ) @@ -76,7 +84,17 @@ void function AddColorPickerMenu() void function OnColorPickerOpen() { - array < int > c = ColorsFromConvar() + string conVar = file.conVar + string displayName = file.displayName + + if (conVar == "") + { + CloseSubmenu() + return + } + + Hud_SetText(file.subTitle, displayName) + array < int > c = ColorsFromConvar(conVar) if (c.len() >= 3) { for (int i = 0; i < c.len(); i++) { @@ -92,7 +110,8 @@ void function OnColorPickerOpen() { int alpha = int(clamp(c.len() == 4 ? c[3] : 255, 0, 255)) Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) file.color = c - printt("ColorPicker Read ConVar", GetConVarString("modemenu_current_color_convar"), "With Value:", GetConVarString(GetConVarString("modemenu_current_color_convar")), ",Parsed To:", + printt("ColorPicker Read ConVar", conVar, "With Value:", + GetConVarString(conVar), ",Parsed To:", c[0], c[1], c[2], alpha) } @@ -104,6 +123,10 @@ void function OnColorPickerClose() { ColorsToConvar() file.color = [] + file.conVar = "" + file.displayName = "" + + Hud_SetText(file.subTitle, "") TryUpdateModSettingLists() } @@ -124,7 +147,7 @@ void function SendTextPanelChanges( var textPanel ) { // ThrowInvalidValue( "This part of color is an integer, and only accepts whole numbers(0..1..255)." ) ResetColor(index) - + } } @@ -141,11 +164,15 @@ void function OnSliderChange( var button ) // write to convar void function UpdateColor() { + string conVar = file.conVar try { - ColorsToConvar() + if (conVar == "") { + throw "Oops We dont have ConVar for color" + } + ColorsToConvar(conVar) - array < int > c = ColorsFromConvar() + array < int > c = ColorsFromConvar(conVar) int alpha = c.len() == 4 ? c[3] : 255 Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) @@ -183,66 +210,66 @@ void function ResetColor(int index) -array function ColorsFromConvar() +array function ColorsFromConvar(string conVar = "") { - string convar = GetConVarString("modemenu_current_color_convar") array c - if (convar != "") { - try { - array tokens = split( GetConVarString(convar), " " ) - - // Assert(tokens.len() == 3) - if (tokens.len() < 3) { - throw "Convar " + convar + ": " + GetConVarString(convar) + "is not a trio/four of numbers" - // printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar)) + try { + if (conVar == "") { + throw "Oops. We dont have ConVar for color here" + } + array tokens = split( GetConVarString(conVar), " " ) - } + // Assert(tokens.len() == 3) + if (tokens.len() < 3) { + throw "Convar " + conVar + ": " + GetConVarString(conVar) + "is not a trio/four of numbers" + // printt("Failed to ColorsFromConvar. With Convar", conVar, ":",GetConVarString(conVar)) - for (int i = 0; i < tokens.len(); i++) { - c.append(int(clamp(tokens[i].tointeger(), 0, 255))) - } + } - if (tokens.len() == 3) { - c.append(255) - } + for (int i = 0; i < tokens.len(); i++) { + c.append(int(clamp(tokens[i].tointeger(), 0, 255))) } - catch ( ex ) - { - printt("Failed to ColorsFromConvar. With Convar", convar, ":",GetConVarString(convar) , ex) - // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + + if (tokens.len() == 3) { + c.append(255) } + + } + catch ( ex ) + { + printt("Failed to ColorsFromConvar. With Convar", conVar, ":",GetConVarString(conVar) , ex) + // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } return c } -void function ColorsToConvar() +void function ColorsToConvar(string conVar = "") { - string convar = GetConVarString("modemenu_current_color_convar") - if (convar != "") { - try { - string str = "" - for (int i = 0; i < 4; i++) { - str += "" + int(Hud_GetUTF8Text( file.textFields[i] )) - if (i != 3) { - str += " " - } + try { + if (conVar == "") { + throw "Oops. We dont have ConVar for color here" + } + string str = "" + for (int i = 0; i < 4; i++) { + str += "" + int(Hud_GetUTF8Text( file.textFields[i] )) + if (i != 3) { + str += " " } + } - SetConVarString(convar, str) - // printt("ColorPicker write ConVar", GetConVarString("modemenu_current_color_convar"), "With " + str) + SetConVarString(conVar, str) + // printt("ColorPicker write ConVar", conVar , "With " + str) - } - catch ( ex ) - { - printt("Failed to ColorsToConvar. With Convar", convar, ":",GetConVarString(convar) , ex) - // ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") - } + } + catch ( ex ) + { + printt("Failed to ColorsToConvar. With Convar", conVar, ":",GetConVarString(conVar) , ex) + // ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } } - void function ThrowInvalidValue( string desc ) { DialogData dialogData @@ -253,9 +280,11 @@ void function ThrowInvalidValue( string desc ) OpenDialog( dialogData ) } - -void function OnScreen_BGActivate( var button ) +void +function OpenColorPickerMenu(string conVar, string displayName) { - CloseSubmenu() - printt("Close ColorPicker") -} + file.conVar = conVar + file.displayName = displayName + + OpenSubmenu(GetMenu("ColorPicker"), false) +} \ No newline at end of file From bf417ca060c661bba336c1813aa6a71a376ddf3a Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Mon, 21 Oct 2024 22:07:11 +0800 Subject: [PATCH 10/11] Update menu_mod_settings.nut Use Color struct instead table. Modified the strings used by ThrowInvalidValue. --- .../scripts/vscripts/ui/menu_mod_settings.nut | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index a6b251343..f81c5ee66 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -83,6 +83,14 @@ struct { int deltaY = 0 } mouseDeltaBuffer +struct Color +{ + int r + int g + int b + int a +} + void function AddModSettingsMenu() { AddMenu( "ModSettings", $"resource/ui/menus/mod_settings.menu", InitModMenu ) @@ -655,7 +663,7 @@ void function SetModMenuNameText( var button ) if (conVar.type == "color") { try { - table color = StringToColors( GetConVarString(conVar.conVar) ) + Color color = StringToColors( GetConVarString(conVar.conVar) ) Hud_SetVisible( colorButton, true ) Hud_SetVisible( colorVGUI, true ) Hud_SetEnabled( colorButton, true ) @@ -670,7 +678,7 @@ void function SetModMenuNameText( var button ) catch ( ex ) { printt(ex) - ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers(each number should be a integer between 0 and 255) - you put something we could not parse!\n\n( Input like \"255 255 255 255\", not \"" + conVar.conVar + "\". )\n Press reset button or change the default value in mod.json. Or inform the mod author.") Hud_SetSize( colorVGUI, 0, int( 45 * scaleY ) ) Hud_SetSize( colorButton, 0, int( 45 * scaleY ) ) @@ -1179,19 +1187,19 @@ void function SendTextPanelChanges( var textPanel ) Hud_SetText( textPanel, clampedNewSetting ) SetConVarString( c.conVar, clampedNewSetting ) - // table color = StringToColors( newSetting ) + // Color color = StringToColors( newSetting ) // Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) // Hud_SetText( textPanel, newSetting ) // SetConVarString( c.conVar, newSetting ) } catch ( ex ) { - printt("Failed to send textField change, because:" + ex) - ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255 255\", not \",\". )") - - table color = StringToColors( GetConVarString( c.conVar ) ) + Color color = StringToColors( GetConVarString( c.conVar ) ) Hud_SetText( textPanel, GetConVarString( c.conVar ) ) - Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) // Hud_SetColor(colorVGUI, 0, 0, 0, 0) + Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + + printt("Failed to send textField change, because:" + ex) + ThrowInvalidValue("This setting is a color, and only accepts a four of numbers(each number should be a integer between 0 and 255) - you put something we could not parse!\n\n( Input like \"255 255 255 255\", not \"" + newSetting + "\". )") } break case "alpha": @@ -1303,27 +1311,25 @@ string function SanitizeDisplayName( string displayName ) return result } -// nothing in the game uses the format "Table.r/g/b/a"... wtf is the point of this function -table function StringToColors( string colorString, string delimiter = " " ) +Color function StringToColors( string colorString, string delimiter = " " ) { - table Table = {} + Color color array tokens = split( colorString, " " ) if ( tokens.len() < 3 || tokens.len() > 4) { throw "The length of tokens should be 3 or 4, but it is " + tokens.len() } - Table.r <- int( clamp(int( tokens[0] ),0,255) ) - Table.g <- int( clamp(int( tokens[1] ),0,255) ) - Table.b <- int( clamp(int( tokens[2] ),0,255) ) + color.r = int(clamp(int(tokens[0]), 0, 255)) + color.g = int(clamp(int(tokens[1]), 0, 255)) + color.b = int(clamp(int(tokens[2]), 0, 255)) if ( tokens.len() == 4 ) - Table.a <- int( clamp(int( tokens[3] ),0,255) ) + color.a = int(clamp(int(tokens[3]), 0, 255)) else - Table.a <- 255 - + color.a = 255 - return Table + return color } void function TryUpdateModSettingLists() { From 617937a4f4be9ac7e454b2d94ce9b5328b8d9a8d Mon Sep 17 00:00:00 2001 From: RainTrap341 Date: Fri, 1 Nov 2024 08:54:51 +0800 Subject: [PATCH 11/11] format and bugfix - replaces spaces with tab - add reset logic to colorVGUI --- Northstar.Client/mod.json | 18 +- .../mod/resource/ui/menus/colorsliders.menu | 654 +++++++++--------- .../scripts/vscripts/ui/menu_mod_settings.nut | 54 +- .../vscripts/ui/menu_ns_color_picker.nut | 184 +++-- 4 files changed, 436 insertions(+), 474 deletions(-) diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index eb96e79ab..3c7a9c7e6 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -131,20 +131,20 @@ "RunOn": "UI" }, { - "Path": "ui/menu_ns_color_picker.nut", - "RunOn": "UI", - "UICallback": { - "After": "AddColorPickerMenu" - } - }, + "Path": "ui/menu_ns_color_picker.nut", + "RunOn": "UI", + "UICallback": { + "After": "AddColorPickerMenu" + } + }, { "Path": "ui/menu_mod_settings.nut", "RunOn": "UI", "UICallback":{ "Before": "AddModSettingsMenu" - } - }, - { + } + }, + { "Path": "ui/ui_mouse_capture.nut", "RunOn": "UI" }, diff --git a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu index 59c076333..d4fffe44c 100644 --- a/Northstar.Client/mod/resource/ui/menus/colorsliders.menu +++ b/Northstar.Client/mod/resource/ui/menus/colorsliders.menu @@ -1,6 +1,5 @@ resource/ui/menus/colorsliders.menu { - menu { ControlName Frame @@ -30,10 +29,8 @@ resource/ui/menus/colorsliders.menu fgcolor_override "0 0 0 255" visible 1 scaleImage 1 - } - DialogFrameButton { ControlName Label @@ -60,8 +57,6 @@ resource/ui/menus/colorsliders.menu pin_to_sibling_corner CENTER } - - DialogHeader { ControlName Label @@ -84,19 +79,19 @@ resource/ui/menus/colorsliders.menu Color { - "ControlName" "ImagePanel" - "image" "vgui/white" - "scaleImage" "1" - "drawColor" "180 180 180 255" // vanilla label color - "visible" "1" - "wide" "600" - "tall" "20" - "enabled" "0" + ControlName ImagePanel + image "vgui/white" + scaleImage 1 + drawColor "180 180 180 255" // vanilla label color + visible 1 + wide "600" + tall "20" + enabled 0 - "pin_to_sibling" DialogFrame - "pin_corner_to_sibling" TOP - "pin_to_sibling_corner" TOP + pin_to_sibling DialogFrame + pin_corner_to_sibling TOP + pin_to_sibling_corner TOP } DialogMessage @@ -117,500 +112,469 @@ resource/ui/menus/colorsliders.menu pin_to_sibling_corner BOTTOM_LEFT } - LabelR // A label that is placed in the middle of the screen - { + LabelR + { Classname LabelClass - ControlName Label + ControlName Label xpos -15 ypos 35 - labelText "R" - "scriptID" "0" + labelText "R" + scriptID 0 - auto_wide_tocontents 1 // Set width automatically relative to the label content + auto_wide_tocontents 1 pin_to_sibling DialogMessage pin_corner_to_sibling TOP_LEFT pin_to_sibling_corner BOTTOM_LEFT - } + } - SliderR - { + SliderR + { Classname SliderClass xpos 15 - "ControlName" "SliderControl" - "scriptID" "0" - - minValue 0 - maxValue 255 - stepSize 1 + ControlName SliderControl + scriptID 0 + + minValue 0 + maxValue 255 + stepSize 1 drawColor "255 0 0 255" - pin_to_sibling LabelR - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT + pin_to_sibling LabelR + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT - //"navRight" "ResetModToDefault" - //"navLeft" "TextEntrySetting" - - BtnDropButton - { - ControlName RuiButton + BtnDropButton + { + ControlName RuiButton - style SliderButton - wide "320" - tall "45" - "labelText" "" - "auto_wide_tocontents" "0" - } + style SliderButton + wide 320 + tall 45 + labelText "" + auto_wide_tocontents 0 + } - "wide" "320" - "tall" "45" - } + wide 320 + tall 45 + } TextEntrySettingR { - "ControlName" "TextEntry" + ControlName TextEntry Classname TextEntrySettingClass - "xpos" 20 - "ypos" "-5" - "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 50 - "tall" "30" - "scriptID" "0" - "textHidden" "0" - "editable" "1" + xpos 20 + ypos -5 + zpos 100 + wide 50 + tall 30 + scriptID 0 + textHidden 0 + editable 1 NumericInputOnly 1 - "font" "Default_21" - "allowRightClickMenu" "0" - "allowSpecialCharacters" "1" - "unicode" "0" - "scriptID" "0" + font Default_21 + allowRightClickMenu 0 + allowSpecialCharacters 1 + unicode 0 + scriptID 0 pin_to_sibling SliderR - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT } ResetModToDefaultR { Classname ResetModToDefaultClass - "ControlName" "RuiButton" - "InheritProperties" "RuiSmallButton" - "labelText" "" - "zpos" "0" - "xpos" "10" - "wide" "75" - "tall" "45" - "scriptID" "0" - "pin_to_sibling" TextEntrySettingR - "pin_corner_to_sibling" "LEFT" - "pin_to_sibling_corner" "RIGHT" - - "navLeft" "TextEntrySettingR" - "navRight" "SliderG" - "enabled" "1" + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "" + zpos 0 + xpos 10 + wide 75 + tall 45 + scriptID 0 + pin_to_sibling TextEntrySettingR + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + navLeft TextEntrySettingR + navRight SliderG + enabled 1 } ResetModImageR { - "ControlName" "ImagePanel" - "image" "vgui/reset" - "scaleImage" "1" - "drawColor" "180 180 180 255" // vanilla label color - "visible" "1" - "wide" "30" - "tall" "30" - "enabled" "0" + ControlName ImagePanel + image "vgui/reset" + scaleImage 1 + drawColor "180 180 180 255" // vanilla label color + visible 1 + wide 30 + tall 30 + enabled 0 - "pin_to_sibling" ResetModToDefaultR - "pin_corner_to_sibling" "CENTER" - "pin_to_sibling_corner" "CENTER" + pin_to_sibling ResetModToDefaultR + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER } - - - - - - - - - - - - - - - LabelG // A label that is placed in the middle of the screen - { + LabelG + { Classname LabelClass - ControlName Label - "scriptID" "1" + ControlName Label + scriptID 1 ypos 25 - labelText "G" + labelText "G" - auto_wide_tocontents 1 // Set width automatically relative to the label content + auto_wide_tocontents 1 pin_to_sibling LabelR pin_corner_to_sibling TOP_LEFT pin_to_sibling_corner BOTTOM_LEFT - } + } - SliderG - { + SliderG + { Classname SliderClass xpos 15 - "ControlName" "SliderControl" - "scriptID" "1" + ControlName SliderControl + scriptID 1 - minValue 0 - maxValue 255 - stepSize 1 + minValue 0 + maxValue 255 + stepSize 1 drawColor "255 0 0 255" - pin_to_sibling LabelG - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT - - //"navRight" "ResetModToDefault" - //"navLeft" "TextEntrySetting" - - BtnDropButton - { - ControlName RuiButton - - style SliderButton - wide "320" - tall "45" - "labelText" "" - "auto_wide_tocontents" "0" - } - - "wide" "320" - "tall" "45" - } - + pin_to_sibling LabelG + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide 320 + tall 45 + labelText "" + auto_wide_tocontents 0 + } + + wide 320 + tall 45 + } TextEntrySettingG { - "ControlName" "TextEntry" + ControlName TextEntry Classname TextEntrySettingClass - "xpos" 20 - "ypos" "-5" - "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 50 - "tall" "30" - "scriptID" "1" + xpos 20 + ypos -5 + zpos 100 + wide 50 + tall 30 + scriptID 1 - "textHidden" "0" - "editable" "1" + textHidden 0 + editable 1 NumericInputOnly 1 - "font" "Default_21" - "allowRightClickMenu" "0" - "allowSpecialCharacters" "1" - "unicode" "0" + font Default_21 + allowRightClickMenu 0 + allowSpecialCharacters 1 + unicode 0 pin_to_sibling SliderG - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT } ResetModToDefaultG { Classname ResetModToDefaultClass - "enabled" "1" + enabled 1 - "ControlName" "RuiButton" - "InheritProperties" "RuiSmallButton" - "labelText" "" - "zpos" "0" - "xpos" "10" - "wide" "75" - "tall" "45" - "scriptID" "1" + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "" + zpos 0 + xpos 10 + wide 75 + tall 45 + scriptID 1 - "pin_to_sibling" TextEntrySettingG - "pin_corner_to_sibling" "LEFT" - "pin_to_sibling_corner" "RIGHT" + pin_to_sibling TextEntrySettingG + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT - "navLeft" "TextEntrySettingG" - "navRight" "SliderB" - "enabled" "1" + navLeft TextEntrySettingG + navRight SliderB + enabled 1 } + ResetModImageG { - "ControlName" "ImagePanel" - "image" "vgui/reset" - "scaleImage" "1" - "drawColor" "180 180 180 255" // vanilla label color - "visible" "1" - "wide" "30" - "tall" "30" - "enabled" "1" + ControlName ImagePanel + image "vgui/reset" + scaleImage 1 + drawColor "180 180 180 255" // vanilla label color + visible 1 + wide 30 + tall 30 + enabled 1 - "pin_to_sibling" ResetModToDefaultG - "pin_corner_to_sibling" "CENTER" - "pin_to_sibling_corner" "CENTER" + pin_to_sibling ResetModToDefaultG + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER } - - - - - - LabelB // A label that is placed in the middle of the screen - { + LabelB + { Classname LabelClass - ControlName Label - "scriptID" "2" + ControlName Label + scriptID 2 ypos 25 - labelText "B" + labelText "B" - auto_wide_tocontents 1 // Set width automatically relative to the label content + auto_wide_tocontents 1 pin_to_sibling LabelG pin_corner_to_sibling TOP_LEFT pin_to_sibling_corner BOTTOM_LEFT - } + } - SliderB - { + SliderB + { Classname SliderClass xpos 15 - "ControlName" "SliderControl" - "scriptID" "2" + ControlName SliderControl + scriptID 2 - minValue 0 - maxValue 255 - stepSize 1 + minValue 0 + maxValue 255 + stepSize 1 drawColor "255 0 0 255" - pin_to_sibling LabelB - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT + pin_to_sibling LabelB + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT - //"navRight" "ResetModToDefault" - //"navLeft" "TextEntrySetting" - - BtnDropButton - { - ControlName RuiButton + BtnDropButton + { + ControlName RuiButton - style SliderButton - wide "320" - tall "45" - "labelText" "" - "auto_wide_tocontents" "0" - } + style SliderButton + wide 320 + tall 45 + labelText "" + auto_wide_tocontents 0 + } - "wide" "320" - "tall" "45" - } + wide 320 + tall 45 + } TextEntrySettingB { Classname TextEntrySettingClass - "ControlName" "TextEntry" - "xpos" 20 - "ypos" "-5" - "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 50 - "tall" "30" - "scriptID" "2" + ControlName TextEntry + xpos 20 + ypos -5 + zpos 100 + wide 50 + tall 30 + scriptID 2 - "textHidden" "0" - "editable" "1" + textHidden 0 + editable 1 NumericInputOnly 1 - "font" "Default_21" - "allowRightClickMenu" "0" - "allowSpecialCharacters" "1" - "unicode" "0" + font Default_21 + allowRightClickMenu 0 + allowSpecialCharacters 1 + unicode 0 pin_to_sibling SliderB - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT - } + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + ResetModToDefaultB { Classname ResetModToDefaultClass - "enabled" "1" + enabled 1 - "ControlName" "RuiButton" - "InheritProperties" "RuiSmallButton" - "labelText" "" - "zpos" "0" - "xpos" "10" - "wide" "75" - "tall" "45" - "scriptID" "2" + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "" + zpos 0 + xpos 10 + wide 75 + tall 45 + scriptID 2 - "pin_to_sibling" TextEntrySettingB - "pin_corner_to_sibling" "LEFT" - "pin_to_sibling_corner" "RIGHT" + pin_to_sibling TextEntrySettingB + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT - "navLeft" "TextEntrySettingB" - "navRight" "SliderA" - "enabled" "1" + navLeft TextEntrySettingB + navRight SliderA + enabled 1 } + ResetModImageB { - "ControlName" "ImagePanel" - "image" "vgui/reset" - "scaleImage" "1" - "drawColor" "180 180 180 255" // vanilla label color - "visible" "1" - "wide" "30" - "tall" "30" - "enabled" "0" + ControlName ImagePanel + image "vgui/reset" + scaleImage 1 + drawColor "180 180 180 255" // vanilla label color + visible 1 + wide 30 + tall 30 + enabled 0 - "pin_to_sibling" ResetModToDefaultB - "pin_corner_to_sibling" "CENTER" - "pin_to_sibling_corner" "CENTER" + pin_to_sibling ResetModToDefaultB + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER } - - - LabelA // A label that is placed in the middle of the screen - { + LabelA + { Classname LabelClass - ControlName Label - "scriptID" "3" + ControlName Label + scriptID 3 ypos 25 - labelText "A" + labelText "A" - auto_wide_tocontents 1 // Set width automatically relative to the label content + auto_wide_tocontents 1 pin_to_sibling LabelB pin_corner_to_sibling TOP_LEFT pin_to_sibling_corner BOTTOM_LEFT - } + } - SliderA - { + SliderA + { Classname SliderClass xpos 15 - "ControlName" "SliderControl" - "scriptID" "3" + ControlName SliderControl + scriptID 3 - minValue 0 - maxValue 255 - stepSize 1 + minValue 0 + maxValue 255 + stepSize 1 drawColor "255 0 0 255" - - pin_to_sibling LabelA - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT - - //"navRight" "ResetModToDefault" - //"navLeft" "TextEntrySetting" - - BtnDropButton - { - ControlName RuiButton - - style SliderButton - wide "320" - tall "45" - "labelText" "" - "auto_wide_tocontents" "0" - } - - "wide" "320" - "tall" "45" - } + + pin_to_sibling LabelA + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + + BtnDropButton + { + ControlName RuiButton + + style SliderButton + wide 320 + tall 45 + labelText "" + auto_wide_tocontents 0 + } + + wide 320 + tall 45 + } TextEntrySettingA { Classname TextEntrySettingClass - "ControlName" "TextEntry" - "xpos" 20 - "ypos" "-5" - "zpos" "100" // This works around input weirdness when the control is constructed by code instead of VGUI blackbox. - "wide" 50 - "tall" "30" - "scriptID" "3" + ControlName TextEntry + xpos 20 + ypos -5 + zpos 100 + wide 50 + tall 30 + scriptID 3 - "textHidden" "0" - "editable" "1" + textHidden 0 + editable 1 NumericInputOnly 1 - "font" "Default_21" - "allowRightClickMenu" "0" - "allowSpecialCharacters" "1" - "unicode" "0" + font Default_21 + allowRightClickMenu 0 + allowSpecialCharacters 1 + unicode 0 pin_to_sibling SliderA - pin_corner_to_sibling LEFT - pin_to_sibling_corner RIGHT - } + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT + } + ResetModToDefaultA { Classname ResetModToDefaultClass - "enabled" "1" + enabled 1 - "ControlName" "RuiButton" - "InheritProperties" "RuiSmallButton" - "labelText" "" - "zpos" "0" - "xpos" "10" - "wide" "75" - "tall" "45" - "scriptID" "3" + ControlName RuiButton + InheritProperties RuiSmallButton + labelText "" + zpos 0 + xpos 10 + wide 75 + tall 45 + scriptID 3 - "pin_to_sibling" TextEntrySettingA - "pin_corner_to_sibling" "LEFT" - "pin_to_sibling_corner" "RIGHT" + pin_to_sibling TextEntrySettingA + pin_corner_to_sibling LEFT + pin_to_sibling_corner RIGHT - "navLeft" "TextEntrySettingA" - "enabled" "1" + navLeft TextEntrySettingA + enabled 1 } + ResetModImageA { - "ControlName" "ImagePanel" - "image" "vgui/reset" - "scaleImage" "1" - "drawColor" "180 180 180 255" // vanilla label color - "visible" "1" - "wide" "30" - "tall" "30" - "enabled" "0" + ControlName ImagePanel + image "vgui/reset" + scaleImage 1 + drawColor "180 180 180 255" // vanilla label color + visible 1 + wide 30 + tall 30 + enabled 0 - "pin_to_sibling" ResetModToDefaultA - "pin_corner_to_sibling" "CENTER" - "pin_to_sibling_corner" "CENTER" + pin_to_sibling ResetModToDefaultA + pin_corner_to_sibling CENTER + pin_to_sibling_corner CENTER } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + } --> } - } \ No newline at end of file diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut index f81c5ee66..fa22922aa 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_mod_settings.nut @@ -282,6 +282,25 @@ void functionref() function ResetConVarEventHandler( int modIndex ) Hud_SetText( Hud_GetChild( file.modPanels[ modIndex - file.scrollOffset ], "TextEntrySetting" ), c.isEnumSetting ? c.values[ GetConVarInt( c.conVar ) ] : GetConVarString( c.conVar ) ) if( c.sliderEnabled ) MS_Slider_SetValue( file.sliders[ modIndex - file.scrollOffset ], GetConVarFloat( c.conVar ) ) + if ( c.type == "color" ) + { + var colorVGUI = Hud_GetChild( file.modPanels[ modIndex - file.scrollOffset ], "ColorPickerImage" ) + try + { + Color color = StringToColors( GetConVarString( c.conVar ) ) + Hud_SetColor( colorVGUI, color.r, color.g, color.b, color.a ) + } + catch ( ex ) + { + ThrowInvalidValue( "This setting is a color, and only accepts a four of numbers(each number should be a integer between 0 and 255) - you put something we could not parse!\n\n( Input like \"255 255 255 255\", not \"" + c.conVar + "\". )\n Press reset button or change the default value in mod.json. Or inform the mod author." ) + Hud_SetColor( colorVGUI, 0, 0, 0, 0 ) + } + } + if ( c.type == "alpha" ) + { + float alpha = GetConVarFloat( c.conVar ) + Hud_SetAlpha( Hud_GetChild( file.modPanels[ modIndex - file.scrollOffset ], "ColorPickerImage" ), int( alpha * 255 ) ) + } } } } @@ -1054,12 +1073,12 @@ void function OnSliderChange( var button ) Hud_SetText( textPanel, string( GetConVarFloat( c.conVar ) ) ) - if (c.type == "alpha") { + if (c.type == "alpha") + { var colorVGUI = Hud_GetChild( Hud_GetParent( textPanel ), "ColorPickerImage" ) - float alpha = GetConVarFloat(c.conVar) - Hud_SetAlpha(colorVGUI, int(alpha * 255)) - // Hud_SetColor(colorVGUI, 255, 255, 255, 255) + float alpha = GetConVarFloat( c.conVar ) + Hud_SetAlpha( colorVGUI, int( alpha * 255 ) ) } } @@ -1171,47 +1190,38 @@ void function SendTextPanelChanges( var textPanel ) array color string clampedNewSetting = "" foreach (string val in split) { - int c = int(clamp(val.tointeger(), 0 ,255)) - color.append(c) + int c = int( clamp( val.tointeger(), 0 ,255 ) ) + color.append( c ) clampedNewSetting += c + " " } if (split.len() == 3) { - color.append(255) + color.append( 255 ) clampedNewSetting += " 255" } - Hud_SetColor(colorVGUI, color[0], color[1], color[2], color[3]) + Hud_SetColor( colorVGUI, color[0], color[1], color[2], color[3] ) Hud_SetText( textPanel, clampedNewSetting ) SetConVarString( c.conVar, clampedNewSetting ) - - // Color color = StringToColors( newSetting ) - // Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) - // Hud_SetText( textPanel, newSetting ) - // SetConVarString( c.conVar, newSetting ) } catch ( ex ) { Color color = StringToColors( GetConVarString( c.conVar ) ) Hud_SetText( textPanel, GetConVarString( c.conVar ) ) - Hud_SetColor(colorVGUI, color.r, color.g, color.b, color.a) + Hud_SetColor( colorVGUI, color.r, color.g, color.b, color.a ) - printt("Failed to send textField change, because:" + ex) - ThrowInvalidValue("This setting is a color, and only accepts a four of numbers(each number should be a integer between 0 and 255) - you put something we could not parse!\n\n( Input like \"255 255 255 255\", not \"" + newSetting + "\". )") + printt( "Failed to send textField change, because:" + ex ) + ThrowInvalidValue( "This setting is a color, and only accepts a four of numbers(each number should be a integer between 0 and 255) - you put something we could not parse!\n\n( Input like \"255 255 255 255\", not \"" + newSetting + "\". )" ) } break case "alpha": try { - float alpha = clamp(newSetting.tofloat(), 0, 1.0) + float alpha = clamp( newSetting.tofloat(), 0, 1.0 ) - // if ( alpha < 0 || alpha > 1) { - // Hud_SetText( textPanel, GetConVarString( c.conVar ) ) - // throw "Alpha should be a float bewteen 0..1." - // } - Hud_SetAlpha(colorVGUI, int(alpha * 255)) + Hud_SetAlpha( colorVGUI, int( alpha * 255 ) ) SetConVarFloat( c.conVar, alpha ) } catch ( ex ) diff --git a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut index 8fbf93130..36e94378a 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/menu_ns_color_picker.nut @@ -2,12 +2,10 @@ untyped global function AddColorPickerMenu global function OpenColorPickerMenu - - -struct { +struct +{ var subTitle - array sliders array labels array textFields @@ -26,7 +24,6 @@ void function AddColorPickerMenu() { AddSubmenu( "ColorPicker", $"resource/ui/menus/colorsliders.menu" ) - file.colorPicker = GetMenu( "ColorPicker" ) file.colorImage = Hud_GetChild( file.colorPicker, "Color" ) file.subTitle = Hud_GetChild( file.colorPicker, "DialogMessage" ) @@ -35,8 +32,6 @@ void function AddColorPickerMenu() RuiSetImage( Hud_GetRui( frameElem ), "basicImage", $"rui/menu/common/dialog_gradient" ) RuiSetFloat3( Hud_GetRui( frameElem ), "basicImageColor", < 1, 1, 1 > ) - // AddMenuFooterOption( file.colorPicker, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) - // RuiButton here due to close action var screen = Hud_GetChild( file.colorPicker, "DarkenBackground" ) Hud_AddEventHandler( screen, UIE_CLICK, void function( var _button ) @@ -54,107 +49,107 @@ void function AddColorPickerMenu() file.labels = GetElementsByClassname( file.colorPicker, "LabelClass" ) file.sliders = [] - foreach (child in GetElementsByClassname( file.colorPicker, "SliderClass" )) { + foreach (child in GetElementsByClassname( file.colorPicker, "SliderClass" )) + { MS_Slider slider = MS_Slider_Setup( child ) MS_Slider_SetMin( slider, 0 ) MS_Slider_SetMax( slider, 255 ) MS_Slider_SetStepSize( slider, 1 ) - file.sliders.append(slider) + file.sliders.append( slider ) Hud_AddEventHandler( child, UIE_CHANGE, OnSliderChange ) } file.textFields = GetElementsByClassname( file.colorPicker, "TextEntrySettingClass" ) - foreach (value in file.textFields) { + foreach ( value in file.textFields ) + { Hud_AddEventHandler( value, UIE_LOSE_FOCUS, SendTextPanelChanges ) } file.resets = GetElementsByClassname( file.colorPicker, "ResetModToDefaultClass" ) - foreach (value in file.resets) { - Hud_AddEventHandler( value, UIE_CLICK, void function (var _button) { - int index = int(Hud_GetScriptID(_button)) - ResetColor(index) - printt("Try to reset color", index) + foreach ( value in file.resets ) + { + Hud_AddEventHandler( value, UIE_CLICK, void function( var _button ) + { + int index = int( Hud_GetScriptID(_button) ) + ResetColor( index ) + // printt("Try to reset color", index) } ) } } -void function OnColorPickerOpen() { +void function OnColorPickerOpen() +{ string conVar = file.conVar string displayName = file.displayName - if (conVar == "") + if ( conVar == "" ) { CloseSubmenu() return } - Hud_SetText(file.subTitle, displayName) - array < int > c = ColorsFromConvar(conVar) - if (c.len() >= 3) { + Hud_SetText( file.subTitle, displayName ) + array < int > c = ColorsFromConvar( conVar ) + if (c.len() >= 3) + { - for (int i = 0; i < c.len(); i++) { + for ( int i = 0; i < c.len(); i++ ) + { MS_Slider slider = file.sliders[i] var textPanel = file.textFields[i] - - int val = int(clamp(c[i], 0, 255)) - MS_Slider_SetValue(slider, val.tofloat()) - Hud_SetText( textPanel, string(val) ) + int val = int( clamp( c[i], 0, 255 ) ) + MS_Slider_SetValue( slider, val.tofloat() ) + Hud_SetText( textPanel, string( val ) ) } - int alpha = int(clamp(c.len() == 4 ? c[3] : 255, 0, 255)) - Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + int alpha = int( clamp( c.len() == 4 ? c[3] : 255, 0, 255 ) ) + Hud_SetColor( file.colorImage, c[0], c[1], c[2], alpha ) file.color = c - printt("ColorPicker Read ConVar", conVar, "With Value:", - GetConVarString(conVar), ",Parsed To:", - c[0], c[1], c[2], alpha) - } } -void function OnColorPickerClose() { - printt("Trying to close Color Picker") - - ColorsToConvar() +void function OnColorPickerClose() +{ + // printt("Trying to close Color Picker") + ColorsToConvar( file.conVar ) file.color = [] file.conVar = "" file.displayName = "" - Hud_SetText(file.subTitle, "") + Hud_SetText( file.subTitle, "" ) TryUpdateModSettingLists() } void function SendTextPanelChanges( var textPanel ) { - int newSetting = int(Hud_GetUTF8Text( textPanel )) - int index = int(Hud_GetScriptID(textPanel)) + int newSetting = int( Hud_GetUTF8Text( textPanel ) ) + int index = int( Hud_GetScriptID( textPanel ) ) try { - newSetting = int(clamp(newSetting, 0, 255)) + newSetting = int( clamp( newSetting, 0, 255 ) ) MS_Slider slider = file.sliders[index] - MS_Slider_SetValue(slider, newSetting.tofloat()) + MS_Slider_SetValue( slider, newSetting.tofloat() ) UpdateColor() } catch ( ex ) { - // ThrowInvalidValue( "This part of color is an integer, and only accepts whole numbers(0..1..255)." ) - ResetColor(index) - + ResetColor( index ) } } void function OnSliderChange( var button ) { - int index = int(Hud_GetScriptID(button)) - int val = int(Hud_SliderControl_GetCurrentValue( button )) + int index = int( Hud_GetScriptID( button ) ) + int val = int( Hud_SliderControl_GetCurrentValue( button ) ) var textPanel = file.textFields[index] Hud_SetText( textPanel, string( val ) ) @@ -166,125 +161,118 @@ void function UpdateColor() { string conVar = file.conVar - try { - if (conVar == "") { + try + { + if ( conVar == "" ) + { throw "Oops We dont have ConVar for color" } - ColorsToConvar(conVar) + ColorsToConvar( conVar ) - array < int > c = ColorsFromConvar(conVar) + array < int > c = ColorsFromConvar( conVar ) int alpha = c.len() == 4 ? c[3] : 255 - Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + Hud_SetColor( file.colorImage, c[0], c[1], c[2], alpha ) } catch ( ex ) { printt("Failed to UpdateColor", ex) - // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") } } -void function ResetColors() { - for (int i = 0; i < 4; i++) { - ResetColor(i) + +void function ResetColors() +{ + for ( int i = 0; i < 4; i++ ) + { + ResetColor( i ) } } -void function ResetColor(int index) +void function ResetColor( int index ) { array < int > c = file.color - if (c.len() >= 3) { + if ( c.len() >= 3 ) + { var textPanel = file.textFields[index] MS_Slider slider = file.sliders[index] - Hud_SetText( textPanel, string(c[index]) ) - MS_Slider_SetValue(slider, c[index].tofloat()) + Hud_SetText( textPanel, string( c[index] ) ) + MS_Slider_SetValue( slider, c[index].tofloat() ) int alpha = c.len() == 4 ? c[3] : 255 - Hud_SetColor(file.colorImage, c[0], c[1], c[2], alpha) + Hud_SetColor( file.colorImage, c[0], c[1], c[2], alpha ) UpdateColor() - } } - - - -array function ColorsFromConvar(string conVar = "") +array function ColorsFromConvar( string conVar = "" ) { array c - try { - if (conVar == "") { + try + { + if ( conVar == "" ) + { throw "Oops. We dont have ConVar for color here" } array tokens = split( GetConVarString(conVar), " " ) // Assert(tokens.len() == 3) - if (tokens.len() < 3) { - throw "Convar " + conVar + ": " + GetConVarString(conVar) + "is not a trio/four of numbers" + if ( tokens.len() < 3 ) + { + throw "Convar " + conVar + " : " + GetConVarString( conVar ) + " is not a trio/four of numbers" // printt("Failed to ColorsFromConvar. With Convar", conVar, ":",GetConVarString(conVar)) - } - for (int i = 0; i < tokens.len(); i++) { - c.append(int(clamp(tokens[i].tointeger(), 0, 255))) + for ( int i = 0; i < tokens.len(); i++ ) + { + c.append( int( clamp( tokens[i].tointeger(), 0, 255 ) ) ) } - if (tokens.len() == 3) { - c.append(255) + if ( tokens.len() == 3 ) + { + c.append( 255 ) } } catch ( ex ) { - printt("Failed to ColorsFromConvar. With Convar", conVar, ":",GetConVarString(conVar) , ex) - // ThrowInvalidValue("This setting is a color, and only accepts a trio of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + printt( "Failed to Convert ConVar String to an int[4] with ConVar", conVar, ":",GetConVarString( conVar ) , ex ) } return c } -void function ColorsToConvar(string conVar = "") +void function ColorsToConvar( string conVar = "" ) { - try { - if (conVar == "") { + try + { + if ( conVar == "" ) { throw "Oops. We dont have ConVar for color here" } string str = "" - for (int i = 0; i < 4; i++) { - str += "" + int(Hud_GetUTF8Text( file.textFields[i] )) - if (i != 3) { + for ( int i = 0; i < 4; i++ ) + { + str += "" + int( Hud_GetUTF8Text( file.textFields[i] ) ) + if ( i != 3 ) str += " " - } } - SetConVarString(conVar, str) + SetConVarString( conVar, str ) // printt("ColorPicker write ConVar", conVar , "With " + str) } catch ( ex ) { - printt("Failed to ColorsToConvar. With Convar", conVar, ":",GetConVarString(conVar) , ex) - // ThrowInvalidValue("This setting is a color, and only accepts a four of numbers - you put something we could not parse!\n\n( Use \".\" for the int like \"255 255 255\", not \",\". )") + printt( "Failed to Convert Ints in Textfields to ConVar String with ConVar", conVar, ":",GetConVarString( conVar ) , ex ) } } -void function ThrowInvalidValue( string desc ) -{ - DialogData dialogData - dialogData.header = "Invalid Value" - dialogData.image = $"ui/menu/common/dialog_error" - dialogData.message = desc - AddDialogButton( dialogData, "#OK" ) - OpenDialog( dialogData ) -} - -void -function OpenColorPickerMenu(string conVar, string displayName) +void function OpenColorPickerMenu( string conVar, string displayName ) { file.conVar = conVar file.displayName = displayName - OpenSubmenu(GetMenu("ColorPicker"), false) + OpenSubmenu( GetMenu( "ColorPicker" ), false ) } \ No newline at end of file