public void OnGUI(UnityModManager.ModEntry modEntry) { if (Mod == null || !Mod.Enabled) { return; } string activeScene = SceneManager.GetActiveScene().name; if (Game.Instance?.Player == null || activeScene == "MainMenu" || activeScene == "Start") { GUILayout.Label(" * Please start or load the game first.".Color(RGBA.yellow)); return; } if (_buttonStyle == null) { _buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleLeft, wordWrap = true } } ; try { using (new GUILayout.HorizontalScope()) { // character selection using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(false))) { List <UnitEntityData> companions = Game.Instance?.Player.AllCharacters .Where(c => c.IsPlayerFaction && !c.Descriptor.IsPet).ToList(); int selectedCharacterIndex = companions.IndexOf(_selectedCharacter) + 1; GUIHelper.SelectionGrid(ref selectedCharacterIndex, new string[] { "None" }.Concat(companions.Select(item => item.CharacterName)).ToArray(), 1, () => { if (selectedCharacterIndex > 0) { _selectedCharacter = companions[selectedCharacterIndex - 1]; _featuresTree = new FeaturesTree(_selectedCharacter.Descriptor.Progression); } }, null, GUILayout.ExpandWidth(false)); if (selectedCharacterIndex == 0 && (Event.current.type == EventType.Layout || Event.current.type == EventType.Used)) { _selectedCharacter = null; _featuresTree = null; } } // features tree if (_featuresTree != null) { using (new GUILayout.VerticalScope()) { bool expandAll; bool collapseAll; // draw tool bar using (new GUILayout.HorizontalScope()) { if (GUILayout.Button("Refresh")) { _featuresTree = new FeaturesTree(_selectedCharacter.Descriptor.Progression); } expandAll = GUILayout.Button("Expand All"); collapseAll = GUILayout.Button("Collapse All"); } GUILayout.Space(10f); // draw tree foreach (FeaturesTree.FeatureNode node in _featuresTree.RootNodes) { draw(node); } void draw(FeaturesTree.FeatureNode node) { using (new GUILayout.HorizontalScope()) { node.Expanded = node.ChildNodes.Count == 0 || (expandAll ? true : collapseAll ? false : node.Expanded); GUIHelper.ToggleButton(ref node.Expanded, node.Name + ("\n[" + node.Blueprint.name + "]").Color(node.IsMissing ? RGBA.maroon : RGBA.grey), _buttonStyle); if (node.Expanded && node.ChildNodes.Count > 0) { using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(false))) { foreach (FeaturesTree.FeatureNode child in node.ChildNodes) { draw(child); } } } else { GUILayout.FlexibleSpace(); } } } } } } } catch (Exception e) { _selectedCharacter = null; _featuresTree = null; modEntry.Logger.Error(e.StackTrace); throw e; } }
public void OnGUI(UnitEntityData character, bool refresh) { if (!Main.IsInGame) { return; } var activeScene = SceneManager.GetActiveScene().name; if (Game.Instance?.Player == null || activeScene == "MainMenu" || activeScene == "Start") { UI.Label(" * Please start or load the game first.".color(RGBA.yellow)); return; } if (_buttonStyle == null) { _buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleLeft, wordWrap = true } } ; try { if (character != _selectedCharacter || refresh) { _selectedCharacter = character; _featuresTree = new FeaturesTree(_selectedCharacter.Descriptor.Progression);; } using (UI.HorizontalScope()) { // features tree if (_featuresTree != null) { using (UI.VerticalScope()) { var expandAll = false; var collapseAll = false; // draw tool bar using (UI.HorizontalScope()) { UI.ActionButton("Refresh", () => _featuresTree = new FeaturesTree(_selectedCharacter.Descriptor.Progression), UI.Width(200)); UI.Button("Expand All", ref expandAll, UI.Width(200)); UI.Button("Collapse All", ref collapseAll, UI.Width(200)); } UI.Space(10f); // draw tree foreach (var node in _featuresTree.RootNodes) { draw(node); } void draw(FeaturesTree.FeatureNode node) { using (UI.HorizontalScope()) { var levelText = node.Level == 0 ? "" : $" {node.Level} - "; var blueprintName = $"[{node.Blueprint.name}]".color(node.IsMissing ? RGBA.maroon : RGBA.aqua); var titleText = $"{levelText}{node.Name.Bold()} {blueprintName}"; if (node.ChildNodes.Count > 0) { if (node.Expanded == ToggleState.None) { node.Expanded = ToggleState.Off; } node.Expanded = expandAll ? ToggleState.On : collapseAll ? ToggleState.Off : node.Expanded; } else { node.Expanded = ToggleState.None; } Mod.Trace($"{node.Expanded} {titleText}"); UI.ToggleButton(ref node.Expanded, titleText, _buttonStyle); if (node.Expanded.IsOn()) { using (UI.VerticalScope(UI.ExpandWidth(false))) { foreach (var child in node.ChildNodes.OrderBy(n => n.Level)) { draw(child); } } } else { GUILayout.FlexibleSpace(); } } } } } } } catch (Exception e) { _selectedCharacter = null; _featuresTree = null; Mod.Error(e); throw e; } }