private static string GetFrozenKerbalDetails(ProtoCrewMember kerbal) { try { string rosterDetails = ""; if (!DFWrapper.APIReady) { DFWrapper.InitDFWrapper(); } if (DFWrapper.APIReady) { if (DFWrapper.DeepFreezeAPI.FrozenKerbals.ContainsKey(kerbal.name)) // "Frozen" { rosterDetails = string.Format("{0} - {1}", SMUtils.Localize("#smloc_roster_015"), DFWrapper.DeepFreezeAPI.FrozenKerbals[kerbal.name].vesselName.Replace("(unloaded)", "")); } else { rosterDetails = SMUtils.Localize("#smloc_roster_015"); // "Frozen"; } } return(rosterDetails); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage(string.Format(" in GetRosterList().\r\nError: {0}", ex), SMUtils.LogType.Error, true); } return(string.Format("{0}:", SMUtils.Localize("#smloc_error_001"))); // "Display Error" } }
internal void CrewTransferStopAction() { // This adds the kerbal(s) to the destination part(s) try { // Add Source Crewmember to target part if (FromCrewMember != null && ToPart.CrewCapacity > ToPart.protoModuleCrew.Count) { AddCrewMember(FromCrewMember, ToPart, ToSeat); } // Add Target Crewmember to source part if (ToCrewMember != null && FromPart.CrewCapacity > FromPart.protoModuleCrew.Count) { AddCrewMember(ToCrewMember, FromPart, FromSeat); } SMAddon.SmVessel.TransferCrewObj.IvaDelayActive = true; SMAddon.FireEventTriggers(); } catch (Exception ex) { SMUtils.LogMessage( string.Format("in CrewTransferAction. Error moving crewmember. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
static CLSClient() { try { // Original call. deep dives into all assemblies... //Type cls_type = AssemblyLoader // .loadedAssemblies // .SelectMany(a => a.assembly.GetExportedTypes()) // .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon"); // this replacement call attempts to filter dynamic assemblies... Dot.Net 2.0 vs Dot.Net 4.0 //Type newType = AssemblyLoader // .loadedAssemblies.Where(a => a.assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder == false) // .SelectMany(a => a.assembly.GetExportedTypes()) // .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon"); // Lighter weight, and should not "dive into" assemblies unnecessarily. Type clsType = AssemblyLoader.loadedAssemblies.Where(a => a.name.Contains("ConnectedLivingSpace")) .SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon"); if (clsType != null) { cls = clsType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static); } } catch (Exception ex) { SMUtils.LogMessage($"Cannot load CLS assembly. Error: {ex}", SMUtils.LogType.Error, false); } }
internal static void FreezeKerbal(ProtoCrewMember kerbal) { try { if (!InstalledMods.IsDfApiReady) { return; } List <Part> .Enumerator cryofreezers = SMUtils.GetFreezerParts().GetEnumerator(); while (cryofreezers.MoveNext()) { if (cryofreezers.Current == null) { continue; } if (!cryofreezers.Current.protoModuleCrew.Contains(kerbal)) { continue; } // ReSharper disable once SuspiciousTypeConversion.Global PartModule deepFreezer = SMConditions.GetFreezerModule(cryofreezers.Current); if (deepFreezer != null) { new DFWrapper.DeepFreezer(deepFreezer).beginFreezeKerbal(kerbal); } break; } cryofreezers.Dispose(); } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in FreezeKerbal. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void Savelog() { try { // time to create a file... string filename = "DebugLog_" + DateTime.Now.ToString(CultureInfo.InvariantCulture) .Replace(" ", "_") .Replace("/", "") .Replace(":", "") + ".txt"; string path = Directory.GetCurrentDirectory() + @"\GameData\ShipManifest\"; if (SMSettings.DebugLogPath.StartsWith(@"\\")) { SMSettings.DebugLogPath = SMSettings.DebugLogPath.Substring(2, SMSettings.DebugLogPath.Length - 2); } else if (SMSettings.DebugLogPath.StartsWith(@"\")) { SMSettings.DebugLogPath = SMSettings.DebugLogPath.Substring(1, SMSettings.DebugLogPath.Length - 1); } if (!SMSettings.DebugLogPath.EndsWith(@"\")) { SMSettings.DebugLogPath += @"\"; } filename = path + SMSettings.DebugLogPath + filename; SMUtils.LogMessage("File Name = " + filename, SMUtils.LogType.Info, true); try { StringBuilder sb = new StringBuilder(); List <string> .Enumerator lines = SMUtils.LogItemList.GetEnumerator(); while (lines.MoveNext()) { if (lines.Current == null) { continue; } sb.AppendLine(lines.Current); } lines.Dispose(); File.WriteAllText(filename, sb.ToString()); SMUtils.LogMessage("File written", SMUtils.LogType.Info, true); } catch (Exception ex) { SMUtils.LogMessage("Error Writing File: " + ex, SMUtils.LogType.Error, true); } } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in Savelog. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void TransferScienceLab(PartModule source, PartModule target, Selection sel) { try { // Create lookup list to avoid a slow linear search for each item // Value is number of labs that have processed it // (would allow to only move data not processed in all labs if there are multiple) Dictionary <string, int> processedScience = new Dictionary <string, int>(); List <ModuleScienceLab> .Enumerator labs = SMAddon.SmVessel.Vessel.FindPartModulesImplementing <ModuleScienceLab>().GetEnumerator(); while (labs.MoveNext()) { List <string> .Enumerator dataitems = labs.Current.ExperimentData.GetEnumerator(); while (dataitems.MoveNext()) { if (!processedScience.ContainsKey(dataitems.Current)) { processedScience.Add(dataitems.Current, 1); } else { processedScience[dataitems.Current]++; } } dataitems.Dispose(); } labs.Dispose(); ScienceData[] moduleScience = (IScienceDataContainer)source != null ? ((IScienceDataContainer)source).GetData() : null; if (moduleScience == null || moduleScience.Length <= 0) { return; } IEnumerator dataItems = moduleScience.GetEnumerator(); while (dataItems.MoveNext()) { if (dataItems.Current == null) { continue; } ScienceData data = (ScienceData)dataItems.Current; bool processed = processedScience.ContainsKey(data.subjectID); if ((sel == Selection.OnlyProcessed && processed) || (sel == Selection.OnlyUnprocessed && !processed)) { if (((ModuleScienceContainer)target).AddData(data)) { ((IScienceDataContainer)source).DumpData(data); } } } } catch (Exception ex) { SMUtils.LogMessage(" in ProcessController.TransferScienceLab: Error: " + ex, SMUtils.LogType.Info, SMSettings.VerboseLogging); } }
internal static void Display(Vector2 displayViewerPosition) { //float scrollX = WindowControl.Position.x + 10; //float scrollY = WindowControl.Position.y + 50 - displayViewerPosition.y; float scrollX = 10; float scrollY = 50 - displayViewerPosition.y; // Reset Tooltip active flag... ToolTipActive = false; SMHighlighter.IsMouseOver = false; GUILayout.BeginVertical(); GUI.enabled = true; //GUILayout.Label("Science Lab Control Center ", SMStyle.LabelTabHeader); GUILayout.Label(SMUtils.Localize("#smloc_control_lab_000"), SMStyle.LabelTabHeader); GUILayout.Label("____________________________________________________________________________________________", SMStyle.LabelStyleHardRule, GUILayout.Height(10), GUILayout.Width(350)); string step = "start"; try { // Display all Labs List <ModuleScienceLab> .Enumerator iLabs = SMAddon.SmVessel.Labs.GetEnumerator(); while (iLabs.MoveNext()) { if (iLabs.Current == null) { continue; } bool isEnabled = true; step = "gui enable"; GUI.enabled = isEnabled; string label = iLabs.Current.name + " - (" + (iLabs.Current.IsOperational() ? SMUtils.Localize("#smloc_control_lab_001") : SMUtils.Localize("#smloc_control_lab_002")) + ")"; // Operational, InOp GUILayout.Label(label, GUILayout.Width(260), GUILayout.Height(40)); Rect rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition)) { SMHighlighter.IsMouseOver = true; SMHighlighter.MouseOverRect = new Rect(scrollX + rect.x, scrollY + rect.y, rect.width, rect.height); SMHighlighter.MouseOverPart = iLabs.Current.part; SMHighlighter.MouseOverParts = null; } } iLabs.Dispose(); // Display MouseOverHighlighting, if any SMHighlighter.MouseOverHighlight(); } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in Solar Panel Tab at step {0}. Error: {1} \r\n\r\n{2}", step, ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } GUILayout.EndVertical(); }
internal static void TransferScience(PartModule source, PartModule target) { try { ScienceData[] moduleScience = (IScienceDataContainer)source != null ? ((IScienceDataContainer)source).GetData() : null; if (moduleScience == null || moduleScience.Length <= 0) { return; } //Utilities.LogMessage("ProcessController.TransferScience: moduleScience has data...", Utilities.LogType.Info, // SMSettings.VerboseLogging); if ((IScienceDataContainer)target == null) { return; } // Lets store the data from the source. if (!((ModuleScienceContainer)target).StoreData( new List <IScienceDataContainer> { (IScienceDataContainer)source }, false)) { return; } //Utilities.LogMessage("ProcessController.TransferScience: ((ModuleScienceContainer)source) data stored", // "Info", SMSettings.VerboseLogging); IEnumerator dataItems = moduleScience.GetEnumerator(); while (dataItems.MoveNext()) { if (dataItems.Current == null) { continue; } ScienceData data = (ScienceData)dataItems.Current; ((IScienceDataContainer)source).DumpData(data); } if (!SMSettings.RealControl) { ((ModuleScienceExperiment)source).ResetExperiment(); } } catch (Exception ex) { SMUtils.LogMessage(" in ProcessController.TransferScience: Error: " + ex, SMUtils.LogType.Info, SMSettings.VerboseLogging); } }
internal static void DumpResources(List <TransferPump> pumps) { // This initiates the Dump process and with realism off, does the dump immediately; with realism on, initiates the real time process. try { if (SMSettings.RealXfers) { // Turn on Pumps for timed process... List <TransferPump> .Enumerator epumps = pumps.GetEnumerator(); while (epumps.MoveNext()) { if (epumps.Current == null) { continue; } TransferPump pump = epumps.Current; pump.PumpRatio = 1; pump.IsPumpOn = true; } epumps.Dispose(); // Add pumps to pump queue SMAddon.SmVessel.TransferPumps.AddRange(pumps); // Start the process. This flag is checked in SMAddon.Update() TransferPump.PumpProcessOn = true; } else { List <TransferPump> .Enumerator epumps = pumps.GetEnumerator(); while (epumps.MoveNext()) { if (epumps.Current == null) { continue; } TransferPump pump = epumps.Current; pump.RunPumpCycle(pump.PumpAmount); } epumps.Dispose(); SMAddon.SmVessel.TransferPumps.Clear(); } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in ProcessController.DumpResources. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static bool CanShowShipManifest(bool ignoreShowSm = false) { try { bool canShow = false; if (SMAddon.ShowUi && HighLogic.LoadedScene == GameScenes.FLIGHT && !IsPauseMenuOpen() && !IsFlightDialogDisplaying() && FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null && !FlightGlobals.ActiveVessel.isEVA && FlightGlobals.ActiveVessel.vesselType != VesselType.Flag //&& FlightGlobals.ActiveVessel.vesselType != VesselType.Debris //&& FlightGlobals.ActiveVessel.vesselType != VesselType.Unknown //&& CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA ) { canShow = ignoreShowSm || WindowManifest.ShowWindow; } return(canShow); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { string values = "SmAddon.ShowUI = " + SMAddon.ShowUi + "\r\n"; values += "HighLogic.LoadedScene = " + HighLogic.LoadedScene + "\r\n"; values += "PauseMenu.isOpen = " + IsPauseMenuOpen() + "\r\n"; values += "FlightResultsDialog.isDisplaying = " + IsFlightDialogDisplaying() + "\r\n"; values += "FlightGlobals.fetch != null = " + (FlightGlobals.fetch != null) + "\r\n"; values += "FlightGlobals.ActiveVessel != null = " + (FlightGlobals.ActiveVessel != null) + "\r\n"; values += "!FlightGlobals.ActiveVessel.isEVA = " + (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.isEVA) + "\r\n"; if (FlightGlobals.ActiveVessel != null) { values += "FlightGlobals.ActiveVessel.vesselType = " + FlightGlobals.ActiveVessel.vesselType + "\r\n"; } values += "CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA = " + (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA); SMUtils.LogMessage( string.Format(" in CanShowShipManifest (repeating error). Error: {0} \r\n\r\n{1}\r\n\r\nValues: {2}", ex.Message, ex.StackTrace, values), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } return(false); } }
internal static void MouseOverHighlight(Part part) { string step = "begin"; try { step = "inside box - Part Selection?"; SetPartHighlight(part, SMSettings.Colors[SMSettings.MouseOverColor]); EdgeHighight(part, true); } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in SMHighlighter.MouseOverHighlight at step {0}. Error: {1}", step, ex), SMUtils.LogType.Error, true); } }
internal static void GetRosterList() { try { RosterList.Clear(); RosterList = HighLogic.CurrentGame.CrewRoster.Crew.ToList(); // Support for DeepFreeze if (InstalledMods.IsDfInstalled && DFWrapper.APIReady) { RosterList.AddRange(HighLogic.CurrentGame.CrewRoster.Unowned); } } catch (Exception ex) { SMUtils.LogMessage(string.Format("Error in GetRosterList().\r\nError: {0}", ex), SMUtils.LogType.Error, true); } }
/// <summary> /// This method is called by WindowTransfer.Xferbutton press. /// </summary> /// <param name="xferPumps"></param> internal static void TransferResources(List <TransferPump> xferPumps) { try { if (SMSettings.RealXfers) { List <TransferPump> .Enumerator pumps = xferPumps.GetEnumerator(); while (pumps.MoveNext()) { if (pumps.Current == null) { continue; } TransferPump pump = pumps.Current; pump.IsPumpOn = true; } pumps.Dispose(); // now lets start the pumping process... SMAddon.SmVessel.TransferPumps.AddRange(xferPumps); // Start the process. This flag is checked in SMAddon.Update() TransferPump.PumpProcessOn = true; } else { //Not in Realism mode, so just move the resource... List <TransferPump> .Enumerator pumps = xferPumps.GetEnumerator(); while (pumps.MoveNext()) { if (pumps.Current == null) { continue; } TransferPump pump = pumps.Current; pump.RunPumpCycle(pump.PumpAmount); } pumps.Dispose(); } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in ProcessController.TransferResources. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
private static void PreLaunchGui() { try { if (SMSettings.EnablePfCrews) { GUILayout.BeginHorizontal(); // Realism Mode is desirable, as there is a cost associated with a kerbal on a flight. No cheating! if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_005"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Fill Crew" { SMAddon.SmVessel.FillCrew(); } if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_006"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Empty Crew" { SMAddon.SmVessel.EmptyCrew(); } GUILayout.EndHorizontal(); } if (!SMSettings.EnablePfResources) { return; } GUILayout.BeginHorizontal(); if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_007"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Fill Resources" { SMAddon.SmVessel.FillResources(); } if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_008"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Empty Resources" { SMAddon.SmVessel.DumpAllResources(); } GUILayout.EndHorizontal(); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in PreLaunchGui. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } } }
internal static void SetPartHighlight(Part part, Color color) { if (part == null) { return; } try { if (!part.HighlightActive) { part.SetHighlight(true, false); } part.highlightType = Part.HighlightType.AlwaysOn; part.SetHighlightColor(color); } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in SetPartHighlight. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void ThawKerbal(string kerbalName) { try { if (InstalledMods.IsDfApiReady) { DFWrapper.KerbalInfo iKerbal = DFWrapper.DeepFreezeAPI.FrozenKerbals[kerbalName]; List <Part> .Enumerator cryofreezers = SMUtils.GetFreezerParts().GetEnumerator(); while (cryofreezers.MoveNext()) { if (cryofreezers.Current == null) { continue; } if (cryofreezers.Current.flightID == iKerbal.partID) { // ReSharper disable once SuspiciousTypeConversion.Global PartModule deepFreezer = SMConditions.GetFreezerModule(cryofreezers.Current); if (deepFreezer != null) { new DFWrapper.DeepFreezer(deepFreezer).beginThawKerbal(kerbalName); } break; } } cryofreezers.Dispose(); } else { SMUtils.LogMessage(string.Format("ThawKerbal. IsDFInstalled: {0}", InstalledMods.IsDfInstalled), SMUtils.LogType.Info, true); } } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in ThawKerbal. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void HighlightClsVessel(bool enabled, bool force = false) { try { if (SMAddon.ClsAddon.Vessel == null) { SMAddon.UpdateClsSpaces(); } if (SMAddon.ClsAddon.Vessel == null) { return; } List <ICLSSpace> .Enumerator spaces = SMAddon.ClsAddon.Vessel.Spaces.GetEnumerator(); while (spaces.MoveNext()) { if (spaces.Current == null) { continue; } List <ICLSPart> .Enumerator parts = spaces.Current.Parts.GetEnumerator(); while (parts.MoveNext()) { parts.Current?.Highlight(enabled, force); } parts.Dispose(); } spaces.Dispose(); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in HighlightCLSVessel (repeating error). Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } } }
internal void CrewTransferStartAction() { // This removes the kerbal(s) from the current (source) part(s) try { if (FromCrewMember != null) { RemoveCrewMember(FromCrewMember, FromPart); } if (ToCrewMember != null) { RemoveCrewMember(ToCrewMember, ToPart); } SMAddon.FireEventTriggers(); } catch (Exception ex) { SMUtils.LogMessage( string.Format("in CrewTransferStartAction. Error moving crewmember. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void SetPartsHighlight(List <Part> parts, Color color, bool force = false) { try { List <Part> .Enumerator list = parts.GetEnumerator(); while (list.MoveNext()) { if (list.Current == null) { continue; } if (!list.Current.HighlightActive || force) { SetPartHighlight(list.Current, color); } } list.Dispose(); } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in SetPartsHighlight. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
internal static void Display(int windowId) { Title = string.Format("{0} {1} - {2}", SMUtils.Localize("#smloc_manifest_002"), SMSettings.CurVersion, SMAddon.SmVessel.Vessel.vesselName); // set input locks when mouseover window... //_inputLocked = GuiUtils.PreventClickthrough(ShowWindow, Position, _inputLocked); // Reset Tooltip active flag... ToolTipActive = false; //GUIContent label = new GUIContent("", "Close Window"); GUIContent label = new GUIContent("", SMUtils.Localize("#smloc_window_tt_001")); if (SMConditions.IsTransferInProgress()) { //label = new GUIContent("", "Action in progress. Cannot close window"); label = new GUIContent("", SMUtils.Localize("#smloc_window_tt_002")); GUI.enabled = false; } Rect rect = new Rect(Position.width - 20, 4, 16, 16); if (GUI.Button(rect, label)) { SMAddon.OnSmButtonClicked(); ToolTip = ""; SMHighlighter.Update_Highlighter(); } if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } GUI.enabled = true; try { GUILayout.BeginVertical(); _smScrollViewerPosition = GUILayout.BeginScrollView(_smScrollViewerPosition, SMStyle.ScrollStyle, GUILayout.Height(100), GUILayout.Width(300)); GUILayout.BeginVertical(); // Prelaunch (landed) Gui if (SMConditions.IsInPreflight()) { PreLaunchGui(); } // Now the Resource Buttons ResourceButtonsList(); GUILayout.EndVertical(); GUILayout.EndScrollView(); //string resLabel = "No Resource Selected"; string resLabel = SMUtils.Localize("#smloc_manifest_003"); if (SMAddon.SmVessel.SelectedResources.Count == 1) { resLabel = SMAddon.SmVessel.SelectedResources[0]; } else if (SMAddon.SmVessel.SelectedResources.Count == 2) { //resLabel = "Multiple Resources selected"; resLabel = SMUtils.Localize("#smloc_manifest_004"); } GUILayout.Label(string.Format("{0}", resLabel), GUILayout.Width(300), GUILayout.Height(20)); // Resource Details List Viewer ResourceDetailsViewer(); // Window toggle Button List WindowToggleButtons(); GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, Screen.width, 30)); SMAddon.RepositionWindow(ref Position); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in WindowManifest.Display. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } } }
private static void ResourceDetailsViewer() { try { _resourceScrollViewerPosition = GUILayout.BeginScrollView(_resourceScrollViewerPosition, SMStyle.ScrollStyle, GUILayout.Height(100), GUILayout.Width(300)); GUILayout.BeginVertical(); if (SMAddon.SmVessel.SelectedResources.Count > 0) { List <Part> .Enumerator pParts = SMAddon.SmVessel.SelectedResourcesParts.GetEnumerator(); while (pParts.MoveNext()) { if (pParts.Current == null) { continue; } Part part = pParts.Current; if (SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { GUIStyle noWrap = SMStyle.LabelStyleNoWrap; GUILayout.Label(string.Format("{0}", part.partInfo.title), noWrap, GUILayout.Width(265), GUILayout.Height(18)); GUIStyle noPad = SMStyle.LabelStyleNoPad; List <string> .Enumerator sResources = SMAddon.SmVessel.SelectedResources.GetEnumerator(); while (sResources.MoveNext()) { if (sResources.Current == null) { continue; } GUILayout.Label( string.Format(" - {0}: ({1:######0.####}/{2:######0.####})", sResources.Current, part.Resources[sResources.Current].amount, part.Resources[sResources.Current].maxAmount), noPad, GUILayout.Width(265), GUILayout.Height(16)); } sResources.Dispose(); } else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Crew.ToString())) { GUILayout.BeginHorizontal(); GUILayout.Label( string.Format("{0}, ({1}/{2})", part.partInfo.title, SMUtils.GetPartCrewCount(part), part.CrewCapacity), GUILayout.Width(265), GUILayout.Height(20)); GUILayout.EndHorizontal(); } else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Science.ToString())) { int scienceCount = 0; IEnumerator pModules = part.Modules.GetEnumerator(); while (pModules.MoveNext()) { if (pModules.Current == null) { continue; } PartModule pm = (PartModule)pModules.Current; ModuleScienceContainer container = pm as ModuleScienceContainer; if (container != null) { scienceCount += container.GetScienceCount(); } else if (pm is ModuleScienceExperiment) { scienceCount += ((ModuleScienceExperiment)pm).GetScienceCount(); } } GUILayout.BeginHorizontal(); GUILayout.Label(string.Format("{0}, ({1})", part.partInfo.title, scienceCount), GUILayout.Width(265)); GUILayout.EndHorizontal(); } } pParts.Dispose(); } } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in WindowManifest.ResourceDetailsViewer. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // in, Error SMAddon.FrameErrTripped = true; } } GUILayout.EndVertical(); GUILayout.EndScrollView(); }
private static void ResourceButtonToggled(string resourceName) { try { if (SMConditions.IsTransferInProgress()) { return; } // First, lets clear any highlighting... SMHighlighter.ClearResourceHighlighting(SMAddon.SmVessel.SelectedResourcesParts); // Now let's update our lists... SMAddon.SmVessel.RefreshLists(); if (!SMAddon.SmVessel.SelectedResources.Contains(resourceName)) { // now lets determine what to do with selection if (SMConditions.ResourceIsSingleton(resourceName)) { SMAddon.SmVessel.SelectedResources.Clear(); SMAddon.SmVessel.SelectedResources.Add(resourceName); } else { if (SMConditions.ResourcesContainSingleton(SMAddon.SmVessel.SelectedResources)) { SMAddon.SmVessel.SelectedResources.Clear(); SMAddon.SmVessel.SelectedResources.Add(resourceName); } else if (SMAddon.SmVessel.SelectedResources.Count > 1) { SMAddon.SmVessel.SelectedResources.RemoveRange(0, 1); SMAddon.SmVessel.SelectedResources.Add(resourceName); } else { SMAddon.SmVessel.SelectedResources.Add(resourceName); } } } else if (SMAddon.SmVessel.SelectedResources.Contains(resourceName)) { SMAddon.SmVessel.SelectedResources.Remove(resourceName); } // Now, refresh the resources parts list SMAddon.SmVessel.GetSelectedResourcesParts(); // now lets reconcile the selected parts based on the new list of resources... ResolveResourcePartSelections(SMAddon.SmVessel.SelectedResources); // Now, based on the resourceselection, do we show the Transfer window? WindowTransfer.ShowWindow = SMAddon.SmVessel.SelectedResources.Count > 0; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in WindowManifest.ResourceButtonToggled. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // in, Error } SMAddon.SmVessel.RefreshLists(); }
private static void ResourceButtonsList() { try { // List required here to prevent loop sync errors with live source. List <string> .Enumerator keys = SMAddon.SmVessel.PartsByResource.Keys.ToList().GetEnumerator(); while (keys.MoveNext()) { if (string.IsNullOrEmpty(keys.Current)) { continue; } GUILayout.BeginHorizontal(); // Button Widths int width = 273; if (!SMSettings.RealXfers && SMConditions.IsResourceTypeOther(keys.Current)) { width = 185; } else if (SMConditions.IsResourceTypeOther(keys.Current)) { width = 223; } // Resource Button string displayAmounts = string.Format("{0}{1}", keys.Current, SMUtils.DisplayVesselResourceTotals(keys.Current)); GUIStyle style = SMAddon.SmVessel.SelectedResources.Contains(keys.Current) ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(displayAmounts, style, GUILayout.Width(width), GUILayout.Height(20))) { ResourceButtonToggled(keys.Current); SMHighlighter.Update_Highlighter(); } // Dump Button if (SMConditions.IsResourceTypeOther(keys.Current) && SMAddon.SmVessel.PartsByResource[keys.Current].Count > 0) { uint pumpId = TransferPump.GetPumpIdFromHash(keys.Current, SMAddon.SmVessel.PartsByResource[keys.Current].First(), SMAddon.SmVessel.PartsByResource[keys.Current].Last(), TransferPump.TypePump.Dump, TransferPump.TriggerButton.Manifest); GUIContent dumpContent = !TransferPump.IsPumpInProgress(pumpId) ? new GUIContent(SMUtils.Localize("#smloc_manifest_009"), SMUtils.Localize("#smloc_manifest_tt_001")) // "Dump", "Dumps the selected resource in this vessel" : new GUIContent(SMUtils.Localize("#smloc_manifest_010"), SMUtils.Localize("#smloc_manifest_tt_002")); // "Stop", "Halts the dumping of the selected resource in this vessel" GUI.enabled = SMConditions.CanResourceBeDumped(keys.Current); if (GUILayout.Button(dumpContent, SMStyle.ButtonStyle, GUILayout.Width(45), GUILayout.Height(20))) { SMVessel.ToggleDumpResource(keys.Current, pumpId); } } // Fill Button if (!SMSettings.RealXfers && SMConditions.IsResourceTypeOther(keys.Current) && SMAddon.SmVessel.PartsByResource[keys.Current].Count > 0) { GUI.enabled = SMConditions.CanResourceBeFilled(keys.Current); if (GUILayout.Button(string.Format("{0}", SMUtils.Localize("#smloc_manifest_011")), SMStyle.ButtonStyle, GUILayout.Width(35), GUILayout.Height(20))) // "Fill" { SMAddon.SmVessel.FillResource(keys.Current); } } GUI.enabled = true; GUILayout.EndHorizontal(); } keys.Dispose(); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in WindowManifest.ResourceButtonList. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } } }
private static void DisplayRosterListViewer() { try { GUILayout.BeginVertical(); // Roster List Header... GUILayout.BeginHorizontal(); //GUILayout.Label("", GUILayout.Width(5)); GUILayout.Label(SMUtils.Localize("#smloc_roster_016"), GUILayout.Width(140)); // "Name" GUILayout.Label(SMUtils.Localize("#smloc_roster_017"), GUILayout.Width(50)); // "Gender" GUILayout.Label(SMUtils.Localize("#smloc_roster_005"), GUILayout.Width(70)); // "Profession" GUILayout.Label(SMUtils.Localize("#smloc_roster_018"), GUILayout.Width(30)); // "Skill" GUILayout.Label(SMUtils.Localize("#smloc_roster_019"), GUILayout.Width(220)); // "Status" GUILayout.Label(SMUtils.Localize("#smloc_roster_020"), GUILayout.Width(55)); // "Edit" GUILayout.Label(SMUtils.Localize("#smloc_roster_021"), GUILayout.Width(65)); // "Action" GUILayout.EndHorizontal(); _scrollViewerPosition = GUILayout.BeginScrollView(_scrollViewerPosition, SMStyle.ScrollStyle, GUILayout.Height(230), GUILayout.Width(680)); // vars for acton to occurs after button press bool isAction = false; Part actionPart = null; string actionText = ""; ProtoCrewMember actionKerbal = null; List <ProtoCrewMember> .Enumerator kerbals = RosterList.GetEnumerator(); while (kerbals.MoveNext()) { if (kerbals.Current == null) { continue; } if (!CanDisplayKerbal(kerbals.Current)) { continue; } GUIStyle labelStyle; if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Dead || kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Missing) { labelStyle = SMStyle.LabelStyleRed; } else if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned) { labelStyle = SMStyle.LabelStyleYellow; } else { labelStyle = SMStyle.LabelStyle; } // What vessel is this Kerbal Assigned to? string rosterDetails = ""; if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned) { List <Vessel> .Enumerator theseVessels = FlightGlobals.Vessels.GetEnumerator(); while (theseVessels.MoveNext()) { if (theseVessels.Current == null) { continue; } List <ProtoCrewMember> crew = theseVessels.Current.GetVesselCrew(); if (crew.Any(crewMember => crewMember == kerbals.Current)) { rosterDetails = string.Format("{0} - {1}", SMUtils.Localize("#smloc_roster_011"), theseVessels.Current.GetName().Replace("(unloaded)", "")); // "Assigned" } } theseVessels.Dispose(); } else if (InstalledMods.IsDfInstalled && DFWrapper.APIReady && kerbals.Current.type == ProtoCrewMember.KerbalType.Unowned) { // This kerbal could be frozen. Lets find out... rosterDetails = GetFrozenKerbalDetails(kerbals.Current); labelStyle = SMStyle.LabelStyleCyan; } else { // Since the kerbal has no vessel assignment, lets show what their status... rosterDetails = kerbals.Current.rosterStatus.ToString(); } string buttonText; string buttonToolTip; GUILayout.BeginHorizontal(); GUILayout.Label(kerbals.Current.name, labelStyle, GUILayout.Width(140), GUILayout.Height(20)); GUILayout.Label(kerbals.Current.gender.ToString(), labelStyle, GUILayout.Width(50)); GUILayout.Label(kerbals.Current.experienceTrait.Title, labelStyle, GUILayout.Width(70)); GUILayout.Label(kerbals.Current.experienceLevel.ToString(), labelStyle, GUILayout.Width(30)); GUILayout.Label(rosterDetails, labelStyle, GUILayout.Width(215)); SetupEditButton(kerbals.Current, out buttonText, out buttonToolTip); if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(55), GUILayout.Height(20), GUILayout.Height(20))) { if (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbals.Current) { SelectedKerbal = new ModKerbal(kerbals.Current, false); SetProfessionFlag(); } else { SelectedKerbal = null; } } Rect rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, XOffset); } // Setup buttons with gui state, button text and tooltip. SetupActionButton(kerbals.Current, out buttonText, out buttonToolTip); if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(65), GUILayout.Height(20))) { isAction = true; actionKerbal = kerbals.Current; actionText = buttonText; if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove" { actionPart = SMAddon.SmVessel.FindPartByKerbal(kerbals.Current); } } Rect rect2 = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect2, GUI.tooltip, ref ToolTipActive, XOffset); } GUILayout.EndHorizontal(); GUI.enabled = true; } kerbals.Dispose(); GUILayout.EndVertical(); GUILayout.EndScrollView(); // perform action from button press. if (!isAction) { return; } if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove" { TransferCrew.RemoveCrewMember(actionKerbal, actionPart); } else if (actionText == SMUtils.Localize("#smloc_roster_023")) // "Add" { TransferCrew.AddCrewMember(actionKerbal, SMAddon.SmVessel.SelectedPartsSource[0]); } else if (actionText == SMUtils.Localize("#smloc_roster_024")) // "Respawn" { RespawnKerbal(actionKerbal); } else if (actionText == SMUtils.Localize("#smloc_roster_025")) // "Thaw" { ThawKerbal(actionKerbal.name); } else if (actionText == SMUtils.Localize("#smloc_roster_026"))// "Freeze" { FreezeKerbal(actionKerbal); } SMAddon.FireEventTriggers(); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage(string.Format(" in RosterListViewer. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } }
internal static void ProcessActivePumps() { // This routine acts as a queue // WHen a pump is set to IsPumOn = true, it will be processed by this routine. //Utilities.LogMessage("Entering: TransferPump.ProcessActivePumps", Utilities.LogType.Info, SMSettings.VerboseLogging); List <TransferPump> pumpsToRemove = new List <TransferPump>(); // this task runs every Update when active. try { List <TransferPump> .Enumerator tPumps = SMAddon.SmVessel.TransferPumps.GetEnumerator(); while (tPumps.MoveNext()) { if (tPumps.Current == null) { continue; } // Check Pump state: if (!tPumps.Current.IsPumpOn) { continue; } TransferPump pump = tPumps.Current; switch (pump.PumpStatus) { case PumpState.Off: //Utilities.LogMessage("Entering: TransferPump.ProcessActivePumps - Off", Utilities.LogType.Info, SMSettings.VerboseLogging); pump.TimeStamp = DateTime.Now; pump.Start(); pump.PumpStatus = PumpState.Start; break; case PumpState.Start: //Utilities.LogMessage("Entering: TransferPump.ProcessActivePumps - Start", Utilities.LogType.Info, SMSettings.VerboseLogging); // Calculate Elapsed. pump.Elapsed += (DateTime.Now - pump.TimeStamp).TotalSeconds; if (pump.Elapsed >= SMSound.SourcePumpStart.clip.length - 0.25) { pump.Run(); pump.PumpStatus = PumpState.Run; } break; case PumpState.Run: //Utilities.LogMessage("Entering: TransferPump.ProcessActivePumps - Run", Utilities.LogType.Info, SMSettings.VerboseLogging); // 1. Get Elapsed from last run double deltaT = (DateTime.Now - pump.TimeStamp).TotalSeconds; // 2. Lets wait long enough to get a resource volume worth moving pump.TimeStamp = DateTime.Now; pump.Running(deltaT); break; case PumpState.Stop: //Utilities.LogMessage("Entering: TransferPump.ProcessActivePumps - Stop", Utilities.LogType.Info, SMSettings.VerboseLogging); pump.Stop(); pump.PumpStatus = PumpState.Off; pumpsToRemove.Add(pump); break; } } tPumps.Dispose(); if (pumpsToRemove.Count <= 0) { return; } List <TransferPump> .Enumerator rpumps = pumpsToRemove.GetEnumerator(); while (rpumps.MoveNext()) { if (rpumps.Current == null) { continue; } SMAddon.SmVessel.TransferPumps.Remove(rpumps.Current); } rpumps.Dispose(); pumpsToRemove.Clear(); } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in TransferPump.ProcessActivePumps (repeating error). Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); SMAddon.FrameErrTripped = true; } } finally { PumpProcessOn = IsAnyPumpOn(); UpdateDisplayPumps(); } }
internal static void Display(int windowId) { Title = SMUtils.Localize("#smloc_roster_001"); // set input locks when mouseover window... //_inputLocked = GuiUtils.PreventClickthrough(ShowWindow, Position, _inputLocked); // Reset Tooltip active flag... ToolTipActive = false; Rect rect = new Rect(Position.width - 20, 4, 16, 16); if (GUI.Button(rect, new GUIContent("", SMUtils.Localize("#smloc_window_tt_001")))) // "Close Window" { OnCreate = false; SelectedKerbal = null; ToolTip = ""; if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { SMAddon.OnSmRosterClicked(); } else { ShowWindow = false; } } if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } try { GUILayout.BeginVertical(); DisplayRosterFilter(); DisplayRosterListViewer(); if (OnCreate) { CreateKerbalViewer(); } else if (SelectedKerbal != null) { EditKerbalViewer(); } else { GUILayout.BeginHorizontal(); GUI.enabled = SMSettings.EnableCrewModify; GUIContent guilabel = new GUIContent(SMUtils.Localize("#smloc_roster_002"), GUI.enabled // "Create Kerbal" ? SMUtils.Localize("#smloc_roster_tt_001") // Realistic Control is On. Create a Kerbal is disabled. : SMUtils.Localize("#smloc_roster_tt_022")); // "Opens the Kerbal creation editor." if (GUILayout.Button(guilabel, GUILayout.MaxWidth(120), GUILayout.Height(20))) { OnCreate = true; } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } GUILayout.EndHorizontal(); GUI.enabled = true; } GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, Screen.width, 30)); SMAddon.RepositionWindow(ref Position); } catch (Exception ex) { SMUtils.LogMessage(string.Format(" in Roster Window. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } }
private static void WindowToggleButtons() { GUILayout.BeginHorizontal(); GUIStyle settingsStyle = WindowSettings.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_012"), settingsStyle, GUILayout.Height(20))) // "Settings" { try { WindowSettings.ShowWindow = !WindowSettings.ShowWindow; if (WindowSettings.ShowWindow) { // Store settings in case we cancel later... SMSettings.MemStoreTempSettings(); } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Settings Window. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } GUIStyle rosterStyle = WindowRoster.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_013"), rosterStyle, GUILayout.Height(20))) // "Roster" { try { WindowRoster.ShowWindow = !WindowRoster.ShowWindow; if (WindowRoster.ShowWindow) { WindowRoster.GetRosterList(); } else { WindowRoster.SelectedKerbal = null; WindowRoster.ToolTip = ""; } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Roster Window. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } GUIStyle controlStyle = WindowControl.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_014"), controlStyle, GUILayout.Height(20))) // "Control" { try { WindowControl.ShowWindow = !WindowControl.ShowWindow; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Control Window. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } GUILayout.EndHorizontal(); }
internal static void DisplayWindowTabs() { Rect rect; GUILayout.BeginHorizontal(); GUIContent label; if (SMSettings.EnableCls) { label = new GUIContent(SMUtils.Localize("#smloc_control_002"), SMUtils.Localize("#smloc_control_tt_001")); GUIStyle hatchesStyle = _selectedTab == Tab.Hatch ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(label, hatchesStyle, GUILayout.Height(20))) // "Hatches" { try { SMAddon.UpdateClsSpaces(); SMAddon.SmVessel.GetHatches(); _selectedTab = Tab.Hatch; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Hatches Tab. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } } GUI.enabled = true; label = new GUIContent(SMUtils.Localize("#smloc_control_003"), SMUtils.Localize("#smloc_control_tt_002")); GUIStyle panelsStyle = _selectedTab == Tab.Panel ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(label, panelsStyle, GUILayout.Height(20))) // "Solar Panels" { try { SMAddon.SmVessel.GetSolarPanels(); _selectedTab = Tab.Panel; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Solar Panels Tab. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } label = new GUIContent(SMUtils.Localize("#smloc_control_004"), SMUtils.Localize("#smloc_control_tt_003")); GUIStyle antennaStyle = _selectedTab == Tab.Antenna ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(label, antennaStyle, GUILayout.Height(20))) // "Antennas" { try { SMAddon.SmVessel.GetAntennas(); _selectedTab = Tab.Antenna; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Antennas Tab. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } label = new GUIContent(SMUtils.Localize("#smloc_control_005"), SMUtils.Localize("#smloc_control_tt_004")); GUIStyle lightsStyle = _selectedTab == Tab.Light ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(label, lightsStyle, GUILayout.Height(20))) // "Lights" { try { SMAddon.SmVessel.GetLights(); _selectedTab = Tab.Light; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Lights Tab. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } label = new GUIContent(SMUtils.Localize("#smloc_control_006"), SMUtils.Localize("#smloc_control_tt_005")); GUIStyle labsStyle = _selectedTab == Tab.Lab ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle; if (GUILayout.Button(label, labsStyle, GUILayout.Height(20))) // "Labs" { try { SMAddon.SmVessel.GetLabs(); _selectedTab = Tab.Lab; } catch (Exception ex) { SMUtils.LogMessage( string.Format(" opening Labs Tab. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); } } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips) { ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10); } GUILayout.EndHorizontal(); }
internal static void ResolveResourcePartSelections(List <string> resourceNames) { try { if (resourceNames.Count > 0) { List <Part> newSources = new List <Part>(); List <Part> newTargets = new List <Part>(); if (WindowTransfer.ShowSourceVessels && SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { SMAddon.SmVessel.SelectedPartsSource = SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource, resourceNames); if (!WindowTransfer.ShowTargetVessels) { List <Part> .Enumerator srcParts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator(); while (srcParts.MoveNext()) { if (srcParts.Current == null) { continue; } if (!SMAddon.SmVessel.SelectedPartsTarget.Contains(srcParts.Current)) { continue; } SMAddon.SmVessel.SelectedPartsTarget.Remove(srcParts.Current); } srcParts.Dispose(); } } else { List <Part> .Enumerator parts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator(); while (parts.MoveNext()) { if (parts.Current == null) { continue; } if (resourceNames.Count > 1) { if (parts.Current.Resources.Contains(resourceNames[0]) && parts.Current.Resources.Contains(resourceNames[1])) { newSources.Add(parts.Current); } } else { if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && parts.Current.CrewCapacity > 0) { newSources.Add(parts.Current); } else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() && parts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0) { newSources.Add(parts.Current); } else if (parts.Current.Resources.Contains(resourceNames[0])) { newSources.Add(parts.Current); } } } parts.Dispose(); SMAddon.SmVessel.SelectedPartsSource.Clear(); SMAddon.SmVessel.SelectedPartsSource = newSources; } if (WindowTransfer.ShowTargetVessels && SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { SMAddon.SmVessel.SelectedPartsTarget = SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget, resourceNames); if (!WindowTransfer.ShowSourceVessels) { List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator(); while (tgtParts.MoveNext()) { if (tgtParts.Current == null) { continue; } if (!SMAddon.SmVessel.SelectedPartsSource.Contains(tgtParts.Current)) { continue; } SMAddon.SmVessel.SelectedPartsSource.Remove(tgtParts.Current); } tgtParts.Dispose(); } } else { List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator(); while (tgtParts.MoveNext()) { if (tgtParts.Current == null) { continue; } if (resourceNames.Count > 1) { if (tgtParts.Current.Resources.Contains(resourceNames[0]) && tgtParts.Current.Resources.Contains(resourceNames[1])) { newTargets.Add(tgtParts.Current); } } else { if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && tgtParts.Current.CrewCapacity > 0) { newTargets.Add(tgtParts.Current); } else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() && tgtParts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0) { newTargets.Add(tgtParts.Current); } else if (tgtParts.Current.Resources.Contains(resourceNames[0])) { newTargets.Add(tgtParts.Current); } } } tgtParts.Dispose(); SMAddon.SmVessel.SelectedPartsTarget.Clear(); SMAddon.SmVessel.SelectedPartsTarget = newTargets; } if (SMConditions.AreSelectedResourcesTypeOther(resourceNames)) { TransferPump.CreateDisplayPumps(); return; } SMAddon.SmVessel.SelectedVesselsSource.Clear(); SMAddon.SmVessel.SelectedVesselsTarget.Clear(); } else { SMAddon.SmVessel.SelectedPartsSource.Clear(); SMAddon.SmVessel.SelectedPartsTarget.Clear(); SMAddon.SmVessel.SelectedVesselsSource.Clear(); SMAddon.SmVessel.SelectedVesselsTarget.Clear(); } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in WindowManifest.ReconcileSelectedXferParts. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // in, Error } }
internal static void LoadSounds() { try { GameObject go = new GameObject("Audio"); SourceCrewStart = go.AddComponent <AudioSource>(); SourceCrewRun = go.AddComponent <AudioSource>(); SourceCrewStop = go.AddComponent <AudioSource>(); if (GameDatabase.Instance.ExistsAudioClip(AudioSourceCrewPathStart) && GameDatabase.Instance.ExistsAudioClip(AudioSourceCrewPathRun) && GameDatabase.Instance.ExistsAudioClip(AudioSourceCrewPathStop)) { ClipCrewStart = GameDatabase.Instance.GetAudioClip(AudioSourceCrewPathStart); ClipCrewRun = GameDatabase.Instance.GetAudioClip(AudioSourceCrewPathRun); ClipCrewStop = GameDatabase.Instance.GetAudioClip(AudioSourceCrewPathStop); // configure sources SourceCrewStart.clip = ClipCrewStart; // Start sound SourceCrewStart.volume = (float)SMSettings.CrewSoundVol; SourceCrewStart.pitch = 1f; SourceCrewRun.clip = ClipCrewRun; // Run sound SourceCrewRun.loop = true; SourceCrewRun.volume = (float)SMSettings.CrewSoundVol; SourceCrewRun.pitch = 1f; SourceCrewStop.clip = ClipCrewStop; // Stop Sound SourceCrewStop.volume = (float)SMSettings.CrewSoundVol; SourceCrewStop.pitch = 1f; } // Now do Pump sounds SourcePumpStart = go.AddComponent <AudioSource>(); SourcePumpRun = go.AddComponent <AudioSource>(); SourcePumpStop = go.AddComponent <AudioSource>(); if (GameDatabase.Instance.ExistsAudioClip(SourcePumpPathStart) && GameDatabase.Instance.ExistsAudioClip(SourcePumpPathRun) && GameDatabase.Instance.ExistsAudioClip(SourcePumpPathStop)) { ClipPumpStart = GameDatabase.Instance.GetAudioClip(SourcePumpPathStart); ClipPumpRun = GameDatabase.Instance.GetAudioClip(SourcePumpPathRun); ClipPumpStop = GameDatabase.Instance.GetAudioClip(SourcePumpPathStop); // configure sources SourcePumpStart.clip = ClipPumpStart; // Start sound SourcePumpStart.volume = (float)SMSettings.PumpSoundVol; SourcePumpStart.pitch = 1f; SourcePumpRun.clip = ClipPumpRun; // Run sound SourcePumpRun.loop = true; SourcePumpRun.volume = (float)SMSettings.PumpSoundVol; SourcePumpRun.pitch = 1f; SourcePumpStop.clip = ClipPumpStop; // Stop Sound SourcePumpStop.volume = (float)SMSettings.PumpSoundVol; SourcePumpStop.pitch = 1f; } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in SMAddon.LoadSounds. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // ReSharper disable once PossibleIntendedRethrow throw ex; } }