internal void DumpAllResources() { List <string> otherResourcesList = (from s in SMAddon.SmVessel.PartsByResource.Keys where SMConditions.TypeOfResource(s) == SMConditions.ResourceType.Pump select s).ToList(); uint pumpId = TransferPump.GetPumpIdFromHash(string.Join("", otherResourcesList.ToArray()), SMAddon.SmVessel.Vessel.parts.First(), SMAddon.SmVessel.Vessel.parts.Last(), TransferPump.TypePump.Dump, TransferPump.TriggerButton.Preflight); List <TransferPump> pumpList = otherResourcesList.Select( resource => new TransferPump(resource, TransferPump.TypePump.Dump, TransferPump.TriggerButton.Preflight, TransferPump.CalcRemainingResource(SMAddon.SmVessel.PartsByResource[resource], resource)) { FromParts = SMAddon.SmVessel.PartsByResource[resource], PumpId = pumpId }).ToList(); if (!TransferPump.PumpsInProgress(pumpId).Any()) { SMAddon.SmVessel.TransferPumps.AddRange(pumpList); ProcessController.DumpResources(SMAddon.SmVessel.TransferPumps); } else { TransferPump.AbortAllPumpsInProcess(pumpId); } }
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; } } }