예제 #1
0
        public void Save(KSP.IO.PluginConfiguration config, string keyPrefix)
        {
            VOID_PanelLine line = this;

            string lineLabelPrecisionKey;
            string lineValuePrecisionKey;

            if (line.LabelIsVarPrecision)
            {
                lineLabelPrecisionKey = string.Format(
                    "{0}_Line{1}_LabelDigits",
                    keyPrefix,
                    line.LineNumber
                    );

                config.SetValue(lineLabelPrecisionKey, line.LabelVarPrecisionDigits);
            }

            if (line.ValueIsVarPrecision)
            {
                lineValuePrecisionKey = string.Format(
                    "{0}_Line{1}_ValueDigits",
                    keyPrefix,
                    line.LineNumber
                    );

                config.SetValue(lineValuePrecisionKey, line.ValueVarPrecisionDigits);
            }
        }
예제 #2
0
        public void Load(ConfigNode node)
        {
            ConfigNode[]   lineNodes;
            ConfigNode     lineNode;
            VOID_PanelLine line;
            bool           hasDefinedLineOrder = false;

            this.Name = node.GetValue(VOID_ScriptedPanel.TITLE_KEY, this.Name);

            this.IsShown = node.GetValue(ISSHOWN_KEY, this.IsShown);

            if (node.HasNode(VOID_ScriptedPanel.LINE_KEY))
            {
                lineNodes = node.GetNodes(VOID_ScriptedPanel.LINE_KEY);
                for (int nIdx = 0; nIdx < lineNodes.Length; nIdx++)
                {
                    lineNode = lineNodes[nIdx];

                    line = new VOID_PanelLine(lineNode);

                    if (line.LineNumber != ushort.MaxValue)
                    {
                        hasDefinedLineOrder = true;
                    }

                    this.panelLines.Add(line);
                }

                if (hasDefinedLineOrder)
                {
                    this.panelLines.Sort((x, y) => x.LineNumber.CompareTo(y.LineNumber));
                }
            }
        }
예제 #3
0
        public void Load(ConfigNode node)
        {
            this.Name = node.GetValue(TITLE_KEY, string.Empty);

            string positionString;

            if (node.TryGetValue(POSITION_KEY, out positionString))
            {
                Vector2 positionVector = KSPUtil.ParseVector2(positionString);

                this.WindowPos.x = positionVector.x;
                this.WindowPos.y = positionVector.y;
            }

            string widthString;

            if (node.TryGetValue(WIDTH_KEY, out widthString))
            {
                float width;

                if (float.TryParse(widthString, out width))
                {
                    this.defWidth = width;
                }
            }

            string styleString;

            if (node.TryGetValue(WINDOW_STYLE_KEY, out styleString))
            {
                GUIStyle windowStyle;

                if (VOID_Styles.TryGetStyle(styleString, out windowStyle))
                {
                    this.windowStyle = windowStyle;
                }
            }

            string textStyleString;

            if (node.TryGetValue(TEXT_STYLE_KEY, out textStyleString))
            {
                GUIStyle textStyle;

                if (VOID_Styles.TryGetStyle(textStyleString, out textStyle))
                {
                    this.textStyle = textStyle;
                }
                else
                {
                    this.textStyle = null;
                }
            }

            string scenesString;

            if (node.TryGetValue(SCENES_KEY, out scenesString))
            {
                scenesString = scenesString.ToLower();

                if (scenesString == "all")
                {
                    this.validScenes = (GameScenes[])Enum.GetValues(typeof(GameScenes));
                }

                string[] scenesArray = scenesString.Split(',');

                List <GameScenes> scenes = new List <GameScenes>();

                string sceneString;
                for (int sIdx = 0; sIdx < scenesArray.Length; sIdx++)
                {
                    sceneString = scenesArray[sIdx];

                    GameScenes scene;

                    try
                    {
                        scene = (GameScenes)Enum.Parse(typeof(GameScenes), sceneString.Trim(), true);
                        scenes.Add(scene);
                    }
                    catch
                    {
                        Logging.PostErrorMessage(
                            "{0}: Failed parsing {1}: '{2}' not a valid {3}.",
                            this.Name,
                            SCENES_KEY,
                            sceneString,
                            typeof(GameScenes).Name
                            );
                    }
                }

                this.validScenes = scenes.ToArray();
            }

            string modesString;
            string modeString;

            Game.Modes mode;

            if (node.TryGetValue(MODES_KEY, out modesString))
            {
                string[] modesArray = modesString.Split(',');

                List <Game.Modes> modes = new List <Game.Modes>();

                for (int mIdx = 0; mIdx < modesArray.Length; mIdx++)
                {
                    modeString = modesArray[mIdx];

                    try
                    {
                        mode = (Game.Modes)Enum.Parse(typeof(Game.Modes), modeString.Trim(), true);
                        modes.Add(mode);
                    }
                    catch
                    {
                        Logging.PostErrorMessage(
                            "{0}: Failed parsing {1}: '{2}' not a valid {3}.",
                            this.Name,
                            SCENES_KEY,
                            modeString,
                            typeof(GameScenes).Name
                            );
                    }
                }

                this.validModes = modes.ToArray();
            }

            if (node.HasValue(SUBTITLE_KEY))
            {
                this.subTitle = new VOID_PanelLine();

                this.subTitle.LabelScript = node.GetValue(SUBTITLE_KEY);
            }

            bool hasDefinedLineOrder = false;

            if (node.HasNode(LINE_KEY))
            {
                ConfigNode[] lineNodes = node.GetNodes(LINE_KEY);
                for (int nIdx = 0; nIdx < lineNodes.Length; nIdx++)
                {
                    ConfigNode lineNode = lineNodes[nIdx];

                    VOID_PanelLine line = new VOID_PanelLine(lineNode);

                    if (line.LineNumber != ushort.MaxValue)
                    {
                        hasDefinedLineOrder = true;
                    }

                    this.panelLines.Add(line);
                }

                if (hasDefinedLineOrder)
                {
                    this.panelLines.Sort((x, y) => x.LineNumber.CompareTo(y.LineNumber));
                }
            }

            if (node.HasNode(LINE_GROUP_KEY))
            {
                ConfigNode[]        groupNodes = node.GetNodes(LINE_GROUP_KEY);
                ConfigNode          groupNode;
                VOID_PanelLineGroup group;

                for (int gIdx = 0; gIdx < groupNodes.Length; gIdx++)
                {
                    groupNode = groupNodes[gIdx];

                    group = new VOID_PanelLineGroup();

                    group.Load(groupNode);

                    this.lineGroups.Add(group);
                }
            }
        }