internal static int GetPartCrewCount(Part part) { int crewCount = 0; if (!InstalledMods.IsDfApiReady) { return(crewCount + part.protoModuleCrew.Count); } if (!part.Modules.Contains("DeepFreezer")) { return(crewCount + part.protoModuleCrew.Count); } PartModule freezerModule = SMConditions.GetFreezerModule(part); // ReSharper disable once SuspiciousTypeConversion.Global DFWrapper.DeepFreezer freezer = new DFWrapper.DeepFreezer(freezerModule); crewCount += freezer.TotalFrozen; return(crewCount + part.protoModuleCrew.Count); }
internal static string DisplayVesselResourceTotals(string selectedResource) { string displayAmount = ""; double currAmount = 0; double totAmount = 0; if (selectedResource == null) { return(string.Format(" - ({0})", currAmount.ToString("#######0"))); } try { if (SMConditions.IsResourceTypeOther(selectedResource)) { List <Part> .Enumerator parts = SMAddon.SmVessel.PartsByResource[selectedResource].GetEnumerator(); while (parts.MoveNext()) { if (parts.Current == null) { continue; } currAmount += parts.Current.Resources[selectedResource].amount; totAmount += parts.Current.Resources[selectedResource].maxAmount; } parts.Dispose(); } switch (SMConditions.TypeOfResource(selectedResource)) { case SMConditions.ResourceType.Crew: currAmount = SMAddon.SmVessel.Vessel.GetCrewCount(); totAmount = SMAddon.SmVessel.Vessel.GetCrewCapacity(); // if DF installed, get total frozen and add to count. if (InstalledMods.IsDfInstalled) { List <Part> .Enumerator cryofreezers = GetFreezerParts().GetEnumerator(); // ReSharper disable once SuspiciousTypeConversion.Global while (cryofreezers.MoveNext()) { if (cryofreezers.Current == null) { continue; } currAmount += new DFWrapper.DeepFreezer(SMConditions.GetFreezerModule(cryofreezers.Current)).TotalFrozen; } cryofreezers.Dispose(); } // Now check for occupied external seats // external seats that are occupied will show up in getcrewcount and getcrewcapacity // Since we cannot yet xfer external crew, we need to remove them from the count.. List <KerbalSeat> seatCount = (from iPart in SMAddon.SmVessel.Vessel.parts where iPart.Modules.Contains("KerbalSeat") from PartModule iModule in iPart.Modules where iModule.ClassName == "KerbalSeat" select(KerbalSeat) iModule into kSeat where kSeat.Occupant != null select kSeat).ToList(); currAmount -= seatCount.Count; totAmount -= seatCount.Count; break; case SMConditions.ResourceType.Science: currAmount += SMAddon.SmVessel.PartsByResource[selectedResource].SelectMany(part => part.Modules.Cast <PartModule>()) .OfType <IScienceDataContainer>() .Sum(module => (double)module.GetScienceCount()); break; } displayAmount = selectedResource != SMConditions.ResourceType.Science.ToString() ? string.Format(" - ({0}/{1})", currAmount.ToString("#######0"), totAmount.ToString("######0")) : string.Format(" - ({0})", currAmount.ToString("#######0")); } catch (Exception ex) { LogMessage(string.Format(" in DisplayResourceTotals(). Error: {0}", ex), LogType.Error, true); } return(displayAmount); }
internal static bool CanKerbalsBeXferred(List<Part> selectedPartsSource, List<Part> selectedPartsTarget) { bool results = false; try { if (IsTransferInProgress()) { WindowTransfer.XferToolTip = "Transfer in progress. Xfers disabled."; return false; } if (selectedPartsSource.Count == 0 || selectedPartsTarget.Count == 0) { WindowTransfer.XferToolTip = "Source or Target Part is not selected.\r\nPlease Select a Source AND a Target part."; return false; } if (selectedPartsSource[0] == selectedPartsTarget[0]) { WindowTransfer.XferToolTip = "Source and Target Part are the same.\r\nUse Move Kerbal (>>) instead."; return false; } // If one of the parts is a DeepFreeze part and no crew are showing in protoModuleCrew, check it isn't full of frozen Kerbals. // This is to prevent SM from Transferring crew into a DeepFreeze part that is full of frozen kerbals. // If there is just one spare seat or seat taken by a Thawed Kerbal that is OK because SM will just transfer them into the empty // seat or swap them with a thawed Kerbal. DFWrapper.DeepFreezer sourcepartFrzr = null; // selectedPartsSource[0].FindModuleImplementing<DFWrapper.DeepFreezer>(); DFWrapper.DeepFreezer targetpartFrzr = null; // selectedPartsTarget[0].FindModuleImplementing<DFWrapper.DeepFreezer>(); PartModule sourcedeepFreezer = GetFreezerModule(selectedPartsSource[0]); if (sourcedeepFreezer != null) sourcepartFrzr = new DFWrapper.DeepFreezer(sourcedeepFreezer); PartModule targetdeepFreezer = GetFreezerModule(selectedPartsTarget[0]); if (targetdeepFreezer != null) targetpartFrzr = new DFWrapper.DeepFreezer(targetdeepFreezer); if (sourcepartFrzr != null) { if (sourcepartFrzr.FreezerSpace == 0) { WindowTransfer.XferToolTip = "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed."; return false; } } if (targetpartFrzr != null) { if (targetpartFrzr.FreezerSpace == 0) { WindowTransfer.XferToolTip = "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed."; return false; } } // Are there kerbals to move? if (selectedPartsSource[0].protoModuleCrew.Count == 0) { WindowTransfer.XferToolTip = "No Kerbals to Move."; return false; } // now if realism mode, are the parts connected to each other in the same living space? results = IsClsInSameSpace(); if (!results) WindowTransfer.EvaToolTip = "CLS is preventing internal Crew Transfer. Click to initiate EVA operation."; } catch (Exception ex) { Utilities.LogMessage(string.Format(" in CanBeXferred. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), Utilities.LogType.Error, true); } if (WindowTransfer.XferToolTip == "") WindowTransfer.XferToolTip = "Source and target Part are the same. Use Move Kerbal instead."; return results; }
internal static bool CanKerbalsBeXferred(List <Part> selectedPartsSource, List <Part> selectedPartsTarget) { bool results = true; WindowTransfer.XferToolTip = ""; try { if (IsTransferInProgress()) { //WindowTransfer.XferToolTip = "Transfer in progress. Xfers disabled."; WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_001"); return(false); } if (selectedPartsSource.Count == 0 || selectedPartsTarget.Count == 0) { WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_002"); // "Source or Target Part is not selected.\r\nPlease Select a Source AND a Target part."; return(false); } if (selectedPartsSource[0] == selectedPartsTarget[0]) { WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_003"); // "Source and Target Part are the same.\r\nUse Move Kerbal (>>) instead."; return(false); } // If one of the parts is a DeepFreeze part and no crew are showing in protoModuleCrew, check it isn't full of frozen Kerbals. // This is to prevent SM from Transferring crew into a DeepFreeze part that is full of frozen kerbals. // If there is just one spare seat or seat taken by a Thawed Kerbal that is OK because SM will just transfer them into the empty // seat or swap them with a thawed Kerbal. DFWrapper.DeepFreezer sourcepartFrzr = null; // selectedPartsSource[0].FindModuleImplementing<DFWrapper.DeepFreezer>(); DFWrapper.DeepFreezer targetpartFrzr = null; // selectedPartsTarget[0].FindModuleImplementing<DFWrapper.DeepFreezer>(); PartModule sourcedeepFreezer = GetFreezerModule(selectedPartsSource[0]); if (sourcedeepFreezer != null) { sourcepartFrzr = new DFWrapper.DeepFreezer(sourcedeepFreezer); } PartModule targetdeepFreezer = GetFreezerModule(selectedPartsTarget[0]); if (targetdeepFreezer != null) { targetpartFrzr = new DFWrapper.DeepFreezer(targetdeepFreezer); } if (sourcepartFrzr != null) { if (sourcepartFrzr.FreezerSpace == 0) { WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_004"); // "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed."; return(false); } } if (targetpartFrzr != null) { if (targetpartFrzr.FreezerSpace == 0) { WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_004"); // "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed."; return(false); } } // Are there kerbals to move? if (selectedPartsSource[0].protoModuleCrew.Count == 0) { //WindowTransfer.XferToolTip = "No Kerbals to Move."; WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_005"); return(false); } // now if realistic xfers is enabled, are the parts connected to each other in the same living space? results = IsClsInSameSpace(selectedPartsSource[0], selectedPartsTarget[0]); if (!results) { WindowTransfer.EvaToolTip = SMUtils.Localize("#smloc_conditions_tt_006"); } // "CLS is preventing internal Crew Transfer. Click to initiate EVA operation."; else { WindowTransfer.XferToolTip = SMUtils.Localize("#smloc_conditions_tt_007"); } // "Kerbal can be Transfered."; } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in CanBeXferred. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } return(results); }
private static void CrewDetails(List<Part> selectedPartsFrom, List<Part> selectedPartsTo) { // Since only one Crew Part can currently be selected, all lists will use an index of [0]. float xOffset = 30; if (selectedPartsFrom.Count <= 0) return; // ReSharper disable once ForCanBeConvertedToForeach for (int x = 0; x < selectedPartsFrom[0].protoModuleCrew.Count; x++) { ProtoCrewMember crewMember = selectedPartsFrom[0].protoModuleCrew[x]; GUILayout.BeginHorizontal(); if (SMConditions.IsTransferInProgress()) GUI.enabled = false; if (GUILayout.Button(new GUIContent("»", "Move Kerbal to another seat within Part"), SMStyle.ButtonStyle, GUILayout.Width(25), GUILayout.Height(20))) { ToolTip = ""; SMAddon.SmVessel.TransferCrewObj.CrewTransferBegin(crewMember, selectedPartsFrom[0], selectedPartsFrom[0]); } if (Event.current.type == EventType.Repaint && ShowToolTips) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, xOffset); } GUI.enabled = true; GUILayout.Label(string.Format(" {0}", crewMember.name + " (" + crewMember.experienceTrait.Title + ")"), GUILayout.Width(190), GUILayout.Height(20)); GUI.enabled = SMConditions.CanKerbalsBeXferred(selectedPartsFrom, selectedPartsTo); if ((SMAddon.SmVessel.TransferCrewObj.FromCrewMember == crewMember || SMAddon.SmVessel.TransferCrewObj.ToCrewMember == crewMember) && SMConditions.IsTransferInProgress()) { GUI.enabled = true; GUILayout.Label("Moving", GUILayout.Width(50), GUILayout.Height(20)); } else if (!SMConditions.IsClsInSameSpace()) { GUI.enabled = true; if (GUILayout.Button(new GUIContent("EVA", EvaToolTip), SMStyle.ButtonStyle, GUILayout.Width(50), GUILayout.Height(20))) { ToolTip = ""; FlightEVA.SpawnEVA(crewMember.KerbalRef); } if (Event.current.type == EventType.Repaint && ShowToolTips) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, xOffset); } } else { if (GUILayout.Button(new GUIContent("Xfer", XferToolTip), SMStyle.ButtonStyle, GUILayout.Width(50), GUILayout.Height(20))) { SMAddon.SmVessel.TransferCrewObj.FromCrewMember = crewMember; SMAddon.SmVessel.TransferCrewObj.CrewTransferBegin(crewMember, selectedPartsFrom[0], selectedPartsTo[0]); } if (Event.current.type == EventType.Repaint && ShowToolTips) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, xOffset); } } GUI.enabled = true; GUILayout.EndHorizontal(); } // Cater for DeepFreeze Continued... parts - list frozen kerbals if (!InstalledMods.IsDfApiReady) return; try { PartModule deepFreezer = (from PartModule pm in selectedPartsFrom[0].Modules where pm.moduleName == "DeepFreezer" select pm).SingleOrDefault(); if (deepFreezer == null) return; DFWrapper.DeepFreezer sourcepartFrzr = new DFWrapper.DeepFreezer(deepFreezer); if (sourcepartFrzr.StoredCrewList.Count <= 0) return; //Dictionary<string, DFWrapper.KerbalInfo> frozenKerbals = DFWrapper.DeepFreezeAPI.FrozenKerbals; List<DFWrapper.FrznCrewMbr>.Enumerator frznCrew = sourcepartFrzr.StoredCrewList.GetEnumerator(); while (frznCrew.MoveNext()) { if (frznCrew.Current == null) continue; GUILayout.BeginHorizontal(); GUI.enabled = false; if (GUILayout.Button(new GUIContent("»", "Move Kerbal to another seat within Part"), SMStyle.ButtonStyle, GUILayout.Width(15), GUILayout.Height(20))) { ToolTip = ""; } if (Event.current.type == EventType.Repaint && ShowToolTips) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, xOffset); } string trait = ""; ProtoCrewMember frozenKerbal = FindFrozenKerbal(frznCrew.Current.CrewName); if (frozenKerbal != null) trait = frozenKerbal.trait; GUI.enabled = true; GUILayout.Label(string.Format(" {0}", frznCrew.Current.CrewName + " (" + trait + ")"), SMStyle.LabelStyleCyan, GUILayout.Width(190), GUILayout.Height(20)); if (GUILayout.Button(new GUIContent("Thaw", "This Kerbal is Frozen. Click to Revive kerbal"), SMStyle.ButtonStyle, GUILayout.Width(50), GUILayout.Height(20))) { WindowRoster.ThawKerbal(frznCrew.Current.CrewName); ToolTip = ""; } if (Event.current.type == EventType.Repaint && ShowToolTips) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, xOffset); } GUILayout.EndHorizontal(); } } catch (Exception ex) { Utilities.LogMessage( string.Format(" in WindowTransfer.CrewDetails. Error attempting to check DeepFreeze for FrozenKerbals. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), Utilities.LogType.Error, true); //Debug.Log("Error attempting to check DeepFreeze for FrozenKerbals"); //Debug.Log(ex.Message); } }
internal static string DisplayVesselResourceTotals(string selectedResource) { string displayAmount = ""; double currAmount = 0; double totAmount = 0; if (selectedResource == null) return string.Format(" - ({0})", currAmount.ToString("#######0")); try { if (SMConditions.IsResourceTypeOther(selectedResource)) { List<Part>.Enumerator parts = SMAddon.SmVessel.PartsByResource[selectedResource].GetEnumerator(); while (parts.MoveNext()) { if (parts.Current == null) continue; currAmount += parts.Current.Resources[selectedResource].amount; totAmount += parts.Current.Resources[selectedResource].maxAmount; } } switch (SMConditions.TypeOfResource(selectedResource)) { case SMConditions.ResourceType.Crew: currAmount = SMAddon.SmVessel.Vessel.GetCrewCount(); totAmount = SMAddon.SmVessel.Vessel.GetCrewCapacity(); // if DF installed, get total frozen and add to count. if (InstalledMods.IsDfInstalled) { List<Part>.Enumerator cryofreezers = GetFreezerParts().GetEnumerator(); // ReSharper disable once SuspiciousTypeConversion.Global while (cryofreezers.MoveNext()) { if (cryofreezers.Current == null) continue; currAmount += new DFWrapper.DeepFreezer(SMConditions.GetFreezerModule(cryofreezers.Current)).TotalFrozen; } } // Now check for occupied external seats // external seats that are occupied will show up in getcrewcount and getcrewcapacity // Since we cannot yet xfer external crew, we need to remove them from the count.. List<KerbalSeat> seatCount = (from iPart in SMAddon.SmVessel.Vessel.parts where iPart.Modules.Contains("KerbalSeat") from PartModule iModule in iPart.Modules where iModule.ClassName == "KerbalSeat" select (KerbalSeat) iModule into kSeat where kSeat.Occupant != null select kSeat).ToList(); currAmount -= seatCount.Count; totAmount -= seatCount.Count; break; case SMConditions.ResourceType.Science: currAmount += SMAddon.SmVessel.PartsByResource[selectedResource].SelectMany(part => part.Modules.Cast<PartModule>()) .OfType<IScienceDataContainer>() .Sum(module => (double) module.GetScienceCount()); break; } displayAmount = selectedResource != SMConditions.ResourceType.Science.ToString() ? string.Format(" - ({0}/{1})", currAmount.ToString("#######0"), totAmount.ToString("######0")) : string.Format(" - ({0})", currAmount.ToString("#######0")); } catch (Exception ex) { LogMessage(string.Format(" in DisplayResourceTotals(). Error: {0}", ex), LogType.Error, true); } return displayAmount; }
internal static int GetPartCrewCount(Part part) { int crewCount = 0; if (!InstalledMods.IsDfApiReady) return crewCount + part.protoModuleCrew.Count; if (!part.Modules.Contains("DeepFreezer")) return crewCount + part.protoModuleCrew.Count; PartModule freezerModule = SMConditions.GetFreezerModule(part); // ReSharper disable once SuspiciousTypeConversion.Global DFWrapper.DeepFreezer freezer = new DFWrapper.DeepFreezer(freezerModule); crewCount += freezer.TotalFrozen; return crewCount + part.protoModuleCrew.Count; }
internal void Update() { if (Time.timeSinceLevelLoad < 2.0f) // Check not loading level return; if (!DFWrapper.InstanceExists) // Check if DFWrapper has been initialized or not. If not try to initialize. { DFWrapper.InitDFWrapper(); } if (DFWrapper.APIReady) // If the DeepFreeze API is Ready we do stuff with it. { DFFrozenKerbals.Clear(); //Get the DeepFreeze Dictionary of all Frozen Kerbals in the current Game. DFFrozenKerbals = DFWrapper.DeepFreezeAPI.FrozenKerbals; //Go through the active vessel and get all the DeepFreezer partmodules. deepfreezers.Clear(); if (FlightGlobals.ActiveVessel != null) { //Get a List of all the PartModules that are DeepFreezer class and store in deepfreezers List. List<Part> cryofreezers = (from p in FlightGlobals.ActiveVessel.parts where p.Modules.Contains("DeepFreezer") select p).ToList(); foreach (Part part in cryofreezers) { PartModule deepFreezer = (from PartModule pm in part.Modules where pm.moduleName == "DeepFreezer" select pm).SingleOrDefault(); if (deepFreezer != null) { deepfreezers.Add(deepFreezer); } } //If we found any DeepFreezer partmodules if (deepfreezers.Count == 1) { foreach (PartModule module in deepfreezers) { //The DFWrapper.DeepFreezer class is a reflection class of the real DeepFreezer PartModule DFWrapper.DeepFreezer freezer = new DFWrapper.DeepFreezer(module); //Populate fields for GUI display - NB: This only works for ONE freezer module in active vessel //But is only for example purposes. If you want to do this for multiple modules then // you will have to create your own Lists, etc. seats = freezer.FreezerSize; isxferto = freezer.crewXferTOActive; isxferfrom = freezer.crewXferFROMActive; isfreezeact = freezer.IsFreezeActive; isthawact = freezer.IsThawActive; outofec = freezer.FreezerOutofEC; partfull = freezer.PartFull; freeseats = freezer.FreezerSpace; tmpsts = freezer.FrzrTmp; totfrozen = freezer.TotalFrozen; frzncrewlst = freezer.StoredCrewList; } } } } }
private void windowDF(int id) { //Init styles sectionTitleStyle = new GUIStyle(GUI.skin.label); sectionTitleStyle.alignment = TextAnchor.MiddleLeft; sectionTitleStyle.stretchWidth = true; sectionTitleStyle.normal.textColor = Color.blue; sectionTitleStyle.fontStyle = FontStyle.Bold; statusStyle = new GUIStyle(GUI.skin.label); statusStyle.alignment = TextAnchor.MiddleLeft; statusStyle.stretchWidth = true; statusStyle.normal.textColor = Color.white; GUILayout.BeginVertical(); GUIscrollViewVector = GUILayout.BeginScrollView(GUIscrollViewVector, false, false); GUILayout.BeginVertical(); GUILayout.Label("# of FrozenKerbals " + DFFrozenKerbals.Count.ToString(), statusStyle); GUILayout.Label("FreezerSize " + seats, statusStyle); GUILayout.Label("FreezerSpace " + freeseats, statusStyle); GUILayout.Label("TotalFrozen " + totfrozen, statusStyle); GUILayout.Label("PartFull " + partfull, statusStyle); GUILayout.Label("IsFreezeActive " + isfreezeact, statusStyle); GUILayout.Label("IsThawActive " + isthawact, statusStyle); GUILayout.Label("FreezerOutofEC " + outofec, statusStyle); GUILayout.Label("crewXferTOActive " + isxferto, statusStyle); GUILayout.Label("crewXferFROMActive " + isxferfrom, statusStyle); GUILayout.Label("FrzrTmp " + tmpsts.ToString(), statusStyle); GUILayout.Label("FrozenCrew:"); if (frzncrewlst.Count == 0) { GUILayout.Label("NONE"); } else { foreach (DFWrapper.FrznCrewMbr frzncrewmbr in frzncrewlst) { GUILayout.BeginHorizontal(); GUILayout.Label(frzncrewmbr.CrewName + " " + frzncrewmbr.SeatIdx + frzncrewmbr.VesselName); if (GUILayout.Button("Thaw")) { //this is a nasty example. Assumes only one freezer module and crew is in that first module. //if using this in your mod, you need to cleanly store and look-up the freezer module for the //crewmember and instantiate a DFWrapper.DeepFreezer for that particular module first. DFWrapper.DeepFreezer freezer = new DFWrapper.DeepFreezer(deepfreezers[0]); freezer.beginThawKerbal(frzncrewmbr.CrewName); } GUILayout.EndHorizontal(); } } GUILayout.Label("ThawedCrew:"); if (deepfreezers[0].part.vessel.GetCrewCount() == 0) { GUILayout.Label("NONE"); } else { foreach (ProtoCrewMember crew in deepfreezers[0].part.vessel.GetVesselCrew()) { GUILayout.BeginHorizontal(); GUILayout.Label(crew.name); if (GUILayout.Button("Freeze")) { //this is a nasty example. Assumes only one freezer module and crew is in that first module. //if using this in your mod, you need to cleanly store and look-up the freezer module for the //crewmember and instantiate a DFWrapper.DeepFreezer for that particular module first. DFWrapper.DeepFreezer freezer = new DFWrapper.DeepFreezer(deepfreezers[0]); freezer.beginFreezeKerbal(crew); } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.DragWindow(); }