Exemple #1
0
        public static float FieldSlider(float value, float increment, float incrementLarge, Vector2 limits, string name, out bool changed, Color backgroundColor, int valueType, bool allowFine = true)
        {
            if (!UIUtility.uiStyleConfigured)
            {
                UIUtility.ConfigureStyles();
            }

            GUILayout.BeginHorizontal();
            double      range = limits.y - limits.x;
            double      value01 = (value - limits.x) / range; // rescaling value to be <0-1> of range for convenience
            double      increment01 = increment / range;
            double      valueOld = value01;
            const float buttonWidth = 12, spaceWidth = 3;

            GUILayout.Label(string.Empty, UIUtility.uiStyleLabelHint);
            Rect rectLast        = GUILayoutUtility.GetLastRect();
            Rect rectSlider      = new Rect(rectLast.xMin + buttonWidth + spaceWidth, rectLast.yMin, rectLast.width - 2 * (buttonWidth + spaceWidth), rectLast.height);
            Rect rectSliderValue = new Rect(rectSlider.xMin, rectSlider.yMin, rectSlider.width * (float)value01, rectSlider.height - 3f);
            Rect rectButtonL     = new Rect(rectLast.xMin, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectButtonR     = new Rect(rectLast.xMin + rectLast.width - buttonWidth, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectLabelValue  = new Rect(rectSlider.xMin + rectSlider.width * 0.75f, rectSlider.yMin, rectSlider.width * 0.25f, rectSlider.height);

            bool buttonAdjust = false;

            if (GUI.Button(rectButtonL, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    value01 -= incrementLarge / range;
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 -= increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }
            if (GUI.Button(rectButtonR, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    value01 += incrementLarge / range;
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 += increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }

            if (!numericInput)
            {
                if (rectLast.Contains(Event.current.mousePosition) && (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && // right click drag doesn't work properly without the event check
                    Event.current.type != EventType.MouseUp)        // drag event covers this, but don't want it to
                {
                    value01 = GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);

                    if (valueOld != value01)
                    {
                        if (Input.GetMouseButton(0) || !allowFine) // normal control
                        {
                            double excess = value01 / increment01;
                            value01 -= (excess - Math.Round(excess)) * increment01;
                        }
                        else if (Input.GetMouseButton(1) && allowFine) // fine control
                        {
                            double excess = valueOld / increment01;
                            value01 = (valueOld - (excess - Math.Round(excess)) * increment01) + Math.Min(value01 - 0.5, 0.4999) * increment01;
                        }
                    }
                }
                else
                {
                    GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);
                }
            }


            GUI.DrawTexture(rectSliderValue, backgroundColor.GetTexture2D()); // slider filled area
            GUI.Label(rectSlider, $"  {name}", UIUtility.uiStyleLabelHint);   // slider name
            if (!numericInput)
            {
                value   = Mathf.Clamp((float)(value01 * range + limits.x), Mathf.Min((float)(limits.x * 0.5), limits.x), limits.y); // lower limit is halved so the fine control can reduce it further but the normal tweak still snaps. Min makes -ve values work
                changed = valueOld != value;
                GUI.Label(rectLabelValue, GetValueTranslation(value, valueType), UIUtility.uiStyleLabelHint);                       // slider value
            }
            else
            {
                changed = false;
                if (float.TryParse(GUI.TextField(rectLabelValue, value.ToString("F3"), UIUtility.uiStyleInputField), out var temp)) // Add optional numeric input
                {
                    if (!buttonAdjust)
                    {
                        value   = temp;
                        value01 = (value - limits.x) / range;
                    }
                    else
                    {
                        value = Mathf.Clamp((float)(value01 * range + limits.x), Mathf.Min((float)(limits.x * 0.5), limits.x), limits.y); // lower limit is halved so the fine control can reduce it further but the normal tweak still snaps. Min makes -ve values work
                    }
                    changed = valueOld != value01;
                }
                value = Mathf.Clamp(value, limits.x, limits.y);
            }

            GUILayout.EndHorizontal();
            return(value);
        }
        public static float IntegerSlider(float value, float incrementLarge, int min, int max, string name, out bool changed, Color backgroundColor, int valueType, bool allowFine = true)
        {
            if (!UIUtility.uiStyleConfigured)
            {
                UIUtility.ConfigureStyles();
            }

            GUILayout.BeginHorizontal();
            int         range = max - min;
            double      value01 = (value - min) / range;
            double      increment01 = 1 / range;
            double      valueOld = value01;
            const float buttonWidth = 12, spaceWidth = 3;

            GUILayout.Label(string.Empty, UIUtility.uiStyleLabelHint);
            Rect rectLast        = GUILayoutUtility.GetLastRect();
            Rect rectSlider      = new Rect(rectLast.xMin + buttonWidth + spaceWidth, rectLast.yMin, rectLast.width - 2 * (buttonWidth + spaceWidth), rectLast.height);
            Rect rectSliderValue = new Rect(rectSlider.xMin, rectSlider.yMin, rectSlider.width * (float)value01, rectSlider.height - 3f);
            Rect rectButtonL     = new Rect(rectLast.xMin, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectButtonR     = new Rect(rectLast.xMin + rectLast.width - buttonWidth, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectLabelValue  = new Rect(rectSlider.xMin + rectSlider.width * 0.75f, rectSlider.yMin, rectSlider.width * 0.25f, rectSlider.height);

            bool buttonAdjust = false;

            if (GUI.Button(rectButtonL, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    value01 -= incrementLarge / range;
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 -= increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }
            if (GUI.Button(rectButtonR, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    value01 += incrementLarge / range;
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 += increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }

            if (!numericInput)
            {
                if (rectLast.Contains(Event.current.mousePosition) && (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && // right click drag doesn't work properly without the event check
                    Event.current.type != EventType.MouseUp)        // drag event covers this, but don't want it to
                {
                    value01 = GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);
                }
                else
                {
                    GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);
                }
            }


            GUI.DrawTexture(rectSliderValue, backgroundColor.GetTexture2D()); // slider filled area
            GUI.Label(rectSlider, $"  {name}", UIUtility.uiStyleLabelHint);   // slider name
            if (!numericInput)
            {
                value = Mathf.Round((float)value01 * range) + min;
                GUI.Label(rectLabelValue, GetValueTranslation(value, valueType), UIUtility.uiStyleLabelHint); // slider value
            }
            else
            {
                if (float.TryParse(GUI.TextField(rectLabelValue, value.ToString("F3"), UIUtility.uiStyleInputField), out var temp)) // Add optional numeric input
                {
                    if (!buttonAdjust)
                    {
                        value   = temp;
                        value01 = (value - min) / range;
                    }
                    else
                    {
                        value = Mathf.Round((float)value01 * range) + min;
                    }
                }
                value = Mathf.Clamp(value, min, max);
            }
            changed = valueOld != value01;
            GUILayout.EndHorizontal();
            return(value);
        }
Exemple #3
0
        public static void LoadConfigs()
        {
            config = KSP.IO.PluginConfiguration.CreateForType <WingProceduralManager> ();
            config.load();

            WingProceduralManager.uiRectWindowEditor = config.GetValue("uiRectWindowEditor", UIUtility.SetToScreenCenterAlways(new Rect()));
            WingProceduralManager.uiRectWindowDebug  = config.GetValue <Rect> ("uiRectWindowDebug", UIUtility.SetToScreenCenterAlways(new Rect()));

            WPDebug.logCAV            = Convert.ToBoolean(config.GetValue("logCAV", "false"));
            WPDebug.logUpdate         = Convert.ToBoolean(config.GetValue("logUpdate", "false"));
            WPDebug.logUpdateGeometry = Convert.ToBoolean(config.GetValue("logUpdateGeometry", "false"));

            WPDebug.logUpdateMaterials = Convert.ToBoolean(config.GetValue("logUpdateMaterials", "false"));
            WPDebug.logMeshReferences  = Convert.ToBoolean(config.GetValue("logMeshReferences", "false"));
            WPDebug.logCheckMeshFilter = Convert.ToBoolean(config.GetValue("logCheckMeshFilter", "false"));

            WPDebug.logPropertyWindow = Convert.ToBoolean(config.GetValue("logPropertyWindow", "false"));
            WPDebug.logFlightSetup    = Convert.ToBoolean(config.GetValue("logFlightSetup", "false"));
            WPDebug.logFieldSetup     = Convert.ToBoolean(config.GetValue("logFieldSetup", "false"));

            WPDebug.logFuel   = Convert.ToBoolean(config.GetValue("logFuel", "false"));
            WPDebug.logLimits = Convert.ToBoolean(config.GetValue("logLimits", "false"));
            WPDebug.logEvents = Convert.ToBoolean(config.GetValue("logEvents", "false"));

            //prefs
            WingProcedural.sharedPropAnglePref = Convert.ToBoolean(config.GetValue("AnglePref", "false"));
            //WingProcedural.sharedPropEdgePref = Convert.ToBoolean(config.GetValue("EdgePref", "false"));
            WingProcedural.sharedPropEThickPref = Convert.ToBoolean(config.GetValue("ThickPref", "false"));
        }
        public static float OffsetSlider(float value, float increment, float range, string name, out bool changed, Color backgroundColor, int valueType, ref int delta, bool allowFine = true)
        {
            if (!UIUtility.uiStyleConfigured)
            {
                UIUtility.ConfigureStyles();
            }

            GUILayout.BeginHorizontal();
            value += range / 2;
            int newDelta = (int)(value / range);

            if (newDelta != delta & newDelta != delta + 1)
            {
                delta = newDelta;
            }
            double      value01 = (value - delta * range) / range;
            double      increment01 = increment / range;
            double      valueOld = value01;
            const float buttonWidth = 12, spaceWidth = 3;

            GUILayout.Label(string.Empty, UIUtility.uiStyleLabelHint);
            Rect rectLast        = GUILayoutUtility.GetLastRect();
            Rect rectSlider      = new Rect(rectLast.xMin + buttonWidth + spaceWidth, rectLast.yMin, rectLast.width - 2 * (buttonWidth + spaceWidth), rectLast.height);
            Rect rectSliderValue = new Rect(rectSlider.xMin, rectSlider.yMin, rectSlider.width * (float)value01, rectSlider.height - 3f);
            Rect rectButtonL     = new Rect(rectLast.xMin, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectButtonR     = new Rect(rectLast.xMin + rectLast.width - buttonWidth, rectLast.yMin, buttonWidth, rectLast.height);
            Rect rectLabelValue  = new Rect(rectSlider.xMin + rectSlider.width * 0.75f, rectSlider.yMin, rectSlider.width * 0.25f, rectSlider.height);

            bool buttonAdjust = false;

            if (GUI.Button(rectButtonL, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    if (delta == 0 & value01 > 0.5)
                    {
                        value01 = 0.5;
                    }
                    else if (value01 == 0)
                    {
                        delta -= 1;
                    }
                    else
                    {
                        value01 = 0;
                    }
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 -= increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }
            if (GUI.Button(rectButtonR, string.Empty, UIUtility.uiStyleButton))
            {
                buttonAdjust = true;
                if (Input.GetMouseButtonUp(0) || !allowFine)
                {
                    if (delta == 0 & value01 < 0.5)
                    {
                        value01 = 0.5;
                    }
                    else if (value01 == 1)
                    {
                        delta += 1;
                    }
                    else
                    {
                        value01 = 1;
                    }
                }
                else if (Input.GetMouseButtonUp(1) && allowFine)
                {
                    value01 += increment01;
                }
                else
                {
                    buttonAdjust = false;
                }
            }

            if (!numericInput)
            {
                if (rectLast.Contains(Event.current.mousePosition) && (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && // right click drag doesn't work properly without the event check
                    Event.current.type != EventType.MouseUp)        // drag event covers this, but don't want it to
                {
                    value01 = GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);

                    if (valueOld != value01)
                    {
                        if (Input.GetMouseButton(0) || !allowFine) // normal control
                        {
                            double excess = value01 / increment01;
                            value01 -= (excess - Math.Round(excess)) * increment01;
                        }
                        else if (Input.GetMouseButton(1) && allowFine) // fine control
                        {
                            double excess = valueOld / increment01;
                            value01 = (valueOld - (excess - Math.Round(excess)) * increment01) + Math.Min(value01 - 0.5, 0.4999) * increment01;
                        }
                    }
                }
                else
                {
                    GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);
                }
            }


            GUI.DrawTexture(rectSliderValue, backgroundColor.GetTexture2D()); // slider filled area
            GUI.Label(rectSlider, $"  {name}", UIUtility.uiStyleLabelHint);   // slider name
            if (!numericInput)
            {
                value = (float)(value01 * range + range * delta - range / 2);
                GUI.Label(rectLabelValue, GetValueTranslation(value, valueType), UIUtility.uiStyleLabelHint); // slider value
            }
            else
            {
                value -= range / 2;
                if (float.TryParse(GUI.TextField(rectLabelValue, value.ToString("F3"), UIUtility.uiStyleInputField), out var temp)) // Add optional numeric input
                {
                    if (!buttonAdjust)
                    {
                        value   = temp;
                        value01 = (value - delta * range) / range;
                    }
                    else
                    {
                        value = (float)(value01 * range + range * delta - range / 2);
                    }
                }
                value = Mathf.Clamp(value, float.NegativeInfinity, float.PositiveInfinity);
            }
            changed = valueOld != value01;
            GUILayout.EndHorizontal();
            return(value);
        }