1
0
forked from akanyan/mu3-mods

feat: implement TestMenuScaling

This commit is contained in:
2025-01-02 00:15:40 +00:00
parent 414bb35f9a
commit f7f3503d56
4 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,95 @@
using MU3.CustomUI;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MU3.TestMode;
class patch_TestModeObject: TestModeObject {
private List<MU3Text> _titleList;
private List<ItemText> _itemList;
protected override void initializeParamater() {
if(_font != null) {
_defaultFont = _font;
}
_canvasSize = new Vector2(Screen.width, Screen.height);
CanvasScaler canvasScaler = Utility.findParentRecursive<CanvasScaler>(transform);
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
canvasScaler.enabled = true;
canvasScaler.scaleFactor = scaleCorrection();
_topPositionY = _canvasSize.y * (1f - _topMargin);
_labelPositionX = _canvasSize.x * _leftMargin;
_labelSizeX = _canvasSize.x * _labelWidth;
_labelFullSizeX = _canvasSize.x * (1f - _leftMargin - _rightMargin);
_valuePositionX = _canvasSize.x * (_leftMargin + _labelWidth);
_valueSizeX = _canvasSize.x * (1f - _leftMargin - _rightMargin - _labelWidth);
}
protected extern void orig_createTitle();
protected override void createTitle() {
orig_createTitle();
float num = _canvasSize.y * (1f - _topMargin);
foreach(var title in _titleList) {
title.transform.position = new Vector3(title.transform.position.x, num, 0f);
num -= 36f * scaleCorrection();
}
}
protected extern void orig_createItems();
protected override void createItems() {
orig_createItems();
for(int i = 0; i < _itemNum; i++) {
float y = _topPositionY - (float)((i + _itemTopLine) * 36f * scaleCorrection());
var item = _itemList[i];
item.labelText.transform.position = new Vector3(item.labelText.transform.position.x, y, 0f);
foreach(var value in item.valueTextList) {
value.transform.position = new Vector3(value.transform.position.x, y);
}
}
}
protected extern void orig_createInstruction();
protected new void createInstruction() {
orig_createInstruction();
float y = _canvasSize.y * _bottomMargin + 36f * scaleCorrection();
_instructionText.transform.position = new Vector3(_instructionText.transform.position.x, y, 0f);
}
protected extern MU3Text orig_makeText();
protected new MU3Text makeText() {
var mU3Text = orig_makeText();
if(Screen.height < 1920.0f - float.Epsilon) {
mU3Text.fontSize = (int)Math.Round(32 * ppiCorrection());
} else {
mU3Text.fontSize = 32;
}
return mU3Text;
}
protected float scaleCorrection() {
return Screen.height / 1920.0f;
}
protected float ppiCorrection() {
return Mathf.Sqrt(scaleCorrection());
}
public new void changeTextLayoutHorizontal(MU3Text text, float left, float width) {
RectTransform rectTransform = text.transform as RectTransform;
Vector3 position = rectTransform.transform.position;
Vector2 sizeDelta = rectTransform.sizeDelta;
position.x = 1080f * left;
sizeDelta.x = 1080f * width;
rectTransform.transform.position = position;
rectTransform.sizeDelta = sizeDelta;
}
}

View File

@ -0,0 +1,29 @@
using MonoMod;
using UnityEngine;
namespace MU3.TestMode;
class patch_TestModePage: TestModePage {
private ItemDefine[] _itemDefines;
[MonoModIgnore]
protected extern float scaleCorrection();
protected extern void orig_createItems();
protected override void createItems() {
orig_createItems();
for(int i = 0; i < _itemDefines.Length; i++) {
ItemDefine itemDefine = _itemDefines[i];
Item item = _itemList[i];
float y = _topPositionY - (float)((itemDefine.lineNumber + _itemTopLine) * 36f * scaleCorrection());
item.labelText.transform.position = new Vector3(item.labelText.transform.position.x, y, 0f);
foreach(var valueItem in item.valueTextList) {
Vector2 sizeDelta = valueItem.rectTransform.sizeDelta;
valueItem.transform.position = new Vector3(valueItem.transform.position.x, y, 0f);
}
}
}
}

View File

@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<AssemblyName>Assembly-CSharp.TestMenuScaling.mm</AssemblyName>
<Description>Test menu scaling</Description>
<OutCategory>fixes</OutCategory>
</PropertyGroup>
<Import Project="..\..\Mu3Mods.csproj" />
</Project>

View File

@ -46,6 +46,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkipCutscenes", "Extras\Ski
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blacklist", "Extras\Blacklist\Blacklist.csproj", "{9053743F-24B5-4A39-838E-964091AC7FF0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestMenuScaling", "Fixes\TestMenuScaling\TestMenuScaling.csproj", "{8053743F-24B5-4A39-838E-964091AC7FF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -140,6 +142,10 @@ Global
{9053743F-24B5-4A39-838E-964091AC7FF0}.Debug|x64.Build.0 = Debug|x64
{9053743F-24B5-4A39-838E-964091AC7FF0}.Release|x64.ActiveCfg = Release|x64
{9053743F-24B5-4A39-838E-964091AC7FF0}.Release|x64.Build.0 = Release|x64
{8053743F-24B5-4A39-838E-964091AC7FF1}.Debug|x64.ActiveCfg = Debug|x64
{8053743F-24B5-4A39-838E-964091AC7FF1}.Debug|x64.Build.0 = Debug|x64
{8053743F-24B5-4A39-838E-964091AC7FF1}.Release|x64.ActiveCfg = Release|x64
{8053743F-24B5-4A39-838E-964091AC7FF1}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE