forked from akanyan/mu3-mods
fix(TestMenuScaling): a better way
This commit is contained in:
@ -1,95 +1,14 @@
|
|||||||
using MU3.CustomUI;
|
using UnityEngine;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace MU3.TestMode;
|
namespace MU3.TestMode;
|
||||||
|
|
||||||
class patch_TestModeObject: TestModeObject {
|
class patch_TestModeObject: TestModeObject {
|
||||||
private List<MU3Text> _titleList;
|
protected extern void orig_initializeParamater();
|
||||||
private List<ItemText> _itemList;
|
|
||||||
|
|
||||||
protected override void initializeParamater() {
|
protected override void initializeParamater() {
|
||||||
if(_font != null) {
|
orig_initializeParamater();
|
||||||
_defaultFont = _font;
|
|
||||||
}
|
|
||||||
_canvasSize = new Vector2(Screen.width, Screen.height);
|
|
||||||
|
|
||||||
CanvasScaler canvasScaler = Utility.findParentRecursive<CanvasScaler>(transform);
|
Canvas canvas = Utility.findParentRecursive<Canvas>(transform);
|
||||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
|
canvas.transform.localScale = new Vector2(1, 1);
|
||||||
canvasScaler.enabled = true;
|
canvas.transform.localPosition = new Vector2(540, 960);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,14 @@
|
|||||||
using MonoMod;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace MU3.TestMode;
|
namespace MU3.TestMode;
|
||||||
|
|
||||||
class patch_TestModePage: TestModePage {
|
class patch_TestModePage: TestModePage {
|
||||||
private ItemDefine[] _itemDefines;
|
private Vector3 _cursorOffset;
|
||||||
|
|
||||||
[MonoModIgnore]
|
protected extern void orig_initializeParamater();
|
||||||
protected extern float scaleCorrection();
|
protected override void initializeParamater() {
|
||||||
|
orig_initializeParamater();
|
||||||
|
|
||||||
protected extern void orig_createItems();
|
_cursorOffset = new Vector3(-48f * Screen.height / 1920f, 0f, 0f);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user