internal void changeWheelState(KSPWheelState newState, bool selfCallback = false) { if (controller != null) { controller.changeWheelState(newState, this, selfCallback); } }
private void updateDisplayState() { KSPWheelState wheelState = controller.wheelState; KSPWheelWearType wearType = HighLogic.CurrentGame.Parameters.CustomParams <KSPWheelSettings>().wearType; Events[nameof(repairWheel)].guiActiveUnfocused = wheelState == KSPWheelState.BROKEN || wearType == KSPWheelWearType.ADVANCED; Fields[nameof(loadStress)].guiActive = wearType != KSPWheelWearType.NONE; Fields[nameof(stressTime)].guiActive = wearType != KSPWheelWearType.NONE; Fields[nameof(displayStatus)].guiActive = wearType != KSPWheelWearType.NONE; Fields[nameof(wheelWear)].guiActive = wearType == KSPWheelWearType.ADVANCED; Fields[nameof(motorWear)].guiActive = wearType == KSPWheelWearType.ADVANCED; Fields[nameof(suspensionWear)].guiActive = wearType == KSPWheelWearType.ADVANCED; Fields[nameof(maxSafeSpeed)].guiActive = Fields[nameof(maxSafeSpeed)].guiActiveEditor = wearType != KSPWheelWearType.NONE; Fields[nameof(maxSafeLoad)].guiActive = Fields[nameof(maxSafeLoad)].guiActiveEditor = wearType != KSPWheelWearType.NONE; switch (wheelState) { case KSPWheelState.RETRACTED: case KSPWheelState.RETRACTING: case KSPWheelState.DEPLOYED: case KSPWheelState.DEPLOYING: displayStatus = "Operational"; break; case KSPWheelState.BROKEN: displayStatus = "Broken"; break; default: break; } }
/// <summary> /// Should be called every Update() frame from PartModule; updates current internal 'playing' state and issues callback to PartModule when animation state changes (transition from deploying to deployed, retracting to retracted) /// </summary> public void updateAnimationState() { animTime = 0f; if (currentAnimState == KSPWheelState.RETRACTING || currentAnimState == KSPWheelState.DEPLOYING) { bool playing = false; int len = animationData.Count; AnimationData data; for (int i = 0; i < len; i++) { data = animationData[i]; if (data.updateAnimations()) { playing = true; } if (data.time > animTime) { animTime = data.time; } } //if no longer playing, set the new animation state and inform the callback of the change if (!playing) { KSPWheelState newState = currentAnimState == KSPWheelState.RETRACTING ? KSPWheelState.RETRACTED : KSPWheelState.DEPLOYED; setToAnimationState(newState, true); } } }
public WheelAnimationHandler(KSPWheelDeployment module, string animationName, float animationSpeed, int animationLayer, KSPWheelState initialState, bool invertAnimation) { this.module = module; this.currentAnimState = initialState; this.invertAnimation = invertAnimation; this.animationData.Add(new AnimationData(module.part, animationName, animationSpeed, animationLayer)); }
public void setToAnimationState(KSPWheelState state, bool callback) { switch (state) { case KSPWheelState.RETRACTING: { setAnimSpeedMult(-1f); if (currentAnimState == KSPWheelState.DEPLOYED) //enforce play backwards from end { setAnimTime(1f); } playAnimation(); break; } case KSPWheelState.DEPLOYING: { setAnimSpeedMult(1f); if (currentAnimState == KSPWheelState.RETRACTED) //enforce play forwards from beginning { setAnimTime(0f); } playAnimation(); break; } case KSPWheelState.DEPLOYED: { setAnimTime(1); setAnimSpeedMult(1); playAnimation(); break; } case KSPWheelState.RETRACTED: { setAnimTime(0); setAnimSpeedMult(-1); playAnimation(); if (wrapMode != WrapMode.Once) { stopAnimation(); } break; } case KSPWheelState.BROKEN: { break; } } this.currentAnimState = state; if (callback) { this.callback.onAnimationStateChanged(state); } }
internal override void onStateChanged(KSPWheelState oldState, KSPWheelState newState) { base.onStateChanged(oldState, newState); tempCollider.enabled = newState == KSPWheelState.RETRACTING || newState == KSPWheelState.DEPLOYING; if (tempCollider.enabled) { CollisionManager.IgnoreCollidersOnVessel(vessel, tempCollider); } }
public WheelAnimationHandler(KSPWheelSubmodule module, string animationName, float animationSpeed, int animationLayer, KSPWheelState initialState, bool invertAnimation, WrapMode wrapMode) { this.module = module; callback = (WheelAnimationCallback)module;//dirty, but whatever... this.currentAnimState = initialState; this.invertAnimation = invertAnimation; this.wrapMode = wrapMode; this.animationData.Add(new AnimationData(module.part, animationName, animationSpeed, animationLayer, wrapMode)); }
/// <summary> /// Callback from animationControl for when an animation transitions from one state to another /// </summary> /// <param name="state"></param> public void onAnimationStateChanged(KSPWheelState state) { changeWheelState(state); if (state == KSPWheelState.RETRACTED) { //TODO reset suspension and steering transforms to neutral? if (lightModule != null) { lightModule.LightsOff(); } if (!string.IsNullOrEmpty(retractEffect)) { part.Effect(retractEffect, 0f); } if (!string.IsNullOrEmpty(retractedEffect)) { part.Effect(retractedEffect, 1f); } if (!string.IsNullOrEmpty(deployEffect)) { part.Effect(deployEffect, 0f); } if (!string.IsNullOrEmpty(deployedEffect)) { part.Effect(deployedEffect, 0f); } } else if (state == KSPWheelState.DEPLOYED) { if (lightModule != null) { lightModule.LightsOn(); } if (!string.IsNullOrEmpty(retractEffect)) { part.Effect(retractEffect, 0f); } if (!string.IsNullOrEmpty(retractedEffect)) { part.Effect(retractedEffect, 0f); } if (!string.IsNullOrEmpty(deployEffect)) { part.Effect(deployEffect, 0f); } if (!string.IsNullOrEmpty(deployedEffect)) { part.Effect(deployedEffect, 1f); } } if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }
public void setToAnimationState(KSPWheelState state, bool callback) { MonoBehaviour.print("setting to internal anim state: " + state + " from current state: " + currentAnimState); switch (state) { case KSPWheelState.RETRACTING: { setAnimSpeed(-1f); if (currentAnimState == KSPWheelState.DEPLOYED) //enforce play backwards from end { setAnimTime(1f); } playAnimation(); break; } case KSPWheelState.DEPLOYING: { setAnimSpeed(1f); if (currentAnimState == KSPWheelState.RETRACTED) //enforce play forwards from beginning { setAnimTime(0f); } playAnimation(); break; } case KSPWheelState.DEPLOYED: { setAnimTime(1); setAnimSpeed(1); playAnimation(); break; } case KSPWheelState.RETRACTED: { setAnimTime(0); setAnimSpeed(-1); playAnimation(); break; } case KSPWheelState.BROKEN: { break; } } this.currentAnimState = state; if (callback) { module.onAnimationStateChanged(state); } }
private void updateWheelMeshes() { KSPWheelState wheelState = controller.wheelState; if (wheelState == KSPWheelState.BROKEN) { if (bustedWheelMeshes != null) { int len = bustedWheelMeshes.Length; for (int i = 0; i < len; i++) { bustedWheelMeshes[i].gameObject.SetActive(true); } if (wheelMeshes != null) { len = wheelMeshes.Length; for (int i = 0; i < len; i++) { wheelMeshes[i].gameObject.SetActive(false); } } } if (wheel != null) { int len = controller.wheelData.Length; for (int i = 0; i < len; i++) { controller.wheelData[i].wheel.angularVelocity = 0f; controller.wheelData[i].wheel.motorTorque = 0f; controller.wheelData[i].wheel.brakeTorque = 0f; } } } else { if (bustedWheelMeshes != null) { int len = bustedWheelMeshes.Length; for (int i = 0; i < len; i++) { bustedWheelMeshes[i].gameObject.SetActive(false); } } if (wheelMeshes != null) { int len = wheelMeshes.Length; for (int i = 0; i < len; i++) { wheelMeshes[i].gameObject.SetActive(true); } } } }
internal override void onStateChanged(KSPWheelState oldState, KSPWheelState newState) { base.onStateChanged(oldState, newState); if (newState == KSPWheelState.DEPLOYING || newState == KSPWheelState.RETRACTING) { enableColliders(); } else { disableColliders(); } }
internal override void onStateChanged(KSPWheelState oldState, KSPWheelState newState) { base.onStateChanged(oldState, newState); if (newState == KSPWheelState.RETRACTING && oldState == KSPWheelState.DEPLOYED && wheel != null) { float comp = wheel.length - wheel.compressionDistance; deployedPosition = comp / wheel.length; } else { deployedPosition = 1f; } }
/// <summary> /// Callback from animationControl for when an animation transitions from one state to another /// </summary> /// <param name="state"></param> public void onAnimationStateChanged(KSPWheelState state) { if (state != KSPWheelState.DEPLOYING) { if (!string.IsNullOrEmpty(effectName)) { part.Effect(effectName, 0f); } } if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }
internal override void onStateChanged(KSPWheelState oldState, KSPWheelState newState) { base.onStateChanged(oldState, newState); if (newState == KSPWheelState.DEPLOYED) { if (animationControl.state != KSPWheelState.DEPLOYED) { animationControl.setToAnimationState(KSPWheelState.DEPLOYED, false); } } else { if (!string.IsNullOrEmpty(effectName)) { part.Effect(effectName, 0f); } animationControl.setToAnimationState(KSPWheelState.RETRACTED, false); } }
/// <summary> /// Checks for AND CONSUMES resources for change to the specified state. /// </summary> /// <param name="state"></param> /// <returns></returns> private bool checkResourceUse(KSPWheelState state) { if (state == KSPWheelState.DEPLOYING && useResourceDeploy && !string.IsNullOrEmpty(deployResourceName) && deployResourceCost > 0) { double used = part.RequestResource(deployResourceName, (double)deployResourceCost); if (used < deployResourceCost)//if not sufficient, return it to the part { part.RequestResource(deployResourceName, -used); return(false); } return(true); } else if (state == KSPWheelState.RETRACTING && useResourceRetract && !string.IsNullOrEmpty(retractResourceName) && retractResourceCost > 0) { double used = part.RequestResource(retractResourceName, (double)retractResourceCost); if (used < retractResourceCost)//if not sufficient, return it to the part { part.RequestResource(retractResourceName, -used); return(false); } return(true); } return(true); }
internal virtual void onStateChanged(KSPWheelState oldState, KSPWheelState newState) { }