/// <summary> /// Generates a set of PartSelectors and allows the user to click a part to add the crew. /// </summary> /// <param name="member">The crew member to add.</param> public void GenerateSelection(ProtoCrewMember member) { // Show upper selection message. ScreenMessages.PostScreenMessage("<color=" + TwitchPurple.Hex + ">Select a pod for " + member.name + " (" + member.experienceTrait.Title + ").</color>", upper); // Lock the the inputs to prevent launch and other shenanigans. InputLockManager.SetControlLock(ControlTypes.ALLBUTCAMERAS, "DTVAddCrew"); // Create the Selector list. selectors = new List <PartSelector>(); // Gets a list of available seats. List <Part> availableSeats = new List <Part>(); // Cycle through all parts. foreach (Part p in FlightGlobals.ActiveVessel.Parts) { // If it has crew capacity, if (p.CrewCapacity > 0) { // And if it has available space, if (p.protoModuleCrew.Count < p.CrewCapacity) { // Add to the list. availableSeats.Add(p); } } } // If no available spots were found, if (availableSeats.Count == 0) { // Post to the screen and leave it. ScreenMessages.PostScreenMessage("<color=" + XKCDColors.HexFormat.KSPNotSoGoodOrange + ">No available seating.</color>", 3f, ScreenMessageStyle.LOWER_CENTER); // Clean up the manager CleanUp(); } // Else, a seat is available. else { // Set the toAdd crew member field. toAdd = member; // For each available spot, foreach (Part p in availableSeats) { // Generate a selector. selectors.Add(PartSelector.Create(p, new Callback <Part>(OnPartSelected), TwitchPurple.RGB, new Color(TwitchPurple.RGB.r - 0.2f, TwitchPurple.RGB.g - 0.2f, TwitchPurple.RGB.b - 0.2f))); } } }
public void Enable() { driver.isEnabled = !driver.isEnabled; Events["Enable"].guiName = !driver.isEnabled ? "Start" : "Stop"; Fields["timePassed"].guiActive = driver.isEnabled; // Create the Race if (driver.isEnabled) { Airrace race = new Airrace { amount = FlightGlobals.Vessels.Count(v => v.FindPartModulesImplementing <AirraceTargetModule>().Count != 0), position = 1, rounds = 0, targets = FlightGlobals.Vessels.SelectMany(v => v.FindPartModulesImplementing <AirraceTargetModule>()).OrderBy(m => m.order).ToList() }; qc = 0; timePassed = "00:00:0000"; driver.race = race; ScreenMessages.PostScreenMessage("Jeb ist am Drücker. Flieg durch die erste Pylone!", 5f, ScreenMessageStyle.UPPER_CENTER); driver.next = PartSelector.Create(race.targets[0].part, p => { }, XKCDColors.BrightAqua, XKCDColors.BrightAqua); } else { driver.race = null; foreach (PartSelector s in driver.all.Values) { s.Dismiss(); } driver.all.Clear(); driver.isRacing = false; ScreenMessages sm = (ScreenMessages)GameObject.FindObjectOfType(typeof(ScreenMessages)); foreach (ScreenMessage msg in sm.ActiveMessages.ToList <ScreenMessage>()) { ScreenMessages.RemoveMessage(msg); } if (driver.isTraining) { driver.isEnabled = false; Enable(); } } }
public void setHighlight(bool on) { if (on && !highlighting) { if (timer < 2) { timer++; } else { highlighting = true; highlighter = PartSelector.Create(crew.InPart, null, iconColor, iconColor); } } if (highlighting && !on) { timer = 0; highlighting = false; highlighter.Dismiss(); } }
// Gets called when someone passes a target public void Trigger(AirraceTargetModule target) { audiosource.transform.position = vessel.rootPart.transform.position; if (target.order == race?.position && race.targets.Contains(target)) { race.position++; next.Dismiss(); all.Clear(); ScreenMessages.PostScreenMessage("Pylone " + target.order + " passiert (Zeit: " + controller.timePassed + ")", 3f, ScreenMessageStyle.UPPER_CENTER); if (race.targets.Count != (Int32)target.order && all.ContainsKey(race.targets[(Int32)target.order].part)) { all[race.targets[(Int32)target.order].part].Dismiss(); all.Remove(race.targets[(Int32)target.order].part); } all.Add(target.part, PartSelector.Create(target.part, p => { }, XKCDColors.GrassyGreen, XKCDColors.GrassyGreen)); if (target.modus == "Start") { raceStart = Planetarium.GetUniversalTime(); isRacing = true; next = PartSelector.Create(race.targets[(Int32)target.order].part, p => { }, XKCDColors.BrightAqua, XKCDColors.BrightAqua); ScreenMessages.PostScreenMessage("Nächste Pylone: " + race.targets[(Int32)target.order].part.vessel.vesselName, 5f, ScreenMessageStyle.UPPER_CENTER); } else if (target.modus == "Ziel") { ScreenMessages.PostScreenMessage("Zielpylone passiert (Zeit: " + controller.timePassed + ") @" + System.Math.Round(controller.vessel.speed, 1) + "m/s", 100f, ScreenMessageStyle.LOWER_CENTER); race.time = TimeSpan.FromSeconds(Planetarium.GetUniversalTime() - raceStart); controller.qc = (Int32)(race.time.TotalMilliseconds * 0.1337); times.Add(race.time, controller.qc); record = times.Keys.Min(); isRacing = false; Vessel v = GetComponent <Vessel>(); foreach (Part p in v.parts) { all.Add(p, PartSelector.Create(p, pa => { }, XKCDColors.GrassyGreen, XKCDColors.GrassyGreen)); } if (isTraining) { controller.Enable(); } } else if (target.modus == "Start+Ziel") { if (target.rounds == race.rounds) { ScreenMessages.PostScreenMessage("Zielpylone passiert (Zeit: " + controller.timePassed + ") @" + System.Math.Round(controller.vessel.speed, 1) + "m/s", 10f, ScreenMessageStyle.LOWER_CENTER); race.time = TimeSpan.FromSeconds(Planetarium.GetUniversalTime() - raceStart); controller.qc = (Int32)(race.time.TotalMilliseconds * 0.1337); times.Add(race.time, controller.qc); record = times.Keys.Min(); isRacing = false; Vessel v = GetComponent <Vessel>(); foreach (Part p in v.parts) { all.Add(p, PartSelector.Create(p, pa => { }, XKCDColors.GrassyGreen, XKCDColors.GrassyGreen)); } if (isTraining) { controller.Enable(); } } else { if (race.rounds == 0) { raceStart = Planetarium.GetUniversalTime(); isRacing = true; } race.rounds++; next = PartSelector.Create(race.targets[(Int32)target.order].part, p => { }, XKCDColors.BrightAqua, XKCDColors.BrightAqua); ScreenMessages.PostScreenMessage("Nächste Pylone: " + (string)next.Host.vessel.vesselName, 5f, ScreenMessageStyle.UPPER_CENTER); } } else if (race.targets.Count == (Int32)target.order && race.targets[0].modus == "Start+Ziel") { #if debug all[race.targets[0].part].Dismiss(); all.Remove(race.targets[0].part); foreach (AirraceTargetModule art in race.targets) { all.Remove(art.part); // all.Add(p, PartSelector.Create(p, pa => { }, XKCDColors.GrassyGreen, XKCDColors.GrassyGreen)); } #endif all.Clear(); next = PartSelector.Create(race.targets[0].part, p => { }, XKCDColors.BrightAqua, XKCDColors.BrightAqua); ScreenMessages.PostScreenMessage("Nächste Pylone: " + race.targets[0].part.vessel.vesselName, 5f, ScreenMessageStyle.UPPER_CENTER); race.position = 1; } else { next = PartSelector.Create(race.targets[(Int32)target.order].part, p => { }, XKCDColors.BrightAqua, XKCDColors.BrightAqua); ScreenMessages.PostScreenMessage("Nächste Pylone: " + (string)next.Host.vessel.vesselName, 5f, ScreenMessageStyle.UPPER_CENTER); } if (!isTraining) { audiosource.PlayOneShot(correct); } } }