1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-04 15:12:17 +08:00

support for logistic control panel

This commit is contained in:
2026-01-14 19:32:07 +08:00
parent b537ff22be
commit 2201de2b1b

View File

@@ -312,7 +312,8 @@ public static class LogisticsPatch
{ {
private static KeyCode _lastKey = KeyCode.None; private static KeyCode _lastKey = KeyCode.None;
private static long _nextKeyTick; private static long _nextKeyTick;
private static bool _skipNextEvent; private static bool _skipNextUIStationStorageEvent;
private static bool _skipNextUIControlPanelStationStorageEvent;
private static bool UpdateKeyPressed(KeyCode code) private static bool UpdateKeyPressed(KeyCode code)
{ {
@@ -388,10 +389,26 @@ public static class LogisticsPatch
EventSystem.current.RaycastAll(new PointerEventData(EventSystem.current) { position = Input.mousePosition }, targets); EventSystem.current.RaycastAll(new PointerEventData(EventSystem.current) { position = Input.mousePosition }, targets);
foreach (var target in targets) foreach (var target in targets)
{ {
StationComponent station = null;
int index = -1;
PlanetFactory planetFactory = null;
var stationStorage = target.gameObject.GetComponentInParent<UIStationStorage>(); var stationStorage = target.gameObject.GetComponentInParent<UIStationStorage>();
var station = stationStorage?.station; bool isControlPanelStationStorage = false;
if (stationStorage != null)
{
station = stationStorage.station;
index = stationStorage.index;
planetFactory = stationStorage.stationWindow?.factory;
} else {
var controlPanelStationStorage = target.gameObject.GetComponentInParent<UIControlPanelStationStorage>();
if (controlPanelStationStorage == null) continue;
station = controlPanelStationStorage.station;
index = controlPanelStationStorage.index;
planetFactory = controlPanelStationStorage.factory;
isControlPanelStationStorage = true;
}
if (station?.storage is null) continue; if (station?.storage is null) continue;
ref var storage = ref station.storage[stationStorage.index]; ref var storage = ref station.storage[index];
var oldMax = storage.max; var oldMax = storage.max;
var newMax = oldMax + delta; var newMax = oldMax + delta;
if (newMax < 0) if (newMax < 0)
@@ -407,9 +424,8 @@ public static class LogisticsPatch
} }
else else
{ {
var factory = stationStorage.stationWindow?.factory; if (planetFactory == null || station.entityId <= 0 || station.entityId >= planetFactory.entityCursor) continue;
if (factory == null || station.entityId <= 0 || station.entityId >= factory.entityCursor) continue; var modelProto = LDB.models.Select(planetFactory.entityPool[station.entityId].modelIndex);
var modelProto = LDB.models.Select(factory.entityPool[station.entityId].modelIndex);
itemCountMax = modelProto == null ? 0 : modelProto.prefabDesc.stationMaxItemCount; itemCountMax = modelProto == null ? 0 : modelProto.prefabDesc.stationMaxItemCount;
itemCountMax += station.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage; itemCountMax += station.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage;
} }
@@ -421,7 +437,14 @@ public static class LogisticsPatch
} }
storage.max = newMax; storage.max = newMax;
_skipNextEvent = oldMax / 100 != newMax / 100; if (isControlPanelStationStorage)
{
_skipNextUIControlPanelStationStorageEvent = oldMax / 100 != newMax / 100;
}
else
{
_skipNextUIStationStorageEvent = oldMax / 100 != newMax / 100;
}
break; break;
} }
} }
@@ -430,8 +453,17 @@ public static class LogisticsPatch
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.OnMaxSliderValueChange))] [HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.OnMaxSliderValueChange))]
private static bool UIStationStorage_OnMaxSliderValueChange_Prefix() private static bool UIStationStorage_OnMaxSliderValueChange_Prefix()
{ {
if (!_skipNextEvent) return true; if (!_skipNextUIStationStorageEvent) return true;
_skipNextEvent = false; _skipNextUIStationStorageEvent = false;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UIControlPanelStationStorage), nameof(UIControlPanelStationStorage.OnMaxSliderValueChange))]
private static bool UIControlPanelStationStorage_OnMaxSliderValueChange_Prefix()
{
if (!_skipNextUIControlPanelStationStorageEvent) return true;
_skipNextUIControlPanelStationStorageEvent = false;
return false; return false;
} }