def setHighlight(item): global uihighlight # dehighlight the old one ac.setBackgroundColor(uihighlight, 0.5, 0.5, 0.5) ac.drawBackground(uihighlight, 0) # set the new one uihighlight = item ac.setBackgroundColor(uihighlight, 1, 0, 0) ac.drawBackground(uihighlight, 1)
def animate(self): #adjust size +1 self.adjustParam("w").adjustParam("h") #adjust position +3 self.adjustParam("x").adjustParam("y") #adjust background self.adjustParam("br").adjustParam("bg").adjustParam("bb").adjustParam("o") #adjust colors + 0.02 self.adjustParam("r").adjustParam("g").adjustParam("b").adjustParam("a") #commit changes if self.params["x"].hasChanged() or self.params["y"].hasChanged(): ac.setPosition(self.label, self.params["x"].value, self.params["y"].value) if self.params["w"].hasChanged() or self.params["h"].hasChanged(): ac.setSize(self.label, self.params["w"].value, self.params["h"].value) if self.params["h"].value == 0: self.isVisible.setValue(False) else: self.isVisible.setValue(True) if self.params["br"].hasChanged() or self.params["bg"].hasChanged() or self.params["bb"].hasChanged(): ac.setBackgroundColor(self.label, self.params["br"].value, self.params["bg"].value, self.params["bb"].value) if self.f_params["o"].value > 0: ac.setBackgroundOpacity(self.label, self.params["o"].value) if self.params["o"].hasChanged(): if self.params["o"].value == 0: self.isVisible.setValue(False) else: self.isVisible.setValue(True) changed=self.isVisible.hasChanged() if changed and self.params["o"].value > 0: self.setVisible(1) elif changed: self.setVisible(0) #fg opacity ac.setBackgroundOpacity(self.label, self.params["o"].value) if self.params["o"].value >= 0.4 : self.isTextVisible.setValue(True) else: self.isTextVisible.setValue(False) if self.isTextVisible.hasChanged(): if self.isTextVisible.value: ac.setText(self.label, self.text) else: ac.setText(self.label, "") if self.params["r"].hasChanged() or self.params["g"].hasChanged() or self.params["b"].hasChanged() or self.params["a"].hasChanged(): ac.setFontColor(self.label, self.params["r"].value, self.params["g"].value, self.params["b"].value, self.params["a"].value) if self.params["a"].value == 0: self.isVisible.setValue(False) else: self.isVisible.setValue(True) changed=self.isVisible.hasChanged() if changed and self.params["a"].value > 0: self.setVisible(1) elif changed: self.setVisible(0)
def reinitialize(self): ac.setTitle(self.data.app_id, "") self.hide_app_background() ac.drawBorder(self.data.app_id, 0) ac.setIconPosition(self.data.app_id, 0, -10000) ac.setSize(self.data.app_id, config.APP_WIDTH, config.APP_HEIGHT) # Click on app area handling - used for toggling modes if not hasattr(self.data, 'click_label'): self.data.click_label = ac.addLabel(self.data.app_id, '') ac.addOnClickedListener(self.data.click_label, sys.modules['deltabar'].onClick) ac.setPosition(self.data.click_label, 0, 0) ac.setSize(self.data.click_label, config.APP_WIDTH, config.APP_HEIGHT) # Delta bar main area if not hasattr(self.data, 'bar_area'): self.data.bar_area = ac.addLabel(self.data.app_id, '') ac.setPosition(self.data.bar_area, config.BAR_CORNER_RADIUS, 0) ac.setSize(self.data.bar_area, config.BAR_WIDTH - 2 * config.BAR_CORNER_RADIUS, config.BAR_HEIGHT) ac.setBackgroundColor(self.data.bar_area, *config.BACKGROUND_COLOR.rgb) ac.setBackgroundOpacity(self.data.bar_area, config.BACKGROUND_COLOR.alpha) # Delta label background area if not hasattr(self.data, 'delta_label_area'): self.data.delta_label_area = ac.addLabel(self.data.app_id, '') ac.setPosition(self.data.delta_label_area, config.BAR_WIDTH_HALF - config.DELTA_LABEL_WIDTH_HALF, config.DELTA_LABEL_Y) ac.setSize(self.data.delta_label_area, config.DELTA_LABEL_WIDTH, config.DELTA_LABEL_HEIGHT) ac.setBackgroundTexture(self.data.delta_label_area, 'apps/python/deltabar/background_delta.png') # Delta label text if not hasattr(self.data, 'delta_label'): self.data.delta_label = ac.addLabel(self.data.app_id, '') ac.setPosition(self.data.delta_label, config.BAR_WIDTH_HALF - config.DELTA_LABEL_WIDTH_HALF, config.DELTA_LABEL_TEXT_Y) ac.setSize(self.data.delta_label, config.DELTA_LABEL_WIDTH, config.DELTA_LABEL_FONT_SIZE) ac.setFontAlignment(self.data.delta_label, 'center') ac.setFontSize(self.data.delta_label, config.DELTA_LABEL_FONT_SIZE) # Banner label (displays current selected mode) if not hasattr(self.data, 'banner_label'): self.data.banner_label = ac.addLabel(self.data.app_id, '') ac.setPosition(self.data.banner_label, config.BAR_WIDTH_HALF - config.BANNER_TEXT_WIDTH / 2, config.BANNER_Y) ac.setSize(self.data.banner_label, config.BANNER_TEXT_WIDTH, config.BANNER_FONT_SIZE) ac.setFontAlignment(self.data.banner_label, 'center') ac.setFontSize(self.data.banner_label, config.BANNER_FONT_SIZE) ac.setFontColor(self.data.banner_label, *config.SLOW_COLOR.rgba)
def setBgColor(self, color, animated=False): self.f_params["br"].setValue(color[0]) self.f_params["bg"].setValue(color[1]) self.f_params["bb"].setValue(color[2]) if not animated: self.o_params["br"].setValue(color[0]) self.o_params["bg"].setValue(color[1]) self.o_params["bb"].setValue(color[2]) self.params["br"].setValue(color[0]) self.params["bg"].setValue(color[1]) self.params["bb"].setValue(color[2]) ac.setBackgroundColor(self.label, *color) if self.f_params["o"].value > 0: ac.setBackgroundOpacity(self.label, self.params["o"].value) return self
def background_color(self, background_color: Color): self._background_color = background_color if not self.background: self.background = background_color.a > 0 or self.background_texture if self.has_id: c = background_color success = ac.setBackgroundColor( self.id, c.r, c.g, c.b) == 1 and ac.setBackgroundOpacity( self.id, c.a) == 1 if not success: console('{}: Background color could not be set.'.format(self))
def acUpdate(deltaT): global timer0, timer1 global tyreLabels, tyrePressureLabels global drsLabel, ersLabel, ersModeLabel, ersRecoveryLabel, fuelLabel, drsPenaltyLabel, drsPenaltyBackgroundLabel global carValue, trackConfigValue, trackValue global currentLapValue, lapValue, previousLapValue, carWasInPit global totalDrivers, trackLength, driversList, totalPenalty, soundPlaying, drsAvailableZones, currentDrsZone, drsPenaltyAwardedInZone, lastTime global tyreCompoundShort, tyreCompoundCleaned, previousTyreCompoundValue, minimumOptimalTemperature, maximumOptimalTemperature, idealPressureFront, idealPressureRear global tyreTemperatureValue, tyreTemperatureValueI, tyreTemperatureValueM, tyreTemperatureValueO, tyrePressureValue, tyreCompoundValue global temperatureTransitionRange, tyrePracticalTemperatureValue global fuelAmountValue, fuelStartValue, relevantLapsNumber, fuelSpentValue, fuelPerLapValue global compounds, modCompounds timer0 += deltaT timer1 += deltaT # Once per second if timer0 > 1: timer0 = 0 # ================================================================================================================= # GET A BUNCH OF INFO # ================================================================================================================= tyreCompoundValue = info.graphics.tyreCompound tyreTemperatureValue = info.physics.tyreCoreTemperature tyreTemperatureValueI = info.physics.tyreTempI tyreTemperatureValueM = info.physics.tyreTempM tyreTemperatureValueO = info.physics.tyreTempO tyrePressureValue = info.physics.wheelsPressure fuelAmountValue = info.physics.fuel if ac.isCarInPitline(0): carWasInPit = 1 # ================================================================================================================= # SET IDEAL TYRE PRESSURES AND TEMPERATURES # ================================================================================================================= if previousTyreCompoundValue != tyreCompoundValue: previousTyreCompoundValue = tyreCompoundValue tyreCompoundShort = tyreCompoundValue[tyreCompoundValue.find("(") + 1:tyreCompoundValue.find(")" )] tyreCompoundCleaned = re.sub( '\_+$', '', re.sub(r'[^\w]+', '_', tyreCompoundValue)).lower() if compounds.has_section(carValue + "_" + tyreCompoundCleaned): try: idealPressureFront = int( compounds.get(carValue + "_" + tyreCompoundCleaned, "IDEAL_PRESSURE_F")) idealPressureRear = int( compounds.get(carValue + "_" + tyreCompoundCleaned, "IDEAL_PRESSURE_R")) minimumOptimalTemperature = int( compounds.get(carValue + "_" + tyreCompoundCleaned, "MIN_OPTIMAL_TEMP")) maximumOptimalTemperature = int( compounds.get(carValue + "_" + tyreCompoundCleaned, "MAX_OPTIMAL_TEMP")) except: ac.console("Error loading tyre data.") elif modCompounds.has_section(carValue + "_" + tyreCompoundCleaned): try: idealPressureFront = int( modCompounds.get(carValue + "_" + tyreCompoundCleaned, "IDEAL_PRESSURE_F")) idealPressureRear = int( modCompounds.get(carValue + "_" + tyreCompoundCleaned, "IDEAL_PRESSURE_R")) minimumOptimalTemperature = int( float( modCompounds.get( carValue + "_" + tyreCompoundCleaned, "MIN_OPTIMAL_TEMP"))) maximumOptimalTemperature = int( float( modCompounds.get( carValue + "_" + tyreCompoundCleaned, "MAX_OPTIMAL_TEMP"))) # ac.console("Tyres: {}, {}psi/{}psi, {}°C-{}°C".format(tyreCompoundValue, idealPressureFront, idealPressureRear, minimumOptimalTemperature, maximumOptimalTemperature)) except: ac.console("Error loading mod tyre data.") else: ac.console( "Tyres: {}, no data found".format(tyreCompoundValue)) # 10 times per second if timer1 > 0.1: timer1 = 0 currentLapValue = info.graphics.iCurrentTime lapValue = ac.getCarState(0, acsys.CS.LapCount) lapProgressValue = ac.getCarState(0, acsys.CS.NormalizedSplinePosition) # ================================================================================================================= # DRS # ================================================================================================================= drsAvailableValue = ac.getCarState(0, acsys.CS.DrsAvailable) drsEnabledValue = ac.getCarState(0, acsys.CS.DrsEnabled) # ================================================================================================================= # DRS SIMPLE (not races) # ================================================================================================================= if info.graphics.session != 2 and ac.getCarName(0) in DRS_ALLOWED_CARS: if drsEnabledValue: set_drs_good() elif drsAvailableValue: set_drs_available() if not soundPlaying and SOUND_ON: # use this variable to control drs beep at begining of drs sound_player.play(audio) sound_player.stop() soundPlaying = True else: soundPlaying = False ac.setVisible(drsLabel, 0) # ================================================================================================================= # DRS DATA COLLECTION # ================================================================================================================= if info.graphics.session == 2 and ac.getCarName(0) in DRS_ALLOWED_CARS: crossedDetectionZone = -1 crossedEndZone = -1 crossedStartZone = -1 curTime = time.time() for i in range(totalDrivers): spline = ac.getCarState(i, acsys.CS.NormalizedSplinePosition) for zid, zone in enumerate(drsZones): if driver_crossed_zone(driversList[i].last_pos, zone['detection'], spline): driversList[i].drs_detection_times[zid] = curTime if i == 0: # current driver crossedDetectionZone = zid # mark zone crossed by driver (not possible to cross multiple zone) if i == 0 and driver_crossed_zone(driversList[i].last_pos, zone['end'], spline): crossedEndZone = zid if i == 0 and driver_crossed_zone(driversList[i].last_pos, zone['start'], spline): crossedStartZone = zid driversList[i].last_pos = spline # ================================================================================================================= # DRS ALLOWANCE MANAGEMENT # ================================================================================================================= # Race Restart if info.graphics.completedLaps == 0 and info.graphics.iCurrentTime == 0: totalPenalty = 0 # reset penalty set_drs_penalty(0) # DRS DETECTION Zone crossed if crossedDetectionZone != -1: if info.graphics.completedLaps + 1 >= DRS_STARTS_ON_LAP: # if this is a valid lap ac.log("Checking Detection Zone: " + str(crossedDetectionZone) + " on lap: " + str(info.graphics.completedLaps)) # check if there is any driver within DRS_GAP if any(driversList[0]. drs_detection_times[crossedDetectionZone] - driver.drs_detection_times[crossedDetectionZone] <= DRS_GAP and driversList[0]. drs_detection_times[crossedDetectionZone] - driver. drs_detection_times[crossedDetectionZone] >= 0 for driver in driversList[1:]): set_drs_possible() drsAvailableZones[crossedDetectionZone] = True # DRS END Zone crossed if crossedEndZone != -1: drsAvailableZones[crossedEndZone] = False currentDrsZone = -1 drsPenaltyAwardedInZone = False # if next zone allows for drs already -- for cases where 1 DRS detection is used in 2 zones if drsAvailableZones[(crossedEndZone + 1) % len(drsAvailableZones)]: set_drs_possible() set_drs_hidden() # DRS START Zone crossed if crossedStartZone != -1: currentDrsZone = crossedStartZone # IN DRS ZONE if drsAvailableValue: if drsAvailableZones[currentDrsZone]: if drsEnabledValue: set_drs_good() else: set_drs_available() if totalPenalty > 0: totalPenalty -= curTime - lastTime set_drs_penalty(totalPenalty) else: if drsEnabledValue: set_drs_bad() if not drsPenaltyAwardedInZone: drsPenaltyAwardedInZone = True announcePenalty( ac.getDriverName(0), info.graphics.completedLaps + 1, "Illegal DRS use, Zone %d" % (currentDrsZone)) # Add penalty amount if abs(curTime - lastTime) < 1: totalPenalty += curTime - lastTime set_drs_penalty(totalPenalty) else: set_drs_hidden() # end of drs update save current values into lasts lastTime = curTime # ================================================================================================================= # ERS LABEL # ================================================================================================================= ersRecoveryLevel = info.physics.ersRecoveryLevel ersMode = info.physics.ersPowerLevel ac.setText(ersModeLabel, "🗲{}".format(ersMode)) ac.setText(ersRecoveryLabel, "↺{}".format(ersRecoveryLevel)) ac.setFontColor(ersModeLabel, *ERS_COLORS[ersMode]) ac.setFontColor(ersLabel, *ERS_COLORS[ersMode]) ac.setFontColor(ersRecoveryLabel, *ERS_COLORS[ersMode]) # ================================================================================================================= # FUEL LABEL # ================================================================================================================= if fuelPerLapValue: ac.setText( fuelLabel, "💧 {:.1f} Laps".format(fuelAmountValue / fuelPerLapValue)) # ================================================================================================================= # TYRE TEMPERATURES # ================================================================================================================= for i in range(4): tyrePracticalTemperatureValue[i] = 0.25 * ( (tyreTemperatureValueI[i] + tyreTemperatureValueM[i] + tyreTemperatureValueO[i]) / 3) + 0.75 * tyreTemperatureValue[i] for i, label in enumerate(tyreLabels): # ac.setText(label, "{:.0f}".format(tyrePracticalTemperatureValue[i])) if minimumOptimalTemperature and maximumOptimalTemperature: if int(round(tyrePracticalTemperatureValue[i]) ) >= minimumOptimalTemperature and int( round(tyrePracticalTemperatureValue[i]) ) <= maximumOptimalTemperature: ac.setBackgroundColor(label, 0.17, 1, 0) elif int(round(tyrePracticalTemperatureValue[i]) ) < minimumOptimalTemperature: idealTemperatureDifference = min( temperatureTransitionRange, minimumOptimalTemperature - tyrePracticalTemperatureValue[i] ) / temperatureTransitionRange ac.setBackgroundColor( label, max(0, 0.17 - idealTemperatureDifference / 5.88), max(0.51, 1 - idealTemperatureDifference / 1.96), min(1, 0 + idealTemperatureDifference)) elif int(round(tyrePracticalTemperatureValue[i]) ) > maximumOptimalTemperature: idealTemperatureDifference = min( temperatureTransitionRange, tyrePracticalTemperatureValue[i] - maximumOptimalTemperature) / temperatureTransitionRange ac.setBackgroundColor( label, min(1, 0.17 + idealTemperatureDifference / 0.83), max(0.17, 1 - idealTemperatureDifference / 0.83), 0) else: ac.setBackgroundOpacity(label, 0) ac.setBackgroundOpacity( label, 1 ) # background colors start to hyde for some reason so this is needed for i, label in enumerate(tyrePressureLabels): if idealPressureFront and idealPressureRear: if i < 2: # front ac.setText( label, "{:+.1f}".format(tyrePressureValue[i] - idealPressureFront)) else: # rear ac.setText( label, "{:+.1f}".format(tyrePressureValue[i] - idealPressureRear)) else: ac.setText(label, "{:.0f}".format(tyrePressureValue[i])) # ================================================================================================================= # CALCULATE AT LAP ENDING OR LAP START # ================================================================================================================= #Display/calculate on lap start if currentLapValue > 500 and currentLapValue < 1000: carWasInPit = 0 fuelStartValue = fuelAmountValue #Display/calculate on lap finish if previousLapValue < lapValue: # announce any penalty at the end of a lap if totalPenalty > 0: announceTotalPenalty(ac.getDriverName(0), info.graphics.completedLaps + 1) previousLapValue = lapValue #Fuel per lap if fuelAmountValue < fuelStartValue and not carWasInPit: relevantLapsNumber += 1 fuelSpentValue += fuelStartValue - fuelAmountValue fuelPerLapValue = fuelSpentValue / relevantLapsNumber
def setBgColor(self, color): ac.setBackgroundColor(self.label, *color) return self
def update(self): ac.setBackgroundColor(self.app, self._bg.r, self._bg.g, self._bg.b) ac.setBackgroundOpacity(self.app, self._bg.a)
def setBgColor(self, color, animated=False): ac.setBackgroundColor(self.button, *color) #ac.setBackgroundOpacity(self.label, self.params["o"].value) return self
def bg_color(self, value): self._bg_color = value ac.setBackgroundColor(self.id, *value)
def setBgColor(self, color): ac.setBackgroundColor(self.label_id, *color) return self
def update(self): ac.setBackgroundColor(self.app, 0, 0, 0) ac.setBackgroundOpacity(self.app, 0) ac.setBackgroundTexture(self.app, "apps/python/ACRM/acrm.png")
def changeElementBgColor(element, Bgr, Bgb, Bgg): ac.setBackgroundColor(element, Bgr, Bgb, Bgg) ac.setBackgroundOpacity(element, 1) ac.drawBackground(element, 1)