Esempio n. 1
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 = $"{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($"{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(
                        $" in WindowManifest.ResourceButtonList.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                        SmUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
            }
        }