Skip to content

Commit 1c2bfdf

Browse files
committed
Add option to show ghost date
1 parent a1d6507 commit 1c2bfdf

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ActivityGhosts/ActivityGhosts.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Dynastream.Fit;
99
using GTA;
1010
using GTA.Math;
11+
using GTA.Native;
1112
using GTA.UI;
1213
using NativeUI;
1314

@@ -21,6 +22,7 @@ public class ActivityGhosts : Script
2122
private Keys menuKey;
2223
public static PointF initialGPSPoint;
2324
public static int opacity;
25+
private bool showDate;
2426

2527
public ActivityGhosts()
2628
{
@@ -40,6 +42,17 @@ private void OnTick(object sender, EventArgs e)
4042
g.Update();
4143
lastTime = System.DateTime.UtcNow;
4244
}
45+
46+
if (showDate)
47+
foreach (Ghost g in ghosts)
48+
if (g.ped.IsOnScreen && g.ped.IsInRange(Game.Player.Character.Position, 20f))
49+
{
50+
var pos = g.ped.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.5f) + g.ped.Velocity / Game.FPS;
51+
Function.Call(Hash.SET_DRAW_ORIGIN, pos.X, pos.Y, pos.Z, 0);
52+
g.date.Scale = 0.4f - GameplayCamera.Position.DistanceTo(g.ped.Position) * 0.01f;
53+
g.date.Draw();
54+
Function.Call(Hash.CLEAR_DRAW_ORIGIN);
55+
}
4356
}
4457

4558
private void OnAbort(object sender, EventArgs e)
@@ -87,7 +100,14 @@ private void LoadGhosts()
87100
points[0].Long -= offset;
88101
else
89102
points[0].Long += offset;
90-
ghosts.Add(new Ghost(points));
103+
string span;
104+
var seconds = (System.DateTime.UtcNow - file.CreationTimeUtc).TotalSeconds;
105+
if (seconds < 7200) span = $"{seconds / 60:N0} minutes";
106+
else if (seconds < 172800) span = $"{seconds / 3600:N0} hours";
107+
else if (seconds < 1209600) span = $"{seconds / 86400:N0} days";
108+
else if (seconds < 5259492) span = $"{seconds / 604800:N0} weeks";
109+
else span = $"{seconds / 2629746:N0} months";
110+
ghosts.Add(new Ghost(points, span));
91111
}
92112
}
93113
}
@@ -107,6 +127,7 @@ private void LoadSettings()
107127
if (opacity < 0) opacity = 0;
108128
if (opacity > 100) opacity = 100;
109129
opacity *= 255 / 100;
130+
showDate = settings.GetValue("Main", "ShowDate", true);
110131
}
111132

112133
private void CreateMenu()
@@ -162,7 +183,8 @@ public class Ghost
162183
{
163184
private List<GeoPoint> points;
164185
private Vehicle vehicle;
165-
private Ped ped;
186+
public Ped ped;
187+
public TextElement date;
166188
private Blip blip;
167189
private int index;
168190

@@ -178,7 +200,7 @@ public class Ghost
178200

179201
private string[] availableCyclists = { "a_m_y_cyclist_01", "a_m_y_roadcyc_01" };
180202

181-
public Ghost(List<GeoPoint> pointList)
203+
public Ghost(List<GeoPoint> pointList, string span)
182204
{
183205
points = pointList;
184206
index = 0;
@@ -215,6 +237,7 @@ public Ghost(List<GeoPoint> pointList)
215237
blip.Color = BlipColor.WhiteNotPure;
216238
}
217239
}
240+
date = new TextElement($"{span} ago", new PointF(0, 0), 1f, Color.WhiteSmoke, GTA.UI.Font.ChaletLondon, Alignment.Center, false, true);
218241
}
219242

220243
public void Update()

ActivityGhosts/ActivityGhosts.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ MenuKey=F8
33
InitialGPSPointLat=-19.10637
44
InitialGPSPointLong=-169.871
55
Opacity=50
6+
ShowDate=true

0 commit comments

Comments
 (0)