mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 05:33:37 +08:00
Work in progress for UXAssist 1.2.5
This commit is contained in:
@@ -14,16 +14,78 @@ public class MyCheckBox : MonoBehaviour
|
||||
public Image checkImage;
|
||||
public Text labelText;
|
||||
public event Action OnChecked;
|
||||
protected event Action OnFree;
|
||||
private bool _checked;
|
||||
|
||||
private static GameObject _baseObject;
|
||||
|
||||
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);
|
||||
|
||||
public static void InitBaseObject()
|
||||
{
|
||||
if (_baseObject) return;
|
||||
var go = Instantiate(UIRoot.instance.uiGame.buildMenu.uxFacilityCheck.gameObject);
|
||||
go.name = "my-checkbox";
|
||||
go.SetActive(false);
|
||||
var comp = go.transform.Find("text");
|
||||
if (comp)
|
||||
{
|
||||
var txt = comp.GetComponent<Text>();
|
||||
if (txt) txt.text = "";
|
||||
var localizer = comp.GetComponent<Localizer>();
|
||||
if (localizer) DestroyImmediate(localizer);
|
||||
}
|
||||
_baseObject = go;
|
||||
}
|
||||
|
||||
protected void OnDestroy()
|
||||
{
|
||||
OnFree?.Invoke();
|
||||
_config.SettingChanged -= _configChanged;
|
||||
}
|
||||
|
||||
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, ConfigEntry<bool> config, string label = "", int fontSize = 15)
|
||||
{
|
||||
return CreateCheckBox(x, y, parent, config.Value, label, fontSize).WithConfigEntry(config);
|
||||
}
|
||||
|
||||
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, bool check, string label = "", int fontSize = 15)
|
||||
{
|
||||
return CreateCheckBox(x, y, parent, fontSize).WithCheck(check).WithLabelText(label);
|
||||
}
|
||||
|
||||
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, int fontSize = 15)
|
||||
{
|
||||
var go = Instantiate(_baseObject);
|
||||
go.name = "my-checkbox";
|
||||
go.SetActive(true);
|
||||
var cb = go.AddComponent<MyCheckBox>();
|
||||
var rect = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||
|
||||
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");
|
||||
if (child != null)
|
||||
{
|
||||
cb.labelText = child.GetComponent<Text>();
|
||||
if (cb.labelText)
|
||||
{
|
||||
cb.labelText.text = "";
|
||||
cb.labelText.fontSize = fontSize;
|
||||
cb.UpdateLabelTextWidth();
|
||||
}
|
||||
}
|
||||
|
||||
cb.uiButton.onClick += cb.OnClick;
|
||||
return cb;
|
||||
}
|
||||
|
||||
private void UpdateLabelTextWidth()
|
||||
{
|
||||
if (labelText) labelText.rectTransform.sizeDelta = new Vector2(labelText.preferredWidth, labelText.rectTransform.sizeDelta.y);
|
||||
}
|
||||
|
||||
public bool Checked
|
||||
@@ -36,6 +98,15 @@ public class MyCheckBox : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLabelText(string val)
|
||||
{
|
||||
if (labelText != null)
|
||||
{
|
||||
labelText.text = val.Translate();
|
||||
UpdateLabelTextWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnable(bool on)
|
||||
{
|
||||
if (uiButton) uiButton.enabled = on;
|
||||
@@ -53,59 +124,43 @@ public class MyCheckBox : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, ConfigEntry<bool> config, string label = "", int fontSize = 15)
|
||||
private EventHandler _configChanged;
|
||||
private Action _checkedChanged;
|
||||
private ConfigEntry<bool> _config;
|
||||
public void SetConfigEntry(ConfigEntry<bool> config)
|
||||
{
|
||||
var cb = CreateCheckBox(x, y, parent, config.Value, label, fontSize);
|
||||
cb.OnChecked += () => config.Value = !config.Value;
|
||||
EventHandler func = (_, _) => cb.Checked = config.Value;
|
||||
config.SettingChanged += func;
|
||||
cb.OnFree += () => config.SettingChanged -= func;
|
||||
return cb;
|
||||
if (_checkedChanged != null) OnChecked -= _checkedChanged;
|
||||
if (_configChanged != null) config.SettingChanged -= _configChanged;
|
||||
|
||||
_config = config;
|
||||
_checkedChanged = () => config.Value = !config.Value;
|
||||
OnChecked += _checkedChanged;
|
||||
_configChanged = (_, _) => Checked = config.Value;
|
||||
config.SettingChanged += _configChanged;
|
||||
}
|
||||
|
||||
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, bool check, string label = "", int fontSize = 15)
|
||||
public MyCheckBox WithLabelText(string val)
|
||||
{
|
||||
var buildMenu = UIRoot.instance.uiGame.buildMenu;
|
||||
var src = buildMenu.uxFacilityCheck;
|
||||
|
||||
var go = Instantiate(src.gameObject);
|
||||
go.name = "my-checkbox";
|
||||
var cb = go.AddComponent<MyCheckBox>();
|
||||
cb._checked = check;
|
||||
var rect = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||
|
||||
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");
|
||||
if (child != null)
|
||||
{
|
||||
DestroyImmediate(child.GetComponent<Localizer>());
|
||||
cb.labelText = child.GetComponent<Text>();
|
||||
cb.labelText.fontSize = fontSize;
|
||||
cb.SetLabelText(label);
|
||||
var width = cb.labelText.preferredWidth;
|
||||
cb.labelText.rectTransform.sizeDelta = new Vector2(width, cb.labelText.rectTransform.sizeDelta.y);
|
||||
}
|
||||
|
||||
//value
|
||||
cb.uiButton.onClick += cb.OnClick;
|
||||
if (cb.checkImage != null)
|
||||
{
|
||||
cb.checkImage.enabled = check;
|
||||
}
|
||||
|
||||
return cb;
|
||||
SetLabelText(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void SetLabelText(string val)
|
||||
public MyCheckBox WithCheck(bool check)
|
||||
{
|
||||
if (labelText != null)
|
||||
{
|
||||
labelText.text = val.Translate();
|
||||
}
|
||||
Checked = check;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCheckBox WithEnable(bool on)
|
||||
{
|
||||
SetEnable(on);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCheckBox WithConfigEntry(ConfigEntry<bool> config)
|
||||
{
|
||||
SetConfigEntry(config);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void OnClick(int obj)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using BepInEx.Configuration;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UXAssist.UI;
|
||||
|
||||
@@ -8,69 +11,180 @@ public class MyComboBox : MonoBehaviour
|
||||
{
|
||||
private RectTransform _rectTrans;
|
||||
private UIComboBox _comboBox;
|
||||
private Action<int> _onSelChanged;
|
||||
private Text _text;
|
||||
public Action<int> OnSelChanged;
|
||||
|
||||
private static GameObject _baseObject;
|
||||
|
||||
public static void InitBaseObject()
|
||||
{
|
||||
if (_baseObject) return;
|
||||
var fontSource = UIRoot.instance.uiGame.buildMenu.uxFacilityCheck.transform.Find("text")?.GetComponent<Text>();
|
||||
var go = Instantiate(UIRoot.instance.optionWindow.resolutionComp.transform.parent.gameObject);
|
||||
go.name = "my-combobox";
|
||||
go.SetActive(false);
|
||||
|
||||
var txt = go.GetComponent<Text>();
|
||||
if (txt) txt.text = "";
|
||||
if (txt && fontSource)
|
||||
{
|
||||
txt.font = fontSource.font;
|
||||
txt.fontSize = fontSource.fontSize;
|
||||
txt.fontStyle = fontSource.fontStyle;
|
||||
txt.color = new Color(1f, 1f, 1f, 0.6f);
|
||||
}
|
||||
var localizer = go.GetComponent<Localizer>();
|
||||
if (localizer) DestroyImmediate(localizer);
|
||||
|
||||
var rect = (RectTransform)go.transform;
|
||||
var cbctrl = rect.transform.Find("ComboBox").GetComponent<UIComboBox>();
|
||||
foreach (var button in cbctrl.ItemButtons)
|
||||
{
|
||||
Destroy(button.gameObject);
|
||||
}
|
||||
cbctrl.Items.Clear();
|
||||
cbctrl.ItemButtons.Clear();
|
||||
if (fontSource)
|
||||
{
|
||||
var txtComp = cbctrl.m_ListItemRes.GetComponentInChildren<Text>();
|
||||
if (txtComp)
|
||||
{
|
||||
txtComp.font = fontSource.font;
|
||||
txtComp.fontSize = fontSource.fontSize;
|
||||
txtComp.fontStyle = fontSource.fontStyle;
|
||||
}
|
||||
txtComp = cbctrl.transform.Find("Main Button")?.GetComponentInChildren<Text>();
|
||||
if (txtComp)
|
||||
{
|
||||
txtComp.font = fontSource.font;
|
||||
txtComp.fontSize = fontSource.fontSize;
|
||||
txtComp.fontStyle = fontSource.fontStyle;
|
||||
}
|
||||
}
|
||||
cbctrl.onSubmit.RemoveAllListeners();
|
||||
cbctrl.onItemIndexChange.RemoveAllListeners();
|
||||
_baseObject = go;
|
||||
}
|
||||
|
||||
public static MyComboBox CreateComboBox(float x, float y, RectTransform parent)
|
||||
{
|
||||
if (!_baseObject)
|
||||
{
|
||||
var go = Instantiate(UIRoot.instance.optionWindow.resolutionComp.transform.parent.gameObject);
|
||||
go.name = "my-combobox";
|
||||
var rect = (RectTransform)go.transform;
|
||||
var cbctrl = rect.transform.Find("ComboBox");
|
||||
var content = cbctrl.Find("Dropdown List ScrollBox")?.Find("Mask")?.Find("Content Panel");
|
||||
if (content != null)
|
||||
{
|
||||
for (var i = content.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var theTrans = content.GetChild(i);
|
||||
if (theTrans.name == "Item Button(Clone)")
|
||||
{
|
||||
Destroy(theTrans.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
var comboBox = cbctrl.GetComponent<UIComboBox>();
|
||||
comboBox.onSubmit.RemoveAllListeners();
|
||||
comboBox.onItemIndexChange.RemoveAllListeners();
|
||||
_baseObject = go;
|
||||
}
|
||||
var gameObject = Instantiate(_baseObject);
|
||||
gameObject.name = "my-combobox";
|
||||
gameObject.SetActive(true);
|
||||
var cb = gameObject.AddComponent<MyComboBox>();
|
||||
var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||
cb._rectTrans = rtrans;
|
||||
|
||||
var box = rtrans.transform.Find("ComboBox").GetComponent<UIComboBox>();
|
||||
cb._text = gameObject.GetComponent<Text>();
|
||||
var box = rtrans.Find("ComboBox").GetComponent<UIComboBox>();
|
||||
cb._comboBox = box;
|
||||
box.onItemIndexChange.AddListener(() => { cb._onSelChanged?.Invoke(box.itemIndex); });
|
||||
box.onItemIndexChange.AddListener(() => { cb.OnSelChanged?.Invoke(box.itemIndex); });
|
||||
cb.UpdateComboBoxPosition();
|
||||
|
||||
return cb;
|
||||
}
|
||||
|
||||
public MyComboBox SetItems(string[] items)
|
||||
|
||||
protected void OnDestroy()
|
||||
{
|
||||
_comboBox.Items = items.ToList();
|
||||
_config.SettingChanged -= _configChanged;
|
||||
}
|
||||
|
||||
private void UpdateComboBoxPosition()
|
||||
{
|
||||
var rtrans = (RectTransform)_comboBox.transform;
|
||||
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);
|
||||
}
|
||||
|
||||
public void SetPrompt(string prompt)
|
||||
{
|
||||
_text.text = prompt.Translate();
|
||||
UpdateComboBoxPosition();
|
||||
}
|
||||
|
||||
public void SetFontSize(int size)
|
||||
{
|
||||
_text.fontSize = size;
|
||||
_comboBox.ItemButtons.ForEach(b => b.GetComponentInChildren<Text>().fontSize = size);
|
||||
_comboBox.m_ListItemRes.GetComponentInChildren<Text>().fontSize = size;
|
||||
var txtComp = _comboBox.transform.Find("Main Button")?.GetComponentInChildren<Text>();
|
||||
if (txtComp) txtComp.fontSize = size;
|
||||
UpdateComboBoxPosition();
|
||||
}
|
||||
|
||||
public void SetItems(params string[] items) => _comboBox.Items = items.Select(s => s.Translate()).ToList();
|
||||
|
||||
public void SetIndex(int index) => _comboBox.itemIndex = index;
|
||||
|
||||
public void SetSize(float width, float height)
|
||||
{
|
||||
var rtrans = (RectTransform)_comboBox.transform;
|
||||
rtrans.sizeDelta = new Vector2(width > 0f ? width : rtrans.sizeDelta.x, height > 0f ? height : rtrans.sizeDelta.y);
|
||||
_rectTrans.sizeDelta = new Vector2(rtrans.localPosition.x + rtrans.sizeDelta.x, _rectTrans.sizeDelta.y);
|
||||
}
|
||||
|
||||
public void AddOnSelChanged(Action<int> action) => OnSelChanged += action;
|
||||
|
||||
private EventHandler _configChanged;
|
||||
private Action<int> _selChanged;
|
||||
private ConfigEntry<int> _config;
|
||||
public void SetConfigEntry(ConfigEntry<int> config)
|
||||
{
|
||||
if (_selChanged != null) OnSelChanged -= _selChanged;
|
||||
if (_configChanged != null) config.SettingChanged -= _configChanged;
|
||||
|
||||
_comboBox.itemIndex = config.Value;
|
||||
_config = config;
|
||||
_selChanged = value => config.Value = value;
|
||||
OnSelChanged += _selChanged;
|
||||
_configChanged = (_, _) => SetIndex(config.Value);
|
||||
config.SettingChanged += _configChanged;
|
||||
}
|
||||
|
||||
public MyComboBox WithPrompt(string prompt)
|
||||
{
|
||||
SetPrompt(prompt);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox SetIndex(int index)
|
||||
public MyComboBox WithFontSize(int size)
|
||||
{
|
||||
_comboBox.itemIndex = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox AddOnSelChanged(Action<int> action)
|
||||
{
|
||||
_onSelChanged += action;
|
||||
SetFontSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox SetSize(float width, float height)
|
||||
public MyComboBox WithItems(params string[] items)
|
||||
{
|
||||
_rectTrans.sizeDelta = new Vector2(width, height);
|
||||
SetItems(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox WithIndex(int index)
|
||||
{
|
||||
SetIndex(index);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox WithSize(float width, float height)
|
||||
{
|
||||
SetSize(width, height);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox WithOnSelChanged(params Action<int>[] action)
|
||||
{
|
||||
foreach (var act in action)
|
||||
AddOnSelChanged(act);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox WithConfigEntry(ConfigEntry<int> config)
|
||||
{
|
||||
SetConfigEntry(config);
|
||||
return this;
|
||||
}
|
||||
|
||||
public float Width => _rectTrans.sizeDelta.x;
|
||||
public float Height => _rectTrans.sizeDelta.y;
|
||||
}
|
||||
@@ -14,36 +14,13 @@ public class MySlider : MonoBehaviour
|
||||
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;
|
||||
set
|
||||
{
|
||||
_value = value;
|
||||
OnValueSet();
|
||||
}
|
||||
}
|
||||
|
||||
public static MySlider CreateSlider(float x, float y, RectTransform parent, float value, float minValue, float maxValue, string format = "G", float width = 0f)
|
||||
{
|
||||
return CreateSlider(x, y, parent, width).WithLabelFormat(format).WithMinMaxValue(minValue, maxValue).WithValue(value);
|
||||
}
|
||||
|
||||
public static MySlider CreateSlider(float x, float y, RectTransform parent, float width = 0f)
|
||||
{
|
||||
var optionWindow = UIRoot.instance.optionWindow;
|
||||
var src = optionWindow.audioVolumeComp;
|
||||
@@ -53,7 +30,6 @@ public class MySlider : MonoBehaviour
|
||||
go.name = "my-slider";
|
||||
go.SetActive(true);
|
||||
var sl = go.AddComponent<MySlider>();
|
||||
sl._value = value;
|
||||
var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent);
|
||||
sl.rectTrans = rect;
|
||||
if (width > 0)
|
||||
@@ -62,10 +38,11 @@ public class MySlider : MonoBehaviour
|
||||
}
|
||||
|
||||
sl.slider = go.GetComponent<Slider>();
|
||||
sl.slider.minValue = minValue;
|
||||
sl.slider.maxValue = maxValue;
|
||||
sl.slider.minValue = 0f;
|
||||
sl.slider.maxValue = 100f;
|
||||
sl.slider.onValueChanged.RemoveAllListeners();
|
||||
sl.slider.onValueChanged.AddListener(sl.SliderChanged);
|
||||
sl.Value = 0f;
|
||||
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
|
||||
if (sl.labelText)
|
||||
{
|
||||
@@ -75,7 +52,7 @@ public class MySlider : MonoBehaviour
|
||||
rectTrans.sizeDelta = new Vector2(22f, 22f);
|
||||
}
|
||||
}
|
||||
sl.labelFormat = format;
|
||||
sl.labelFormat = "G";
|
||||
|
||||
sl.handleSlideArea = sl.transform.Find("Handle Slide Area")?.GetComponent<RectTransform>();
|
||||
|
||||
@@ -89,35 +66,72 @@ public class MySlider : MonoBehaviour
|
||||
{
|
||||
fill.color = new Color(1f, 1f, 1f, 0.28f);
|
||||
}
|
||||
sl.OnValueSet();
|
||||
sl.UpdateLabel();
|
||||
|
||||
return sl;
|
||||
}
|
||||
public void OnValueSet()
|
||||
|
||||
public void SetEnable(bool on)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
var sliderVal = _value;
|
||||
if (slider) slider.interactable = on;
|
||||
}
|
||||
}
|
||||
|
||||
public float Value
|
||||
{
|
||||
get => slider.value;
|
||||
set
|
||||
{
|
||||
var sliderVal = value;
|
||||
if (sliderVal.Equals(slider.value)) return;
|
||||
if (sliderVal > slider.maxValue)
|
||||
{
|
||||
_value = sliderVal = slider.maxValue;
|
||||
sliderVal = slider.maxValue;
|
||||
}
|
||||
else if (sliderVal < slider.minValue)
|
||||
{
|
||||
_value = sliderVal = slider.minValue;
|
||||
sliderVal = slider.minValue;
|
||||
}
|
||||
|
||||
slider.value = sliderVal;
|
||||
UpdateLabel();
|
||||
}
|
||||
}
|
||||
|
||||
public MySlider WithValue(float value)
|
||||
{
|
||||
Value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySlider WithMinMaxValue(float min, float max)
|
||||
{
|
||||
slider.minValue = min;
|
||||
slider.maxValue = max;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySlider WithLabelFormat(string format)
|
||||
{
|
||||
if (format == labelFormat) return this;
|
||||
labelFormat = format;
|
||||
UpdateLabel();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySlider WithEnable(bool on)
|
||||
{
|
||||
SetEnable(on);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void UpdateLabel()
|
||||
{
|
||||
if (labelText != null)
|
||||
{
|
||||
labelText.text = _value.ToString(labelFormat);
|
||||
labelText.text = slider.value.ToString(labelFormat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,13 +143,19 @@ public class MySlider : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public MySlider WithSmallerHandle(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 void SliderChanged(float val)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
var newVal = Mathf.Round(slider.value);
|
||||
if (_value.Equals(newVal)) return;
|
||||
_value = newVal;
|
||||
UpdateLabel();
|
||||
OnValueChanged?.Invoke();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using UXAssist.Common;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace UXAssist.UI;
|
||||
|
||||
@@ -23,6 +22,46 @@ public class MyWindow : ManualBehaviour
|
||||
protected const float Margin = 30f;
|
||||
protected const float Spacing = 10f;
|
||||
public event Action OnFree;
|
||||
private static GameObject _baseObject;
|
||||
|
||||
public static void InitBaseObject()
|
||||
{
|
||||
if (_baseObject) return;
|
||||
var go = Instantiate(UIRoot.instance.uiGame.tankWindow.gameObject);
|
||||
go.SetActive(false);
|
||||
go.name = "my-window";
|
||||
Destroy(go.GetComponent<UITankWindow>());
|
||||
for (var i = 0; i < go.transform.childCount; i++)
|
||||
{
|
||||
var child = go.transform.GetChild(i).gameObject;
|
||||
if (child.name != "panel-bg" && child.name != "shadow" && child.name != "panel-bg")
|
||||
{
|
||||
Destroy(child);
|
||||
}
|
||||
}
|
||||
|
||||
_baseObject = go;
|
||||
}
|
||||
|
||||
public static T Create<T>(string name, string title = "") where T : MyWindow
|
||||
{
|
||||
var go = Instantiate(_baseObject, UIRoot.instance.uiGame.transform.parent);
|
||||
go.name = name;
|
||||
go.SetActive(false);
|
||||
MyWindow win = go.AddComponent<T>();
|
||||
if (!win) return null;
|
||||
|
||||
var btn = go.transform.Find("panel-bg")?.gameObject.GetComponentInChildren<Button>();
|
||||
if (btn) btn.onClick.AddListener(win._Close);
|
||||
|
||||
win.SetTitle(title);
|
||||
win._Create();
|
||||
if (MyWindowManager.Initialized)
|
||||
{
|
||||
win._Init(win.data);
|
||||
}
|
||||
return (T)win;
|
||||
}
|
||||
|
||||
public override void _OnFree()
|
||||
{
|
||||
@@ -197,6 +236,14 @@ public class MyWindow : ManualBehaviour
|
||||
MaxY = Math.Max(MaxY, y + cb.Height);
|
||||
return cb;
|
||||
}
|
||||
|
||||
public MyComboBox AddComboBox(float x, float y, RectTransform parent, string label = "", int fontSize = 15)
|
||||
{
|
||||
var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithPrompt(label).WithFontSize(fontSize);
|
||||
_maxX = Math.Max(_maxX, x + comboBox.Width);
|
||||
MaxY = Math.Max(MaxY, y + comboBox.Height);
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
public MySlider AddSlider(float x, float y, RectTransform parent, float value, float minValue, float maxValue, string format = "G", float width = 0f)
|
||||
{
|
||||
@@ -429,55 +476,29 @@ public class MyWindowWithTabs : MyWindow
|
||||
}
|
||||
}
|
||||
|
||||
public class MyWindowManager
|
||||
public abstract class MyWindowManager
|
||||
{
|
||||
private static readonly List<ManualBehaviour> Windows = new(4);
|
||||
private static bool _initialized;
|
||||
|
||||
public static bool Initialized { get; private set; }
|
||||
|
||||
public static void Enable(bool on)
|
||||
{
|
||||
Patch.Enable(on);
|
||||
}
|
||||
|
||||
public static void InitBaseObjects()
|
||||
{
|
||||
MyWindow.InitBaseObject();
|
||||
MyCheckBox.InitBaseObject();
|
||||
MyComboBox.InitBaseObject();
|
||||
}
|
||||
|
||||
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow
|
||||
{
|
||||
var srcWin = UIRoot.instance.uiGame.tankWindow;
|
||||
var src = srcWin.gameObject;
|
||||
var go = Object.Instantiate(src, UIRoot.instance.uiGame.transform.parent);
|
||||
go.name = name;
|
||||
go.SetActive(false);
|
||||
Object.Destroy(go.GetComponent<UITankWindow>());
|
||||
var win = go.AddComponent<T>() as MyWindow;
|
||||
if (win == null)
|
||||
return null;
|
||||
|
||||
for (var i = 0; i < go.transform.childCount; i++)
|
||||
{
|
||||
var child = go.transform.GetChild(i).gameObject;
|
||||
if (child.name == "panel-bg")
|
||||
{
|
||||
var btn = child.GetComponentInChildren<Button>();
|
||||
//close-btn
|
||||
if (btn)
|
||||
{
|
||||
btn.onClick.AddListener(win._Close);
|
||||
}
|
||||
}
|
||||
else if (child.name != "shadow" && child.name != "panel-bg")
|
||||
{
|
||||
Object.Destroy(child);
|
||||
}
|
||||
}
|
||||
|
||||
win.SetTitle(title);
|
||||
win._Create();
|
||||
if (_initialized)
|
||||
{
|
||||
win._Init(win.data);
|
||||
}
|
||||
|
||||
Windows.Add(win);
|
||||
return (T)win;
|
||||
var win = MyWindow.Create<T>(name, title);
|
||||
if (win) Windows.Add(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
public static void DestroyWindow(ManualBehaviour win)
|
||||
@@ -506,13 +527,13 @@ public class MyWindowManager
|
||||
|
||||
private static void InitAllWindows()
|
||||
{
|
||||
if (_initialized) return;
|
||||
if (Initialized) return;
|
||||
if (!UIRoot.instance) return;
|
||||
foreach (var win in Windows)
|
||||
{
|
||||
win._Init(win.data);
|
||||
}
|
||||
_initialized = true;
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user