Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale unity GUI #1152

Merged
merged 18 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions TLM/TLM/U/UIScaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ private static float BaseResolutionY {
public static float MaxWidth {
get {
float ret = Config.GuiScaleToResolution ? BaseResolutionX : Screen.width;
return ret / Config.GuiScale;
return ret / UIScale;
}
}

public static float MaxHeight {
get {
float ret = Config.GuiScaleToResolution ? BaseResolutionY : Screen.height;
return ret / Config.GuiScale;
return ret / UIScale;
}
}

Expand All @@ -70,8 +70,7 @@ public static float UIAspectScale {

public static float UIScale => GlobalConfig.Instance.Main.GuiScale * 0.01f;


public static Matrix4x4 ScaleMatrix => Matrix4x4.Scale(Vector3.one * UIScaler.UIScale);
public static Matrix4x4 ScaleMatrix => Matrix4x4.Scale(Vector3.one * UIAspectScale);

public static Vector2 MousePosition {
get {
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/UI/LegacySubTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public virtual string GetTutorialKey() {

protected void DragWindow(ref Rect window) {
Vector2 resolution = UIView.GetAView().GetScreenResolution();
window.x = Mathf.Clamp(window.x, 0, resolution.x - window.width);
window.y = Mathf.Clamp(window.y, 0, resolution.y - window.height);
window.x = Mathf.Clamp(window.x, 0, UIScaler.MaxWidth - window.width);
window.y = Mathf.Clamp(window.y, 0, UIScaler.MaxHeight - window.height);

bool primaryMouseDown = Input.GetMouseButton(0);
if (primaryMouseDown) {
Expand Down
6 changes: 4 additions & 2 deletions TLM/TLM/UI/SubTools/SpeedLimits/SpeedLimitsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace TrafficManager.UI.SubTools.SpeedLimits {
using UnityEngine;
using static TrafficManager.Util.Shortcuts;
using TrafficManager.Util.Extensions;
using TrafficManager.U;

public class SpeedLimitsTool : LegacySubTool {
public const int
Expand Down Expand Up @@ -142,6 +143,8 @@ public override void OnSecondaryClickOverlay() {

public override void OnToolGUI(Event e) {
base.OnToolGUI(e);
var oldMatrix = GUI.matrix;
GUI.matrix = UIScaler.ScaleMatrix;
Copy link
Contributor

@DaEgi01 DaEgi01 Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this matrix switching thing?
currently on the train, can't look it up easily.
is GUI.matrix our code?
if not and we can't change it than this is ok.
if its ours we really should change it :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GUI.matrix is Unity code for immediate gui, works pretty much like GUI.color, but obviously changes different thing 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk .. in that case the code is fine.


string unitTitle = string.Format(
" ({0})",
Expand Down Expand Up @@ -176,8 +179,7 @@ public override void OnToolGUI(Event e) {
&& defaultsWindowRect.Contains(
Event.current.mousePosition));

// overlayHandleHovered = false;
// ShowSigns(false);
GUI.matrix = oldMatrix;
}

private static NetLane[] laneBuffer => NetManager.instance.m_lanes.m_buffer;
Expand Down
14 changes: 10 additions & 4 deletions TLM/TLM/UI/SubTools/TimedTrafficLights/TimedTrafficLightsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TrafficManager.UI.SubTools.TimedTrafficLights {
using TrafficManager.API.TrafficLight;
using TrafficManager.Manager.Impl;
using TrafficManager.State;
using TrafficManager.U;
using TrafficManager.UI.MainMenu.OSD;
using TrafficManager.UI.Textures;
using TrafficManager.Util;
Expand Down Expand Up @@ -1098,13 +1099,16 @@ private string GetStepChangeMetricDescription(StepChangeMetric metric) {
private void GuiTimedTrafficLightsNode() {
_cursorInSecondaryPanel = false;

var oldMatrix = GUI.matrix;
GUI.matrix = UIScaler.ScaleMatrix;
_windowRect2 = GUILayout.Window(
id: 252,
screenRect: _windowRect2,
func: _guiTimedTrafficLightsNodeWindowDelegate,
text: T("TTL.Window.Title:Select nodes"),
style: WindowStyle,
options: EmptyOptionsArray);
GUI.matrix = oldMatrix;

_cursorInSecondaryPanel = _windowRect2.Contains(Event.current.mousePosition);
}
Expand All @@ -1115,6 +1119,8 @@ private void GuiTimedTrafficLightsNode() {
private void GuiTimedTrafficLights() {
_cursorInSecondaryPanel = false;

var oldMatrix = GUI.matrix;
GUI.matrix = UIScaler.ScaleMatrix;
_windowRect = GUILayout.Window(
id: 253,
screenRect: _windowRect,
Expand All @@ -1124,11 +1130,8 @@ private void GuiTimedTrafficLights() {
options: EmptyOptionsArray);

_cursorInSecondaryPanel = _windowRect.Contains(Event.current.mousePosition);
GUI.matrix = oldMatrix;

GUI.matrix = Matrix4x4.TRS(
new Vector3(0, 0, 0),
Quaternion.identity,
new Vector3(1, 1, 1)); // revert scaling
ShowGUI();
}

Expand All @@ -1138,6 +1141,8 @@ private void GuiTimedTrafficLights() {
private void GuiTimedTrafficLightsCopy() {
_cursorInSecondaryPanel = false;

var oldMatrix = GUI.matrix;
GUI.matrix = UIScaler.ScaleMatrix;
_windowRect2 = GUILayout.Window(
id: 255,
screenRect: _windowRect2,
Expand All @@ -1147,6 +1152,7 @@ private void GuiTimedTrafficLightsCopy() {
options: EmptyOptionsArray);

_cursorInSecondaryPanel = _windowRect2.Contains(Event.current.mousePosition);
GUI.matrix = oldMatrix;
}

private void GuiTimedTrafficLightsPasteWindow(int num) {
Expand Down