예제 #1
0
        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);
            }
        }
예제 #2
0
 internal static bool CanResourceBeFilled(string resourceName)
 {
     return((!SMSettings.RealXfers ||
             SMAddon.SmVessel.IsRecoverable && AreSelectedResourcesTypeOther(new List <string> {
         resourceName
     }))
            &&
            TransferPump.CalcRemainingCapacity(SMAddon.SmVessel.PartsByResource[resourceName], resourceName) >
            SMSettings.Tolerance);
 }
예제 #3
0
        internal void RefreshLists()
        {
            //Utilities.LogMessage("Entered:  SMVessel.RefreshLists", Utilities.LogType.Info, SMSettings.VerboseLogging);
            if (Vessel == null)
            {
                return;
            }
            SMConditions.ListsUpdating = true;
            UpdatePartsByResource();
            GetSelectedResourcesParts();
            UpdateDockedVessels();

            // now lets reconcile the selected parts based on the new list of resources...
            WindowManifest.ResolveResourcePartSelections(SMAddon.SmVessel.SelectedResources);

            // Now lets update the Resource Xfer Objects...
            TransferPump.UpdateDisplayPumps();

            // now SM settings / hatches.
            if (SMSettings.EnableCls && SMConditions.CanShowShipManifest())
            {
                if (SMAddon.GetClsAddon())
                {
                    SMAddon.UpdateClsSpaces();
                    if (SMAddon.GetClsVessel())
                    {
                        GetHatches();
                    }
                }
            }

            // Control Window datasources
            GetDockedVessels();
            GetHatches();
            GetAntennas();
            GetLights();
            GetSolarPanels();
            GetLabs();
            WindowRoster.GetRosterList();
            //Utilities.LogMessage("Exiting:  SMVessel.RefreshLists", Utilities.LogType.Info, SMSettings.VerboseLogging);
            SMConditions.ListsUpdating = false;
        }
예제 #4
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);
     }
 }
예제 #5
0
        internal static void ToggleDumpResource(List <Part> partList, List <string> resourceNames, uint pumpId)
        {
            // This routine is called by the dump part button on the Transfer Window interface.
            // This routine is also called by the dump docked vessel button on the Transfer window interface.
            List <TransferPump> pumpList =
                resourceNames.Select(
                    resource =>
                    new TransferPump(resource, TransferPump.TypePump.Dump, TransferPump.TriggerButton.Transfer,
                                     TransferPump.CalcRemainingResource(partList, resource))
            {
                FromParts = partList,
                PumpId    = pumpId,
                PumpRatio = 1
            }).ToList();

            if (!TransferPump.PumpsInProgress(pumpId).Any())
            {
                ProcessController.DumpResources(pumpList);
            }
            else
            {
                TransferPump.AbortAllPumpsInProcess(pumpId);
            }
        }
예제 #6
0
        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
            }
        }
예제 #7
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;
                }
            }
        }
예제 #8
0
 internal static bool CanResourceBeDumped(string resourceName)
 {
     return(TransferPump.CalcRemainingResource(SMAddon.SmVessel.PartsByResource[resourceName], resourceName) >
            SMSettings.Tolerance &&
            IsResourceTypeOther(resourceName));
 }