@@ -21,6 +21,7 @@ public class ActivityGhosts : Script
21
21
private Blip start ;
22
22
private int lastTime ;
23
23
private Keys menuKey ;
24
+ private Keys loadKey ;
24
25
public static PointF initialGPSPoint ;
25
26
public static int opacity ;
26
27
private bool showDate ;
@@ -93,30 +94,35 @@ private void LoadGhosts()
93
94
{
94
95
FitActivityDecoder fit = new FitActivityDecoder ( file . FullName ) ;
95
96
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 )
97
98
{
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 ) ) ;
118
116
}
119
117
}
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
+ }
120
126
}
121
127
Notification . Show ( $ "{ ghosts . Count } ghosts loaded") ;
122
128
}
@@ -126,13 +132,14 @@ private void LoadSettings()
126
132
CultureInfo . CurrentCulture = new CultureInfo ( "" , false ) ;
127
133
ScriptSettings settings = ScriptSettings . Load ( @".\Scripts\ActivityGhosts.ini" ) ;
128
134
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 ) ;
129
136
float initialGPSPointLat = settings . GetValue ( "Main" , "InitialGPSPointLat" , - 19.10637f ) ;
130
137
float initialGPSPointLong = settings . GetValue ( "Main" , "InitialGPSPointLong" , - 169.871f ) ;
131
138
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 ;
136
143
showDate = settings . GetValue ( "Main" , "ShowDate" , true ) ;
137
144
}
138
145
@@ -149,14 +156,6 @@ private void CreateMenu()
149
156
loadMenuItem . Activated += ( sender , itemArgs ) =>
150
157
{
151
158
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
- }
160
159
mainMenu . Visible = false ;
161
160
} ;
162
161
regroupMenuItem = new NativeItem ( "Regroup" , "Regroup ghosts" )
@@ -188,6 +187,13 @@ private void CreateMenu()
188
187
{
189
188
if ( e . KeyCode == menuKey )
190
189
mainMenu . Visible = ! mainMenu . Visible ;
190
+ else if ( e . KeyCode == loadKey )
191
+ {
192
+ if ( ghosts . Count == 0 )
193
+ LoadGhosts ( ) ;
194
+ else
195
+ RegroupGhosts ( ) ;
196
+ }
191
197
} ;
192
198
}
193
199
}
0 commit comments