Skip to content

Converting PopulateDiskSpaceUI() to create a slider #3139

@Coaxgames

Description

@Coaxgames

Got tired of upgrades being rather limited, im using a config tweak for Very weak KOS CommandPod on all pods and Probes.

During gameplay i would always run out of storage or just maxed it out everytime. So i made a fork and replaced the old "kOS Disk Space" UI with a new one that has a 8x limit and costs more per upgrade (doing the cost in moduleManager patch File) and converted the INT/String type into a float type on line 104 & 105 in KOSProcessor.cs

Line 104: [KSPField(isPersistant = false, guiName = "kOS Disk Space", guiActive = false, guiActiveEditor = true, groupName = PAWGroup, groupDisplayName = PAWGroup), UI_FloatRange(scene = UI_Scene.Editor)]
Line 105: 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

Swapped out the PopulateDiskSpaceUI() Function guts with a slider

        private void PopulateDiskSpaceUI()
        {
            //populate diskSpaceUI selector
            // 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 / 8f,
                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";
        }

And finally swapped out the old Update() stuff related to the old UI_Options UI to this:

if (diskSpace != Mathf.RoundToInt(diskSpaceUI)) //Tested in-game, no issues found
{
         diskSpace = Mathf.RoundToInt(diskSpaceUI); ///Tested as well
         UpdateCostAndMass();
         GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}

My concerns are that something in the KOS API may read that as a string, and because its a float, i would assume when converting from Type A to Type B it would error from something else but haven't had an issue yet.

Posted a Issue because im new to Pull requests And felt this was the better option for a Qol modification.
So how could i go about doing that if whats done here is ok? (didnt do the docs yet, But wouldnt take me much effort)
Fork Link incase anyone needs it: https://github.com/Coaxgames/KOS-Custom

In-game View:
Image

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions