1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-03-22 11:53:25 +08:00

UXAssist: bug fix

This commit is contained in:
2026-02-13 23:29:22 +08:00
parent 3e24461ef0
commit 2e13206346
5 changed files with 97 additions and 63 deletions

View File

@@ -3,6 +3,10 @@
## Changlog
* 1.5.4
* `Auto-contruct`:
* Add a UI option to hide it completely.
* Fix an issue that may cause circling.
* 1.5.3
* New feature: `Auto-contruct`
* Fly to buildings to be contructed automatically.
@@ -377,6 +381,10 @@
## 更新日志
* 1.5.4
* `自动建造`
* 增加了一个 UI 选项,可完全隐藏该功能。
* 修复了可能导致盘旋的问题。
* 1.5.3
* 新功能:`自动建造`
* 自动飞行到待建造的建筑处进行建造。

View File

@@ -271,7 +271,7 @@ public static class UIFunctions
{
if (ToggleAutoConstruct == null) return;
var localPlanet = GameMain.localPlanet;
var active = localPlanet != null && localPlanet.factoryLoaded && localPlanet.factory.prebuildCount > 0;
var active = localPlanet != null && localPlanet.factoryLoaded && localPlanet.factory.prebuildCount > 0 && Patches.FactoryPatch.AutoConstructButtonEnabled.Value;
ToggleAutoConstruct.gameObject.SetActive(active);
ConstructCountPanel.gameObject.SetActive(active);
}

View File

@@ -32,6 +32,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
public static ConfigEntry<bool> DoNotRenderEntitiesEnabled;
public static ConfigEntry<bool> DragBuildPowerPolesEnabled;
public static ConfigEntry<bool> DragBuildPowerPolesAlternatelyEnabled;
public static ConfigEntry<bool> AutoConstructButtonEnabled;
public static ConfigEntry<bool> AutoConstructEnabled;
public static ConfigEntry<bool> BeltSignalsForBuyOutEnabled;
public static ConfigEntry<bool> TankFastFillInAndTakeOutEnabled;
@@ -124,6 +125,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
DoNotRenderEntitiesEnabled.SettingChanged += (_, _) => DoNotRenderEntities.Enable(DoNotRenderEntitiesEnabled.Value);
DragBuildPowerPolesEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
DragBuildPowerPolesAlternatelyEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.AlternatelyChanged();
AutoConstructButtonEnabled.SettingChanged += (_, _) => AutoConstructButton.Enable(AutoConstructButtonEnabled.Value);
AutoConstructEnabled.SettingChanged += (_, _) => Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
TankFastFillInAndTakeOutEnabled.SettingChanged += (_, _) => TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
@@ -154,6 +156,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
ProtectVeinsFromExhaustion.Enable(ProtectVeinsFromExhaustionEnabled.Value);
DoNotRenderEntities.Enable(DoNotRenderEntitiesEnabled.Value);
DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
AutoConstructButton.Enable(AutoConstructButtonEnabled.Value);
BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
TweakBuildingBuffer.Enable(TweakBuildingBufferEnabled.Value);
@@ -171,6 +174,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
TweakBuildingBuffer.Enable(false);
TankFastFillInAndTakeOut.Enable(false);
BeltSignalsForBuyOut.Enable(false);
AutoConstructButton.Enable(false);
DragBuildPowerPoles.Enable(false);
DoNotRenderEntities.Enable(false);
ProtectVeinsFromExhaustion.Enable(false);
@@ -276,78 +280,94 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
return matcher.InstructionEnumeration();
}
#region Auto Construct
private static int _lastPrebuildCount = -1;
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.NotifyFactoryLoaded))]
private static void PlanetData_NotifyFactoryLoaded_Postfix()
public class AutoConstructButton : PatchImpl<AutoConstructButton>
{
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
_lastPrebuildCount = -1;
}
private static int _lastPrebuildCount = -1;
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.UnloadFactory))]
private static void PlanetData_UnloadFactory_Postfix()
{
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
_lastPrebuildCount = -1;
}
protected override void OnEnable()
{
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAction_Rts), nameof(PlayerAction_Rts.GameTick))]
private static void PlayerAction_Rts_GameTick_Postfix(PlayerAction_Rts __instance, long timei)
{
if (timei % 60L != 0) return;
var planet = GameMain.localPlanet;
if (planet == null || !planet.factoryLoaded) return;
var factory = planet.factory;
var prebuildCount = factory.prebuildCount;
if (_lastPrebuildCount != prebuildCount)
protected override void OnDisable()
{
if (_lastPrebuildCount <= 0 || prebuildCount == 0)
{
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
}
_lastPrebuildCount = prebuildCount;
Functions.UIFunctions.UpdateConstructCountText(prebuildCount);
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
_lastPrebuildCount = -1;
}
if (prebuildCount <= 0) return;
if (!AutoConstructEnabled.Value) return;
var player = __instance.player;
if (prebuildCount <= player.mecha.constructionModule.buildTargetTotalCount) return;
if (player.orders.orderCount > 0) return;
var prebuilds = factory.prebuildPool;
var minDist = float.MaxValue;
var minIndex = 0;
var playerPos = player.position;
for (var i = factory.prebuildCursor - 1; i > 0; i--)
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.NotifyFactoryLoaded))]
private static void PlanetData_NotifyFactoryLoaded_Postfix()
{
ref var prebuild = ref prebuilds[i];
if (prebuild.id != i || prebuild.isDestroyed) continue;
if (prebuild.itemRequired > 0)
{
if (player.package.GetItemCount(prebuild.protoId) < prebuild.itemRequired) continue;
}
var dist = (prebuild.pos - playerPos).sqrMagnitude;
if (dist < minDist)
{
minDist = dist;
minIndex = i;
}
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
_lastPrebuildCount = -1;
}
if (minIndex == 0) return;
var diff = prebuilds[minIndex].pos - playerPos;
if (diff.sqrMagnitude < 400f) return;
if (player.movementState == EMovementState.Walk && player.mecha.thrusterLevel >= 1)
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.UnloadFactory))]
private static void PlanetData_UnloadFactory_Postfix()
{
player.controller.actionWalk.SwitchToFly();
return;
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
_lastPrebuildCount = -1;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAction_Rts), nameof(PlayerAction_Rts.GameTick))]
private static void PlayerAction_Rts_GameTick_Postfix(PlayerAction_Rts __instance, long timei)
{
if (timei % 60L != 0) return;
var planet = GameMain.localPlanet;
if (planet == null || !planet.factoryLoaded) return;
var factory = planet.factory;
var prebuildCount = factory.prebuildCount;
if (_lastPrebuildCount != prebuildCount)
{
if (_lastPrebuildCount <= 0 || prebuildCount == 0)
{
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
}
_lastPrebuildCount = prebuildCount;
Functions.UIFunctions.UpdateConstructCountText(prebuildCount);
}
if (prebuildCount <= 0) return;
if (!AutoConstructEnabled.Value) return;
var player = __instance.player;
if (prebuildCount <= player.mecha.constructionModule.buildTargetTotalCount) return;
if (player.orders.orderCount > 0) return;
if (player.controller.horzVelocity.sqrMagnitude > 0.01f)
{
return;
}
var prebuilds = factory.prebuildPool;
var minDist = float.MaxValue;
var minIndex = 0;
var playerPos = player.position;
for (var i = factory.prebuildCursor - 1; i > 0; i--)
{
ref var prebuild = ref prebuilds[i];
if (prebuild.id != i || prebuild.isDestroyed) continue;
if (prebuild.itemRequired > 0)
{
if (player.package.GetItemCount(prebuild.protoId) < prebuild.itemRequired) continue;
}
var dist = (prebuild.pos - playerPos).sqrMagnitude;
if (dist < minDist)
{
minDist = dist;
minIndex = i;
}
}
if (minIndex == 0) return;
var diff = prebuilds[minIndex].pos - playerPos;
if (diff.sqrMagnitude < 400f) return;
if (player.movementState == EMovementState.Walk && player.mecha.thrusterLevel >= 1)
{
player.controller.actionWalk.SwitchToFly();
return;
}
player.Order(OrderNode.MoveTo(prebuilds[minIndex].pos + diff.normalized * 6f), false);
}
player.Order(OrderNode.MoveTo(prebuilds[minIndex].pos + diff.normalized * 4f), false);
}
#endregion
public class NightLight : PatchImpl<NightLight>
{

View File

@@ -71,6 +71,7 @@ public static class UIConfigWindow
I18N.Add("Do not render factory entities", "Do not render factory entities (except belts and sorters)", "不渲染工厂建筑实体(除了传送带和分拣器)");
I18N.Add("Drag building power poles in maximum connection range", "Drag building power poles in maximum connection range", "拖动建造电线杆时自动使用最大连接距离间隔");
I18N.Add("Build Tesla Tower and Wireless Power Tower alternately", "Build Tesla Tower and Wireless Power Tower alternately", "交替建造电力感应塔和无线输电塔");
I18N.Add("Auto-construct button", "Auto-construct button", "自动建造按钮");
I18N.Add("Belt signals for buy out dark fog items automatically", "Belt signals for buy out dark fog items automatically", "用于自动购买黑雾物品的传送带信号");
I18N.Add("Ctrl+Shift+Click to pick items from whole belts", "Ctrl+Shift+Click to pick items from whole belts", "按住Ctrl+Shift点击从整条传送带抓取物品");
I18N.Add("Include branches of belts", "Include branches of belts", "包含传送带分支");
@@ -411,6 +412,9 @@ public static class UIConfigWindow
}
}
y += 36f;
wnd.AddCheckBox(x, y, tab2, FactoryPatch.AutoConstructButtonEnabled, "Auto-construct button");
{
y += 36f;
wnd.AddCheckBox(x, y, tab2, FactoryPatch.PressShiftToTakeWholeBeltItemsEnabled, "Ctrl+Shift+Click to pick items from whole belts");

View File

@@ -130,6 +130,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
"Drag building power poles in maximum connection range");
FactoryPatch.DragBuildPowerPolesAlternatelyEnabled = Config.Bind("Factory", "DragBuildPowerPolesAlternately", true,
"Build Tesla Tower and Wireless Power Tower alternately");
FactoryPatch.AutoConstructButtonEnabled = Config.Bind("Factory", "AutoConstructButton", false,
"Enable auto-construct button");
FactoryPatch.AutoConstructEnabled = Config.Bind("Factory", "AutoConstruct", false,
"Fly toward the building to be constructed automatically");
FactoryPatch.BeltSignalsForBuyOutEnabled = Config.Bind("Factory", "BeltSignalsForBuyOut", false,