Skip to content

Commit

Permalink
ui is cooler now
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Nov 1, 2024
1 parent a4d38cd commit 8dde01a
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 16 deletions.
6 changes: 3 additions & 3 deletions UniTAS/Patcher/Implementations/GUI/Components/DropdownList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public bool DropdownButtons(Rect position, (string, Action)[] buttons)
alignment = TextAnchor.MiddleLeft,
normal = new()
{
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.15f, 0.15f, 0.15f)),
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.09f, 0.12f, 0.22f)),
textColor = Color.white
},
hover = new()
{
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.22f, 0.22f, 0.22f)),
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.12f, 0.16f, 0.29f)),
textColor = Color.white
},
active = new()
{
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.32f, 0.32f, 0.32f)),
background = TextureUtils.MakeSolidColourTexture(2, 2, new Color(0.15f, 0.27f, 0.37f)),
textColor = Color.white
},
fixedHeight = 25,
Expand Down
31 changes: 23 additions & 8 deletions UniTAS/Patcher/Implementations/GUI/Windows/ObjectPickerWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UniTAS.Patcher.Interfaces.DependencyInjection;
Expand All @@ -13,11 +14,21 @@
namespace UniTAS.Patcher.Implementations.GUI.Windows;

[Register]
public class ObjectPickerWindow(WindowDependencies windowDependencies, IUnityInputWrapper unityInput)
: Window(windowDependencies,
config: new WindowConfig(defaultWindowRect: GUIUtils.WindowRect(500, 500), windowName: "Object picker"))
public class ObjectPickerWindow : Window
{
private readonly IUpdateEvents _updateEvents = windowDependencies.UpdateEvents;
public ObjectPickerWindow(WindowDependencies windowDependencies, IUnityInputWrapper unityInput) : base(
windowDependencies,
config: new WindowConfig(defaultWindowRect: GUIUtils.WindowRect(500, 500), windowName: "Object picker"))
{
_unityInput = unityInput;
_updateEvents = windowDependencies.UpdateEvents;
var objectIconTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
windowDependencies.TextureWrapper.LoadImage(objectIconTexture,
Path.Combine(UniTASPaths.Resources, "object-icon.png"));
_objNameContent = new(objectIconTexture);
}

private readonly IUpdateEvents _updateEvents;

private Vector2 _scrollPos = Vector2.zero;

Expand Down Expand Up @@ -113,7 +124,7 @@ private void ApplyFilterToObjects()

private void ClickSelectUpdate()
{
var mousePos = unityInput.MousePosition;
var mousePos = _unityInput.MousePosition;
if (_raycastCamera == null)
{
_raycastCamera = Camera.main;
Expand Down Expand Up @@ -141,13 +152,13 @@ private void ClickSelectUpdate()
_clickSelectText = builder.ToString();

var close = false;
if (unityInput.GetMouseButtonDown(0))
if (_unityInput.GetMouseButtonDown(0))
{
close = true;
_objects = [(0, raycastHit.gameObject)];
}

if (!close && unityInput.AnyKeyDown)
if (!close && _unityInput.AnyKeyDown)
{
close = true;
}
Expand Down Expand Up @@ -187,6 +198,8 @@ private static Transform RaycastFromCamera(Camera camera, Vector2 mousePos)
private string _search;
private GUIStyle _objNameStyle;

private readonly GUIContent _objNameContent;

protected override void OnGUI()
{
GUILayout.BeginVertical();
Expand Down Expand Up @@ -251,7 +264,8 @@ protected override void OnGUI()
if (depth > 0)
GUILayout.Space(depth * 20);
_objNameStyle ??= new GUIStyle(UnityEngine.GUI.skin.label) { alignment = TextAnchor.MiddleLeft };
if (GUILayout.Button(obj.name, _objNameStyle))
_objNameContent.text = $" {obj.name}";
if (GUILayout.Button(_objNameContent, _objNameStyle))
{
OnObjectSelected?.Invoke(this, obj);
_selected = true;
Expand All @@ -276,4 +290,5 @@ protected override void OnGUI()

public event Action<ObjectPickerWindow, GameObject> OnObjectSelected;
private bool _selected;
private readonly IUnityInputWrapper _unityInput;
}
5 changes: 3 additions & 2 deletions UniTAS/Patcher/Implementations/GUI/Windows/ToolBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ private set
private readonly IDropdownList _dropdownList;

public ToolBar(IWindowFactory windowFactory, IBinds binds, IGUIComponentFactory guiComponentFactory,
IObjectTrackerManager objectTrackerManager, IUpdateEvents updateEvents, ICursorWrapper cursorWrapper, IGameRestart gameRestart)
IObjectTrackerManager objectTrackerManager, IUpdateEvents updateEvents, ICursorWrapper cursorWrapper,
IGameRestart gameRestart)
{
_windowFactory = windowFactory;
_cursorWrapper = cursorWrapper;
gameRestart.OnGameRestart += OnGameRestart;
_dropdownList = guiComponentFactory.CreateComponent<IDropdownList>();

_buttonNormal.SetPixel(0, 0, new(0.25f, 0.25f, 0.25f));
_buttonNormal.SetPixel(0, 0, new(0.129f, 0.149f, 0.263f));
_buttonNormal.Apply();
var buttonHold = new Texture2D(1, 1);
buttonHold.SetPixel(0, 0, new(0.5f, 0.5f, 0.5f));
Expand Down
43 changes: 41 additions & 2 deletions UniTAS/Patcher/Interfaces/GUI/Window.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.IO;
using BepInEx;
using UniTAS.Patcher.Models.GUI;
using UniTAS.Patcher.Services;
using UniTAS.Patcher.Services.GUI;
using UniTAS.Patcher.Services.NoRefresh;
using UniTAS.Patcher.Services.UnityEvents;
using UniTAS.Patcher.Services.UnitySafeWrappers.Wrappers;
using UniTAS.Patcher.Utils;
using UnityEngine;

Expand Down Expand Up @@ -85,6 +87,7 @@ protected WindowConfig Config
private readonly IConfig _configService;
private readonly IToolBar _toolBar;
private readonly INoRefresh _noRefresh;
private readonly ITextureWrapper _textureWrapper;

private string WindowName { get; set; }
public string WindowConfigId { get; }
Expand All @@ -104,6 +107,7 @@ protected Window(WindowDependencies windowDependencies, string windowId = null)
_configService = windowDependencies.Config;
_toolBar = windowDependencies.ToolBar;
_noRefresh = windowDependencies.NoRefresh;
_textureWrapper = windowDependencies.TextureWrapper;
}

protected Window(WindowDependencies windowDependencies, WindowConfig config, string windowId = null)
Expand All @@ -116,6 +120,7 @@ protected Window(WindowDependencies windowDependencies, WindowConfig config, str
_configService = windowDependencies.Config;
_toolBar = windowDependencies.ToolBar;
_noRefresh = windowDependencies.NoRefresh;
_textureWrapper = windowDependencies.TextureWrapper;
if (config != null)
{
Config = config;
Expand Down Expand Up @@ -179,6 +184,10 @@ protected void Init()

private bool _pendingNewLayout = true;

private static GUIStyle _windowStyle;
private static readonly Texture2D WindowBgOnNormal = new Texture2D(1, 1, TextureFormat.ARGB32, false);
private static readonly Texture2D WindowBgNormal = new Texture2D(1, 1, TextureFormat.ARGB32, false);

private void OnGUIUnconditional()
{
var currentEvent = Event.current;
Expand Down Expand Up @@ -218,9 +227,24 @@ private void OnGUIUnconditional()

_pendingNewLayout = false;

_windowRect = GUILayout.Window(_windowId, _windowRect, WindowUpdate, WindowName, Config.LayoutOptions);
if (_windowStyle == null)
{
_windowStyle = new GUIStyle(UnityEngine.GUI.skin.window);
_textureWrapper.LoadImage(WindowBgOnNormal, Path.Combine(UniTASPaths.Resources, "window-on-normal.png"));
_textureWrapper.LoadImage(WindowBgNormal, Path.Combine(UniTASPaths.Resources, "window-normal.png"));
_windowStyle.onNormal.background = WindowBgOnNormal;
_windowStyle.normal.background = WindowBgNormal;
}

_windowRect = GUILayout.Window(_windowId, _windowRect, WindowUpdate, WindowName, _windowStyle,
Config.LayoutOptions);
}

private static GUIStyle _closeButtonStyle;
private static readonly Texture2D CloseButtonNormal = new Texture2D(1, 1, TextureFormat.ARGB32, false);
private static readonly Texture2D CloseButtonHover = new Texture2D(1, 1, TextureFormat.ARGB32, false);
private static readonly Texture2D CloseButtonClick = new Texture2D(1, 1, TextureFormat.ARGB32, false);

private void WindowUpdate(int id)
{
HandleDragResize();
Expand All @@ -231,8 +255,23 @@ private void WindowUpdate(int id)
GUILayout.BeginHorizontal(GUIUtils.EmptyOptions);

// close button
if (_closeButtonStyle == null)
{
_closeButtonStyle = new GUIStyle(UnityEngine.GUI.skin.button);

_textureWrapper.LoadImage(CloseButtonNormal,
Path.Combine(UniTASPaths.Resources, "window-close-normal.png"));
_textureWrapper.LoadImage(CloseButtonHover,
Path.Combine(UniTASPaths.Resources, "window-close-hover.png"));
_textureWrapper.LoadImage(CloseButtonClick,
Path.Combine(UniTASPaths.Resources, "window-close-click.png"));
_closeButtonStyle.normal.background = CloseButtonNormal;
_closeButtonStyle.hover.background = CloseButtonHover;
_closeButtonStyle.active.background = CloseButtonClick;
}

if (UnityEngine.GUI.Button(new(_windowRect.width - CloseButtonSize, 0f, CloseButtonSize, CloseButtonSize),
"x"))
GUIContent.none, _closeButtonStyle))
{
Show = false;
}
Expand Down
5 changes: 4 additions & 1 deletion UniTAS/Patcher/Models/GUI/WindowDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UniTAS.Patcher.Services.GUI;
using UniTAS.Patcher.Services.NoRefresh;
using UniTAS.Patcher.Services.UnityEvents;
using UniTAS.Patcher.Services.UnitySafeWrappers.Wrappers;

namespace UniTAS.Patcher.Models.GUI;

Expand All @@ -10,11 +11,13 @@ public class WindowDependencies(
IPatchReverseInvoker patchReverseInvoker,
IConfig config,
IToolBar toolBar,
INoRefresh noRefresh)
INoRefresh noRefresh,
ITextureWrapper textureWrapper)
{
public IUpdateEvents UpdateEvents { get; } = updateEvents;
public IPatchReverseInvoker PatchReverseInvoker { get; } = patchReverseInvoker;
public IConfig Config { get; } = config;
public INoRefresh NoRefresh { get; } = noRefresh;
public IToolBar ToolBar { get; } = toolBar;
public ITextureWrapper TextureWrapper { get; } = textureWrapper;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8dde01a

Please sign in to comment.