forked from akanyan/mu3-mods
feat: implement TestMenuScaling
This commit is contained in:
95
Fixes/TestMenuScaling/MU3.TestMode/patch_TestModeObject.cs
Normal file
95
Fixes/TestMenuScaling/MU3.TestMode/patch_TestModeObject.cs
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user