mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 21:33:28 +08:00
tweaks for Dyson Shell dismantling
This commit is contained in:
44
UXAssist/Functions/DysonSphereFunctions.cs
Normal file
44
UXAssist/Functions/DysonSphereFunctions.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
namespace UXAssist.Functions;
|
||||||
|
|
||||||
|
public static class DysonSphereFunctions
|
||||||
|
{
|
||||||
|
public static StarData CurrentStarForDysonSystem()
|
||||||
|
{
|
||||||
|
StarData star = null;
|
||||||
|
var dysonEditor = UIRoot.instance?.uiGame?.dysonEditor;
|
||||||
|
if (dysonEditor != null && dysonEditor.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
star = dysonEditor.selection.viewStar;
|
||||||
|
}
|
||||||
|
return star ?? GameMain.data?.localStar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InitCurrentDysonLayer(StarData star, int index)
|
||||||
|
{
|
||||||
|
star ??= CurrentStarForDysonSystem();
|
||||||
|
if (star == null) return;
|
||||||
|
var dysonSpheres = GameMain.data?.dysonSpheres;
|
||||||
|
if (dysonSpheres == null) return;
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
if (dysonSpheres[star.index] == null) return;
|
||||||
|
var dysonSphere = new DysonSphere();
|
||||||
|
dysonSpheres[star.index] = dysonSphere;
|
||||||
|
dysonSphere.Init(GameMain.data, star);
|
||||||
|
dysonSphere.ResetNew();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ds = dysonSpheres[star.index];
|
||||||
|
if (ds?.layersIdBased[index] == null) return;
|
||||||
|
var pool = ds.rocketPool;
|
||||||
|
for (var id = ds.rocketCursor - 1; id > 0; id--)
|
||||||
|
{
|
||||||
|
if (pool[id].id != id) continue;
|
||||||
|
if (pool[id].nodeLayerId != index) continue;
|
||||||
|
ds.RemoveDysonRocket(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ds.RemoveLayer(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,35 +40,6 @@ public class DysonSpherePatch: PatchImpl<DysonSpherePatch>
|
|||||||
Enable(false);
|
Enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void InitCurrentDysonSphere(int index)
|
|
||||||
{
|
|
||||||
var star = GameMain.localStar;
|
|
||||||
if (star == null) return;
|
|
||||||
var dysonSpheres = GameMain.data?.dysonSpheres;
|
|
||||||
if (dysonSpheres == null) return;
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
if (dysonSpheres[star.index] == null) return;
|
|
||||||
var dysonSphere = new DysonSphere();
|
|
||||||
dysonSpheres[star.index] = dysonSphere;
|
|
||||||
dysonSphere.Init(GameMain.data, star);
|
|
||||||
dysonSphere.ResetNew();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var ds = dysonSpheres[star.index];
|
|
||||||
if (ds?.layersIdBased[index] == null) return;
|
|
||||||
var pool = ds.rocketPool;
|
|
||||||
for (var id = ds.rocketCursor - 1; id > 0; id--)
|
|
||||||
{
|
|
||||||
if (pool[id].id != id) continue;
|
|
||||||
if (pool[id].nodeLayerId != index) continue;
|
|
||||||
ds.RemoveDysonRocket(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ds.RemoveLayer(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(DysonSwarm), nameof(DysonSwarm.AutoConstruct))]
|
[HarmonyPatch(typeof(DysonSwarm), nameof(DysonSwarm.AutoConstruct))]
|
||||||
private static bool DysonSwarm_AutoConstruct_Prefix(DysonSwarm __instance)
|
private static bool DysonSwarm_AutoConstruct_Prefix(DysonSwarm __instance)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public static class UIConfigWindow
|
|||||||
{
|
{
|
||||||
private static RectTransform _windowTrans;
|
private static RectTransform _windowTrans;
|
||||||
private static RectTransform _dysonTab;
|
private static RectTransform _dysonTab;
|
||||||
|
private static UIButton _dysonInitBtn;
|
||||||
private static readonly UIButton[] DysonLayerBtn = new UIButton[10];
|
private static readonly UIButton[] DysonLayerBtn = new UIButton[10];
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
@@ -365,9 +366,9 @@ public static class UIConfigWindow
|
|||||||
wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.OnlyConstructNodesEnabled, "Construct only structure points but frames");
|
wnd.AddCheckBox(x, y, tab4, DysonSpherePatch.OnlyConstructNodesEnabled, "Construct only structure points but frames");
|
||||||
x = 400f;
|
x = 400f;
|
||||||
y = 10f;
|
y = 10f;
|
||||||
wnd.AddButton(x, y, tab4, "Initialize Dyson Sphere", 16, "init-dyson-sphere", () =>
|
_dysonInitBtn = wnd.AddButton(x, y, tab4, "Initialize Dyson Sphere", 16, "init-dyson-sphere", () =>
|
||||||
UIMessageBox.Show("Initialize Dyson Sphere".Translate(), "Initialize Dyson Sphere Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null,
|
UIMessageBox.Show("Initialize Dyson Sphere".Translate(), "Initialize Dyson Sphere Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null,
|
||||||
() => { DysonSpherePatch.InitCurrentDysonSphere(-1); })
|
() => { DysonSphereFunctions.InitCurrentDysonLayer(null, -1); })
|
||||||
);
|
);
|
||||||
y += 36f;
|
y += 36f;
|
||||||
wnd.AddText2(x, y, tab4, "Click to dismantle selected layer", 16, "text-dismantle-layer");
|
wnd.AddText2(x, y, tab4, "Click to dismantle selected layer", 16, "text-dismantle-layer");
|
||||||
@@ -376,8 +377,11 @@ public static class UIConfigWindow
|
|||||||
{
|
{
|
||||||
var id = i + 1;
|
var id = i + 1;
|
||||||
var btn = wnd.AddFlatButton(x, y, tab4, id.ToString(), 12, "dismantle-layer-" + id, () =>
|
var btn = wnd.AddFlatButton(x, y, tab4, id.ToString(), 12, "dismantle-layer-" + id, () =>
|
||||||
UIMessageBox.Show("Dismantle selected layer".Translate(), "Dismantle selected layer Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null,
|
{
|
||||||
() => { DysonSpherePatch.InitCurrentDysonSphere(id); })
|
var star = DysonSphereFunctions.CurrentStarForDysonSystem();
|
||||||
|
UIMessageBox.Show("Dismantle selected layer".Translate(), "Dismantle selected layer Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null,
|
||||||
|
() => { DysonSphereFunctions.InitCurrentDysonLayer(star, id); });
|
||||||
|
}
|
||||||
);
|
);
|
||||||
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
|
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
|
||||||
DysonLayerBtn[i] = btn;
|
DysonLayerBtn[i] = btn;
|
||||||
@@ -440,26 +444,22 @@ public static class UIConfigWindow
|
|||||||
private static void UpdateDysonShells()
|
private static void UpdateDysonShells()
|
||||||
{
|
{
|
||||||
if (!_dysonTab.gameObject.activeSelf) return;
|
if (!_dysonTab.gameObject.activeSelf) return;
|
||||||
var star = GameMain.localStar;
|
var star = DysonSphereFunctions.CurrentStarForDysonSystem();
|
||||||
if (star != null)
|
if (star == null)
|
||||||
{
|
{
|
||||||
var dysonSpheres = GameMain.data?.dysonSpheres;
|
for (var i = 0; i < 10; i++)
|
||||||
if (dysonSpheres?[star.index] != null)
|
|
||||||
{
|
{
|
||||||
var ds = dysonSpheres[star.index];
|
DysonLayerBtn[i].button.interactable = false;
|
||||||
for (var i = 1; i <= 10; i++)
|
|
||||||
{
|
|
||||||
var layer = ds.layersIdBased[i];
|
|
||||||
DysonLayerBtn[i - 1].button.interactable = layer != null && layer.id == i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
var dysonSpheres = GameMain.data?.dysonSpheres;
|
||||||
for (var i = 0; i < 10; i++)
|
if (dysonSpheres?[star.index] == null) return;
|
||||||
|
var ds = dysonSpheres[star.index];
|
||||||
|
for (var i = 1; i <= 10; i++)
|
||||||
{
|
{
|
||||||
DysonLayerBtn[i].button.interactable = false;
|
var layer = ds.layersIdBased[i];
|
||||||
|
DysonLayerBtn[i - 1].button.interactable = layer != null && layer.id == i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user