[+] Window Magic!
Build AquaMai / build (SDEZ) (push) Has been cancelled Details
Build AquaMai / build (SDGA145) (push) Has been cancelled Details

pull/55/head
Clansty 2024-09-27 21:50:27 +08:00
parent c1c7788cd3
commit 74e39c437d
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
6 changed files with 99 additions and 1 deletions

View File

@ -314,6 +314,7 @@
<Compile Include="TouchSensitivity\Enable.cs" />
<Compile Include="Utils\JudgeAdjust.cs" />
<Compile Include="Utils\LogUserId.cs" />
<Compile Include="Utils\WindowState.cs" />
<Compile Include="UX\CustomPlaceName.cs" />
<Compile Include="UX\CustomVersionString.cs" />
<Compile Include="UX\DemoMaster.cs" />

View File

@ -72,6 +72,12 @@ JudgeAdjustA=0.0
JudgeAdjustB=0.0
# Touch screen delay, unit is milliseconds, one second = 1000 milliseconds. Must be an integer
TouchDelay=0
# Window the game
Windowed=false
# Width and height for windowed mode, rendering resolution for fullscreen mode
# If set to 0, windowed mode will remember the user-set size, fullscreen mode will use the current display resolution
Width=0
Height=0
# ===================================
# Save some potentially unnecessary time

View File

@ -88,6 +88,12 @@ JudgeAdjustA=0.0
JudgeAdjustB=0.0
# 触摸屏延迟,单位为毫秒,一秒 = 1000 毫秒。必须是整数
TouchDelay=0
# 窗口化游戏
Windowed=false
# 宽度和高度窗口化时为游戏窗口大小,全屏时为渲染分辨率
# 如果设为 0窗口化将记住用户设定的大小全屏时将使用当前显示器分辨率
Width=0
Height=0
# ===================================
# 节省一些不知道有用没用的时间

View File

@ -57,6 +57,9 @@ namespace AquaMai
public float JudgeAdjustA { get; set; }
public float JudgeAdjustB { get; set; }
public int TouchDelay { get; set; }
public bool Windowed { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
public class TimeSavingConfig

View File

@ -73,7 +73,6 @@ namespace AquaMai
{
Patch(directiveType);
}
else MelonLogger.Error($"Type not found for {categoryProp.Name}.{settingProp.Name}");
}
}
}
@ -119,6 +118,7 @@ namespace AquaMai
// Fixes that does not have side effects
// These don't need to be configurable
WindowState.Execute();
// Helpers
Patch(typeof(MessageHelper));
Patch(typeof(MusicDirHelper));

View File

@ -0,0 +1,82 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using UnityEngine;
namespace AquaMai.Utils;
public class WindowState
{
private const int GWL_STYLE = -16;
private const int WS_WHATEVER = 0x14CF0000;
private static IntPtr hwnd = IntPtr.Zero;
public static void Execute()
{
if (AquaMai.AppConfig.Utils.Windowed)
{
var alreadyWindowed = Screen.fullScreenMode == FullScreenMode.Windowed;
if (AquaMai.AppConfig.Utils.Width == 0 || AquaMai.AppConfig.Utils.Height == 0)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
}
else
{
alreadyWindowed = false;
Screen.SetResolution(AquaMai.AppConfig.Utils.Width, AquaMai.AppConfig.Utils.Height, FullScreenMode.Windowed);
}
hwnd = GetWindowHandle();
if(alreadyWindowed)
{
SetResizeable();
}
else
{
Task.Run(async () =>
{
await Task.Delay(3000);
// Screen.SetResolution has delay
SetResizeable();
});
}
}
else
{
var width = AquaMai.AppConfig.Utils.Width == 0 ? Display.main.systemWidth : AquaMai.AppConfig.Utils.Width;
var height = AquaMai.AppConfig.Utils.Height == 0 ? Display.main.systemHeight : AquaMai.AppConfig.Utils.Height;
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow);
}
}
public static void SetResizeable()
{
if (hwnd == IntPtr.Zero) return;
SetWindowLongPtr(hwnd, GWL_STYLE, WS_WHATEVER);
}
private delegate bool EnumThreadDelegate(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
[DllImport("Kernel32.dll")]
static extern int GetCurrentThreadId();
static IntPtr GetWindowHandle()
{
IntPtr returnHwnd = IntPtr.Zero;
var threadId = GetCurrentThreadId();
EnumThreadWindows(threadId,
(hWnd, lParam) =>
{
if (returnHwnd == IntPtr.Zero) returnHwnd = hWnd;
return true;
}, IntPtr.Zero);
return returnHwnd;
}
[DllImport("user32.dll")]
static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, int dwNewLong);
}