Skip to content

Commit 353c7d0

Browse files
committed
Add load/regroup key
Fix opacity setting
1 parent 1cd63d1 commit 353c7d0

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

ActivityGhosts/ActivityGhosts.cs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ActivityGhosts : Script
2121
private Blip start;
2222
private int lastTime;
2323
private Keys menuKey;
24+
private Keys loadKey;
2425
public static PointF initialGPSPoint;
2526
public static int opacity;
2627
private bool showDate;
@@ -93,30 +94,35 @@ private void LoadGhosts()
9394
{
9495
FitActivityDecoder fit = new FitActivityDecoder(file.FullName);
9596
List<GeoPoint> points = fit.pointList;
96-
if (points.Count > 1)
97+
if (points.Count > 1 && Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f)
9798
{
98-
if (Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f)
99-
{
100-
int offset = ghosts.Count / 2 + 1;
101-
if (ghosts.Count % 2 == 0)
102-
offset *= -1;
103-
points[0].Lat += offset;
104-
float h = Game.Player.Character.Heading;
105-
if ((h > 90f && h < 180f) || (h > 270f && h < 360f))
106-
points[0].Long -= offset;
107-
else
108-
points[0].Long += offset;
109-
string span;
110-
var seconds = (System.DateTime.UtcNow - fit.startTime).TotalSeconds;
111-
if (seconds < 7200) span = $"{seconds / 60:N0} minutes";
112-
else if (seconds < 172800) span = $"{seconds / 3600:N0} hours";
113-
else if (seconds < 1209600) span = $"{seconds / 86400:N0} days";
114-
else if (seconds < 5259492) span = $"{seconds / 604800:N0} weeks";
115-
else span = $"{seconds / 2629746:N0} months";
116-
ghosts.Add(new Ghost(points, fit.sport, span));
117-
}
99+
int offset = ghosts.Count / 2 + 1;
100+
if (ghosts.Count % 2 == 0)
101+
offset *= -1;
102+
points[0].Lat += offset;
103+
float h = Game.Player.Character.Heading;
104+
if ((h > 90f && h < 180f) || (h > 270f && h < 360f))
105+
points[0].Long -= offset;
106+
else
107+
points[0].Long += offset;
108+
string span;
109+
var seconds = (System.DateTime.UtcNow - fit.startTime).TotalSeconds;
110+
if (seconds < 7200) span = $"{seconds / 60:N0} minutes";
111+
else if (seconds < 172800) span = $"{seconds / 3600:N0} hours";
112+
else if (seconds < 1209600) span = $"{seconds / 86400:N0} days";
113+
else if (seconds < 5259492) span = $"{seconds / 604800:N0} weeks";
114+
else span = $"{seconds / 2629746:N0} months";
115+
ghosts.Add(new Ghost(points, fit.sport, span));
118116
}
119117
}
118+
if (ghosts.Count > 0)
119+
{
120+
start = World.CreateBlip(Game.Player.Character.Position);
121+
start.Sprite = BlipSprite.RaceBike;
122+
loadMenuItem.Enabled = false;
123+
regroupMenuItem.Enabled = true;
124+
deleteMenuItem.Enabled = true;
125+
}
120126
}
121127
Notification.Show($"{ghosts.Count} ghosts loaded");
122128
}
@@ -126,13 +132,14 @@ private void LoadSettings()
126132
CultureInfo.CurrentCulture = new CultureInfo("", false);
127133
ScriptSettings settings = ScriptSettings.Load(@".\Scripts\ActivityGhosts.ini");
128134
menuKey = (Keys)Enum.Parse(typeof(Keys), settings.GetValue("Main", "MenuKey", "F8"), true);
135+
loadKey = (Keys)Enum.Parse(typeof(Keys), settings.GetValue("Main", "LoadKey", "G"), true);
129136
float initialGPSPointLat = settings.GetValue("Main", "InitialGPSPointLat", -19.10637f);
130137
float initialGPSPointLong = settings.GetValue("Main", "InitialGPSPointLong", -169.871f);
131138
initialGPSPoint = new PointF(initialGPSPointLat, initialGPSPointLong);
132-
opacity = settings.GetValue("Main", "Opacity", 50);
133-
if (opacity < 0) opacity = 0;
134-
if (opacity > 100) opacity = 100;
135-
opacity *= 255 / 100;
139+
opacity = settings.GetValue("Main", "Opacity", 5);
140+
if (opacity < 1) opacity = 1;
141+
if (opacity > 5) opacity = 5;
142+
opacity *= 51;
136143
showDate = settings.GetValue("Main", "ShowDate", true);
137144
}
138145

@@ -149,14 +156,6 @@ private void CreateMenu()
149156
loadMenuItem.Activated += (sender, itemArgs) =>
150157
{
151158
LoadGhosts();
152-
if (ghosts.Count > 0)
153-
{
154-
start = World.CreateBlip(Game.Player.Character.Position);
155-
start.Sprite = BlipSprite.RaceBike;
156-
loadMenuItem.Enabled = false;
157-
regroupMenuItem.Enabled = true;
158-
deleteMenuItem.Enabled = true;
159-
}
160159
mainMenu.Visible = false;
161160
};
162161
regroupMenuItem = new NativeItem("Regroup", "Regroup ghosts")
@@ -188,6 +187,13 @@ private void CreateMenu()
188187
{
189188
if (e.KeyCode == menuKey)
190189
mainMenu.Visible = !mainMenu.Visible;
190+
else if (e.KeyCode == loadKey)
191+
{
192+
if (ghosts.Count == 0)
193+
LoadGhosts();
194+
else
195+
RegroupGhosts();
196+
}
191197
};
192198
}
193199
}

ActivityGhosts/ActivityGhosts.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[Main]
22
MenuKey=F8
3+
LoadKey=G
34
InitialGPSPointLat=-19.10637
45
InitialGPSPointLong=-169.871
5-
Opacity=50
6+
Opacity=5
67
ShowDate=true

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Basic activity ghosts mod for [GTBikeV](https://www.gtbikev.com/)
55
## Installation
66
- Put `ActivityGhosts.dll` and `ActivityGhosts.ini` in the `Scripts` folder
77
- Optionally, open `ActivityGhosts.ini` and edit preferences
8+
- **MenuKey**: key to open the menu
9+
- **LoadKey**: key to load or regroup ghosts
10+
- **InitialGPSPointLat**: initial latitude used in FIT files
11+
- **InitialGPSPointLong**: initial longitude used in FIT files
12+
- **Opacity**: ghosts opacity (1-5)
13+
- **ShowDate**: show activity date above ghosts
814
- The requirements should be satisfied if you have already installed GTBikeV
915

1016
## Usage

0 commit comments

Comments
 (0)