示例#1
0
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (!moving)
            {
                return;
            }

            if (scalar >= 0.95f)
            {
                if (oneShot)
                {
                    isLocked = true;
                }

                moving = false;
                deployEvent();
                onStop.Fire(anim[animationName].normalizedTime);
            }
            else if (scalar <= 0.05f)
            {
                isLocked = false;
                moving   = false;
                retractEvent();
                onStop.Fire(anim[animationName].normalizedTime);
            }
        }
示例#2
0
 private void FlightReadyHandler()
 {
     if (sceneChangeEvent != null)
     {
         sceneChangeEvent.Fire(OutboundPackets.SceneChange, 0x00);
     }
 }
示例#3
0
        protected virtual void OnVesselWasModified(Vessel vessel)
        {
            LoggingUtil.LogDebug(this, "OnVesselWasModified: " + vessel.id);
            vessel.GetHashes().Count();

            // Check for a vessel creation after a part joint break
            if (HighLogic.LoadedScene != GameScenes.FLIGHT || lastBreak == null || vessel == lastBreak)
            {
                LoggingUtil.LogVerbose(this, "    returning, wrong scene or wrong vessel...");
                return;
            }

            IEnumerable <uint> otherVesselHashes = lastBreak.GetHashes();
            IEnumerable <uint> vesselHashes      = vessel.GetHashes();

            // OnVesselWasModified gets called twice, on the first call the vessels are still
            // connected.  Check for that case.
            if (vesselModifiedCallCount++ == 0)
            {
                LoggingUtil.LogVerbose(this, "    first call check");
                // The second call will be for the original vessel.  Swap over to check that one.
                lastBreak = vessel;
                return;
            }

            // Get the keys we will be looking at
            List <string> vesselKeys      = GetAssociatedKeys(vessel).ToList();
            List <string> otherVesselKeys = GetAssociatedKeys(lastBreak).ToList();

            // Check the lists and see if we need to do a switch
            foreach (string key in vesselKeys)
            {
                // Check if we need to switch over to the newly created vessel
                VesselInfo vi = vessels[key];
                if (otherVesselHashes.Contains(vi.hash))
                {
                    LoggingUtil.LogDebug(this, "Moving association for '" + key + "' from " + vi.id + " to " + lastBreak.id);
                    vi.id = lastBreak.id;
                    OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(lastBreak, key));
                }
            }
            foreach (string key in otherVesselKeys)
            {
                // Check if we need to switch over to the newly created vessel
                VesselInfo vi = vessels[key];
                if (vesselHashes.Contains(vi.hash))
                {
                    LoggingUtil.LogDebug(this, "Moving association for '" + key + "' from " + vi.id + " to " + vessel.id);
                    vi.id = vessel.id;
                    OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(vessel, key));
                }
            }

            lastBreak = null;
        }
        private void UpdateFSM()
        {
            switch (deployState)
            {
            case DeployState.EXTENDED:
                SetDragCubeWeight(1f);
                break;

            case DeployState.RETRACTED:
                SetDragCubeWeight(0f);
                break;

            case DeployState.EXTENDING:
                if (anim[animationName].normalizedTime >= 1.0)
                {
                    anim.Stop(animationName);
                    deployState = DeployState.EXTENDED;
                    part.ScheduleSetCollisionIgnores();
                    onAnimationStop.Fire(1f);
                    savedAnimationTime            = 1.0f;
                    Events["RetractEvent"].active = true;
                    statusDisplay = Localizer.Format("#LOC_B10_MMSEV_Status_Extended");
                }
                else
                {
                    statusDisplay = Localizer.Format("#LOC_B10_MMSEV_Status_Extending");
                }
                SetDragCubeWeight(1f - anim[animationName].normalizedTime);
                break;

            case DeployState.RETRACTING:
                if (anim[animationName].normalizedTime <= 0.0)
                {
                    anim.Stop(animationName);
                    deployState = DeployState.RETRACTED;
                    part.ScheduleSetCollisionIgnores();
                    Events["ExtendEvent"].active = true;
                    onAnimationStop.Fire(0f);
                    savedAnimationTime = 0.0f;
                    statusDisplay      = Localizer.Format("#LOC_B10_MMSEV_Status_Retracted");
                }
                else
                {
                    statusDisplay = Localizer.Format("#LOC_B10_MMSEV_Status_Retracting");
                }
                SetDragCubeWeight(1f - anim[animationName].normalizedTime);
                break;

            case DeployState.BROKEN:
                statusDisplay = Localizer.Format("#LOC_B10_MMSEV_Status_Broken");
                break;
            }
        }
示例#5
0
        protected override void Update()
        {
            base.Update();

            if (HighLogic.LoadedSceneIsFlight)
            {
                if (noScience)
                {
                    Events["CollectDataExternalEvent"].active  = false;
                    Events["ResetExperimentExternal"].active   = false;
                    Events["ResetExperiment"].active           = false;
                    Events["DeployExperiment"].active          = false;
                    Events["DeployExperimentExternal"].active  = false;
                    Events["TransferDataEvent"].active         = false;
                    Events["CleanUpExperimentExternal"].active = false;
                    Deployed = true;
                }

                if (IsDeployed && fullyDeployed)
                {
                    rotating = true;
                    dishRotate();
                }

                if (!fullyDeployed && rotating)
                {
                    spinDishDown();
                }

                if (!moving)
                {
                    return;
                }

                if (scalar >= 0.95f)
                {
                    deployEvent();
                    isLocked = true;
                    moving   = false;
                    onStop.Fire(anim[animationName].normalizedTime);
                }
                else if (scalar <= 0.05f)
                {
                    isLocked = false;
                    moving   = false;
                    retractEvent();
                    onStop.Fire(anim[animationName].normalizedTime);
                }
            }
        }
示例#6
0
 public void LFProvider()
 {
     if (LFChannel != null)
     {
         LFChannel.Fire(OutboundPackets.LiquidFuel, TotalLF);
     }
 }
示例#7
0
        public void TargetProvider()
        {
            try
            {
                if (FlightGlobals.fetch.VesselTarget != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ship_tgtVelocity != null && FlightGlobals.ActiveVessel.targetObject != null)
                {
                    if (FlightGlobals.fetch.VesselTarget.GetTransform() != null && FlightGlobals.ActiveVessel.transform != null)
                    {
                        myTargetInfo.distance = (float)Vector3.Distance(FlightGlobals.fetch.VesselTarget.GetTransform().position, FlightGlobals.ActiveVessel.transform.position);
                        myTargetInfo.velocity = (float)FlightGlobals.ship_tgtVelocity.magnitude;

                        Vector3 targetDirection = FlightGlobals.ActiveVessel.targetObject.GetTransform().position - FlightGlobals.ActiveVessel.transform.position;
                        KerbalSimpitTelemetryProvider.WorldVecToNavHeading(FlightGlobals.ActiveVessel, targetDirection, out myTargetInfo.heading, out myTargetInfo.pitch);

                        KerbalSimpitTelemetryProvider.WorldVecToNavHeading(FlightGlobals.ActiveVessel, FlightGlobals.ship_tgtVelocity, out myTargetInfo.velocityHeading, out myTargetInfo.velocityPitch);
                        if (targetChannel != null)
                        {
                            targetChannel.Fire(OutboundPackets.TargetInfo, myTargetInfo);
                        }
                    }
                }
            }
            catch (NullReferenceException e)
            {
                // Several issues where caused when a target was not set or when switching vessels and some data is set but not all data needed.
                // This catch prevent the provider from stopping to work, but we should investigate if it is still triggered somehow
                Debug.Log("Simpit : Exception raised in TargetProvider");
                Debug.Log(e.Message);
                Debug.Log(e.StackTrace);
            }
        }
        private void Start()
        {
            dialog = gameObject.GetComponentInParent <ExperimentsResultDialog>();

            if (dialog == null)
            {
                Destroy(gameObject);
            }

            if (ScienceRelay.Instance != null)
            {
                if (buttonNext != null)
                {
                    buttonNext.onClick.AddListener(ScienceRelay.Instance.onPageChange);
                }

                if (buttonPrev != null)
                {
                    buttonPrev.onClick.AddListener(ScienceRelay.Instance.onPageChange);
                }

                if (buttonTransfer != null)
                {
                    buttonTransfer.onClick.AddListener(ScienceRelay.Instance.onTransfer);
                }
            }

            onDialogSpawn.Fire(dialog);
        }
 public void ResourceProvider()
 {
     if (resourceChannel != null)
     {
         resourceChannel.Fire(OutboundPackets.TACLSResource, resourceStruct);
     }
 }
        /// <summary>
        /// Creates a permanent link between the given vessel and key.
        /// </summary>
        /// <param name="key">The key to create an association with.</param>
        /// <param name="vessel">The vessel that will be associated with the key</param>
        public void AssociateVessel(string key, Vessel vessel)
        {
            if (vessel != null)
            {
                LoggingUtil.LogVerbose(this, "Associating vessel " + vessel.id + " with key '" + key + "'.");
            }
            else
            {
                LoggingUtil.LogVerbose(this, "Disassociating key '" + key + "'.");
            }

            // First remove whatever was there
            if (vessels.ContainsKey(key))
            {
                Guid   oldVesselId = vessels[key];
                Vessel oldVessel   = FlightGlobals.Vessels.Find(v => v.id == oldVesselId);
                vessels.Remove(key);

                if (oldVessel != null)
                {
                    LoggingUtil.LogVerbose(this, "Firing OnVesselDisassociation.");
                    OnVesselDisassociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(oldVessel, key));
                }
            }

            // Add the new vessel
            if (vessel != null)
            {
                vessels[key] = vessel.id;
                LoggingUtil.LogVerbose(this, "Firing OnVesselAssociation.");
                OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(vessel, key));
            }
        }
示例#11
0
        IEnumerator WaitAndLoadProgeny(ConfigNode config)
        {
            yield return(null);

            LoadZygotes(config);
            onProgenyScenarioLoaded.Fire(this);
        }
        void FixedUpdate()
        {
            // RemoteTech not yet initialized
            if (RTCore.Instance == null)
            {
                return;
            }

            // Catch up to our start position
            if (mTick < 0)
            {
                mTick++;
                return;
            }

            int i = mTickIndex;

            // Modified logic from RemoteTech.NetworkManager.OnPhysicsUpdate
            var count = RTCore.Instance.Satellites.Count;

            if (count == 0)
            {
                return;
            }
            int baseline  = (count / REFRESH_TICKS);
            int takeCount = baseline + (((mTick++ % REFRESH_TICKS) < (count - baseline * REFRESH_TICKS)) ? 1 : 0);
            IEnumerable <ISatellite> commandStations = RTCore.Instance.Satellites.FindCommandStations();

            foreach (VesselSatellite s in RTCore.Instance.Satellites.Concat(RTCore.Instance.Satellites).Skip(mTickIndex).Take(takeCount))
            {
                // Increment counter for cycling
                i++;

                // RemoteTech didn't do the update - we do it
                if (!s.SignalProcessor.VesselLoaded && HighLogic.LoadedScene != GameScenes.TRACKSTATION)
                {
                    // Each vessel gets refreshed every UNLOADED_REFRESH_CYCLE passes - but spread
                    // out the vessels across the cycles.
                    if ((i + mCycle) % UNLOADED_REFRESH_CYCLE == 0)
                    {
                        RTCore.Instance.Network.FindPath(s, commandStations);
                    }
                    else
                    {
                        // Don't fire the event
                        continue;
                    }
                }

                // Fire our event
                LoggingUtil.LogVerbose(this, "OnRemoteTechUpdate: " + s);
                OnRemoteTechUpdate.Fire(s);
            }
            mTickIndex += takeCount;
            if (mTickIndex >= RTCore.Instance.Satellites.Count)
            {
                mCycle++;
            }
            mTickIndex = mTickIndex % RTCore.Instance.Satellites.Count;
        }
 internal void RemoveSite(SurveySite site)
 {
     if (sites.ContainsKey(site.BodyName))
     {
         sites[site.BodyName].RemoveSite(site);
     }
     onSiteRemoved.Fire(site);
 }
示例#14
0
 public void AltitudeProvider()
 {
     myAlt.alt     = (float)FlightGlobals.ActiveVessel.altitude;
     myAlt.surfalt = (float)FlightGlobals.ActiveVessel.radarAltitude;
     if (altitudeChannel != null)
     {
         altitudeChannel.Fire(OutboundPackets.Altitude, myAlt);
     }
 }
        public void Retract()
        {
            if (deployState == DeployState.BROKEN)
            {
                return;
            }

            if (anim != null)
            {
                anim[animationName].speed          = HighLogic.LoadedSceneIsEditor ? -animationSpeed * 10 : -animationSpeed;
                anim[animationName].normalizedTime = 1.0f;
                anim[animationName].enabled        = true;
                anim.Play(animationName);

                deployState = DeployState.RETRACTING;
                Events["RetractEvent"].active = false;
                onAnimationStart.Fire(1f, 0f);
            }
        }
        //Our override OnScienceReceived event.
        //We block all OnScienceReceived from triggering the ProgressTracker where the subject contains: "TarsierSpaceTech.SpaceTelescope"
        private void OnScienceReceived(float amount, ScienceSubject subject, ProtoVessel vessel, bool data3)
        {
            //if (!_block)
            if (!subject.id.Contains("TarsierSpaceTech.SpaceTelescope"))
            {
                ProxyOnScienceReceived.Fire(amount, subject, vessel, data3);
            }

            //_block = false;
        }
示例#17
0
        //Our override OnScienceReceived event.
        //We block all OnScienceReceived from triggering the ProgressTracker where the subject contains: "TarsierSpaceTech.SpaceTelescope"
        private void OnScienceReceived(float amount, ScienceSubject subject, ProtoVessel vessel, bool data3)
        {
            //if (!_block)
            if (!subject.id.Contains("CactEyePlanetary"))
            {
                ProxyOnScienceReceived.Fire(amount, subject, vessel, data3);
            }

            //_block = false;
        }
示例#18
0
        protected void applyPenalties(double snacksMissed, Vessel vessel)
        {
            if (snacksMissed < 0.001)
            {
                return;
            }

            int hungryKerbals = Convert.ToInt32(snacksMissed / SnacksProperties.SnacksPerMeal);
            List <ISnacksPenalty> randomPenalties = new List <ISnacksPenalty>();

            ISnacksPenalty[] penalties;

            //Let player know how many kerbals are hungry
            if (vessel.loaded)
            {
                ScreenMessages.PostScreenMessage(vessel.vesselName + ": " + hungryKerbals + " Kerbals are hungry for snacks.", 5, ScreenMessageStyle.UPPER_LEFT);
            }
            else
            {
                ScreenMessages.PostScreenMessage(vessel.protoVessel.vesselName + ": " + hungryKerbals + " Kerbals are hungry for snacks.", 5, ScreenMessageStyle.UPPER_LEFT);
            }

            //Apply the penalties
            penalties = penaltyHandlers.ToArray();
            for (int index = 0; index < penalties.Length; index++)
            {
                //If we should always apply the penalty then do so
                if (!SnacksProperties.RandomPenaltiesEnabled || penalties[index].AlwaysApply())
                {
                    penalties[index].ApplyPenalty(hungryKerbals, vessel);
                }

                //Add the penalty to the list of random penalties
                else
                {
                    randomPenalties.Add(penalties[index]);
                }
            }

            //If we have random penalties to apply then do so
            if (randomPenalties.Count > 0)
            {
                int penaltyIndex = random.Next(0, randomPenalties.Count);
                if (penaltyIndex == randomPenalties.Count)
                {
                    penaltyIndex = randomPenalties.Count - 1;
                }

                randomPenalties[penaltyIndex].ApplyPenalty(hungryKerbals, vessel);
            }

            //Send the bad news
            onKerbalsMissedMeal.Fire(vessel, hungryKerbals);
        }
示例#19
0
        void Start()
        {
            Debug.Log("UIKerbalsTrigger", "Start");

            GameObject gene = GetComponent <MissionControl>()?.avatarController?.gameObject?.GetChild("instructor_Gene");

            if (gene != null)
            {
                MissionGene.Fire(gene);
            }
        }
 public void MsgProvider()
 {
     if (_msgToSend)
     {
         if (_msgChannel != null)
         {
             _msgChannel.Fire(_channelID, _message);
         }
         _msgToSend    = false;
         _forceSending = false;
     }
 }
示例#21
0
 public void TargetProvider()
 {
     if (FlightGlobals.fetch.VesselTarget != null)
     {
         myTargetInfo.distance = (float)Vector3.Distance(FlightGlobals.fetch.VesselTarget.GetVessel().transform.position, FlightGlobals.ActiveVessel.transform.position);
         myTargetInfo.velocity = (float)FlightGlobals.ship_tgtVelocity.magnitude;
         if (targetChannel != null)
         {
             targetChannel.Fire(OutboundPackets.TargetInfo, myTargetInfo);
         }
     }
 }
示例#22
0
        protected override void Update()
        {
            base.Update();

            if (noScience)
            {
                Events["CollectDataExternalEvent"].active  = false;
                Events["ResetExperimentExternal"].active   = false;
                Events["ResetExperiment"].active           = false;
                Events["DeployExperiment"].active          = false;
                Events["DeployExperimentExternal"].active  = false;
                Events["TransferDataEvent"].active         = false;
                Events["CleanUpExperimentExternal"].active = false;
                Deployed = true;
            }

            if (!moving)
            {
                return;
            }

            if (scalar >= 0.95f)
            {
                if (oneShot)
                {
                    isLocked = true;
                }

                moving = false;
                deployEvent();
                onStop.Fire(anim[animationName].normalizedTime);
            }
            else if (scalar <= 0.05f)
            {
                isLocked = false;
                moving   = false;
                retractEvent();
                onStop.Fire(anim[animationName].normalizedTime);
            }
        }
示例#23
0
        public void TechUnlockEvent(GameEvents.HostTargetAction <RDTech, RDTech.OperationResult> ev)
        {
            //TODO: Check if any of the parts are experimental, if so, do the normal KCT stuff and then set them experimental again
            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }
            if (ev.target == RDTech.OperationResult.Successful)
            {
                KCT_TechItem tech = new KCT_TechItem();
                if (ev.host != null)
                {
                    tech = new KCT_TechItem(ev.host);
                }

                foreach (AvailablePart expt in ev.host.partsPurchased)
                {
                    if (ResearchAndDevelopment.IsExperimentalPart(expt))
                    {
                        KCT_GameStates.ExperimentalParts.Add(expt);
                    }
                }

                //if (!KCT_GameStates.settings.InstantTechUnlock && !KCT_GameStates.settings.DisableBuildTime) tech.DisableTech();
                if (!tech.isInList())
                {
                    if (KCT_PresetManager.Instance.ActivePreset.generalSettings.TechUpgrades)
                    {
                        ScreenMessages.PostScreenMessage("[KCT] Upgrade Point Added!", 4.0f, ScreenMessageStyle.UPPER_LEFT);
                    }

                    if (KCT_PresetManager.Instance.ActivePreset.generalSettings.TechUnlockTimes && KCT_PresetManager.Instance.ActivePreset.generalSettings.BuildTimes)
                    {
                        KCT_GameStates.TechList.Add(tech);
                        foreach (KCT_TechItem techItem in KCT_GameStates.TechList)
                        {
                            techItem.UpdateBuildRate(KCT_GameStates.TechList.IndexOf(techItem));
                        }
                        double timeLeft = tech.BuildRate > 0 ? tech.TimeLeft : tech.EstimatedTimeLeft;
                        ScreenMessages.PostScreenMessage("[KCT] Node will unlock in " + MagiCore.Utilities.GetFormattedTime(timeLeft), 4.0f, ScreenMessageStyle.UPPER_LEFT);
                        onTechQueued.Fire(ev.host);
                    }
                }
                else
                {
                    ResearchAndDevelopment.Instance.AddScience(tech.scienceCost, TransactionReasons.RnDTechResearch);
                    ScreenMessages.PostScreenMessage("[KCT] This node is already being researched!", 4.0f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage("[KCT] It will unlock in " + MagiCore.Utilities.GetFormattedTime((KCT_GameStates.TechList.First(t => t.techID == ev.host.techID)).TimeLeft), 4.0f, ScreenMessageStyle.UPPER_LEFT);
                }
            }
        }
 void Deploy()
 {
     if (!deployed)
     {
         deployed = true;
         if (Anim != null)
         {
             Anim[deployAnimationName].speed   = 1;
             Anim[deployAnimationName].enabled = true;
             Anim.Play(deployAnimationName);
             onMove.Fire(0, 1);
         }
     }
 }
示例#25
0
        public void TechUnlockEvent(GameEvents.HostTargetAction <RDTech, RDTech.OperationResult> ev)
        {
            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                return;
            }
            if (ev.target == RDTech.OperationResult.Successful)
            {
                var tech = new TechItem();
                if (ev.host != null)
                {
                    tech = new TechItem(ev.host);
                }

                if (!tech.IsInList())
                {
                    if (PresetManager.Instance.ActivePreset.GeneralSettings.TechUpgrades)
                    {
                        ScreenMessages.PostScreenMessage("[KCT] Upgrade Point Added!", 4f, ScreenMessageStyle.UPPER_LEFT);
                    }

                    if (PresetManager.Instance.ActivePreset.GeneralSettings.TechUnlockTimes && PresetManager.Instance.ActivePreset.GeneralSettings.BuildTimes)
                    {
                        KCTGameStates.TechList.Add(tech);
                        foreach (TechItem techItem in KCTGameStates.TechList)
                        {
                            techItem.UpdateBuildRate(KCTGameStates.TechList.IndexOf(techItem));
                        }
                        double timeLeft = tech.BuildRate > 0 ? tech.TimeLeft : tech.EstimatedTimeLeft;
                        ScreenMessages.PostScreenMessage($"[KCT] Node will unlock in {MagiCore.Utilities.GetFormattedTime(timeLeft)}", 4f, ScreenMessageStyle.UPPER_LEFT);

                        foreach (AvailablePart ap in ev.host.partsAssigned)
                        {
                            if (Utilities.AddExperimentalPart(ap))
                            {
                                KCTDebug.Log($"{ap.name} added to ExpParts: {ResearchAndDevelopment.IsExperimentalPart(ap)}");
                            }
                        }

                        OnTechQueued.Fire(ev.host);
                    }
                }
                else
                {
                    ResearchAndDevelopment.Instance.AddScience(tech.ScienceCost, TransactionReasons.RnDTechResearch);
                    ScreenMessages.PostScreenMessage("[KCT] This node is already being researched!", 4f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage($"[KCT] It will unlock in {MagiCore.Utilities.GetFormattedTime((KCTGameStates.TechList.First(t => t.TechID == ev.host.techID)).TimeLeft)}", 4f, ScreenMessageStyle.UPPER_LEFT);
                }
            }
        }
示例#26
0
        internal void ModifyStake(Vessel vessel)
        {
            Debug.Log(String.Format("[EL ST] ModifyStake {0} {1}", vessel.vesselName, vessel.mainBody.bodyName));
            string bodyName = vessel.mainBody.bodyName;
            string siteName = vessel.vesselName;

            if (!sites.ContainsKey(bodyName) ||
                !sites[bodyName].Contains(siteName))
            {
                Debug.Log(String.Format("[EL ST] stake not found"));
                return;
            }
            onSiteModified.Fire(sites[bodyName][siteName].FindSite(vessel));
        }
        internal SurveySite AddSite(SurveySite site)
        {
            if (!sites.ContainsKey(site.BodyName))
            {
                sites[site.BodyName] = new SiteBody();
            }
            var s = sites[site.BodyName].AddSite(site);

            // if a different site is returned, the given site was merged into
            // another site rather than added.
            if (s == site)
            {
                onSiteAdded.Fire(site);
            }
            return(s);
        }
示例#28
0
        private bool updateCurrentState()
        {
            byte newState = getGroups();

            if (newState != currentStateBuffer)
            {
                if (AGStateChannel != null)
                {
                    AGStateChannel.Fire(OutboundPackets.ActionGroups, newState);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#29
0
        public void applyVariant(int newIndex, bool fireEvents = false)
        {
            if (variants == null || newIndex < 0 || newIndex > variants.Count - 1)
            {
                return;
            }

            SWVariant variant = variants[variantIndex];

            variant.applyVariant(part, currentMeshSet);

            if (updateSymmetry)
            {
                int            count = part.symmetryCounterparts.Count;
                SWPartVariants partVariant;
                for (int index = 0; index < count; index++)
                {
                    partVariant = part.symmetryCounterparts[index].FindModuleImplementing <SWPartVariants>();
                    partVariant.variantIndex   = variantIndex;
                    partVariant.variantApplied = true;
                    variant = partVariant.variants[variantIndex];
                    variant.applyVariant(part.symmetryCounterparts[index], currentMeshSet);
                }
            }

            if (fireEvents)
            {
                /*
                 * UI_VariantSelector variantSelector = getVariantSelector();
                 *
                 * GameEvents.onVariantApplied.Fire(part, variantSelector.variants[variantIndex]);
                 * if (HighLogic.LoadedSceneIsEditor)
                 *  GameEvents.onEditorVariantApplied.Fire(part, variantSelector.variants[variantIndex]);
                 */

                if (variant.extraInfo.Count > 0)
                {
                    onApplyVariantExtraInfo.Fire(this, variant.name, variant.extraInfo);
                }
            }

            variantApplied = true;
        }
示例#30
0
        /// <summary>
        /// Creates a permanent link between the given vessel and key.
        /// </summary>
        /// <param name="key">The key to create an association with.</param>
        /// <param name="vessel">The vessel that will be associated with the key</param>
        public void AssociateVessel(string key, Vessel vessel)
        {
            // Already associated!
            if (vessel != null && vessels.ContainsKey(key) && vessels[key].id == vessel.id)
            {
                return;
            }
            else if (vessel == null && !vessels.ContainsKey(key))
            {
                return;
            }

            if (vessel != null)
            {
                LoggingUtil.LogVerbose(this, "Associating vessel {0} with key '{1}'.", vessel.id, key);
            }
            else
            {
                LoggingUtil.LogVerbose(this, "Disassociating key '{0}'.", key);
            }

            // First remove whatever was there
            if (vessels.ContainsKey(key))
            {
                Guid   oldVesselId = vessels[key].id;
                Vessel oldVessel   = FlightGlobals.Vessels.Find(v => v != null && v.id == oldVesselId);
                vessels.Remove(key);

                if (oldVessel != null)
                {
                    LoggingUtil.LogVerbose(this, "Firing OnVesselDisassociation.");
                    OnVesselDisassociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(oldVessel, key));
                }
            }

            // Add the new vessel
            if (vessel != null)
            {
                vessels[key] = new VesselInfo(vessel);
                LoggingUtil.LogVerbose(this, "Firing OnVesselAssociation.");
                OnVesselAssociation.Fire(new GameEvents.HostTargetAction <Vessel, string>(vessel, key));
            }
        }