display battle tie-break token
This commit is contained in:
parent
818d2886f4
commit
23110383c2
9 changed files with 127 additions and 29 deletions
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||
from typing import Dict
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtGui import QIcon, QPixmap, QPainter
|
||||
|
||||
|
||||
# Paths
|
||||
|
|
@ -17,37 +17,44 @@ ROLE_ID = Qt.ItemDataRole.UserRole + 1
|
|||
|
||||
|
||||
class IconName(str, Enum):
|
||||
UNDO = ("undo",)
|
||||
REDO = ("redo",)
|
||||
PAIRING = ("pairing",)
|
||||
DRAW = ("draw",)
|
||||
DELETE = ("delete",)
|
||||
SAVE_AS = ("save_as",)
|
||||
SAVE = ("save",)
|
||||
NEW = ("new",)
|
||||
EXIT = ("exit",)
|
||||
END = ("end",)
|
||||
OPEN = ("load",)
|
||||
ONGOING = ("ongoing",)
|
||||
EXPORT = ("export",)
|
||||
EDIT = ("edit",)
|
||||
ADD = ("add",)
|
||||
ABOUT = ("about",)
|
||||
WARS = ("wars",)
|
||||
DONE = ("done",)
|
||||
WIN = ("win",)
|
||||
PLAYERS = ("players",)
|
||||
UNDO = "undo"
|
||||
REDO = "redo"
|
||||
PAIRING = "pairing"
|
||||
DRAW = "draw"
|
||||
TIEBREAK = "tie-break"
|
||||
DELETE = "delete"
|
||||
SAVE_AS = "save_as"
|
||||
SAVE = "save"
|
||||
NEW = "new"
|
||||
EXIT = "exit"
|
||||
END = "end"
|
||||
OPEN = "load"
|
||||
ONGOING = "ongoing"
|
||||
EXPORT = "export"
|
||||
EDIT = "edit"
|
||||
ADD = "add"
|
||||
ABOUT = "about"
|
||||
WARS = "wars"
|
||||
DONE = "done"
|
||||
WIN = "win"
|
||||
PLAYERS = "players"
|
||||
WARCHRON = "warchron"
|
||||
TOKEN = "token"
|
||||
TOKENS = "tokens"
|
||||
TIEBREAK_TOKEN = auto()
|
||||
|
||||
|
||||
class Icons:
|
||||
_cache: Dict[str, QIcon] = {}
|
||||
_icon_cache: Dict[IconName, QIcon] = {}
|
||||
|
||||
_pixmap_cache: Dict[IconName, QPixmap] = {}
|
||||
|
||||
_paths = {
|
||||
IconName.UNDO: "arrow-curve-180-left",
|
||||
IconName.REDO: "arrow-curve",
|
||||
IconName.PAIRING: "arrow-switch",
|
||||
IconName.DRAW: "balance.png",
|
||||
IconName.TIEBREAK: "balance-unbalance.png",
|
||||
IconName.DELETE: "cross.png",
|
||||
IconName.SAVE_AS: "disk--pencil.png",
|
||||
IconName.SAVE: "disk.png",
|
||||
|
|
@ -65,14 +72,43 @@ class Icons:
|
|||
IconName.WIN: "trophy.png",
|
||||
IconName.PLAYERS: "users.png",
|
||||
IconName.WARCHRON: "warchron_logo.png",
|
||||
IconName.TOKEN: "point.png",
|
||||
IconName.TOKENS: "points.png",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get(cls, name: IconName) -> QIcon:
|
||||
if name not in cls._cache:
|
||||
if name not in cls._icon_cache:
|
||||
path = RESOURCES_DIR / cls._paths[name]
|
||||
cls._cache[name] = QIcon(str(path))
|
||||
return cls._cache[name]
|
||||
cls._icon_cache[name] = QIcon(str(path))
|
||||
return cls._icon_cache[name]
|
||||
|
||||
@classmethod
|
||||
def get_pixmap(cls, name: IconName) -> QPixmap:
|
||||
if name in cls._pixmap_cache:
|
||||
return cls._pixmap_cache[name]
|
||||
if name == IconName.TIEBREAK_TOKEN:
|
||||
pix = cls._compose(
|
||||
cls.get_pixmap(IconName.TIEBREAK),
|
||||
cls.get_pixmap(IconName.TOKEN),
|
||||
)
|
||||
else:
|
||||
path = RESOURCES_DIR / cls._paths[name]
|
||||
pix = QPixmap(path.as_posix())
|
||||
cls._pixmap_cache[name] = pix
|
||||
return pix
|
||||
|
||||
@staticmethod
|
||||
def _compose(left: QPixmap, right: QPixmap) -> QPixmap:
|
||||
w = left.width() + right.width()
|
||||
h = max(left.height(), right.height())
|
||||
result = QPixmap(w, h)
|
||||
result.fill(Qt.GlobalColor.transparent)
|
||||
painter = QPainter(result)
|
||||
painter.drawPixmap(0, (h - left.height()) // 2, left)
|
||||
painter.drawPixmap(left.width(), (h - right.height()) // 2, right)
|
||||
painter.end()
|
||||
return result
|
||||
|
||||
|
||||
class ItemType(StrEnum):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue