mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-02-05 03:42:20 +08:00
UXAssist: Auto construct
This commit is contained in:
@@ -33,6 +33,8 @@ public static class UIFunctions
|
||||
|
||||
I18N.Add("Enable auto-cruise", "Enable auto-cruise", "启用自动巡航");
|
||||
I18N.Add("Disable auto-cruise", "Disable auto-cruise", "禁用自动巡航");
|
||||
I18N.Add("Enable auto-construct", "Enable auto-construct", "启用自动建造");
|
||||
I18N.Add("Disable auto-construct", "Disable auto-construct", "禁用自动建造");
|
||||
I18N.Add("High yield", "High yield", "高产");
|
||||
I18N.Add("Perfect", "Perfect", "完美");
|
||||
I18N.Add("Union results", "Union results", "结果取并集");
|
||||
@@ -136,6 +138,7 @@ public static class UIFunctions
|
||||
}
|
||||
}
|
||||
InitToggleAutoCruiseCheckButton();
|
||||
InitToggleAutoConstructCheckButton();
|
||||
InitStarmapButtons();
|
||||
_initialized = true;
|
||||
}
|
||||
@@ -201,6 +204,42 @@ public static class UIFunctions
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToggleAutoConstructCheckButton
|
||||
public static UI.MyCheckButton ToggleAutoConstruct;
|
||||
|
||||
public static void InitToggleAutoConstructCheckButton()
|
||||
{
|
||||
var lowGroup = GameObject.Find("UI Root/Overlay Canvas/In Game/Low Group");
|
||||
ToggleAutoConstruct = MyCheckButton.CreateCheckButton(0, 0, lowGroup.GetComponent<RectTransform>(), Patches.FactoryPatch.AutoConstructEnabled).WithSize(120f, 40f);
|
||||
UpdateToggleAutoConstructCheckButtonVisiblility();
|
||||
ToggleAutoConstructChecked();
|
||||
ToggleAutoConstruct.OnChecked += ToggleAutoConstructChecked;
|
||||
var rectTrans = ToggleAutoConstruct.rectTrans;
|
||||
rectTrans.anchorMax = new Vector2(0.5f, 0f);
|
||||
rectTrans.anchorMin = new Vector2(0.5f, 0f);
|
||||
rectTrans.pivot = new Vector2(0.5f, 0f);
|
||||
rectTrans.anchoredPosition3D = new Vector3(0f, 140f, 0f);
|
||||
static void ToggleAutoConstructChecked()
|
||||
{
|
||||
if (ToggleAutoConstruct.Checked)
|
||||
{
|
||||
ToggleAutoConstruct.SetLabelText("Disable auto-construct");
|
||||
}
|
||||
else
|
||||
{
|
||||
ToggleAutoConstruct.SetLabelText("Enable auto-construct");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateToggleAutoConstructCheckButtonVisiblility()
|
||||
{
|
||||
if (ToggleAutoConstruct == null) return;
|
||||
var localPlanet = GameMain.localPlanet;
|
||||
ToggleAutoConstruct.gameObject.SetActive(localPlanet != null && localPlanet.factoryLoaded && localPlanet.factory.prebuildCount > 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region StarMapButtons
|
||||
private static int _cornerComboBoxIndex;
|
||||
private static string[] _starOrderNames;
|
||||
|
||||
@@ -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> AutoConstructEnabled;
|
||||
public static ConfigEntry<bool> BeltSignalsForBuyOutEnabled;
|
||||
public static ConfigEntry<bool> TankFastFillInAndTakeOutEnabled;
|
||||
public static ConfigEntry<int> TankFastFillInAndTakeOutMultiplier;
|
||||
@@ -123,6 +124,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
|
||||
DoNotRenderEntitiesEnabled.SettingChanged += (_, _) => DoNotRenderEntities.Enable(DoNotRenderEntitiesEnabled.Value);
|
||||
DragBuildPowerPolesEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.Enable(DragBuildPowerPolesEnabled.Value);
|
||||
DragBuildPowerPolesAlternatelyEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.AlternatelyChanged();
|
||||
AutoConstructEnabled.SettingChanged += (_, _) => Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
|
||||
BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
|
||||
TankFastFillInAndTakeOutEnabled.SettingChanged += (_, _) => TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
|
||||
TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => UpdateTankFastFillInAndTakeOutMultiplierRealValue();
|
||||
@@ -274,6 +276,76 @@ 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()
|
||||
{
|
||||
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
|
||||
_lastPrebuildCount = -1;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.UnloadFactory))]
|
||||
private static void PlanetData_UnloadFactory_Postfix()
|
||||
{
|
||||
Functions.UIFunctions.UpdateToggleAutoConstructCheckButtonVisiblility();
|
||||
_lastPrebuildCount = -1;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerAction_Rts), nameof(PlayerAction_Rts.GameTick))]
|
||||
private static void PlayerAction_Rts_GameTick_Prefix(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;
|
||||
}
|
||||
if (prebuildCount <= 0) return;
|
||||
if (!AutoConstructEnabled.Value) return;
|
||||
var player = __instance.player;
|
||||
if (player.orders.orderCount > 0) return;
|
||||
if (player.movementState == EMovementState.Walk && player.mecha.thrusterLevel >= 1)
|
||||
{
|
||||
player.controller.actionWalk.SwitchToFly();
|
||||
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;
|
||||
if ((prebuilds[minIndex].pos - playerPos).sqrMagnitude < 400f) return;
|
||||
player.Order(OrderNode.MoveTo(prebuilds[minIndex].pos), false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class NightLight : PatchImpl<NightLight>
|
||||
{
|
||||
private static bool _nightlightInitialized;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MyCheckButton : MonoBehaviour
|
||||
openNormalColor = tankWindow.openNormalColor;
|
||||
closeMouseOverColor = tankWindow.closeMouseOverColor;
|
||||
closePressColor = tankWindow.closePressColor;
|
||||
closeNormalColor = tankWindow.closeNormalColor;
|
||||
closeNormalColor = /*tankWindow.closeNormalColor*/ new Color(0.6557f, 0.9145f, 1f, 0.4f);
|
||||
|
||||
var go = Instantiate(UIRoot.instance.uiGame.beltWindow.reverseButton.gameObject);
|
||||
go.name = "my-checkbutton";
|
||||
@@ -259,7 +259,7 @@ public class MyCheckButton : MonoBehaviour
|
||||
{
|
||||
uiButton.transitions[0].mouseoverColor = closeMouseOverColor;
|
||||
uiButton.transitions[0].pressedColor = closePressColor;
|
||||
uiButton.transitions[0].normalColor = new Color(0.6557f, 0.9145f, 1f, 0.0627f);
|
||||
uiButton.transitions[0].normalColor = closeNormalColor;
|
||||
}
|
||||
uiButton.RefreshTransitionsImmediately();
|
||||
}
|
||||
|
||||
@@ -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.AutoConstructEnabled = Config.Bind("Factory", "AutoConstruct", false,
|
||||
"Fly toward the building to be constructed automatically");
|
||||
FactoryPatch.BeltSignalsForBuyOutEnabled = Config.Bind("Factory", "BeltSignalsForBuyOut", false,
|
||||
"Belt signals for buy out dark fog items automatically");
|
||||
FactoryPatch.TankFastFillInAndTakeOutEnabled = Config.Bind("Factory", "TankFastFillInAndTakeOut", false,
|
||||
|
||||
Reference in New Issue
Block a user