diff --git a/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModeObject.cs b/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModeObject.cs new file mode 100644 index 0000000..44d8256 --- /dev/null +++ b/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModeObject.cs @@ -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 _titleList; + private List _itemList; + + protected override void initializeParamater() { + if(_font != null) { + _defaultFont = _font; + } + _canvasSize = new Vector2(Screen.width, Screen.height); + + CanvasScaler canvasScaler = Utility.findParentRecursive(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; + } +} diff --git a/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModePage.cs b/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModePage.cs new file mode 100644 index 0000000..27e0d3d --- /dev/null +++ b/Fixes/TestMenuScaling/MU3.TestMode/patch_TestModePage.cs @@ -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); + } + } + } +} diff --git a/Fixes/TestMenuScaling/TestMenuScaling.csproj b/Fixes/TestMenuScaling/TestMenuScaling.csproj new file mode 100644 index 0000000..debf823 --- /dev/null +++ b/Fixes/TestMenuScaling/TestMenuScaling.csproj @@ -0,0 +1,8 @@ + + + Assembly-CSharp.TestMenuScaling.mm + Test menu scaling + fixes + + + \ No newline at end of file diff --git a/Mu3Mods.sln b/Mu3Mods.sln index cdfcea3..39e0c02 100644 --- a/Mu3Mods.sln +++ b/Mu3Mods.sln @@ -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