1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 21:33:28 +08:00

UXAssist v1.3.3

This commit is contained in:
2025-05-10 00:50:11 +08:00
parent ac2cc258ee
commit c7465133f7
8 changed files with 438 additions and 300 deletions

View File

@@ -5,7 +5,6 @@ using UnityEngine.UI;
namespace UXAssist.UI;
// MyCheckButton modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyCheckButton.cs
public class MyCheckButton : MonoBehaviour
{
public RectTransform rectTrans;

View File

@@ -0,0 +1,95 @@
using System;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.UI;
namespace UXAssist.UI;
public class MyFlatButton : MonoBehaviour
{
public RectTransform rectTrans;
public UIButton uiButton;
public Text labelText;
private static GameObject _baseObject;
public static void InitBaseObject()
{
if (_baseObject) return;
var panel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.layerPanel;
var go = Instantiate(panel.layerButtons[0].gameObject);
var btn = go.GetComponent<UIButton>();
btn.gameObject.name = "my-flatbutton";
btn.highlighted = false;
var img = btn.GetComponent<Image>();
if (img != null)
{
img.sprite = panel.buttonDefaultSprite;
img.color = new Color(img.color.r, img.color.g, img.color.b, 13f / 255f);
}
img = btn.gameObject.transform.Find("frame")?.GetComponent<Image>();
if (img != null)
{
img.color = new Color(img.color.r, img.color.g, img.color.b, 0f);
}
btn.button.onClick.RemoveAllListeners();
_baseObject = go;
}
public static MyFlatButton CreateFlatButton(float x, float y, RectTransform parent, string label = "", int fontSize = 15, Action<int> onClick = null)
{
return CreateFlatButton(x, y, parent, fontSize, onClick).WithLabelText(label);
}
public static MyFlatButton CreateFlatButton(float x, float y, RectTransform parent, int fontSize = 15, Action<int> onClick = null)
{
var go = Instantiate(_baseObject);
go.name = "my-flatbutton";
go.SetActive(true);
var cb = go.AddComponent<MyFlatButton>();
var rect = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
cb.rectTrans = rect;
cb.uiButton = go.GetComponent<UIButton>();
cb.labelText = go.transform.Find("Text")?.GetComponent<Text>();
cb.uiButton.onClick += onClick;
return cb;
}
public void SetLabelText(string val)
{
if (labelText != null)
{
labelText.text = val.Translate();
}
}
public MyFlatButton WithLabelText(string val)
{
SetLabelText(val);
return this;
}
public MyFlatButton WithSize(float width, float height)
{
rectTrans.sizeDelta = new Vector2(width, height);
return this;
}
public MyFlatButton WithTip(string tip, float delay = 1f)
{
uiButton.tips.type = UIButton.ItemTipType.Other;
uiButton.tips.topLevel = true;
uiButton.tips.tipTitle = tip;
uiButton.tips.tipText = null;
uiButton.tips.delay = delay;
uiButton.tips.corner = 2;
uiButton.UpdateTip();
return this;
}
public float Width => rectTrans.sizeDelta.x + labelText.rectTransform.sizeDelta.x;
public float Height => Math.Max(rectTrans.sizeDelta.y, labelText.rectTransform.sizeDelta.y);
}

View File

@@ -194,38 +194,13 @@ public class MyWindow : ManualBehaviour
return btn;
}
public UIButton AddFlatButton(float x, float y, RectTransform parent, string text = "", int fontSize = 12, string objName = "button", UnityAction onClick = null)
public MyFlatButton AddFlatButton(float x, float y, RectTransform parent, string text = "", int fontSize = 12, string objName = "button", UnityAction onClick = null)
{
var panel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.layerPanel;
var btn = Instantiate(panel.layerButtons[0]);
var btn = MyFlatButton.CreateFlatButton(x, y, parent, text, fontSize, _ => onClick());
btn.gameObject.name = objName;
btn.highlighted = false;
var img = btn.GetComponent<Image>();
if (img != null)
{
img.sprite = panel.buttonDefaultSprite;
img.color = new Color(img.color.r, img.color.g, img.color.b, 13f / 255f);
}
img = btn.gameObject.transform.Find("frame")?.GetComponent<Image>();
if (img != null)
{
img.color = new Color(img.color.r, img.color.g, img.color.b, 0f);
}
var rect = Util.NormalizeRectWithTopLeft(btn, x, y, parent);
var t = btn.gameObject.transform.Find("Text")?.GetComponent<Text>();
if (t != null)
{
t.text = text.Translate();
t.fontSize = fontSize;
}
btn.button.onClick.RemoveAllListeners();
if (onClick != null) btn.button.onClick.AddListener(onClick);
_maxX = Math.Max(_maxX, x + rect.sizeDelta.x);
MaxY = Math.Max(MaxY, y + rect.sizeDelta.y);
_maxX = Math.Max(_maxX, x + btn.Width);
MaxY = Math.Max(MaxY, y + btn.Height);
return btn;
}
@@ -568,6 +543,7 @@ public abstract class MyWindowManager
MyCheckBox.InitBaseObject();
MyComboBox.InitBaseObject();
MyCornerComboBox.InitBaseObject();
MyFlatButton.InitBaseObject();
}
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow