mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-02-04 13:12:17 +08:00
ui fix
This commit is contained in:
@@ -10,7 +10,6 @@ public class MyComboBox : MonoBehaviour
|
||||
{
|
||||
private RectTransform _rectTrans;
|
||||
private UIComboBox _comboBox;
|
||||
private Text _text;
|
||||
public Action<int> OnSelChanged;
|
||||
|
||||
private static GameObject _baseObject;
|
||||
@@ -34,7 +33,6 @@ public class MyComboBox : MonoBehaviour
|
||||
if (fontSource)
|
||||
{
|
||||
var txtComp = cbctrl.m_ListItemRes.GetComponentInChildren<Text>();
|
||||
UXAssist.Logger.LogDebug($"txtComp: [{txtComp}]");
|
||||
if (txtComp)
|
||||
{
|
||||
txtComp.font = fontSource.font;
|
||||
@@ -42,7 +40,6 @@ public class MyComboBox : MonoBehaviour
|
||||
txtComp.fontStyle = fontSource.fontStyle;
|
||||
}
|
||||
txtComp = rect.Find("Main Button/Text")?.GetComponent<Text>();
|
||||
UXAssist.Logger.LogDebug($"txtComp: [{txtComp}]");
|
||||
if (txtComp)
|
||||
{
|
||||
txtComp.font = fontSource.font;
|
||||
@@ -63,8 +60,6 @@ public class MyComboBox : MonoBehaviour
|
||||
var cb = gameObject.AddComponent<MyComboBox>();
|
||||
var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||
cb._rectTrans = rtrans;
|
||||
cb._text = gameObject.transform.Find("Main Button/Text")?.GetComponent<Text>();
|
||||
UXAssist.Logger.LogDebug($"cb._text: [{cb._text}]");
|
||||
var box = rtrans.GetComponent<UIComboBox>();
|
||||
cb._comboBox = box;
|
||||
box.onItemIndexChange.AddListener(() => { cb.OnSelChanged?.Invoke(box.itemIndex); });
|
||||
@@ -81,21 +76,11 @@ public class MyComboBox : MonoBehaviour
|
||||
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 + 5f + 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>();
|
||||
@@ -137,12 +122,6 @@ public class MyComboBox : MonoBehaviour
|
||||
config.SettingChanged += _configChanged;
|
||||
}
|
||||
|
||||
public MyComboBox WithPrompt(string prompt)
|
||||
{
|
||||
SetPrompt(prompt);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyComboBox WithFontSize(int size)
|
||||
{
|
||||
SetFontSize(size);
|
||||
|
||||
@@ -25,9 +25,10 @@ public class MyConfigWindow : MyWindowWithTabs
|
||||
base._OnCreate();
|
||||
_windowTrans = GetComponent<RectTransform>();
|
||||
OnUICreated?.Invoke(this, _windowTrans);
|
||||
AutoFitWindowSize();
|
||||
SetCurrentTab(0);
|
||||
OnUpdateUI?.Invoke();
|
||||
// Delay 500ms to run AutoFitWindowSize() after the window is created
|
||||
// Invoke(nameof(AutoFitWindowSize), 0f);
|
||||
}
|
||||
|
||||
public override void _OnDestroy()
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MyWindow : ManualBehaviour
|
||||
var go = Instantiate(UIRoot.instance.uiGame.inserterWindow.gameObject);
|
||||
go.SetActive(false);
|
||||
go.name = "my-window";
|
||||
Destroy(go.GetComponent<UITankWindow>());
|
||||
Destroy(go.GetComponent<UIInserterWindow>());
|
||||
for (var i = go.transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var child = go.transform.GetChild(i).gameObject;
|
||||
@@ -63,6 +63,11 @@ public class MyWindow : ManualBehaviour
|
||||
return (T)win;
|
||||
}
|
||||
|
||||
public override void _OnOpen()
|
||||
{
|
||||
AutoFitWindowSize();
|
||||
}
|
||||
|
||||
public override void _OnFree()
|
||||
{
|
||||
OnFree?.Invoke();
|
||||
@@ -99,6 +104,15 @@ public class MyWindow : ManualBehaviour
|
||||
{
|
||||
var trans = GetComponent<RectTransform>();
|
||||
trans.sizeDelta = new Vector2(_maxX + Margin + TabWidth + Spacing + Margin, MaxY + TitleHeight + Margin);
|
||||
// var panelBgTrans = trans.Find("panel-bg")?.GetComponent<RectTransform>();
|
||||
// if (panelBgTrans != null)
|
||||
// {
|
||||
// panelBgTrans.anchorMax = new Vector2(0f, 1f);
|
||||
// panelBgTrans.anchorMin = new Vector2(0f, 1f);
|
||||
// panelBgTrans.pivot = new Vector2(0f, 1f);
|
||||
// panelBgTrans.localPosition = new Vector3(0f, 0f, 0f);
|
||||
// panelBgTrans.sizeDelta = new Vector2(_maxX + Margin + TabWidth + Spacing + Margin, MaxY + TitleHeight + Margin);
|
||||
// }
|
||||
}
|
||||
|
||||
private static void AddElement(float x, float y, RectTransform rect, RectTransform parent = null)
|
||||
@@ -212,9 +226,9 @@ public class MyWindow : ManualBehaviour
|
||||
return cb;
|
||||
}
|
||||
|
||||
public MyComboBox AddComboBox(float x, float y, RectTransform parent, string label = "", int fontSize = 15)
|
||||
public MyComboBox AddComboBox(float x, float y, RectTransform parent, int fontSize = 15)
|
||||
{
|
||||
var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithPrompt(label).WithFontSize(fontSize);
|
||||
var comboBox = MyComboBox.CreateComboBox(x, y, parent).WithFontSize(fontSize);
|
||||
_maxX = Math.Max(_maxX, x + comboBox.Width);
|
||||
MaxY = Math.Max(MaxY, y + comboBox.Height);
|
||||
return comboBox;
|
||||
|
||||
@@ -333,7 +333,8 @@ public static class UIConfigWindow
|
||||
x = 0f;
|
||||
}
|
||||
y += 36f;
|
||||
wnd.AddComboBox(x + 2f, y, tab1, "Process priority").WithItems("High", "Above Normal", "Normal", "Below Normal", "Idle").WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority);
|
||||
txt = wnd.AddText2(x + 2f, y, tab1, "Process priority", 15, "process-priority");
|
||||
wnd.AddComboBox(x + 7f + txt.preferredWidth, y, tab1).WithItems("High", "Above Normal", "Normal", "Below Normal", "Idle").WithSize(100f, 0f).WithConfigEntry(WindowFunctions.ProcessPriority);
|
||||
|
||||
var tab2 = wnd.AddTab(trans, "Factory");
|
||||
x = 0f;
|
||||
|
||||
Reference in New Issue
Block a user