mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 02:13:29 +08:00
Work in progress for UXAssist 1.2.5
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
## Changlog
|
## Changlog
|
||||||
|
|
||||||
* 1.2.5
|
* 1.2.5
|
||||||
|
+ New feature: `Set process priority`
|
||||||
|
+ New feature: `Set enabled CPU threads`
|
||||||
+ `Drag building power poles in maximum connection range`: Add a new config option `Build Tesla Tower and Wireless Power Tower alternately`
|
+ `Drag building power poles in maximum connection range`: Add a new config option `Build Tesla Tower and Wireless Power Tower alternately`
|
||||||
* 1.2.4
|
* 1.2.4
|
||||||
+ `Sunlight at night`:
|
+ `Sunlight at night`:
|
||||||
@@ -201,6 +203,8 @@
|
|||||||
## 更新日志
|
## 更新日志
|
||||||
|
|
||||||
* 1.2.5
|
* 1.2.5
|
||||||
|
+ 新功能:`设置进程优先级`
|
||||||
|
+ 新功能:`设置使用的CPU线程`
|
||||||
+ `拖动建造电线杆时自动使用最大连接距离间隔`:添加一个新的设置项`交替建造电力感应塔和无线输电塔`
|
+ `拖动建造电线杆时自动使用最大连接距离间隔`:添加一个新的设置项`交替建造电力感应塔和无线输电塔`
|
||||||
* 1.2.4
|
* 1.2.4
|
||||||
+ `夜间日光灯`:
|
+ `夜间日光灯`:
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ public static class WinApi
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Priorities
|
||||||
|
|
||||||
|
public const int HIGH_PRIORITY_CLASS = 0x00000080;
|
||||||
|
public const int ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000;
|
||||||
|
public const int NORMAL_PRIORITY_CLASS = 0x00000020;
|
||||||
|
public const int BELOW_NORMAL_PRIORITY_CLASS = 0x00004000;
|
||||||
|
public const int IDLE_PRIORITY_CLASS = 0x00000040;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Messages
|
#region Messages
|
||||||
|
|
||||||
public const int WM_CREATE = 0x0001;
|
public const int WM_CREATE = 0x0001;
|
||||||
@@ -113,13 +123,13 @@ public static class WinApi
|
|||||||
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
|
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
|
||||||
|
|
||||||
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
||||||
public static extern bool GetProcessAffinityMask(IntPtr hProcess, out IntPtr lpProcessAffinityMask, out IntPtr lpSystemAffinityMask);
|
public static extern bool GetProcessAffinityMask(IntPtr hProcess, out ulong lpProcessAffinityMask, out ulong lpSystemAffinityMask);
|
||||||
|
|
||||||
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
||||||
public static extern IntPtr GetCurrentProcess();
|
public static extern IntPtr GetCurrentProcess();
|
||||||
|
|
||||||
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
||||||
public static extern bool SetProcessAffinityMask(IntPtr hProcess, IntPtr dwProcessAffinityMask);
|
public static extern bool SetProcessAffinityMask(IntPtr hProcess, ulong dwProcessAffinityMask);
|
||||||
|
|
||||||
// GetPriorityClass and SetPriorityClass
|
// GetPriorityClass and SetPriorityClass
|
||||||
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
|
||||||
@@ -17,6 +18,23 @@ public static class WindowFunctions
|
|||||||
private static IntPtr _gameWindowHandle = IntPtr.Zero;
|
private static IntPtr _gameWindowHandle = IntPtr.Zero;
|
||||||
|
|
||||||
private static bool _gameLoaded;
|
private static bool _gameLoaded;
|
||||||
|
public static WinApi.LogicalProcessorDetails ProcessorDetails { get; private set; }
|
||||||
|
|
||||||
|
public static ConfigEntry<int> ProcessPriority;
|
||||||
|
public static ConfigEntry<int> ProcessAffinity;
|
||||||
|
|
||||||
|
private static readonly int[] ProrityFlags = [
|
||||||
|
WinApi.HIGH_PRIORITY_CLASS,
|
||||||
|
WinApi.ABOVE_NORMAL_PRIORITY_CLASS,
|
||||||
|
WinApi.NORMAL_PRIORITY_CLASS,
|
||||||
|
WinApi.BELOW_NORMAL_PRIORITY_CLASS,
|
||||||
|
WinApi.IDLE_PRIORITY_CLASS
|
||||||
|
];
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
ProcessorDetails = WinApi.GetLogicalProcessorDetails();
|
||||||
|
}
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
@@ -28,6 +46,39 @@ public static class WindowFunctions
|
|||||||
_oldWndProc = WinApi.SetWindowLongPtr(gameWnd, WinApi.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc));
|
_oldWndProc = WinApi.SetWindowLongPtr(gameWnd, WinApi.GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc));
|
||||||
}
|
}
|
||||||
Patches.GamePatch.LoadLastWindowRect.MoveWindowPosition(true);
|
Patches.GamePatch.LoadLastWindowRect.MoveWindowPosition(true);
|
||||||
|
|
||||||
|
ProcessPriority.SettingChanged += (_, _) => WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]);
|
||||||
|
WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]);
|
||||||
|
ProcessAffinity.SettingChanged += (_, _) => UpdateAffinity();
|
||||||
|
UpdateAffinity();
|
||||||
|
return;
|
||||||
|
|
||||||
|
void UpdateAffinity()
|
||||||
|
{
|
||||||
|
var process = WinApi.GetCurrentProcess();
|
||||||
|
if (!WinApi.GetProcessAffinityMask(process, out _, out var systemMask))
|
||||||
|
{
|
||||||
|
systemMask = ulong.MaxValue;
|
||||||
|
}
|
||||||
|
switch (ProcessAffinity.Value)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
WinApi.SetProcessAffinityMask(process, systemMask);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
WinApi.SetProcessAffinityMask(process, systemMask & ((1UL << (ProcessorDetails.ThreadCount / 2)) - 1UL));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
WinApi.SetProcessAffinityMask(process, systemMask & (ProcessorDetails.ThreadCount > 16 ? 0xFFUL : 1UL));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
WinApi.SetProcessAffinityMask(process, systemMask & ProcessorDetails.PerformanceCoreMask);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
WinApi.SetProcessAffinityMask(process, systemMask & ProcessorDetails.EfficiencyCoreMask);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
|
private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
|
||||||
@@ -35,8 +86,7 @@ public static class WindowFunctions
|
|||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WinApi.WM_ACTIVATE:
|
case WinApi.WM_ACTIVATE:
|
||||||
// UXAssist.Logger.LogDebug($"Activate: {wParam.ToInt32()}, {lParam.ToInt32()}");
|
WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), ProrityFlags[ProcessPriority.Value]);
|
||||||
// TODO: Set Priority like: WinApi.SetPriorityClass(WinApi.GetCurrentProcess(), 0x00000080);
|
|
||||||
break;
|
break;
|
||||||
case WinApi.WM_DESTROY:
|
case WinApi.WM_DESTROY:
|
||||||
if (_oldWndProc != IntPtr.Zero && _gameWindowHandle != IntPtr.Zero)
|
if (_oldWndProc != IntPtr.Zero && _gameWindowHandle != IntPtr.Zero)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
- This will not affect some game animations.
|
- This will not affect some game animations.
|
||||||
- When set game speed in mod `Auxilaryfunction`, this feature will be disabled.
|
- When set game speed in mod `Auxilaryfunction`, this feature will be disabled.
|
||||||
- When mod `BulletTime` is installed, this feature will be hidden, but patch `BulletTime`'s speed control, to make its maximum speed 10x.
|
- When mod `BulletTime` is installed, this feature will be hidden, but patch `BulletTime`'s speed control, to make its maximum speed 10x.
|
||||||
|
- Set process priority
|
||||||
|
- Set enabled CPU threads
|
||||||
- Increase maximum count of Metadata Instantiations to 20000 (from 2000)
|
- Increase maximum count of Metadata Instantiations to 20000 (from 2000)
|
||||||
- Increase capacity of player order queue to 128 (from 16)
|
- Increase capacity of player order queue to 128 (from 16)
|
||||||
+ Planet/Factory
|
+ Planet/Factory
|
||||||
@@ -147,6 +149,8 @@
|
|||||||
- 这不会影响一些游戏动画
|
- 这不会影响一些游戏动画
|
||||||
- 当在`Auxilaryfunction`mod中设置游戏速度时,此功能将被禁用
|
- 当在`Auxilaryfunction`mod中设置游戏速度时,此功能将被禁用
|
||||||
- 当安装了`BulletTime`mod时,此功能将被隐藏,但会对`BulletTime`的速度控制打补丁,使其最大速度变为10倍
|
- 当安装了`BulletTime`mod时,此功能将被隐藏,但会对`BulletTime`的速度控制打补丁,使其最大速度变为10倍
|
||||||
|
- 设置进程优先级
|
||||||
|
- 设置使用的CPU线程
|
||||||
- 将元数据提取的最大数量增加到20000(原来为2000)
|
- 将元数据提取的最大数量增加到20000(原来为2000)
|
||||||
- 将玩家指令队列的容量增加到128(原来为16)
|
- 将玩家指令队列的容量增加到128(原来为16)
|
||||||
+ 行星/工厂
|
+ 行星/工厂
|
||||||
|
|||||||
@@ -14,16 +14,78 @@ public class MyCheckBox : MonoBehaviour
|
|||||||
public Image checkImage;
|
public Image checkImage;
|
||||||
public Text labelText;
|
public Text labelText;
|
||||||
public event Action OnChecked;
|
public event Action OnChecked;
|
||||||
protected event Action OnFree;
|
|
||||||
private bool _checked;
|
private bool _checked;
|
||||||
|
|
||||||
|
private static GameObject _baseObject;
|
||||||
|
|
||||||
private static readonly Color BoxColor = new Color(1f, 1f, 1f, 100f / 255f);
|
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 CheckColor = new Color(1f, 1f, 1f, 1f);
|
||||||
private static readonly Color TextColor = new Color(178f / 255f, 178f / 255f, 178f / 255f, 168f / 255f);
|
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()
|
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
|
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)
|
public void SetEnable(bool on)
|
||||||
{
|
{
|
||||||
if (uiButton) uiButton.enabled = 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);
|
if (_checkedChanged != null) OnChecked -= _checkedChanged;
|
||||||
cb.OnChecked += () => config.Value = !config.Value;
|
if (_configChanged != null) config.SettingChanged -= _configChanged;
|
||||||
EventHandler func = (_, _) => cb.Checked = config.Value;
|
|
||||||
config.SettingChanged += func;
|
_config = config;
|
||||||
cb.OnFree += () => config.SettingChanged -= func;
|
_checkedChanged = () => config.Value = !config.Value;
|
||||||
return cb;
|
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;
|
SetLabelText(val);
|
||||||
var src = buildMenu.uxFacilityCheck;
|
return this;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetLabelText(string val)
|
public MyCheckBox WithCheck(bool check)
|
||||||
{
|
{
|
||||||
if (labelText != null)
|
Checked = check;
|
||||||
{
|
return this;
|
||||||
labelText.text = val.Translate();
|
}
|
||||||
}
|
|
||||||
|
public MyCheckBox WithEnable(bool on)
|
||||||
|
{
|
||||||
|
SetEnable(on);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyCheckBox WithConfigEntry(ConfigEntry<bool> config)
|
||||||
|
{
|
||||||
|
SetConfigEntry(config);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClick(int obj)
|
public void OnClick(int obj)
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace UXAssist.UI;
|
namespace UXAssist.UI;
|
||||||
|
|
||||||
@@ -8,69 +11,180 @@ public class MyComboBox : MonoBehaviour
|
|||||||
{
|
{
|
||||||
private RectTransform _rectTrans;
|
private RectTransform _rectTrans;
|
||||||
private UIComboBox _comboBox;
|
private UIComboBox _comboBox;
|
||||||
private Action<int> _onSelChanged;
|
private Text _text;
|
||||||
|
public Action<int> OnSelChanged;
|
||||||
|
|
||||||
private static GameObject _baseObject;
|
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)
|
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);
|
var gameObject = Instantiate(_baseObject);
|
||||||
gameObject.name = "my-combobox";
|
gameObject.name = "my-combobox";
|
||||||
|
gameObject.SetActive(true);
|
||||||
var cb = gameObject.AddComponent<MyComboBox>();
|
var cb = gameObject.AddComponent<MyComboBox>();
|
||||||
var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
var rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||||
cb._rectTrans = rtrans;
|
cb._rectTrans = rtrans;
|
||||||
|
cb._text = gameObject.GetComponent<Text>();
|
||||||
var box = rtrans.transform.Find("ComboBox").GetComponent<UIComboBox>();
|
var box = rtrans.Find("ComboBox").GetComponent<UIComboBox>();
|
||||||
cb._comboBox = box;
|
cb._comboBox = box;
|
||||||
box.onItemIndexChange.AddListener(() => { cb._onSelChanged?.Invoke(box.itemIndex); });
|
box.onItemIndexChange.AddListener(() => { cb.OnSelChanged?.Invoke(box.itemIndex); });
|
||||||
|
cb.UpdateComboBoxPosition();
|
||||||
|
|
||||||
return cb;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyComboBox SetIndex(int index)
|
public MyComboBox WithFontSize(int size)
|
||||||
{
|
{
|
||||||
_comboBox.itemIndex = index;
|
SetFontSize(size);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyComboBox AddOnSelChanged(Action<int> action)
|
public MyComboBox WithItems(params string[] items)
|
||||||
{
|
{
|
||||||
_onSelChanged += action;
|
SetItems(items);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyComboBox SetSize(float width, float height)
|
public MyComboBox WithIndex(int index)
|
||||||
{
|
{
|
||||||
_rectTrans.sizeDelta = new Vector2(width, height);
|
SetIndex(index);
|
||||||
return this;
|
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 Text labelText;
|
||||||
public string labelFormat;
|
public string labelFormat;
|
||||||
public event Action OnValueChanged;
|
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)
|
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 optionWindow = UIRoot.instance.optionWindow;
|
||||||
var src = optionWindow.audioVolumeComp;
|
var src = optionWindow.audioVolumeComp;
|
||||||
@@ -53,7 +30,6 @@ public class MySlider : MonoBehaviour
|
|||||||
go.name = "my-slider";
|
go.name = "my-slider";
|
||||||
go.SetActive(true);
|
go.SetActive(true);
|
||||||
var sl = go.AddComponent<MySlider>();
|
var sl = go.AddComponent<MySlider>();
|
||||||
sl._value = value;
|
|
||||||
var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent);
|
var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent);
|
||||||
sl.rectTrans = rect;
|
sl.rectTrans = rect;
|
||||||
if (width > 0)
|
if (width > 0)
|
||||||
@@ -62,10 +38,11 @@ public class MySlider : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
sl.slider = go.GetComponent<Slider>();
|
sl.slider = go.GetComponent<Slider>();
|
||||||
sl.slider.minValue = minValue;
|
sl.slider.minValue = 0f;
|
||||||
sl.slider.maxValue = maxValue;
|
sl.slider.maxValue = 100f;
|
||||||
sl.slider.onValueChanged.RemoveAllListeners();
|
sl.slider.onValueChanged.RemoveAllListeners();
|
||||||
sl.slider.onValueChanged.AddListener(sl.SliderChanged);
|
sl.slider.onValueChanged.AddListener(sl.SliderChanged);
|
||||||
|
sl.Value = 0f;
|
||||||
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
|
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
|
||||||
if (sl.labelText)
|
if (sl.labelText)
|
||||||
{
|
{
|
||||||
@@ -75,7 +52,7 @@ public class MySlider : MonoBehaviour
|
|||||||
rectTrans.sizeDelta = new Vector2(22f, 22f);
|
rectTrans.sizeDelta = new Vector2(22f, 22f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sl.labelFormat = format;
|
sl.labelFormat = "G";
|
||||||
|
|
||||||
sl.handleSlideArea = sl.transform.Find("Handle Slide Area")?.GetComponent<RectTransform>();
|
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);
|
fill.color = new Color(1f, 1f, 1f, 0.28f);
|
||||||
}
|
}
|
||||||
sl.OnValueSet();
|
|
||||||
sl.UpdateLabel();
|
sl.UpdateLabel();
|
||||||
|
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
public void OnValueSet()
|
|
||||||
|
public void SetEnable(bool on)
|
||||||
{
|
{
|
||||||
lock (this)
|
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.Equals(slider.value)) return;
|
||||||
if (sliderVal > slider.maxValue)
|
if (sliderVal > slider.maxValue)
|
||||||
{
|
{
|
||||||
_value = sliderVal = slider.maxValue;
|
sliderVal = slider.maxValue;
|
||||||
}
|
}
|
||||||
else if (sliderVal < slider.minValue)
|
else if (sliderVal < slider.minValue)
|
||||||
{
|
{
|
||||||
_value = sliderVal = slider.minValue;
|
sliderVal = slider.minValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
slider.value = sliderVal;
|
slider.value = sliderVal;
|
||||||
UpdateLabel();
|
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()
|
public void UpdateLabel()
|
||||||
{
|
{
|
||||||
if (labelText != null)
|
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)
|
public void SliderChanged(float val)
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (this)
|
||||||
{
|
{
|
||||||
var newVal = Mathf.Round(slider.value);
|
|
||||||
if (_value.Equals(newVal)) return;
|
|
||||||
_value = newVal;
|
|
||||||
UpdateLabel();
|
UpdateLabel();
|
||||||
OnValueChanged?.Invoke();
|
OnValueChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ using UnityEngine;
|
|||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using Object = UnityEngine.Object;
|
|
||||||
|
|
||||||
namespace UXAssist.UI;
|
namespace UXAssist.UI;
|
||||||
|
|
||||||
@@ -23,6 +22,46 @@ public class MyWindow : ManualBehaviour
|
|||||||
protected const float Margin = 30f;
|
protected const float Margin = 30f;
|
||||||
protected const float Spacing = 10f;
|
protected const float Spacing = 10f;
|
||||||
public event Action OnFree;
|
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()
|
public override void _OnFree()
|
||||||
{
|
{
|
||||||
@@ -198,6 +237,14 @@ public class MyWindow : ManualBehaviour
|
|||||||
return cb;
|
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)
|
public MySlider AddSlider(float x, float y, RectTransform parent, float value, float minValue, float maxValue, string format = "G", float width = 0f)
|
||||||
{
|
{
|
||||||
var slider = MySlider.CreateSlider(x, y, parent, value, minValue, maxValue, format, width);
|
var slider = MySlider.CreateSlider(x, y, parent, value, minValue, maxValue, format, width);
|
||||||
@@ -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 readonly List<ManualBehaviour> Windows = new(4);
|
||||||
private static bool _initialized;
|
|
||||||
|
public static bool Initialized { get; private set; }
|
||||||
|
|
||||||
public static void Enable(bool on)
|
public static void Enable(bool on)
|
||||||
{
|
{
|
||||||
Patch.Enable(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
|
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow
|
||||||
{
|
{
|
||||||
var srcWin = UIRoot.instance.uiGame.tankWindow;
|
var win = MyWindow.Create<T>(name, title);
|
||||||
var src = srcWin.gameObject;
|
if (win) Windows.Add(win);
|
||||||
var go = Object.Instantiate(src, UIRoot.instance.uiGame.transform.parent);
|
return win;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DestroyWindow(ManualBehaviour win)
|
public static void DestroyWindow(ManualBehaviour win)
|
||||||
@@ -506,13 +527,13 @@ public class MyWindowManager
|
|||||||
|
|
||||||
private static void InitAllWindows()
|
private static void InitAllWindows()
|
||||||
{
|
{
|
||||||
if (_initialized) return;
|
if (Initialized) return;
|
||||||
if (!UIRoot.instance) return;
|
if (!UIRoot.instance) return;
|
||||||
foreach (var win in Windows)
|
foreach (var win in Windows)
|
||||||
{
|
{
|
||||||
win._Init(win.data);
|
win._Init(win.data);
|
||||||
}
|
}
|
||||||
_initialized = true;
|
Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using UXAssist.UI;
|
using UXAssist.UI;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using UXAssist.Functions;
|
using UXAssist.Functions;
|
||||||
@@ -36,6 +35,19 @@ public static class UIConfigWindow
|
|||||||
I18N.Add("Default profile name", "Default profile name", "默认配置档案名");
|
I18N.Add("Default profile name", "Default profile name", "默认配置档案名");
|
||||||
I18N.Add("Logical Frame Rate", "Logical Frame Rate", "逻辑帧倍率");
|
I18N.Add("Logical Frame Rate", "Logical Frame Rate", "逻辑帧倍率");
|
||||||
I18N.Add("Reset", "Reset", "重置");
|
I18N.Add("Reset", "Reset", "重置");
|
||||||
|
I18N.Add("Process priority", "Process priority", "进程优先级");
|
||||||
|
I18N.Add("High", "High", "高");
|
||||||
|
I18N.Add("Above Normal", "Above Normal", "高于正常");
|
||||||
|
I18N.Add("Normal", "Normal", "正常");
|
||||||
|
I18N.Add("Below Normal", "Below Normal", "低于正常");
|
||||||
|
I18N.Add("Idle", "Idle", "空闲");
|
||||||
|
I18N.Add("Enabled CPUs", "Enabled CPU Threads", "使用CPU线程");
|
||||||
|
I18N.Add("All CPUs", "All CPUs", "所有CPU");
|
||||||
|
I18N.Add("First {0} CPUs", "First {0} CPUs", "前{0}个CPU");
|
||||||
|
I18N.Add("First 8 CPUs", "First 8 CPUs", "前8个CPU");
|
||||||
|
I18N.Add("First CPU only", "First CPU only", "仅第一个CPU");
|
||||||
|
I18N.Add("All P-Cores", "All P-Cores", "所有性能(P)核心");
|
||||||
|
I18N.Add("All E-Cores", "All E-Cores", "所有效率(E)核心");
|
||||||
I18N.Add("Unlimited interactive range", "Unlimited interactive range", "无限交互距离");
|
I18N.Add("Unlimited interactive range", "Unlimited interactive range", "无限交互距离");
|
||||||
I18N.Add("Night Light", "Sunlight at night", "夜间日光灯");
|
I18N.Add("Night Light", "Sunlight at night", "夜间日光灯");
|
||||||
I18N.Add("Angle X:", "Angle X:", "入射角度X:");
|
I18N.Add("Angle X:", "Angle X:", "入射角度X:");
|
||||||
@@ -155,18 +167,16 @@ public static class UIConfigWindow
|
|||||||
*/
|
*/
|
||||||
y += 36f;
|
y += 36f;
|
||||||
wnd.AddCheckBox(x, y, tab1, GamePatch.ConvertSavesFromPeaceEnabled, "Convert old saves to Combat Mode on loading");
|
wnd.AddCheckBox(x, y, tab1, GamePatch.ConvertSavesFromPeaceEnabled, "Convert old saves to Combat Mode on loading");
|
||||||
|
|
||||||
MyCheckBox checkBoxForMeasureTextWidth;
|
MyCheckBox checkBoxForMeasureTextWidth;
|
||||||
if (WindowFunctions.ProfileName != null)
|
if (WindowFunctions.ProfileName != null)
|
||||||
{
|
{
|
||||||
y += 36f;
|
y += 36f;
|
||||||
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedSaveFolderEnabled, "Profile-based save folder");
|
checkBoxForMeasureTextWidth = wnd.AddCheckBox(x, y, tab1, GamePatch.ProfileBasedSaveFolderEnabled, "Profile-based save folder");
|
||||||
wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based save folder", "Profile-based save folder tips", "btn-profile-based-save-folder-tips");
|
wnd.AddTipsButton2(checkBoxForMeasureTextWidth.Width + 5f, y + 6f, tab1, "Profile-based save folder", "Profile-based save folder tips", "btn-profile-based-save-folder-tips");
|
||||||
x = 0;
|
|
||||||
y += 30f;
|
y += 30f;
|
||||||
wnd.AddText2(x, y, tab1, "Default profile name", 15, "text-default-profile-name");
|
wnd.AddText2(x + 2f, y, tab1, "Default profile name", 15, "text-default-profile-name");
|
||||||
y += 24f;
|
y += 24f;
|
||||||
wnd.AddInputField(x, y, 200f, tab1, GamePatch.DefaultProfileName, 15, "input-profile-save-folder");
|
wnd.AddInputField(x + 2f, y, 200f, tab1, GamePatch.DefaultProfileName, 15, "input-profile-save-folder");
|
||||||
y += 18f;
|
y += 18f;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -179,10 +189,30 @@ public static class UIConfigWindow
|
|||||||
y += 36f;
|
y += 36f;
|
||||||
txt = wnd.AddText2(x + 2f, y, tab1, "Logical Frame Rate", 15, "game-frame-rate");
|
txt = wnd.AddText2(x + 2f, y, tab1, "Logical Frame Rate", 15, "game-frame-rate");
|
||||||
x += txt.preferredWidth + 7f;
|
x += txt.preferredWidth + 7f;
|
||||||
wnd.AddSlider(x, y + 6f, tab1, GamePatch.GameUpsFactor, new UpsMapper(), "0.0x", 100f).MakeHandleSmaller();
|
wnd.AddSlider(x, y + 6f, tab1, GamePatch.GameUpsFactor, new UpsMapper(), "0.0x", 100f).WithSmallerHandle();
|
||||||
var btn = wnd.AddFlatButton(x + 104f, y + 6f, tab1, "Reset", 13, "reset-game-frame-rate", () => GamePatch.GameUpsFactor.Value = 1.0f);
|
var btn = wnd.AddFlatButton(x + 104f, y + 6f, tab1, "Reset", 13, "reset-game-frame-rate", () => GamePatch.GameUpsFactor.Value = 1.0f);
|
||||||
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
|
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
|
||||||
|
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);
|
||||||
|
var details = WindowFunctions.ProcessorDetails;
|
||||||
|
string[] affinities;
|
||||||
|
if (details.HybridArchitecture)
|
||||||
|
{
|
||||||
|
affinities = new string[5];
|
||||||
|
affinities[3] = "All P-Cores";
|
||||||
|
affinities[4] = "All E-Cores";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
affinities = new string[3];
|
||||||
|
}
|
||||||
|
affinities[0] = "All CPUs";
|
||||||
|
affinities[1] = string.Format("First {0} CPUs".Translate(), details.ThreadCount / 2);
|
||||||
|
affinities[2] = details.ThreadCount > 16 ? "First 8 CPUs" : "First CPU only";
|
||||||
|
y += 36f;
|
||||||
|
wnd.AddComboBox(x + 2f, y, tab1, "Enabled CPUs").WithItems(affinities).WithSize(200f, 0f).WithConfigEntry(WindowFunctions.ProcessAffinity);
|
||||||
|
|
||||||
var tab2 = wnd.AddTab(trans, "Planet/Factory");
|
var tab2 = wnd.AddTab(trans, "Planet/Factory");
|
||||||
x = 0f;
|
x = 0f;
|
||||||
@@ -195,10 +225,10 @@ public static class UIConfigWindow
|
|||||||
x += checkBoxForMeasureTextWidth.Width + 5f + 10f;
|
x += checkBoxForMeasureTextWidth.Width + 5f + 10f;
|
||||||
txt = wnd.AddText2(x, y + 2f, tab2, "Angle X:", 13, "text-nightlight-angle-x");
|
txt = wnd.AddText2(x, y + 2f, tab2, "Angle X:", 13, "text-nightlight-angle-x");
|
||||||
x += txt.preferredWidth + 5f;
|
x += txt.preferredWidth + 5f;
|
||||||
wnd.AddSlider(x, y + 7f, tab2, FactoryPatch.NightLightAngleX, new AngleMapper(), "0", 60f).MakeHandleSmaller();
|
wnd.AddSlider(x, y + 7f, tab2, FactoryPatch.NightLightAngleX, new AngleMapper(), "0", 60f).WithSmallerHandle();
|
||||||
x += 70f;
|
x += 70f;
|
||||||
txt = wnd.AddText2(x, y + 2f, tab2, "Y:", 13, "text-nightlight-angle-y");
|
txt = wnd.AddText2(x, y + 2f, tab2, "Y:", 13, "text-nightlight-angle-y");
|
||||||
wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryPatch.NightLightAngleY, new AngleMapper(), "0", 60f).MakeHandleSmaller();
|
wnd.AddSlider(x + txt.preferredWidth + 5f, y + 7f, tab2, FactoryPatch.NightLightAngleY, new AngleMapper(), "0", 60f).WithSmallerHandle();
|
||||||
x = 0;
|
x = 0;
|
||||||
y += 36f;
|
y += 36f;
|
||||||
wnd.AddCheckBox(x, y, tab2, FactoryPatch.LargerAreaForUpgradeAndDismantleEnabled, "Larger area for upgrade and dismantle");
|
wnd.AddCheckBox(x, y, tab2, FactoryPatch.LargerAreaForUpgradeAndDismantleEnabled, "Larger area for upgrade and dismantle");
|
||||||
|
|||||||
@@ -86,6 +86,15 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
|||||||
"Convert saves from Peace mode to Combat mode on save loading");
|
"Convert saves from Peace mode to Combat mode on save loading");
|
||||||
GamePatch.GameUpsFactor = _dummyConfig.Bind("Game", "GameUpsFactor", 1.0,
|
GamePatch.GameUpsFactor = _dummyConfig.Bind("Game", "GameUpsFactor", 1.0,
|
||||||
"Game UPS factor (1.0 for normal speed)");
|
"Game UPS factor (1.0 for normal speed)");
|
||||||
|
WindowFunctions.ProcessPriority = Config.Bind("Game", "ProcessPriority", 2,
|
||||||
|
new ConfigDescription("Game process priority\n 0: High 1: Above Normal 2: Normal 3: Below Normal 4: Idle", new AcceptableValueRange<int>(0, 4)));
|
||||||
|
WindowFunctions.ProcessAffinity = Config.Bind("Game", "CPUAffinity", -1,
|
||||||
|
new ConfigDescription("""
|
||||||
|
Game process CPU affinity
|
||||||
|
0: All 1: First-half CPUs 2. First 8 CPUs (if total CPUs are greater than 16)
|
||||||
|
3. All Performance Cores(If Intel 13th or greater) 4. All Efficiency Cores(If Intel 13th or greater)
|
||||||
|
""", new AcceptableValueRange<int>(0, 4)));
|
||||||
|
|
||||||
FactoryPatch.UnlimitInteractiveEnabled = Config.Bind("Factory", "UnlimitInteractive", false,
|
FactoryPatch.UnlimitInteractiveEnabled = Config.Bind("Factory", "UnlimitInteractive", false,
|
||||||
"Unlimit interactive range");
|
"Unlimit interactive range");
|
||||||
FactoryPatch.RemoveSomeConditionEnabled = Config.Bind("Factory", "RemoveSomeBuildConditionCheck", false,
|
FactoryPatch.RemoveSomeConditionEnabled = Config.Bind("Factory", "RemoveSomeBuildConditionCheck", false,
|
||||||
@@ -174,6 +183,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
MyWindowManager.InitBaseObjects();
|
||||||
MyWindowManager.Enable(true);
|
MyWindowManager.Enable(true);
|
||||||
UIPatch.Enable(true);
|
UIPatch.Enable(true);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>net472</TargetFramework>
|
<TargetFramework>net472</TargetFramework>
|
||||||
<BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid>
|
<BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid>
|
||||||
<Description>DSP MOD - UXAssist</Description>
|
<Description>DSP MOD - UXAssist</Description>
|
||||||
<Version>1.2.4</Version>
|
<Version>1.2.5</Version>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<PackageId>UXAssist</PackageId>
|
<PackageId>UXAssist</PackageId>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "UXAssist",
|
"name": "UXAssist",
|
||||||
"version_number": "1.2.4",
|
"version_number": "1.2.5",
|
||||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist",
|
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist",
|
||||||
"description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁",
|
"description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|||||||
Reference in New Issue
Block a user