Beispiel #1
0
        internal void Update(RPMVesselComputer comp)
        {
            float value;

            if (enablingVariable != null)
            {
                if (!enablingVariable.IsInRange(comp))
                {
                    return;
                }
            }

            if (variable.Get(out value, comp))
            {
                if (useLog10)
                {
                    value = JUtil.PseudoLog10(value);
                }
                float xOffset = JUtil.DualLerp(textureLimit, scale, value);

                MeshFilter meshFilter = barObject.GetComponent <MeshFilter>();

                meshFilter.mesh.uv = new[]
                {
                    new Vector2(xOffset - textureSize, 0.0f),
                    new Vector2(xOffset + textureSize, 0.0f),
                    new Vector2(xOffset - textureSize, 1.0f),
                    new Vector2(xOffset + textureSize, 1.0f)
                };

                JUtil.ShowHide(true, barObject);
            }
        }
        public bool InverseLerp(RPMVesselComputer comp, out float scaledValue)
        {
            float value;
            float low, high;

            if (!(sourceValue.Get(out value, comp) && lowerBound.Get(out low, comp) && upperBound.Get(out high, comp)))
            {
                scaledValue = 0.0f;
                return(false);
            }
            else
            {
                scaledValue = Mathf.InverseLerp(low, high, value);
                return(true);
            }
        }
Beispiel #3
0
        public object Evaluate(RPMVesselComputer comp)
        {
            float lerp, extent1, extent2;

            if (sourceVariable.InverseLerp(comp, out lerp) && mappedExtent1.Get(out extent1, comp) && mappedExtent2.Get(out extent2, comp))
            {
                return(Mathf.Lerp(extent1, extent2, lerp));
            }
            else
            {
                return(0.0f);
            }
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try
            {
                if (string.IsNullOrEmpty(perPodPersistenceName))
                {
                    JUtil.LogErrorMessage(this, "perPodPersistenceName must be defined");
                    return;
                }
                if (string.IsNullOrEmpty(defaultValue))
                {
                    JUtil.LogErrorMessage(this, "defaultValue must be defined");
                    return;
                }

                if (stepSize < 0.0f)
                {
                    stepSize = 0.0f;
                }

                //JUtil.LogMessage(this, "Start(): {0}, {1}, {2}, {3}, {4}", perPodPersistenceName, defaultValue, minValue, maxValue, stepSize);

                if (!string.IsNullOrEmpty(minValue))
                {
                    minRange = VariableOrNumber.Instantiate(minValue);
                    //JUtil.LogMessage(this, "Created lower bound variable");
                }
                if (!string.IsNullOrEmpty(maxValue))
                {
                    maxRange = VariableOrNumber.Instantiate(maxValue);
                    //JUtil.LogMessage(this, "Created upper bound variable");
                }
                if ((minRange == null || maxRange == null) && loopInput == true)
                {
                    JUtil.LogErrorMessage(this, "Overriding loopInput - minValue or maxValue is missing");
                    loopInput = false;
                }

                RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                if (!comp.HasPersistentVariable(perPodPersistenceName))
                {
                    //JUtil.LogMessage(this, "Initializing per pod persistence value {0}", perPodPersistenceName);

                    VariableOrNumber von = VariableOrNumber.Instantiate(defaultValue);
                    float            value;
                    if (von.Get(out value, comp))
                    {
                        if (stepSize > 0.0f)
                        {
                            float remainder = value % stepSize;
                            value -= remainder;
                        }
                        comp.SetPersistentVariable(perPodPersistenceName, value);
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Failed to evaluate default value of {0} for {1}", defaultValue, perPodPersistenceName);
                        return;
                    }
                }

                ConfigNode moduleConfig = null;
                foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP"))
                {
                    if (node.GetValue("name") == internalProp.propName)
                    {
                        moduleConfig = node.GetNodes("MODULE")[moduleID];
                        ConfigNode[] inputNodes = moduleConfig.GetNodes("USERINPUTSET");

                        for (int i = 0; i < inputNodes.Length; i++)
                        {
                            try
                            {
                                numericInputs.Add(new NumericInput(inputNodes[i], internalProp));
                                //JUtil.LogMessage(this, "Added USERINPUTSET {0}", inputNodes[i].GetValue("switchTransform"));
                            }
                            catch (ArgumentException e)
                            {
                                JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
                            }
                        }
                        break;
                    }
                }

                enabled = true;
            }
            catch
            {
                JUtil.AnnoyUser(this);
                enabled = false;
                throw;
            }
        }
Beispiel #5
0
        public void Click()
        {
            bool switchEnabled = true;

            if (!forcedShutdown)
            {
                if (!string.IsNullOrEmpty(perPodMasterSwitchName))
                {
                    switchEnabled = persistence.GetBool(perPodMasterSwitchName, false);
                }
                if (masterVariable != null)
                {
                    RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);
                    float             value, range1, range2;
                    if (masterVariable.Get(out value, comp, persistence) && masterRange[0].Get(out range1, comp, persistence) && masterRange[1].Get(out range2, comp, persistence))
                    {
                        float minR = Mathf.Min(range1, range2);
                        float maxR = Mathf.Max(range1, range2);
                        if (value < minR || value > maxR)
                        {
                            // If the master variable is out of spec, disable the switch.
                            switchEnabled = false;
                        }
                    }
                }
            }
            if (!switchEnabled)
            {
                // If the master switch is 'off' and we're not here because
                // of a forced shutdown, don't allow this switch to work.
                // early return
                return;
            }

            if (isCustomAction)
            {
                if (switchGroupIdentifier >= 0)
                {
                    if (!forcedShutdown && !customGroupList[actionName])
                    {
                        customGroupList[actionName] = true;
                        if (!string.IsNullOrEmpty(persistentVarName))
                        {
                            persistence.SetVar(persistentVarName, switchGroupIdentifier);
                        }
                    }
                    // else: can't turn off a radio group switch.
                }
                else
                {
                    customGroupList[actionName] = !customGroupList[actionName];
                    if (!string.IsNullOrEmpty(persistentVarName))
                    {
                        persistence.SetVar(persistentVarName, customGroupList[actionName]);
                    }
                }
            }
            else
            {
                vessel.ActionGroups.ToggleGroup(groupList[actionName]);
            }
            // Now we do extra things that with regular actions can't happen.
            switch (actionName)
            {
            case "intlight":
                SetInternalLights(customGroupList[actionName]);
                break;

            case "plugin":
                actionHandler((stateHandler != null) ? !stateHandler() : customGroupList[actionName]);
                break;

            case "stage":
                if (InputLockManager.IsUnlocked(ControlTypes.STAGING))
                {
                    Staging.ActivateNextStage();
                }
                break;
            }
        }