public override void ModuleWindow(int id) { bool mayHaveErrorPane = false; if (this.showErrorPane) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.BeginVertical(); } if (this.subTitle != null) { object subObj = this.subTitle.LabelFunction.DynamicInvoke(); if (subObj is string) { GUILayout.Label( (string)subObj, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true)); } else if (subObj is GUIContent) { GUILayout.Label( (GUIContent)subObj, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true)); } } VOID_PanelLineGroup.DoLineLoop(this.PanelLines, this.runtimeErrors, this.errorIndices, this.textStyle); mayHaveErrorPane |= this.errorIndices.Count > 0; VOID_PanelLineGroup group; for (int gIdx = 0; gIdx < this.lineGroups.Count; gIdx++) { group = this.lineGroups[gIdx]; group.IsShown = Layout.Toggle(group.IsShown, group.Name); if (group.IsShown) { VOID_PanelLineGroup.DoLineLoop(group.PanelLines, group.runtimeErrors, group.errorIndices, this.textStyle); mayHaveErrorPane |= group.errorIndices.Count > 0; } } if (Event.current.type == EventType.Repaint) { this.tooltipContents = GUI.tooltip; } if (this.showErrorPane) { GUILayout.EndVertical(); GUILayout.BeginVertical(this.core.Skin.box, GUILayout.MaxWidth(this.defWidth * 0.6f)); VOID_PanelLineGroup.DoErrorReport(this.PanelLines, this.runtimeErrors, this.errorIndices); for (int gIdx = 0; gIdx < this.lineGroups.Count; gIdx++) { group = this.lineGroups[gIdx]; VOID_PanelLineGroup.DoErrorReport( group.PanelLines, group.runtimeErrors, group.errorIndices, group.Name ); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (mayHaveErrorPane) { GUIStyle buttonStyle = this.core.Skin.button; RectOffset padding = buttonStyle.padding; RectOffset border = buttonStyle.border; Rect errorButtonRect = new Rect( 0f, 0f, border.left + border.right, border.top + border.bottom ); errorButtonRect.width = Mathf.Max(errorButtonRect.width, 16f); errorButtonRect.height = Mathf.Max(errorButtonRect.height, 16f); errorButtonRect.x = this.WindowPos.width - (errorButtonRect.width - 2f) * 2f - 8f; errorButtonRect.y = 2f; GUI.Button(errorButtonRect, this.showErrorPane ? "←" : "→", buttonStyle); if (Event.current.type == EventType.Repaint && Input.GetMouseButtonUp(0)) { if (errorButtonRect.Contains(Event.current.mousePosition)) { this.showErrorPane = !this.showErrorPane; this.defWidth *= this.showErrorPane ? 2.5f : 0.4f; } } } else { this.showErrorPane = false; } base.ModuleWindow(id); }
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); } } }