Example #1
0
        internal static int GetPartsCrewCount(List <Part> parts)
        {
            int count = 0;

            List <Part> .Enumerator part = parts.GetEnumerator();
            while (part.MoveNext())
            {
                if (part.Current == null)
                {
                    continue;
                }
                if (part.Current.CrewCapacity <= 0)
                {
                    continue;
                }
                count += part.Current.protoModuleCrew.Count;
                if (!InstalledMods.IsDfApiReady)
                {
                    continue;
                }
                if (!part.Current.Modules.Contains("DeepFreezer"))
                {
                    continue;
                }
                PartModule freezerModule = SMConditions.GetFreezerModule(part.Current);
                // ReSharper disable once SuspiciousTypeConversion.Global
                DfWrapper.DeepFreezer freezer = new DfWrapper.DeepFreezer(freezerModule);
                count += freezer.TotalFrozen;
            }
            part.Dispose();
            return(count);
        }
Example #2
0
 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);
     }
 }
Example #3
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);
            }
        }
Example #4
0
        internal static bool IsCrewFull(Part part)
        {
            if (!InstalledMods.IsDfInstalled || !part.Modules.Contains("DeepFreezer"))
            {
                return(part.protoModuleCrew.Count == part.CrewCapacity);
            }
            PartModule deepFreezer = SMConditions.GetFreezerModule(part);

            return(deepFreezer != null && new DFWrapper.DeepFreezer(deepFreezer).PartFull);
        }
Example #5
0
 internal void GetHatches()
 {
     _hatches.Clear();
     try
     {
         if (!SMSettings.EnableCls || !SMConditions.CanShowShipManifest())
         {
             return;
         }
         if (!SMAddon.GetClsAddon())
         {
             return;
         }
         SMAddon.UpdateClsSpaces();
         if (!SMAddon.GetClsVessel())
         {
             return;
         }
         List <ICLSPart> .Enumerator hParts = SMAddon.ClsAddon.Vessel.Parts.GetEnumerator();
         while (hParts.MoveNext())
         {
             if (hParts.Current == null)
             {
                 continue;
             }
             List <PartModule> .Enumerator hModules = hParts.Current.Part.Modules.GetEnumerator();
             while (hModules.MoveNext())
             {
                 if (hModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)hModules.Current;
                 if (pModule.moduleName != "ModuleDockingHatch")
                 {
                     continue;
                 }
                 ModHatch pHatch = new ModHatch
                 {
                     HatchModule = (PartModule)hModules.Current,
                     ClsPart     = hParts.Current
                 };
                 _hatches.Add(pHatch);
             }
             hModules.Dispose();
         }
         hParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetHatches().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Example #6
0
        internal static void UpdateDisplayPumps()
        {
            // Now lets update the Resource Xfer pumps for display use...
            if (!SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources))
            {
                return;
            }
            if (!WindowTransfer.DisplayPumps.Any())
            {
                CreateDisplayPumps();
            }

            // Lets create a pump Object for managing pump options and data.
            List <Part> sourceParts = WindowTransfer.ShowSourceVessels
        ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource,
                                                   SMAddon.SmVessel.SelectedResources)
        : SMAddon.SmVessel.SelectedPartsSource;
            List <Part> targetParts = WindowTransfer.ShowTargetVessels
        ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget,
                                                   SMAddon.SmVessel.SelectedResources)
        : SMAddon.SmVessel.SelectedPartsTarget;

            List <TransferPump> .Enumerator dPumps = WindowTransfer.DisplayPumps.GetEnumerator();
            while (dPumps.MoveNext())
            {
                if (dPumps.Current == null)
                {
                    continue;
                }
                // Lets update pump data (it persists).
                TransferPump pump = dPumps.Current;
                switch (pump.PumpType)
                {
                case TypePump.Dump:
                case TypePump.SourceToTarget:
                    pump.FromParts = sourceParts;
                    pump.ToParts   = targetParts;
                    break;

                case TypePump.TargetToSource:
                    pump.FromParts = targetParts;
                    pump.ToParts   = sourceParts;
                    break;
                }
                pump.EditSliderAmount =
                    CalcMaxPumpAmt(pump.FromParts, pump.ToParts, SMAddon.SmVessel.SelectedResources)
                    .ToString(CultureInfo.InvariantCulture);
            }
            dPumps.Dispose();
        }
Example #7
0
        internal static void CreateDisplayPumps()
        {
            // Now lets update the Resource Xfer pumps for display use...
            WindowTransfer.DisplayPumps.Clear();
            if (!SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources))
            {
                return;
            }
            // Lets create a pump Object for managing pump options and data.
            List <Part> displaySourceParts = WindowTransfer.ShowSourceVessels
        ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource,
                                                   SMAddon.SmVessel.SelectedResources)
        : SMAddon.SmVessel.SelectedPartsSource;
            List <Part> displayTargetParts = WindowTransfer.ShowTargetVessels
        ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget,
                                                   SMAddon.SmVessel.SelectedResources)
        : SMAddon.SmVessel.SelectedPartsTarget;

            List <string> .Enumerator resources = SMAddon.SmVessel.SelectedResources.GetEnumerator();
            while (resources.MoveNext())
            {
                TransferPump pump1 = new TransferPump
                {
                    Resource         = resources.Current,
                    PumpType         = TypePump.SourceToTarget,
                    PumpAmount       = CalcMaxPumpAmt(displaySourceParts, displayTargetParts, SMAddon.SmVessel.SelectedResources),
                    EditSliderAmount =
                        CalcMaxPumpAmt(displaySourceParts, displayTargetParts, SMAddon.SmVessel.SelectedResources)
                        .ToString(CultureInfo.InvariantCulture),
                    FromParts = displaySourceParts,
                    ToParts   = displayTargetParts
                };
                WindowTransfer.DisplayPumps.Add(pump1);

                TransferPump pump2 = new TransferPump
                {
                    Resource         = resources.Current,
                    PumpType         = TypePump.TargetToSource,
                    PumpAmount       = CalcMaxPumpAmt(displayTargetParts, displaySourceParts, SMAddon.SmVessel.SelectedResources),
                    EditSliderAmount =
                        CalcMaxPumpAmt(displayTargetParts, displaySourceParts, SMAddon.SmVessel.SelectedResources)
                        .ToString(CultureInfo.InvariantCulture),
                    FromParts = displayTargetParts,
                    ToParts   = displaySourceParts
                };
                WindowTransfer.DisplayPumps.Add(pump2);
            }
            resources.Dispose();
        }
Example #8
0
 internal static void RepairKerbal(ProtoCrewMember kerbal)
 {
     try
     {
         if (!SMConditions.KerbalIsBroken(kerbal))
         {
             throw new Exception("Tried to repair an unbroken kerbal: " + kerbal.ToString());
         }
         // For now, the only broken Kerbals are "Assigned" but for some reason are still Applicants. So we convert them to Crew.
         kerbal.type = ProtoCrewMember.KerbalType.Crew;
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($" in RepairKerbal.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                            SmUtils.LogType.Error, true);
     }
 }
Example #9
0
        internal static int GetPartCrewCount(Part part)
        {
            int crewCount = part.protoModuleCrew.Count;

            if (!InstalledMods.IsDfApiReady)
            {
                return(crewCount);
            }
            if (!part.Modules.Contains("DeepFreezer"))
            {
                return(crewCount);
            }
            PartModule freezerModule = SMConditions.GetFreezerModule(part);

            // ReSharper disable once SuspiciousTypeConversion.Global
            DfWrapper.DeepFreezer freezer = new DfWrapper.DeepFreezer(freezerModule);
            crewCount += freezer.TotalFrozen;
            return(crewCount);
        }
Example #10
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;
        }
Example #11
0
        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);
            }
        }
Example #12
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
            }
        }
Example #13
0
        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;
                }
            }
        }
Example #14
0
        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();
        }
Example #15
0
        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();
        }
Example #16
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;
                }
            }
        }
Example #17
0
        internal static string DisplayVesselResourceTotals(string selectedResource)
        {
            string displayAmount = "";
            double currAmount    = 0;
            double totAmount     = 0;

            if (selectedResource == null)
            {
                return($" - ({currAmount:#######0})");
            }
            try
            {
                if (SMConditions.IsResourceTypeOther(selectedResource))
                {
                    List <Part> .Enumerator parts = SMAddon.SmVessel.PartsByResource[selectedResource].GetEnumerator();
                    while (parts.MoveNext())
                    {
                        if (parts.Current == null)
                        {
                            continue;
                        }
                        currAmount += parts.Current.Resources[selectedResource].amount;
                        totAmount  += parts.Current.Resources[selectedResource].maxAmount;
                    }
                    parts.Dispose();
                }
                switch (SMConditions.TypeOfResource(selectedResource))
                {
                case SMConditions.ResourceType.Crew:
                    currAmount = SMAddon.SmVessel.Vessel.GetCrewCount();
                    totAmount  = SMAddon.SmVessel.Vessel.GetCrewCapacity();

                    // if DF installed, get total frozen and add to count.
                    if (InstalledMods.IsDfInstalled)
                    {
                        List <Part> .Enumerator cryofreezers = GetFreezerParts().GetEnumerator();
                        // ReSharper disable once SuspiciousTypeConversion.Global
                        while (cryofreezers.MoveNext())
                        {
                            if (cryofreezers.Current == null)
                            {
                                continue;
                            }
                            currAmount += new DfWrapper.DeepFreezer(SMConditions.GetFreezerModule(cryofreezers.Current)).TotalFrozen;
                        }
                        cryofreezers.Dispose();
                    }

                    // Now check for occupied external seats
                    // external seats that are occupied will show up in getcrewcount and getcrewcapacity
                    // Since we cannot yet xfer external crew, we need to remove them from the count..
                    List <KerbalSeat> seatCount = (from iPart in SMAddon.SmVessel.Vessel.parts
                                                   where iPart.Modules.Contains("KerbalSeat")
                                                   from PartModule iModule in iPart.Modules
                                                   where iModule.ClassName == "KerbalSeat"
                                                   select(KerbalSeat) iModule
                                                   into kSeat
                                                   where kSeat.Occupant != null
                                                   select kSeat).ToList();
                    currAmount -= seatCount.Count;
                    totAmount  -= seatCount.Count;
                    break;

                case SMConditions.ResourceType.Science:
                    currAmount +=
                        SMAddon.SmVessel.PartsByResource[selectedResource].SelectMany(part => part.Modules.Cast <PartModule>())
                        .OfType <IScienceDataContainer>()
                        .Sum(module => (double)module.GetScienceCount());
                    break;
                }
                displayAmount = selectedResource != SMConditions.ResourceType.Science.ToString()
          ? $" - ({currAmount:#######0}/{totAmount:######0})"
          : $" - ({currAmount:#######0})";
            }
            catch (Exception ex)
            {
                LogMessage($" in DisplayResourceTotals().  Error:  {ex}", LogType.Error, true);
            }

            return(displayAmount);
        }
Example #18
0
        internal static void DisplayTabActions()
        {
            GUILayout.BeginHorizontal();
            switch (_selectedTab)
            {
            case Tab.Panel:
                GUI.enabled = SMAddon.SmVessel.SolarPanels.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_016"], GUILayout.Height(20))) // "Retract All Solar Panels"
                {
                    TabSolarPanel.RetractAllPanels();
                }
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_007"], GUILayout.Height(20))) // "Extend All Solar Panels"
                {
                    TabSolarPanel.ExtendAllPanels();
                }
                break;

            case Tab.Hatch:
                GUI.enabled = SMAddon.SmVessel.Hatches.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_008"], GUILayout.Height(20))) // "Close All Hatches"
                {
                    TabHatch.CloseAllHatches();
                }
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_009"], GUILayout.Height(20))) // "Open All Hatches"
                {
                    TabHatch.OpenAllHatches();
                }
                break;

            case Tab.Antenna:
                GUI.enabled = SMAddon.SmVessel.Antennas.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_010"], GUILayout.Height(20))) // "Retract All Antennas"
                {
                    TabAntenna.RetractAllAntennas();
                }
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_011"], GUILayout.Height(20))) // "Extend All Antennas"
                {
                    TabAntenna.ExtendAllAntennas();
                }
                break;

            case Tab.Light:
                GUI.enabled = SMAddon.SmVessel.Lights.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_012"], GUILayout.Height(20))) // "Turn Off All Lights"
                {
                    TabLight.TurnOffAllLights();
                }
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_013"], GUILayout.Height(20))) // "Turn On All Lights"
                {
                    TabLight.TurnOnAllLights();
                }
                break;

            case Tab.Lab:
                GUI.enabled = SMAddon.SmVessel.Labs.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_014"], GUILayout.Height(20))) // "Turn Off All Labs"
                {
                    TabLight.TurnOffAllLights();
                }
                if (GUILayout.Button(SmUtils.SmTags["#smloc_control_015"], GUILayout.Height(20))) // "Turn On All Labs"
                {
                    TabLight.TurnOnAllLights();
                }
                break;

            case Tab.Vessel:
                // Temporary commenting of code to allow release.  Will work Vessel combining in later release.
                //GUI.enabled = TabVessel.CombineVesselCount > 0;
                //if (GUILayout.Button(SmUtils.SmTags["#smloc_control_018"], GUILayout.Height(20))) // "Combine Selected Vessels"
                //  TabVessel.CombineSelectedVessels();
                //if (GUILayout.Button(SmUtils.SmTags["#smloc_control_019"], GUILayout.Height(20))) // "Clear Vessel Selections"
                //  TabVessel.ClearVesselCount();
                break;

            case Tab.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }
Example #19
0
        internal static void DisplayTabActions()
        {
            GUILayout.BeginHorizontal();
            switch (_selectedTab)
            {
            case Tab.Panel:
                GUI.enabled = SMAddon.SmVessel.SolarPanels.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_016"), GUILayout.Height(20))) // "Retract All Solar Panels"
                {
                    TabSolarPanel.RetractAllPanels();
                }
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_007"), GUILayout.Height(20))) // "Extend All Solar Panels"
                {
                    TabSolarPanel.ExtendAllPanels();
                }
                break;

            case Tab.Hatch:
                GUI.enabled = SMAddon.SmVessel.Hatches.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_008"), GUILayout.Height(20))) // "Close All Hatches"
                {
                    TabHatch.CloseAllHatches();
                }
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_009"), GUILayout.Height(20))) // "Open All Hatches"
                {
                    TabHatch.OpenAllHatches();
                }
                break;

            case Tab.Antenna:
                GUI.enabled = SMAddon.SmVessel.Antennas.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_010"), GUILayout.Height(20))) // "Retract All Antennas"
                {
                    TabAntenna.RetractAllAntennas();
                }
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_011"), GUILayout.Height(20))) // "Extend All Antennas"
                {
                    TabAntenna.ExtendAllAntennas();
                }
                break;

            case Tab.Light:
                GUI.enabled = SMAddon.SmVessel.Lights.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_012"), GUILayout.Height(20))) // "Turn Off All Lights"
                {
                    TabLight.TurnOffAllLights();
                }
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_013"), GUILayout.Height(20))) // "Turn On All Lights"
                {
                    TabLight.TurnOnAllLights();
                }
                break;

            case Tab.Lab:
                GUI.enabled = SMAddon.SmVessel.Labs.Count > 0 && (!SMSettings.RealControl || SMConditions.IsShipControllable());
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_014"), GUILayout.Height(20))) // "Turn Off All Labs"
                {
                    TabLight.TurnOffAllLights();
                }
                if (GUILayout.Button(SMUtils.Localize("#smloc_control_015"), GUILayout.Height(20))) // "Turn On All Labs"
                {
                    TabLight.TurnOnAllLights();
                }
                break;

            case Tab.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }
Example #20
0
        internal void GetDockedVessels()
        {
            if (_dockedVessels == null)
            {
                _dockedVessels = new List <ModDockedVessel>();
            }
            else
            {
                _dockedVessels.Clear();
            }
            List <Part> .Enumerator dockingParts =
                (from p in Vessel.parts where p.Modules.Contains("ModuleDockingNode") select p).ToList().GetEnumerator();
            while (dockingParts.MoveNext())
            {
                if (dockingParts.Current == null)
                {
                    continue;
                }
                List <ModuleDockingNode> .Enumerator dNodes =
                    dockingParts.Current.FindModulesImplementing <ModuleDockingNode>().GetEnumerator();
                while (dNodes.MoveNext())
                {
                    if (dNodes.Current == null)
                    {
                        continue;
                    }
                    if (dNodes.Current.vesselInfo == null)
                    {
                        continue;
                    }
                    ModDockedVessel modDockedVessel = new ModDockedVessel(dNodes.Current);
                    if (modDockedVessel.LaunchId == 0)
                    {
                        continue;
                    }
                    modDockedVessel.IsDocked = SMConditions.IsVesselDocked(modDockedVessel);
                    _dockedVessels.Add(modDockedVessel);
                }
                dNodes.Dispose();
            }
            dockingParts.Dispose();

            //Now lets scrub the list to remove child vessels within the list.
            // this can happen when multiple decouples and docking occur...
            List <ModDockedVessel> vesselsToRemove = new List <ModDockedVessel>();

            // create vessel list to start wtih
            List <ModDockedVessel> .Enumerator srcVessels = _dockedVessels.GetEnumerator();
            while (srcVessels.MoveNext())
            {
                if (srcVessels.Current == null)
                {
                    continue;
                }
                // create vessel list to compare to
                bool isUnique = false;
                List <ModDockedVessel> .Enumerator cmpVessels = _dockedVessels.GetEnumerator();
                while (cmpVessels.MoveNext())
                {
                    if (cmpVessels.Current == null)
                    {
                        continue;
                    }
                    if (cmpVessels.Current == srcVessels.Current)
                    {
                        continue;
                    }
                    if (vesselsToRemove.Contains(cmpVessels.Current))
                    {
                        continue;
                    }
                    List <Part> .Enumerator vParts = cmpVessels.Current.VesselParts.GetEnumerator();
                    while (vParts.MoveNext())
                    {
                        // if any part of the target is not in the src vessel, the src is not a child of the target vessel.  move on.
                        if (srcVessels.Current.VesselParts.Contains(vParts.Current))
                        {
                            continue;
                        }
                        isUnique = true;
                        break;
                    }
                    vParts.Dispose();
                    if (isUnique)
                    {
                        continue;
                    }
                    // since we are here, then all parts are in another vessel.  this is likely a child.  add it to the remove list.
                    vesselsToRemove.Add(cmpVessels.Current);
                    break;
                }
                cmpVessels.Dispose();
            }
            srcVessels.Dispose();
            if (vesselsToRemove.Count <= 0)
            {
                return;
            }
            List <ModDockedVessel> .Enumerator remove = vesselsToRemove.GetEnumerator();
            while (remove.MoveNext())
            {
                if (remove.Current == null)
                {
                    continue;
                }
                _dockedVessels.Remove(remove.Current);
            }
            remove.Dispose();
        }
Example #21
0
        internal static void Display(Vector2 displayViewerPosition)
        {
            //float scrollX = WindowControl.Position.x + 20;
            //float scrollY = WindowControl.Position.y + 50 - displayViewerPosition.y;
            float scrollX = 20;
            float scrollY = displayViewerPosition.y;

            // Reset Tooltip active flag...
            ToolTipActive             = false;
            SMHighlighter.IsMouseOver = false;

            GUILayout.BeginVertical();
            GUI.enabled = true;
            //GUILayout.Label("Vessel Control Center", SMStyle.LabelTabHeader);
            GUILayout.Label(SmUtils.Localize("#smloc_control_vessel_000"), SMStyle.LabelTabHeader);
            GUILayout.Label("____________________________________________________________________________________________",
                            SMStyle.LabelStyleHardRule, GUILayout.Height(10), GUILayout.Width(guiRuleWidth));
            string step = "start";

            try
            {
                // Display all Vessels Docked together
                // ReSharper disable once ForCanBeConvertedToForeach
                for (int v = 0; v < SMAddon.SmVessel.DockedVessels.Count; v++)
                {
                    GUI.enabled = SMAddon.SmVessel.DockedVessels[v].IsDocked;

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("UnDock", GUILayout.Width(guiBtnWidth)))
                    {
                        // close hatches If CLS applies
                        if (SMConditions.IsClsEnabled())
                        {
                            CloseVesselHatches(SMAddon.SmVessel.DockedVessels[v]);
                        }

                        // Decouple/undock selected vessel.
                        UndockSelectedVessel(SMAddon.SmVessel.DockedVessels[v]);
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, SMAddon.SmVessel.DockedVessels[v], Event.current.mousePosition);
                    }
                    GUI.enabled = true;
                    if (SMAddon.SmVessel.DockedVessels[v].IsEditing)
                    {
                        SMAddon.SmVessel.DockedVessels[v].renameVessel = GUILayout.TextField(SMAddon.SmVessel.DockedVessels[v].renameVessel, GUILayout.Width(guiLabelWidth - (guiBtnWidth + 5)));
                    }
                    else
                    {
                        GUILayout.Label($"{SMAddon.SmVessel.DockedVessels[v].VesselInfo.name}", GUILayout.Width(guiLabelWidth));
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, SMAddon.SmVessel.DockedVessels[v], Event.current.mousePosition);
                    }
                    // now editing buttons.
                    GUIContent content = SMAddon.SmVessel.DockedVessels[v].IsEditing ? new GUIContent("Save", "Saves the changes to the docked vessel name.") : new GUIContent("Edit", "Change the docked vessel name.");
                    if (GUILayout.Button(content, GUILayout.Width(50)))
                    {
                        if (SMAddon.SmVessel.DockedVessels[v].IsEditing)
                        {
                            SMAddon.SmVessel.DockedVessels[v].VesselInfo.name = SMAddon.SmVessel.DockedVessels[v].renameVessel;
                            SMAddon.SmVessel.DockedVessels[v].renameVessel    = null;
                            SMAddon.SmVessel.DockedVessels[v].IsEditing       = false;
                        }
                        else
                        {
                            SMAddon.SmVessel.DockedVessels[v].IsEditing    = true;
                            SMAddon.SmVessel.DockedVessels[v].renameVessel = SMAddon.SmVessel.DockedVessels[v].VesselInfo.name;
                        }
                    }
                    if (SMAddon.SmVessel.DockedVessels[v].IsEditing)
                    {
                        GUIContent cancelContent = new GUIContent("Cancel", "Cancel changes to docked vessel name");
                        if (GUILayout.Button(cancelContent, GUILayout.Width(guiBtnWidth)))
                        {
                            SMAddon.SmVessel.DockedVessels[v].renameVessel = null;
                            SMAddon.SmVessel.DockedVessels[v].IsEditing    = false;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                // Display MouseOverHighlighting, if any
                SMHighlighter.MouseOverHighlight();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in Vessels Tab at step {step}.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                    SmUtils.LogType.Error, true);
            }
            GUI.enabled = true;
            GUILayout.EndVertical();
        }
Example #22
0
        internal void UpdatePartsByResource()
        {
            if (_partsByResource == null)
            {
                _partsByResource = new Dictionary <string, List <Part> >();
            }
            else
            {
                _partsByResource.Clear();
            }

            // Let's update...
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            List <Part> .Enumerator parts = Vessel.Parts.GetEnumerator();
            while (parts.MoveNext())
            {
                if (parts.Current == null)
                {
                    continue;
                }
                Part part = parts.Current;
                // First let's Get any Crew, if desired...
                if (SMSettings.EnableCrew && (part.CrewCapacity > 0 || SMConditions.IsUsiInflatable(part)) && part.partInfo.name != "kerbalEVA")
                {
                    bool vResourceFound = false;
                    // is resource in the list yet?.
                    if (_partsByResource.Keys.Contains(SMConditions.ResourceType.Crew.ToString()))
                    {
                        // found resource.  lets add part to its list.
                        vResourceFound = true;
                        List <Part> eParts = _partsByResource[SMConditions.ResourceType.Crew.ToString()];
                        part.crewTransferAvailable = SMSettings.EnableStockCrewXfer;
                        eParts.Add(part);
                    }
                    if (!vResourceFound)
                    {
                        // found a new resource.  lets add it to the list of resources.
                        List <Part> nParts = new List <Part> {
                            part
                        };
                        _partsByResource.Add(SMConditions.ResourceType.Crew.ToString(), nParts);
                    }
                }
                // Let's Get any Science...
                if (SMSettings.EnableScience)
                {
                    IScienceDataContainer[] sciModules = part.FindModulesImplementing <IScienceDataContainer>().ToArray();
                    if (sciModules.Length > 0)
                    {
                        // is resource in the list yet?.
                        // We only need the first match on the part so stop.
                        if (_partsByResource.Keys.Contains(SMConditions.ResourceType.Science.ToString()))
                        {
                            _partsByResource[SMConditions.ResourceType.Science.ToString()].Add(part);
                        }
                        else
                        {
                            // found a new resource.  lets add it to the list of resources.
                            List <Part> nParts = new List <Part> {
                                part
                            };
                            _partsByResource.Add(SMConditions.ResourceType.Science.ToString(), nParts);
                        }
                    }
                }

                // Now, let's get flight Resources.
                if (!SMSettings.EnableResources)
                {
                    continue;
                }
                {
                    IEnumerator resources = part.Resources.GetEnumerator();
                    while (resources.MoveNext())
                    {
                        if (resources.Current == null)
                        {
                            continue;
                        }
                        PartResource resource = (PartResource)resources.Current;
                        // Realism Mode.  we want to exclude Resources with TransferMode = NONE...
                        if (SMSettings.RealXfers &&
                            (!resource.info.isVisible || resource.info.resourceTransferMode == ResourceTransferMode.NONE))
                        {
                            continue;
                        }
                        bool vResourceFound = false;
                        // is resource in the list yet?.
                        if (_partsByResource.Keys.Contains(resource.info.name))
                        {
                            vResourceFound = true;
                            List <Part> eParts = _partsByResource[resource.info.name];
                            eParts.Add(part);
                        }
                        if (vResourceFound)
                        {
                            continue;
                        }
                        // found a new resource.  lets add it to the list of resources.
                        List <Part> nParts = new List <Part> {
                            part
                        };
                        _partsByResource.Add(resource.info.name, nParts);
                    }
                }
            }
            parts.Dispose();
        }
Example #23
0
        private static void SetupActionButton(ProtoCrewMember kerbal, out string buttonText, out string buttonToolTip)
        {
            if (HighLogic.LoadedScene != GameScenes.SPACECENTER)
            {
                if (SMConditions.CanKerbalBeAdded(kerbal))
                {
                    GUI.enabled   = true;
                    buttonText    = SMUtils.Localize("#smloc_roster_023"); // "Add";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_010");
                    //buttonToolTip = "Adds a kerbal to the Selected Source Part,\r\nin the first available seat.";
                }
                else if (SMConditions.FrozenKerbalNotThawable(kerbal))
                {
                    GUI.enabled   = false;
                    buttonText    = SMUtils.Localize("#smloc_roster_025"); // "Thaw";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_011");
                    // buttonToolTip = "Thaw disabled.  Vessel not active. UnFreeze a Kerbal and Revive them.\r\nWill then become assigned to current vessel.";
                }
                else if (SMConditions.FrozenKerbalIsThawable(kerbal))
                {
                    GUI.enabled   = true;
                    buttonText    = SMUtils.Localize("#smloc_roster_025"); // "Thaw";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_012");
                    // buttonToolTip = "UnFreeze a Kerbal and Revive them.\r\nWill then become assigned to current vessel.";
                }
                else if (SMConditions.CanKerbalBeFrozen(kerbal))
                {
                    GUI.enabled   = true;
                    buttonText    = SMUtils.Localize("#smloc_roster_026"); // "Freeze";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_013");
                    // buttonToolTip = "Freezes a Kerbal in the DeepFreezer.\r\nWill then become Unowned and will not consume life support.";
                }
                else if (SMConditions.CanKerbalBeRemoved(kerbal))
                {
                    GUI.enabled   = true;
                    buttonText    = SMUtils.Localize("#smloc_roster_022");    // "Remove";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_014"); // "Removes a Kerbal from the active vessel.\r\nWill then become available.";
                }
                else if (SMConditions.KerbalCannotBeRemovedRealism(kerbal))
                {
                    GUI.enabled   = false;
                    buttonText    = SMUtils.Localize("#smloc_roster_022");    // "Remove";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_023"); // "Remove Disabled. Roster Modifications is preventing this action.\r\nTo Remove this Kerbal, Change your Roster Modifications Setting.";
                }
                else if (SMConditions.KerbalCannotBeAddedNoSource(kerbal))
                {
                    GUI.enabled   = false;
                    buttonText    = SMUtils.Localize("#smloc_roster_023"); // "Add";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_015");
                    // buttonToolTip = "Add Disabled.  No source part is selected.\r\nTo add a Kerbal, Select a Source Part with an available seat.";
                }
                else if (SMConditions.KerbalCannotBeAddedRealism(kerbal))
                {
                    GUI.enabled   = false;
                    buttonText    = SMUtils.Localize("#smloc_roster_023"); // "Add";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_016");
                    // buttonToolTip = "Add Disabled.  Roster Modifications is preventing this action.\r\nTo add a Kerbal, Change your Roster Modifications Setting.";
                }
                else
                {
                    GUI.enabled   = false;
                    buttonText    = "--";
                    buttonToolTip = SMUtils.Localize("#smloc_roster_tt_017");
                    // buttonToolTip = "Kerbal is not available.\r\nCurrent status does not allow any action.";
                }
            }
            else // HighLogic.LoadedScene == GameScenes.SPACECENTER
            {
                GUI.enabled   = false;
                buttonText    = "--";
                buttonToolTip = SMUtils.Localize("#smloc_roster_tt_018");
                // buttonToolTip = "Kerbal is not dead or missing.\r\nCurrent status does not allow any action while in Space Center.";
            }

            // Applies to both scenes.
            if (SMConditions.CanKerbalBeReSpawned(kerbal))
            {
                GUI.enabled   = SMSettings.EnableCrewModify;
                buttonText    = SMUtils.Localize("#smloc_roster_024"); // "Respawn";
                buttonToolTip = SMSettings.EnableCrewModify
          ? SMUtils.Localize("#smloc_roster_tt_020")                   // "Brings a Kerbal back to life.\r\nWill then become available.";
          : SMUtils.Localize("#smloc_roster_tt_019");                  // "Realistic Control is preventing this action.";
            }
        }
Example #24
0
        internal static void Display(Vector2 displayViewerPosition)
        {
            //float scrollX = WindowControl.Position.x + 20;
            //float scrollY = WindowControl.Position.y + 50 - displayViewerPosition.y;
            float scrollX = 20;
            float scrollY = displayViewerPosition.y;

            // Reset Tooltip active flag...
            ToolTipActive             = false;
            SMHighlighter.IsMouseOver = false;
            // Reset Tooltip active flag...
            ToolTipActive    = false;
            _canShowToolTips = WindowSettings.ShowToolTips && ShowToolTips;

            Position = WindowControl.Position;

            GUILayout.BeginVertical();
            GUI.enabled = true;
            //GUILayout.Label("Vessel Control Center", SMStyle.LabelTabHeader);
            GUILayout.Label(SmUtils.SmTags["#smloc_control_vessel_000"], SMStyle.LabelTabHeader);
            GUILayout.Label("____________________________________________________________________________________________",
                            SMStyle.LabelStyleHardRule, GUILayout.Height(10), GUILayout.Width(guiRuleWidth));
            string step = "start";

            try
            {
                int combineVesselcount = 0;
                // Display all Vessels Docked together
                // ReSharper disable once ForCanBeConvertedToForeach
                for (int v = 0; v < SMAddon.SmVessel.DockedVessels.Count; v++)
                {
                    ModDockedVessel mdv = SMAddon.SmVessel.DockedVessels[v];
                    GUI.enabled = mdv.IsDocked;

                    GUILayout.BeginHorizontal();
                    GUIContent content = new GUIContent("", SmUtils.SmTags["#smloc_control_vessel_tt_001"]); //"Include in list of vessels to combine into a single docked vessel"

                    bool isChecked = mdv.Combine;
                    // temporary commenting of comnbine code to allow release.  Will work for next version.
                    //isChecked = GUILayout.Toggle(isChecked, content, GUILayout.Width(20));
                    if (isChecked)
                    {
                        combineVesselcount += 1;
                    }
                    if (isChecked != mdv.Combine)
                    {
                        mdv.Combine = isChecked;
                    }
                    // temporary commenting to allow release.  Will work on comnbine code for next version.
                    //Rect rect = GUILayoutUtility.GetLastRect();
                    //if (Event.current.type == EventType.Repaint && _canShowToolTips)
                    //  ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, scrollX);
                    //if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    //{
                    //  SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, mdv,
                    //    Event.current.mousePosition);
                    //}

                    content = new GUIContent(SmUtils.SmTags["#smloc_control_vessel_001"], SmUtils.SmTags["#smloc_control_vessel_tt_005"]);
                    if (GUILayout.Button(content, GUILayout.Width(guiBtnWidth))) //"UnDock"
                    {
                        // close hatches If CLS applies
                        if (SMConditions.IsClsEnabled())
                        {
                            CloseVesselHatches(mdv);
                        }

                        // Decouple/undock selected vessel.
                        UndockSelectedVessel(mdv);
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && _canShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, scrollX);
                    }
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, mdv,
                                                       Event.current.mousePosition);
                    }

                    GUI.enabled = true;
                    if (mdv.IsEditing)
                    {
                        mdv.RenameVessel = GUILayout.TextField(mdv.RenameVessel, GUILayout.Width(guiLabelWidth - (guiBtnWidth + 5)));
                    }
                    else
                    {
                        GUILayout.Label($"{mdv.VesselInfo.name}", GUILayout.Width(guiLabelWidth));
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, mdv,
                                                       Event.current.mousePosition);
                    }

                    // now editing buttons.
                    content = mdv.IsEditing ? new GUIContent(SmUtils.SmTags["#smloc_control_vessel_002"], SmUtils.SmTags["#smloc_control_vessel_tt_002"]) : new GUIContent(SmUtils.SmTags["#smloc_control_vessel_003"], SmUtils.SmTags["#smloc_control_vessel_tt_003"]); // "Save" // "Saves the changes to the docked vessel name." // Edit // "Change the docked vessel name."
                    if (GUILayout.Button(content, GUILayout.Width(50)))
                    {
                        if (SMAddon.SmVessel.DockedVessels[v].IsEditing)
                        {
                            mdv.VesselInfo.name = mdv.RenameVessel;
                            mdv.RenameVessel    = null;
                            mdv.IsEditing       = false;
                        }
                        else
                        {
                            mdv.IsEditing    = true;
                            mdv.RenameVessel = SMAddon.SmVessel.DockedVessels[v].VesselInfo.name;
                        }
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && _canShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, scrollX);
                    }
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, mdv,
                                                       Event.current.mousePosition);
                    }

                    if (mdv.IsEditing)
                    {
                        GUIContent cancelContent = new GUIContent(SmUtils.SmTags["#smloc_control_vessel_004"], SmUtils.SmTags["#smloc_control_vessel_tt_004"]); // "Cancel","Cancel changes to docked vessel name"
                        if (GUILayout.Button(cancelContent, GUILayout.Width(guiBtnWidth)))
                        {
                            mdv.RenameVessel = null;
                            mdv.IsEditing    = false;
                        }
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && _canShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, scrollX);
                    }
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, mdv,
                                                       Event.current.mousePosition);
                    }
                    GUILayout.EndHorizontal();
                }
                // update static count for control window action buttons.
                CombineVesselCount = combineVesselcount;
                // Display MouseOverHighlighting, if any
                SMHighlighter.MouseOverHighlight();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in Vessels Tab at step {step}.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                    SmUtils.LogType.Error, true);
            }
            GUI.enabled = true;
            GUILayout.EndVertical();
        }