mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 22:13:30 +08:00
work in progress
This commit is contained in:
@@ -89,6 +89,10 @@ public static class LogisticsPatch
|
||||
{
|
||||
RealtimeLogisticsInfoPanel.StationInfoPanelsUpdate();
|
||||
}
|
||||
if (LogisticsCapacityTweaksEnabled.Value && VFInput.onGUI && !VFInput.inputing)
|
||||
{
|
||||
LogisticsCapacityTweaks.UpdateInput();
|
||||
}
|
||||
}
|
||||
|
||||
private class AutoConfigLogistics: PatchImpl<AutoConfigLogistics>
|
||||
|
||||
@@ -70,10 +70,7 @@ public static class PlayerPatch
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (_toggleAllStarsNameKey.keyValue)
|
||||
{
|
||||
ShortcutKeysForStarsName.ToggleAllStarsName();
|
||||
}
|
||||
ShortcutKeysForStarsName.OnUpdate();
|
||||
if (_autoDriveKey.keyValue)
|
||||
{
|
||||
AutoNavigation.ToggleAutoCruise();
|
||||
@@ -156,12 +153,28 @@ public static class PlayerPatch
|
||||
public class ShortcutKeysForStarsName: PatchImpl<ShortcutKeysForStarsName>
|
||||
{
|
||||
private static int _showAllStarsNameStatus;
|
||||
private static bool _forceShowAllStarsName;
|
||||
private static bool _forceShowAllStarsNameExternal;
|
||||
|
||||
public static void ToggleAllStarsName()
|
||||
{
|
||||
_showAllStarsNameStatus = (_showAllStarsNameStatus + 1) % 3;
|
||||
}
|
||||
|
||||
public static void SetForceShowAllStarsNameExternal(bool value)
|
||||
{
|
||||
_forceShowAllStarsNameExternal = value;
|
||||
}
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (_toggleAllStarsNameKey.keyValue)
|
||||
{
|
||||
ToggleAllStarsName();
|
||||
}
|
||||
_forceShowAllStarsName = _forceShowAllStarsNameExternal || _showAllStarsNameKey.IsKeyPressing();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIStarmap), nameof(UIStarmap._OnClose))]
|
||||
private static void UIStarmap__OnClose_Postfix()
|
||||
@@ -189,8 +202,7 @@ public static class PlayerPatch
|
||||
new CodeInstruction(OpCodes.Ldc_I4_1),
|
||||
new CodeInstruction(OpCodes.Ceq),
|
||||
new CodeInstruction(OpCodes.Brtrue, jumpPos.Value),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllStarsNameKey))),
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch.ShortcutKeysForStarsName), nameof(_forceShowAllStarsName))),
|
||||
new CodeInstruction(OpCodes.Brtrue, jumpPos.Value),
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(ShortcutKeysForStarsName), nameof(_showAllStarsNameStatus))),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_2),
|
||||
|
||||
143
UXAssist/UI/MyCornerComboBox.cs
Normal file
143
UXAssist/UI/MyCornerComboBox.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UXAssist.UI;
|
||||
|
||||
public class MyCornerComboBox : MonoBehaviour
|
||||
{
|
||||
private RectTransform _rectTrans;
|
||||
private UIComboBox _comboBox;
|
||||
public Action<int> OnSelChanged;
|
||||
|
||||
private static GameObject _baseObject;
|
||||
|
||||
public static void InitBaseObject()
|
||||
{
|
||||
if (_baseObject) return;
|
||||
var go = Instantiate(UIRoot.instance.uiGame.starDetail.displayCombo.gameObject);
|
||||
go.name = "my-small-combobox";
|
||||
go.SetActive(false);
|
||||
|
||||
var cbctrl = go.transform.GetComponent<UIComboBox>();
|
||||
foreach (var button in cbctrl.ItemButtons)
|
||||
{
|
||||
Destroy(button.gameObject);
|
||||
}
|
||||
cbctrl.Items.Clear();
|
||||
cbctrl.ItemButtons.Clear();
|
||||
cbctrl.onSubmit.RemoveAllListeners();
|
||||
cbctrl.onItemIndexChange.RemoveAllListeners();
|
||||
_baseObject = go;
|
||||
}
|
||||
|
||||
public static MyCornerComboBox CreateComboBox(float x, float y, RectTransform parent, bool topRight = false)
|
||||
{
|
||||
var gameObject = Instantiate(_baseObject);
|
||||
gameObject.name = "my-combobox";
|
||||
gameObject.SetActive(true);
|
||||
var cb = gameObject.AddComponent<MyCornerComboBox>();
|
||||
RectTransform rtrans;
|
||||
if (topRight)
|
||||
{
|
||||
rtrans = Util.NormalizeRectWithTopRight(cb, x, y, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
rtrans = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||
}
|
||||
cb._rectTrans = rtrans;
|
||||
var box = rtrans.GetComponent<UIComboBox>();
|
||||
cb._comboBox = box;
|
||||
box.onItemIndexChange.AddListener(() => { cb.OnSelChanged?.Invoke(box.itemIndex); });
|
||||
|
||||
return cb;
|
||||
}
|
||||
|
||||
protected void OnDestroy()
|
||||
{
|
||||
_config.SettingChanged -= _configChanged;
|
||||
}
|
||||
|
||||
public void SetFontSize(int size)
|
||||
{
|
||||
var textComp = _comboBox.transform.Find("Main Button")?.GetComponentInChildren<Text>();
|
||||
if (textComp) textComp.fontSize = size;
|
||||
_comboBox.ItemButtons.ForEach(b => b.GetComponentInChildren<Text>().fontSize = size);
|
||||
_comboBox.m_ListItemRes.GetComponentInChildren<Text>().fontSize = size;
|
||||
}
|
||||
|
||||
public void SetItems(params string[] items)
|
||||
{
|
||||
_comboBox.Items = [.. items.Select(s => s.Translate())];
|
||||
_comboBox.StartItemIndex = 0;
|
||||
_comboBox.DropDownCount = items.Length;
|
||||
}
|
||||
|
||||
public void SetIndex(int index) => _comboBox.itemIndex = index;
|
||||
|
||||
public void SetSize(float width, float height)
|
||||
{
|
||||
_rectTrans.sizeDelta = new Vector2(width > 0f ? width : _rectTrans.sizeDelta.x, height > 0f ? height : _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 MyCornerComboBox WithFontSize(int size)
|
||||
{
|
||||
SetFontSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCornerComboBox WithItems(params string[] items)
|
||||
{
|
||||
SetItems(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCornerComboBox WithIndex(int index)
|
||||
{
|
||||
SetIndex(index);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCornerComboBox WithSize(float width, float height)
|
||||
{
|
||||
SetSize(width, height);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCornerComboBox WithOnSelChanged(params Action<int>[] action)
|
||||
{
|
||||
foreach (var act in action)
|
||||
AddOnSelChanged(act);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyCornerComboBox WithConfigEntry(ConfigEntry<int> config)
|
||||
{
|
||||
SetConfigEntry(config);
|
||||
return this;
|
||||
}
|
||||
|
||||
public float Width => _rectTrans.sizeDelta.x;
|
||||
public float Height => _rectTrans.sizeDelta.y;
|
||||
}
|
||||
@@ -245,13 +245,13 @@ 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;
|
||||
// }
|
||||
public MyCornerComboBox AddCornerComboBox(float x, float y, RectTransform parent, int fontSize = 15)
|
||||
{
|
||||
var comboBox = MyCornerComboBox.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>
|
||||
@@ -566,7 +566,7 @@ public abstract class MyWindowManager
|
||||
MyWindow.InitBaseObject();
|
||||
MyCheckBox.InitBaseObject();
|
||||
MyComboBox.InitBaseObject();
|
||||
// MySmallComboBox.InitBaseObject();
|
||||
MyCornerComboBox.InitBaseObject();
|
||||
}
|
||||
|
||||
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow
|
||||
|
||||
@@ -9,7 +9,6 @@ using CommonAPI.Systems;
|
||||
using crecheng.DSPModSave;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Functions;
|
||||
using UXAssist.Patches;
|
||||
@@ -27,10 +26,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
public new static readonly ManualLogSource Logger =
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private static bool _configWinInitialized;
|
||||
private static MyConfigWindow _configWin;
|
||||
private static bool _initialized;
|
||||
private static PressKeyBind _toggleKey;
|
||||
private static ConfigFile _dummyConfig;
|
||||
private Type[] _patches, _compats;
|
||||
|
||||
@@ -61,13 +56,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
{
|
||||
SaveOnConfigSet = false
|
||||
};
|
||||
_toggleKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
|
||||
{
|
||||
key = new CombineKey((int)KeyCode.BackQuote, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false),
|
||||
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
|
||||
name = "OpenUXAssistConfigWindow",
|
||||
canOverride = true
|
||||
});
|
||||
GamePatch.EnableWindowResizeEnabled = Config.Bind("Game", "EnableWindowResize", false,
|
||||
"Enable game window resize (maximum box and thick frame)");
|
||||
GamePatch.LoadLastWindowRectEnabled = Config.Bind("Game", "LoadLastWindowRect", false,
|
||||
@@ -208,7 +196,6 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
|
||||
I18N.Init();
|
||||
I18N.Add("UXAssist Config", "UXAssist Config", "UX助手设置");
|
||||
I18N.Add("KEYOpenUXAssistConfigWindow", "[UXA] Open UXAssist Config Window", "[UXA] 打开UX助手设置面板");
|
||||
|
||||
// UI Patches
|
||||
GameLogic.Enable(true);
|
||||
@@ -222,14 +209,12 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
_compats?.Do(type => type.GetMethod("Init")?.Invoke(null, null));
|
||||
|
||||
I18N.Apply();
|
||||
I18N.OnInitialized += RecreateConfigWindow;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
MyWindowManager.InitBaseObjects();
|
||||
MyWindowManager.Enable(true);
|
||||
UIPatch.Enable(true);
|
||||
|
||||
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null));
|
||||
|
||||
@@ -248,148 +233,11 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
|
||||
private void Update()
|
||||
{
|
||||
LogisticsPatch.OnUpdate();
|
||||
if (VFInput.inputing) return;
|
||||
if (VFInput.onGUI)
|
||||
{
|
||||
LogisticsPatch.LogisticsCapacityTweaks.UpdateInput();
|
||||
}
|
||||
if (_toggleKey.keyValue)
|
||||
{
|
||||
ToggleConfigWindow();
|
||||
}
|
||||
UIFunctions.OnUpdate();
|
||||
GamePatch.OnUpdate();
|
||||
FactoryPatch.OnUpdate();
|
||||
PlayerPatch.OnUpdate();
|
||||
LogisticsPatch.OnUpdate();
|
||||
}
|
||||
|
||||
private static void ToggleConfigWindow()
|
||||
{
|
||||
if (!_configWinInitialized)
|
||||
{
|
||||
if (!I18N.Initialized()) return;
|
||||
_configWinInitialized = true;
|
||||
_configWin = MyConfigWindow.CreateInstance();
|
||||
}
|
||||
|
||||
if (_configWin.active)
|
||||
{
|
||||
_configWin._Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
_configWin.Open();
|
||||
}
|
||||
}
|
||||
|
||||
private static void RecreateConfigWindow()
|
||||
{
|
||||
if (!_configWinInitialized) return;
|
||||
var wasActive = _configWin.active;
|
||||
if (wasActive) _configWin._Close();
|
||||
MyConfigWindow.DestroyInstance(_configWin);
|
||||
_configWinInitialized = false;
|
||||
if (wasActive) ToggleConfigWindow();
|
||||
}
|
||||
|
||||
[PatchGuid(PluginInfo.PLUGIN_GUID)]
|
||||
private class UIPatch: PatchImpl<UIPatch>
|
||||
{
|
||||
private static GameObject _buttonOnPlanetGlobe;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
InitMenuButtons();
|
||||
}
|
||||
|
||||
private static void InitMenuButtons()
|
||||
{
|
||||
if (_initialized) return;
|
||||
var uiRoot = UIRoot.instance;
|
||||
if (!uiRoot) return;
|
||||
{
|
||||
var mainMenu = uiRoot.uiMainMenu;
|
||||
var src = mainMenu.newGameButton;
|
||||
var parent = src.transform.parent;
|
||||
var btn = Instantiate(src, parent);
|
||||
btn.name = "button-uxassist-config";
|
||||
var l = btn.text.GetComponent<Localizer>();
|
||||
if (l != null)
|
||||
{
|
||||
l.stringKey = "UXAssist Config";
|
||||
l.translation = "UXAssist Config".Translate();
|
||||
}
|
||||
|
||||
btn.text.text = "UXAssist Config".Translate();
|
||||
btn.text.fontSize = btn.text.fontSize * 7 / 8;
|
||||
I18N.OnInitialized += () => { btn.text.text = "UXAssist Config".Translate(); };
|
||||
var vec = ((RectTransform)mainMenu.exitButton.transform).anchoredPosition3D;
|
||||
var vec2 = ((RectTransform)mainMenu.creditsButton.transform).anchoredPosition3D;
|
||||
var transform1 = (RectTransform)btn.transform;
|
||||
transform1.anchoredPosition3D = new Vector3(vec.x, vec.y + (vec.y - vec2.y) * 2, vec.z);
|
||||
btn.button.onClick.RemoveAllListeners();
|
||||
btn.button.onClick.AddListener(ToggleConfigWindow);
|
||||
}
|
||||
{
|
||||
var panel = uiRoot.uiGame.planetGlobe;
|
||||
var src = panel.button2;
|
||||
var sandboxMenu = uiRoot.uiGame.sandboxMenu;
|
||||
var icon = sandboxMenu.categoryButtons[6].transform.Find("icon")?.GetComponent<Image>()?.sprite;
|
||||
var b = Instantiate(src, src.transform.parent);
|
||||
_buttonOnPlanetGlobe = b.gameObject;
|
||||
var rect = (RectTransform)_buttonOnPlanetGlobe.transform;
|
||||
var btn = _buttonOnPlanetGlobe.GetComponent<UIButton>();
|
||||
var img = _buttonOnPlanetGlobe.transform.Find("button-2/icon")?.GetComponent<Image>();
|
||||
if (img != null)
|
||||
{
|
||||
img.sprite = icon;
|
||||
}
|
||||
|
||||
if (_buttonOnPlanetGlobe != null && btn != null)
|
||||
{
|
||||
_buttonOnPlanetGlobe.name = "open-uxassist-config";
|
||||
rect.localScale = new Vector3(0.6f, 0.6f, 0.6f);
|
||||
rect.anchoredPosition3D = new Vector3(64f, -5f, 0f);
|
||||
b.onClick.RemoveAllListeners();
|
||||
btn.onClick += _ => { ToggleConfigWindow(); };
|
||||
btn.tips.tipTitle = "UXAssist Config";
|
||||
I18N.OnInitialized += () => { btn.tips.tipTitle = "UXAssist Config".Translate(); };
|
||||
btn.tips.tipText = null;
|
||||
btn.tips.corner = 9;
|
||||
btn.tips.offset = new Vector2(-20f, -20f);
|
||||
_buttonOnPlanetGlobe.SetActive(true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
{
|
||||
var cb = MySmallComboBox.CreateComboBox(125, 0, uiRoot.uiGame.starmap.transform as RectTransform, true).WithItems("显示原始名称", "显示星球类型+距离");
|
||||
cb.SetIndex(0);
|
||||
}
|
||||
*/
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
// Add config button to main menu
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot._OnOpen))]
|
||||
public static void UIRoot__OnOpen_Postfix()
|
||||
{
|
||||
InitMenuButtons();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIPlanetGlobe), nameof(UIPlanetGlobe.DistributeButtons))]
|
||||
private static void UIPlanetGlobe_DistributeButtons_Postfix(UIPlanetGlobe __instance)
|
||||
{
|
||||
if (_buttonOnPlanetGlobe == null) return;
|
||||
var rect = (RectTransform)_buttonOnPlanetGlobe.transform;
|
||||
if (__instance.dysonSphereSystemUnlocked || __instance.logisticsSystemUnlocked)
|
||||
{
|
||||
rect.anchoredPosition3D = new Vector3(64f, -5f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.anchoredPosition3D = new Vector3(128f, -100f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user