示例#1
0
        internal static SMVessel GetInstance(Vessel vessel)
        {
            foreach (KeyValuePair <WeakReference <Vessel>, SMVessel> kvp in _controllers.ToArray())
            {
                WeakReference <Vessel> wr = kvp.Key;
                Vessel v = wr.Target;
                if (v == null)
                {
                    _controllers.Remove(wr);
                }
                else if (v == vessel)
                {
                    return(_controllers[wr]);
                }
            }

            SMVessel commander = new SMVessel();

            _controllers[new WeakReference <Vessel>(vessel)] = commander;
            return(commander);
        }
示例#2
0
        internal static SMVessel GetInstance(Vessel vessel)
        {
            foreach (KeyValuePair<WeakReference<Vessel>, SMVessel> kvp in _controllers.ToArray())
              {
            WeakReference<Vessel> wr = kvp.Key;
            Vessel v = wr.Target;
            if (v == null)
            {
              _controllers.Remove(wr);
            }
            else if (v == vessel)
            {
              return _controllers[wr];
            }
              }

              SMVessel commander = new SMVessel();
              _controllers[new WeakReference<Vessel>(vessel)] = commander;
              return commander;
        }
示例#3
0
        internal void UpdateSMcontroller(Vessel newVessel)
        {
            try
              {
            SMHighlighter.ClearResourceHighlighting(SmVessel.SelectedResourcesParts);
            if (SmVessel.Vessel != newVessel)
            {
              if (SmVessel.TransferCrewObj.CrewXferActive && !SmVessel.TransferCrewObj.IvaDelayActive)
            SmVessel.TransferCrewObj.CrewTransferAbort();
              if (TransferPump.PumpProcessOn) TransferPump.PumpProcessOn = false;
            }

            if (SmVessel.Vessel != null && SMConditions.CanShowShipManifest())
            {
              if (newVessel.isEVA && !SmVessel.Vessel.isEVA)
              {
            if (WindowManifest.ShowWindow) OnSmButtonClicked();

            // kill selected resource and its associated highlighting.
            SmVessel.SelectedResources.Clear();
              }

            }

            // Now let's update the current vessel view...
            SmVessel = SMVessel.GetInstance(newVessel);
            SmVessel.RefreshLists();
              }
              catch (Exception ex)
              {
            Utilities.LogMessage("Error in:  SMAddon.UpdateSMcontroller.  " + ex, Utilities.LogType.Error, true);
              }
        }
示例#4
0
        internal void Start()
        {
            try
              {
            // Reset frame error latch if set
            if (FrameErrTripped)
              FrameErrTripped = false;

            if (WindowRoster.ResetRosterSize)
              WindowRoster.Position.height = SMSettings.UseUnityStyle ? 330 : 350;

            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.EnableChangeProfession)
            WindowRoster.ResetKerbalNames();

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

            if (HighLogic.LoadedScene != GameScenes.FLIGHT) return;
            // Instantiate Event handlers
            GameEvents.onCrewTransferPartListCreated.Add(OnCrewTransferPartListCreated);
            GameEvents.onCrewTransferSelected.Add(OnCrewTransferSelected);
            GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested);
            GameEvents.onVesselChange.Add(OnVesselChange);
            GameEvents.onVesselWasModified.Add(OnVesselWasModified);
            GameEvents.onVesselChange.Add(OnVesselChange);
            GameEvents.onVesselLoaded.Add(OnVesselLoaded);
            GameEvents.onShowUI.Add(OnShowUi);
            GameEvents.onHideUI.Add(OnHideUi);

            // get the current Vessel data
            SmVessel = SMVessel.GetInstance(FlightGlobals.ActiveVessel);

            // Is CLS installed and enabled?
            if (GetClsAddon())
            {
              SMSettings.ClsInstalled = true;
              SMSettings.SaveSettings();
              UpdateClsSpaces();
            }
            else
            {
              SMSettings.EnableCls = false;
              SMSettings.ClsInstalled = false;
              SMSettings.SaveSettings();
            }

            // Support for DeepFreeze
            //Trigger Update to check and initialize the DeepFreeze Wrapper API
            SceneChangeInitDfWrapper = true;

            // Load sounds for transfers.
            SMSound.LoadSounds();
              }
              catch (Exception ex)
              {
            Utilities.LogMessage("Error in:  SMAddon.Start.  " + ex, Utilities.LogType.Error, true);
              }
        }