def _createFooterButtons(self, root): modLabel = Label(self.window) removeBorders(modLabel) Color.paintDark(modLabel) modLabel.grid(column=0,row=self.currentRow, sticky='nswe', columnspan=4) self.currentRow += 1 button = tk.Button(self.window, text="Savegame Config") removeBorders(button) Color.paintDark(button) button.grid(column=0,row=self.currentRow, sticky='sw') if self.config.hasValue("linux-tweaks"): linuxTweaks = lambda: SettingWindow(self.window, self.game, self.config) button = tk.Button(self.window, text="Linux Tweaks", command=linuxTweaks) else: button = tk.Button(self.window, text="Linux Tweaks") removeBorders(button) Color.paintDark(button) button.grid(column=1,row=self.currentRow, sticky='sw') button = tk.Button(self.window, text="Game Tools") removeBorders(button) Color.paintDark(button) button.grid(column=2,row=self.currentRow, sticky='sw') button = tk.Button(self.window, text="Game Info") removeBorders(button) Color.paintDark(button) button.grid(column=3,row=self.currentRow, sticky='sw')
def createButton(root, game, data): runFunction = getRunFunction(game, data) try: gameImage = getImageOrException(game) gameButton = tk.Button(root, text=game, image=gameImage, command=runFunction) removeBorders(gameButton) Color.paintDark(gameButton) gameButton.image = gameImage except AssetException: gameButton = createButtonWithoutImage(root, game, data) return gameButton
def __init__(self, data: ACData = None, meta: ACMeta = None): super().__init__('ACLIB Comparator', 200, 200, 300, 55, True) self.hide_decoration() self.background_color = Color(0.1, 0.1, 0.1, 0.5) self._data = data self._meta = meta self._mode = 0 self._opponents = [] self._grid = ACGrid(12, 11, self) self._header = CR_Header(self._grid, 'Lap Time') self._left = CR_Icon(self._grid, Comparator.TEXTURES['left']) self._right = CR_Icon(self._grid, Comparator.TEXTURES['right']) self._add = CR_Button(self._grid, 'Add Opponent') self._remove = CR_Button(self._grid, 'Remove Opponent') self._grid.add(self._left, 0, 0, 1, 6) self._grid.add(self._header, 1, 0, 10, 6) self._grid.add(self._right, 11, 0, 1, 6) self._grid.add(self._add, 0, 6, 6, 5) self._grid.add(self._remove, 6, 6, 6, 5) self._left.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_left) self._right.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_right) #self._add.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_add) #self._remove.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_remove) self._add_opponent(0) self._add_opponent(1)
def donut(x: int, y: int, r: int, w: int, start: int = 0, stop: int = 360, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) sample = (stop - start) / (36 * r) while start <= stop: rad1 = start rad2 = min(start + 1, stop) ac.glVertex2f(x + cos(rad1) * r, y - sin(rad1) * r) ac.glVertex2f(x + cos(rad2) * r, y - sin(rad2) * r) ac.glVertex2f(x + cos(rad1) * (r - w), y - sin(rad1) * (r - w)) ac.glVertex2f(x + cos(rad2) * (r - w), y - sin(rad2) * (r - w)) if filled: ac.glVertex2f(x + cos(rad2) * r, y - sin(rad2) * r) ac.glVertex2f(x + cos(rad1) * (r - w), y - sin(rad1) * (r - w)) start += sample ac.glEnd()
def circle(x: int, y: int, radius: int, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) start = 0 stop = 360 sample = 36 * radius while start <= stop: rad1 = start rad2 = min(start + 1, stop) ac.glVertex2f(x + cos(rad1) * radius, y - sin(rad1) * radius) ac.glVertex2f(x + cos(rad2) * radius, y - sin(rad2) * radius) if filled: ac.glVertex2f(x, y) start += sample ac.glEnd()
def on_min(self, km: int): if not self._monitor: return self._min_fuel_avg = self.avg(self._min_fuel_avg, self._min_fuel_ref) self._min_fuel_ref = self.fuel enough_for = self.enough_for(self._min_fuel_avg) self._avg_min.text = 'Ø {:2.1f} l/min'.format(self._min_fuel_avg) self._min.text = '+ {:2.1f} min'.format(enough_for) # if self._data.session.session == Type.RACE: if enough_for < self.race_dist_left(): self._min.background_color = Color(1, 0, 0, 1) else: self._min.background_color = Color(0, 0, 0, 0)
def on_lap(self, lap: int): if not self._monitor: self._monitor = True return self._lap_fuel_avg = self.avg(self._lap_fuel_avg, self._lap_fuel_ref) self._lap_fuel_ref = self.fuel enough_for = self.enough_for(self._lap_fuel_avg) self._avg_lap.text = 'Ø {:2.1f} l/L'.format(self._lap_fuel_avg) self._lap.text = '+ {:2.1f} L'.format(enough_for) #if self._data.session.session == Type.RACE: if enough_for < self.race_dist_left(): self._lap.background_color = Color(1, 0, 0, 1) else: self._lap.background_color = Color(0, 0, 0, 0)
def polygon(points, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glBegin(2) else: ac.glBegin(1) for i in points: if isinstance(i, Vec2i): ac.glVertex2f(i.x, i.y) ac.glEnd()
def _createButtons(self, root, game, data): if "linux-tweaks" in data: detailData = data['linux-tweaks'] for index, content in enumerate(detailData): if "title" in detailData[content]: spaceItem = Label(self.window) spaceItem.config(font=("Impact", 15)) Color.paint(spaceItem) self._addWidget(spaceItem) itemTitle = Label(self.window, text=detailData[content]["title"]) Color.paint(itemTitle) itemTitle.config(font=("Impact", 15)) self._addWidget(itemTitle) runFunction = getRunFunction(game, detailData[content]) button = tk.Button(self.window, text=content, command=runFunction) removeBorders(button) Style.styleButton(button) self._addWidget(button) if "description" in detailData[content]: itemDescription = Label( self.window, text=detailData[content]["description"]) Color.paint(itemDescription) self._addWidget(itemDescription)
def __init__(self, parent=None): super().__init__() self._db_click_timer = 0.0 self._db_click_timeout = 0.3 # 500 ms self._mouse_down = False # Properties self._id = -1 self._timer = 0 self._timer_callback = None self._update_timer = 0.0 self._render_timer = 0.0 self._parent = parent self._child = None self._position = Point(0, 0) self._size = Size(0, 0) self._no_update = False self._no_render = False self._visible = True self._background = False self._border = False self._background_texture = '' self._background_color = Color(0.0, 0.0, 0.0, 0.0) self._border_color = Color(0.0, 0.0, 0.0, 0.0) self._active_animation = None self._animation_queue = [] # Event listeners self.on(ACWidget.EVENT.PARENT_CHANGED, self._on_parent_changed) self.on(ACWidget.EVENT.POSITION_CHANGED, self._on_position_changed) self.on(ACWidget.EVENT.SIZE_CHANGED, self._on_size_changed) self.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_mouse_down) self.on(ACWidget.EVENT.ON_MOUSE_UP, self._on_mouse_up) self.on(ACWidget.EVENT.VISIBILITY_CHANGED, self._on_visibility_changed)
def __init__(self, parent: ACWidget, data: ACData, meta: ACMeta): super().__init__(12, 2, parent) self.background_color = Color(0, 0, 0, 0.5) self._data = data self._meta = meta self._mode = 0 self._index = 0 self._player = self._data.players[self._index] self._server = self._data.server self._sec_format = '{s:02d}.{ms:03d}' self._on_player_lap_changed_callback_id = None self._label = CR_Name(self, self._player.name) self._label.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._focus_player) self._multi = ACMultiWidget(self) self._laps = ACHBox(self) self._bst = CR_Label(self._laps, 'BST: --:--:---') self._lst = CR_Label(self._laps, 'LST: --:--:---') self._sector_box = ACHBox(self) self._sectors = [] self._sectors.append(CR_Label(self._sector_box, 'S1: --:---')) self._sectors.append(CR_Label(self._sector_box, 'S2: --:---')) self._sectors.append(CR_Label(self._sector_box, 'S3: --:---')) self._left = CR_Icon(self, ComparatorRow.TEXTURES['left']) self._right = CR_Icon(self, ComparatorRow.TEXTURES['right']) self._laps.add(self._bst) self._laps.add(self._lst) self._sector_box.add(self._sectors[0]) self._sector_box.add(self._sectors[1]) self._sector_box.add(self._sectors[2]) self._multi.add(self._laps) self._multi.add(self._sector_box) self.add(self._left, 0, 0) self.add(self._label, 1, 0, 10, 1) self.add(self._right, 11, 0) self.add(self._multi, 0, 1, 12, 1) self.change_mode(self._mode) self._left.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_left) self._right.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_right)
def __init__(self, root, game, config, serviceLocator): self.game = game self.columnSpan = 4 self.currentRow = 0 self.root = root self.window = tk.Toplevel(root, bg=Color.darkBackground) self.window.title("Game Launcher " + game) self.window.geometry("460x470") self.window.resizable(0, 0) config.setValue("appName", game) self.config = config self.serviceLocator = serviceLocator self.runner = RunnerFactory.getRunner(self.config) try: appTitle = config.getValue(["title"]) except: appTitle = game gameName = Label(self.window, text=appTitle) Color.paintDark(gameName) self._addWidgetFullWidth(gameName) gameName.config(font=("Impact", 20)) try: self.window.gameImage = getImageOrException(game) panel = tk.Label(self.window, image = self.window.gameImage) except AssetException: invisiblePixel = tk.PhotoImage(width=460, height=1) self.window.gameImage = invisiblePixel panel = tk.Label(self.window, image = self.window.gameImage) Color.paint(panel) panel.grid(column=0,row=self.currentRow, sticky='ns', columnspan=self.columnSpan) self.currentRow += 1 try: appDescription = config.getValue(["description"]) gameDescription = Label(self.window, heigh=5, text=appDescription) Color.paintBox(gameDescription) gameDescription.config(relief='flat', borderwidth=20) self._addWidgetFullWidth(gameDescription) except: pass self._createPlayButton() self._createTopBarButtons(self.window, game, config.getData()) try: appTitle = config.getValue(["mods"]) self._createModSelector(self.window, config.getData()) self.currentRow += 1 except: self._createEmptyModSelector(self.window, config.getData()) self.currentRow += 1 self.currentRow += 1 self._createFooterButtons(self.window) self.currentRow += 1
def _createModSelector(self, root, data): modLabel = Label(self.window) removeBorders(modLabel) Color.paintDark(modLabel) modLabel.grid(column=3,row=self.currentRow, sticky='nswe', columnspan=1) variable = StringVar(self.window) variable.set("Standard") # default value options = self.config.getValue(["mods"]) option = OptionMenu(self.window, variable, *options , command=self.modSelected) option.config(relief='flat') removeBorders(option) Color.paintDark(option) Color.paintDark(option["menu"]) option.grid(column=1,row=self.currentRow, sticky='nsw', columnspan=2)
def rect(x: int, y: int, w: int, h: int, color: Color = Color(1, 1, 1, 1), filled: bool = True): ac.glColor4f(color.r, color.g, color.b, color.a) if filled: ac.glQuad(x, y, w, h) else: ac.glBegin(1) ac.glVertex2f(x, y) ac.glVertex2f(x + w, y) ac.glVertex2f(x + w, y) ac.glVertex2f(x + w, y + h) ac.glVertex2f(x + w, y + h) ac.glVertex2f(x, y + h) ac.glVertex2f(x, y + h) ac.glVertex2f(x, y) ac.glEnd()
def createMenu(self, menuData): menubar = Menu(self.root, relief='flat') Color.paintDark(menubar) filemenu = Menu(menubar, tearoff=0, relief='flat') Color.paintDark(filemenu) helpmenu = Menu(menubar, tearoff=0, relief='flat') Color.paintDark(helpmenu) for index, content in enumerate(menuData): menuRunFunction = self.getMenuRunFunction("./", menuData[content]) filemenu.add_command(label=content, command=menuRunFunction) filemenu.add_command(label="Quit", command=self.root.destroy) helpmenu.add_command(label="About", command=self.showAbout) menubar.add_cascade(label="File", menu=filemenu) menubar.add_cascade(label="Help", menu=helpmenu) menubar.add_command(label="System", command=self.showSystem) self.root.config(menu=menubar)
class CR_Name(ACLabel): FONT = Font("Roboto Mono", Color(1.0, 0.0, 0.0, 0.75), True) def __init__(self, parent: ACWidget, text: str): super().__init__(parent, text, 'center', CR_Name.FONT)
def _createEmptyModSelector(self, root, data): modLabel = Label(self.window) removeBorders(modLabel) Color.paintDark(modLabel) modLabel.grid(column=1,row=self.currentRow, sticky='nswe', columnspan=4)
def line(x1: int, y1: int, x2: int, y2: int, color: Color = Color(1, 1, 1, 1)): ac.glColor4f(color.r, color.g, color.b, color.a) ac.glBegin(1) ac.glVertex2f(x1, y1) ac.glVertex2f(x2, y2) ac.glEnd()
def styleButton(widget): Color.paintButton(widget) Style._defaultButtonHighlight(widget) widget.config(font=("Impact", 15))
class ComparatorRow(ACGrid): TEXTURES = { 'left': path(TEXTURE_DIR, 'arrow-left-slim.png'), 'right': path(TEXTURE_DIR, 'arrow-right-slim.png') } COLORS = { 'gb': PURPLE, 'pb': Color(0.0, 0.75, 0, 1.0), 'pw': Color(0.7, 0.7, 0, 1.0) } def __init__(self, parent: ACWidget, data: ACData, meta: ACMeta): super().__init__(12, 2, parent) self.background_color = Color(0, 0, 0, 0.5) self._data = data self._meta = meta self._mode = 0 self._index = 0 self._player = self._data.players[self._index] self._server = self._data.server self._sec_format = '{s:02d}.{ms:03d}' self._on_player_lap_changed_callback_id = None self._label = CR_Name(self, self._player.name) self._label.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._focus_player) self._multi = ACMultiWidget(self) self._laps = ACHBox(self) self._bst = CR_Label(self._laps, 'BST: --:--:---') self._lst = CR_Label(self._laps, 'LST: --:--:---') self._sector_box = ACHBox(self) self._sectors = [] self._sectors.append(CR_Label(self._sector_box, 'S1: --:---')) self._sectors.append(CR_Label(self._sector_box, 'S2: --:---')) self._sectors.append(CR_Label(self._sector_box, 'S3: --:---')) self._left = CR_Icon(self, ComparatorRow.TEXTURES['left']) self._right = CR_Icon(self, ComparatorRow.TEXTURES['right']) self._laps.add(self._bst) self._laps.add(self._lst) self._sector_box.add(self._sectors[0]) self._sector_box.add(self._sectors[1]) self._sector_box.add(self._sectors[2]) self._multi.add(self._laps) self._multi.add(self._sector_box) self.add(self._left, 0, 0) self.add(self._label, 1, 0, 10, 1) self.add(self._right, 11, 0) self.add(self._multi, 0, 1, 12, 1) self.change_mode(self._mode) self._left.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_left) self._right.on(ACWidget.EVENT.ON_MOUSE_DOWN, self._on_right) def _focus_player(self, *args): ac.focusCar(self._index) def _update_index(self): self._player = self._data.players[self._index] self._label.text = self._player.name def _on_left(self, *args): if self._index > 0: self._index -= 1 else: self._index = self._server.cars - 1 self._update_index() def _on_right(self, *args): if self._index < self._server.cars - 1: self._index += 1 else: self._index = 0 self._update_index() def change_mode(self, mode: int): self._mode = mode if self._mode == 0: self._laps.visible = True self._sector_box.visible = False elif self._mode == 1: self._laps.visible = False self._sector_box.visible = True def update_best_last_lap(self, lap: int): # todo add multiplayer events pass def update(self, delta: float): super().update(delta) # Update every 300 ms. if (self.update_timer * 10) % 3 == 0: if self._mode == 1: player = self._player[self._index] for i in range(0, 3): self._sectors[i].text = 'S{}: {}'.format( i + 1, Format.duration(player.sector_time(i), form=self._sec_format)) if i != player.sector_index and player.sector_time(i) > 0: if player.sector_time(i) == player.gb_sector_time(i): self._sectors[i].font = CR_Label.BRIGHT self._sectors[ i].background_color = ComparatorRow.COLORS[ 'gb'] elif player.sector_time(i) == player.pb_sector_time(i): self._sectors[i].font = CR_Label.DARK self._sectors[ i].background_color = ComparatorRow.COLORS[ 'pb'] else: self._sectors[i].font = CR_Label.DARK self._sectors[ i].background_color = ComparatorRow.COLORS[ 'pw'] else: self._sectors[i].font = CR_Label.BRIGHT self._sectors[i].background_color = BLACK # Update every second. if self._update_timer > 1.0: self.reset_update_timer() if self._mode == 0: player = self._player[self._index] self._bst.text = 'BST: ' + Format.duration(player.best_lap) self._lst.text = 'LST: ' + Format.duration(player.last_lap) if player.last_lap > 0 and player.last_lap == player.gb_lap_time: self._lst.font = CR_Label.BRIGHT self._lst.background_color = ComparatorRow.COLORS['gb'] elif player.last_lap == player.pb_lap_time: self._lst.font = CR_Label.DARK self._lst.background_color = ComparatorRow.COLORS['pb'] else: self._lst.font = CR_Label.BRIGHT self._lst.background_color = BLACK if player.best_lap > 0 and player.best_lap == player.gb_lap_time: self._bst.font = CR_Label.BRIGHT self._bst.background_color = ComparatorRow.COLORS['gb'] elif player.best_lap == player.pb_lap_time: self._bst.font = CR_Label.DARK self._bst.background_color = ComparatorRow.COLORS['pb'] else: self._bst.font = CR_Label.BRIGHT self._bst.background_color = BLACK
class CR_Label(ACLabel): BRIGHT = Font("Roboto Mono", Color(1.0, 1.0, 1.0)) DARK = Font("Roboto Mono", Color(0.0, 0.0, 0.0)) def __init__(self, parent: ACWidget, text: str): super().__init__(parent, text, 'center', CR_Label.BRIGHT)
class CR_Button(ACButton): FONT = Font("Roboto Mono", Color(0, 0, 0)) def __init__(self, parent: ACWidget, text: str): super().__init__(parent, text, 'center', CR_Button.FONT)
def __init__(self, data: ACData = None, meta: ACMeta = None): super().__init__('ACLIB Fuel', 200, 200, 300, 100, True, True) self.hide_decoration() self._data = data self._meta = meta # Init self._normal_font = Font('Roboto Mono') self._normal_font.bold = 1 self._normal_font.color = WHITE self._main_grid = ACGrid(5, 4, self) self._grid = ACGrid(3, 3, self._main_grid) self._avg_km = ACLabel(self._grid, 'Ø 00.0 l/km', 'center', self._normal_font) self._avg_lap = ACLabel(self._grid, 'Ø 00.0 l/L', 'center', self._normal_font) self._avg_min = ACLabel(self._grid, 'Ø 00.0 l/min', 'center', self._normal_font) self._fuel = ACLabel(self._grid, '+ 00.0 l', 'center', self._normal_font) self._km = ACLabel(self._grid, '+ 00.0 km', 'center', self._normal_font) self._lap = ACLabel(self._grid, '+ 00.0 L', 'center', self._normal_font) self._min = ACLabel(self._grid, '+ 00.0 min', 'center', self._normal_font) # Style self.background_color = Color(0, 0, 0, 0.5) #self._fuel.background_color = Color(0.75, 0.75, 0, 0.75) self._main_grid.add(self._fuel, 3, 0, 2, 1) self._main_grid.add(self._avg_km, 1, 1, 2, 1) self._main_grid.add(self._km, 3, 1, 2, 1) self._main_grid.add(self._avg_lap, 1, 2, 2, 1) self._main_grid.add(self._lap, 3, 2, 2, 1) self._main_grid.add(self._avg_min, 1, 3, 2, 1) self._main_grid.add(self._min, 3, 3, 2, 1) # Data self._monitor = False self._timer = 0 self._track_len = 0 self._km_fuel_ref = 0 self._lap_fuel_ref = 0 self._min_fuel_ref = 0 self._km_fuel_avg = 0 self._lap_fuel_avg = 0 self._min_fuel_avg = 0 self._data.on(ACData.EVENT.READY, self._on_ready)
def stylePrimaryButton(widget): Color.paintPrimaryButton(widget) Style._defaultButtonHighlight(widget) widget.config(font=("Impact", 30))