1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 22:13:30 +08:00

some fixes

This commit is contained in:
2024-09-20 17:34:10 +08:00
parent 2d2602d8b9
commit 177c74d6e9
3 changed files with 50 additions and 32 deletions

View File

@@ -397,7 +397,9 @@ public static class LogisticsPatch
var storage = stationEntry.station?.storage;
if (storage == null) return;
var itemId = storage.Length > slot ? storage[slot].itemId : 0;
var controlPanelWindow = UIRoot.instance?.uiGame?.controlPanelWindow;
var uiRoot = UIRoot.instance;
if (!uiRoot) return;
var controlPanelWindow = uiRoot.uiGame?.controlPanelWindow;
if (controlPanelWindow == null) return;
var filterPanel = controlPanelWindow.filterPanel;
if (filterPanel == null) return;
@@ -487,7 +489,8 @@ public static class LogisticsPatch
public static void Enable(bool on)
{
_stationTipRoot?.SetActive(on);
if (_stationTipRoot)
_stationTipRoot.SetActive(on);
}
public static void EnableBars(bool on)

View File

@@ -6,6 +6,7 @@ using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using UXAssist.Common;
using Object = UnityEngine.Object;
namespace UXAssist.UI;
@@ -420,21 +421,14 @@ public class MyWindowWithTabs : MyWindow
}
}
public static class MyWindowManager
public class MyWindowManager
{
private static readonly List<ManualBehaviour> Windows = new(4);
private static bool _initialized;
private static Harmony _patch;
public static void Init()
public static void Enable(bool on)
{
_patch ??= Harmony.CreateAndPatchAll(typeof(Patch));
}
public static void Uninit()
{
_patch?.UnpatchSelf();
_patch = null;
Patch.Enable(on);
}
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow
@@ -495,8 +489,24 @@ public static class MyWindowManager
}
*/
public static class Patch
public class Patch: PatchImpl<Patch>
{
protected override void OnEnable()
{
InitAllWindows();
}
private static void InitAllWindows()
{
if (_initialized) return;
if (!UIRoot.instance) return;
foreach (var win in Windows)
{
win._Init(win.data);
}
_initialized = true;
}
/*
//_Create -> _Init
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnCreate")]
@@ -520,13 +530,7 @@ public static class MyWindowManager
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot._OnOpen))]
public static void UIRoot__OnOpen_Postfix()
{
if (_initialized) return;
foreach (var win in Windows)
{
win._Init(win.data);
}
_initialized = true;
InitAllWindows();
}
/*

View File

@@ -156,11 +156,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航");
// UI Patches
UIPatch.Enable(true);
GameLogic.Enable(true);
MyWindowManager.Init();
UIConfigWindow.Init();
_patches = Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches");
@@ -172,6 +169,9 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
private void Start()
{
MyWindowManager.Enable(true);
UIPatch.Enable(true);
_patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null));
var patch = UIPatch.GetHarmony();
ModsCompat.AuxilaryfunctionWrapper.Init(patch);
@@ -182,10 +182,9 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
{
_patches?.Do(type => type.GetMethod("Uninit")?.Invoke(null, null));
MyWindowManager.Uninit();
GameLogic.Enable(false);
UIPatch.Enable(false);
MyWindowManager.Enable(false);
GameLogic.Enable(false);
}
private void Update()
@@ -244,13 +243,18 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
{
private static GameObject _buttonOnPlanetGlobe;
// Add config button to main menu
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot.OpenMainMenuUI))]
public static void UIRoot_OpenMainMenuUI_Postfix()
protected override void OnEnable()
{
InitMenuButtons();
}
private static void InitMenuButtons()
{
if (_initialized) return;
var uiRoot = UIRoot.instance;
if (!uiRoot) return;
{
var mainMenu = UIRoot.instance.uiMainMenu;
var mainMenu = uiRoot.uiMainMenu;
var src = mainMenu.newGameButton;
var parent = src.transform.parent;
var btn = Instantiate(src, parent);
@@ -273,9 +277,9 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
btn.button.onClick.AddListener(ToggleConfigWindow);
}
{
var panel = UIRoot.instance.uiGame.planetGlobe;
var panel = uiRoot.uiGame.planetGlobe;
var src = panel.button2;
var sandboxMenu = UIRoot.instance.uiGame.sandboxMenu;
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;
@@ -304,6 +308,13 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
}
_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))]