//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>()); }
//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>()); }
//Main GUI window private void Window(int id) { GUILayout.BeginVertical(); #region Info labels StringBuilder builder = new StringBuilder(); builder.Append("Selected part: ").AppendLine(this.part.partInfo.title); builder.Append("Symmetry counterparts: ").AppendLine(this.part.symmetryCounterparts.Count.ToString()); builder.Append("Case mass: ").Append(rcModule.caseMass.ToString()).Append("t"); if (sizes.Count > 0) { builder.Append("\t\t\t\t\tCase cost: ").Append(this.sizes[pChute.size].cost.ToString()).Append("f"); } builder.Append("\nTotal part mass: ").Append(this.part.TotalMass().ToString("0.###")).Append("t"); builder.Append("\t\t\tTotal case part cost: ").Append(this.part.TotalCost().ToString("0.#")).Append("f"); GUILayout.Label(builder.ToString(), skins.label); #endregion #region Presets GUILayout.BeginHorizontal(); if (GUILayout.Button("Select a preset", skins.button)) { this.presetVisible = !this.presetVisible; } if (GUILayout.Button("Save as preset...", skins.button)) { this.presetSaveVisible = !this.presetSaveVisible; } GUILayout.EndHorizontal(); #endregion mainScroll = GUILayout.BeginScrollView(mainScroll, false, false, skins.horizontalScrollbar, skins.verticalScrollbar); #region Planet selector GUILayout.Space(10); GUILayout.BeginHorizontal(GUILayout.Height(30)); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Label("Target planet:", skins.label); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); pChute.planets = GUILayout.SelectionGrid(pChute.planets, pChute.bodies.bodyNames, 4, skins.button, GUILayout.Width(250)); GUILayout.EndHorizontal(); pChute.body = pChute.bodies.GetBody(pChute.planets); #endregion #region Size cyclers if (sizes.Count > 0) { GUILayout.BeginHorizontal(GUILayout.Height(20)); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Label("Cycle part size", skins.label); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Previous size", skins.button, GUILayout.Width(125))) { pChute.size--; if (pChute.size < 0) { pChute.size = sizes.Count - 1; } } if (GUILayout.Button("Next size", skins.button, GUILayout.Width(125))) { pChute.size++; if (pChute.size > sizes.Count - 1) { pChute.size = 0; } } GUILayout.EndHorizontal(); } #endregion GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); #region Texture selectors GUILayout.Space(5); chutes[0].TextureSelector(); #endregion #region General //Materials editor GUILayout.Space(5); chutes[0].MaterialsSelector(); //MustGoDown GUILayout.Space(5); GUILayout.BeginHorizontal(GUILayout.MaxWidth(window.width)); GUILayout.Label("Must go down to deploy:", skins.label); if (GUILayout.Toggle(pChute.mustGoDown, "True", skins.toggle)) { pChute.mustGoDown = true; } GUILayout.FlexibleSpace(); if (GUILayout.Toggle(!pChute.mustGoDown, "False", skins.toggle)) { pChute.mustGoDown = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //DeployOnGround GUILayout.Space(5); GUILayout.BeginHorizontal(GUILayout.MaxWidth(window.width)); GUILayout.Label("Deploy on ground contact:", skins.label); if (GUILayout.Toggle(pChute.deployOnGround, "True", skins.toggle)) { pChute.deployOnGround = true; } GUILayout.FlexibleSpace(); if (GUILayout.Toggle(!pChute.deployOnGround, "False", skins.toggle)) { pChute.deployOnGround = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //Timer GUILayout.Space(5); GUILayout.BeginHorizontal(); if (RCUtils.CanParseTime(pChute.timer) && RCUtils.CheckRange(RCUtils.ParseTime(pChute.timer), 0, 3600)) { GUILayout.Label("Deployment timer:", skins.label); } else { GUILayout.Label("Deployment timer:", RCUtils.redLabel); } GUILayout.FlexibleSpace(); pChute.timer = GUILayout.TextField(pChute.timer, 10, skins.textField, GUILayout.Width(150)); GUILayout.EndHorizontal(); //Spares GUILayout.Space(5); GUILayout.BeginHorizontal(); if (RCUtils.CanParseWithEmpty(pChute.spares) && RCUtils.CheckRange(RCUtils.ParseWithEmpty(pChute.spares), -1, 10) && RCUtils.IsWholeNumber(RCUtils.ParseWithEmpty(pChute.spares))) { GUILayout.Label("Spare chutes:", skins.label); } else { GUILayout.Label("Spare chutes:", RCUtils.redLabel); } GUILayout.FlexibleSpace(); pChute.spares = GUILayout.TextField(pChute.spares, 10, skins.textField, GUILayout.Width(150)); GUILayout.EndHorizontal(); //CutSpeed CreateEntryArea("Autocut speed (m/s):", ref pChute.cutSpeed, 0.01f, 100); //LandingAlt CreateEntryArea("Landing alt (m):", ref pChute.landingAlt, 0, (float)pChute.body.GetMaxAtmosphereAltitude()); #endregion #region Main //Indicator label GUILayout.Space(10); GUILayout.Label("________________________________________________", RCUtils.boldLabel); GUILayout.Label("Main chute:", RCUtils.boldLabel, GUILayout.Width(150)); GUILayout.Label("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾", RCUtils.boldLabel); chutes[0].Calculations(); #endregion #region Secondary if (pChute.secondaryChute) { for (int i = 1; i < chutes.Count; i++) { ChuteTemplate chute = chutes[i]; //Indicator label GUILayout.Space(10); GUILayout.Label("________________________________________________", RCUtils.boldLabel); GUILayout.Label("Chute #" + (i + 1) + " :", RCUtils.boldLabel, GUILayout.Width(150)); GUILayout.Label("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾", RCUtils.boldLabel); #region Texture selectors GUILayout.Space(5); chute.TextureSelector(); #endregion //Materials editor GUILayout.Space(5); chute.MaterialsSelector(); chute.Calculations(); } } #endregion GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); #region Application GUILayout.Space(5); if (GUILayout.Button("Apply settings", skins.button)) { pChute.Apply(false); } if (part.symmetryCounterparts.Count > 0) { if (GUILayout.Button("Apply to all symmetry counterparts", skins.button)) { pChute.Apply(true); } } #endregion GUILayout.EndVertical(); }
//Main GUI window private void Window(int id) { GUILayout.BeginVertical(); #region Info labels GUILayout.Label("Selected part: " + this.part.partInfo.title, skins.label); GUILayout.Label("Symmetry counterparts: " + (this.part.symmetryCounterparts.Count), skins.label); GUILayout.Label("Case mass: " + rcModule.caseMass + "t", skins.label); GUILayout.Label("Total part mass: " + this.part.TotalMass().ToString("0.###") + "t", skins.label); #endregion #region Presets GUILayout.BeginHorizontal(); if (GUILayout.Button("Select a preset", skins.button)) { this.presetVisible = !this.presetVisible; } if (GUILayout.Button("Save as preset...", skins.button)) { this.presetSaveVisible = !this.presetSaveVisible; } GUILayout.EndHorizontal(); #endregion #region Planet selector GUILayout.Space(10); GUILayout.BeginHorizontal(GUILayout.Height(30)); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Label("Target planet:", skins.label); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); planets = GUILayout.SelectionGrid(planets, bodies.GetNames(), 4, skins.button, GUILayout.Width(250)); GUILayout.EndHorizontal(); body = bodies.GetBody(planets); #endregion #region Size cyclers if (sizes.Count > 0) { GUILayout.BeginHorizontal(GUILayout.Height(20)); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); GUILayout.Label("Cycle part size", skins.label); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Previous size", skins.button, GUILayout.Width(125))) { size--; if (size < 0) { size = sizes.Count - 1; } } if (GUILayout.Button("Next size", skins.button, GUILayout.Width(125))) { size++; if (size > sizes.Count - 1) { size = 0; } } GUILayout.EndHorizontal(); } #endregion GUILayout.Space(5); mainScroll = GUILayout.BeginScrollView(mainScroll, false, false, skins.horizontalScrollbar, skins.verticalScrollbar); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); #region Texture selectors GUILayout.Space(5); main.TextureSelector(); #endregion #region General //Materials editor GUILayout.Space(5); main.MaterialsSelector(); //MustGoDown GUILayout.Space(5); GUILayout.BeginHorizontal(GUILayout.MaxWidth(window.width)); GUILayout.Label("Must go down to deploy:", skins.label); if (GUILayout.Toggle(mustGoDown, "True", skins.toggle)) { mustGoDown = true; } GUILayout.FlexibleSpace(); if (GUILayout.Toggle(!mustGoDown, "False", skins.toggle)) { mustGoDown = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //DeployOnGround GUILayout.Space(5); GUILayout.BeginHorizontal(GUILayout.MaxWidth(window.width)); GUILayout.Label("Deploy on ground contact:", skins.label); if (GUILayout.Toggle(deployOnGround, "True", skins.toggle)) { deployOnGround = true; } GUILayout.FlexibleSpace(); if (GUILayout.Toggle(!deployOnGround, "False", skins.toggle)) { deployOnGround = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //Timer GUILayout.Space(5); GUILayout.BeginHorizontal(); if (RCUtils.CanParseTime(timer) && RCUtils.CheckRange(RCUtils.ParseTime(timer), 0, 3600)) { GUILayout.Label("Deployment timer:", skins.label); } else { GUILayout.Label("Deployment timer:", RCUtils.redLabel); } GUILayout.FlexibleSpace(); timer = GUILayout.TextField(timer, 10, skins.textField, GUILayout.Width(150)); GUILayout.EndHorizontal(); //Spares GUILayout.Space(5); GUILayout.BeginHorizontal(); if (RCUtils.CanParseWithEmpty(spares) && RCUtils.CheckRange(RCUtils.ParseWithEmpty(spares), -1, 10) && RCUtils.IsWholeNumber(RCUtils.ParseWithEmpty(spares))) { GUILayout.Label("Spare chutes:", skins.label); } else { GUILayout.Label("Spare chutes:", RCUtils.redLabel); } GUILayout.FlexibleSpace(); spares = GUILayout.TextField(spares, 10, skins.textField, GUILayout.Width(150)); GUILayout.EndHorizontal(); //CutSpeed CreateEntryArea("Autocut speed (m/s):", ref cutSpeed, 0.01f, 100); #endregion #region Main //Indicator label GUILayout.Space(10); GUILayout.Label("________________________________________________", RCUtils.boldLabel); GUILayout.Label("Main chute:", RCUtils.boldLabel, GUILayout.Width(150)); GUILayout.Label("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾", RCUtils.boldLabel); main.Calculations(); #endregion #region Secondary if (secondaryChute) { //Indicator label GUILayout.Space(10); GUILayout.Label("________________________________________________", RCUtils.boldLabel); GUILayout.Label("Secondary chute:", RCUtils.boldLabel, GUILayout.Width(150)); GUILayout.Label("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾", RCUtils.boldLabel); #region Texture selectors GUILayout.Space(5); secondary.TextureSelector(); #endregion //Materials editor GUILayout.Space(5); secondary.MaterialsSelector(); secondary.Calculations(); } #endregion GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); #region Application GUILayout.Space(5); if (GUILayout.Button("Apply settings", skins.button)) { Apply(false); } if (part.symmetryCounterparts.Count > 0) { if (GUILayout.Button("Apply to all symmetry counterparts", skins.button)) { Apply(true); } } #endregion GUILayout.EndVertical(); }
//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 }