コード例 #1
0
        //Lists the errors of a given type
        internal List <string> GetErrors(string type)
        {
            if (type == "general")
            {
                List <string> general = new List <string>();

                if (!RCUtils.CanParseTime(timer) || !RCUtils.CheckRange(RCUtils.ParseTime(timer), 0, 3600))
                {
                    general.Add("Deployment timer");
                }
                if (!RCUtils.CanParseWithEmpty(spares) || !RCUtils.CheckRange(RCUtils.ParseWithEmpty(spares), -1, 10) || !RCUtils.IsWholeNumber(RCUtils.ParseWithEmpty(spares)))
                {
                    general.Add("Spare chutes");
                }
                if (!RCUtils.CanParse(cutSpeed) || !RCUtils.CheckRange(float.Parse(cutSpeed), 0.01f, 100))
                {
                    general.Add("Autocut speed");
                }
                if (!RCUtils.CanParse(landingAlt) || !RCUtils.CheckRange(float.Parse(landingAlt), 0, (float)body.GetMaxAtmosphereAltitude()))
                {
                    general.Add("Landing altitude");
                }
                return(general);
            }
            else if (type == "main" || type == "secondary")
            {
                return(chutes.SelectMany(c => c.errors).ToList());
            }
            return(new List <string>());
        }
コード例 #2
0
        //Lists the errors of a given type
        private List <string> GetErrors(string type)
        {
            if (type == "general")
            {
                List <string> general = new List <string>();

                if (!RCUtils.CanParseTime(timer) || !RCUtils.CheckRange(RCUtils.ParseTime(timer), 0, 3600))
                {
                    general.Add("Deployment timer");
                }
                if (!RCUtils.CanParseWithEmpty(spares) || !RCUtils.CheckRange(RCUtils.ParseWithEmpty(spares), -1, 10) || !RCUtils.IsWholeNumber(RCUtils.ParseWithEmpty(spares)))
                {
                    general.Add("Spare chutes");
                }
                if (!RCUtils.CanParse(cutSpeed) || !RCUtils.CheckRange(float.Parse(cutSpeed), 0.01f, 100))
                {
                    general.Add("Autocut speed");
                }
                return(general);
            }
            else if (type == "main")
            {
                return(main.errors);
            }
            else if (type == "secondary")
            {
                return(secondary.errors);
            }
            return(new List <string>());
        }
コード例 #3
0
 //Creates a label + text field
 internal void CreateEntryArea(string label, ref string value, float min, float max, float width = 150)
 {
     GUILayout.Space(5);
     GUILayout.BeginHorizontal();
     if (RCUtils.CanParse(value) && RCUtils.CheckRange(float.Parse(value), min, max))
     {
         GUILayout.Label(label, skins.label);
     }
     else
     {
         GUILayout.Label(label, RCUtils.redLabel);
     }
     GUILayout.FlexibleSpace();
     value = GUILayout.TextField(value, 10, skins.textField, GUILayout.Width(width));
     GUILayout.EndHorizontal();
 }
コード例 #4
0
ファイル: ChuteTemplate.cs プロジェクト: Apoapsis-A/RealChute
        //Calculations GUI core
        internal void Calculations()
        {
            #region Calculations
            //Selection mode
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Calculations mode:", skins.label);
            if (GUILayout.Toggle(calcSelect, "Automatic", skins.toggle))
            {
                calcSelect = true;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Toggle(!calcSelect, "Manual", skins.toggle))
            {
                calcSelect = false;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(5);

            //Calculations
            parachuteScroll = GUILayout.BeginScrollView(parachuteScroll, false, false, skins.horizontalScrollbar, skins.verticalScrollbar, skins.box, GUILayout.Height(160));

            #region Automatic
            if (calcSelect)
            {
                typeID = GUILayout.SelectionGrid(typeID, RCUtils.types, 3, skins.button);

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Toggle(getMass, "Use current craft mass", skins.button, GUILayout.Width(150)))
                {
                    getMass = true;
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Toggle(!getMass, "Input craft mass", skins.button, GUILayout.Width(150)))
                {
                    getMass = false;
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                if (getMass)
                {
                    GUILayout.Label("Currently using " + (useDry ? "dry mass" : "wet mass"), skins.label);
                    if (useDry)
                    {
                        if (GUILayout.Button("Switch to wet mass", skins.button, GUILayout.Width(125)))
                        {
                            useDry = false;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Switch to dry mass", skins.button, GUILayout.Width(125)))
                        {
                            useDry = true;
                        }
                    }
                }

                else
                {
                    string m = mass;
                    this.editorGUI.CreateEntryArea("Mass to use (t):", ref m, 0.1f, 10000, 100);
                    mass = m;
                }

                GUILayout.Space(5);
                GUILayout.BeginHorizontal();
                if (typeID == 0)
                {
                    if (RCUtils.CanParse(landingSpeed) && RCUtils.CheckRange(float.Parse(landingSpeed), 0.1f, 300))
                    {
                        GUILayout.Label("Wanted touchdown speed (m/s):", skins.label);
                    }
                    else
                    {
                        GUILayout.Label("Wanted touchdown speed (m/s):", RCUtils.redLabel);
                    }
                }
                else if (typeID == 1)
                {
                    if (RCUtils.CanParse(landingSpeed) && RCUtils.CheckRange(float.Parse(landingSpeed), 0.1f, 5000))
                    {
                        GUILayout.Label("Wanted speed at target alt (m/s):", skins.label);
                    }
                    else
                    {
                        GUILayout.Label("Wanted speed at target alt (m/s):", RCUtils.redLabel);
                    }
                }
                else
                {
                    if (RCUtils.CanParse(landingSpeed) && RCUtils.CheckRange(float.Parse(landingSpeed), 0.1f, 300))
                    {
                        GUILayout.Label("Planned landing speed (m/s):", skins.label);
                    }
                    else
                    {
                        GUILayout.Label("Planned landing speed (m/s):", RCUtils.redLabel);
                    }
                }
                GUILayout.FlexibleSpace();
                landingSpeed = GUILayout.TextField(landingSpeed, 10, skins.textField, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                if (typeID == 2)
                {
                    string decel = deceleration;
                    this.editorGUI.CreateEntryArea("Wanted deceleration (m/s²):", ref decel, 0.1f, 100, 100);
                    deceleration = decel;
                }

                if (typeID == 1)
                {
                    string depAlt = refDepAlt;
                    this.editorGUI.CreateEntryArea("Target altitude (m):", ref depAlt, 10, (float)body.GetMaxAtmosphereAltitude(), 100);
                    refDepAlt = depAlt;
                }

                string chutes = chuteCount;
                this.editorGUI.CreateEntryArea("Parachutes used (parts):", ref chutes, 1, 100, 100);
                chuteCount = chutes;
            }
            #endregion

            #region Manual
            else
            {
                //Predeployed diameter
                string preDep = preDepDiam, dep = depDiam;
                this.editorGUI.CreateEntryArea("Predeployed diameter (m):", ref preDep, 0.5f, model.maxDiam / 2, 100);
                if (RCUtils.CanParse(preDepDiam))
                {
                    GUILayout.Label("Resulting area: " + RCUtils.GetArea(float.Parse(preDepDiam)).ToString("0.00") + "m²", skins.label);
                }
                else
                {
                    GUILayout.Label("Resulting predeployed area: --- m²", skins.label);
                }

                //Deployed diameter
                this.editorGUI.CreateEntryArea("Deployed diameter (m):", ref dep, 1, model.maxDiam, 100);
                if (RCUtils.CanParse(depDiam))
                {
                    GUILayout.Label("Resulting area: " + RCUtils.GetArea(float.Parse(depDiam)).ToString("0.00") + "m²", skins.label);
                }
                else
                {
                    GUILayout.Label("Resulting deployed area: --- m²", skins.label);
                }
                preDepDiam = preDep;
                depDiam    = dep;
            }
            #endregion

            GUILayout.EndScrollView();
            #endregion

            #region Specific
            //Pressure/alt toggle
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle(isPressure, "Pressure predeployment", skins.toggle))
            {
                if (!isPressure)
                {
                    isPressure        = true;
                    this.predepClause = this.parachute.minPressure.ToString();
                }
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Toggle(!isPressure, "Altitude predeployment", skins.toggle))
            {
                if (isPressure)
                {
                    isPressure        = false;
                    this.predepClause = this.parachute.minDeployment.ToString();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            if (isPressure)
            {
                if (RCUtils.CanParse(predepClause) && RCUtils.CheckRange(float.Parse(predepClause), 0.0001f, (float)body.GetPressureASL()))
                {
                    GUILayout.Label("Predeployment pressure (atm):", skins.label);
                }
                else
                {
                    GUILayout.Label("Predeployment pressure (atm):", RCUtils.redLabel);
                }
            }
            else
            {
                if (RCUtils.CanParse(predepClause) && RCUtils.CheckRange(float.Parse(predepClause), 10, (float)body.GetMaxAtmosphereAltitude()))
                {
                    GUILayout.Label("Predeployment altitude (m):", skins.label);
                }
                else
                {
                    GUILayout.Label("Predeployment altitude (m):", RCUtils.redLabel);
                }
            }
            GUILayout.FlexibleSpace();
            predepClause = GUILayout.TextField(predepClause, 10, skins.textField, GUILayout.Width(150));
            GUILayout.EndHorizontal();

            //Deployment altitude
            this.editorGUI.CreateEntryArea("Deployment altitude", ref deploymentAlt, 10, (float)body.GetMaxAtmosphereAltitude());

            //Cut altitude
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            if (RCUtils.CanParseWithEmpty(cutAlt) && RCUtils.CheckRange(RCUtils.ParseWithEmpty(cutAlt), -1, (float)body.GetMaxAtmosphereAltitude()))
            {
                GUILayout.Label("Autocut altitude (m):", skins.label);
            }
            else
            {
                GUILayout.Label("Autocut altitude (m):", RCUtils.redLabel);
            }
            GUILayout.FlexibleSpace();
            cutAlt = GUILayout.TextField(cutAlt, 10, skins.textField, GUILayout.Width(150));
            GUILayout.EndHorizontal();

            //Predeployment speed
            this.editorGUI.CreateEntryArea("Pre deployment speed (s):", ref preDepSpeed, 0.5f, 5);

            //Deployment speed
            this.editorGUI.CreateEntryArea("Deployment speed (s):", ref depSpeed, 1, 10);
            #endregion
        }