86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
from typing import List, Dict
|
|
|
|
from PyQt6.QtWidgets import (
|
|
QWidget,
|
|
QDialog,
|
|
QCheckBox,
|
|
QGroupBox,
|
|
QHBoxLayout,
|
|
QVBoxLayout,
|
|
QLabel,
|
|
QLineEdit,
|
|
)
|
|
from PyQt6.QtCore import Qt
|
|
|
|
from warchron.constants import Icons, IconName, ContextType, RESOURCES_DIR
|
|
from warchron.controller.dtos import ParticipantOption
|
|
from warchron.view.ui.ui_tie_dialog import Ui_tieDialog
|
|
|
|
|
|
class TieDialog(QDialog):
|
|
def __init__(
|
|
self,
|
|
parent: QWidget | None = None,
|
|
*,
|
|
players: List[ParticipantOption],
|
|
counters: List[int],
|
|
context_type: ContextType,
|
|
context_id: str,
|
|
context_name: str | None = None,
|
|
) -> None:
|
|
super().__init__(parent)
|
|
self._context_id = context_id
|
|
self._checkboxes: Dict[str, QCheckBox] = {}
|
|
self.ui: Ui_tieDialog = Ui_tieDialog()
|
|
self.ui.setupUi(self) # type: ignore
|
|
self.setWindowIcon(Icons.get(IconName.WARCHRONICO))
|
|
self.ui.tieContext.setText(self._get_context_title(context_type, context_name))
|
|
grid = self.ui.playersGridLayout
|
|
icon_path = (RESOURCES_DIR / Icons._paths[IconName.TOKENS]).as_posix()
|
|
token_html = (
|
|
f'<img src="{icon_path}" width="16" height="16"> Remaining token(s)'
|
|
)
|
|
for i, (player, tokens) in enumerate(zip(players, counters)):
|
|
group = QGroupBox(player.name)
|
|
row_layout = QHBoxLayout()
|
|
left = QVBoxLayout()
|
|
spend_label = QLabel("Spend token")
|
|
token_label = QLabel(token_html)
|
|
token_label.setTextFormat(Qt.TextFormat.RichText)
|
|
left.addWidget(spend_label)
|
|
left.addWidget(token_label)
|
|
right = QVBoxLayout()
|
|
checkbox = QCheckBox()
|
|
count = QLineEdit(str(tokens))
|
|
count.setEnabled(False)
|
|
if tokens < 1:
|
|
checkbox.setDisabled(True)
|
|
right.addWidget(checkbox)
|
|
right.addWidget(count)
|
|
row_layout.addLayout(left)
|
|
row_layout.addLayout(right)
|
|
group.setLayout(row_layout)
|
|
row = i // 2
|
|
col = i % 2
|
|
grid.addWidget(group, row, col)
|
|
self._checkboxes[player.id] = checkbox
|
|
grid.setColumnStretch(0, 1)
|
|
grid.setColumnStretch(1, 1)
|
|
self.ui.playersScrollArea.setMinimumHeight(110)
|
|
self.adjustSize()
|
|
|
|
def get_bids(self) -> Dict[str, bool]:
|
|
return {pid: checkbox.isChecked() for pid, checkbox in self._checkboxes.items()}
|
|
|
|
@staticmethod
|
|
def _get_context_title(
|
|
context_type: ContextType, context_name: str | None = None
|
|
) -> str:
|
|
titles = {
|
|
ContextType.BATTLE: "Battle tie",
|
|
ContextType.CAMPAIGN: "Campaign tie",
|
|
ContextType.WAR: "War tie",
|
|
ContextType.CHOICE: "Choice tie",
|
|
ContextType.OBJECTIVE: f"Objective tie: {context_name}",
|
|
}
|
|
return titles.get(context_type, "Tie")
|