refactor(UXAssist): replace magic numbers with constants

This commit is contained in:
2026-06-23 20:25:13 +08:00
parent 7973cbe358
commit a133fd9e14
8 changed files with 76 additions and 124 deletions
+1
View File
@@ -144,5 +144,6 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod`
- **Shared library:** `UXAssist` acts as a common library. `CheatEnabler` and `UniverseGenTweaks` reference `UXAssist.csproj` directly to reuse `Common/`, `UI/`, and config panel infrastructure. - **Shared library:** `UXAssist` acts as a common library. `CheatEnabler` and `UniverseGenTweaks` reference `UXAssist.csproj` directly to reuse `Common/`, `UI/`, and config panel infrastructure.
- **Preloader pattern:** `DustbinPreloader` and `LabOptPreloader` use Mono.Cecil to inject new fields into game assemblies at BepInEx preload time, enabling their corresponding main mods to read/write those fields via normal C# without reflection. - **Preloader pattern:** `DustbinPreloader` and `LabOptPreloader` use Mono.Cecil to inject new fields into game assemblies at BepInEx preload time, enabling their corresponding main mods to read/write those fields via normal C# without reflection.
- **Internationalization:** `UXAssist/Common/I18N.cs` provides bilingual (EN + ZH) string lookup used across UXAssist and CheatEnabler. - **Internationalization:** `UXAssist/Common/I18N.cs` provides bilingual (EN + ZH) string lookup used across UXAssist and CheatEnabler.
- **Centralized game constants:** Hard-coded item IDs, tech IDs, logistics capacities, and Dyson sphere geometry defaults live in `UXAssist/Common/GameConstants` (`ItemIds`, `TechIds`, `LogisticsConstants`, `DysonSphereConstants`). Prefer these constants over inline literals in UXAssist patches.
- **Transpiler patches:** Performance-critical mods (LabOpt, MechaDronesTweaks) use `[HarmonyTranspiler]` to rewrite IL instructions directly for maximum efficiency. - **Transpiler patches:** Performance-critical mods (LabOpt, MechaDronesTweaks) use `[HarmonyTranspiler]` to rewrite IL instructions directly for maximum efficiency.
- **Save persistence:** Mods that need to persist data use the `IModCanSave` interface from DSPModSave. - **Save persistence:** Mods that need to persist data use the `IModCanSave` interface from DSPModSave.
+1 -1
View File
@@ -281,7 +281,7 @@ public static class TechFunctions
var history = GameMain.data?.history; var history = GameMain.data?.history;
if (history == null) return; if (history == null) return;
history.inserterStackCountObsolete = 1; history.inserterStackCountObsolete = 1;
for (var id = 3301; id <= 3305; id++) for (var id = global::UXAssist.Common.GameConstants.TechIds.SorterCargoStackingCustomStart; id <= global::UXAssist.Common.GameConstants.TechIds.SorterCargoStackingCustomEnd - 1; id++)
{ {
history.techStates.TryGetValue(id, out var state); history.techStates.TryGetValue(id, out var state);
if (!state.unlocked) continue; if (!state.unlocked) continue;
+5 -4
View File
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using HarmonyLib; using HarmonyLib;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.GameConstants;
using GameLogicProc = UXAssist.Common.GameLogic; using GameLogicProc = UXAssist.Common.GameLogic;
namespace UXAssist.Patches.Factory; namespace UXAssist.Patches.Factory;
@@ -45,7 +46,7 @@ internal static class BeltSignalPatch
private static bool _initialized; private static bool _initialized;
private static bool _loaded; private static bool _loaded;
private static long _clusterSeedKey; private static long _clusterSeedKey;
private static readonly int[] DarkFogItemIds = [5201, 5206, 5202, 5204, 5203, 5205]; private static readonly int[] DarkFogItemIds = ItemIds.DarkFogItemIds;
private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10]; private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10];
public static readonly int[] DarkFogItemsInVoid = [0, 0, 0, 0, 0, 0]; public static readonly int[] DarkFogItemsInVoid = [0, 0, 0, 0, 0, 0];
private static Dictionary<int, uint>[] _signalBelts = new Dictionary<int, uint>[64]; private static Dictionary<int, uint>[] _signalBelts = new Dictionary<int, uint>[64];
@@ -340,13 +341,13 @@ internal static class BeltSignalPatch
var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
if (consume < 4) if (consume < 4)
{ {
var metaverseLong = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006); var metaverseLong = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, ItemIds.Metaverse);
if (metaverseLong > 0L) if (metaverseLong > 0L)
{ {
var metaverse = metaverseLong > 10 ? 10 : (int)metaverseLong; var metaverse = metaverseLong > 10 ? 10 : (int)metaverseLong;
propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse); propertySystem.AddItemConsumption(_clusterSeedKey, ItemIds.Metaverse, metaverse);
var mainPlayer = GameMain.mainPlayer; var mainPlayer = GameMain.mainPlayer;
GameMain.history.AddPropertyItemConsumption(6006, metaverse, true); GameMain.history.AddPropertyItemConsumption(ItemIds.Metaverse, metaverse, true);
var count = DarkFogItemExchangeRate[itemIdx] * metaverse; var count = DarkFogItemExchangeRate[itemIdx] * metaverse;
DarkFogItemsInVoid[itemIdx] += count; DarkFogItemsInVoid[itemIdx] += count;
consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4);
@@ -5,6 +5,7 @@ using BepInEx.Configuration;
using HarmonyLib; using HarmonyLib;
using UnityEngine; using UnityEngine;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.GameConstants;
namespace UXAssist.Patches.Logistics; namespace UXAssist.Patches.Logistics;
@@ -85,7 +86,7 @@ internal class AutoConfigLogistics : PatchImpl<AutoConfigLogistics>
{ {
if (__instance.handPrefabDesc.isDispenser) if (__instance.handPrefabDesc.isDispenser)
{ {
__instance.handBpParams[bpIndex][2] = (int)(long)(5000.0 * LogisticsPatch.AutoConfigDispenserChargePower.Value + 0.5); __instance.handBpParams[bpIndex][2] = (int)(long)(LogisticsConstants.DispenserChargePowerMultiplier * LogisticsPatch.AutoConfigDispenserChargePower.Value + 0.5);
} }
} }
+32 -31
View File
@@ -7,6 +7,7 @@ using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.GameConstants;
namespace UXAssist.Patches.Logistics; namespace UXAssist.Patches.Logistics;
@@ -29,13 +30,13 @@ internal class LogisticsCapacityTweaks : PatchImpl<LogisticsCapacityTweaks>
if (code != _lastKey) if (code != _lastKey)
{ {
_lastKey = code; _lastKey = code;
_nextKeyTick = main.timei + 30; _nextKeyTick = main.timei + LogisticsConstants.KeyRepeatInitialDelay;
return true; return true;
} }
var currTick = main.timei; var currTick = main.timei;
if (_nextKeyTick > currTick) return false; if (_nextKeyTick > currTick) return false;
_nextKeyTick = currTick + 4; _nextKeyTick = currTick + LogisticsConstants.KeyRepeatInterval;
return true; return true;
} }
@@ -54,38 +55,38 @@ internal class LogisticsCapacityTweaks : PatchImpl<LogisticsCapacityTweaks>
if (UpdateKeyPressed(KeyCode.LeftArrow)) if (UpdateKeyPressed(KeyCode.LeftArrow))
{ {
if (ctrl) if (ctrl)
delta = -100000; delta = -LogisticsConstants.MassiveAdjustment;
else if (alt) else if (alt)
delta = -1000; delta = -LogisticsConstants.LargeAdjustment;
else else
delta = -10; delta = -LogisticsConstants.SmallAdjustment;
} }
else if (UpdateKeyPressed(KeyCode.RightArrow)) else if (UpdateKeyPressed(KeyCode.RightArrow))
{ {
if (ctrl) if (ctrl)
delta = 100000; delta = LogisticsConstants.MassiveAdjustment;
else if (alt) else if (alt)
delta = 1000; delta = LogisticsConstants.LargeAdjustment;
else else
delta = 10; delta = LogisticsConstants.SmallAdjustment;
} }
else if (UpdateKeyPressed(KeyCode.DownArrow)) else if (UpdateKeyPressed(KeyCode.DownArrow))
{ {
if (ctrl) if (ctrl)
delta = -1000000; delta = -LogisticsConstants.GargantuanAdjustment;
else if (alt) else if (alt)
delta = -10000; delta = -LogisticsConstants.HugeAdjustment;
else else
delta = -100; delta = -LogisticsConstants.MediumAdjustment;
} }
else if (UpdateKeyPressed(KeyCode.UpArrow)) else if (UpdateKeyPressed(KeyCode.UpArrow))
{ {
if (ctrl) if (ctrl)
delta = 1000000; delta = LogisticsConstants.GargantuanAdjustment;
else if (alt) else if (alt)
delta = 10000; delta = LogisticsConstants.HugeAdjustment;
else else
delta = 100; delta = LogisticsConstants.MediumAdjustment;
} }
else else
{ {
@@ -129,7 +130,7 @@ internal class LogisticsCapacityTweaks : PatchImpl<LogisticsCapacityTweaks>
int itemCountMax; int itemCountMax;
if (LogisticsPatch.AllowOverflowInLogisticsEnabled.Value) if (LogisticsPatch.AllowOverflowInLogisticsEnabled.Value)
{ {
itemCountMax = 90000000; itemCountMax = LogisticsConstants.OverflowStorageMax;
} }
else else
{ {
@@ -230,7 +231,7 @@ internal class LogisticsCapacityTweaks : PatchImpl<LogisticsCapacityTweaks>
{ {
var max = storage[j].max; var max = storage[j].max;
if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue; if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue;
storage[j].max = Mathf.RoundToInt((float)(max * ratio / 50.0)) * 50; storage[j].max = Mathf.RoundToInt((float)(max * ratio / LogisticsConstants.LocalStorageRounding)) * LogisticsConstants.LocalStorageRounding;
} }
} }
@@ -256,7 +257,7 @@ internal class LogisticsCapacityTweaks : PatchImpl<LogisticsCapacityTweaks>
{ {
var max = storage[j].max; var max = storage[j].max;
if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue; if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue;
storage[j].max = Mathf.RoundToInt((float)(max * ratio / 100.0)) * 100; storage[j].max = Mathf.RoundToInt((float)(max * ratio / LogisticsConstants.RemoteStorageRounding)) * LogisticsConstants.RemoteStorageRounding;
} }
} }
@@ -275,7 +276,7 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
var window = UIRoot.instance?.uiGame?.stationWindow; var window = UIRoot.instance?.uiGame?.stationWindow;
if (window == null) return; if (window == null) return;
window._Close(); window._Close();
window.maxMiningSpeedSlider.maxValue = 27f; window.maxMiningSpeedSlider.maxValue = LogisticsConstants.MiningSpeedSliderMaxExtended;
} }
protected override void OnDisable() protected override void OnDisable()
@@ -283,7 +284,7 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
var window = UIRoot.instance?.uiGame?.stationWindow; var window = UIRoot.instance?.uiGame?.stationWindow;
if (window == null) return; if (window == null) return;
window._Close(); window._Close();
window.maxMiningSpeedSlider.maxValue = 20f; window.maxMiningSpeedSlider.maxValue = LogisticsConstants.MiningSpeedSliderMaxDefault;
} }
[HarmonyTranspiler] [HarmonyTranspiler]
@@ -295,13 +296,13 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate((UIStationWindow window) => Transpilers.EmitDelegate((UIStationWindow window) =>
{ {
window.maxMiningSpeedSlider.maxValue = 27f; window.maxMiningSpeedSlider.maxValue = LogisticsConstants.MiningSpeedSliderMaxExtended;
}) })
).MatchForward(false, ).MatchForward(false,
new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.maxChargePowerSlider))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.maxChargePowerSlider))),
new CodeMatch(ci => ci.IsLdloc()), new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(0xC350)), new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(LogisticsConstants.ChargePowerSliderScale)),
new CodeMatch(OpCodes.Conv_I8) new CodeMatch(OpCodes.Conv_I8)
); );
var pos = matcher.Pos + 1; var pos = matcher.Pos + 1;
@@ -318,11 +319,11 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
new CodeInstruction(OpCodes.Ldloc_S, locWorkEnergyPerTick), new CodeInstruction(OpCodes.Ldloc_S, locWorkEnergyPerTick),
Transpilers.EmitDelegate((UIStationWindow window, long maxWorkEnergy, long workEnergyPerTick) => Transpilers.EmitDelegate((UIStationWindow window, long maxWorkEnergy, long workEnergyPerTick) =>
{ {
var maxSliderValue = maxWorkEnergy / 50000L; var maxSliderValue = maxWorkEnergy / LogisticsConstants.ChargePowerSliderScale;
window.maxChargePowerSlider.maxValue = maxSliderValue + 9; window.maxChargePowerSlider.maxValue = maxSliderValue + 9;
window.maxChargePowerSlider.minValue = maxWorkEnergy / 500000L; window.maxChargePowerSlider.minValue = maxWorkEnergy / LogisticsConstants.ChargePowerSliderMinScale;
if (workEnergyPerTick <= maxWorkEnergy) if (workEnergyPerTick <= maxWorkEnergy)
window.maxChargePowerSlider.Set(workEnergyPerTick / 50000L, false); window.maxChargePowerSlider.Set(workEnergyPerTick / LogisticsConstants.ChargePowerSliderScale, false);
else else
window.maxChargePowerSlider.Set(maxSliderValue + (workEnergyPerTick - 1) / maxWorkEnergy + 1, false); window.maxChargePowerSlider.Set(maxSliderValue + (workEnergyPerTick - 1) / maxWorkEnergy + 1, false);
}) })
@@ -348,9 +349,9 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
matcher.Start().Advance(pos).RemoveInstructions(pos2 - pos).Insert( matcher.Start().Advance(pos).RemoveInstructions(pos2 - pos).Insert(
Transpilers.EmitDelegate((int speed) => Transpilers.EmitDelegate((int speed) =>
{ {
if (speed <= 30000) if (speed <= LogisticsConstants.MaxMiningSpeedBase)
return (speed - 10000) / 1000; return (speed - LogisticsConstants.MinMiningSpeedBase) / LogisticsConstants.MiningSpeedFineStep;
return (speed - 30000) / 10000 + 20; return (speed - LogisticsConstants.MaxMiningSpeedBase) / LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MiningSpeedSliderMaxDefault;
}) })
); );
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
@@ -362,7 +363,7 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(10000)), new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(LogisticsConstants.MinMiningSpeedBase)),
new CodeMatch(OpCodes.Ldarg_1) new CodeMatch(OpCodes.Ldarg_1)
); );
var pos = matcher.Pos; var pos = matcher.Pos;
@@ -378,9 +379,9 @@ internal class GreaterPowerUsageInLogistics : PatchImpl<GreaterPowerUsageInLogis
Transpilers.EmitDelegate((float value) => Transpilers.EmitDelegate((float value) =>
{ {
var intval = (int)(value + 0.5f); var intval = (int)(value + 0.5f);
if (intval <= 20) if (intval <= LogisticsConstants.MiningSpeedSliderMaxDefault)
return intval * 1000 + 10000; return intval * LogisticsConstants.MiningSpeedFineStep + LogisticsConstants.MinMiningSpeedBase;
return (intval - 20) * 10000 + 30000; return (intval - LogisticsConstants.MiningSpeedSliderMaxDefault) * LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MaxMiningSpeedBase;
}) })
); );
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();
+4 -3
View File
@@ -5,6 +5,7 @@ using HarmonyLib;
using UnityEngine; using UnityEngine;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.ModFeatures; using UXAssist.Common.ModFeatures;
using UXAssist.Common.GameConstants;
using GameLogicProc = UXAssist.Common.GameLogic; using GameLogicProc = UXAssist.Common.GameLogic;
namespace UXAssist.Patches.Logistics; namespace UXAssist.Patches.Logistics;
@@ -178,7 +179,7 @@ public static class LogisticsPatch
{ {
ref var entity = ref factory.entityPool[station.entityId]; ref var entity = ref factory.entityPool[station.entityId];
if (entity.id != station.entityId || entity.minerId <= 0 || entity.minerId >= factory.factorySystem.minerCursor) return false; if (entity.id != station.entityId || entity.minerId <= 0 || entity.minerId >= factory.factorySystem.minerCursor) return false;
factory.factorySystem.minerPool[entity.minerId].speed = 10000 + AutoConfigVeinCollectorHarvestSpeed.Value * 1000; factory.factorySystem.minerPool[entity.minerId].speed = LogisticsConstants.MinMiningSpeedBase + AutoConfigVeinCollectorHarvestSpeed.Value * LogisticsConstants.MiningSpeedFineStep;
return true; return true;
} }
@@ -186,7 +187,7 @@ public static class LogisticsPatch
station.pilerCount = AutoConfigVeinCollectorMinPilerValue.Value; station.pilerCount = AutoConfigVeinCollectorMinPilerValue.Value;
internal static void DispenserSetChargePower(PlanetFactory factory, DispenserComponent dispenser) => internal static void DispenserSetChargePower(PlanetFactory factory, DispenserComponent dispenser) =>
factory.powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick = (long)(5000.0 * AutoConfigDispenserChargePower.Value + 0.5); factory.powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick = (long)(LogisticsConstants.DispenserChargePowerMultiplier * AutoConfigDispenserChargePower.Value + 0.5);
internal static void DispenserFillCouriers(PlanetFactory factory, DispenserComponent dispenser) internal static void DispenserFillCouriers(PlanetFactory factory, DispenserComponent dispenser)
{ {
@@ -195,7 +196,7 @@ public static class LogisticsPatch
} }
internal static void BattleBaseSetChargePower(PlanetFactory factory, BattleBaseComponent battleBase) => internal static void BattleBaseSetChargePower(PlanetFactory factory, BattleBaseComponent battleBase) =>
factory.powerSystem.consumerPool[battleBase.pcId].workEnergyPerTick = (long)(5000.0 * AutoConfigBattleBaseChargePower.Value + 0.5); factory.powerSystem.consumerPool[battleBase.pcId].workEnergyPerTick = (long)(LogisticsConstants.DispenserChargePowerMultiplier * AutoConfigBattleBaseChargePower.Value + 0.5);
// === Per-facility "apply all settings" (also used as auto-config-on-build entry point) === // === Per-facility "apply all settings" (also used as auto-config-on-build entry point) ===
@@ -8,6 +8,7 @@ using UnityEngine.EventSystems;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using UnityEngine.UI; using UnityEngine.UI;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.GameConstants;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
namespace UXAssist.Patches.Logistics; namespace UXAssist.Patches.Logistics;
@@ -181,19 +182,18 @@ internal static class RealtimeLogisticsInfoPanel
private static int _lastPlanetId; private static int _lastPlanetId;
private static int _localStorageMax = 5000; private static int _localStorageMax = LogisticsConstants.DefaultLocalStorageMax;
private static int _remoteStorageMax = 10000; private static int _remoteStorageMax = LogisticsConstants.DefaultRemoteStorageMax;
private static int _localStorageExtra; private static int _localStorageExtra;
private static int _remoteStorageExtra; private static int _remoteStorageExtra;
private static int _localStorageMaxTotal = _localStorageMax; private static int _localStorageMaxTotal = _localStorageMax;
private static int _remoteStorageMaxTotal = _remoteStorageMax; private static int _remoteStorageMaxTotal = _remoteStorageMax;
private static float _localStoragePixelPerItem = StorageSliderWidth / _localStorageMaxTotal; private static float _localStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _localStorageMaxTotal;
private static float _remoteStoragePixelPerItem = StorageSliderWidth / _remoteStorageMaxTotal; private static float _remoteStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _remoteStorageMaxTotal;
private static int _storageMaxSlotCount = 5; private static int _storageMaxSlotCount = LogisticsConstants.DefaultStorageSlotCount;
private const int CarrierSlotCount = 3; private const int CarrierSlotCount = 3;
private const float StorageSliderWidth = 70f;
private const float StorageSliderHeight = 5f;
private static bool UpdateStorageMax() private static bool UpdateStorageMax()
{ {
@@ -204,8 +204,8 @@ internal static class RealtimeLogisticsInfoPanel
_remoteStorageExtra = history.remoteStationExtraStorage; _remoteStorageExtra = history.remoteStationExtraStorage;
_localStorageMaxTotal = _localStorageMax + _localStorageExtra; _localStorageMaxTotal = _localStorageMax + _localStorageExtra;
_remoteStorageMaxTotal = _remoteStorageMax + _remoteStorageExtra; _remoteStorageMaxTotal = _remoteStorageMax + _remoteStorageExtra;
_localStoragePixelPerItem = StorageSliderWidth / _localStorageMaxTotal; _localStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _localStorageMaxTotal;
_remoteStoragePixelPerItem = StorageSliderWidth / _remoteStorageMaxTotal; _remoteStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _remoteStorageMaxTotal;
return true; return true;
} }
@@ -258,9 +258,9 @@ internal static class RealtimeLogisticsInfoPanel
internal static void OnDataLoaded() internal static void OnDataLoaded()
{ {
_storageMaxSlotCount = 5; _storageMaxSlotCount = LogisticsConstants.DefaultStorageSlotCount;
_localStorageMax = 5000; _localStorageMax = LogisticsConstants.DefaultLocalStorageMax;
_remoteStorageMax = 10000; _remoteStorageMax = LogisticsConstants.DefaultRemoteStorageMax;
foreach (var model in LDB.models.dataArray) foreach (var model in LDB.models.dataArray)
{ {
var prefabDesc = model?.prefabDesc; var prefabDesc = model?.prefabDesc;
@@ -361,25 +361,25 @@ internal static class RealtimeLogisticsInfoPanel
var sliderBg = Object.Instantiate(sliderBgPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); var sliderBg = Object.Instantiate(sliderBgPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform);
sliderBg.name = "sliderBg" + index; sliderBg.name = "sliderBg" + index;
rectTrans = (RectTransform)sliderBg.transform; rectTrans = (RectTransform)sliderBg.transform;
rectTrans.sizeDelta = new Vector2(StorageSliderWidth, StorageSliderHeight); rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f);
rectTrans.pivot = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f);
rectTrans.anchoredPosition3D = new Vector3(30f, y - 22f, 0f); rectTrans.anchoredPosition3D = new Vector3(30f, y - 22f, 0f);
rectTrans = (RectTransform)sliderBg.transform.Find("current-fg").transform; rectTrans = (RectTransform)sliderBg.transform.Find("current-fg").transform;
rectTrans.sizeDelta = new Vector2(0f, StorageSliderHeight); rectTrans.sizeDelta = new Vector2(0f, LogisticsConstants.StorageSliderHeight);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f);
rectTrans.pivot = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f);
rectTrans.localPosition = new Vector3(0f, 0f, 0f); rectTrans.localPosition = new Vector3(0f, 0f, 0f);
rectTrans = (RectTransform)sliderBg.transform.Find("ordered-fg").transform; rectTrans = (RectTransform)sliderBg.transform.Find("ordered-fg").transform;
rectTrans.sizeDelta = new Vector2(0f, StorageSliderHeight); rectTrans.sizeDelta = new Vector2(0f, LogisticsConstants.StorageSliderHeight);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f);
rectTrans.pivot = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f);
rectTrans.localPosition = new Vector3(0f, 0f, 0f); rectTrans.localPosition = new Vector3(0f, 0f, 0f);
rectTrans = (RectTransform)sliderBg.transform.Find("max-fg").transform; rectTrans = (RectTransform)sliderBg.transform.Find("max-fg").transform;
rectTrans.sizeDelta = new Vector2(StorageSliderWidth, StorageSliderHeight); rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight);
rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMax = new Vector2(0f, 1f);
rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f);
rectTrans.pivot = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f);
@@ -934,7 +934,7 @@ internal static class RealtimeLogisticsInfoPanel
{ {
((RectTransform)_sliderCurrent[i].transform).sizeDelta = new Vector2( ((RectTransform)_sliderCurrent[i].transform).sizeDelta = new Vector2(
_pixelPerItem * itemCount, _pixelPerItem * itemCount,
StorageSliderHeight LogisticsConstants.StorageSliderHeight
); );
_sliderCurrent[i].gameObject.SetActive(true); _sliderCurrent[i].gameObject.SetActive(true);
} }
@@ -968,7 +968,7 @@ internal static class RealtimeLogisticsInfoPanel
); );
rectTrans.sizeDelta = new Vector2( rectTrans.sizeDelta = new Vector2(
_pixelPerItem * itemOrdered + 0.49f, _pixelPerItem * itemOrdered + 0.49f,
StorageSliderHeight LogisticsConstants.StorageSliderHeight
); );
break; break;
case < 0: case < 0:
@@ -981,7 +981,7 @@ internal static class RealtimeLogisticsInfoPanel
); );
rectTrans.sizeDelta = new Vector2( rectTrans.sizeDelta = new Vector2(
_pixelPerItem * -itemOrdered + 0.49f, _pixelPerItem * -itemOrdered + 0.49f,
StorageSliderHeight LogisticsConstants.StorageSliderHeight
); );
break; break;
} }
@@ -997,7 +997,7 @@ internal static class RealtimeLogisticsInfoPanel
if (itemMax > itemLimit) itemMax = itemLimit; if (itemMax > itemLimit) itemMax = itemLimit;
((RectTransform)_sliderMax[i].transform).sizeDelta = new Vector2( ((RectTransform)_sliderMax[i].transform).sizeDelta = new Vector2(
_pixelPerItem * itemMax, _pixelPerItem * itemMax,
StorageSliderHeight LogisticsConstants.StorageSliderHeight
); );
} }
} }
+11 -64
View File
@@ -6,6 +6,7 @@ using HarmonyLib;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UXAssist.Common; using UXAssist.Common;
using UXAssist.Common.GameConstants;
using GameLogicProc = UXAssist.Common.GameLogic; using GameLogicProc = UXAssist.Common.GameLogic;
namespace UXAssist.Patches; namespace UXAssist.Patches;
@@ -66,7 +67,7 @@ public static class TechPatch
var delim = -26.0f; var delim = -26.0f;
var x = 9.0f; var x = 9.0f;
var y = -27.0f; var y = -27.0f;
var tp3301 = techs.Select(3301); var tp3301 = techs.Select(TechIds.SorterCargoStackingCustomStart);
if (tp3301 != null && tp3301.IsObsolete) if (tp3301 != null && tp3301.IsObsolete)
{ {
_protoPatched = false; _protoPatched = false;
@@ -84,11 +85,11 @@ public static class TechPatch
{ {
switch (tp.ID) switch (tp.ID)
{ {
case >= 3301 and <= 3305: case >= TechIds.SorterCargoStackingCustomStart and <= TechIds.SorterCargoStackingCustomEnd - 1:
tp.UnlockValues[0] = tp.ID - 3300 + 1; tp.UnlockValues[0] = tp.ID - TechIds.SorterCargoStackingCustomStart + 2;
tp.IsObsolete = false; tp.IsObsolete = false;
tp.Position = new Vector2(x + 4.0f * (tp.ID - 3301), y); tp.Position = new Vector2(x + 4.0f * (tp.ID - TechIds.SorterCargoStackingCustomStart), y);
if (tp.ID == 3305) if (tp.ID == TechIds.SorterCargoStackingCustomEnd - 1)
{ {
tp.postTechArray = []; tp.postTechArray = [];
if (UIRoot.instance.uiGame.techTree.nodes.TryGetValue(tp.ID, out var node)) if (UIRoot.instance.uiGame.techTree.nodes.TryGetValue(tp.ID, out var node))
@@ -97,10 +98,10 @@ public static class TechPatch
} }
} }
continue; continue;
case 3306: case TechIds.SorterCargoStackingCustomEnd:
tp.PreTechs = []; tp.PreTechs = [];
tp.preTechArray = []; tp.preTechArray = [];
tp.Position = new Vector2(x + 4.0f * (tp.ID - 3301), y); tp.Position = new Vector2(x + 4.0f * (tp.ID - TechIds.SorterCargoStackingCustomStart), y);
continue; continue;
} }
@@ -113,7 +114,7 @@ public static class TechPatch
else else
{ {
var delim = -28.0f; var delim = -28.0f;
var tp3301 = techs.Select(3301); var tp3301 = techs.Select(TechIds.SorterCargoStackingCustomStart);
if (tp3301 != null && !tp3301.IsObsolete) if (tp3301 != null && !tp3301.IsObsolete)
{ {
_protoPatched = true; _protoPatched = true;
@@ -122,7 +123,7 @@ public static class TechPatch
if (!_protoPatched) return; if (!_protoPatched) return;
foreach (var tp in techs.dataArray) foreach (var tp in techs.dataArray)
{ {
if (tp.ID is >= 3301 and <= 3306) if (tp.ID is >= TechIds.SorterCargoStackingCustomStart and <= TechIds.SorterCargoStackingCustomEnd)
{ {
tp.IsObsolete = true; tp.IsObsolete = true;
continue; continue;
@@ -154,61 +155,7 @@ public static class TechPatch
public static void Enable(bool enable) public static void Enable(bool enable)
{ {
if (_techsToDisableSet == null) _techsToDisableSet ??= new HashSet<int>(TechIds.CombatTechs);
{
(int, int)[] techListToDisable =
[
// Explosive Unit, Crystal Explosive Unit
// 爆破单元,晶石爆破单元
(1803, 1804),
// Implosion Cannon
// 聚爆加农炮
(1807, 1807),
// Signal Tower, Planetary Defense System, Jammer Tower, Plasma Turret, Titanium Ammo Box, Superalloy Ammo Box, High-Explosive Shell Set, Supersonic Missile Set, Crystal Shell Set, Gravity Missile Set, Antimatter Capsule, Precision Drone, Prototype, Attack Drone, Corvette, Destroyer, Suppressing Capsule, EM Capsule Mk.III
// 信号塔, 行星防御系统, 干扰塔, 磁化电浆炮, 钛化弹箱, 超合金弹箱, 高爆炮弹组, 超音速导弹组, 晶石炮弹组, 引力导弹组, 反物质胶囊, 地面战斗机-A型, 地面战斗机-E型, 地面战斗机-F型, 太空战斗机-A型, 太空战斗机-F型, 电磁胶囊II, 电磁胶囊III
(1809, 1825),
// Auto Reconstruction Marking
// 自动标记重建
(2951, 2956),
// Energy Shield
// 能量护盾
(2801, 2807),
// Kinetic Weapon Damage
// 动能武器伤害
(5001, 5006),
// Energy Weapon Damage
// 能量武器伤害
(5101, 5106),
// Explosive Weapon Damage
// 爆炸武器伤害
(5201, 5206),
// Combat Drone Damage
// 战斗无人机伤害
(5301, 5305),
// Combat Drone Attack Speed
// 战斗无人机攻击速度
(5401, 5405),
// Combat Drone Engine
// 战斗无人机引擎
(5601, 5605),
// Combat Drone Durability
// 战斗无人机耐久
(5701, 5705),
// Ground Squadron Expansion
// 地面编队扩容
(5801, 5807),
// Space Fleet Expansion
// 太空编队扩容
(5901, 5907),
// Enhanced Structure
// 结构强化
(6001, 6006),
// Planetary Shield
// 行星护盾
(6101, 6106),
];
_techsToDisableSet = [.. techListToDisable.SelectMany(t => Enumerable.Range(t.Item1, t.Item2 - t.Item1 + 1))];
}
if (enable) if (enable)
{ {
if (DSPGame.GameDesc != null) if (DSPGame.GameDesc != null)