1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | // // VOID_Orbital.cs // // Author: // toadicus <> // // Copyright (c) 2013 toadicus // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. using KSP; using System; using System.Linq; using UnityEngine; namespace VOID { public class VOID_VesselRegister : VOID_WindowModule { [AVOID_SaveValue("selectedBodyIdx")] protected VOID_SaveValue<int> selectedBodyIdx = 0; protected CelestialBody seletedBody; [AVOID_SaveValue("selectedVesselTypeIdx")] protected VOID_SaveValue<int> selectedVesselTypeIdx = 0; protected VesselType selectedVesselType; protected string vesselSituation = "Orbiting"; protected Vector2 selectorScrollPos = new Vector2(); protected Vessel _selectedVessel; public Vessel selectedVessel { get { return this._selectedVessel; } } public VOID_VesselRegister() { this._Name = "Vessel Register"; this.WindowPos.x = 845; this.WindowPos.y = 275; this.defHeight = 375; } public override void ModuleWindow(int _) { if (!VOID_Core.Instance.allVesselTypes.Any()) { return; } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("<")) { selectedBodyIdx--; if (selectedBodyIdx < 0) selectedBodyIdx = VOID_Core.Instance.allBodies.Count - 1; } GUILayout.Label(VOID_Core.Instance.allBodies[selectedBodyIdx].bodyName, VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true)); if (GUILayout.Button(">")) { selectedBodyIdx++; if (selectedBodyIdx > VOID_Core.Instance.allBodies.Count - 1) selectedBodyIdx = 0; } GUILayout.EndHorizontal(); seletedBody = VOID_Core.Instance.allBodies[selectedBodyIdx]; GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("<")) { selectedVesselTypeIdx--; if (selectedVesselTypeIdx < 0) selectedVesselTypeIdx = VOID_Core.Instance.allVesselTypes.Count - 1; } GUILayout.Label(VOID_Core.Instance.allVesselTypes[selectedVesselTypeIdx].ToString(), VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true)); if (GUILayout.Button(">")) { selectedVesselTypeIdx++; if (selectedVesselTypeIdx > VOID_Core.Instance.allVesselTypes.Count - 1) selectedVesselTypeIdx = 0; } GUILayout.EndHorizontal(); selectedVesselType = VOID_Core.Instance.allVesselTypes[selectedVesselTypeIdx]; GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("Landed", GUILayout.ExpandWidth(true))) vesselSituation = "Landed"; if (GUILayout.Button("Orbiting", GUILayout.ExpandWidth(true))) vesselSituation = "Orbiting"; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label( Tools.UppercaseFirst(vesselSituation) + " " + selectedVesselType.ToString() + "s @ " + seletedBody.bodyName, VOID_Core.Instance.LabelStyles["center"], GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); selectorScrollPos = GUILayout.BeginScrollView(selectorScrollPos, false, false); foreach (Vessel v in FlightGlobals.Vessels) { if (v != vessel && v.vesselType == selectedVesselType && v.mainBody == seletedBody) { if ((vesselSituation == "Landed" && (v.situation == Vessel.Situations.LANDED || v.situation == Vessel.Situations.PRELAUNCH || v.situation == Vessel.Situations.SPLASHED)) || (vesselSituation == "Orbiting" && (v.situation == Vessel.Situations.ESCAPING || v.situation == Vessel.Situations.FLYING || v.situation == Vessel.Situations.ORBITING || v.situation == Vessel.Situations.SUB_ORBITAL)) ) { if (GUILayout.Button(v.vesselName, GUILayout.ExpandWidth(true))) { if (_selectedVessel != v) { _selectedVessel = v; //set clicked vessel as selected_vessel this._Active = true; //turn bool on to open the window if closed } else { _selectedVessel = null; } } } } } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.DragWindow(); } } } |