1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 04:13:32 +08:00
This commit is contained in:
2024-09-24 21:24:21 +08:00
parent 53ba10bb23
commit 9d5af1c340
10 changed files with 194 additions and 85 deletions

View File

@@ -8,14 +8,19 @@ namespace UXAssist.UI;
// MyCheckBox modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyCheckBox.cs
public class MyCheckBox : MonoBehaviour
{
public UIButton uiButton;
public Image checkImage;
public RectTransform rectTrans;
public UIButton uiButton;
public Image boxImage;
public Image checkImage;
public Text labelText;
public event Action OnChecked;
protected event Action OnFree;
private bool _checked;
private static readonly Color BoxColor = new Color(1f, 1f, 1f, 100f / 255f);
private static readonly Color CheckColor = new Color(1f, 1f, 1f, 1f);
private static readonly Color TextColor = new Color(178f / 255f, 178f / 255f, 178f / 255f, 168f / 255f);
protected void OnDestroy()
{
OnFree?.Invoke();
@@ -31,6 +36,23 @@ public class MyCheckBox : MonoBehaviour
}
}
public void SetEnable(bool on)
{
if (uiButton) uiButton.enabled = on;
if (on)
{
if (boxImage) boxImage.color = BoxColor;
if (checkImage) checkImage.color = CheckColor;
if (labelText) labelText.color = TextColor;
}
else
{
if (boxImage) boxImage.color = BoxColor.RGBMultiplied(0.5f);
if (checkImage) checkImage.color = CheckColor.RGBMultiplied(0.5f);
if (labelText) labelText.color = TextColor.RGBMultiplied(0.5f);
}
}
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, ConfigEntry<bool> config, string label = "", int fontSize = 15)
{
var cb = CreateCheckBox(x, y, parent, config.Value, label, fontSize);
@@ -54,6 +76,7 @@ public class MyCheckBox : MonoBehaviour
cb.rectTrans = rect;
cb.uiButton = go.GetComponent<UIButton>();
cb.boxImage = go.transform.GetComponent<Image>();
cb.checkImage = go.transform.Find("checked")?.GetComponent<Image>();
var child = go.transform.Find("text");

View File

@@ -8,12 +8,31 @@ namespace UXAssist.UI;
public class MySlider : MonoBehaviour
{
public Slider slider;
public RectTransform rectTrans;
public Slider slider;
public RectTransform handleSlideArea;
public Text labelText;
public string labelFormat;
public event Action OnValueChanged;
private float _value;
public void SetEnable(bool on)
{
lock (this)
{
if (slider) slider.interactable = on;
}
}
public MySlider MakeHandleSmaller(float deltaX = 10f, float deltaY = 0f)
{
var oldSize = slider.handleRect.sizeDelta;
slider.handleRect.sizeDelta = new Vector2(oldSize.x - deltaX, oldSize.y - deltaY);
handleSlideArea.offsetMin = new Vector2(handleSlideArea.offsetMin.x - deltaX / 2, handleSlideArea.offsetMin.y);
handleSlideArea.offsetMax = new Vector2(handleSlideArea.offsetMax.x + deltaX / 2, handleSlideArea.offsetMax.y);
return this;
}
public float Value
{
get => _value;
@@ -48,7 +67,7 @@ public class MySlider : MonoBehaviour
sl.slider.onValueChanged.RemoveAllListeners();
sl.slider.onValueChanged.AddListener(sl.SliderChanged);
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
if (sl.labelText != null)
if (sl.labelText)
{
sl.labelText.fontSize = 14;
if (sl.labelText.transform is RectTransform rectTrans)
@@ -57,6 +76,8 @@ public class MySlider : MonoBehaviour
}
}
sl.labelFormat = format;
sl.handleSlideArea = sl.transform.Find("Handle Slide Area")?.GetComponent<RectTransform>();
var bg = sl.slider.transform.Find("Background")?.GetComponent<Image>();
if (bg != null)

View File

@@ -22,7 +22,7 @@ public class MyWindow : ManualBehaviour
protected const float TabHeight = 27f;
protected const float Margin = 30f;
protected const float Spacing = 10f;
protected event Action OnFree;
public event Action OnFree;
public override void _OnFree()
{