Example #1
0
 internal static void ToggleDumpResource(string resourceName, uint pumpId)
 {
     if (!TransferPump.IsPumpInProgress(pumpId))
     {
         //Fired by Resource Dump on Manifest Window.
         TransferPump pump = new TransferPump(resourceName, TransferPump.TypePump.Dump, TransferPump.TriggerButton.Manifest,
                                              TransferPump.CalcRemainingResource(SMAddon.SmVessel.PartsByResource[resourceName], resourceName))
         {
             FromParts = SMAddon.SmVessel.PartsByResource[resourceName],
             PumpId    = pumpId
         };
         List <TransferPump> pumps = new List <TransferPump>
         {
             pump
         };
         ProcessController.DumpResources(pumps);
     }
     else
     {
         TransferPump.AbortAllPumpsInProcess(pumpId);
     }
 }
Example #2
0
        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;
                }
            }
        }