17
17
from utils import get_image_size , time_to_string
18
18
from DriverWidget import DriverWidget
19
19
from DriverComparisonWidget import DriverComparisonWidget
20
- from LeaderboardRow import LeaderboardRow
20
+ from LeaderboardRow import LeaderboardRow , INFO_TYPE
21
21
from FastestLapBanner import FastestLapBanner
22
22
23
23
37
37
replay_started = False
38
38
quali_started = False
39
39
40
- leaderboard_displayed = False
41
-
42
40
qualify_session_time = 0
43
41
44
42
# REPLAY FILE
57
55
leaderboardBaseLabel = None
58
56
leaderboardInfoBackgroundLabel = None
59
57
leaderboardBackgroundLabel = None
58
+ flagLabel = None
60
59
61
60
class Driver : # class to hold driver information
62
61
def __init__ (self , id , n_splits ):
@@ -87,6 +86,7 @@ def acMain(ac_version):
87
86
# LABELS
88
87
global leaderboard
89
88
global lapCountTimerLabel , leaderboardBaseLabel , leaderboardInfoBackgroundLabel , leaderboardBackgroundLabel
89
+ global flagLabel
90
90
91
91
totalDrivers = ac .getCarsCount ()
92
92
n_splits = ac .getTrackLength (0 ) / FC .TRACK_SECTION_LENGTH
@@ -113,7 +113,7 @@ def acMain(ac_version):
113
113
ac .setPosition (leaderboardBackgroundLabel , 0 , h )
114
114
ac .setSize (leaderboardBackgroundLabel , w , totalDrivers * LeaderboardRow .ROW_HEIGHT + 2 )
115
115
ac .setBackgroundTexture (leaderboardBackgroundLabel , FC .LEADERBOARD_BACKGROUND );
116
-
116
+
117
117
# ===============================
118
118
# Lap Counter / Time
119
119
lapCountTimerLabel = ac .addLabel (leaderboardWindow , "" )
@@ -123,13 +123,27 @@ def acMain(ac_version):
123
123
ac .setFontAlignment (lapCountTimerLabel , "center" )
124
124
ac .setFontColor (lapCountTimerLabel , 0.86 , 0.86 , 0.86 , 1 )
125
125
126
+ # ===============================
127
+ # Flags
128
+ flagLabel = ac .addLabel (leaderboardWindow , "" )
129
+ ac .setPosition (flagLabel , w , 8 )
130
+ ac .setSize (flagLabel , 110 , h - 8 )
131
+ ac .setVisible (flagLabel , 0 )
132
+
126
133
# ===============================
127
134
# Info Background
128
135
leaderboardInfoBackgroundLabel = ac .addLabel (leaderboardWindow , "" )
129
136
ac .setPosition (leaderboardInfoBackgroundLabel , w , h )
130
137
ac .setSize (leaderboardInfoBackgroundLabel , 110 , totalDrivers * LeaderboardRow .ROW_HEIGHT + 2 )
131
138
ac .setBackgroundTexture (leaderboardInfoBackgroundLabel , FC .LEADERBOARD_INFO_BACKGROUNG )
132
139
140
+ info_button = ac .addButton (leaderboardWindow , "" )
141
+ ac .setPosition (info_button , w , h )
142
+ ac .setSize (info_button , 110 , totalDrivers * LeaderboardRow .ROW_HEIGHT + 2 )
143
+ ac .addOnClickedListener (info_button , on_click_info )
144
+ ac .setBackgroundOpacity (info_button , 0 )
145
+ ac .drawBorder (info_button , 0 )
146
+
133
147
# ===============================
134
148
# Driver Widget
135
149
driverWidget = DriverWidget (FC .APP_NAME + " Driver" )
@@ -175,6 +189,7 @@ def acUpdate(deltaT):
175
189
# LABELS
176
190
global leaderboard
177
191
global lapCountTimerLabel , leaderboardBaseLabel , leaderboardInfoBackgroundLabel , leaderboardBackgroundLabel
192
+ global flagLabel
178
193
179
194
# ============================
180
195
# UPDATE TIMERS
@@ -260,6 +275,20 @@ def acUpdate(deltaT):
260
275
fastest_lap_banner .timer -= timer1
261
276
fastest_lap_banner .hide ()
262
277
278
+ # ============================
279
+ # FLAGS
280
+ if info .graphics .flag == 1 :
281
+ ac .setBackgroundTexture (flagLabel , FC .BLUE_FLAG )
282
+ ac .setVisible (flagLabel , 1 )
283
+ elif info .graphics .flag == 2 :
284
+ ac .setBackgroundTexture (flagLabel , FC .YELLOW_FLAG )
285
+ ac .setVisible (flagLabel , 1 )
286
+ elif info .graphics .flag == 5 :
287
+ ac .setBackgroundTexture (flagLabel , FC .CHECKERED_FLAG )
288
+ ac .setVisible (flagLabel , 1 )
289
+ elif info .graphics .flag == 0 :
290
+ ac .setVisible (flagLabel , 0 )
291
+
263
292
timer1 = 0
264
293
265
294
# Once per second
@@ -284,17 +313,22 @@ def acUpdate(deltaT):
284
313
# ===========================
285
314
# CALCULATE TIME DIFERENCES
286
315
dPosition = sorted (drivers , key = lambda x : x .position )
287
- for i in range (1 , len (dPosition )):
288
- driver_ahead , driver = dPosition [i - 1 ], dPosition [i ]
289
- timeDiff = driver .split_times [driver .current_split - 1 ] - driver_ahead .split_times [driver .current_split - 1 ]
290
- if timeDiff < 0 : continue # ignore these times, happens on overtakes
291
- if driver .position > totalDrivers : continue # might try to update before it is possible
292
- driver .timeDiff = timeDiff
293
- if timeDiff > 60 :
294
- leaderboard [driver .position ].update_time ("+1 MIN" )
295
- else :
296
- leaderboard [driver .position ].update_time ("+" + time_to_string (timeDiff * 1000 ))
297
- leaderboard [0 ].update_time ("Interval" ) # Force it
316
+ if LeaderboardRow .update_type == INFO_TYPE .GAPS :
317
+ for i in range (1 , len (dPosition )):
318
+ driver_ahead , driver = dPosition [i - 1 ], dPosition [i ]
319
+ timeDiff = driver .split_times [driver .current_split - 1 ] - driver_ahead .split_times [driver .current_split - 1 ]
320
+ if timeDiff < 0 : continue # ignore these times, happens on overtakes
321
+ if driver .position > totalDrivers : continue # might try to update before it is possible
322
+ driver .timeDiff = timeDiff
323
+ if timeDiff > 60 :
324
+ leaderboard [driver .position ].update_time ("+1 MIN" )
325
+ else :
326
+ leaderboard [driver .position ].update_time ("+" + time_to_string (timeDiff * 1000 ))
327
+ leaderboard [0 ].update_time ("Interval" ) # Force it
328
+ elif LeaderboardRow .update_type == INFO_TYPE .POSITIONS :
329
+ for d in dPosition :
330
+ posDiff = d .starting_position - d .position - 1
331
+ leaderboard [d .position ].update_positions (posDiff )
298
332
299
333
# ============================
300
334
# MARK FASTEST LAP
@@ -561,9 +595,13 @@ def acUpdate(deltaT):
561
595
# UPDATE TIMES
562
596
if replay_data :
563
597
for row in leaderboard :
564
- row .update_time ("+" + time_to_string (drivers [row .driverId ].timeDiff * 1000 ))
565
- if row .row == 0 :
566
- row .update_time ("Interval" ) # Force it
598
+ if LeaderboardRow .update_type == INFO_TYPE .GAPS :
599
+ row .update_time ("+" + time_to_string (drivers [row .driverId ].timeDiff * 1000 ))
600
+ if row .row == 0 :
601
+ row .update_time ("Interval" ) # Force it
602
+ elif LeaderboardRow .update_type == INFO_TYPE .POSITIONS :
603
+ posDiff = drivers [row .driverId ].starting_position - drivers [row .driverId ].position - 1
604
+ row .update_positions (posDiff )
567
605
568
606
# END UPDATE
569
607
@@ -572,18 +610,6 @@ def acShutdown():
572
610
if replay_file :
573
611
replay_file .close ()
574
612
575
- def hide_leaderboard ():
576
- global leaderboard_displayed
577
- global leaderboard
578
- global lapCountTimerLabel , leaderboardBaseLabel , leaderboardInfoBackgroundLabel , leaderboardBackgroundLabel
579
- if not leaderboard_displayed : return
580
-
581
- def show_leaderboard ():
582
- global leaderboard_displayed
583
- global leaderboard
584
- global lapCountTimerLabel , leaderboardBaseLabel , leaderboardInfoBackgroundLabel , leaderboardBackgroundLabel
585
- if leaderboard_displayed : return
586
-
587
613
def write_driver_info (replay_file , laps , time , drivers ):
588
614
data = "U %d %d " % (laps , time )
589
615
for d in drivers :
@@ -676,5 +702,8 @@ def lookup_fastest_lap(lap, time, replay_data):
676
702
return replay_data ['FL' ][lap ][it - 1 ]
677
703
return None
678
704
679
-
705
+ def on_click_info (* args ):
706
+ # cycle through types
707
+ LeaderboardRow .update_type += 1
708
+ LeaderboardRow .update_type %= INFO_TYPE .N_TYPES
680
709
0 commit comments