1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 21:33:28 +08:00

work in progress

This commit is contained in:
2025-04-24 17:25:47 +08:00
parent 40aa331294
commit 68a18c113d
20 changed files with 339 additions and 228 deletions

View File

@@ -7,7 +7,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Threading;
public static class UIFunctions public static class UIFunctions
{ {
@@ -19,6 +19,7 @@ public static class UIFunctions
private static int _cornerComboBoxIndex; private static int _cornerComboBoxIndex;
private static string[] _starOrderNames; private static string[] _starOrderNames;
private static bool _starmapFilterInitialized; private static bool _starmapFilterInitialized;
private static ulong[] _starmapStarFilterValues;
private static bool _starFilterEnabled; private static bool _starFilterEnabled;
private static UI.MyCheckButton _starmapFilterToggler; private static UI.MyCheckButton _starmapFilterToggler;
public static bool[] ShowStarName; public static bool[] ShowStarName;
@@ -34,82 +35,16 @@ public static class UIFunctions
}); });
I18N.Add("KEYOpenUXAssistConfigWindow", "[UXA] Open UXAssist Config Window", "[UXA] 打开UX助手设置面板"); I18N.Add("KEYOpenUXAssistConfigWindow", "[UXA] Open UXAssist Config Window", "[UXA] 打开UX助手设置面板");
I18N.OnInitialized += RecreateConfigWindow; I18N.OnInitialized += RecreateConfigWindow;
GameLogic.OnGameBegin += () =>
{
var galaxy = GameMain.data.galaxy;
ShowStarName = new bool[galaxy.starCount];
_starOrderNames = new string[galaxy.starCount];
StarData[] stars = [.. galaxy.stars.Where(star => star != null)];
Array.Sort(stars, (a, b) =>
{
int res = a.position.sqrMagnitude.CompareTo(b.position.sqrMagnitude);
if (res != 0) return res;
return a.index.CompareTo(b.index);
});
for (int i = 0; i < stars.Length; i++)
{
var star = stars[i];
_starOrderNames[star.index] = star.displayName;
}
int[] spectrCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (int i = 0; i < stars.Length; i++)
{
var star = stars[i];
var index = star.index;
switch (star.type)
{
case EStarType.MainSeqStar:
switch (star.spectr)
{
case ESpectrType.M:
_starOrderNames[index] = String.Format("M{0}", ++spectrCount[0]);
break;
case ESpectrType.K:
_starOrderNames[index] = String.Format("K{0}", ++spectrCount[1]);
break;
case ESpectrType.G:
_starOrderNames[index] = String.Format("G{0}", ++spectrCount[2]);
break;
case ESpectrType.F:
_starOrderNames[index] = String.Format("F{0}", ++spectrCount[3]);
break;
case ESpectrType.A:
_starOrderNames[index] = String.Format("A{0}", ++spectrCount[4]);
break;
case ESpectrType.B:
_starOrderNames[index] = String.Format("B{0}", ++spectrCount[5]);
break;
case ESpectrType.O:
_starOrderNames[index] = String.Format("O{0}", ++spectrCount[6]);
break;
}
break;
case EStarType.GiantStar:
_starOrderNames[index] = String.Format("GS{0}", ++spectrCount[7]);
break;
case EStarType.WhiteDwarf:
_starOrderNames[index] = String.Format("WD{0}", ++spectrCount[8]);
break;
case EStarType.NeutronStar:
_starOrderNames[index] = String.Format("NS{0}", ++spectrCount[9]);
break;
case EStarType.BlackHole:
_starOrderNames[index] = String.Format("BH{0}", ++spectrCount[10]);
break;
}
}
};
GameLogic.OnGameEnd += () =>
{
_starOrderNames = null;
ShowStarName = null;
};
} }
public static void OnUpdate() public static void OnUpdate()
{ {
if (!_starmapFilterInitialized || _starmapFilterToggler == null || _starmapFilterToggler.gameObject.activeSelf) return; if (!_starmapFilterInitialized || _starmapFilterToggler == null || _starmapFilterToggler.gameObject.activeSelf) return;
if (PlanetModelingManager.scnPlanetReqList.Count == 0) _starmapFilterToggler.gameObject.SetActive(true); if (PlanetModelingManager.scnPlanetReqList.Count == 0)
{
StarmapUpdateFilterValues();
_starmapFilterToggler.gameObject.SetActive(true);
}
} }
public static void OnInputUpdate() public static void OnInputUpdate()
@@ -139,6 +74,23 @@ public static class UIFunctions
} }
} }
private static readonly Sprite[] PlanetIcons = [
Common.Util.LoadEmbeddedSprite("assets/planet_icon/07.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/09.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/10.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/13.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/14.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/15.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/16.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/17.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/18.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/19.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/21.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/22.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/23.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/24.png"),
Common.Util.LoadEmbeddedSprite("assets/planet_icon/25.png")
];
public static void InitMenuButtons() public static void InitMenuButtons()
{ {
if (_initialized) return; if (_initialized) return;
@@ -205,20 +157,28 @@ public static class UIFunctions
{ {
Functions.UIFunctions.CornerComboBoxIndex = index; Functions.UIFunctions.CornerComboBoxIndex = index;
}; };
_starmapFilterToggler = UI.MyCheckButton.CreateCheckButton(20, 0, rtrans, false, ">>").WithSize(20, 20); _starmapFilterToggler = UI.MyCheckButton.CreateCheckButton(10, 0, rtrans, false, ">>").WithSize(24, 24);
MyCheckButton[] buttons = [ MyCheckButton[] buttons = [
UI.MyCheckButton.CreateCheckButton(40, 0, rtrans, false).WithIcon().WithSize(20, 20), // Kimberlite UI.MyCheckButton.CreateCheckButton(34, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Kimberlite
UI.MyCheckButton.CreateCheckButton(60, 0, rtrans, false).WithIcon().WithSize(20, 20), // Fractal Silicon UI.MyCheckButton.CreateCheckButton(58, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Fractal Silicon
UI.MyCheckButton.CreateCheckButton(80, 0, rtrans, false).WithIcon().WithSize(20, 20), // Organic Crystal UI.MyCheckButton.CreateCheckButton(82, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Organic Crystal
UI.MyCheckButton.CreateCheckButton(100, 0, rtrans, false).WithIcon().WithSize(20, 20), // Grating Crystal UI.MyCheckButton.CreateCheckButton(106, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Grating Crystal
UI.MyCheckButton.CreateCheckButton(120, 0, rtrans, false).WithIcon().WithSize(20, 20), // Stalagmite Crystal UI.MyCheckButton.CreateCheckButton(130, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Stalagmite Crystal
UI.MyCheckButton.CreateCheckButton(140, 0, rtrans, false).WithIcon().WithSize(20, 20), // Unipolar Magnet UI.MyCheckButton.CreateCheckButton(154, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Unipolar Magnet
UI.MyCheckButton.CreateCheckButton(160, 0, rtrans, false).WithIcon().WithSize(20, 20), // Crude Oil UI.MyCheckButton.CreateCheckButton(178, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Crude Oil
UI.MyCheckButton.CreateCheckButton(180, 0, rtrans, false).WithIcon().WithSize(20, 20), // Fire Ice UI.MyCheckButton.CreateCheckButton(202, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Fire Ice
UI.MyCheckButton.CreateCheckButton(200, 0, rtrans, false).WithIcon().WithSize(20, 20), // Sulfuric Acid UI.MyCheckButton.CreateCheckButton(226, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Sulfuric Acid
UI.MyCheckButton.CreateCheckButton(220, 0, rtrans, false).WithIcon().WithSize(20, 20), // Water UI.MyCheckButton.CreateCheckButton(250, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Water
UI.MyCheckButton.CreateCheckButton(240, 0, rtrans, false).WithIcon().WithSize(20, 20), // Hydrogen UI.MyCheckButton.CreateCheckButton(274, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Hydrogen
UI.MyCheckButton.CreateCheckButton(260, 0, rtrans, false).WithIcon().WithSize(20, 20), // Deuterium UI.MyCheckButton.CreateCheckButton(298, 0, rtrans, false).WithIcon().WithSize(24, 24).WithIconWidth(24), // Deuterium
UI.MyCheckButton.CreateCheckButton(34, 24, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 48, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 72, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 96, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 120, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 144, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
UI.MyCheckButton.CreateCheckButton(34, 168, rtrans, false).WithIcon().WithSize(120, 24).WithIconWidth(24),
]; ];
_starmapFilterToggler.OnChecked += UpdateButtons; _starmapFilterToggler.OnChecked += UpdateButtons;
foreach (var button in buttons) foreach (var button in buttons)
@@ -246,15 +206,118 @@ public static class UIFunctions
buttons[10].WithTip(itemProto.Name).SetIcon(itemProto.iconSprite); buttons[10].WithTip(itemProto.Name).SetIcon(itemProto.iconSprite);
itemProto = LDB.items.Select(1121); itemProto = LDB.items.Select(1121);
buttons[11].WithTip(itemProto.Name).SetIcon(itemProto.iconSprite); buttons[11].WithTip(itemProto.Name).SetIcon(itemProto.iconSprite);
// [ 0] = 07.png
// [ 1] = 09.png
// [ 2] = 10.png
// [ 3] = 13.png
// [ 4] = 14.png
// [ 5] = 15.png
// [ 6] = 16.png
// [ 7] = 17.png
// [ 8] = 18.png
// [ 9] = 19.png
// [10] = 21.png
// [11] = 22.png
// [12] = 23.png
// [13] = 24.png
// [14] = 25.png
var themeProto = LDB.themes.Select(16);
buttons[12].SetLabelText(themeProto.DisplayName);
buttons[12].SetIcon(PlanetIcons[6]);
themeProto = LDB.themes.Select(23);
buttons[13].SetLabelText(themeProto.DisplayName);
buttons[13].SetIcon(PlanetIcons[12]);
themeProto = LDB.themes.Select(10);
buttons[14].SetLabelText(themeProto.DisplayName);
buttons[14].SetIcon(PlanetIcons[2]);
themeProto = LDB.themes.Select(15);
buttons[15].SetLabelText(themeProto.DisplayName);
buttons[15].SetIcon(PlanetIcons[5]);
themeProto = LDB.themes.Select(18);
buttons[16].SetLabelText(themeProto.DisplayName);
buttons[16].SetIcon(PlanetIcons[8]);
themeProto = LDB.themes.Select(22);
buttons[17].SetLabelText(themeProto.DisplayName);
buttons[17].SetIcon(PlanetIcons[11]);
themeProto = LDB.themes.Select(25);
buttons[18].SetLabelText(themeProto.DisplayName);
buttons[18].SetIcon(PlanetIcons[14]);
}; };
GameLogic.OnGameBegin += () => GameLogic.OnGameBegin += () =>
{ {
if (DSPGame.IsMenuDemo) return; if (DSPGame.IsMenuDemo) return;
var galaxy = GameMain.data.galaxy;
ShowStarName = new bool[galaxy.starCount];
_starOrderNames = new string[galaxy.starCount];
_starmapStarFilterValues = new ulong[galaxy.starCount];
StarData[] stars = [.. galaxy.stars.Where(star => star != null)];
Array.Sort(stars, (a, b) =>
{
int res = a.position.sqrMagnitude.CompareTo(b.position.sqrMagnitude);
if (res != 0) return res;
return a.index.CompareTo(b.index);
});
for (int i = 0; i < stars.Length; i++)
{
var star = stars[i];
_starOrderNames[star.index] = star.displayName;
}
int[] spectrCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (int i = 0; i < stars.Length; i++)
{
var star = stars[i];
var index = star.index;
switch (star.type)
{
case EStarType.MainSeqStar:
switch (star.spectr)
{
case ESpectrType.M:
_starOrderNames[index] = String.Format("M{0}", ++spectrCount[0]);
break;
case ESpectrType.K:
_starOrderNames[index] = String.Format("K{0}", ++spectrCount[1]);
break;
case ESpectrType.G:
_starOrderNames[index] = String.Format("G{0}", ++spectrCount[2]);
break;
case ESpectrType.F:
_starOrderNames[index] = String.Format("F{0}", ++spectrCount[3]);
break;
case ESpectrType.A:
_starOrderNames[index] = String.Format("A{0}", ++spectrCount[4]);
break;
case ESpectrType.B:
_starOrderNames[index] = String.Format("B{0}", ++spectrCount[5]);
break;
case ESpectrType.O:
_starOrderNames[index] = String.Format("O{0}", ++spectrCount[6]);
break;
}
break;
case EStarType.GiantStar:
_starOrderNames[index] = String.Format("GS{0}", ++spectrCount[7]);
break;
case EStarType.WhiteDwarf:
_starOrderNames[index] = String.Format("WD{0}", ++spectrCount[8]);
break;
case EStarType.NeutronStar:
_starOrderNames[index] = String.Format("NS{0}", ++spectrCount[9]);
break;
case EStarType.BlackHole:
_starOrderNames[index] = String.Format("BH{0}", ++spectrCount[10]);
break;
}
}
_starmapFilterToggler.gameObject.SetActive(false); _starmapFilterToggler.gameObject.SetActive(false);
_starmapFilterToggler.Checked = false; _starmapFilterToggler.Checked = false;
UpdateButtons(); UpdateButtons();
SetStarFilterEnabled(false); SetStarFilterEnabled(false);
foreach (var star in GameMain.data.galaxy.stars) foreach (var star in galaxy.stars)
{ {
if (star != null) PlanetModelingManager.RequestScanStar(star); if (star != null) PlanetModelingManager.RequestScanStar(star);
} }
@@ -262,6 +325,9 @@ public static class UIFunctions
}; };
GameLogic.OnGameEnd += () => GameLogic.OnGameEnd += () =>
{ {
_starOrderNames = null;
ShowStarName = null;
_starmapStarFilterValues = null;
_starmapFilterInitialized = false; _starmapFilterInitialized = false;
}; };
void UpdateButtons() void UpdateButtons()
@@ -285,50 +351,70 @@ public static class UIFunctions
} }
void UpdateStarmapStarFilters() void UpdateStarmapStarFilters()
{ {
List<(int, int)> filters = []; var filterValue = 0UL;
bool showAny = false;
if (_starmapFilterToggler.Checked) if (_starmapFilterToggler.Checked)
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if (buttons[i].Checked) if (buttons[i].Checked)
{ {
filters.Add((i + 9, 0)); filterValue |= 1UL << (i + 9);
showAny = true;
} }
} }
if (buttons[6].Checked) if (buttons[6].Checked)
{ {
filters.Add((7, 0)); filterValue |= 1UL << 7;
showAny = true;
} }
if (buttons[7].Checked) if (buttons[7].Checked)
{ {
filters.Add((8, 1011)); filterValue |= 1UL << 8;
showAny = true;
} }
if (buttons[8].Checked) if (buttons[8].Checked)
{ {
filters.Add((0, 1116)); filterValue |= 1UL << 22;
showAny = true;
} }
if (buttons[9].Checked) if (buttons[9].Checked)
{ {
filters.Add((0, 1000)); filterValue |= 1UL << 23;
showAny = true;
} }
if (buttons[10].Checked) if (buttons[10].Checked)
{ {
filters.Add((0, 1120)); filterValue |= 1UL << 20;
showAny = true;
} }
if (buttons[11].Checked) if (buttons[11].Checked)
{ {
filters.Add((0, 1121)); filterValue |= 1UL << 21;
showAny = true; }
if (buttons[12].Checked)
{
filterValue |= 1UL << (30 + 16);
}
if (buttons[13].Checked)
{
filterValue |= 1UL << (30 + 23);
}
if (buttons[14].Checked)
{
filterValue |= 1UL << (30 + 10);
}
if (buttons[15].Checked)
{
filterValue |= 1UL << (30 + 15);
}
if (buttons[16].Checked)
{
filterValue |= 1UL << (30 + 18);
}
if (buttons[17].Checked)
{
filterValue |= 1UL << (30 + 22);
}
if (buttons[18].Checked)
{
filterValue |= 1UL << (30 + 25);
} }
} }
if (!showAny) if (filterValue == 0UL)
{ {
for (int i = 0; i < ShowStarName.Length; i++) for (int i = 0; i < ShowStarName.Length; i++)
{ {
@@ -337,69 +423,9 @@ public static class UIFunctions
SetStarFilterEnabled(false); SetStarFilterEnabled(false);
return; return;
} }
var galaxy = GameMain.data.galaxy; for (int i = _starmapStarFilterValues.Length - 1; i >= 0; i--)
var stars = galaxy.stars;
for (int i = 0; i < galaxy.starCount; i++)
{ {
var star = stars[i]; ShowStarName[i] = (_starmapStarFilterValues[i] & filterValue) == filterValue;
if (star == null) continue;
ShowStarName[i] = false;
var allMatch = true;
foreach (var filter in filters)
{
var match = false;
foreach (var planet in star.planets)
{
if (planet == null) continue;
if (planet.type == EPlanetType.Gas)
{
if (filter.Item2 != 0)
{
foreach (var n in planet.gasItems)
{
if (n == filter.Item2)
{
match = true;
break;
}
}
if (match) break;
}
}
else
{
if (filter.Item2 != 0)
{
if (planet.waterItemId == filter.Item2)
{
match = true;
break;
}
}
if (filter.Item1 != 0)
{
foreach (var group in planet.veinGroups)
{
if (group.amount > 0 && (int)group.type == filter.Item1)
{
match = true;
break;
}
}
if (match) break;
}
}
}
if (!match)
{
allMatch = false;
break;
}
}
if (allMatch)
{
ShowStarName[i] = true;
}
} }
SetStarFilterEnabled(true); SetStarFilterEnabled(true);
} }
@@ -407,6 +433,93 @@ public static class UIFunctions
_initialized = true; _initialized = true;
} }
private static void StarmapUpdateFilterValues()
{
var galaxy = GameMain.data.galaxy;
var stars = galaxy.stars;
for (int i = 0; i < galaxy.starCount; i++)
{
var star = stars[i];
if (star == null) continue;
var value = 0UL;
foreach (var planet in star.planets)
{
if (planet == null) continue;
while (planet.scanning)
{
Thread.Sleep(50);
}
var planetValue = 0UL;
if (planet.type == EPlanetType.Gas)
{
foreach (var n in planet.gasItems)
{
switch (n)
{
case 1011:
planetValue |= 1UL << 8;
break;
case 1120:
planetValue |= 1UL << 20;
break;
case 1121:
planetValue |= 1UL << 21;
break;
}
}
}
else
{
foreach (var group in planet.veinGroups)
{
if (group.amount > 0)
{
planetValue |= 1UL << (int)group.type;
}
}
switch (planet.waterItemId)
{
case 1116:
planetValue |= 1UL << 22;
break;
case 1000:
planetValue |= 1UL << 23;
break;
}
}
if ((value & (1UL << (30 + planet.theme))) == 0)
{
switch (planet.theme)
{
case 7: case 9: case 13: case 17: case 19: case 24:
{
const ulong needed = 0x7EUL;
if ((planetValue & needed) == needed)
{
value |= 1UL << (30 + planet.theme);
}
break;
}
case 14:
{
const ulong needed = 0x2200UL;
if ((planetValue & needed) == needed)
{
value |= 1UL << (30 + planet.theme);
}
break;
}
case 10: case 15: case 16: case 18: case 21: case 22: case 23: case 25:
value |= 1UL << (30 + planet.theme);
break;
}
}
value |= planetValue;
}
_starmapStarFilterValues[i] = value;
}
}
public static void RecreateConfigWindow() public static void RecreateConfigWindow()
{ {
if (!_configWinInitialized) return; if (!_configWinInitialized) return;

View File

@@ -18,7 +18,6 @@ public static class WindowFunctions
private static IntPtr _oldWndProc = IntPtr.Zero; private static IntPtr _oldWndProc = IntPtr.Zero;
private static IntPtr _gameWindowHandle = IntPtr.Zero; private static IntPtr _gameWindowHandle = IntPtr.Zero;
private static bool _gameLoaded;
public static WinApi.LogicalProcessorDetails ProcessorDetails { get; private set; } public static WinApi.LogicalProcessorDetails ProcessorDetails { get; private set; }
public static ConfigEntry<int> ProcessPriority; public static ConfigEntry<int> ProcessPriority;
@@ -48,7 +47,6 @@ public static class WindowFunctions
public static void Start() public static void Start()
{ {
GameLogic.OnDataLoaded += OnDataLoaded;
var wndProc = new WinApi.WndProc(GameWndProc); var wndProc = new WinApi.WndProc(GameWndProc);
var gameWnd = FindGameWindow(); var gameWnd = FindGameWindow();
if (gameWnd != IntPtr.Zero) if (gameWnd != IntPtr.Zero)
@@ -65,7 +63,7 @@ public static class WindowFunctions
UpdateAffinity(); UpdateAffinity();
return; return;
void UpdateAffinity() static void UpdateAffinity()
{ {
var process = WinApi.GetCurrentProcess(); var process = WinApi.GetCurrentProcess();
if (!WinApi.GetProcessAffinityMask(process, out _, out var systemMask)) if (!WinApi.GetProcessAffinityMask(process, out _, out var systemMask))
@@ -94,16 +92,6 @@ public static class WindowFunctions
} }
} }
public static void Uninit()
{
GameLogic.OnDataLoaded -= OnDataLoaded;
}
private static void OnDataLoaded()
{
_gameLoaded = true;
}
private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam) private static IntPtr GameWndProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
{ {
switch (uMsg) switch (uMsg)
@@ -122,13 +110,13 @@ public static class WindowFunctions
switch ((long)wParam & 0xFFF0L) switch ((long)wParam & 0xFFF0L)
{ {
case WinApi.SC_MOVE: case WinApi.SC_MOVE:
if (GamePatch.LoadLastWindowRectEnabled.Value && !_gameLoaded) return (IntPtr)1L; if (GamePatch.LoadLastWindowRectEnabled.Value && !GameMain.isRunning) return (IntPtr)1L;
break; break;
} }
break; break;
case WinApi.WM_MOVING: case WinApi.WM_MOVING:
if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break; if (!GamePatch.LoadLastWindowRectEnabled.Value || GameMain.isRunning) break;
var rect = GamePatch.LastWindowRect.Value; var rect = GamePatch.LastWindowRect.Value;
if (rect is { z: 0f, w: 0f }) break; if (rect is { z: 0f, w: 0f }) break;
var x = Mathf.RoundToInt(rect.x); var x = Mathf.RoundToInt(rect.x);
@@ -137,9 +125,9 @@ public static class WindowFunctions
rect2.Left = x; rect2.Left = x;
rect2.Top = y; rect2.Top = y;
Marshal.StructureToPtr(rect2, lParam, false); Marshal.StructureToPtr(rect2, lParam, false);
break; return (IntPtr)1L;
case WinApi.WM_SIZING: case WinApi.WM_SIZING:
if (!GamePatch.LoadLastWindowRectEnabled.Value || _gameLoaded) break; if (!GamePatch.LoadLastWindowRectEnabled.Value || Screen.fullScreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow || GameMain.isRunning) break;
rect = GamePatch.LastWindowRect.Value; rect = GamePatch.LastWindowRect.Value;
if (rect is { z: 0f, w: 0f }) break; if (rect is { z: 0f, w: 0f }) break;
x = Mathf.RoundToInt(rect.x); x = Mathf.RoundToInt(rect.x);
@@ -152,7 +140,7 @@ public static class WindowFunctions
rect2.Right = x + w; rect2.Right = x + w;
rect2.Bottom = y + h; rect2.Bottom = y + h;
Marshal.StructureToPtr(rect2, lParam, false); Marshal.StructureToPtr(rect2, lParam, false);
break; return (IntPtr)1L;
} }
return WinApi.CallWindowProc(_oldWndProc, hWnd, uMsg, wParam, lParam); return WinApi.CallWindowProc(_oldWndProc, hWnd, uMsg, wParam, lParam);
@@ -219,24 +207,32 @@ public static class WindowFunctions
{ {
// Get profile name from command line arguments, and set window title accordingly // Get profile name from command line arguments, and set window title accordingly
var args = Environment.GetCommandLineArgs(); var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length - 1; i++) for (var i = args.Length - 2; i >= 0; i--)
{ {
// Doorstop 3.x and 4.x use different arguments to pass the target assembly path if (args[i] == "--gale-profile")
if (args[i] != "--doorstop-target" && args[i] != "--doorstop-target-assembly") continue; {
var arg = args[i + 1]; // We use gale profile name directly
const string doorstopPathSuffix = @"\BepInEx\core\BepInEx.Preloader.dll"; ProfileName = args[i + 1];
if (!arg.EndsWith(doorstopPathSuffix, StringComparison.OrdinalIgnoreCase)) }
break; else
arg = arg.Substring(0, arg.Length - doorstopPathSuffix.Length); {
const string profileSuffix = @"\profiles\"; // Doorstop 3.x and 4.x use different arguments to pass the target assembly path
var index = arg.LastIndexOf(profileSuffix, StringComparison.OrdinalIgnoreCase); if (args[i] != "--doorstop-target" && args[i] != "--doorstop-target-assembly") continue;
if (index < 0) var arg = args[i + 1];
break; const string doorstopPathSuffix = @"\BepInEx\core\BepInEx.Preloader.dll";
arg = arg.Substring(index + profileSuffix.Length); if (!arg.EndsWith(doorstopPathSuffix, StringComparison.OrdinalIgnoreCase))
break;
arg = arg.Substring(0, arg.Length - doorstopPathSuffix.Length);
const string profileSuffix = @"\profiles\";
var index = arg.LastIndexOf(profileSuffix, StringComparison.OrdinalIgnoreCase);
if (index < 0)
break;
arg = arg.Substring(index + profileSuffix.Length);
ProfileName = arg;
}
var wnd = FindGameWindow(); var wnd = FindGameWindow();
if (wnd == IntPtr.Zero) return; if (wnd == IntPtr.Zero) return;
ProfileName = arg; _gameWindowTitle = $"Dyson Sphere Program - {ProfileName}";
_gameWindowTitle = $"Dyson Sphere Program - {arg}";
WinApi.SetWindowText(wnd, _gameWindowTitle); WinApi.SetWindowText(wnd, _gameWindowTitle);
break; break;
} }

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Threading;
using System.Xml; using System.Xml;
using BepInEx.Configuration; using BepInEx.Configuration;
using CommonAPI.Systems; using CommonAPI.Systems;
@@ -270,8 +271,6 @@ public class GamePatch : PatchImpl<GamePatch>
LastWindowRect.Value = new Vector4(x, y, w, h); LastWindowRect.Value = new Vector4(x, y, w, h);
} }
} }
MoveWindowPosition();
} }
protected override void OnDisable() protected override void OnDisable()
@@ -311,13 +310,6 @@ public class GamePatch : PatchImpl<GamePatch>
height = h; height = h;
} }
[HarmonyPostfix]
[HarmonyPatch(typeof(Screen), nameof(Screen.SetResolution), typeof(int), typeof(int), typeof(FullScreenMode), typeof(int))]
private static void Screen_SetResolution_Postfix(FullScreenMode fullscreenMode)
{
MoveWindowPosition();
}
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix() private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
{ {
if (_loaded || Screen.fullScreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return; if (_loaded || Screen.fullScreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return;

View File

@@ -46,7 +46,11 @@ public class MyCheckButton : MonoBehaviour
if (txt) if (txt)
{ {
txt.text = ""; txt.text = "";
txt.rectTransform.pivot = new Vector2(0.5f, 0.5f); txt.alignment = TextAnchor.MiddleCenter;
txt.rectTransform.anchorMax = new Vector2(0f, 1f);
txt.rectTransform.anchorMin = new Vector2(0f, 1f);
txt.rectTransform.pivot = new Vector2(0f, 1f);
txt.rectTransform.localPosition = new Vector3(0f, 0f, 0f);
} }
var localizer = comp.GetComponent<Localizer>(); var localizer = comp.GetComponent<Localizer>();
if (localizer) DestroyImmediate(localizer); if (localizer) DestroyImmediate(localizer);
@@ -88,21 +92,16 @@ public class MyCheckButton : MonoBehaviour
{ {
cb.labelText.text = ""; cb.labelText.text = "";
cb.labelText.fontSize = fontSize; cb.labelText.fontSize = fontSize;
cb.UpdateLabelTextWidth();
} }
} }
cb._iconWidth = Mathf.Min(cb._iconWidth > 0f ? cb._iconWidth : 28f, rect.sizeDelta.y); cb._iconWidth = Mathf.Min(cb._iconWidth > 0f ? cb._iconWidth : 32f, rect.sizeDelta.y);
cb.UpdateCheckColor(); cb.UpdateCheckColor();
cb.uiButton.onClick += cb.OnClick; cb.uiButton.onClick += cb.OnClick;
cb.UpdateSize();
return cb; return cb;
} }
private void UpdateLabelTextWidth()
{
if (labelText) labelText.rectTransform.sizeDelta = new Vector2(labelText.preferredWidth, labelText.rectTransform.sizeDelta.y);
}
public bool Checked public bool Checked
{ {
get => _checked; get => _checked;
@@ -118,7 +117,6 @@ public class MyCheckButton : MonoBehaviour
if (labelText != null) if (labelText != null)
{ {
labelText.text = val.Translate(); labelText.text = val.Translate();
UpdateLabelTextWidth();
} }
} }
@@ -147,17 +145,19 @@ public class MyCheckButton : MonoBehaviour
{ {
var width = rectTrans.sizeDelta.x; var width = rectTrans.sizeDelta.x;
var height = rectTrans.sizeDelta.y; var height = rectTrans.sizeDelta.y;
labelText.rectTransform.localPosition = new Vector3(icon != null ? _iconWidth : 0f, 0f, 0f);
labelText.rectTransform.sizeDelta = new Vector2(icon != null ? width - _iconWidth : width, height); labelText.rectTransform.sizeDelta = new Vector2(icon != null ? width - _iconWidth : width, height);
if (icon != null) if (icon != null)
{ {
icon.transform.localPosition = new Vector3((-width - _iconWidth) * 0.5f, 0f, 0f); icon.rectTransform.sizeDelta = new Vector2(_iconWidth, _iconWidth);
icon.rectTransform.localPosition = new Vector3(0f, -height * 0.5f, 0f);
} }
} }
public MyCheckButton WithSize(float width, float height) public MyCheckButton WithSize(float width, float height)
{ {
rectTrans.sizeDelta = new Vector2(width, height); rectTrans.sizeDelta = new Vector2(width, height);
if (height > _iconWidth) _iconWidth = height; if (height < _iconWidth) _iconWidth = height;
UpdateSize(); UpdateSize();
return this; return this;
} }
@@ -178,25 +178,21 @@ public class MyCheckButton : MonoBehaviour
public MyCheckButton WithIcon(Sprite sprite = null) public MyCheckButton WithIcon(Sprite sprite = null)
{ {
var trans = labelText.gameObject.transform;
if (icon == null) if (icon == null)
{ {
var iconGo = new GameObject("icon"); var iconGo = new GameObject("icon");
var rect = iconGo.AddComponent<RectTransform>(); var rect = iconGo.AddComponent<RectTransform>();
(icon = iconGo.AddComponent<Image>()).sprite = sprite; (icon = iconGo.AddComponent<Image>()).sprite = sprite;
iconGo.transform.SetParent(trans); iconGo.transform.SetParent(rectTrans);
rect.localPosition = new Vector3(0f, 0f, 0f);
rect.sizeDelta = new Vector2(_iconWidth, _iconWidth); rect.sizeDelta = new Vector2(_iconWidth, _iconWidth);
rect.localScale = new Vector3(1f, 1f, 1f); rect.localScale = new Vector3(1f, 1f, 1f);
rect.anchorMax = new Vector2(0f, 1f); rect.anchorMax = new Vector2(0f, 1f);
rect.anchorMin = new Vector2(0f, 1f); rect.anchorMin = new Vector2(0f, 1f);
rect.pivot = new Vector2(0f, 0.5f); rect.pivot = new Vector2(0f, 0.5f);
var height = rectTrans.sizeDelta.y;
rect.localPosition = new Vector3(0f, -height * 0.5f, 0f);
iconGo.SetActive(sprite != null); iconGo.SetActive(sprite != null);
UpdateSize();
var width = rectTrans.sizeDelta.x;
var originPosition = labelText.rectTransform.localPosition;
labelText.rectTransform.localPosition = new Vector3(originPosition.x + _iconWidth * 0.5f, originPosition.y, originPosition.z);
labelText.rectTransform.sizeDelta = new Vector2(width - _iconWidth, labelText.rectTransform.sizeDelta.y);
} }
else else
{ {
@@ -220,7 +216,6 @@ public class MyCheckButton : MonoBehaviour
public void SetIcon(Sprite sprite = null) public void SetIcon(Sprite sprite = null)
{ {
icon.sprite = sprite; icon.sprite = sprite;
icon.transform.localPosition = new Vector3((-rectTrans.sizeDelta.x - _iconWidth) * 0.5f, 0f, 0f);
icon.gameObject.SetActive(sprite != null); icon.gameObject.SetActive(sprite != null);
} }
@@ -258,7 +253,7 @@ public class MyCheckButton : MonoBehaviour
{ {
uiButton.transitions[0].mouseoverColor = closeMouseOverColor; uiButton.transitions[0].mouseoverColor = closeMouseOverColor;
uiButton.transitions[0].pressedColor = closePressColor; uiButton.transitions[0].pressedColor = closePressColor;
uiButton.transitions[0].normalColor = closeNormalColor; uiButton.transitions[0].normalColor = new Color(0.6557f, 0.9145f, 1f, 0.0627f);
} }
} }
} }

View File

@@ -42,6 +42,21 @@
<EmbeddedResource Include="assets/icon/in.png" /> <EmbeddedResource Include="assets/icon/in.png" />
<EmbeddedResource Include="assets/icon/out.png" /> <EmbeddedResource Include="assets/icon/out.png" />
<EmbeddedResource Include="assets/icon/keep.png" /> <EmbeddedResource Include="assets/icon/keep.png" />
<EmbeddedResource Include="assets/planet_icon/07.png" />
<EmbeddedResource Include="assets/planet_icon/09.png" />
<EmbeddedResource Include="assets/planet_icon/10.png" />
<EmbeddedResource Include="assets/planet_icon/13.png" />
<EmbeddedResource Include="assets/planet_icon/14.png" />
<EmbeddedResource Include="assets/planet_icon/15.png" />
<EmbeddedResource Include="assets/planet_icon/16.png" />
<EmbeddedResource Include="assets/planet_icon/17.png" />
<EmbeddedResource Include="assets/planet_icon/18.png" />
<EmbeddedResource Include="assets/planet_icon/19.png" />
<EmbeddedResource Include="assets/planet_icon/21.png" />
<EmbeddedResource Include="assets/planet_icon/22.png" />
<EmbeddedResource Include="assets/planet_icon/23.png" />
<EmbeddedResource Include="assets/planet_icon/24.png" />
<EmbeddedResource Include="assets/planet_icon/25.png" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'"> <ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB