Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 53.63 KB | None | 0 0
  1. import ac
  2. import acsys
  3. import math
  4. import functools
  5. from .util.classes import Label, Value, Colors, Font
  6. from .configuration import Configuration
  7.  
  8.  
  9. class Driver:
  10.     def __init__(self, app, identifier, name, pos, is_lap_label=False, is_results=False):
  11.         self.identifier = identifier
  12.         self.rowHeight = Configuration.ui_row_height
  13.         self.race = False
  14.         self.race_start_position = -1
  15.         self.cur_theme = Value(-1)
  16.         self.font = Value(0)
  17.         self.theme = Value(-1)
  18.         self.border_direction = Value(-1)
  19.         self.isLapTimeValid=True
  20.         self.row_height = Value(-1)
  21.         self.hasStartedRace = False
  22.         self.inPitFromPitLane = False
  23.         self.isInPitLane = Value(False)
  24.         self.isInPitLaneOld = False
  25.         self.isInPitBox = Value(False)
  26.         str_offset = " "
  27.         self.final_y = 0
  28.         self.isDisplayed = False
  29.         self.firstDraw = False
  30.         self.isAlive = Value(False)
  31.         self.is_results = is_results
  32.         self.movingUp = False
  33.         self.isCurrentVehicule = Value(False)
  34.         self.isLapLabel = is_lap_label
  35.         self.qual_mode = Value(0)
  36.         self.race_gaps = []
  37.         self.finished = Value(False)
  38.         self.bestLap = 0
  39.         self.compact_mode = False
  40.         self.bestLapServer = 0
  41.         self.lapCount = 0
  42.         self.fullName = Value(name)
  43.         self.shortName = name
  44.         self.time = Value()
  45.         self.gap = Value()
  46.         self.raceProgress = 0
  47.         self.race_current_sector = Value(0)
  48.         self.race_standings_sector = Value(0)
  49.         self.push_2_pass_status = Value(0)
  50.         self.push_2_pass_left = Value(0)
  51.         self.isInPit = Value(False)
  52.         self.completedLaps = Value()
  53.         self.completedLapsChanged = False
  54.         self.last_lap_visible_end = 0
  55.         self.time_highlight_end = 0
  56.         self.position_highlight_end = 0
  57.         self.highlight = Value()
  58.         self.pit_highlight_end = 0
  59.         self.pit_highlight = Value()
  60.         self.position = Value()
  61.         self.position_offset = Value()
  62.         self.carName = ac.getCarName(self.identifier)
  63.         self.num_pos = 0
  64.         self.showingFullNames = False
  65.         fontSize = 28
  66.         self.lbl_time = Label(app) \
  67.             .set(w=self.rowHeight * 4.7, h=self.rowHeight,
  68.                  x=self.rowHeight, y=0,
  69.                  opacity=0)
  70.         if self.isLapLabel:
  71.             self.lbl_name = Label(app) \
  72.                 .set(w=self.rowHeight * 6, h=self.rowHeight,
  73.                      x=0, y=0,
  74.                      opacity=0)
  75.             self.lbl_name_txt = Label(app, str_offset + name) \
  76.                 .set(w=self.rowHeight * 6, h=self.rowHeight,
  77.                      x=0, y=0,
  78.                      font_size=fontSize,
  79.                      align="left",
  80.                      opacity=0)
  81.         elif self.is_results:
  82.             self.lbl_name = Label(app) \
  83.                 .set(w=self.rowHeight * 5, h=self.rowHeight,
  84.                      x=self.rowHeight, y=0,
  85.                      opacity=0)
  86.             self.lbl_name_txt = Label(app, str_offset + self.format_name_tlc(name)) \
  87.                 .set(w=self.rowHeight * 5, h=self.rowHeight,
  88.                      x=self.rowHeight, y=0,
  89.                      font_size=fontSize,
  90.                      align="left",
  91.                      opacity=0)
  92.             self.lbl_position = Label(app) \
  93.                 .set(w=self.rowHeight, h=self.rowHeight,
  94.                      x=0, y=0,
  95.                      opacity=0)
  96.             self.lbl_position_txt = Label(app, str(pos + 1)) \
  97.                 .set(w=self.rowHeight, h=self.rowHeight,
  98.                      x=0, y=0,
  99.                      font_size=fontSize,
  100.                      align="center",
  101.                      opacity=0)
  102.             self.lbl_pit = Label(app, "P") \
  103.                 .set(w=self.rowHeight * 0.6, h=self.rowHeight - 2,
  104.                      x=self.rowHeight * 6, y=self.final_y + 2,
  105.                      font_size=fontSize - 3,
  106.                      align="center",
  107.                      opacity=0)
  108.             self.lbl_pit.setAnimationSpeed("rgb", 0.08)
  109.             self.lbl_position.setAnimationMode("y", "spring")
  110.             self.lbl_position_txt.setAnimationMode("y", "spring")
  111.             self.lbl_pit.setAnimationMode("y", "spring")
  112.         else:
  113.             self.lbl_name = Label(app) \
  114.                 .set(w=self.rowHeight * 5, h=self.rowHeight,
  115.                      x=self.rowHeight, y=0,
  116.                      font_size=fontSize,
  117.                      align="left",
  118.                      opacity=0)
  119.             self.lbl_name_txt = Label(app, str_offset + self.format_name_tlc(name)) \
  120.                 .set(w=self.rowHeight * 5, h=self.rowHeight,
  121.                      x=self.rowHeight, y=0,
  122.                      font_size=fontSize,
  123.                      align="left",
  124.                      opacity=0)
  125.             self.lbl_position = Label(app) \
  126.                 .set(w=self.rowHeight, h=self.rowHeight,
  127.                      x=0, y=0,
  128.                      opacity=0)
  129.             self.lbl_position_txt = Label(app, str(pos + 1)) \
  130.                 .set(w=self.rowHeight, h=self.rowHeight,
  131.                      x=0, y=0,
  132.                      font_size=fontSize,
  133.                      align="center",
  134.                      opacity=0)
  135.             self.lbl_pit = Label(app, "P") \
  136.                 .set(w=self.rowHeight * 0.6, h=self.rowHeight - 2,
  137.                      x=self.rowHeight * 6, y=self.final_y + 2,
  138.                      font_size=fontSize - 3,
  139.                      align="center",
  140.                      opacity=0)
  141.             self.lbl_p2p = Label(app, "0") \
  142.                 .set(w=self.rowHeight * 0.55, h=self.rowHeight - 2,
  143.                      x=self.rowHeight * 6, y=self.final_y + 2,
  144.                      font_size=fontSize - 3,
  145.                      align="center",
  146.                      opacity=0)
  147.             self.lbl_p2p.setAnimationSpeed("rgb", 0.08)
  148.             self.lbl_pit.setAnimationSpeed("rgb", 0.08)
  149.             self.lbl_position.setAnimationMode("y", "spring")
  150.             self.lbl_position_txt.setAnimationMode("y", "spring")
  151.             self.lbl_p2p.setAnimationMode("y", "spring")
  152.             self.lbl_pit.setAnimationMode("y", "spring")
  153.         self.lbl_time_txt = Label(app, "+0.000") \
  154.             .set(w=self.rowHeight * 4.7, h=self.rowHeight,
  155.                  x=self.rowHeight, y=0,
  156.                  font_size=fontSize,
  157.                  align="right",
  158.                  opacity=0)
  159.         self.lbl_border = Label(app) \
  160.             .set(w=self.rowHeight * 2.8, h=2,
  161.                  x=0, y=self.rowHeight - 2,
  162.                  background=Colors.red(bg=True),
  163.                  opacity=Colors.border_opacity())
  164.         self.set_name()
  165.         self.lbl_time_txt.setAnimationSpeed("rgb", 0.08)
  166.         self.lbl_name.setAnimationSpeed("w", 2)
  167.         self.lbl_time.setAnimationSpeed("w", 2)
  168.         self.lbl_name.setAnimationMode("y", "spring")
  169.         self.lbl_name_txt.setAnimationMode("y", "spring")
  170.         self.lbl_time.setAnimationMode("y", "spring")
  171.         self.lbl_time_txt.setAnimationMode("y", "spring")
  172.         self.lbl_border.setAnimationMode("y", "spring")
  173.         self.redraw_size()
  174.  
  175.         if not self.isLapLabel:
  176.             self.partial_func = functools.partial(self.on_click_func, driver=self.identifier)
  177.             ac.addOnClickedListener(self.lbl_position.label, self.partial_func)
  178.             ac.addOnClickedListener(self.lbl_name.label, self.partial_func)
  179.  
  180.     @classmethod
  181.     def on_click_func(*args, driver=0):
  182.         ac.focusCar(driver)
  183.  
  184.     def redraw_size(self):
  185.         # Config
  186.         self.row_height.setValue(Configuration.ui_row_height)
  187.         self.border_direction.setValue(Colors.border_direction)
  188.         self.theme.setValue(Colors.general_theme + Colors.theme_red + Colors.theme_green + Colors.theme_blue)
  189.         self.font.setValue(Font.current)
  190.         self.rowHeight = self.row_height.value
  191.         font_size = Font.get_font_size(self.rowHeight + Font.get_font_offset())
  192.         if Colors.border_direction == 1:
  193.             border_offset = 8
  194.         else:
  195.             border_offset = 4
  196.         # Colors
  197.         if self.theme.hasChanged():
  198.             if not self.isLapLabel:
  199.                 self.set_border()
  200.                 if self.pit_highlight.value:
  201.                     self.lbl_pit.set(color=Colors.tower_pit_highlight_txt(), animated=True, init=True)
  202.                 else:
  203.                     self.lbl_pit.set(color=Colors.tower_pit_txt(), animated=True, init=True)
  204.             if self.race:
  205.                 battles = True
  206.             else:
  207.                 battles = False
  208.             if self.position.value % 2 == 1:
  209.                 if not self.isLapLabel:
  210.                     if self.position.value == 1 and Colors.tower_first_position_different():
  211.                         self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  212.                         self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  213.                         self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  214.                         self.lbl_time_txt.set(color=Colors.tower_time_odd_txt(), animated=True, init=True)
  215.                         self.lbl_position.set(background=Colors.tower_position_first_bg(), animated=True, init=True)
  216.                         self.lbl_position_txt.set(color=Colors.tower_position_first_txt(), animated=True, init=True)
  217.                         self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  218.                     elif battles and self.isCurrentVehicule.value:
  219.                         self.lbl_name.set(background=Colors.tower_driver_highlight_odd_bg(), animated=True, init=True)
  220.                         self.lbl_name_txt.set(color=Colors.tower_driver_highlight_odd_txt(), animated=True, init=True)
  221.                         self.lbl_time.set(background=Colors.tower_time_highlight_odd_bg(), animated=True, init=True)
  222.                         self.lbl_time_txt.set(color=Colors.tower_time_highlight_txt(), animated=True, init=True)
  223.                         self.lbl_position.set(background=Colors.tower_position_highlight_odd_bg(), animated=True, init=True)
  224.                         self.lbl_position_txt.set(color=Colors.tower_position_highlight_odd_txt(), animated=True, init=True)
  225.                         self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  226.                     else:
  227.                         if self.isAlive.value:
  228.                             self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  229.                             self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  230.                             self.lbl_position.set(background=Colors.tower_position_odd_bg(), animated=True, init=True)
  231.                             self.lbl_position_txt.set(color=Colors.tower_position_odd_txt(), animated=True, init=True)
  232.                             self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  233.                             self.lbl_time_txt.set(color=Colors.tower_time_odd_txt(), animated=True, init=True)
  234.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  235.                         else:
  236.                             self.lbl_name.set(background=Colors.tower_driver_retired_bg(), animated=True, init=True)
  237.                             self.lbl_name_txt.set(color=Colors.tower_driver_retired_txt(), animated=True, init=True)
  238.                             self.lbl_position.set(background=Colors.tower_position_retired_bg(), animated=True, init=True)
  239.                             self.lbl_position_txt.set(color=Colors.tower_position_retired_txt(), animated=True, init=True)
  240.                             self.lbl_time.set(background=Colors.tower_time_retired_bg(), animated=True, init=True)
  241.                             self.lbl_time_txt.set(color=Colors.tower_time_retired_txt(), animated=True, init=True)
  242.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity_retired(), animated=True, init=True)
  243.                 else:
  244.                     self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  245.                     self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  246.                     self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  247.                     self.set_time_stint(self.time.value, self.isLapTimeValid)
  248.             else:
  249.                 if not self.isLapLabel:
  250.                     if battles and self.isCurrentVehicule.value:
  251.                         self.lbl_name.set(background=Colors.tower_driver_highlight_even_bg(), animated=True, init=True)
  252.                         self.lbl_name_txt.set(color=Colors.tower_driver_highlight_even_txt(), animated=True, init=True)
  253.                         self.lbl_time.set(background=Colors.tower_time_highlight_even_bg(), animated=True, init=True)
  254.                         self.lbl_time_txt.set(color=Colors.tower_time_highlight_txt(), animated=True, init=True)
  255.                         self.lbl_position.set(background=Colors.tower_position_highlight_even_bg(), animated=True, init=True)
  256.                         self.lbl_position_txt.set(color=Colors.tower_position_highlight_even_txt(), animated=True, init=True)
  257.                     else:
  258.                         if self.isAlive.value:
  259.                             self.lbl_name.set(background=Colors.tower_driver_even_bg(), animated=True, init=True)
  260.                             self.lbl_name_txt.set(color=Colors.tower_driver_even_txt(), animated=True, init=True)
  261.                             self.lbl_position.set(background=Colors.tower_position_even_bg(), animated=True, init=True)
  262.                             self.lbl_position_txt.set(color=Colors.tower_position_even_txt(), animated=True, init=True)
  263.                             self.lbl_time.set(background=Colors.tower_time_even_bg(), animated=True, init=True)
  264.                             self.lbl_time_txt.set(color=Colors.tower_time_even_txt(), animated=True, init=True)
  265.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  266.                         else:
  267.                             self.lbl_name.set(background=Colors.tower_driver_retired_bg(), animated=True, init=True)
  268.                             self.lbl_name_txt.set(color=Colors.tower_driver_retired_txt(), animated=True, init=True)
  269.                             self.lbl_position.set(background=Colors.tower_position_retired_bg(), animated=True, init=True)
  270.                             self.lbl_position_txt.set(color=Colors.tower_position_retired_txt(), animated=True, init=True)
  271.                             self.lbl_time.set(background=Colors.tower_time_retired_bg(), animated=True, init=True)
  272.                             self.lbl_time_txt.set(color=Colors.tower_time_retired_txt(), animated=True, init=True)
  273.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity_retired(), animated=True, init=True)
  274.                 else:
  275.                     self.lbl_name.set(background=Colors.tower_driver_even_bg(), animated=True, init=True)
  276.                     self.lbl_name_txt.set(color=Colors.tower_driver_even_txt(), animated=True, init=True)
  277.                     self.lbl_time.set(background=Colors.tower_time_even_bg(), animated=True, init=True)
  278.                     self.set_time_stint(self.time.value, self.isLapTimeValid)
  279.         # Names
  280.         lbl_multi = 1.2
  281.         if Configuration.names >= 2 and not self.isLapLabel:  # First Last
  282.             self.show_full_name()
  283.             lbl_multi = 4.3
  284.         else:  # TLC
  285.             self.set_name()
  286.         self.lbl_time_txt.set(w=self.rowHeight * 4.7, h=self.rowHeight,
  287.                               x=self.rowHeight * lbl_multi + border_offset,
  288.                               font_size=font_size, animated=True)
  289.  
  290.         font_changed = self.font.hasChanged()
  291.         if self.row_height.hasChanged() or font_changed or self.border_direction.hasChanged():
  292.             # Fonts
  293.             if font_changed:
  294.                 self.lbl_name_txt.update_font()
  295.                 self.lbl_time_txt.update_font()
  296.                 if not self.isLapLabel:
  297.                     self.lbl_position_txt.update_font()
  298.                     self.lbl_pit.update_font()
  299.                     self.lbl_p2p.update_font()
  300.             # UI
  301.             #self.position.setValue(-1) + border_offset
  302.             if self.isLapLabel:
  303.                 self.lbl_name.set(w=self.get_name_width() + 4,
  304.                                   h=self.rowHeight,
  305.                                   x=border_offset - 4)
  306.                 self.lbl_name_txt.set(w=self.get_name_width(),
  307.                                       h=self.rowHeight,
  308.                                       x=border_offset - 2,
  309.                                       font_size=font_size)
  310.                 self.lbl_time.set(w=self.get_time_width(),
  311.                                   h=self.rowHeight,
  312.                                   x=self.get_name_width() + border_offset)
  313.             else:
  314.                 self.lbl_name.set(w=self.get_name_width(),
  315.                                   h=self.rowHeight,
  316.                                   x=self.rowHeight + border_offset)
  317.                 self.lbl_time.set(w=self.get_time_width(),
  318.                                   h=self.rowHeight,
  319.                                   x=self.rowHeight + border_offset + self.get_name_width())
  320.                 self.lbl_name_txt.set(w=self.get_name_width(),
  321.                                       h=self.rowHeight,
  322.                                       x=self.rowHeight + border_offset,
  323.                                       font_size=font_size)
  324.                 self.lbl_position.set(w=self.rowHeight + 4, h=self.rowHeight)
  325.                 self.lbl_position_txt.set(w=self.rowHeight + 4, h=self.rowHeight,
  326.                                       font_size=font_size)
  327.                 self.lbl_pit.set(w=self.rowHeight * 0.6, h=self.rowHeight - 2,
  328.                                  x=self.get_pit_x(),
  329.                                  font_size=font_size - 3, animated=True)
  330.                 self.lbl_p2p.set(w=self.rowHeight * 0.55, h=self.rowHeight - 2,
  331.                                  x=self.get_pit_x(),
  332.                                  font_size=font_size - 6, animated=True)
  333.  
  334.             if Colors.border_direction == 1:
  335.                 if self.isLapLabel:
  336.                     self.lbl_border.set(w=4, h=self.rowHeight,
  337.                                         x=0, y=self.final_y)
  338.                 else:
  339.                     self.lbl_border.set(w=4, h=self.rowHeight,
  340.                                         x=self.rowHeight + 4, y=self.final_y)
  341.             else:
  342.                 self.lbl_border.set(w=self.rowHeight * 2.8, h=2,
  343.                                     x=0, y=self.final_y + self.rowHeight - 2)
  344.             if self.isDisplayed:
  345.                 self.final_y = self.num_pos * self.rowHeight
  346.                 self.lbl_name.setY(self.final_y, True)
  347.                 self.lbl_time.setY(self.final_y, True)
  348.                 self.lbl_name_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  349.                 self.lbl_time_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  350.                 if not self.isLapLabel:
  351.                     self.lbl_position_txt.setText(str(self.position.value))
  352.                     self.lbl_position.setY(self.final_y, True)
  353.                     self.lbl_position_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  354.                     self.lbl_pit.setY(self.final_y + 3 + Font.get_font_x_offset(), True)
  355.                     self.lbl_p2p.setY(self.final_y + 5 + Font.get_font_x_offset(), True)
  356.  
  357.                 if Colors.border_direction == 1:
  358.                     self.lbl_border.setY(self.final_y, True)
  359.                 else:
  360.                     self.lbl_border.setY(self.final_y + self.rowHeight - 2, True)
  361.  
  362.     def show(self, needs_tlc=True, race=True, compact=False):
  363.         self.race = race
  364.         self.compact_mode = compact
  365.         # P2P
  366.         if not self.isLapLabel:
  367.             if not self.isInPit.value and self.push_2_pass_status.value > 0 and not self.finished.value:
  368.                 self.lbl_p2p.setX(self.get_pit_x(), self.isDisplayed)
  369.                 self.lbl_p2p.show()
  370.             else:
  371.                 self.lbl_p2p.hide()
  372.         if self.showingFullNames and needs_tlc:
  373.             self.set_name()
  374.         elif not self.showingFullNames and not needs_tlc:
  375.             self.show_full_name()
  376.         if not self.isDisplayed:
  377.             if not self.isLapLabel:
  378.                 self.lbl_name.set(w=self.get_name_width())
  379.                 if Colors.border_direction == 1:
  380.                     border_offset = 8
  381.                 else:
  382.                     border_offset = 4
  383.                 self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width())
  384.             self.isDisplayed = True
  385.         self.lbl_name.show()
  386.         self.lbl_name_txt.show()
  387.  
  388.         if not self.is_compact_mode():
  389.             self.lbl_time.show()
  390.             self.lbl_time_txt.show()
  391.         else:
  392.             self.lbl_time.hide()
  393.             self.lbl_time_txt.hide()
  394.  
  395.         #if (self.isLapLabel and Colors.border_direction == 0) or not self.isLapLabel:
  396.         self.lbl_border.show()
  397.         #else:
  398.         #    self.lbl_border.hide()
  399.         if not self.isLapLabel:
  400.             self.lbl_position.show()
  401.             self.lbl_position_txt.show()
  402.             if not self.isAlive.value and not self.finished.value:
  403.                 self.lbl_name_txt.setColor(Colors.tower_driver_retired_txt(), animated=True, init=True)
  404.             elif self.isInPit.value or ac.getCarState(self.identifier, acsys.CS.SpeedKMH) > 30 or self.finished.value:
  405.                 if self.race and self.isCurrentVehicule.value:
  406.                     if self.position.value % 2 == 1:
  407.                         self.lbl_name_txt.setColor(Colors.tower_driver_highlight_odd_txt(), animated=True, init=True)
  408.                     else:
  409.                         self.lbl_name_txt.setColor(Colors.tower_driver_highlight_even_txt(), animated=True, init=True)
  410.                 elif self.position.value % 2 == 1:
  411.                     self.lbl_name_txt.setColor(Colors.tower_driver_odd_txt(), animated=True, init=True)
  412.                 else:
  413.                     self.lbl_name_txt.setColor(Colors.tower_driver_even_txt(), animated=True, init=True)
  414.             else:
  415.                 self.lbl_name_txt.setColor(Colors.tower_driver_stopped_txt(), animated=True, init=True)
  416.  
  417.     def update_pit(self, session_time):
  418.         if not self.isLapLabel:
  419.             if Colors.border_direction == 1:
  420.                 border_offset = 8
  421.             else:
  422.                 border_offset = 4
  423.             if not self.isLapLabel and self.isInPit.hasChanged():
  424.                 if self.isInPit.value:
  425.                     self.pit_highlight_end = session_time - 5000
  426.                     self.lbl_pit.setX(self.get_pit_x(), True)
  427.                     self.lbl_pit.show()
  428.                     self.lbl_name.set(w=self.get_name_width(), animated=True)
  429.                     self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated=True)
  430.                 else:
  431.                     self.lbl_pit.hide()
  432.                     self.lbl_name.set(w=self.get_name_width(), animated=True)
  433.                     self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated= True)
  434.             if self.isInPit.value and (self.lbl_name.f_params["w"].value < self.rowHeight * 5.6 or self.lbl_pit.f_params["a"].value < 1):
  435.                 self.lbl_pit.setX(self.get_pit_x(), True)
  436.                 self.lbl_pit.show()
  437.                 self.lbl_name.set(w=self.get_name_width(), animated=True)
  438.                 self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated=True)
  439.             elif not self.isInPit.value and (self.lbl_name.f_params["w"].value > self.rowHeight * 5 or self.lbl_pit.f_params["a"].value == 1):
  440.                 self.lbl_pit.hide()
  441.                 self.lbl_name.set(w=self.get_name_width(), animated=True)
  442.                 self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated= True)
  443.             if session_time == -1:
  444.                 self.pit_highlight_end = 0
  445.             self.pit_highlight.setValue(self.pit_highlight_end != 0 and self.pit_highlight_end < session_time)
  446.             if self.pit_highlight.hasChanged():
  447.                 if self.pit_highlight.value:
  448.                     self.lbl_pit.setColor(Colors.tower_pit_highlight_txt(), init=True)
  449.                 else:
  450.                     self.lbl_pit.setColor(Colors.tower_pit_txt(), animated=True, init=True)
  451.  
  452.     def hide(self, reset=False):
  453.         if not self.isLapLabel:
  454.             self.lbl_position.hide()
  455.             self.lbl_position_txt.hide()
  456.             self.lbl_pit.hide()
  457.             self.lbl_p2p.hide()
  458.             if Colors.border_direction == 1:
  459.                 border_offset = 8
  460.             else:
  461.                 border_offset = 4
  462.             #if self.isInPit.value:
  463.             self.lbl_name.set(w=self.get_name_width())
  464.             self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width())
  465.             #else:
  466.             #    self.lbl_name.set(w=self.get_name_width())
  467.             #    self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width())
  468.         self.lbl_time.hide()
  469.         self.lbl_time_txt.hide()
  470.         self.lbl_border.hide()
  471.         self.lbl_name.hide()
  472.         self.lbl_name_txt.hide()
  473.         self.isDisplayed = False
  474.         if reset:
  475.             self.finished.setValue(False)
  476.             self.isInPit.setValue(False)
  477.             self.firstDraw = False
  478.             self.set_name()
  479.             self.race_current_sector.setValue(0)
  480.             self.race_standings_sector.setValue(0)
  481.             self.race_gaps = []
  482.             self.completedLaps.setValue(0)
  483.             self.completedLapsChanged = False
  484.             self.last_lap_visible_end = 0
  485.             self.time_highlight_end = 0
  486.             self.bestLap = 0
  487.             self.bestLapServer = 0
  488.             self.position_highlight_end = 0
  489.             self.inPitFromPitLane = False
  490.             self.hasStartedRace = False
  491.             self.isInPitBox.setValue(False)
  492.             self.push_2_pass_status.setValue(0)
  493.             self.push_2_pass_left.setValue(0)
  494.  
  495.     def get_best_lap(self, lap=False):
  496.         if lap:
  497.             self.bestLap = lap
  498.         if self.bestLapServer > 0 and self.bestLap > 0:
  499.             if self.bestLapServer > self.bestLap:
  500.                 return self.bestLap
  501.             else:
  502.                 return self.bestLapServer
  503.         if self.bestLapServer > 0:
  504.             return self.bestLapServer
  505.         if self.bestLap > 0:
  506.             return self.bestLap
  507.         return 0
  508.  
  509.     def set_name(self):
  510.         self.showingFullNames = False
  511.         offset = " "
  512.         if self.isLapLabel:
  513.             self.lbl_name_txt.setText(offset + self.fullName.value)
  514.         else:
  515.             if Configuration.names == 1:
  516.                 self.lbl_name_txt.setText(offset + self.format_name_tlc2(self.fullName.value))
  517.             else:
  518.                 self.lbl_name_txt.setText(offset + self.format_name_tlc(self.fullName.value))
  519.             self.set_border()
  520.  
  521.     def set_border(self):
  522.         colors_by_class = bool(Configuration.carColorsBy == 1)
  523.         self.lbl_border.set(background=Colors.colorFromCar(self.carName, colors_by_class, Colors.tower_border_default_bg()),
  524.                             init=True)
  525.  
  526.     def show_full_name(self):
  527.         offset = " "
  528.         self.showingFullNames = True
  529.         if self.isLapLabel:
  530.             self.lbl_name_txt.setText(offset + self.fullName.value)
  531.         else:
  532.             if Configuration.names == 4:
  533.                 self.lbl_name_txt.setText(offset + self.format_first_name(self.fullName.value))
  534.             elif Configuration.names == 3:
  535.                 self.lbl_name_txt.setText(offset + self.format_last_name2(self.fullName.value))
  536.             else:
  537.                 self.lbl_name_txt.setText(offset + self.format_last_name(self.fullName.value))
  538.  
  539.     def set_time(self, time, leader, session_time, mode):
  540.         if self.highlight.value:
  541.             if mode == 0:
  542.                 mode = 1
  543.         self.qual_mode.setValue(mode)
  544.         self.time.setValue(time)
  545.         self.gap.setValue(time - leader)
  546.         time_changed = self.time.hasChanged()
  547.         if time_changed or self.gap.hasChanged() or self.qual_mode.hasChanged():
  548.             if time_changed:
  549.                 self.time_highlight_end = session_time - 5000
  550.             if self.position.value == 1 or mode == 1:
  551.                 self.lbl_time_txt.change_font_if_needed().setText(self.format_time(self.time.value))
  552.             else:
  553.                 self.lbl_time_txt.change_font_if_needed().setText("+" + self.format_time(self.gap.value))
  554.  
  555.     def set_time_stint(self, time, valid):
  556.         self.isLapTimeValid = valid
  557.         self.time.setValue(time)
  558.         self.gap.setValue(time)
  559.         if self.time.hasChanged() or self.gap.hasChanged():
  560.             self.lbl_time_txt.change_font_if_needed().setText(self.format_time(self.time.value))
  561.             if valid:
  562.                 if self.position.value % 2 == 1:
  563.                     self.lbl_time_txt.setColor(Colors.tower_time_odd_txt(), animated=True, init=True)
  564.                 else:
  565.                     self.lbl_time_txt.setColor(Colors.tower_time_even_txt(), animated=True, init=True)
  566.             else:
  567.                 self.lbl_time_txt.setColor(Colors.tower_stint_lap_invalid_txt(), animated=True, init=True)
  568.  
  569.     def set_time_race(self, time, leader, session_time):
  570.         if self.position.value == 1:
  571.             self.lbl_time_txt.change_font_if_needed().setText("Lap " + str(time)).setColor(Colors.tower_time_odd_txt(), animated=True, init=True)
  572.         elif self.position.value % 2 == 1:
  573.             self.lbl_time_txt.change_font_if_needed().setText("+" + self.format_time(leader - session_time)).setColor(Colors.tower_time_odd_txt(), animated=True, init=True)
  574.         else:
  575.             self.lbl_time_txt.change_font_if_needed().setText("+" + self.format_time(leader - session_time)).setColor(Colors.tower_time_even_txt(), animated=True, init=True)
  576.  
  577.     def set_time_race_battle(self, time, identifier, lap=False, intervals=False):
  578.         if self.isCurrentVehicule.value:
  579.             normal_color = Colors.tower_time_highlight_txt()
  580.         elif self.position.value % 2 == 1:
  581.             normal_color = Colors.tower_time_odd_txt()
  582.         else:
  583.             normal_color = Colors.tower_time_even_txt()
  584.         if time == "PIT":
  585.             self.lbl_time_txt.change_font_if_needed().setText("PIT").setColor(Colors.tower_time_pit_txt(), animated=True, init=True)
  586.         elif time == "DNF":
  587.             self.lbl_time_txt.change_font_if_needed().setText("DNF").setColor(Colors.tower_time_retired_txt(), animated=True, init=True)
  588.             self.lbl_name.set(background=Colors.tower_driver_retired_bg(), animated=True, init=True)
  589.             self.lbl_name_txt.set(color=Colors.tower_driver_retired_txt(), animated=True, init=True)
  590.             self.lbl_position.set(background=Colors.tower_position_retired_bg(), animated=True, init=True)
  591.             self.lbl_position_txt.set(color=Colors.tower_position_retired_txt(), animated=True, init=True)
  592.             self.lbl_time.set(background=Colors.tower_time_retired_bg(), animated=True, init=True)
  593.             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity_retired(), animated=True, init=True)
  594.         elif isinstance(time, str) and time.find("UP") >= 0:
  595.             self.lbl_time_txt.change_font_if_needed(1).setText(time.replace("UP", u"\u25B2")).setColor(Colors.tower_time_place_gain_txt(), animated=True, init=True)
  596.             #self.lbl_time_txt.change_font_if_needed(1).setText(u"\u25B2").setColor(Colors.tower_time_place_gain_txt(), animated=True, init=True)
  597.         elif isinstance(time, str) and time.find("DOWN") >= 0:
  598.             self.lbl_time_txt.change_font_if_needed(1).setText(time.replace("DOWN", u"\u25BC")).setColor(Colors.tower_time_place_lost_txt(), animated=True, init=True)
  599.             #self.lbl_time_txt.change_font_if_needed(1).setText(u"\u25BC").setColor(Colors.tower_time_place_lost_txt(), animated=True, init=True)
  600.         elif isinstance(time, str) and time.find("NEUTRAL") >= 0:
  601.             self.lbl_time_txt.change_font_if_needed(1).setText(time.replace("NEUTRAL", u"\u25C0")).setColor(normal_color, animated=True, init=True)
  602.         elif self.identifier == identifier or time == 600000:
  603.             self.lbl_time_txt.change_font_if_needed().setText("").setColor(normal_color, animated=True, init=True)
  604.         elif lap:
  605.             str_time = "+" + str(math.floor(abs(time)))
  606.             if abs(time) >= 2:
  607.                 str_time += " Laps"
  608.             else:
  609.                 str_time += " Lap"
  610.             self.lbl_time_txt.change_font_if_needed().setText(str_time).setColor(normal_color, animated=True, init=True)
  611.         elif identifier == -1:
  612.             if time <= ac.getCarState(self.identifier, acsys.CS.BestLap):
  613.                 self.lbl_time_txt.change_font_if_needed().setText(self.format_time(time)).setColor(Colors.tower_time_best_lap_txt(), animated=True, init=True)
  614.             else:
  615.                 self.lbl_time_txt.change_font_if_needed().setText(self.format_time(time)).setColor(Colors.tower_time_last_lap_txt(), animated=True, init=True)
  616.         else:
  617.             if intervals:
  618.                 self.lbl_time_txt.change_font_if_needed().setText("+" + self.format_time(time)).setColor(normal_color, animated=True, init=True)
  619.             else:
  620.                 self.lbl_time_txt.change_font_if_needed().setText(self.format_time(time)).setColor(normal_color, animated=True, init=True)
  621.  
  622.     def optimise(self):
  623.         if len(self.race_gaps) > 132:
  624.             del self.race_gaps[0:len(self.race_gaps) - 132]
  625.  
  626.     def set_position(self, position, offset, battles):
  627.         if not self.isLapLabel:
  628.             self.isInPitLane.setValue(bool(ac.isCarInPitline(self.identifier)))
  629.             self.isInPitBox.setValue(bool(ac.isCarInPit(self.identifier)))
  630.             pit_value = self.isInPitLane.value or self.isInPitBox.value
  631.             self.isInPit.setValue(pit_value)
  632.             if self.race:
  633.                 if self.isInPitBox.hasChanged():
  634.                     if self.isInPitBox.value:
  635.                         self.inPitFromPitLane = self.isInPitLaneOld
  636.                     else:
  637.                         self.inPitFromPitLane = False
  638.                 self.isInPitLaneOld = self.isInPitLane.value
  639.  
  640.         self.position.setValue(position)
  641.         self.position_offset.setValue(offset)
  642.         position_changed = self.position.hasChanged()
  643.         if position_changed or self.position_offset.hasChanged() or self.isCurrentVehicule.hasChanged() or self.isAlive.hasChanged():
  644.             if position_changed:
  645.                 if self.position.value < self.position.old:
  646.                     self.movingUp = True
  647.                 else:
  648.                     self.movingUp = False
  649.                 if self.position.old > 0:
  650.                     self.position_highlight_end = True
  651.             # move labels
  652.             self.num_pos = position - 1 - offset
  653.             self.final_y = self.num_pos * self.rowHeight
  654.             # avoid long slide on first draw
  655.             if not self.firstDraw:
  656.                 if self.isLapLabel:
  657.                     self.lbl_name.setY(self.final_y)
  658.                     self.lbl_name_txt.setY(self.final_y + Font.get_font_x_offset())
  659.                 else:
  660.                     self.lbl_name.setY(self.final_y)
  661.                     self.lbl_name_txt.setY(self.final_y + Font.get_font_x_offset())
  662.                     self.lbl_position.setY(self.final_y)
  663.                     self.lbl_position_txt.setY(self.final_y + Font.get_font_x_offset())
  664.                     self.lbl_pit.setY(self.final_y + 3 + Font.get_font_x_offset())
  665.                     self.lbl_p2p.setY(self.final_y + 5 + Font.get_font_x_offset())
  666.                 self.lbl_time.setY(self.final_y)
  667.                 self.lbl_time_txt.setY(self.final_y + Font.get_font_x_offset())
  668.                 if Colors.border_direction == 1:
  669.                     self.lbl_border.setY(self.final_y)
  670.                 else:
  671.                     self.lbl_border.setY(self.final_y + self.rowHeight - 2)
  672.                 self.firstDraw = True
  673.  
  674.             if self.isLapLabel:
  675.                 self.lbl_name.setY(self.final_y, True)
  676.                 self.lbl_time.setY(self.final_y, True)
  677.                 self.lbl_name_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  678.             else:
  679.                 self.lbl_position_txt.setText(str(self.position.value))
  680.                 self.lbl_name.setY(self.final_y, True)
  681.                 self.lbl_name_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  682.                 self.lbl_position.setY(self.final_y, True)
  683.                 self.lbl_position_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  684.                 self.lbl_pit.setY(self.final_y + Font.get_font_x_offset() + self.rowHeight/10, True)  #  + self.rowHeight/10 +3
  685.                 self.lbl_p2p.setY(self.final_y + Font.get_font_x_offset() + self.rowHeight/8, True)  # + 5
  686.  
  687.             self.lbl_time.setY(self.final_y, True)
  688.             self.lbl_time_txt.setY(self.final_y + Font.get_font_x_offset(), True)
  689.             if Colors.border_direction == 1:
  690.                 self.lbl_border.setY(self.final_y, True)
  691.             else:
  692.                 self.lbl_border.setY(self.final_y + self.rowHeight - 2, True)
  693.             # ------------------- Colors -----------------
  694.             if position % 2 == 1:
  695.                 if not self.isLapLabel:
  696.                     if position == 1 and Colors.tower_first_position_different():
  697.                         self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  698.                         self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  699.                         self.lbl_position.set(background=Colors.tower_position_first_bg(), animated=True, init=True)
  700.                         self.lbl_position_txt.set(color=Colors.tower_position_first_txt(), animated=True, init=True)
  701.                         self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  702.                         self.lbl_time_txt.set(color=Colors.tower_time_odd_txt(), animated=True, init=True)
  703.                         self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  704.                     elif battles and self.isCurrentVehicule.value:
  705.                         self.lbl_name.set(background=Colors.tower_driver_highlight_odd_bg(), animated=True, init=True)
  706.                         self.lbl_name_txt.set(color=Colors.tower_driver_highlight_odd_txt(), animated=True, init=True)
  707.                         self.lbl_position.set(background=Colors.tower_position_highlight_odd_bg(), animated=True, init=True)
  708.                         self.lbl_position_txt.set(color=Colors.tower_position_highlight_odd_txt(), animated=True, init=True)
  709.                         self.lbl_time.set(background=Colors.tower_time_highlight_odd_bg(), animated=True, init=True)
  710.                         self.lbl_time_txt.set(color=Colors.tower_time_highlight_txt(), animated=True, init=True)
  711.                         self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  712.                     else:
  713.                         if self.isAlive.value:
  714.                             self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  715.                             self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  716.                             self.lbl_position.set(background=Colors.tower_position_odd_bg(), animated=True, init=True)
  717.                             self.lbl_position_txt.set(color=Colors.tower_position_odd_txt(), animated=True, init=True)
  718.                             self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  719.                             self.lbl_time_txt.set(color=Colors.tower_time_odd_txt(), animated=True, init=True)
  720.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  721.                         else:
  722.                             self.lbl_name.set(background=Colors.tower_driver_retired_bg(), animated=True, init=True)
  723.                             self.lbl_name_txt.set(color=Colors.tower_driver_retired_txt(), animated=True, init=True)
  724.                             self.lbl_position.set(background=Colors.tower_position_retired_bg(), animated=True, init=True)
  725.                             self.lbl_position_txt.set(color=Colors.tower_position_retired_txt(), animated=True, init=True)
  726.                             self.lbl_time.set(background=Colors.tower_time_retired_bg(), animated=True, init=True)
  727.                             self.lbl_time_txt.set(color=Colors.tower_time_retired_txt(), animated=True, init=True)
  728.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity_retired(), animated=True, init=True)
  729.                 else:
  730.                     self.lbl_name.set(background=Colors.tower_driver_odd_bg(), animated=True, init=True)
  731.                     self.lbl_name_txt.set(color=Colors.tower_driver_odd_txt(), animated=True, init=True)
  732.                     self.lbl_time.set(background=Colors.tower_time_odd_bg(), animated=True, init=True)
  733.                     self.set_time_stint(self.time.value, self.isLapTimeValid)
  734.             else:
  735.                 if not self.isLapLabel:
  736.                     if battles and self.isCurrentVehicule.value:
  737.                         self.lbl_name.set(background=Colors.tower_driver_highlight_even_bg(), animated=True, init=True)
  738.                         self.lbl_name_txt.set(color=Colors.tower_driver_highlight_even_txt(), animated=True, init=True)
  739.                         self.lbl_position.set(background=Colors.tower_position_highlight_even_bg(), animated=True, init=True)
  740.                         self.lbl_position_txt.set(color=Colors.tower_position_highlight_even_txt(), animated=True, init=True)
  741.                         self.lbl_time.set(background=Colors.tower_time_highlight_even_bg(), animated=True, init=True)
  742.                         self.lbl_time_txt.set(color=Colors.tower_time_highlight_txt(), animated=True, init=True)
  743.                         self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  744.                     else:
  745.                         if self.isAlive.value:
  746.                             self.lbl_name.set(background=Colors.tower_driver_even_bg(), animated=True, init=True)
  747.                             self.lbl_name_txt.set(color=Colors.tower_driver_even_txt(), animated=True, init=True)
  748.                             self.lbl_position.set(background=Colors.tower_position_even_bg(), animated=True, init=True)
  749.                             self.lbl_position_txt.set(color=Colors.tower_position_even_txt(), animated=True, init=True)
  750.                             self.lbl_time.set(background=Colors.tower_time_even_bg(), animated=True, init=True)
  751.                             self.lbl_time_txt.set(color=Colors.tower_time_even_txt(), animated=True, init=True)
  752.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity(), animated=True, init=True)
  753.                         else:
  754.                             self.lbl_name.set(background=Colors.tower_driver_retired_bg(), animated=True, init=True)
  755.                             self.lbl_name_txt.set(color=Colors.tower_driver_retired_txt(), animated=True, init=True)
  756.                             self.lbl_position.set(background=Colors.tower_position_retired_bg(), animated=True, init=True)
  757.                             self.lbl_position_txt.set(color=Colors.tower_position_retired_txt(), animated=True, init=True)
  758.                             self.lbl_time.set(background=Colors.tower_time_retired_bg(), animated=True, init=True)
  759.                             self.lbl_time_txt.set(color=Colors.tower_time_retired_txt(), animated=True, init=True)
  760.                             self.lbl_border.set(opacity=Colors.tower_border_default_bg_opacity_retired(), animated=True, init=True)
  761.                 else:
  762.                     self.lbl_name.set(background=Colors.tower_driver_even_bg(), animated=True, init=True)
  763.                     self.lbl_name_txt.set(color=Colors.tower_driver_even_txt(), animated=True, init=True)
  764.                     self.lbl_time.set(background=Colors.tower_time_even_bg(), animated=True, init=True)
  765.                     self.set_time_stint(self.time.value, self.isLapTimeValid)
  766.  
  767.         if not self.isLapLabel:
  768.             self.fullName.setValue(ac.getDriverName(self.identifier))
  769.             if self.fullName.hasChanged():
  770.                 # Reset
  771.                 self.finished.setValue(False)
  772.                 self.set_name()
  773.                 self.race_current_sector.setValue(0)
  774.                 self.race_standings_sector.setValue(0)
  775.                 self.race_gaps = []
  776.                 self.completedLaps.setValue(0)
  777.                 self.completedLapsChanged = False
  778.                 self.last_lap_visible_end = 0
  779.                 self.time_highlight_end = 0
  780.                 self.bestLap = 0
  781.                 self.bestLapServer = 0
  782.                 self.position_highlight_end = 0
  783.                 self.inPitFromPitLane = False
  784.                 self.hasStartedRace = False
  785.                 self.isInPitBox.setValue(False)
  786.  
  787.     def format_name_tlc(self, name):
  788.         space = name.find(" ")
  789.         if space > 0:
  790.             name = name[space:]
  791.         name = name.strip().upper()
  792.         if len(name) > 2:
  793.             return name[:3]
  794.         return name
  795.  
  796.     def format_name_tlc2(self, name):
  797.         first = ""
  798.         if len(name) > 0:
  799.             first = name[0].upper()
  800.         space = name.find(" ")
  801.         if space > 0:
  802.             name = name[space:]
  803.         name = name.strip().upper()
  804.         if len(name) > 2 and len(first) > 0:
  805.             return first + name[:2]
  806.         if len(name) > 2:
  807.             return name[:3]
  808.         return name
  809.  
  810.     def format_last_name(self, name):
  811.         space = name.find(" ")
  812.         if space > 0:
  813.             name = name[space:]
  814.         name = name.strip().upper()
  815.         if len(name) > 9:
  816.             return name[:10]
  817.         return name
  818.  
  819.     def format_last_name2(self, name):
  820.         first = ""
  821.         if len(name) > 0:
  822.             first = name[0].upper()
  823.         space = name.find(" ")
  824.         if space > 0:
  825.             name = first + "." + name[space:]
  826.         name = name.strip().upper()
  827.         if len(name) > 9:
  828.             return name[:10]
  829.         return name
  830.  
  831.     def format_first_name(self, name):
  832.         space = name.find(" ")
  833.         if space > 0:
  834.             name = name[:space]
  835.         name = name.strip().upper()
  836.         if len(name) > 9:
  837.             return name[:10]
  838.         return name
  839.  
  840.     def format_time(self, ms):
  841.         s = ms / 1000
  842.         m, s = divmod(s, 60)
  843.         h, m = divmod(m, 60)
  844.         # d,h=divmod(h,24)
  845.         d = ms % 1000
  846.         if math.isnan(s) or math.isnan(d) or math.isnan(m) or math.isnan(h):
  847.             return ""
  848.         if h > 0:
  849.             return "{0}:{1}:{2}.{3}".format(int(h), str(int(m)).zfill(2), str(int(s)).zfill(2), str(int(d)).zfill(3))
  850.         elif m > 0:
  851.             return "{0}:{1}.{2}".format(int(m), str(int(s)).zfill(2), str(int(d)).zfill(3))
  852.         else:
  853.             return "{0}.{1}".format(int(s), str(int(d)).zfill(3))
  854.  
  855.     def is_compact_mode(self):
  856.         if self.isLapLabel:
  857.             return False
  858.         if not self.race and self.compact_mode and not self.highlight.value:
  859.             return True
  860.         if self.race and self.compact_mode:
  861.             return True
  862.         return False
  863.  
  864.     def get_name_width(self):
  865.         # Name
  866.         if self.showingFullNames and not self.isLapLabel:  # Configuration.names >= 2:
  867.             name_width = 5.2
  868.         else:
  869.             name_width = 2.1
  870.         # Position
  871.         if self.isLapLabel:
  872.             return self.rowHeight * name_width + self.rowHeight # + 4
  873.         # Time
  874.         #if not self.is_compact_mode():
  875.         #    name_width += 3.1
  876.         # Pit and P2P
  877.         if self.is_compact_mode():
  878.             if self.isInPit.value and not self.finished.value:
  879.                 if self.is_compact_mode() or not self.race:
  880.                     name_width += 0.6
  881.             elif self.push_2_pass_status.value > 0 and not self.finished.value:
  882.                 name_width += 0.6
  883.         return self.rowHeight * name_width
  884.  
  885.     def get_time_width(self):
  886.         if self.is_compact_mode():
  887.             return 0
  888.         # Time
  889.         name_width = 3.1
  890.         if self.isLapLabel:
  891.             return self.rowHeight * name_width
  892.         # Pit and P2P
  893.         if self.isInPit.value and not self.finished.value:
  894.             if not self.race:
  895.                 name_width += 0.6
  896.         elif self.push_2_pass_status.value > 0 and not self.finished.value:
  897.             name_width += 0.6
  898.         return self.rowHeight * name_width
  899.  
  900.     def get_pit_x(self):
  901.         # Name
  902.         if self.showingFullNames:  # Configuration.names >= 2:
  903.             pit_x = 6.2
  904.         else:
  905.             pit_x = 3.1
  906.         # Time
  907.         if not self.is_compact_mode():
  908.             pit_x += 3.1
  909.         if Colors.border_direction == 1:
  910.             pit_offset = 7
  911.         else:
  912.             pit_offset = 4
  913.         return self.rowHeight * pit_x + pit_offset
  914.  
  915.     def animate(self, session_time_left):
  916.         if session_time_left == -1:
  917.             self.time_highlight_end = 0
  918.         if not self.isLapLabel:
  919.             # Anything that needs live changes
  920.             if self.isDisplayed:
  921.                 self.cur_theme.setValue(Colors.general_theme)
  922.                 # Push 2 Pass
  923.                 self.push_2_pass_status.setValue(ac.getCarState(self.identifier, acsys.CS.P2PStatus))
  924.                 if self.push_2_pass_status.value > 0:  # OFF = 0
  925.                     self.push_2_pass_left.setValue(ac.getCarState(self.identifier, acsys.CS.P2PActivations))
  926.                     if self.push_2_pass_status.hasChanged() or self.cur_theme.hasChanged():
  927.                         if self.push_2_pass_status.value == 1:  # COOLING = 1
  928.                             self.lbl_p2p.setColor(Colors.tower_p2p_cooling(), animated=True, init=True)
  929.                         elif self.push_2_pass_status.value == 2:  # AVAILABLE = 2
  930.                             self.lbl_p2p.setColor(Colors.tower_p2p_txt(), animated=True, init=True)
  931.                         elif self.push_2_pass_status.value == 3:  # ACTIVE = 3
  932.                             self.lbl_p2p.setColor(Colors.tower_p2p_active(), animated=True, init=True)
  933.                     if self.push_2_pass_left.hasChanged():
  934.                         self.lbl_p2p.setText(str(self.push_2_pass_left.value))
  935.                 self.highlight.setValue(self.time_highlight_end != 0 and self.time_highlight_end < session_time_left)
  936.                 if Colors.border_direction == 1:
  937.                     border_offset = 8
  938.                 else:
  939.                     border_offset = 4
  940.                 if not self.race and self.isDisplayed:
  941.                     if self.highlight.hasChanged():
  942.                         if self.highlight.value:
  943.                             self.lbl_time_txt.setColor(Colors.tower_time_qualification_highlight_txt(), animated=True, init=True)
  944.                             self.lbl_time_txt.show()
  945.                         else:
  946.                             if self.position.value % 2 == 1:
  947.                                 self.lbl_time_txt.setColor(Colors.tower_time_odd_txt(), animated=True, init=True)
  948.                             else:
  949.                                 self.lbl_time_txt.setColor(Colors.tower_time_even_txt(), animated=True, init=True)
  950.  
  951.                             if self.is_compact_mode():
  952.                                 self.lbl_time.hide()
  953.                                 self.lbl_time_txt.hide()
  954.                             else:
  955.                                 self.lbl_time.show()
  956.                                 self.lbl_time_txt.show()
  957.                     self.lbl_name.set(w=self.get_name_width(), animated=True)
  958.                     self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated=True)
  959.                     self.lbl_pit.setX(self.get_pit_x(), True)
  960.                 elif self.race and self.isDisplayed:
  961.                     if self.is_compact_mode() and self.isInPit.value and self.isDisplayed and self.isAlive.value and not self.finished.value:
  962.                         self.lbl_pit.setX(self.get_pit_x(), True)
  963.                         self.lbl_pit.setColor(Colors.tower_pit_txt(), animated=True, init=True)
  964.                         self.lbl_pit.show()
  965.                     else:
  966.                         self.lbl_pit.hide()
  967.                     self.lbl_name.set(w=self.get_name_width(), animated=True)
  968.                     self.lbl_time.set(w=self.get_time_width(), x=self.rowHeight + border_offset + self.get_name_width(), animated=True)
  969.             # not isLapLabel
  970.             self.lbl_position.animate()
  971.             self.lbl_position_txt.animate()
  972.             self.lbl_pit.animate()
  973.             self.lbl_p2p.animate()
  974.         self.lbl_border.animate()
  975.         self.lbl_time.animate()
  976.         self.lbl_time_txt.animate()
  977.         self.lbl_name.animate()
  978.         self.lbl_name_txt.animate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement