mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 21:33:28 +08:00
WIP
This commit is contained in:
@@ -113,34 +113,38 @@ public class CheatEnabler : BaseUnityPlugin
|
||||
ShowConfigWindow();
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), "_OnOpen")]
|
||||
public static void UIRoot__OnOpen_Postfix()
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(UIRoot), nameof(UIRoot.OpenMainMenuUI))]
|
||||
public static void UIRoot_OpenMainMenuUI_Postfix()
|
||||
{
|
||||
if (_initialized) return;
|
||||
{
|
||||
var mainMenu = UIRoot.instance.uiMainMenu;
|
||||
var src = mainMenu.newGameButton.gameObject;
|
||||
var src = mainMenu.newGameButton;
|
||||
var parent = src.transform.parent;
|
||||
var btn = Instantiate(src, parent);
|
||||
btn.name = "btn-cheatenabler-config";
|
||||
var btnConfig = btn.GetComponent<UIMainMenuButton>();
|
||||
btnConfig.text.text = "CheatEnabler Config";
|
||||
btnConfig.text.fontSize = btnConfig.text.fontSize * 7 / 8;
|
||||
I18N.OnInitialized += () => { btnConfig.text.text = "CheatEnabler Config".Translate(); };
|
||||
btnConfig.transform.SetParent(parent);
|
||||
btn.name = "button-cheatenabler-config";
|
||||
var l = btn.text.GetComponent<Localizer>();
|
||||
if (l != null)
|
||||
{
|
||||
l.stringKey = "CheatEnabler Config";
|
||||
l.translation = "CheatEnabler Config".Translate();
|
||||
}
|
||||
btn.text.text = "CheatEnabler Config".Translate();
|
||||
btn.text.fontSize = btn.text.fontSize * 7 / 8;
|
||||
I18N.OnInitialized += () => { btn.text.text = "CheatEnabler Config".Translate(); };
|
||||
var vec = ((RectTransform)mainMenu.exitButton.transform).anchoredPosition3D;
|
||||
var vec2 = ((RectTransform)mainMenu.creditsButton.transform).anchoredPosition3D;
|
||||
var transform1 = (RectTransform)btn.transform;
|
||||
transform1.anchoredPosition3D = new Vector3(vec.x, vec.y + (vec.y - vec2.y) * 2, vec.z);
|
||||
btnConfig.button.onClick.RemoveAllListeners();
|
||||
btnConfig.button.onClick.AddListener(ShowConfigWindow);
|
||||
btn.button.onClick.RemoveAllListeners();
|
||||
btn.button.onClick.AddListener(ShowConfigWindow);
|
||||
}
|
||||
{
|
||||
var panel = UIRoot.instance.uiGame.planetGlobe;
|
||||
var src = panel.button2;
|
||||
var sandboxMenu = UIRoot.instance.uiGame.sandboxMenu;
|
||||
var icon = sandboxMenu.categoryButtons[6].transform.Find("icon")?.GetComponent<Image>()?.sprite;
|
||||
var b = GameObject.Instantiate<Button>(src, src.transform.parent);
|
||||
var b = Instantiate(src, src.transform.parent);
|
||||
var panelButtonGo = b.gameObject;
|
||||
var rect = (RectTransform)panelButtonGo.transform;
|
||||
var btn = panelButtonGo.GetComponent<UIButton>();
|
||||
|
||||
160
CheatEnabler/PlanetFunctions.cs
Normal file
160
CheatEnabler/PlanetFunctions.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CheatEnabler;
|
||||
public static class PlanetFunctions {
|
||||
public static void DismantleAll(bool toBag)
|
||||
{
|
||||
var player = GameMain.mainPlayer;
|
||||
if (player == null) return;
|
||||
var planet = GameMain.localPlanet;
|
||||
if (planet == null || planet.factory == null) return;
|
||||
foreach (var etd in GameMain.localPlanet.factory.entityPool)
|
||||
{
|
||||
var stationId = etd.stationId;
|
||||
if (stationId > 0)
|
||||
{
|
||||
var sc = GameMain.localPlanet.factory.transport.stationPool[stationId];
|
||||
if (toBag)
|
||||
{
|
||||
for (var i = 0; i < sc.storage.Length; i++)
|
||||
{
|
||||
var package = player.TryAddItemToPackage(sc.storage[i].itemId, sc.storage[i].count, 0, true, etd.id);
|
||||
UIItemup.Up(sc.storage[i].itemId, package);
|
||||
}
|
||||
}
|
||||
|
||||
sc.storage = new StationStore[sc.storage.Length];
|
||||
sc.needs = new int[sc.needs.Length];
|
||||
}
|
||||
|
||||
if (toBag)
|
||||
{
|
||||
player.controller.actionBuild.DoDismantleObject(etd.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.localPlanet.factory.RemoveEntityWithComponents(etd.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void BuryAllVeins(bool bury)
|
||||
{
|
||||
var planet = GameMain.localPlanet;
|
||||
var factory = planet?.factory;
|
||||
if (factory == null) return;
|
||||
var physics = planet.physics;
|
||||
var height = bury ? planet.realRadius - 50f : planet.realRadius + 0.07f;
|
||||
var array = factory.veinPool;
|
||||
var num = factory.veinCursor;
|
||||
for (var m = 1; m < num; m++)
|
||||
{
|
||||
var pos = array[m].pos;
|
||||
var colliderId = array[m].colliderId;
|
||||
var colliderData = physics.GetColliderData(colliderId);
|
||||
var vector = colliderData.pos.normalized * (height + 0.4f);
|
||||
physics.colChunks[colliderId >> 20].colliderPool[colliderId & 0xFFFFF].pos = vector;
|
||||
array[m].pos = pos.normalized * height;
|
||||
var quaternion = Maths.SphericalRotation(array[m].pos, Random.value * 360f);
|
||||
physics.SetPlanetPhysicsColliderDirty();
|
||||
GameMain.gpuiManager.AlterModel(array[m].modelIndex, array[m].modelId, m, array[m].pos, quaternion, false);
|
||||
}
|
||||
GameMain.gpuiManager.SyncAllGPUBuffer();
|
||||
}
|
||||
|
||||
public static void RecreatePlanet(bool revertReform)
|
||||
{
|
||||
var player = GameMain.mainPlayer;
|
||||
if (player == null) return;
|
||||
var planet = GameMain.localPlanet;
|
||||
var factory = planet?.factory;
|
||||
if (factory == null) return;
|
||||
//planet.data = new PlanetRawData(planet.precision);
|
||||
//planet.data.CalcVerts();
|
||||
for (var id = 1; id < factory.entityCursor; id++)
|
||||
{
|
||||
var ed = factory.entityPool[id];
|
||||
if (ed.id != id) continue;
|
||||
if (ed.colliderId != 0)
|
||||
{
|
||||
planet.physics.RemoveLinkedColliderData(ed.colliderId);
|
||||
planet.physics.NotifyObjectRemove(EObjectType.Entity, ed.id);
|
||||
}
|
||||
|
||||
if (ed.modelId != 0)
|
||||
{
|
||||
GameMain.gpuiManager.RemoveModel(ed.modelIndex, ed.modelId);
|
||||
}
|
||||
|
||||
if (ed.mmblockId != 0)
|
||||
{
|
||||
factory.blockContainer.RemoveMiniBlock(ed.mmblockId);
|
||||
}
|
||||
|
||||
if (ed.audioId != 0)
|
||||
{
|
||||
if (planet.audio != null)
|
||||
{
|
||||
planet.audio.RemoveAudioData(ed.audioId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (factory.transport != null && factory.transport.stationPool != null)
|
||||
{
|
||||
foreach (var sc in factory.transport.stationPool)
|
||||
{
|
||||
if (sc == null || sc.id <= 0) continue;
|
||||
sc.storage = new StationStore[sc.storage.Length];
|
||||
sc.needs = new int[sc.needs.Length];
|
||||
int protoId = factory.entityPool[sc.entityId].protoId;
|
||||
factory.DismantleFinally(player, sc.entityId, ref protoId);
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.gameScenario != null)
|
||||
{
|
||||
if (factory.powerSystem != null && factory.powerSystem.genPool != null)
|
||||
{
|
||||
foreach (var pgc in factory.powerSystem.genPool)
|
||||
{
|
||||
if (pgc.id <= 0) continue;
|
||||
int protoId = factory.entityPool[pgc.entityId].protoId;
|
||||
GameMain.gameScenario.achievementLogic.NotifyBeforeDismantleEntity(planet.id, protoId, pgc.entityId);
|
||||
GameMain.gameScenario.NotifyOnDismantleEntity(planet.id, protoId, pgc.entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (revertReform)
|
||||
{
|
||||
factory.PlanetReformRevert();
|
||||
}
|
||||
|
||||
planet.UnloadFactory();
|
||||
var index = factory.index;
|
||||
for (var i = 1; i < GameMain.data.warningSystem.warningCursor; i++)
|
||||
{
|
||||
if (GameMain.data.warningSystem.warningPool[i].factoryId == index)
|
||||
GameMain.data.warningSystem.RemoveWarningData(GameMain.data.warningSystem.warningPool[i].id);
|
||||
}
|
||||
|
||||
factory.entityCursor = 1;
|
||||
factory.entityRecycleCursor = 0;
|
||||
factory.SetEntityCapacity(1024);
|
||||
factory.prebuildCursor = 1;
|
||||
factory.prebuildRecycleCursor = 0;
|
||||
factory.SetPrebuildCapacity(256);
|
||||
factory.cargoContainer = new CargoContainer();
|
||||
factory.cargoTraffic = new CargoTraffic(planet);
|
||||
factory.blockContainer = new MiniBlockContainer();
|
||||
factory.factoryStorage = new FactoryStorage(planet);
|
||||
factory.powerSystem = new PowerSystem(planet);
|
||||
factory.factorySystem = new FactorySystem(planet);
|
||||
factory.transport = new PlanetTransport(GameMain.data, planet);
|
||||
factory.transport.Init();
|
||||
factory.digitalSystem = new DigitalSystem(planet);
|
||||
//GameMain.data.statistics.production.CreateFactoryStat(index);
|
||||
planet.LoadFactory();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace CheatEnabler.UI;
|
||||
public class MyWindow: ManualBehaviour
|
||||
{
|
||||
private readonly Dictionary<InputField, Tuple<UnityAction<string>, UnityAction<string>>> _inputFields = new();
|
||||
private readonly Dictionary<UIButton, UnityAction> _buttons = new();
|
||||
protected bool EventRegistered { get; private set; }
|
||||
|
||||
public virtual void TryClose()
|
||||
@@ -67,18 +68,51 @@ public class MyWindow: ManualBehaviour
|
||||
return txt;
|
||||
}
|
||||
|
||||
protected UIButton AddButton(float x, float y, RectTransform parent, string text = "", int fontSize = 16, string objName = "button", UnityAction onClick = null)
|
||||
{
|
||||
var panel = UIRoot.instance.uiGame.statWindow.performancePanelUI;
|
||||
var btn = Instantiate(panel.cpuActiveButton);
|
||||
btn.gameObject.name = objName;
|
||||
var rect = Util.NormalizeRectWithTopLeft(btn, x, y, parent);
|
||||
rect.sizeDelta = new Vector2(120, rect.sizeDelta.y);
|
||||
var l = btn.gameObject.transform.Find("button-text").GetComponent<Localizer>();
|
||||
var t = btn.gameObject.transform.Find("button-text").GetComponent<Text>();
|
||||
if (l != null)
|
||||
{
|
||||
l.stringKey = text;
|
||||
l.translation = text.Translate();
|
||||
}
|
||||
if (t != null)
|
||||
{
|
||||
t.text = text.Translate();
|
||||
}
|
||||
t.fontSize = fontSize;
|
||||
btn.button.onClick.RemoveAllListeners();
|
||||
btn.tip = null;
|
||||
btn.tips = new UIButton.TipSettings();
|
||||
_buttons[btn] = onClick;
|
||||
if (EventRegistered)
|
||||
{
|
||||
if (onClick != null)
|
||||
btn.button.onClick.AddListener(onClick);
|
||||
}
|
||||
return btn;
|
||||
}
|
||||
|
||||
protected InputField AddInputField(float x, float y, RectTransform parent, string text = "", int fontSize = 16, string objName = "input", UnityAction<string> onChanged = null, UnityAction<string> onEditEnd = null)
|
||||
{
|
||||
var stationWindow = UIRoot.instance.uiGame.stationWindow;
|
||||
//public InputField nameInput;
|
||||
var inputField = Instantiate(stationWindow.nameInput);
|
||||
inputField.gameObject.name = "search-field";
|
||||
inputField.gameObject.name = objName;
|
||||
Destroy(inputField.GetComponent<UIButton>());
|
||||
inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f);
|
||||
var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent);
|
||||
rect.sizeDelta = new Vector2(210, rect.sizeDelta.y);
|
||||
inputField.textComponent.text = text;
|
||||
inputField.textComponent.fontSize = fontSize;
|
||||
inputField.onValueChanged.RemoveAllListeners();
|
||||
inputField.onEndEdit.RemoveAllListeners();
|
||||
_inputFields[inputField] = Tuple.Create(onChanged, onEditEnd);
|
||||
if (EventRegistered)
|
||||
{
|
||||
@@ -102,6 +136,12 @@ public class MyWindow: ManualBehaviour
|
||||
if (t.Value.Item2 != null)
|
||||
inputField.onEndEdit.AddListener(t.Value.Item2);
|
||||
}
|
||||
foreach (var t in _buttons)
|
||||
{
|
||||
var btn = t.Key;
|
||||
if (t.Value != null)
|
||||
btn.button.onClick.AddListener(t.Value);
|
||||
}
|
||||
EventRegistered = true;
|
||||
}
|
||||
|
||||
@@ -110,6 +150,12 @@ public class MyWindow: ManualBehaviour
|
||||
base._OnUnregEvent();
|
||||
if (!EventRegistered) return;
|
||||
EventRegistered = false;
|
||||
foreach (var t in _buttons)
|
||||
{
|
||||
var btn = t.Key;
|
||||
if (t.Value != null)
|
||||
btn.button.onClick.RemoveListener(t.Value);
|
||||
}
|
||||
foreach (var t in _inputFields)
|
||||
{
|
||||
var inputField = t.Key;
|
||||
@@ -144,6 +190,7 @@ public class MyWindowWithTabs : MyWindow
|
||||
var src = swarmPanel.orbitButtons[0];
|
||||
var btn = Instantiate(src);
|
||||
var btnRect = Util.NormalizeRectWithTopLeft(btn, x, 54f, parent);
|
||||
btn.name = "tab-btn-" + index;
|
||||
btnRect.sizeDelta = new Vector2(100f, 24f);
|
||||
btn.transform.Find("frame").gameObject.SetActive(false);
|
||||
if (btn.transitions.Length >= 3)
|
||||
|
||||
@@ -27,6 +27,8 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
||||
I18N.Add("Unipolar magnet on birth planet", "Unipolar magnet on birth planet", "母星有单极磁石");
|
||||
I18N.Add("Birth planet is solid flat (no water at all)", "Birth planet is solid flat (no water at all)", "母星是纯平的(没有水)");
|
||||
I18N.Add("Birth star has high luminosity", "Birth star has high luminosity", "母星系恒星高亮");
|
||||
I18N.Add("Initialize This Planet", "Initialize This Planet", "初始化本行星");
|
||||
I18N.Add("Dismantle All Buildings", "Dismantle All Buildings", "拆除所有建筑");
|
||||
I18N.Apply();
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
||||
public override void _OnCreate()
|
||||
{
|
||||
_windowTrans = GetComponent<RectTransform>();
|
||||
_windowTrans.sizeDelta = new Vector2(480f, 295f);
|
||||
_windowTrans.sizeDelta = new Vector2(480f, 331f);
|
||||
|
||||
CreateUI();
|
||||
}
|
||||
@@ -64,6 +66,44 @@ public class UIConfigWindow : UI.MyWindowWithTabs
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, WaterPumperPatch.Enabled, "Pump Anywhere".Translate());
|
||||
y += 36f;
|
||||
UI.MyCheckBox.CreateCheckBox(x, y, tab2, TerraformPatch.Enabled, "Terraform without enought sands".Translate());
|
||||
x = 300f;
|
||||
y = 10f;
|
||||
AddButton(x, y, tab2, "矿物掩埋标题", 16, "button-bury-all", () =>
|
||||
{
|
||||
PlanetFunctions.BuryAllVeins(true);
|
||||
});
|
||||
y += 36f;
|
||||
AddButton(x, y, tab2, "矿物还原标题", 16, "button-bury-restore-all", () =>
|
||||
{
|
||||
PlanetFunctions.BuryAllVeins(false);
|
||||
});
|
||||
y += 36f;
|
||||
AddButton(x, y, tab2, "铺满地基提示", 16, "button-reform-all", () =>
|
||||
{
|
||||
var player = GameMain.mainPlayer;
|
||||
if (player == null) return;
|
||||
var reformTool = player.controller.actionBuild.reformTool;
|
||||
var factory = GameMain.localPlanet?.factory;
|
||||
if (factory == null) return;
|
||||
GameMain.localPlanet.factory.PlanetReformAll(reformTool.brushType, reformTool.brushColor, reformTool.buryVeins);
|
||||
});
|
||||
y += 36f;
|
||||
AddButton(x, y, tab2, "还原地形提示", 16, "button-reform-revert-all", () =>
|
||||
{
|
||||
var factory = GameMain.localPlanet?.factory;
|
||||
if (factory == null) return;
|
||||
GameMain.localPlanet.factory.PlanetReformRevert();
|
||||
});
|
||||
y += 36f;
|
||||
AddButton(x, y, tab2, "Initialize This Planet", 16, "button-init-planet", () =>
|
||||
{
|
||||
PlanetFunctions.RecreatePlanet(true);
|
||||
});
|
||||
y += 36f;
|
||||
AddButton(x, y, tab2, "Dismantle All Buildings", 16, "button-dismantle-all", () =>
|
||||
{
|
||||
PlanetFunctions.DismantleAll(false);
|
||||
});
|
||||
|
||||
var tab3 = AddTab(236f, 2, _windowTrans, "Birth".Translate());
|
||||
x = 0f;
|
||||
|
||||
Reference in New Issue
Block a user