mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-02-05 10:22:19 +08:00
WIP
This commit is contained in:
@@ -64,6 +64,12 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
"Birth star has high luminosity").Value;
|
"Birth star has high luminosity").Value;
|
||||||
_terraformAnyway = Config.Bind("General", "TerraformAnyway", _terraformAnyway,
|
_terraformAnyway = Config.Bind("General", "TerraformAnyway", _terraformAnyway,
|
||||||
"Can do terraform without enough sands").Value;
|
"Can do terraform without enough sands").Value;
|
||||||
|
|
||||||
|
I18N.Init();
|
||||||
|
|
||||||
|
// UI Patch
|
||||||
|
Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
||||||
|
|
||||||
if (_devShortcuts)
|
if (_devShortcuts)
|
||||||
{
|
{
|
||||||
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
||||||
|
|||||||
61
CheatEnabler/I18N.cs
Normal file
61
CheatEnabler/I18N.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace CheatEnabler;
|
||||||
|
|
||||||
|
public class I18N
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Harmony.CreateAndPatchAll(typeof(I18N));
|
||||||
|
}
|
||||||
|
private static int _nextID = 0;
|
||||||
|
private static readonly List<StringProto> StringsToAdd = new();
|
||||||
|
public static void Add(string key, string enus, string zhcn = null, string frfr = null)
|
||||||
|
{
|
||||||
|
var strings = LDB._strings;
|
||||||
|
while (_nextID <= 12000)
|
||||||
|
{
|
||||||
|
if (!strings.dataIndices.ContainsKey(_nextID))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_nextID++;
|
||||||
|
}
|
||||||
|
var strProto = new StringProto
|
||||||
|
{
|
||||||
|
Name = key,
|
||||||
|
ID = _nextID,
|
||||||
|
SID = "",
|
||||||
|
ENUS = enus,
|
||||||
|
ZHCN = string.IsNullOrEmpty(zhcn) ? enus : zhcn,
|
||||||
|
FRFR = string.IsNullOrEmpty(frfr) ? enus : frfr
|
||||||
|
};
|
||||||
|
StringsToAdd.Add(strProto);
|
||||||
|
_nextID++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool _initialized = false;
|
||||||
|
[HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||||
|
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||||
|
{
|
||||||
|
if (_initialized) return;
|
||||||
|
_initialized = true;
|
||||||
|
if (StringsToAdd.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var strings = LDB._strings;
|
||||||
|
var index = strings.dataArray.Length;
|
||||||
|
strings.dataArray = strings.dataArray.Concat(StringsToAdd).ToArray();
|
||||||
|
StringsToAdd.Clear();
|
||||||
|
var newIndex = strings.dataArray.Length;
|
||||||
|
for (; index < newIndex; index++)
|
||||||
|
{
|
||||||
|
strings.dataIndices[strings.dataArray[index].ID] = index;
|
||||||
|
strings.nameIndices[strings.dataArray[index].Name] = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
88
CheatEnabler/UI/MyCheckbox.cs
Normal file
88
CheatEnabler/UI/MyCheckbox.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace CheatEnabler.UI;
|
||||||
|
|
||||||
|
// MyCheckBox modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyCheckBox.cs
|
||||||
|
public class MyCheckBox : MonoBehaviour
|
||||||
|
{
|
||||||
|
public UIButton uiButton;
|
||||||
|
public Image checkImage;
|
||||||
|
public RectTransform rectTrans;
|
||||||
|
public Text labelText;
|
||||||
|
|
||||||
|
public event Action OnChecked;
|
||||||
|
public bool Checked
|
||||||
|
{
|
||||||
|
get => _checked;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_checked = value;
|
||||||
|
checkImage.enabled = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _checked;
|
||||||
|
|
||||||
|
public static MyCheckBox CreateCheckBox(bool check, Transform parent = null, float x = 0f, float y = 0f, string label = "", int fontSize = 15)
|
||||||
|
{
|
||||||
|
var buildMenu = UIRoot.instance.uiGame.buildMenu;
|
||||||
|
var src = buildMenu.uxFacilityCheck;
|
||||||
|
|
||||||
|
var go = Instantiate(src.gameObject);
|
||||||
|
var rect = go.transform as RectTransform;
|
||||||
|
if (rect == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
go.name = "my-checkbox";
|
||||||
|
var cb = go.AddComponent<MyCheckBox>();
|
||||||
|
cb._checked = check;
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
|
rect.SetParent(parent);
|
||||||
|
}
|
||||||
|
rect.anchorMax = new Vector2(0f, 1f);
|
||||||
|
rect.anchorMin = new Vector2(0f, 1f);
|
||||||
|
rect.pivot = new Vector2(0f, 1f);
|
||||||
|
rect.anchoredPosition3D = new Vector3(x, -y, 0f);
|
||||||
|
|
||||||
|
cb.rectTrans = rect;
|
||||||
|
cb.uiButton = go.GetComponent<UIButton>();
|
||||||
|
cb.checkImage = go.transform.Find("checked")?.GetComponent<Image>();
|
||||||
|
|
||||||
|
var child = go.transform.Find("text");
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
DestroyImmediate(child.GetComponent<Localizer>());
|
||||||
|
cb.labelText = child.GetComponent<Text>();
|
||||||
|
cb.labelText.fontSize = fontSize;
|
||||||
|
cb.SetLabelText(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
//value
|
||||||
|
cb.uiButton.onClick += cb.OnClick;
|
||||||
|
if (cb.checkImage != null)
|
||||||
|
{
|
||||||
|
cb.checkImage.enabled = check;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetLabelText(string val)
|
||||||
|
{
|
||||||
|
if (labelText != null)
|
||||||
|
{
|
||||||
|
labelText.text = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnClick(int obj)
|
||||||
|
{
|
||||||
|
_checked = !_checked;
|
||||||
|
checkImage.enabled = _checked;
|
||||||
|
OnChecked?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
159
CheatEnabler/UI/MyWindow.cs
Normal file
159
CheatEnabler/UI/MyWindow.cs
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace CheatEnabler.UI;
|
||||||
|
|
||||||
|
// MyWindowManager modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyWindowCtl.cs
|
||||||
|
public static class MyWindowManager
|
||||||
|
{
|
||||||
|
private static readonly List<ManualBehaviour> Windows = new(4);
|
||||||
|
private static bool _inited = false;
|
||||||
|
|
||||||
|
public static T CreateWindow<T>(string name, string title = "") where T : Component
|
||||||
|
{
|
||||||
|
var srcWin = UIRoot.instance.uiGame.tankWindow;
|
||||||
|
var src = srcWin.gameObject;
|
||||||
|
var go = Object.Instantiate(src, srcWin.transform.parent);
|
||||||
|
go.name = name;
|
||||||
|
go.SetActive(false);
|
||||||
|
Object.Destroy(go.GetComponent<UITankWindow>());
|
||||||
|
var win = go.AddComponent<T>() as ManualBehaviour;
|
||||||
|
if (win == null)
|
||||||
|
return null;
|
||||||
|
//shadow
|
||||||
|
for (var i = 0; i < go.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
var child = go.transform.GetChild(i).gameObject;
|
||||||
|
if (child.name == "panel-bg")
|
||||||
|
{
|
||||||
|
var btn = child.GetComponentInChildren<Button>();
|
||||||
|
//close-btn
|
||||||
|
if (btn != null)
|
||||||
|
{
|
||||||
|
btn.onClick.AddListener(win._Close);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (child.name != "shadow" && child.name != "panel-bg")
|
||||||
|
{
|
||||||
|
Object.Destroy(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTitle(win, title);
|
||||||
|
win._Create();
|
||||||
|
if (_inited)
|
||||||
|
{
|
||||||
|
win._Init(win.data);
|
||||||
|
}
|
||||||
|
Windows.Add(win);
|
||||||
|
return win as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetTitle(ManualBehaviour win, string title)
|
||||||
|
{
|
||||||
|
var txt = GetTitleText(win);
|
||||||
|
if (txt)
|
||||||
|
{
|
||||||
|
txt.text = title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Text GetTitleText(ManualBehaviour win)
|
||||||
|
{
|
||||||
|
return win.gameObject.transform.Find("panel-bg/title-text")?.gameObject.GetComponent<Text>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static RectTransform GetRectTransform(ManualBehaviour win)
|
||||||
|
{
|
||||||
|
return win.GetComponent<RectTransform>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public static void SetRect(ManualBehaviour win, RectTransform rect)
|
||||||
|
{
|
||||||
|
var rectTransform = win.GetComponent<RectTransform>();
|
||||||
|
//rectTransform.position =
|
||||||
|
//rectTransform.sizeDelta = rect;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void OpenWindow(ManualBehaviour win)
|
||||||
|
{
|
||||||
|
win._Open();
|
||||||
|
win.transform.SetAsLastSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CloseWindow(ManualBehaviour win)
|
||||||
|
{
|
||||||
|
win._Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Patch
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
//_Create -> _Init
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnCreate")]
|
||||||
|
public static void UIGame__OnCreate_Postfix()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnDestroy")]
|
||||||
|
public static void UIGame__OnDestroy_Postfix()
|
||||||
|
{
|
||||||
|
foreach (var win in Windows)
|
||||||
|
{
|
||||||
|
win._Destroy();
|
||||||
|
}
|
||||||
|
Windows.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnInit")]
|
||||||
|
public static void UIGame__OnInit_Postfix(UIGame __instance)
|
||||||
|
{
|
||||||
|
foreach (var win in Windows)
|
||||||
|
{
|
||||||
|
win._Init(win.data);
|
||||||
|
}
|
||||||
|
_inited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnFree")]
|
||||||
|
public static void UIGame__OnFree_Postfix()
|
||||||
|
{
|
||||||
|
foreach (var win in Windows)
|
||||||
|
{
|
||||||
|
win._Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnUpdate")]
|
||||||
|
public static void UIGame__OnUpdate_Postfix()
|
||||||
|
{
|
||||||
|
if (GameMain.isPaused || !GameMain.isRunning)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (var win in Windows)
|
||||||
|
{
|
||||||
|
win._Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "ShutAllFunctionWindow")]
|
||||||
|
public static void UIGame_ShutAllFunctionWindow_Postfix()
|
||||||
|
{
|
||||||
|
foreach (var win in Windows)
|
||||||
|
{
|
||||||
|
win._Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user