Skip to content

Commit

Permalink
UI work
Browse files Browse the repository at this point in the history
  • Loading branch information
xADDBx committed Nov 17, 2024
1 parent 6089875 commit 7142a2a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 36 deletions.
4 changes: 2 additions & 2 deletions ToyBox/Classes/MainUI/PatchTool/UI/PatchListUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public static void OnGUI() {
}, Width(100));
}
Space(50);
ActionButton("Modify".localize(), () => {
ActionButton("Open in Tab".localize(), () => {
PatchToolUIManager.OpenBlueprintInTab(patch.BlueprintGuid);
});
Space(50);
Space(100);
ActionButton("Delete".localize(), () => {
DeletePatch(patch);
});
Expand Down
76 changes: 66 additions & 10 deletions ToyBox/Classes/MainUI/PatchTool/UI/PatchToolTabUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using HarmonyLib;
using Kingmaker.Blueprints;
using Kingmaker.UnitLogic;
using ModKit;
using ModKit.DataViewer;
using ModKit.Utility.Extensions;
using System;
using System.Collections;
Expand All @@ -11,6 +13,8 @@
using System.Threading.Tasks;
using UniRx;
using UnityEngine;
using static Kingmaker.Visual.Sound.SoundEventsEmitter;
using static Unity.Burst.Intrinsics.X86.Avx;

namespace ToyBox.PatchTool;
public class PatchToolTabUI {
Expand All @@ -24,6 +28,9 @@ public class PatchToolTabUI {
private static Dictionary<Type, List<Type>> _compatibleTypes = new();
private static Dictionary<Type, List<Type>> _allowedTypes = new();
private HashSet<object> _visited = new();
private bool _showBlueprintPicker = false;
private bool _showPatchManager = false;
private bool _showFieldsEditor = false;
internal string Target = "";
private string _pickerText = "";
public int IndentPerLevel = 25;
Expand Down Expand Up @@ -113,14 +120,17 @@ public void SetTarget(string guid) {
}
public void OnGUI() {
_visited.Clear();
using (HorizontalScope()) {
Label("Enter target blueprint id".localize(), Width(200));
TextField(ref _pickerText, null, Width(350));
ActionButton("Pick Blueprint".localize(), () => {
SetTarget(_pickerText);
});
DisclosureToggle("Show Blueprint Picker", ref _showBlueprintPicker);
if (_showBlueprintPicker) {
using (HorizontalScope()) {
Space(20);
Label("Enter target blueprint id".localize(), Width(200));
TextField(ref _pickerText, null, Width(350));
ActionButton("Pick Blueprint".localize(), () => {
SetTarget(_pickerText);
});
}
}
Div();
if ((CurrentState == null || CurrentState.IsDirty) && !Target.IsNullOrEmpty()) {
if (Event.current.type == EventType.Layout) {
ClearCache();
Expand All @@ -131,9 +141,55 @@ public void OnGUI() {
}
}
if (CurrentState != null) {
using (HorizontalScope()) {
Space(-IndentPerLevel);
NestedGUI(CurrentState.Blueprint);
Space(15);
Div();
Space(15);
DisclosureToggle("Show Patch Manager".localize(), ref _showPatchManager);
if (_showPatchManager) {
using (HorizontalScope()) {
Space(20);
using (VerticalScope()) {
using (HorizontalScope()) {
Label($"Current Patch targets bp: {BlueprintExtensions.GetTitle(CurrentState.Blueprint).Cyan()}({CurrentState.Blueprint.name ?? CurrentState.Blueprint.AssetGuid}) and has {CurrentState.Operations.Count.ToString().Cyan()} operations.");
Space(30);
using (VerticalScope()) {
int count = 0;
foreach (var op in CurrentState.Operations.ToList()) {
count++;
using (HorizontalScope()) {
Label($"Operation: {op.OperationType}", Width(200));
Space(20);
Label($"Field: {op.FieldName}", Width(300));
Space(20);
ReflectionTreeView.DetailToggle("Inspect".localize(), op, op, 0);
Space(20);
if (count == CurrentState.Operations.Count) {
ActionButton("Remove".localize(), () => {
CurrentState.Operations.Remove(op);
});
}
}
ReflectionTreeView.OnDetailGUI(op);
}
}
}
Space(10);
ActionButton("Apply Changes".localize(), () => {
CurrentState.CreateAndRegisterPatch();
});
}
}
}
Space(15);
Div();
Space(15);
DisclosureToggle("Show Fields Editor".localize(), ref _showFieldsEditor);
if (_showFieldsEditor) {
using (HorizontalScope()) {
Space(20);
Space(-IndentPerLevel);
NestedGUI(CurrentState.Blueprint);
}
}
}
}
Expand Down
61 changes: 37 additions & 24 deletions ToyBox/Classes/MainUI/PatchTool/UI/PatchToolUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,62 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace ToyBox.PatchTool;
public static class PatchToolUIManager {
private static List<PatchToolTabUI> instances = new();
private static int selectedIndex = -1;
private static bool showExistingPatchesUI = false;
public static void OnGUI() {
Label("Note:".localize().Green().Bold() + " " + "As with Etudes Editor, this is a very powerful feature. You naturally won't break your game by simply changing the damage of a weapon, but this feature allows a lot of things that could potentially causes issues. Beware of that and always work on a backup save.".localize().Green());
Label("Warning:".localize().Yellow().Bold() + " " + "After finishing creating a patch, it is advised to restart the game before playing on a proper save.".localize().Yellow());
Label("Warning:".localize().Yellow().Bold() + " " + "This is a very powerful feature. You won't break your game by simply changing the damage of a weapon, but this feature allows doing a lot of things that could potentially causes issues. Beware of that and always keep a backup.".localize().Orange());
Label("Note:".localize().Green().Bold() + " " + "After finishing creating a patch, it is advised to restart the game before playing on a proper save.".localize().Green());
Space(15);
Div();
Space(15);
DisclosureToggle("Manage existing patches".localize(), ref showExistingPatchesUI, 200);
if (showExistingPatchesUI) {
PatchListUI.OnGUI();
Div();
Space(20);
}
Label("Tabs".localize().Bold(), AutoWidth());
Space(15);
Div();
Space(15);
using (HorizontalScope()) {
Label("Tabs".localize().Bold(), AutoWidth());
Space(50);
for (int i = 0; i < instances.Count; i++) {
using (HorizontalScope()) {
var tabName = instances[i].Target.IsNullOrEmpty() ? "New Tab".localize() : instances[i].Target;
if (i == selectedIndex) {
Label($"[{tabName}]", AutoWidth());
} else {
ActionButton(tabName, () => {
selectedIndex = i;
}, AutoWidth());
}
ActionButton("Close".localize(), () => {
instances.RemoveAt(i);
if (selectedIndex >= instances.Count) {
selectedIndex = instances.Count - 1;
}
}, AutoWidth());
}
}
ActionButton("+", () => {
instances.Add(new PatchToolTabUI());
selectedIndex = instances.Count - 1;
}, AutoWidth());
}
Label("");
using (VerticalScope()) {
for (int j = 0; j < instances.Count; j += 4) {
using (HorizontalScope()) {
for (int i = j; (i < instances.Count) && (i < j + 4); i++) {
var tabName = instances[i].Target.IsNullOrEmpty() ? "New Tab".localize() : instances[i].Target;
if (i == selectedIndex) {
Label($"[{tabName}]", Width(300));
} else {
ActionButton(tabName, () => {
selectedIndex = i;
}, Width(300));
}
ActionButton("Close".localize(), () => {
instances.RemoveAt(i);
if (selectedIndex >= instances.Count) {
selectedIndex = instances.Count - 1;
}
}, Width(70));
Space(50);
}
}
Label("");
}
}
Space(15);
Div();
Space(20);
Space(15);
if (selectedIndex >= 0 && selectedIndex < instances.Count) {
instances[selectedIndex].OnGUI();
} else {
Expand Down

0 comments on commit 7142a2a

Please sign in to comment.