Skip to content

Commit

Permalink
Add load/regroup key
Browse files Browse the repository at this point in the history
Fix opacity setting
  • Loading branch information
oldnapalm committed May 3, 2022
1 parent 1cd63d1 commit 353c7d0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
72 changes: 39 additions & 33 deletions ActivityGhosts/ActivityGhosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ActivityGhosts : Script
private Blip start;
private int lastTime;
private Keys menuKey;
private Keys loadKey;
public static PointF initialGPSPoint;
public static int opacity;
private bool showDate;
Expand Down Expand Up @@ -93,30 +94,35 @@ private void LoadGhosts()
{
FitActivityDecoder fit = new FitActivityDecoder(file.FullName);
List<GeoPoint> points = fit.pointList;
if (points.Count > 1)
if (points.Count > 1 && Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f)
{
if (Game.Player.Character.Position.DistanceTo2D(new Vector2(points[0].Lat, points[0].Long)) < 50f)
{
int offset = ghosts.Count / 2 + 1;
if (ghosts.Count % 2 == 0)
offset *= -1;
points[0].Lat += offset;
float h = Game.Player.Character.Heading;
if ((h > 90f && h < 180f) || (h > 270f && h < 360f))
points[0].Long -= offset;
else
points[0].Long += offset;
string span;
var seconds = (System.DateTime.UtcNow - fit.startTime).TotalSeconds;
if (seconds < 7200) span = $"{seconds / 60:N0} minutes";
else if (seconds < 172800) span = $"{seconds / 3600:N0} hours";
else if (seconds < 1209600) span = $"{seconds / 86400:N0} days";
else if (seconds < 5259492) span = $"{seconds / 604800:N0} weeks";
else span = $"{seconds / 2629746:N0} months";
ghosts.Add(new Ghost(points, fit.sport, span));
}
int offset = ghosts.Count / 2 + 1;
if (ghosts.Count % 2 == 0)
offset *= -1;
points[0].Lat += offset;
float h = Game.Player.Character.Heading;
if ((h > 90f && h < 180f) || (h > 270f && h < 360f))
points[0].Long -= offset;
else
points[0].Long += offset;
string span;
var seconds = (System.DateTime.UtcNow - fit.startTime).TotalSeconds;
if (seconds < 7200) span = $"{seconds / 60:N0} minutes";
else if (seconds < 172800) span = $"{seconds / 3600:N0} hours";
else if (seconds < 1209600) span = $"{seconds / 86400:N0} days";
else if (seconds < 5259492) span = $"{seconds / 604800:N0} weeks";
else span = $"{seconds / 2629746:N0} months";
ghosts.Add(new Ghost(points, fit.sport, span));
}
}
if (ghosts.Count > 0)
{
start = World.CreateBlip(Game.Player.Character.Position);
start.Sprite = BlipSprite.RaceBike;
loadMenuItem.Enabled = false;
regroupMenuItem.Enabled = true;
deleteMenuItem.Enabled = true;
}
}
Notification.Show($"{ghosts.Count} ghosts loaded");
}
Expand All @@ -126,13 +132,14 @@ private void LoadSettings()
CultureInfo.CurrentCulture = new CultureInfo("", false);
ScriptSettings settings = ScriptSettings.Load(@".\Scripts\ActivityGhosts.ini");
menuKey = (Keys)Enum.Parse(typeof(Keys), settings.GetValue("Main", "MenuKey", "F8"), true);
loadKey = (Keys)Enum.Parse(typeof(Keys), settings.GetValue("Main", "LoadKey", "G"), true);
float initialGPSPointLat = settings.GetValue("Main", "InitialGPSPointLat", -19.10637f);
float initialGPSPointLong = settings.GetValue("Main", "InitialGPSPointLong", -169.871f);
initialGPSPoint = new PointF(initialGPSPointLat, initialGPSPointLong);
opacity = settings.GetValue("Main", "Opacity", 50);
if (opacity < 0) opacity = 0;
if (opacity > 100) opacity = 100;
opacity *= 255 / 100;
opacity = settings.GetValue("Main", "Opacity", 5);
if (opacity < 1) opacity = 1;
if (opacity > 5) opacity = 5;
opacity *= 51;
showDate = settings.GetValue("Main", "ShowDate", true);
}

Expand All @@ -149,14 +156,6 @@ private void CreateMenu()
loadMenuItem.Activated += (sender, itemArgs) =>
{
LoadGhosts();
if (ghosts.Count > 0)
{
start = World.CreateBlip(Game.Player.Character.Position);
start.Sprite = BlipSprite.RaceBike;
loadMenuItem.Enabled = false;
regroupMenuItem.Enabled = true;
deleteMenuItem.Enabled = true;
}
mainMenu.Visible = false;
};
regroupMenuItem = new NativeItem("Regroup", "Regroup ghosts")
Expand Down Expand Up @@ -188,6 +187,13 @@ private void CreateMenu()
{
if (e.KeyCode == menuKey)
mainMenu.Visible = !mainMenu.Visible;
else if (e.KeyCode == loadKey)
{
if (ghosts.Count == 0)
LoadGhosts();
else
RegroupGhosts();
}
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion ActivityGhosts/ActivityGhosts.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Main]
MenuKey=F8
LoadKey=G
InitialGPSPointLat=-19.10637
InitialGPSPointLong=-169.871
Opacity=50
Opacity=5
ShowDate=true
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Basic activity ghosts mod for [GTBikeV](https://www.gtbikev.com/)
## Installation
- Put `ActivityGhosts.dll` and `ActivityGhosts.ini` in the `Scripts` folder
- Optionally, open `ActivityGhosts.ini` and edit preferences
- **MenuKey**: key to open the menu
- **LoadKey**: key to load or regroup ghosts
- **InitialGPSPointLat**: initial latitude used in FIT files
- **InitialGPSPointLong**: initial longitude used in FIT files
- **Opacity**: ghosts opacity (1-5)
- **ShowDate**: show activity date above ghosts
- The requirements should be satisfied if you have already installed GTBikeV

## Usage
Expand Down

0 comments on commit 353c7d0

Please sign in to comment.