mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 15:33:31 +08:00
work in progress
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MySideSlider : MonoBehaviour
|
||||
if (sl.slider.transform is RectTransform rectTrans)
|
||||
{
|
||||
rectTrans.localPosition = new Vector3(width, rectTrans.localPosition.y, rectTrans.localPosition.z);
|
||||
rectTrans.sizeDelta = new Vector2(textWidth <= 0f ? width + 5f : width, rectTrans.sizeDelta.y);
|
||||
rectTrans.sizeDelta = new Vector2(width, rectTrans.sizeDelta.y);
|
||||
}
|
||||
sl.Value = 0f;
|
||||
|
||||
@@ -52,8 +52,12 @@ public class MySideSlider : MonoBehaviour
|
||||
{
|
||||
rectTrans2.sizeDelta = new Vector2(textWidth, rectTrans2.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectTrans2.sizeDelta = new Vector2(-textWidth, rectTrans2.sizeDelta.y);
|
||||
}
|
||||
rectTrans2.pivot = new Vector2(0f, 1f);
|
||||
rectTrans2.localPosition = new Vector3(width, rectTrans2.localPosition.y, rectTrans2.localPosition.z);
|
||||
rectTrans2.localPosition = new Vector3(textWidth <= 0f ? width + 10f : width, rectTrans2.localPosition.y, rectTrans2.localPosition.z);
|
||||
}
|
||||
sl.labelFormat = "G";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user