From 7c92a54f3a3ad23f01d0a9d1a654adbd44585649 Mon Sep 17 00:00:00 2001 From: Coaxgames Date: Sun, 4 May 2025 16:07:34 -0600 Subject: [PATCH 1/3] Added a 12x slider I tested with "* 4" and it seemed a tad small for the Config tweak mod (using Patch Manager to add kos to cockpits) So Working in the Script i noticed a block of math keeping it Clamped. so i left it as 8*BaseDiskSpace and increased smoothing cost is not an issue without a tweak patch, so that has not been changed but using 1024 * 8 with extra cost would be recommended to follow IRL ByteSizes. Most parts in the KOS mod seem to rise just out of that area. i felt as if it was to limited for upgrades One last note: would recommend adjusting "public float ECPerInstruction = 0.000004F;" to 0.000008F. --- src/kOS/Module/kOSProcessor.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/kOS/Module/kOSProcessor.cs b/src/kOS/Module/kOSProcessor.cs index 68d02feb9..7dec96ff0 100644 --- a/src/kOS/Module/kOSProcessor.cs +++ b/src/kOS/Module/kOSProcessor.cs @@ -101,8 +101,8 @@ public string Tag [KSPField(isPersistant = true, guiName = "kOS Base Module Mass", guiActive = false, groupName = PAWGroup, groupDisplayName = PAWGroup)] public float baseModuleMass = 0F; // this is the base mass added to a part for including the kOSProcessor, default to 0. - [KSPField(isPersistant = false, guiName = "kOS Disk Space", guiActive = false, guiActiveEditor = true, groupName = PAWGroup, groupDisplayName = PAWGroup), UI_ChooseOption(scene = UI_Scene.Editor)] - public string diskSpaceUI = "1024"; + [KSPField(isPersistant = false, guiName = "kOS Disk Space", guiActive = false, guiActiveEditor = true, groupName = PAWGroup, groupDisplayName = PAWGroup), UI_FloatRange(scene = UI_Scene.Editor)] + public float diskSpaceUI = 1024f; //needed for the slider, Could convert from String back into float or int. but works better and feels natural to have as a float to begin with [KSPField(isPersistant = true, guiName = "CPU/Disk Upgrade Cost", guiActive = false, guiActiveEditor = true, groupName = PAWGroup, groupDisplayName = PAWGroup)] public float additionalCost = 0F; @@ -111,7 +111,7 @@ public string Tag public float additionalMassGui = 0F; [KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false)] - public float diskSpaceCostFactor = 0.0244140625F; //implies approx 100funds for 4096bytes of diskSpace + public float diskSpaceCostFactor = 0.0244140625F; //implies approx 100funds for 4096bytes of diskSpace. SliderNote: would recommend a small increase to: 0.0484140625F [KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false)] public float diskSpaceMassFactor = 0.0000000048829F; //implies approx 0.020kg for 4096bytes of diskSpace @@ -376,11 +376,19 @@ private void PopulateDiskSpaceUI() diskSpaceUI = diskSpace.ToString(); BaseField field = Fields["diskSpaceUI"]; UI_ChooseOption options = (UI_ChooseOption)field.uiControlEditor; - var sizeOptions = new string[3]; - sizeOptions[0] = baseDiskSpace.ToString(); - sizeOptions[1] = (baseDiskSpace * 2).ToString(); - sizeOptions[2] = (baseDiskSpace * 4).ToString(); - options.options = sizeOptions; + + UI_FloatRange slider = new UI_FloatRange + { + minValue = baseDiskSpace, + maxValue = baseDiskSpace * 8, + stepIncrement = baseDiskSpace / 4f, + scene = UI_Scene.Editor + }; + + //These should be here, yes they are declared above but this is good practice to include parms when making the ui object + field.uiControlEditor = slider; + field.guiActiveEditor = true; + field.guiName = "KOS Disk Space"; } //implement IPartMassModifier component @@ -812,9 +820,10 @@ public void Update() InitUI(); } UpdateRP1TechLevel(true); - if (diskSpace != Convert.ToInt32(diskSpaceUI)) + // This part is now just rounding from INT, this counters any issue with DiskSpace or BaseDiskSpace being incorrect or "Out of range" + if (diskSpace != Mathf.RoundToInt(diskSpaceUI)) //Tested in-game, no issues found { - diskSpace = Convert.ToInt32(diskSpaceUI); + diskSpace = Mathf.RoundToInt(diskSpaceUI); ///Tested as well UpdateCostAndMass(); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } From d2a1cf18efe361feef16ff5838879c27ca7f402c Mon Sep 17 00:00:00 2001 From: Coaxgames Date: Sun, 4 May 2025 16:09:38 -0600 Subject: [PATCH 2/3] Update kOSProcessor.cs Forgot to remove the old UI_ChooseOption --- src/kOS/Module/kOSProcessor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kOS/Module/kOSProcessor.cs b/src/kOS/Module/kOSProcessor.cs index 7dec96ff0..edc1f7bec 100644 --- a/src/kOS/Module/kOSProcessor.cs +++ b/src/kOS/Module/kOSProcessor.cs @@ -375,7 +375,6 @@ private void PopulateDiskSpaceUI() //populate diskSpaceUI selector diskSpaceUI = diskSpace.ToString(); BaseField field = Fields["diskSpaceUI"]; - UI_ChooseOption options = (UI_ChooseOption)field.uiControlEditor; UI_FloatRange slider = new UI_FloatRange { From 346068e16608fe91af05b02db115e260ab49b3fe Mon Sep 17 00:00:00 2001 From: Coaxgames Date: Sun, 4 May 2025 16:15:08 -0600 Subject: [PATCH 3/3] VSCode reverted changes? Build failed bc of string converting, unsure why it undid the change when im currently running this build in-game --- src/kOS/Module/kOSProcessor.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kOS/Module/kOSProcessor.cs b/src/kOS/Module/kOSProcessor.cs index edc1f7bec..52f29967d 100644 --- a/src/kOS/Module/kOSProcessor.cs +++ b/src/kOS/Module/kOSProcessor.cs @@ -373,14 +373,18 @@ private void UpdateRP1TechLevel(bool InEditor) private void PopulateDiskSpaceUI() { //populate diskSpaceUI selector - diskSpaceUI = diskSpace.ToString(); + // Set the initial value to current disk space + diskSpaceUI = diskSpace; + + // Get the field and setup the slider BaseField field = Fields["diskSpaceUI"]; + UI_FloatRange slider = new UI_FloatRange { minValue = baseDiskSpace, maxValue = baseDiskSpace * 8, - stepIncrement = baseDiskSpace / 4f, + stepIncrement = baseDiskSpace / 8f, scene = UI_Scene.Editor };