mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2025-12-19 13:03:32 +08:00
WIP
This commit is contained in:
@@ -70,8 +70,8 @@ internal class CruiseAssistConfigManager(ConfigFile config) : ConfigManager(conf
|
|||||||
saveFlag |= UpdateEntry("State", "DebugWindowTop", (int)CruiseAssistDebugUI.Rect.y);
|
saveFlag |= UpdateEntry("State", "DebugWindowTop", (int)CruiseAssistDebugUI.Rect.y);
|
||||||
if (CruiseAssistPlugin.Seed != -1)
|
if (CruiseAssistPlugin.Seed != -1)
|
||||||
{
|
{
|
||||||
saveFlag |= UpdateEntry("Save", $"History_{CruiseAssistPlugin.Seed}", ListUtils.ToString(CruiseAssistPlugin.History));
|
saveFlag |= UpdateEntry("Save", $"History_{CruiseAssistPlugin.Seed}", CruiseAssistStarListUI.HistoryToString());
|
||||||
saveFlag |= UpdateEntry("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", ListUtils.ToString(CruiseAssistPlugin.Bookmark));
|
saveFlag |= UpdateEntry("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", CruiseAssistStarListUI.BookmarkToString());
|
||||||
}
|
}
|
||||||
CruiseAssistMainUI.NextCheckGameTick = long.MaxValue;
|
CruiseAssistMainUI.NextCheckGameTick = long.MaxValue;
|
||||||
return saveFlag;
|
return saveFlag;
|
||||||
@@ -84,20 +84,16 @@ internal class CruiseAssistConfigManager(ConfigFile config) : ConfigManager(conf
|
|||||||
var reset = CruiseAssistPlugin.Seed != -1;
|
var reset = CruiseAssistPlugin.Seed != -1;
|
||||||
if (!reset) return;
|
if (!reset) return;
|
||||||
CruiseAssistPlugin.Seed = -1;
|
CruiseAssistPlugin.Seed = -1;
|
||||||
CruiseAssistPlugin.History = [];
|
CruiseAssistStarListUI.ClearHistory();
|
||||||
CruiseAssistPlugin.HistoryDistinct = [];
|
CruiseAssistStarListUI.ClearBookmark();
|
||||||
CruiseAssistPlugin.Bookmark = [];
|
|
||||||
CruiseAssistPlugin.BookmarkSet = [];
|
|
||||||
LogManager.LogInfo("clear seed.");
|
LogManager.LogInfo("clear seed.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (CruiseAssistPlugin.Seed == GameMain.galaxy.seed) return;
|
if (CruiseAssistPlugin.Seed == GameMain.galaxy.seed) return;
|
||||||
CruiseAssistPlugin.Seed = GameMain.galaxy.seed;
|
CruiseAssistPlugin.Seed = GameMain.galaxy.seed;
|
||||||
CruiseAssistPlugin.History = ListUtils.ParseToIntList(Bind("Save", $"History_{CruiseAssistPlugin.Seed}", "").Value);
|
CruiseAssistStarListUI.HistoryFromString(Bind("Save", $"History_{CruiseAssistPlugin.Seed}", "").Value);
|
||||||
CruiseAssistPlugin.HistoryDistinct = Enumerable.Reverse(CruiseAssistPlugin.History).Distinct().ToList();
|
CruiseAssistStarListUI.BookmarkFromString(Bind("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", "").Value);
|
||||||
CruiseAssistPlugin.Bookmark = ListUtils.ParseToIntList(Bind("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", "").Value);
|
|
||||||
CruiseAssistPlugin.BookmarkSet = [..CruiseAssistPlugin.Bookmark];
|
|
||||||
LogManager.LogInfo($"change seed {CruiseAssistPlugin.Seed}.");
|
LogManager.LogInfo($"change seed {CruiseAssistPlugin.Seed}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,60 +139,12 @@ public class CruiseAssistPlugin : BaseUnityPlugin
|
|||||||
public static CruiseAssistState State = CruiseAssistState.Inactive;
|
public static CruiseAssistState State = CruiseAssistState.Inactive;
|
||||||
public static bool Interrupt = false;
|
public static bool Interrupt = false;
|
||||||
public static int Seed = -1;
|
public static int Seed = -1;
|
||||||
public static List<int> History = [];
|
|
||||||
public static List<int> HistoryDistinct = [];
|
|
||||||
public static List<int> Bookmark = [];
|
|
||||||
public static HashSet<int> BookmarkSet = [];
|
|
||||||
public static readonly Func<StarData, string> GetStarName = star => star.displayName;
|
public static readonly Func<StarData, string> GetStarName = star => star.displayName;
|
||||||
public static readonly Func<PlanetData, string> GetPlanetName = planet => planet.displayName;
|
public static readonly Func<PlanetData, string> GetPlanetName = planet => planet.displayName;
|
||||||
internal static readonly List<ICruiseAssistExtensionAPI> Extensions = [];
|
internal static readonly List<ICruiseAssistExtensionAPI> Extensions = [];
|
||||||
private Harmony _harmony;
|
private Harmony _harmony;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
|
||||||
public static void AddHistory(int id)
|
|
||||||
{
|
|
||||||
if (History.Count >= 128)
|
|
||||||
{
|
|
||||||
History.RemoveAt(0);
|
|
||||||
}
|
|
||||||
History.Add(id);
|
|
||||||
HistoryDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveHistoryAt(int index)
|
|
||||||
{
|
|
||||||
History.RemoveAt(index);
|
|
||||||
HistoryDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ClearHistory()
|
|
||||||
{
|
|
||||||
History.Clear();
|
|
||||||
HistoryDistinct.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HasBookmark(int id) => BookmarkSet.Contains(id);
|
|
||||||
|
|
||||||
public static bool AddBookmark(int id)
|
|
||||||
{
|
|
||||||
if (!BookmarkSet.Add(id)) return false;
|
|
||||||
Bookmark.Add(id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool RemoveBookmark(int id)
|
|
||||||
{
|
|
||||||
if (!BookmarkSet.Remove(id)) return false;
|
|
||||||
Bookmark.Remove(id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ClearBookmark()
|
|
||||||
{
|
|
||||||
Bookmark.Clear();
|
|
||||||
BookmarkSet.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Conf
|
public static class Conf
|
||||||
{
|
{
|
||||||
public static bool MarkVisitedFlag = true;
|
public static bool MarkVisitedFlag = true;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CruiseAssist.Commons;
|
using CruiseAssist.Commons;
|
||||||
using CruiseAssist.Enums;
|
using CruiseAssist.Enums;
|
||||||
|
using CruiseAssist.UI;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
namespace CruiseAssist.Patches;
|
||||||
@@ -21,9 +22,9 @@ internal class Patch_PlayerMoveWalk
|
|||||||
CruiseAssistPlugin.TargetSelected = false;
|
CruiseAssistPlugin.TargetSelected = false;
|
||||||
if (GameMain.localPlanet != null)
|
if (GameMain.localPlanet != null)
|
||||||
{
|
{
|
||||||
if (CruiseAssistPlugin.History.Count == 0 || CruiseAssistPlugin.History.Last() != GameMain.localPlanet.id)
|
if (CruiseAssistStarListUI.LastHistoryId() != GameMain.localPlanet.id)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.AddHistory(GameMain.localPlanet.id);
|
CruiseAssistStarListUI.AddHistory(GameMain.localPlanet);
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,8 +77,6 @@ public static class CruiseAssistDebugUI
|
|||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input1.z={GameMain.mainPlayer.controller.input1.z}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"GameMain.mainPlayer.controller.input1.z={GameMain.mainPlayer.controller.input1.z}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
GUILayout.Label($"VFInput._sailSpeedUp={VFInput._sailSpeedUp}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"VFInput._sailSpeedUp={VFInput._sailSpeedUp}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
GUILayout.Label($"CruiseAssistPlugin.Enable={CruiseAssistPlugin.Enable}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"CruiseAssistPlugin.Enable={CruiseAssistPlugin.Enable}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
GUILayout.Label($"CruiseAssistPlugin.History={CruiseAssistPlugin.History.Count()}", _debugStyle, Array.Empty<GUILayoutOption>());
|
|
||||||
GUILayout.Label("CruiseAssistPlugin.History=" + ListUtils.ToString(CruiseAssistPlugin.History), _debugStyle, Array.Empty<GUILayoutOption>());
|
|
||||||
GUILayout.Label($"GUI.skin.window.margin.top={GUI.skin.window.margin.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"GUI.skin.window.margin.top={GUI.skin.window.margin.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
GUILayout.Label($"GUI.skin.window.border.top={GUI.skin.window.border.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"GUI.skin.window.border.top={GUI.skin.window.border.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
GUILayout.Label($"GUI.skin.window.padding.top={GUI.skin.window.padding.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
GUILayout.Label($"GUI.skin.window.padding.top={GUI.skin.window.padding.top}", _debugStyle, Array.Empty<GUILayoutOption>());
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -203,15 +202,15 @@ public static class CruiseAssistStarListUI
|
|||||||
{
|
{
|
||||||
if (planetData != null)
|
if (planetData != null)
|
||||||
{
|
{
|
||||||
if (CruiseAssistPlugin.RemoveBookmark(planetData.id))
|
if (RemoveBookmark(planetData))
|
||||||
{
|
{
|
||||||
celestialBody.InBookmark = false;
|
celestialBody.InBookmark = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (CruiseAssistPlugin.Bookmark.Count <= 128)
|
if (Bookmark.Count <= 128)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.AddBookmark(planetData.id);
|
AddBookmark(planetData);
|
||||||
celestialBody.InBookmark = true;
|
celestialBody.InBookmark = true;
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||||
}
|
}
|
||||||
@@ -225,22 +224,20 @@ public static class CruiseAssistStarListUI
|
|||||||
case 1 or 2:
|
case 1 or 2:
|
||||||
{
|
{
|
||||||
var highlighted = false;
|
var highlighted = false;
|
||||||
var enumBookmark = ListSelected != 1 ? CruiseAssistPlugin.Bookmark : Enumerable.Reverse(CruiseAssistPlugin.History);
|
var enumBookmark = ListSelected != 1 ? Bookmark : Enumerable.Reverse(History);
|
||||||
if (ListSelected == 1 && ActionSelected[ListSelected] != 2 && CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag)
|
if (ListSelected == 1 && ActionSelected[ListSelected] != 2 && CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag)
|
||||||
{
|
{
|
||||||
enumBookmark = CruiseAssistPlugin.HistoryDistinct;
|
enumBookmark = HistoryDistinct;
|
||||||
}
|
}
|
||||||
|
|
||||||
var listIndex = -1;
|
var listIndex = -1;
|
||||||
enumBookmark.Do(delegate(int id)
|
enumBookmark.Do(body =>
|
||||||
{
|
{
|
||||||
|
var planetData = body.PlanetData;
|
||||||
|
var id = planetData.id;
|
||||||
listIndex += 1;
|
listIndex += 1;
|
||||||
var planetData = GameMain.galaxy.PlanetById(id);
|
var selected = !highlighted && selectTargetPlanet != null && planetData.id == selectTargetPlanet.id;
|
||||||
if (planetData == null) return;
|
if (selected)
|
||||||
var magnitude = (planetData.uPosition - GameMain.mainPlayer.uPosition).magnitude;
|
|
||||||
_nameLabelStyle.normal.textColor = Color.white;
|
|
||||||
_nRangeLabelStyle.normal.textColor = Color.white;
|
|
||||||
if (!highlighted && selectTargetPlanet != null && planetData.id == selectTargetPlanet.id)
|
|
||||||
{
|
{
|
||||||
_nameLabelStyle.normal.textColor = Color.cyan;
|
_nameLabelStyle.normal.textColor = Color.cyan;
|
||||||
_nRangeLabelStyle.normal.textColor = Color.cyan;
|
_nRangeLabelStyle.normal.textColor = Color.cyan;
|
||||||
@@ -254,32 +251,32 @@ public static class CruiseAssistStarListUI
|
|||||||
name = (planetData.factory != null ? VisitedMark : NonVisitMark) + name;
|
name = (planetData.factory != null ? VisitedMark : NonVisitMark) + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.Label(name, _nameLabelStyle);
|
GUILayout.Label(name, selected ? _nameLabelHighlightStyle : _nameLabelStyle);
|
||||||
var height = _nameLabelStyle.CalcHeight(new GUIContent(name), _nameLabelStyle.fixedWidth);
|
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
GUILayout.Label(CruiseAssistMainUI.RangeToString(magnitude), height < 30f ? _nRangeLabelStyle : _hRangeLabelStyle);
|
GUILayout.Label(CruiseAssistMainUI.RangeToString(body.Range), selected ? _nRangeLabelHighlightStyle : _nRangeLabelStyle);
|
||||||
if (ListSelected == 2 && ActionSelected[ListSelected] == 1)
|
if (ListSelected == 2 && ActionSelected[ListSelected] == 1)
|
||||||
{
|
{
|
||||||
var index = CruiseAssistPlugin.Bookmark.IndexOf(id);
|
var first = Bookmark[0] == body;
|
||||||
var first = index == 0;
|
var last = Bookmark.Last() == body;
|
||||||
var last = index == CruiseAssistPlugin.Bookmark.Count - 1;
|
if (GUILayout.Button(last ? "-" : "↓", _nSortButtonStyle))
|
||||||
if (GUILayout.Button(last ? "-" : "↓", height < 30f ? _nSortButtonStyle : _hSortButtonStyle))
|
|
||||||
{
|
{
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||||
if (!last)
|
if (!last)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.Bookmark.RemoveAt(index);
|
var index = Bookmark.IndexOf(body);
|
||||||
CruiseAssistPlugin.Bookmark.Insert(index + 1, id);
|
Bookmark.RemoveAt(index);
|
||||||
|
Bookmark.Insert(index + 1, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GUILayout.Button(first ? "-" : "↑", height < 30f ? _nSortButtonStyle : _hSortButtonStyle))
|
if (GUILayout.Button(first ? "-" : "↑", _nSortButtonStyle))
|
||||||
{
|
{
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.Bookmark.RemoveAt(index);
|
var index = Bookmark.IndexOf(body);
|
||||||
CruiseAssistPlugin.Bookmark.Insert(index - 1, id);
|
Bookmark.RemoveAt(index);
|
||||||
|
Bookmark.Insert(index - 1, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +285,7 @@ public static class CruiseAssistStarListUI
|
|||||||
if (GUILayout.Button(
|
if (GUILayout.Button(
|
||||||
ActionSelected[ListSelected] == 0 ? "SET" :
|
ActionSelected[ListSelected] == 0 ? "SET" :
|
||||||
ActionSelected[ListSelected] == 2 ? ListSelected == 1 && listIndex == 0 ? "-" : "DEL" :
|
ActionSelected[ListSelected] == 2 ? ListSelected == 1 && listIndex == 0 ? "-" : "DEL" :
|
||||||
CruiseAssistPlugin.Bookmark.Contains(id) ? "DEL" : "ADD", height < 30f ? _nActionButtonStyle : _hActionButtonStyle))
|
HasBookmark(id) ? "DEL" : "ADD", _nActionButtonStyle))
|
||||||
{
|
{
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||||
switch (ActionSelected[ListSelected])
|
switch (ActionSelected[ListSelected])
|
||||||
@@ -307,13 +304,13 @@ public static class CruiseAssistStarListUI
|
|||||||
{
|
{
|
||||||
if (ListSelected == 1)
|
if (ListSelected == 1)
|
||||||
{
|
{
|
||||||
if (CruiseAssistPlugin.Bookmark.Contains(id))
|
if (HasBookmark(id))
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.Bookmark.Remove(id);
|
RemoveBookmark(planetData);
|
||||||
}
|
}
|
||||||
else if (CruiseAssistPlugin.Bookmark.Count <= 128)
|
else if (Bookmark.Count <= 128)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.Bookmark.Add(id);
|
AddBookmark(planetData);
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,14 +327,17 @@ public static class CruiseAssistStarListUI
|
|||||||
{
|
{
|
||||||
if (listIndex != 0)
|
if (listIndex != 0)
|
||||||
{
|
{
|
||||||
CruiseAssistPlugin.RemoveHistoryAt(CruiseAssistPlugin.History.Count - 1 - listIndex);
|
if (CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag)
|
||||||
|
RemoveHistoryDistinctAt(listIndex);
|
||||||
|
else
|
||||||
|
RemoveHistoryAt(History.Count - 1 - listIndex);
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
CruiseAssistPlugin.Bookmark.Remove(planetData.id);
|
RemoveBookmark(planetData);
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -567,7 +567,7 @@ public static class CruiseAssistStarListUI
|
|||||||
Pos = planet.uPosition,
|
Pos = planet.uPosition,
|
||||||
IsPlanet = true,
|
IsPlanet = true,
|
||||||
Visited = visted,
|
Visited = visted,
|
||||||
InBookmark = CruiseAssistPlugin.HasBookmark(planet.id)
|
InBookmark = HasBookmark(planet.id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,7 +612,7 @@ public static class CruiseAssistStarListUI
|
|||||||
Pos = planet.uPosition,
|
Pos = planet.uPosition,
|
||||||
IsPlanet = true,
|
IsPlanet = true,
|
||||||
Visited = visted,
|
Visited = visted,
|
||||||
InBookmark = CruiseAssistPlugin.HasBookmark(planet.id)
|
InBookmark = HasBookmark(planet.id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -644,6 +644,107 @@ public static class CruiseAssistStarListUI
|
|||||||
_celestialBodies.Sort((s1, s2) => s1.Range.CompareTo(s2.Range));
|
_celestialBodies.Sort((s1, s2) => s1.Range.CompareTo(s2.Range));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AddHistory(PlanetData planet)
|
||||||
|
{
|
||||||
|
if (History.Count >= 128)
|
||||||
|
{
|
||||||
|
History.RemoveAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
History.Add(new BookmarkCelestialBody
|
||||||
|
{
|
||||||
|
PlanetData = planet,
|
||||||
|
Name = CruiseAssistPlugin.GetStarName(planet.star) + " - " + CruiseAssistPlugin.GetPlanetName(planet),
|
||||||
|
Range = (planet.uPosition - GameMain.mainPlayer.uPosition).magnitude - planet.realRadius
|
||||||
|
});
|
||||||
|
HistoryDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RemoveHistoryAt(int index)
|
||||||
|
{
|
||||||
|
History.RemoveAt(index);
|
||||||
|
HistoryDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RemoveHistoryDistinctAt(int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= HistoryDistinct.Count) return;
|
||||||
|
var body = HistoryDistinct[index];
|
||||||
|
History.Remove(body);
|
||||||
|
HistoryDistinct.RemoveAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearHistory()
|
||||||
|
{
|
||||||
|
History.Clear();
|
||||||
|
HistoryDistinct.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int LastHistoryId() => History.Count > 0 ? History.Last().PlanetData.id : 0;
|
||||||
|
|
||||||
|
public static string HistoryToString() => History.Join(body => body.PlanetData.id.ToString(), ",");
|
||||||
|
|
||||||
|
public static void HistoryFromString(string str)
|
||||||
|
{
|
||||||
|
Bookmark.Clear();
|
||||||
|
foreach (var s in str.Split(','))
|
||||||
|
{
|
||||||
|
if (!int.TryParse(s, out var id)) continue;
|
||||||
|
var planet = GameMain.galaxy.PlanetById(id);
|
||||||
|
if (planet == null) continue;
|
||||||
|
AddBookmark(planet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasBookmark(int id) => BookmarkSet.Contains(id);
|
||||||
|
|
||||||
|
private static bool AddBookmark(PlanetData planet)
|
||||||
|
{
|
||||||
|
if (!BookmarkSet.Add(planet.id)) return false;
|
||||||
|
Bookmark.Add(new BookmarkCelestialBody
|
||||||
|
{
|
||||||
|
PlanetData = planet,
|
||||||
|
Name = CruiseAssistPlugin.GetStarName(planet.star) + " - " + CruiseAssistPlugin.GetPlanetName(planet),
|
||||||
|
Range = (planet.uPosition - GameMain.mainPlayer.uPosition).magnitude - planet.realRadius
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool RemoveBookmark(PlanetData planet)
|
||||||
|
{
|
||||||
|
var id = planet.id;
|
||||||
|
if (!BookmarkSet.Remove(id)) return false;
|
||||||
|
Bookmark.RemoveAll(body => body.PlanetData.id == id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveBookmarkAt(int index)
|
||||||
|
{
|
||||||
|
var body = Bookmark[index];
|
||||||
|
BookmarkSet.Remove(body.PlanetData.id);
|
||||||
|
Bookmark.RemoveAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearBookmark()
|
||||||
|
{
|
||||||
|
Bookmark.Clear();
|
||||||
|
BookmarkSet.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string BookmarkToString() => Bookmark.Join(body => body.PlanetData.id.ToString(), ",");
|
||||||
|
|
||||||
|
public static void BookmarkFromString(string str)
|
||||||
|
{
|
||||||
|
Bookmark.Clear();
|
||||||
|
foreach (var s in str.Split(','))
|
||||||
|
{
|
||||||
|
if (!int.TryParse(s, out var id)) continue;
|
||||||
|
var planet = GameMain.galaxy.PlanetById(id);
|
||||||
|
if (planet == null) continue;
|
||||||
|
AddBookmark(planet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class CelestialBody
|
private class CelestialBody
|
||||||
{
|
{
|
||||||
public StarData StarData;
|
public StarData StarData;
|
||||||
@@ -657,11 +758,23 @@ public static class CruiseAssistStarListUI
|
|||||||
public bool InBookmark;
|
public bool InBookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class BookmarkCelestialBody
|
||||||
|
{
|
||||||
|
public PlanetData PlanetData;
|
||||||
|
public string Name;
|
||||||
|
public double Range;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<CelestialBody> _celestialBodies;
|
private static List<CelestialBody> _celestialBodies;
|
||||||
private static List<CelestialBody> _stars;
|
private static List<CelestialBody> _stars;
|
||||||
private static List<CelestialBody> _localStarPlanets;
|
private static List<CelestialBody> _localStarPlanets;
|
||||||
private static List<CelestialBody> _selectedStarPlanets;
|
private static List<CelestialBody> _selectedStarPlanets;
|
||||||
|
|
||||||
|
private static readonly List<BookmarkCelestialBody> History = [];
|
||||||
|
private static List<BookmarkCelestialBody> HistoryDistinct = [];
|
||||||
|
private static readonly List<BookmarkCelestialBody> Bookmark = [];
|
||||||
|
private static readonly HashSet<int> BookmarkSet = [];
|
||||||
|
|
||||||
private static long _nextCheckTick;
|
private static long _nextCheckTick;
|
||||||
private static StarData _lastLocalStar;
|
private static StarData _lastLocalStar;
|
||||||
private static PlanetData _lastLocalPlanet;
|
private static PlanetData _lastLocalPlanet;
|
||||||
|
|||||||
Reference in New Issue
Block a user