示例#1
0
    internal static SMController GetInstance(Vessel vessel)
    {
      foreach (var kvp in controllers.ToArray())
      {
        var wr = kvp.Key;
        var v = wr.Target;
        if (v == null)
        {
          controllers.Remove(wr);
        }
        else if (v == vessel)
        {
          return controllers[wr];
        }
      }

      var commander = new SMController();
      controllers[new WeakReference<Vessel>(vessel)] = commander;
      return commander;
    }
        internal static SMController GetInstance(Vessel vessel)
        {
            foreach (var kvp in controllers.ToArray())
            {
                var wr = kvp.Key;
                var v  = wr.Target;
                if (v == null)
                {
                    controllers.Remove(wr);
                }
                else if (v == vessel)
                {
                    return(controllers[wr]);
                }
            }

            var commander = new SMController();

            controllers[new WeakReference <Vessel>(vessel)] = commander;
            return(commander);
        }
示例#3
0
    internal void Update()
    {
      try
      {
        CheckForToolbarTypeToggle();

        if (HighLogic.LoadedScene == GameScenes.FLIGHT)
        {
          if (FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null)
          {
            //Instantiate the controller for the active vessel.
            smController = SMController.GetInstance(vessel);
            SMHighlighter.Update_Highlighter();

            // Realism Mode Resource transfer operation (real time)
            // XferOn is flagged in the Resource Controller
            if (TransferResource.ResourceXferActive)
            {
              TransferResource.ResourceTransferProcess();
            }

            // Realism Mode Crew transfer operation (real time)
            if (smController.CrewTransfer.CrewXferActive)
              smController.CrewTransfer.CrewTransferProcess();
            else if (smController.CrewTransfer.IsStockXfer)
            {
              TransferCrew.RevertCrewTransfer(smController.CrewTransfer.FromCrewMember, smController.CrewTransfer.FromPart, smController.CrewTransfer.ToPart);
              smController.CrewTransfer.CrewTransferBegin(smController.CrewTransfer.FromCrewMember, smController.CrewTransfer.FromPart, smController.CrewTransfer.ToPart);
            }

            if (SMSettings.EnableOnCrewTransferEvent && TransferCrew.FireSourceXferEvent)
            {
              // Now let's deal with third party mod support...
              TransferCrew.FireSourceXferEvent = false;
              GameEvents.onCrewTransferred.Fire(TransferCrew.SourceAction);

              //If a swap, we need to handle that too...
              if (TransferCrew.FireTargetXferEvent)
              {
                TransferCrew.FireTargetXferEvent = false;
                GameEvents.onCrewTransferred.Fire(TransferCrew.TargetAction);
              }
            }
          }
        }
      }
      catch (Exception ex)
      {
        if (!frameErrTripped)
        {
          Utilities.LogMessage(string.Format(" in Update (repeating error).  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
          frameErrTripped = true;
        }
      }
    }
示例#4
0
    internal void Start()
    {
      Utilities.LogMessage("SMAddon.Start.", "Info", SMSettings.VerboseLogging);
      try
      {
        // Reset frame error latch if set
        if (frameErrTripped)
          frameErrTripped = false;

        if (WindowRoster.resetRosterSize)
          if (SMSettings.UseUnityStyle)
            WindowRoster.Position.height = 330; //reset hight
          else
            WindowRoster.Position.height = 350; //reset hight

        if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
        {
          if (GetCLSAddon())
          {
            SMSettings.CLSInstalled = true;
          }
          else
          {
            SMSettings.EnableCLS = false;
            SMSettings.CLSInstalled = false;
          }
          // reset any hacked kerbal names in game save from old version of SM/KSP
          if (SMSettings.RenameWithProfession)
            WindowRoster.ResetKerbalNames();

          SMSettings.SaveSettings();
          //RunSave();
        }

        if (HighLogic.LoadedScene == GameScenes.FLIGHT)
        {
          // Instantiate Event handlers
          GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested);
          GameEvents.onVesselChange.Add(OnVesselChange);
          GameEvents.onPartDie.Add(OnPartDie);
          GameEvents.onPartExplode.Add(OnPartExplode);
          GameEvents.onPartUndock.Add(OnPartUndock);
          GameEvents.onStageSeparation.Add(OnStageSeparation);
          GameEvents.onUndock.Add(OnUndock);
          GameEvents.onVesselCreate.Add(OnVesselCreate);
          GameEvents.onVesselDestroy.Add(OnVesselDestroy);
          GameEvents.onVesselWasModified.Add(OnVesselWasModified);
          GameEvents.onVesselChange.Add(OnVesselChange);
          GameEvents.onVesselLoaded.Add(OnVesselLoaded);
          GameEvents.onVesselTerminated.Add(OnVesselTerminated);
          GameEvents.onFlightReady.Add(OnFlightReady);
          GameEvents.onCrewTransferred.Add(OnCrewTransferred);
          GameEvents.onShowUI.Add(OnShowUI);
          GameEvents.onHideUI.Add(OnHideUI);


          // get the current Vessel data
          vessel = FlightGlobals.ActiveVessel;
          smController = SMController.GetInstance(vessel);

          // Is CLS installed and enabled?
          if (GetCLSAddon())
          {
            SMSettings.CLSInstalled = true;
            SMSettings.SaveSettings();
            //RunSave();
            UpdateCLSSpaces();
          }
          else
          {
            Utilities.LogMessage("Start - CLS is not installed.", "Info", SMSettings.VerboseLogging);
            SMSettings.EnableCLS = false;
            SMSettings.CLSInstalled = false;
            SMSettings.SaveSettings();
            //RunSave();
          }
          Utilities.LogMessage("CLS Installed?  " + SMSettings.CLSInstalled.ToString(), "Info", SMSettings.VerboseLogging);
        }
      }
      catch (Exception ex)
      {
        Utilities.LogMessage("Error in:  ShipManifestAddon.Start.  " + ex.ToString(), "Error", true);
      }
    }
示例#5
0
    internal void UpdateSMcontroller(Vessel newVessel)
    {
      try
      {
        SMHighlighter.ClearResourceHighlighting(smController.SelectedResourcesParts);
        if (vessel != newVessel)
        {
          if (smController.CrewTransfer.CrewXferActive && !smController.CrewTransfer.IvaDelayActive)
            smController.CrewTransfer.CrewTransferAbort();
          if (TransferResource.ResourceXferActive && SMSettings.RealismMode)
            TransferResource.ResourceTransferAbort();
        }

        if (vessel != null && SMAddon.CanShowShipManifest(false))
        {
          if (newVessel.isEVA && !vessel.isEVA)
          {
            if (WindowManifest.ShowWindow == true)
              OnSMButtonToggle();

            // kill selected resource and its associated highlighting.
            smController.SelectedResources.Clear();
            Utilities.LogMessage("New Vessel is a Kerbal on EVA.  ", "Info", SMSettings.VerboseLogging);
          }
        }

        // Now let's update the current vessel view...
        vessel = newVessel;
        smController = SMController.GetInstance(vessel);
        smController.RefreshLists();
      }
      catch (Exception ex)
      {
        Utilities.LogMessage("Error in:  ShipManifestAddon.UpdateSMcontroller.  " + ex.ToString(), "Error", true);
      }
    }
        private static void RosterListViewer()
        {
            try
            {
                ScrollViewerPosition = GUILayout.BeginScrollView(ScrollViewerPosition, GUILayout.Height(200), GUILayout.Width(400));
                GUILayout.BeginVertical();

                foreach (ProtoCrewMember kerbal in HighLogic.CurrentGame.CrewRoster.Crew)
                {
                    GUIStyle labelStyle = null;
                    if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Dead || kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Missing)
                    {
                        labelStyle = SMStyle.LabelStyleRed;
                    }
                    else if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        labelStyle = SMStyle.LabelStyleYellow;
                    }
                    else
                    {
                        labelStyle = SMStyle.LabelStyle;
                    }

                    // What vessel is this Kerbal Assigned to?
                    string vesselName = "";
                    if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        foreach (Vessel thisVessel in FlightGlobals.Vessels)
                        {
                            List <ProtoCrewMember> crew = thisVessel.GetVesselCrew();
                            foreach (ProtoCrewMember crewMember in crew)
                            {
                                if (crewMember == kerbal)
                                {
                                    vesselName = "\r\n  -  " + thisVessel.name.Replace("(unloaded)", "");
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // Since the kerbal has no vessel assignment, lets show what their status is instead...
                        vesselName = "\r\n  -  " + kerbal.rosterStatus;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(string.Format("{0}{1}", kerbal.name + ", (" + kerbal.experienceTrait.Title + ")", vesselName), labelStyle, GUILayout.Width(230), GUILayout.Height(10));  // + "  (" + kerbal.seat.vessel.name + ")"
                    string buttonText    = string.Empty;
                    string buttonToolTip = string.Empty;

                    if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Available)
                    {
                        GUI.enabled = true;
                    }
                    else
                    {
                        GUI.enabled = false;
                    }

                    buttonText = (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal) ? "Edit" : "Cancel";
                    if (GUI.enabled)
                    {
                        buttonToolTip = (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal) ? "Edit this Kerbal's characteristics" : "Cancel any changes to this Kerbal";
                    }
                    else
                    {
                        buttonToolTip = "Kerbal is not available at this time.\r\nEditing is disabled";
                    }

                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(60)))
                    {
                        if (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal)
                        {
                            SelectedKerbal = new ModKerbal(kerbal, false);
                            SetProfessionFlag();
                        }
                        else
                        {
                            SelectedKerbal = null;
                        }
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips == true)
                    {
                        ToolTip = Utilities.SetActiveTooltip(rect, Settings.RosterPosition, GUI.tooltip, ref ToolTipActive, 30, 20 - ScrollViewerPosition.y);
                    }

                    if (HighLogic.LoadedScene != GameScenes.SPACECENTER && ((Settings.RealismMode && SMAddon.smController.IsPreLaunch) || !Settings.RealismMode) && kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Available && SMAddon.smController.SelectedPartsSource.Count > 0 && !SMController.CrewPartIsFull(SMAddon.smController.SelectedPartsSource[0]))
                    {
                        GUI.enabled   = true;
                        buttonText    = "Add";
                        buttonToolTip = "Adds a kerbal to the Selected Source Part,\r\nin the first available seat.";
                    }
                    else if (kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Dead || kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Missing)
                    {
                        GUI.enabled   = true;
                        buttonText    = "Respawn";
                        buttonToolTip = "Brings a Kerbal back to life.\r\nWill then become available.";
                    }
                    else if (HighLogic.LoadedScene != GameScenes.SPACECENTER && ((Settings.RealismMode && SMAddon.smController.IsPreLaunch) || !Settings.RealismMode) && kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Assigned && FlightGlobals.ActiveVessel.GetVesselCrew().Contains(kerbal))
                    {
                        GUI.enabled   = true;
                        buttonText    = "Remove";
                        buttonToolTip = "Removes a Kerbal from the active vessel.\r\nWill then become available.";
                    }
                    else if (HighLogic.LoadedScene != GameScenes.SPACECENTER && ((Settings.RealismMode && SMAddon.smController.IsPreLaunch) || !Settings.RealismMode) && kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Available && SMAddon.smController.SelectedPartsSource.Count == 0)
                    {
                        GUI.enabled   = false;
                        buttonText    = "Add";
                        buttonToolTip = "Add Disabled.  No source part is selected.\r\nTo add a Kerbal, Select a Source Part with an available seat.";
                    }
                    else if (HighLogic.LoadedScene != GameScenes.SPACECENTER && (Settings.RealismMode && !SMAddon.smController.IsPreLaunch) && kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Available)
                    {
                        GUI.enabled   = false;
                        buttonText    = "Add";
                        buttonToolTip = "Add Disabled.  Realism Settings are preventing this action.\r\nTo add a Kerbal, Change your realism Settings.";
                    }
                    else
                    {
                        GUI.enabled   = false;
                        buttonText    = "--";
                        buttonToolTip = "Kerbal is not available (" + kerbal.rosterStatus + ").\r\nCurrent status does not allow any action.";
                    }

                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(60)))
                    {
                        if (buttonText == "Add")
                        {
                            SMController.AddCrewMember(kerbal, SMAddon.smController.SelectedPartsSource[0]);
                        }
                        else if (buttonText == "Respawn")
                        {
                            SMController.RespawnKerbal(kerbal);
                        }
                        else if (buttonText == "Remove")
                        {
                            // get part...
                            Part part = SMAddon.smController.FindKerbalPart(kerbal);
                            if (part != null)
                            {
                                SMController.RemoveCrewMember(kerbal, part);
                            }
                        }
                    }
                    Rect rect2 = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips == true)
                    {
                        ToolTip = Utilities.SetActiveTooltip(rect2, Settings.RosterPosition, GUI.tooltip, ref ToolTipActive, 30, 20 - ScrollViewerPosition.y);
                    }
                    GUILayout.EndHorizontal();
                    GUI.enabled = true;
                }

                GUILayout.EndVertical();
                GUILayout.EndScrollView();
            }
            catch (Exception ex)
            {
                Utilities.LogMessage(string.Format(" in RosterListViewer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
            }
        }