1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-05 07:02:17 +08:00

work in progress

This commit is contained in:
2025-04-20 20:36:52 +08:00
parent f32b11f49a
commit 3d54a1a83e
10 changed files with 227 additions and 102 deletions

View File

@@ -93,7 +93,7 @@ public class MyComboBox : MonoBehaviour
var oldPosition = rtrans.localPosition;
var pwidth = _text.preferredWidth;
rtrans.localPosition = new Vector3(pwidth + 5f, oldPosition.y, oldPosition.z);
_rectTrans.sizeDelta = new Vector2(rtrans.localPosition.x + rtrans.sizeDelta.x, _rectTrans.sizeDelta.y);
_rectTrans.sizeDelta = new Vector2(rtrans.localPosition.x + 5f + rtrans.sizeDelta.x, _rectTrans.sizeDelta.y);
}
public void SetPrompt(string prompt)
@@ -112,7 +112,12 @@ public class MyComboBox : MonoBehaviour
UpdateComboBoxPosition();
}
public void SetItems(params string[] items) => _comboBox.Items = items.Select(s => s.Translate()).ToList();
public void SetItems(params string[] items)
{
_comboBox.Items = [.. items.Select(s => s.Translate())];
_comboBox.StartItemIndex = 0;
_comboBox.DropDownCount = Math.Min(items.Length, 8);
}
public void SetIndex(int index) => _comboBox.itemIndex = index;

View File

@@ -245,6 +245,14 @@ public class MyWindow : ManualBehaviour
return comboBox;
}
public MySmallComboBox AddSmallComboBox(float x, float y, RectTransform parent, int fontSize = 15)
{
var comboBox = MySmallComboBox.CreateComboBox(x, y, parent).WithFontSize(fontSize);
_maxX = Math.Max(_maxX, x + comboBox.Width);
MaxY = Math.Max(MaxY, y + comboBox.Height);
return comboBox;
}
#region Slider
public class ValueMapper<T>
{
@@ -315,9 +323,9 @@ public class MyWindow : ManualBehaviour
return slider;
}
public MySlider AddSlider<T>(float x, float y, RectTransform parent, ConfigEntry<T> config, ValueMapper<T> valueMapper, string format = "G", float width = 0f, float textWidth = 0f)
public MySlider AddSlider<T>(float x, float y, RectTransform parent, ConfigEntry<T> config, ValueMapper<T> valueMapper, string format = "G", float width = 0f)
{
var slider = MySlider.CreateSlider(x, y, parent, OnConfigValueChanged(config), valueMapper.Min, valueMapper.Max, format, width, textWidth);
var slider = MySlider.CreateSlider(x, y, parent, OnConfigValueChanged(config), valueMapper.Min, valueMapper.Max, format, width);
slider.SetLabelText(valueMapper.FormatValue(format, config.Value));
config.SettingChanged += SettingsChanged;
OnFree += () => config.SettingChanged -= SettingsChanged;
@@ -558,6 +566,7 @@ public abstract class MyWindowManager
MyWindow.InitBaseObject();
MyCheckBox.InitBaseObject();
MyComboBox.InitBaseObject();
MySmallComboBox.InitBaseObject();
}
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow

View File

@@ -19,6 +19,20 @@ public static class Util
return rect;
}
public static RectTransform NormalizeRectWithTopRight(Component cmp, float right, float top, Transform parent = null)
{
if (cmp.transform is not RectTransform rect) return null;
if (parent != null)
{
rect.SetParent(parent, false);
}
rect.anchorMax = new Vector2(1f, 1f);
rect.anchorMin = new Vector2(1f, 1f);
rect.pivot = new Vector2(1f, 1f);
rect.anchoredPosition3D = new Vector3(-right, -top, 0f);
return rect;
}
public static RectTransform NormalizeRectWithBottomLeft(Component cmp, float left, float bottom, Transform parent = null)
{
if (cmp.transform is not RectTransform rect) return null;