Exemple #1
0
        public VariableLabelSet(ConfigNode node, Part part)
        {
            RasterPropMonitorComputer rpmComp = null;

            if (node.HasValue("labelText"))
            {
                string labelText = node.GetValue("labelText").Trim().UnMangleConfigText();
                hasText = true;
                oneShot = !labelText.Contains("$&$");
                rpmComp = RasterPropMonitorComputer.Instantiate(part, true);
                label   = new StringProcessorFormatter(labelText, rpmComp);
            }
            else
            {
                hasText = false;
                oneShot = true;
            }

            if (node.HasValue("color"))
            {
                color    = JUtil.ParseColor32(node.GetValue("color").Trim(), part, ref rpmComp);
                hasColor = true;
            }
            else
            {
                hasColor = false;
            }
        }
        public VariableLabelSet(ConfigNode node)
        {
            if (node.HasValue("labelText"))
            {
                string labelText = node.GetValue("labelText").Trim().UnMangleConfigText();
                hasText = true;
                oneShot = !labelText.Contains("$&$");
                label   = new StringProcessorFormatter(labelText);
            }
            else
            {
                hasText = false;
                oneShot = true;
            }

            if (node.HasValue("color"))
            {
                color    = ConfigNode.ParseColor32(node.GetValue("color").Trim());
                hasColor = true;
            }
            else
            {
                hasColor = false;
            }
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                Transform textObjTransform = internalProp.FindModelTransform(transformName);
                textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, "", Color.green, false, "TopLeft");
                // Force oneshot if there's no variables:
                oneshot |= !labelText.Contains("$&$");
                string sourceString = labelText.UnMangleConfigText();

                if (!string.IsNullOrEmpty(sourceString) && sourceString.Length > 1)
                {
                    // Alow a " character to escape leading whitespace
                    if (sourceString[0] == '"')
                    {
                        sourceString = sourceString.Substring(1);
                    }
                }
                spf = new StringProcessorFormatter(sourceString, rpmComp);

                if (!oneshot)
                {
                    rpmComp.UpdateDataRefreshRate(refreshRate);
                }

                if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
                {
                    positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp);
                    negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp);
                    zeroColorValue     = JUtil.ParseColor32(zeroColor, part, ref rpmComp);
                    del = (Action <float>)Delegate.CreateDelegate(typeof(Action <float>), this, "OnCallback");
                    rpmComp.RegisterVariableCallback(variableName, del);
                    registeredVessel = vessel.id;

                    // Initialize the text color. Actually, callback registration took care of that
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Start failed with exception {0}", e);
                spf = new StringProcessorFormatter("x", rpmComp);
            }
        }
Exemple #4
0
        public void UpdateText(RasterPropMonitorComputer rpmComp)
        {
            // If there's a handler references method, it gets called before each text call.
            if (pageHandlerS.getHandlerReferences != null)
            {
                pageHandlerS.getHandlerReferences(pageHandlerModule, backgroundHandlerModule);
            }

            if (pageHandlerMethod != null)
            {
                processedText = pageHandlerMethod(screenWidth, screenHeight);

                if (processedText.IndexOf("$&$", StringComparison.Ordinal) != -1)
                {
                    // There are processed variables in here?
                    StringBuilder bf         = new StringBuilder();
                    string[]      linesArray = processedText.Split(JUtil.LineSeparator, StringSplitOptions.None);
                    for (int i = 0; i < linesArray.Length; i++)
                    {
                        bf.AppendLine(StringProcessor.ProcessString(linesArray[i], rpmComp));
                    }
                    processedText = bf.ToString();
                }
            }
            else
            {
                if (isMutable)
                {
                    if (spf == null)
                    {
                        string[] linesArray = text.Split(JUtil.LineSeparator, StringSplitOptions.None);
                        spf = new StringProcessorFormatter[linesArray.Length];
                        for (int i = 0; i < linesArray.Length; ++i)
                        {
                            spf[i] = new StringProcessorFormatter(linesArray[i], rpmComp);
                        }
                    }

                    StringBuilder bf = new StringBuilder();
                    for (int i = 0; i < spf.Length; i++)
                    {
                        bf.AppendLine(StringProcessor.ProcessString(spf[i], rpmComp));
                    }

                    processedText = bf.ToString();
                }
            }
        }
        public static string ProcessString(StringProcessorFormatter formatter, RPMVesselComputer comp)
        {
            if (formatter.usesComp)
            {
                for (int i = 0; i < formatter.sourceVariables.Length; ++i)
                {
                    formatter.sourceValues[i] = comp.ProcessVariable(formatter.sourceVariables[i]);
                }

                return(string.Format(formatter.formatString, formatter.sourceValues));
            }
            else
            {
                return(formatter.formatString);
            }
        }
Exemple #6
0
        public void Start()
        {
            RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);

            Transform textObjTransform = internalProp.FindModelTransform(transformName);

            textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty);
            // Force oneshot if there's no variables:
            oneshot |= !labelText.Contains("$&$");
            string sourceString = labelText.UnMangleConfigText();

            // Alow a " character to escape leading whitespace
            if (sourceString[0] == '"')
            {
                sourceString = sourceString.Substring(1);
            }
            spf = new StringProcessorFormatter(sourceString);

            if (!oneshot)
            {
                comp.UpdateDataRefreshRate(refreshRate);
            }

            if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
            {
                positiveColorValue = ConfigNode.ParseColor32(positiveColor);
                negativeColorValue = ConfigNode.ParseColor32(negativeColor);
                zeroColorValue     = ConfigNode.ParseColor32(zeroColor);
                del = (Action <RPMVesselComputer, float>)Delegate.CreateDelegate(typeof(Action <RPMVesselComputer, float>), this, "OnCallback");
                comp.RegisterCallback(variableName, del);

                // Initialize the text color.
                float value = comp.ProcessVariable(variableName).MassageToFloat();
                if (value < 0.0f)
                {
                    textObj.text.Color = negativeColorValue;
                }
                else if (value > 0.0f)
                {
                    textObj.text.Color = positiveColorValue;
                }
                else
                {
                    textObj.text.Color = zeroColorValue;
                }
            }
        }
        public static string ProcessString(StringProcessorFormatter formatter, RasterPropMonitorComputer rpmComp)
        {
            if (formatter.usesComp)
            {
                try
                {
                    RPMVesselComputer comp = RPMVesselComputer.Instance(rpmComp.vessel);
                    for (int i = 0; i < formatter.sourceVariables.Length; ++i)
                    {
                        formatter.sourceValues[i] = formatter.sourceVariables[i].Get();
                    }

                    return string.Format(fp, formatter.formatString, formatter.sourceValues);
                }
                catch(Exception e)
                {
                    JUtil.LogErrorMessage(formatter, "Exception trapped in ProcessString for {1}: {0}", e, formatter.formatString);
                }
            }

            return formatter.formatString;
        }
Exemple #8
0
        public static string ProcessString(StringProcessorFormatter formatter, RasterPropMonitorComputer rpmComp)
        {
            if (formatter.usesComp)
            {
                try
                {
                    RPMVesselComputer comp = RPMVesselComputer.Instance(rpmComp.vessel);
                    for (int i = 0; i < formatter.sourceVariables.Length; ++i)
                    {
                        formatter.sourceValues[i] = formatter.sourceVariables[i].Get();
                    }

                    return(string.Format(fp, formatter.formatString, formatter.sourceValues));
                }
                catch (Exception e)
                {
                    JUtil.LogErrorMessage(formatter, "Exception trapped in ProcessString for {1}: {0}", e, formatter.formatString);
                }
            }

            return(formatter.formatString);
        }
Exemple #9
0
 internal JSILabelSet(string labelText, RasterPropMonitorComputer rpmComp, bool isOneshot)
 {
     oneshot         = isOneshot;
     oneshotComplete = false;
     spf             = new StringProcessorFormatter(labelText, rpmComp);
 }
        public void Start()
        {
            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                Transform textObjTransform = internalProp.FindModelTransform(transformName);
                textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, string.Empty);
                // Force oneshot if there's no variables:
                oneshot |= !labelText.Contains("$&$");
                string sourceString = labelText.UnMangleConfigText();

                if (!string.IsNullOrEmpty(sourceString) && sourceString.Length > 1)
                {
                    // Alow a " character to escape leading whitespace
                    if (sourceString[0] == '"')
                    {
                        sourceString = sourceString.Substring(1);
                    }
                }
                spf = new StringProcessorFormatter(sourceString, rpmComp);

                if (!oneshot)
                {
                    rpmComp.UpdateDataRefreshRate(refreshRate);
                }

                if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
                {
                    positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp);
                    negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp);
                    zeroColorValue = JUtil.ParseColor32(zeroColor, part, ref rpmComp);
                    del = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), this, "OnCallback");
                    rpmComp.RegisterVariableCallback(variableName, del);
                    registeredVessel = vessel.id;

                    // Initialize the text color. Actually, callback registration took care of that
                }
            }
            catch(Exception e)
            {
                JUtil.LogErrorMessage(this, "Start failed with exception {0}", e);
                spf = new StringProcessorFormatter("x", rpmComp);
            }
        }
        public void UpdateText(RasterPropMonitorComputer rpmComp)
        {
            // If there's a handler references method, it gets called before each text call.
            if (pageHandlerS.getHandlerReferences != null)
            {
                pageHandlerS.getHandlerReferences(pageHandlerModule, backgroundHandlerModule);
            }

            if (pageHandlerMethod != null)
            {
                processedText = pageHandlerMethod(screenWidth, screenHeight);

                if (processedText.IndexOf("$&$", StringComparison.Ordinal) != -1)
                {
                    // There are processed variables in here?
                    StringBuilder bf = new StringBuilder();
                    string[] linesArray = processedText.Split(JUtil.LineSeparator, StringSplitOptions.None);
                    for (int i = 0; i < linesArray.Length; i++)
                    {
                        bf.AppendLine(StringProcessor.ProcessString(linesArray[i], rpmComp));
                    }
                    processedText = bf.ToString();
                }
            }
            else
            {
                if (isMutable)
                {
                    if(spf == null)
                    {
                        string[] linesArray = text.Split(JUtil.LineSeparator, StringSplitOptions.None);
                        spf = new StringProcessorFormatter[linesArray.Length];
                        for(int i=0; i<linesArray.Length; ++i)
                        {
                            spf[i] = new StringProcessorFormatter(linesArray[i], rpmComp);
                        }
                    }

                    StringBuilder bf = new StringBuilder();
                    for (int i = 0; i < spf.Length; i++)
                    {
                        bf.AppendLine(StringProcessor.ProcessString(spf[i], rpmComp));
                    }

                    processedText = bf.ToString();
                }
            }
        }
 internal JSILabelSet(string labelText, RasterPropMonitorComputer rpmComp, bool isOneshot)
 {
     oneshot = isOneshot;
     oneshotComplete = false;
     spf = new StringProcessorFormatter(labelText, rpmComp);
 }