Skip to content

Commit 0abebf7

Browse files
Szczyrkwitcher112
andauthored
Bugfix/v3.17.x.x/1158 incorrect scrolling of window on multiple monitors, fixes debug menu and correct processing modified files during install diff (#165)
* Fix incorrect scrolling of window on multiple monitors (1158) and fixes debug menu * fixed process modified files * Update changelog and version * Update version and changelog * Update Version.cs * Refactoring * Update Version.cs * Update CHANGELOG.md Co-authored-by: Jakub Szczyrk <Jakub Szczyrk> Co-authored-by: Tomasz Jaworski <[email protected]>
1 parent b487406 commit 0abebf7

File tree

5 files changed

+80
-33
lines changed

5 files changed

+80
-33
lines changed

Assets/PatchKit Patcher/Scripts/Debug/DebugMenu.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Diagnostics;
44
using System.IO;
5+
using PatchKit.Unity.Patcher.UI;
56
using PatchKit.Unity.Utilities;
67
using UnityEngine;
78
using UnityEngine.UI;
@@ -18,17 +19,11 @@ public class DebugMenu : MonoBehaviour
1819
private string _popupMessage;
1920
private GraphicRaycaster _graphicRaycaster;
2021
private PlatformType _platformType;
22+
private bool _wasInitialized;
23+
2124

2225
void Start()
2326
{
24-
int windowWidth = 250;
25-
int windowHeight = 180;
26-
int x = (Screen.width - windowWidth) / 2;
27-
int y = (Screen.height - windowHeight) / 2;
28-
int popupRectY = (Screen.height - 120) / 2;
29-
_rect = new Rect(x, y, windowWidth, windowHeight);
30-
_popupRect = new Rect(x, popupRectY, windowWidth, 120);
31-
_texturePopupRect = new Rect(0, popupRectY - y, windowWidth, 120);
3227
_graphicRaycaster = FindObjectOfType<GraphicRaycaster>();
3328
_platformType = Platform.GetPlatformType();
3429
}
@@ -50,6 +45,20 @@ void OnGUI()
5045

5146
if (_show)
5247
{
48+
if (!_wasInitialized)
49+
{
50+
_wasInitialized = true;
51+
float scale = ScreenScale.Value;
52+
float windowWidth = 250 * scale;
53+
float windowHeight = 200 * scale;
54+
float x = (Screen.width - windowWidth) / 2;
55+
float y = (Screen.height - windowHeight) / 2;
56+
float popupRectY = (Screen.height - 120) / 2;
57+
_rect = new Rect(x, y, windowWidth, windowHeight);
58+
_popupRect = new Rect(x, popupRectY, windowWidth, 120);
59+
_texturePopupRect = new Rect(0, popupRectY - y, windowWidth, 120);
60+
}
61+
5362
GUI.DrawTexture(_rect, Texture2D.whiteTexture);
5463
GUI.Window(0, _rect, Draw, "Debug Menu");
5564
if (_showPopup)
@@ -103,6 +112,11 @@ void Draw(int id)
103112
}
104113
}
105114

115+
if (GUILayout.Button("Close"))
116+
{
117+
Close();
118+
}
119+
106120
if (_showPopup)
107121
{
108122
GUI.DrawTexture(_texturePopupRect, Texture2D.whiteTexture);
@@ -269,6 +283,7 @@ void Open()
269283
{
270284
_show = true;
271285
_graphicRaycaster.enabled = false;
286+
_wasInitialized = false;
272287
}
273288

274289
private ProcessStartInfo GetProcessStartInfo(string executablePath)

Assets/PatchKit Patcher/Scripts/UI/BorderlessWindow.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,7 @@ private void Awake()
126126
CanvasScaler = FindObjectOfType<CanvasScaler>();
127127
}
128128

129-
float screenScale;
130-
float screenDpi = Screen.dpi;
131-
if (screenDpi >= 400)
132-
{
133-
screenScale = 4;
134-
}
135-
else if (screenDpi >= 200)
136-
{
137-
screenScale = 2;
138-
}
139-
else
140-
{
141-
if (screenDpi == 0)
142-
{
143-
_logger.LogWarning("Unable to determine the current DPI.");
144-
}
145-
146-
screenScale = 1;
147-
}
148-
149-
_logger.LogDebug(string.Format("Screen scale: {0}", screenScale));
150-
129+
float screenScale = ScreenScale.Value;
151130
EnforceCorrectScreenSize(screenScale);
152131

153132
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
@@ -234,9 +213,6 @@ private void Update()
234213
screenMax.x -= Screen.width;
235214
screenMax.y -= Screen.height;
236215

237-
_windowRect.position = new Vector2(Mathf.Clamp(_windowRect.position.x, 0.0f, screenMax.x),
238-
Mathf.Clamp(_windowRect.position.y, 0.0f, screenMax.y));
239-
240216
int flags = (int) GetWindowLongPtr(_windowsHandle, GwlStyle);
241217

242218
Flags.Unset(ref flags, WsCaption);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using PatchKit.Unity.Patcher.Debug;
2+
using UnityEngine;
3+
4+
namespace PatchKit.Unity.Patcher.UI
5+
{
6+
public class ScreenScale
7+
{
8+
private static readonly DebugLogger DebugLogger = new DebugLogger(typeof(ScreenScale));
9+
10+
public static float Value
11+
{
12+
get
13+
{
14+
float screenScale;
15+
float screenDpi = Screen.dpi;
16+
if (screenDpi >= 400)
17+
{
18+
screenScale = 4;
19+
}
20+
else if (screenDpi >= 200)
21+
{
22+
screenScale = 2;
23+
}
24+
else
25+
{
26+
if (screenDpi == 0)
27+
{
28+
DebugLogger.LogWarning("Unable to determine the current DPI.");
29+
}
30+
31+
screenScale = 1;
32+
}
33+
34+
DebugLogger.Log(string.Format("DPI: {0}", Screen.dpi));
35+
DebugLogger.Log(string.Format("Screen scale: {0}", screenScale));
36+
37+
return screenScale;
38+
}
39+
}
40+
}
41+
}

Assets/PatchKit Patcher/Scripts/UI/ScreenScale.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [3.17.9.0]
8+
### Added
9+
- Support HDPI for debug menu
10+
811
### Fixed
912
- Wrong information about file size during installation
13+
- Broken borderless window position restrictions on multiple monitors (#1158)
1014

1115
## [3.17.8.0]
1216
### Fixed

0 commit comments

Comments
 (0)