//private void setLaunchEventText()
    //{
    //    if (moveAtLaunch)
    //    {
    //        Events["toggleMoveAtLaunchEvent"].guiName = "Launch on runway";
    //    }
    //    else
    //    {
    //        Events["toggleMoveAtLaunchEvent"].guiName = "Launch in water";
    //    }
    //}

    public override void OnStart(PartModule.StartState state)
    {
        //setLaunchEventText();
        if (HighLogic.LoadedSceneIsFlight)
        {
            windowID        = FSGUIwindowID.getNextID();
            fileNameElement = new PopupElement("Name", "New");
            PopupElement saveButtonElement = new PopupElement(new PopupButton("Save", 0f, savePositionToFile));
            saveButtonElement.buttons.Add(new PopupButton("Cancel", 0f, cancelSave));
            popup = new FSGUIPopup(part, "FSmoveCraftAtLaunch", 0, windowID, FSGUIwindowID.standardRect, "Save Position", fileNameElement);
            popup.sections[0].elements.Add(saveButtonElement);
            popup.showCloseButton   = true;
            popup.useInEditor       = false;
            popup.useInActionEditor = false;
            popup.useInFlight       = true;
        }

        files = Directory.GetFiles(Firespitter.Tools.PlugInDataPath, "*.pos");
    }
示例#2
0
    public override void OnStart(PartModule.StartState state)
    {
        base.OnStart(state);

        if (popupWindowID == 0)
        {
            popupWindowID = FSGUIwindowID.getNextID();
            //Debug.Log("Assigned window ID: " + popupWindowID);
        }

        partTransform = part.FindModelTransform(targetPartObject);
        buildAngleList();

        elementSteerRoll      = new PopupElement("Use roll steering", new PopupButton("Yes", "No", 0f, toggleSteerRoll));
        elementSteerYaw       = new PopupElement("Use yaw steering", new PopupButton("Yes", "No", 0f, toggleSteerYaw));
        elementSteerPitch     = new PopupElement("Use pitch steering", new PopupButton("Yes", "No", 0f, toggleSteerPitch));
        elementSteerPitchType = new PopupElement("Pitch type", new PopupButton("Throttle", "Rotation", 0f, toggleSteerPitchType));
        elementSteerPitchType.buttons.Add(new PopupButton("Front", "Rear", 0f, toggleSteerPitchLocation));

        elementVTOLSteeringMode = new PopupElement("Mode", new PopupButton("Off", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Single", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Double", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Custom", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.titleSize = 30f;

        #region in editor
        if (HighLogic.LoadedSceneIsEditor)
        {
            elementInfoText = new PopupElement("Presets set to 0 are excluded.");
            popup           = new FSGUIPopup(part, "FSVTOLrotator", 0, popupWindowID, new Rect(550f, 200f, 325f, 150f), "VTOL presets", elementInfoText); //FSGUIwindowID.VTOLrotator
            popup.sections[0].elements.Add(new PopupElement("Settings are per engine!"));

            elementTestAngle = new PopupElement(new PopupButton("Use Preset " + selectedListAngle, 100f, testUseAngle));
            popup.sections[0].elements.Add(elementTestAngle);
            elementTestAngle.buttons.Add(new PopupButton("Next", 40f, testNextAngle));
            elementTestAngle.buttons.Add(new PopupButton("Reset", 50f, testReset));

            elementStepSize           = new PopupElement("Step size", stepAngle.ToString());
            elementStepSize.titleSize = 135f;
            elementStepSize.inputSize = 55f;
            popup.sections[0].elements.Add(elementStepSize);

            elementMaxDownAngle           = new PopupElement("Max negative rot.,", maxDownAngle.ToString());
            elementMaxDownAngle.titleSize = 135f;
            elementMaxDownAngle.inputSize = 55f;
            popup.sections[0].elements.Add(elementMaxDownAngle);

            for (int i = 0; i <= 5; i++) // ------------- hard coded ---------------------------
            {
                elementPresets.Add(new PopupElement());
                float presetAngle = 0f;
                if (i < availableAnglesList.Count)
                {
                    presetAngle = availableAnglesList[i];
                }
                elementPresets[i]           = new PopupElement("Preset " + i, presetAngle.ToString());
                elementPresets[i].titleSize = 135f;
                elementPresets[i].inputSize = 55f;
                popup.sections[0].elements.Add(elementPresets[i]);
            }

            popup.sections[0].elements.Add(new PopupElement("--- VTOL steering ---"));
            popup.sections[0].elements.Add(elementVTOLSteeringMode);
            popup.sections[0].elements.Add(elementSteerRoll);
            popup.sections[0].elements.Add(elementSteerYaw);
            popup.sections[0].elements.Add(elementSteerPitch);
            popup.sections[0].elements.Add(elementSteerPitchType);
            updateButtonTexts();

            popup.useInFlight = false;
            popup.useInEditor = true;
            //popup.useInActionEditor = true;
        }
        #endregion

        #region in flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            atmosphericNerf = part.Modules.OfType <FSpropellerAtmosphericNerf>().FirstOrDefault();
            // --- moved the element creation to the top, for use in both editor and flight
            popup = new FSGUIPopup(part, "FSVTOLrotator", 0, popupWindowID, new Rect(500f, 300f, 250f, 100f), "VTOL steering", elementSteerRoll); //FSGUIwindowID.VTOLrotator
            popup.sections[0].elements.Add(elementSteerYaw);
            popup.sections[0].elements.Add(elementSteerPitch);
            popup.sections[0].elements.Add(elementSteerPitchType);

            popup.useInFlight       = true;
            popup.useInActionEditor = false;

            if (VTOLSteeringMode != "Custom")
            {
                updateSteeringSetup(VTOLSteeringMode);
            }
            else
            {
                Events["showPopupEvent"].guiActive = true;
            }

            updateButtonTexts();
        }
        #endregion
    }
示例#3
0
    public override void OnStart(PartModule.StartState state)
    {
        base.OnStart(state);

        if (popupWindowID == 0)
        {
            popupWindowID = FSGUIwindowID.getNextID();
            //Debug.Log("Assigned window ID: " + popupWindowID);
        }

        partTransform = part.FindModelTransform(targetPartObject);
        buildAngleList();

        elementSteerRoll = new PopupElement("Use roll steering", new PopupButton("Yes", "No", 0f, toggleSteerRoll));
        elementSteerYaw = new PopupElement("Use yaw steering", new PopupButton("Yes", "No", 0f, toggleSteerYaw));
        elementSteerPitch = new PopupElement("Use pitch steering", new PopupButton("Yes", "No", 0f, toggleSteerPitch));
        elementSteerPitchType = new PopupElement("Pitch type", new PopupButton("Throttle", "Rotation", 0f, toggleSteerPitchType));
        elementSteerPitchType.buttons.Add(new PopupButton("Front", "Rear", 0f, toggleSteerPitchLocation));

        elementVTOLSteeringMode = new PopupElement("Mode", new PopupButton("Off", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Single", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Double", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.buttons.Add(new PopupButton("Custom", 0f, buttonSetVTOLSteering));
        elementVTOLSteeringMode.titleSize = 30f;

        #region in editor
        if (HighLogic.LoadedSceneIsEditor)
        {
            elementInfoText = new PopupElement("Presets set to 0 are excluded.");
            popup = new FSGUIPopup(part, "FSVTOLrotator", 0, popupWindowID, new Rect(550f, 200f, 325f, 150f), "VTOL presets", elementInfoText); //FSGUIwindowID.VTOLrotator
            popup.sections[0].elements.Add(new PopupElement("Settings are per engine!"));

            elementTestAngle = new PopupElement(new PopupButton("Use Preset " + selectedListAngle, 100f, testUseAngle));
            popup.sections[0].elements.Add(elementTestAngle);
            elementTestAngle.buttons.Add(new PopupButton("Next", 40f, testNextAngle));
            elementTestAngle.buttons.Add(new PopupButton("Reset", 50f, testReset));

            elementStepSize = new PopupElement("Step size", stepAngle.ToString());
            elementStepSize.titleSize = 135f;
            elementStepSize.inputSize = 55f;
            popup.sections[0].elements.Add(elementStepSize);

            elementMaxDownAngle = new PopupElement("Max negative rot.,", maxDownAngle.ToString());
            elementMaxDownAngle.titleSize = 135f;
            elementMaxDownAngle.inputSize = 55f;
            popup.sections[0].elements.Add(elementMaxDownAngle);

            for (int i = 0; i <= 5; i++) // ------------- hard coded ---------------------------
            {
                elementPresets.Add(new PopupElement());
                float presetAngle = 0f;
                if (i < availableAnglesList.Count)
                {
                    presetAngle = availableAnglesList[i];
                }
                elementPresets[i] = new PopupElement("Preset " + i, presetAngle.ToString());
                elementPresets[i].titleSize = 135f;
                elementPresets[i].inputSize = 55f;
                popup.sections[0].elements.Add(elementPresets[i]);
            }

            popup.sections[0].elements.Add(new PopupElement("--- VTOL steering ---"));
            popup.sections[0].elements.Add(elementVTOLSteeringMode);
            popup.sections[0].elements.Add(elementSteerRoll);
            popup.sections[0].elements.Add(elementSteerYaw);
            popup.sections[0].elements.Add(elementSteerPitch);
            popup.sections[0].elements.Add(elementSteerPitchType);
            updateButtonTexts();

            popup.useInFlight = false;
            popup.useInEditor = true;
            //popup.useInActionEditor = true;
        }
        #endregion

        #region in flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            atmosphericNerf = part.Modules.OfType<FSpropellerAtmosphericNerf>().FirstOrDefault();
            // --- moved the element creation to the top, for use in both editor and flight
            popup = new FSGUIPopup(part, "FSVTOLrotator", 0, popupWindowID, new Rect(500f, 300f, 250f, 100f), "VTOL steering", elementSteerRoll); //FSGUIwindowID.VTOLrotator
            popup.sections[0].elements.Add(elementSteerYaw);
            popup.sections[0].elements.Add(elementSteerPitch);
            popup.sections[0].elements.Add(elementSteerPitchType);

            popup.useInFlight = true;
            popup.useInActionEditor = false;

            if (VTOLSteeringMode != "Custom")
            {
                updateSteeringSetup(VTOLSteeringMode);
            }
            else
            {
                Events["showPopupEvent"].guiActive = true;
            }

            updateButtonTexts();
        }
        #endregion
    }
示例#4
0
    public override void OnStart(PartModule.StartState state)
    {
        base.OnStart(state);
        if (popupWindowID == 0)
        {
            popupWindowID = FSGUIwindowID.getNextID();
        }
        firstPresetLine = 1;
        PopupElement element = new PopupElement(new PopupButton("+", 25f, adjustTrimFromButton));

        element.buttons.Add(new PopupButton("-", 25f, adjustTrimFromButton));
        element.buttons.Add(new PopupButton("Add", 43f, addPresetLine));
        element.buttons.Add(new PopupButton("Del", 43f, removePresetLine));
        popup = new FSGUIPopup(part, "FStrimAdjustment", moduleID, popupWindowID, new Rect(100f, 200f, 180f, 150f), axis + " Trim Adjustment", element);//FSGUIwindowID.trimAdjustment + moduleID


        if (HighLogic.LoadedSceneIsEditor)
        {
            //popup.showMenu = true;
            elementShowOnFlightStart           = new PopupElement("Show on Launch?", new PopupButton("Y", "N", 30f, toggleShowOnFlightStart));
            elementShowOnFlightStart.titleSize = 120f;
            popup.sections[0].elements.Add(elementShowOnFlightStart);
            elementShowOnFlightStart.buttons[0].toggle(showOnFlightStart);
            firstPresetLine = 2;
        }
        else
        {
            if (HighLogic.LoadedSceneIsFlight && showOnFlightStart)
            {
                popup.showMenu = true;
            }
            else
            {
                popup.showMenu = false;
            }
        }

        popup.useInFlight = false;
        popup.useInEditor = true;
        //popup.useInActionEditor = true;

        addPresetLine(presetTrim0);
        if (presetTrim1 != 0f)
        {
            addPresetLine(presetTrim1);
        }
        if (presetTrim2 != 0f)
        {
            addPresetLine(presetTrim2);
        }

        if (HighLogic.LoadedSceneIsEditor)
        {
            popup.windowRect.x = 450f;
        }

        Actions["togglePopupAction"].guiName      = "Toggle " + axis + " Popup";
        Actions["usePreset1Action"].guiName       = "Use " + axis + " Preset 1";
        Events["togglePopupEvent"].guiName        = "Toggle " + axis + " Popup";
        Actions["increaseTrimAction"].guiName     = axis + " trim + 1 step";
        Actions["decreaseTrimAction"].guiName     = axis + " trim - 1 step";
        Actions["increaseTrimMoreAction"].guiName = "" + axis + " trim +" + MoreTrimActionMultiplier + " steps";
        Actions["decreaseTrimMoreAction"].guiName = "" + axis + " trim -" + MoreTrimActionMultiplier + " steps";
    }
示例#5
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Log.dbg("FSwheel: Could not set deployment state {0}", deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed     = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed          = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            #region create wheel setup
            List <WheelCollider> colliderList   = new List <WheelCollider>();
            List <Transform>     wheelMeshList  = new List <Transform>();
            List <Transform>     suspensionList = new List <Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                {
                    suffix = "";
                }
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent <WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);

                        Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                        if (wheelMeshTransform != null)
                        {
                            wheelMeshList.Add(wheelMeshTransform);
                        }
                        else
                        {
                            Log.info("FSwheel: missing wheel mesh {0}{1}", wheelMeshName, suffix);
                        }
                        Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                        if (suspensionTransform != null)
                        {
                            suspensionList.Add(suspensionTransform);
                        }
                        else
                        {
                            Log.info("FSwheel: missing suspensionParent {0}{1}", suspensionParentName, suffix);
                        }
                    }
                }
                else
                {
                    Log.info("FSwheel: missing wheel collider {0}{1}", wheelColliderName, suffix);
                }
            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            Log.dbg("FSwheel: wheelist count is {0}", wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Log.info("FSwheel: reversemotorset: {0}", reverseMotorSet);
                if (!reverseMotorSet)                                                                                           //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0)                                                                                                // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        Log.dbg("FSwheel: Reversing motor, dot: {0}", dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        Log.dbg("FSwheel: Motor reversing skipped, dot: {0}", dot);
                    }
                    if (motorStartsReversed)
                    {
                        reverseMotor = !reverseMotor;
                    }
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness       = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip  = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip   = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue  = forwardsExtremumValue;
                wheelList.sidewaysStiffness      = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip  = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip   = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue  = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f)
            {
                wheelList.radius = wheelColliderRadius;
            }
            else
            {
                wheelColliderRadius = wheelList.radius;
            }
            if (wheelColliderMass >= 0f)
            {
                wheelList.mass = wheelColliderMass;
            }
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance)
            {
                wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            }
            else
            {
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;
            }

            #endregion

            #region GUI popup

            popup                           = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
            popup.useInFlight               = true;
            wheelRadiusElement              = new PopupElement("Radius", wheelColliderRadius.ToString());
            suspensionDistanceElement       = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
            suspensionSpringElement         = new PopupElement("Spring", suspensionSpring.ToString());
            suspensionDamperElement         = new PopupElement("Damper", suspensionDamper.ToString());
            suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
            popup.sections[0].elements.Add(wheelRadiusElement);
            popup.sections[0].elements.Add(suspensionDistanceElement);
            popup.sections[0].elements.Add(suspensionSpringElement);
            popup.sections[0].elements.Add(suspensionDamperElement);
            popup.sections[0].elements.Add(suspensionTargetPositionElement);

            suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
            popup.sections[0].elements.Add(suspensionUpdateElement);

            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new Firespitter.FSparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize     = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize     = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy   = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy   = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow   = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion
        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange     = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange     = unfocusedRange;

        Events["EnableMotorEvent"].guiActive        = !motorEnabled;
        Events["DisableMotorEvent"].guiActive       = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor  = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive        = !brakesEngaged;
        Events["brakesOffEvent"].guiActive       = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor  = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive        = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive       = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor  = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused  = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active         = false;
            Events["DisableMotorEvent"].active        = false;
            Events["EnableReverseMotorEvent"].active  = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive    = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive           = false;
            Events["brakesOffEvent"].guiActive          = false;
            Events["brakesOnEvent"].guiActiveUnfocused  = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }
示例#6
0
    public override void OnStart(PartModule.StartState state)
    {
        base.OnStart(state);
        if (popupWindowID == 0)
            popupWindowID = FSGUIwindowID.getNextID();
        firstPresetLine = 1;
        PopupElement element = new PopupElement(new PopupButton("+", 25f, adjustTrimFromButton));
        element.buttons.Add(new PopupButton("-", 25f, adjustTrimFromButton));
        element.buttons.Add(new PopupButton("Add", 43f, addPresetLine));
        element.buttons.Add(new PopupButton("Del", 43f, removePresetLine));
        popup = new FSGUIPopup(part, "FStrimAdjustment", moduleID, popupWindowID, new Rect(100f, 200f, 180f, 150f), axis + " Trim Adjustment", element);//FSGUIwindowID.trimAdjustment + moduleID

        if (HighLogic.LoadedSceneIsEditor)
        {
            //popup.showMenu = true;
            elementShowOnFlightStart = new PopupElement("Show on Launch?", new PopupButton("Y", "N", 30f, toggleShowOnFlightStart));
            elementShowOnFlightStart.titleSize = 120f;
            popup.sections[0].elements.Add(elementShowOnFlightStart);
            elementShowOnFlightStart.buttons[0].toggle(showOnFlightStart);
            firstPresetLine = 2;
        }
        else
        {
            if (HighLogic.LoadedSceneIsFlight && showOnFlightStart)
            {
                popup.showMenu = true;
            }
            else
            {
                popup.showMenu = false;
            }
        }

        popup.useInFlight = false;
        popup.useInEditor = true;
        //popup.useInActionEditor = true;

        addPresetLine(presetTrim0);
        if (presetTrim1 != 0f)
            addPresetLine(presetTrim1);
        if (presetTrim2 != 0f)
            addPresetLine(presetTrim2);

        if (HighLogic.LoadedSceneIsEditor)
        {
            popup.windowRect.x = 450f;
        }

        Actions["togglePopupAction"].guiName = "Toggle " + axis + " Popup";
        Actions["usePreset1Action"].guiName = "Use " + axis + " Preset 1";
        Events["togglePopupEvent"].guiName = "Toggle " + axis + " Popup";
        Actions["increaseTrimAction"].guiName = axis + " trim + 1 step";
        Actions["decreaseTrimAction"].guiName = axis + " trim - 1 step";
        Actions["increaseTrimMoreAction"].guiName = "" + axis + " trim +" + MoreTrimActionMultiplier + " steps";
        Actions["decreaseTrimMoreAction"].guiName = "" + axis + " trim -" + MoreTrimActionMultiplier + " steps";
    }
    //private void setLaunchEventText()
    //{
    //    if (moveAtLaunch)
    //    {
    //        Events["toggleMoveAtLaunchEvent"].guiName = "Launch on runway";
    //    }
    //    else
    //    {
    //        Events["toggleMoveAtLaunchEvent"].guiName = "Launch in water";
    //    }
    //}
    public override void OnStart(PartModule.StartState state)
    {
        //setLaunchEventText();
        if (HighLogic.LoadedSceneIsFlight)
        {
            windowID = FSGUIwindowID.getNextID();
            fileNameElement = new PopupElement("Name", "New");
            PopupElement saveButtonElement = new PopupElement(new PopupButton("Save", 0f, savePositionToFile));
            saveButtonElement.buttons.Add(new PopupButton("Cancel", 0f, cancelSave));
            popup = new FSGUIPopup(part, "FSmoveCraftAtLaunch", 0, windowID, FSGUIwindowID.standardRect, "Save Position", fileNameElement);
            popup.sections[0].elements.Add(saveButtonElement);
            popup.showCloseButton = true;
            popup.useInEditor = false;
            popup.useInActionEditor = false;
            popup.useInFlight = true;
        }

        files = Directory.GetFiles(Firespitter.Tools.PlugInDataPath, "*.pos");
    }
示例#8
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Debug.Log("FSwheel: Could not set deployment state " + deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed = animSpeed;
            anim.Play(animationName);
        }
        #endregion  

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {

            #region create wheel setup
            List<WheelCollider> colliderList = new List<WheelCollider>();
            List<Transform> wheelMeshList = new List<Transform>();
            List<Transform> suspensionList = new List<Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                    suffix = "";
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent<WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);

                        Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                        if (wheelMeshTransform != null)
                        {
                            wheelMeshList.Add(wheelMeshTransform);
                        }
                        else
                        {
                            Debug.Log("FSwheel: missing wheel mesh " + wheelMeshName + suffix);
                        }
                        Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                        if (suspensionTransform != null)
                        {
                            suspensionList.Add(suspensionTransform);
                        }
                        else
                        {
                            Debug.Log("FSwheel: missing suspensionParent " + suspensionParentName + suffix);
                        }
                    }
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel collider " + wheelColliderName + suffix);
                }
            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            //Debug.Log("FSwheel: wheelist count is " + wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Debug.Log("FSwheel: reversemotorset: " + reverseMotorSet);
                if (!reverseMotorSet) //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0) // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        //Debug.Log("FSwheel: Reversing motor, dot: " + dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        //Debug.Log("FSwheel: Motor reversing skipped, dot: " + dot);
                    }
                    if (motorStartsReversed)
                        reverseMotor = !reverseMotor;
                    reverseMotorSet = true;
                }                
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }            

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue = forwardsExtremumValue;
                wheelList.sidewaysStiffness = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f) wheelList.radius = wheelColliderRadius;
            else
                wheelColliderRadius = wheelList.radius;
            if (wheelColliderMass >= 0f) wheelList.mass = wheelColliderMass;
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance) wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            else
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;

            #endregion                     

            #region GUI popup

            popup = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
            popup.useInFlight = true;
            wheelRadiusElement = new PopupElement("Radius", wheelColliderRadius.ToString());
            suspensionDistanceElement = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
            suspensionSpringElement = new PopupElement("Spring", suspensionSpring.ToString());
            suspensionDamperElement = new PopupElement("Damper", suspensionDamper.ToString());
            suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
            popup.sections[0].elements.Add(wheelRadiusElement);
            popup.sections[0].elements.Add(suspensionDistanceElement);
            popup.sections[0].elements.Add(suspensionSpringElement);
            popup.sections[0].elements.Add(suspensionDamperElement);
            popup.sections[0].elements.Add(suspensionTargetPositionElement);
            
            suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
            popup.sections[0].elements.Add(suspensionUpdateElement);

            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {                
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;                    
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new Firespitter.FSparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow = 0.1f;
                        
                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion

        }        

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange = unfocusedRange;

        Events["EnableMotorEvent"].guiActive = !motorEnabled;
        Events["DisableMotorEvent"].guiActive = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive = !brakesEngaged;
        Events["brakesOffEvent"].guiActive = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active = false;
            Events["DisableMotorEvent"].active = false;
            Events["EnableReverseMotorEvent"].active = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive = false;
            Events["brakesOffEvent"].guiActive = false;
            Events["brakesOnEvent"].guiActiveUnfocused = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }
        
        #endregion
    }