public void OnGUI(UnityModManager.ModEntry modEntry) { if (Mod == null || !Mod.Enabled) { return; } if (_buttonStyle == null) { _buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleLeft } } ; if (firstTime) { RefreshListOfPatchOwners(modEntry.Info.Id); RefreshPatchInfoOfAllMods(modEntry.Info.Id); firstTime = false; } try { var selectedPatchName = "All".bold(); using (new GUILayout.HorizontalScope()) { // modId <=> color using (new GUILayout.VerticalScope()) { if (GUILayout.Button("Refresh List Of Patch Owners", _buttonStyle)) { RefreshListOfPatchOwners(modEntry.Info.Id); } //if (GUILayout.Button("Clear List Of Patch Owners", _buttonStyle)) { // _patches = null; // _modID = null; // _modIdsToColor = null; //} } // mod selection if (_modIdsToColor != null) { using (new GUILayout.VerticalScope()) { if (GUILayout.Button("All".bold(), _buttonStyle)) { _patches = null; _modID = null; RefreshPatchInfoOfAllMods(modEntry.Info.Id); } foreach (KeyValuePair <string, string> pair in _modIdsToColor) { if (GUILayout.Button(pair.Key.Color(pair.Value).bold(), _buttonStyle)) { _patches = null; _modID = pair.Key; RefreshPatchInfoOfSelected(_modID); } } } // info selection using (new GUILayout.VerticalScope()) { selectedPatchName = string.IsNullOrEmpty(_modID) ? "All".bold() : _modID.Color(_modIdsToColor[_modID]).bold(); if (GUILayout.Button($"Refresh Patch Info ({selectedPatchName})", _buttonStyle)) { RefreshPatchInfoOfAllMods(_modID); } if (GUILayout.Button($"Potential Conflicts for ({selectedPatchName})", _buttonStyle)) { RefreshPatchInfoOfPotentialConflict(_modID); } } } GUILayout.FlexibleSpace(); } if (_modIdsToColor != null) { GUILayout.Space(10f); GUILayout.Label($"Selected Patch Owner: {selectedPatchName}"); GUILayout.Space(10f); } // display info if (_modIdsToColor != null && _patches != null) { int index = 1; var methodBases = _patches.Keys.Concat(_disabled.Keys).Distinct().OrderBy(m => m.Name); UI.Space(15); UI.Div(); UI.Space(10); UI.Label("Patch Debug"); using (UI.HorizontalScope()) { if (_patches.Sum(entry => entry.Value.Count()) > 0) { UI.ActionButton("Disable All", () => { var actions = new List <Action> { }; foreach (var method in methodBases) { var enabledPatches = EnabledPatchesForMethod(method); foreach (var patch in enabledPatches) { actions.Add(() => EnablePatchForMethod(false, patch, method)); } } foreach (var action in actions) { action(); } }); } if (_disabled.Sum(entry => entry.Value.Count()) > 0) { UI.ActionButton("Enable All", () => { var actions = new List <Action> { }; foreach (var method in methodBases) { var disabledPatches = DisabledPatchesForMethod(method); foreach (var patch in disabledPatches) { actions.Add(() => EnablePatchForMethod(true, patch, method)); } } foreach (var action in actions) { action(); } }); } } foreach (var method in methodBases) { UI.Space(15); UI.Div(); UI.Space(10); using (new GUILayout.VerticalScope()) { string typeStr = method.DeclaringType.FullName; var methodComponents = method.ToString().Split(); var returnTypeStr = methodComponents[0]; var methodName = methodComponents[1]; using (new GUILayout.HorizontalScope()) { GUILayout.Label($"{index++}", GUI.skin.box, UI.AutoWidth()); UI.Space(10); GUILayout.Label($"{returnTypeStr.Grey().Bold()} {methodName.Bold()}\t{typeStr.Grey().Italic()}"); } var enabledPatches = EnabledPatchesForMethod(method); var disabledPatches = DisabledPatchesForMethod(method); // do some quick cleanup of disabled entries that have been re-enabled outside of here var intersection = new HashSet <Patch>(disabledPatches); intersection.IntersectWith(enabledPatches); if (intersection.Count > 0) { foreach (var dupe in intersection) { disabledPatches.Remove(dupe); _disabled[method] = disabledPatches; } } var patches = enabledPatches.Concat(disabledPatches).OrderBy(p => p.owner).ToArray(); UI.Space(15); using (new GUILayout.HorizontalScope()) { UI.Space(50); using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { bool enabled = enabledPatches.Contains(patch); if (ModKit.Private.UI.CheckBox("", enabled)) { EnablePatchForMethod(!enabled, patch, method); } } } using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { GUILayout.Label(patch.PatchMethod.Name, GUI.skin.label); } } UI.Space(10); using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { GUILayout.Label(patch.owner.Color(_modIdsToColor[patch.owner]).bold(), GUI.skin.label); } } UI.Space(10); using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { GUILayout.Label(patch.priority.ToString(), GUI.skin.label); } } UI.Space(10); using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { GUILayout.Label(patch.PatchMethod.DeclaringType.DeclaringType?.Name ?? "---", GUI.skin.label); } } UI.Space(10); using (new GUILayout.VerticalScope()) { foreach (Patch patch in patches) { GUILayout.TextArea(patch.PatchMethod.DeclaringType.Name, GUI.skin.textField); } } GUILayout.FlexibleSpace(); } } } } } catch (Exception e) { _patches = null; _modID = null; _modIdsToColor = null; modEntry.Logger.Error(e.StackTrace); throw e; } }
public void OnGUI(bool drawRoot = true, bool collapse = false) { if (_tree == null) { return; } if (_buttonStyle == null) { _buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleLeft, stretchHeight = true } } ; if (_valueStyle == null) { _valueStyle = new GUIStyle(GUI.skin.box) { alignment = TextAnchor.MiddleLeft, stretchHeight = true } } ; int startIndexUBound = Math.Max(0, _nodesCount - MaxRows); // mouse wheel & fix scroll position if (Event.current.type == EventType.Layout) { _totalNodeCount = _tree.RootNode.ChildrenCount; if (startIndexUBound > 0) { if (_mouseOver) { var delta = Input.mouseScrollDelta; if (delta.y > 0 && _startIndex > 0) { _startIndex--; } else if (delta.y < 0 && _startIndex < startIndexUBound) { _startIndex++; } } if (_startIndex > startIndexUBound) { _startIndex = startIndexUBound; } } else { _startIndex = 0; } } using (new GUILayout.VerticalScope()) { // tool-bar using (new GUILayout.HorizontalScope()) { if (GUILayout.Button("Collapse", GUILayout.ExpandWidth(false))) { collapse = true; _skipLevels = 0; } if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(false))) { _tree.RootNode.SetDirty(); } GUILayout.Space(10f); //GUIHelper.AdjusterButton(ref _skipLevels, "Skip Levels:", 0); //GUILayout.Space(10f); Main.settings.maxRows = GUIHelper.AdjusterButton(Main.settings.maxRows, "Max Rows:", 10); GUILayout.Space(10f); #if false GUILayout.Label("Title Width:", GUILayout.ExpandWidth(false)); TitleMinWidth = GUILayout.HorizontalSlider(TitleMinWidth, 0f, Screen.width / 2, GUILayout.Width(100f)); GUILayout.Space(10f); #endif GUILayout.Label($"Scroll: {_startIndex} / {_totalNodeCount}", GUILayout.ExpandWidth(false)); GUILayout.Space(10f); UI.ActionTextField(ref searchText, "searhText", (text) => { }, () => { searchText = searchText.Trim(); ReflectionSearch.Shared.StartSearch(_tree.RootNode, searchText, updateCounts, _searchResults); }, UI.Width(250)); GUILayout.Space(10f); bool isSearching = ReflectionSearch.Shared.isSearching; UI.ActionButton(isSearching ? "Stop" : "Search", () => { if (isSearching) { ReflectionSearch.Shared.Stop(); } else { searchText = searchText.Trim(); ReflectionSearch.Shared.StartSearch(_tree.RootNode, searchText, updateCounts, _searchResults); } }, UI.AutoWidth()); GUILayout.Space(10f); if (GUIHelper.AdjusterButton(ref Main.settings.maxSearchDepth, "Max Depth:", 0)) { ReflectionSearch.Shared.StartSearch(_tree.RootNode, searchText, updateCounts, _searchResults); } GUILayout.Space(10f); if (visitCount > 0) { GUILayout.Label($"found {_searchResults.Count}".Cyan() + $" visited: {visitCount} (d: {searchDepth} b: {searchBreadth})".Orange()); } GUILayout.FlexibleSpace(); } // view using (new GUILayout.VerticalScope()) { using (new GUILayout.ScrollViewScope(new Vector2(), GUIStyle.none, GUIStyle.none, GUILayout.Height(_height))) { using (new GUILayout.HorizontalScope(GUI.skin.box)) { // nodes using (new GUILayout.VerticalScope()) { _nodesCount = 0; if (searchText.Length > 0) { _searchResults.Traverse((node, depth) => { var toggleState = node.ToggleState; if (!node.Node.hasChildren) { toggleState = ToggleState.None; } else if (node.ToggleState == ToggleState.None) { toggleState = ToggleState.Off; } if (node.Node.NodeType == NodeType.Root) { if (node.matches.Count == 0) { return(false); } GUILayout.Label("Search Results".Cyan().Bold()); } else { DrawNodePrivate(node.Node, depth, ref toggleState); } if (node.ToggleState != toggleState) { Main.Log(node.ToString()); } node.ToggleState = toggleState; if (toggleState.IsOn()) { DrawChildren(node.Node, depth + 1, collapse); } return(true); // toggleState == ToggleState.On; }, 0); } if (drawRoot) { DrawNode(_tree.RootNode, 0, collapse); } else { DrawChildren(_tree.RootNode, 0, collapse); } } // scrollbar // if (startIndexUBound > 0) _startIndex = (int)GUILayout.VerticalScrollbar(_startIndex, MaxRows, 0f, Math.Max(MaxRows, _totalNodeCount), GUILayout.ExpandHeight(true)); } // cache height if (Event.current.type == EventType.Repaint) { var mousePos = Event.current.mousePosition; _mouseOver = _viewerRect.Contains(Event.current.mousePosition); //Main.Log($"mousePos: {mousePos} Rect: {_viewerRect} --> {_mouseOver}"); _viewerRect = GUILayoutUtility.GetLastRect(); _height = _viewerRect.height + 5f; } } } } }
public static void OnGUI() { var ks = KingdomState.Instance; if (ks == null) { UI.Label("You must unlock the crusade before you can access these toys.".yellow().bold()); return; } var moraleState = ks.MoraleState; UI.HStack("Morale", 1, () => { UI.Toggle("Flags always green", ref settings.toggleCrusadeFlagsStayGreen); KingdomCheats.AddMorale(); }, () => { var value = moraleState.CurrentValue; UI.Slider("Morale", ref value, moraleState.MinValue, moraleState.MaxValue, 1, "", UI.AutoWidth()); moraleState.CurrentValue = value; }, () => { var value = moraleState.MaxValue; UI.Slider("Max Morale", ref value, -200, 200, 20, "", UI.AutoWidth()); moraleState.MaxValue = value; }, () => { var value = moraleState.MinValue; UI.Slider("Min Morale", ref value, -200, 200, -100, "", UI.AutoWidth()); moraleState.MinValue = value; }, () => { } ); UI.Div(0, 25); UI.HStack("Kingdom", 1, () => { UI.Label("increment".cyan(), UI.Width(325)); var increment = UI.IntTextField(ref settings.increment, null, UI.Width(150)); UI.Space(25); UI.Label("Experimental".orange().bold()); }, () => { using (UI.VerticalScope()) { UI.Space(15); UI.Div(0, 0, 800); using (UI.HorizontalScope()) { UI.Label("Kingdom Stat", UI.Width(325)); UI.Label("Rank", UI.Width(150)); UI.Label("Experience", UI.Width(150)); UI.Label("Next Rank", UI.Width(150)); } foreach (var kingdomStat in ks.Stats) { var conditions = KingdomRoot.Instance.RankUps.Conditions[kingdomStat.Type]; using (UI.HorizontalScope()) { var rank = kingdomStat.Rank; var exp = kingdomStat.Value.ToString().orange(); var required = conditions.GetRequiredStatValue(kingdomStat.Rank + 1).ToString().cyan(); UI.ValueAdjuster(kingdomStat.Type.ToString(), () => kingdomStat.Rank, v => kingdomStat.Rank = v, 1, 0, 8); UI.Space(42); UI.Label(exp, UI.Width(150)); UI.Label(required, UI.Width(150)); UI.Space(10); UI.ActionButton($"Gain {settings.increment}", () => { kingdomStat.Value += settings.increment; }, UI.AutoWidth()); UI.ActionButton($"Lose {settings.increment}", () => { kingdomStat.Value -= settings.increment; }, UI.AutoWidth()); } } UI.Div(0, 0, 800); UI.DescriptiveLabel("Cost Modifiers", "The following modifiers all work on ".green() + "cost = cost (1 + modifier) ".yellow() + "so a value of ".green() + "-1".yellow() + " means the cost is free, ".green() + "0".yellow() + " is normal cost and ".green() + "2".yellow() + " increases it 3x".green()); UI.Slider("Claim Cost Modifier", () => ks.ClaimCostModifier, v => ks.ClaimCostModifier = v, -1, 2, 0, 1); UI.Slider("Claim Time Modifier", () => ks.ClaimTimeModifier, v => ks.ClaimTimeModifier = v, -1, 2, 0, 1); UI.Slider("Rankup Time Modifer", () => ks.RankupTimeModifier, v => ks.RankupTimeModifier = v, -1, 2, 0, 1); UI.Slider("Build Time Modifier", ref settings.kingdomBuildingTimeModifier, -1, 2, 0, 1); UI.Div(0, 0, 800); UI.DescriptiveLabel("Random Encounters", "The following modifiers all work on ".green() + "chance = chance (1 + modifier) ".yellow() + "so a value of ".green() + "-1".yellow() + " means the chance is 0, ".green() + "0".yellow() + " is chance cost and ".green() + "2".yellow() + " increases it 3x".green()); UI.Slider("% Chance (Unclaimed)", () => ks.REModifierUnclaimed, v => ks.REModifierUnclaimed = v, -1f, 2f, 0f, 1); UI.Slider("% Chance (Claimed)", () => ks.REModifierClaimed, v => ks.REModifierClaimed = v, -1, 2, -0.5f, 1); UI.Slider("% Chance (Upgraded)", () => ks.REModifierUpgraded, v => ks.REModifierUnclaimed = v, -1f, 2f, -1f, 1); UI.Div(0, 0, 800); UI.ValueAdjuster("Confidence (Royal Court)", () => ks.RoyalCourtConfidence, v => ks.RoyalCourtConfidence = v, 1, 0, int.MaxValue); UI.ValueAdjuster("Confidence (Nobles)", () => ks.NobilityConfidence, v => ks.NobilityConfidence = v, 1, 0, int.MaxValue); UI.ValueAdjuster("Victories This Week", () => ks.VictoriesThisWeek, v => ks.VictoriesThisWeek = v, 1, 0, int.MaxValue); UI.EnumGrid("Unrest", () => ks.Unrest, (u) => ks.Unrest = u); UI.AlignmentGrid("Alignment", ks.Alignment, (a) => ks.Alignment = a, UI.Width(325)); } }, () => { using (UI.VerticalScope()) { UI.Space(15); UI.Div(0, 0, 800); UI.Label("Kingdom Finances"); } }, () => { UI.Label("Finances".cyan(), UI.Width(325)); UI.Label(ks.Resources.Finances.ToString().orange().bold(), UI.Width(100)); UI.ActionButton($"Gain {settings.increment}", () => { ks.Resources += KingdomResourcesAmount.FromFinances(settings.increment); }, UI.AutoWidth()); UI.ActionButton($"Lose {settings.increment}", () => { ks.Resources -= KingdomResourcesAmount.FromFinances(settings.increment); }, UI.AutoWidth()); }, () => { UI.Label("Materials".cyan(), UI.Width(325)); UI.Label(ks.Resources.Materials.ToString().orange().bold(), UI.Width(100)); UI.ActionButton($"Gain {settings.increment}", () => { ks.Resources += KingdomResourcesAmount.FromMaterials(settings.increment); }, UI.AutoWidth()); UI.ActionButton($"Lose {settings.increment}", () => { ks.Resources -= KingdomResourcesAmount.FromMaterials(settings.increment); }, UI.AutoWidth()); }, () => { UI.Label("Favors".cyan(), UI.Width(325)); UI.Label(ks.Resources.Favors.ToString().orange().bold(), UI.Width(100)); UI.ActionButton($"Gain {settings.increment}", () => { ks.Resources += KingdomResourcesAmount.FromFavors(settings.increment); }, UI.AutoWidth()); UI.ActionButton($"Lose {settings.increment}", () => { ks.Resources -= KingdomResourcesAmount.FromFavors(settings.increment); }, UI.AutoWidth()); }, () => { using (UI.VerticalScope()) { UI.Space(15); UI.Div(0, 0, 800); } }, () => UI.Toggle("Instant Events", ref settings.toggleInstantEvent), () => UI.Toggle("Ignore Event Solution Restrictions", ref settings.toggleIgnoreEventSolutionRestrictions), () => { UI.Slider("Crusade card resolution time multiplier", ref settings.kingdomTaskResolutionLengthMultiplier, -1, 2, 0, 2, "", UI.Width(400)); UI.Space(25); UI.Label("Multiplies crusade card resolution time by (1 + modifier). -1 will make things as fast as possible (minimum 1 day to avoid possible bugs)".green()); }, () => { UI.Slider("Build Time Modifier", ref settings.kingdomBuildingTimeModifier, -1, 2, 0, 2, "", UI.Width(400)); var instance = KingdomState.Instance; if (instance != null) { instance.BuildingTimeModifier = settings.kingdomBuildingTimeModifier; } UI.Space(25); UI.Label("Multiplies build time by (1 + modifier). -1 will make new buildings instant.".green()); }, () => { var startDate = Game.Instance.BlueprintRoot.Calendar.GetStartDate(); var currentDate = KingdomState.Instance.Date; var dateText = Game.Instance.BlueprintRoot.Calendar.GetDateText(currentDate - startDate, GameDateFormat.Full, true); using (UI.VerticalScope()) { UI.Space(15); UI.Div(0, 0, 800); using (UI.HorizontalScope()) { UI.Label("Date".cyan(), UI.Width(325)); UI.Label(dateText.orange().bold(), UI.AutoWidth()); UI.ActionButton($"+1 Day", () => { Actions.KingdomTimelineAdvanceDays(1); }, UI.Width(150)); UI.ActionButton($"+1 Month", () => { Actions.KingdomTimelineAdvanceDays(KingdomState.Instance.DaysTillNextMonth); }, UI.Width(150)); } UI.ValueAdjuster("Current Day", () => ks.CurrentDay, v => ks.CurrentDay = v, 1, 0, int.MaxValue); UI.ValueAdjuster("Current Turn", () => ks.CurrentTurn, v => ks.CurrentTurn = v, 1, 0, int.MaxValue); } }, () => { } ); 25.space(); UI.Div(); SettlementsEditor.OnGUI(); }