Skip to content

Commit a1b111e

Browse files
committed
feat: Deployment of version v1.2.0.
1 parent 7b90e70 commit a1b111e

9 files changed

Lines changed: 309 additions & 40 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ obj/
33
*.user
44
*.suo
55
.vs/
6+
.vscode/

ImprovedLandmarks/ImprovedLandmarks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@
7777
<Compile Include="CustomLandmark.cs" />
7878
<Compile Include="LandmarkManager.cs" />
7979
<Compile Include="LandmarkGUI.cs" />
80+
<Compile Include="ObjectLabelManager.cs" />
8081
<Compile Include="Patches\DrawLandmarksPatch.cs" />
82+
<Compile Include="Patches\GameSelectorPatch.cs" />
8183
<Compile Include="Patches\MapClickPatch.cs" />
8284
<Compile Include="Patches\WorldRenamePatch.cs" />
85+
<Compile Include="Patches\RocketLabelCleanupPatch.cs" />
8386
</ItemGroup>
8487
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8588
</Project>

ImprovedLandmarks/LandmarkManager.cs

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,29 @@
55

66
namespace ImprovedLandmarks
77
{
8+
public class WorldData
9+
{
10+
public List<CustomLandmark> landmarks = new List<CustomLandmark>();
11+
public List<int> labeledObjects = new List<int>();
12+
}
13+
814
public static class LandmarkManager
915
{
10-
static Dictionary<string, List<CustomLandmark>> _allLandmarks = new Dictionary<string, List<CustomLandmark>>();
16+
public static List<int> GetLabeledObjects(string world)
17+
{
18+
if (string.IsNullOrEmpty(world)) world = "default";
19+
if (!_worlds.ContainsKey(world)) return new List<int>();
20+
return new List<int>(_worlds[world].labeledObjects);
21+
}
22+
23+
public static void SetLabeledObjects(string world, IEnumerable<int> objects)
24+
{
25+
if (string.IsNullOrEmpty(world)) world = "default";
26+
if (!_worlds.ContainsKey(world)) _worlds[world] = new WorldData();
27+
_worlds[world].labeledObjects = new List<int>(objects);
28+
SaveAll();
29+
}
30+
static Dictionary<string, WorldData> _worlds = new Dictionary<string, WorldData>();
1131
static string _currentWorld = "";
1232

1333
public static List<CustomLandmark> Landmarks
@@ -16,16 +36,17 @@ public static List<CustomLandmark> Landmarks
1636
{
1737
if (string.IsNullOrEmpty(_currentWorld))
1838
return new List<CustomLandmark>();
19-
if (!_allLandmarks.ContainsKey(_currentWorld))
20-
_allLandmarks[_currentWorld] = new List<CustomLandmark>();
21-
return _allLandmarks[_currentWorld];
39+
if (!_worlds.ContainsKey(_currentWorld))
40+
_worlds[_currentWorld] = new WorldData();
41+
return _worlds[_currentWorld].landmarks;
2242
}
2343
}
2444

2545
public static string CurrentWorld => _currentWorld;
2646

2747
static string _savePath;
2848
static string _configPath;
49+
static string _objectLabelsPath;
2950

3051
public static void Load(string modFolder)
3152
{
@@ -36,51 +57,73 @@ public static void Load(string modFolder)
3657
return;
3758

3859
string json = File.ReadAllText(_savePath);
39-
60+
bool upgraded = false;
4061
try
4162
{
42-
var loaded = JsonConvert.DeserializeObject<Dictionary<string, List<CustomLandmark>>>(json);
63+
var loaded = JsonConvert.DeserializeObject<Dictionary<string, WorldData>>(json);
4364
if (loaded != null)
4465
{
45-
_allLandmarks = loaded;
46-
return;
66+
_worlds = loaded;
67+
upgraded = true;
4768
}
4869
}
4970
catch { }
5071

51-
try
72+
if (!upgraded)
5273
{
53-
var legacy = JsonConvert.DeserializeObject<List<CustomLandmark>>(json);
54-
if (legacy != null && legacy.Count > 0)
74+
try
5575
{
56-
_allLandmarks["default"] = legacy;
57-
SaveAll();
76+
var loaded = JsonConvert.DeserializeObject<Dictionary<string, List<CustomLandmark>>>(json);
77+
if (loaded != null)
78+
{
79+
foreach (var kv in loaded)
80+
{
81+
if (!_worlds.ContainsKey(kv.Key))
82+
_worlds[kv.Key] = new WorldData();
83+
_worlds[kv.Key].landmarks = kv.Value;
84+
}
85+
upgraded = true;
86+
SaveAll();
87+
}
5888
}
89+
catch { }
90+
}
91+
92+
if (!upgraded)
93+
{
94+
try
95+
{
96+
var legacy = JsonConvert.DeserializeObject<List<CustomLandmark>>(json);
97+
if (legacy != null && legacy.Count > 0)
98+
{
99+
_worlds["default"] = new WorldData { landmarks = legacy };
100+
SaveAll();
101+
}
102+
}
103+
catch { }
59104
}
60-
catch { }
61105
}
62106

63107
public static void SetCurrentWorld(string worldName)
64108
{
65109
_currentWorld = string.IsNullOrEmpty(worldName) ? "default" : worldName;
66-
if (!_allLandmarks.ContainsKey(_currentWorld))
67-
_allLandmarks[_currentWorld] = new List<CustomLandmark>();
110+
if (!_worlds.ContainsKey(_currentWorld))
111+
_worlds[_currentWorld] = new WorldData();
68112
}
69113

70114
static void SaveAll()
71115
{
72116
if (_savePath == null)
73117
return;
74118

75-
// Remove empty or keyless entries before saving
76119
var toRemove = new List<string>();
77-
foreach (var kv in _allLandmarks)
78-
if (string.IsNullOrEmpty(kv.Key) || kv.Value.Count == 0)
120+
foreach (var kv in _worlds)
121+
if (string.IsNullOrEmpty(kv.Key) || (kv.Value.landmarks.Count == 0 && kv.Value.labeledObjects.Count == 0))
79122
toRemove.Add(kv.Key);
80123
foreach (var key in toRemove)
81-
_allLandmarks.Remove(key);
124+
_worlds.Remove(key);
82125

83-
string json = JsonConvert.SerializeObject(_allLandmarks, Formatting.Indented);
126+
string json = JsonConvert.SerializeObject(_worlds, Formatting.Indented);
84127
File.WriteAllText(_savePath, json);
85128
}
86129

@@ -90,18 +133,19 @@ public static void RemoveWorld(string worldName)
90133
{
91134
if (string.IsNullOrEmpty(worldName))
92135
return;
93-
_allLandmarks.Remove(worldName);
136+
_worlds.Remove(worldName);
94137
SaveAll();
95138
}
96139

97140
public static void RenameWorld(string oldName, string newName)
98141
{
99142
if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName))
100143
return;
101-
if (!_allLandmarks.ContainsKey(oldName))
102-
return;
103-
_allLandmarks[newName] = _allLandmarks[oldName];
104-
_allLandmarks.Remove(oldName);
144+
if (_worlds.ContainsKey(oldName))
145+
{
146+
_worlds[newName] = _worlds[oldName];
147+
_worlds.Remove(oldName);
148+
}
105149
if (_currentWorld == oldName)
106150
_currentWorld = newName;
107151
SaveAll();
@@ -144,6 +188,24 @@ public static Vector2 LoadGuiPosition(Vector2 defaultPos)
144188

145189
public static bool ConfigExists => _configPath != null && File.Exists(_configPath);
146190

191+
public static bool IsObjectLabeled(int branch)
192+
{
193+
if (string.IsNullOrEmpty(_currentWorld)) return false;
194+
if (!_worlds.TryGetValue(_currentWorld, out var data)) return false;
195+
return data.labeledObjects.Contains(branch);
196+
}
197+
198+
public static void ToggleObjectLabel(int branch)
199+
{
200+
if (string.IsNullOrEmpty(_currentWorld)) return;
201+
if (!_worlds.ContainsKey(_currentWorld))
202+
_worlds[_currentWorld] = new WorldData();
203+
var list = _worlds[_currentWorld].labeledObjects;
204+
if (!list.Remove(branch))
205+
list.Add(branch);
206+
SaveAll();
207+
}
208+
147209
public static void SaveGuiPosition(Vector2 pos)
148210
{
149211
if (_configPath == null) return;

ImprovedLandmarks/Main.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class Main : Mod, IUpdatable
1717
public override string DisplayName => "Improved Landmarks";
1818
public override string Author => "Jorgeluisreis";
1919
public override string MinimumGameVersionNecessary => "1.5.9.8";
20-
public override string ModVersion => "1.1.0";
21-
public override string Description => "Allows creating custom landmarks anywhere on the map.";
20+
public override string ModVersion => "1.2.0";
21+
public override string Description => "Allows creating custom landmarks anywhere on the map and toggling object name labels individually.";
2222
public override string IconLink => "https://raw.githubusercontent.com/Jorgeluisreis/ImprovedLandmarks/refs/heads/main/Images/Icon.png";
2323

2424
public override Dictionary<string, string> Dependencies => new Dictionary<string, string>
@@ -38,10 +38,12 @@ public class Main : Mod, IUpdatable
3838

3939
public override void Early_Load()
4040
{
41-
patcher = new Harmony("improved.landmarks.mod");
41+
patcher = new Harmony("improved.landmarks.mod");
4242

43-
try { patcher.PatchAll(); }
44-
catch (System.Exception ex) { Debug.LogError($"[ImprovedLandmarks] PatchAll failed: {ex}"); }
43+
_ = typeof(ImprovedLandmarks.Patches.RocketLabelCleanupPatch);
44+
45+
try { patcher.PatchAll(); }
46+
catch (System.Exception ex) { Debug.LogError($"[ImprovedLandmarks] PatchAll failed: {ex}"); }
4547

4648
try
4749
{
@@ -82,7 +84,9 @@ public override void Load()
8284

8385
SceneHelper.OnWorldSceneLoaded += () =>
8486
{
85-
LandmarkManager.SetCurrentWorld(GetCurrentWorldName());
87+
string worldName = GetCurrentWorldName();
88+
LandmarkManager.SetCurrentWorld(worldName);
89+
ObjectLabelManager.Init(ModFolder, worldName);
8690
LandmarkGUI.Build();
8791
};
8892
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Newtonsoft.Json;
4+
5+
namespace ImprovedLandmarks
6+
{
7+
public static class ObjectLabelManager
8+
{
9+
private static HashSet<int> labels = new HashSet<int>();
10+
private static string _currentWorld = "default";
11+
12+
public static void Init(string modFolder, string worldName)
13+
{
14+
_currentWorld = string.IsNullOrEmpty(worldName) ? "default" : worldName;
15+
ReloadFromLandmarkManager();
16+
}
17+
18+
public static void ReloadFromLandmarkManager()
19+
{
20+
labels.Clear();
21+
var list = LandmarkManager.GetLabeledObjects(_currentWorld);
22+
if (list != null)
23+
foreach (var id in list)
24+
labels.Add(id);
25+
}
26+
27+
public static bool IsLabeled(int objectId)
28+
{
29+
return labels.Contains(objectId);
30+
}
31+
32+
public static void SetLabel(int objectId, bool show)
33+
{
34+
if (show)
35+
labels.Add(objectId);
36+
else
37+
labels.Remove(objectId);
38+
LandmarkManager.SetLabeledObjects(_currentWorld, labels);
39+
}
40+
41+
public static void ToggleLabel(int objectId)
42+
{
43+
SetLabel(objectId, !IsLabeled(objectId));
44+
}
45+
46+
public static void ClearLabels()
47+
{
48+
labels.Clear();
49+
LandmarkManager.SetLabeledObjects(_currentWorld, labels);
50+
}
51+
public static void RemoveLabelForObject(int objectId)
52+
{
53+
if (labels.Remove(objectId))
54+
LandmarkManager.SetLabeledObjects(_currentWorld, labels);
55+
}
56+
}
57+
}

ImprovedLandmarks/Patches/DrawLandmarksPatch.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ public static void Postfix()
4343
Vector2 previewNormal = new Vector2(Mathf.Sin(previewRad), Mathf.Cos(previewRad));
4444
MapDrawer.DrawPointWithText(preview.PinSize, previewColor, Field.Text(LandmarkGUI.CurrentInputText), preview.LabelSize, previewColor, previewPos, previewNormal, 4, preview.LabelSpacing);
4545
}
46+
foreach (MapRocket mapObject in Object.FindObjectsByType<MapRocket>(FindObjectsSortMode.None))
47+
{
48+
if (mapObject == null || mapObject.rocket == null) continue;
49+
int branch = mapObject.rocket.stats.branch;
50+
if (branch < 0 || !ObjectLabelManager.IsLabeled(branch)) continue;
51+
52+
string displayName = string.IsNullOrEmpty(mapObject.rocket.rocketName) ? "Object" : mapObject.rocket.rocketName;
53+
double zoom = Map.view.view.distance;
54+
float spacing = 0.2f * (float)(1000.0 / zoom);
55+
Vector2 labelPos = (Vector2)mapObject.Select_MenuPosition + new Vector2(0, spacing);
56+
Planet planet = mapObject.rocket.location.planet.Value;
57+
double fadeRadius = planet.data.basics.radius * (2.0 + 5.0);
58+
float alpha = Mathf.Min(MapDrawer.GetFadeIn(Map.view.view.distance, fadeRadius * 0.5 * 1.5, fadeRadius * 0.4 * 1.5));
59+
Color vanillaColor = new Color(1f, 1f, 1f, alpha);
60+
MapDrawer.DrawPointWithText(2, vanillaColor, Field.Text(displayName), 40, vanillaColor, labelPos, Vector2.up, 4, 999);
61+
}
4662
}
4763
}
4864
}

0 commit comments

Comments
 (0)