1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 16:13:31 +08:00

code cleanup

This commit is contained in:
2023-12-14 21:52:35 +08:00
parent aa5d8a2454
commit 51f35bb573
28 changed files with 318 additions and 466 deletions

View File

@@ -18,7 +18,7 @@ public static class I18N
public static bool Initialized() => _initialized;
private static int _nextID = 1;
private static readonly List<StringProto> StringsToAdd = new();
private static readonly List<StringProto> StringsToAdd = [];
public static void Add(string key, string enus, string zhcn = null, string frfr = null)
{
var strProto = new StringProto

View File

@@ -139,7 +139,7 @@ public static class DysonSpherePatch
private static void SetNodeForAbsorb(int index, int layerId, int nodeId, bool canAbsorb)
{
ref var comp = ref _nodeForAbsorb[index];
comp ??= new HashSet<int>();
comp ??= [];
var idx = nodeId * 10 + layerId;
if (canAbsorb)
comp.Add(idx);
@@ -241,7 +241,7 @@ public static class DysonSpherePatch
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(DysonNode), nameof(DysonNode.sp)))
).Advance(1);
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.Labels = [];
matcher.Insert(
new CodeInstruction(OpCodes.Ldarg_0).WithLabels(labels),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StopEjectOnNodeComplete), nameof(StopEjectOnNodeComplete.UpdateNodeForAbsorbOnSpChange)))

View File

@@ -326,7 +326,7 @@ public static class FactoryPatch
);
var jumpPos = matcher.InstructionAt(3).operand;
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.Labels = [];
/* Insert: br 2358 (1C12) ldloc.s V_8 (8)
*/
matcher.Insert(new CodeInstruction(OpCodes.Br, jumpPos).WithLabels(labels));
@@ -360,7 +360,7 @@ public static class FactoryPatch
{
// Remove 7 instructions, if the following instruction is br/br.s, remove it as well
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.Labels = [];
matcher.RemoveInstructions(7);
var opcode = matcher.Opcode;
if (opcode == OpCodes.Br || opcode == OpCodes.Br_S)
@@ -384,7 +384,7 @@ public static class FactoryPatch
matcher.Repeat(codeMatcher =>
{
var labels = codeMatcher.Labels;
codeMatcher.Labels = new List<Label>();
codeMatcher.Labels = [];
codeMatcher.RemoveInstructions(3);
var opcode = codeMatcher.Opcode;
if (opcode == OpCodes.Br || opcode == OpCodes.Br_S)

View File

@@ -178,7 +178,6 @@ public static class PlanetFunctions
{
if (prebuildPool[i].id != i) continue;
pos = prebuildPool[i].pos;
found = true;
break;
}
}

View File

@@ -51,7 +51,7 @@ public static class PlanetPatch
matcher.Repeat(codeMatcher =>
{
var labels = codeMatcher.Labels;
codeMatcher.Labels = new List<Label>();
codeMatcher.Labels = [];
codeMatcher.RemoveInstructions(3).Labels.AddRange(labels);
});
return matcher.InstructionEnumeration();
@@ -82,7 +82,7 @@ public static class PlanetPatch
new CodeMatch(OpCodes.Stloc_1)
);
var labels = matcher.Labels;
matcher.Labels = new List<Label>();
matcher.Labels = [];
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))).WithLabels(labels),
new CodeInstruction(OpCodes.Ldc_I4_3),

View File

@@ -121,8 +121,8 @@ public class MyKeyBinder : MonoBehaviour
}
}
public bool TrySetValue()
private bool TrySetValue()
{
if (Input.GetKey(KeyCode.Escape))
{
@@ -155,7 +155,7 @@ public class MyKeyBinder : MonoBehaviour
KeyCode.LeftCommand, KeyCode.LeftApple, KeyCode.LeftWindows,
KeyCode.RightCommand, KeyCode.RightApple, KeyCode.RightWindows };
public string GetPressedKey()
private string GetPressedKey()
{
var key = _lastKey.ToString();
if (string.IsNullOrEmpty(key))
@@ -179,7 +179,7 @@ public class MyKeyBinder : MonoBehaviour
}
//通常キーが押されているかチェック _lastKey に保存
public bool GetIunptKeys()
private bool GetIunptKeys()
{
var anyKey = false;

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Object = UnityEngine.Object;
namespace UXAssist.UI;
@@ -133,14 +134,13 @@ public class MyWindow: ManualBehaviour
if (t != null)
{
t.text = text.Translate();
t.fontSize = fontSize;
}
t.fontSize = fontSize;
btn.button.onClick.RemoveAllListeners();
_buttons[btn] = onClick;
if (EventRegistered)
if (EventRegistered && onClick != null)
{
if (onClick != null)
btn.button.onClick.AddListener(onClick);
btn.button.onClick.AddListener(onClick);
}
return btn;
}
@@ -215,7 +215,7 @@ public class MyWindow: ManualBehaviour
public class MyWindowWithTabs : MyWindow
{
private readonly List<Tuple<RectTransform, UIButton>> _tabs = new();
private readonly List<Tuple<RectTransform, UIButton>> _tabs = [];
private float _tabY = 54f;
public override void TryClose()
{
@@ -347,10 +347,10 @@ public static class MyWindowManager
{
var srcWin = UIRoot.instance.uiGame.tankWindow;
var src = srcWin.gameObject;
var go = GameObject.Instantiate(src, UIRoot.instance.uiGame.transform.parent);
var go = Object.Instantiate(src, UIRoot.instance.uiGame.transform.parent);
go.name = name;
go.SetActive(false);
GameObject.Destroy(go.GetComponent<UITankWindow>());
Object.Destroy(go.GetComponent<UITankWindow>());
var win = go.AddComponent<T>() as MyWindow;
if (win == null)
return null;
@@ -369,7 +369,7 @@ public static class MyWindowManager
}
else if (child.name != "shadow" && child.name != "panel-bg")
{
GameObject.Destroy(child);
Object.Destroy(child);
}
}

View File

@@ -86,17 +86,17 @@ public static class UIConfigWindow
x = 400f;
y = 10f;
wnd.AddButton(x, y, tab2, "Initialize This Planet", 16, "button-init-planet", () =>
UIMessageBox.Show("Initialize This Planet".Translate(), "Initialize This Planet Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, new UIMessageBox.Response(() =>
UIMessageBox.Show("Initialize This Planet".Translate(), "Initialize This Planet Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, () =>
{
PlanetFunctions.RecreatePlanet(true);
}))
})
);
y += 36f;
wnd.AddButton(x, y, tab2, "Dismantle All Buildings", 16, "button-dismantle-all", () =>
UIMessageBox.Show("Dismantle All Buildings".Translate(), "Dismantle All Buildings Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, new UIMessageBox.Response(() =>
UIMessageBox.Show("Dismantle All Buildings".Translate(), "Dismantle All Buildings Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, () =>
{
PlanetFunctions.DismantleAll(false);
}))
})
);
y += 72f;
@@ -128,10 +128,10 @@ public static class UIConfigWindow
x = 400f;
y = 10f;
wnd.AddButton(x, y, tab3, "Initialize Dyson Sphere", 16, "init-dyson-sphere", () =>
UIMessageBox.Show("Initialize Dyson Sphere".Translate(), "Initialize Dyson Sphere Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, new UIMessageBox.Response(() =>
UIMessageBox.Show("Initialize Dyson Sphere".Translate(), "Initialize Dyson Sphere Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, () =>
{
DysonSpherePatch.InitCurrentDysonSphere(-1);
}))
})
);
y += 36f;
MyWindow.AddText(x, y, tab3, "Click to dismantle selected layer", 16, "text-dismantle-layer");
@@ -140,10 +140,10 @@ public static class UIConfigWindow
{
var id = i + 1;
var btn = wnd.AddFlatButton(x, y, tab3, id.ToString(), 12, "dismantle-layer-" + id, () =>
UIMessageBox.Show("Dismantle selected layer".Translate(), "Dismantle selected layer Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, new UIMessageBox.Response(() =>
UIMessageBox.Show("Dismantle selected layer".Translate(), "Dismantle selected layer Confirm".Translate(), "取消".Translate(), "确定".Translate(), 2, null, () =>
{
DysonSpherePatch.InitCurrentDysonSphere(id);
}))
})
);
((RectTransform)btn.transform).sizeDelta = new Vector2(40f, 20f);
DysonLayerBtn[i] = btn;