fix campaign tie loop + dynamic tie dialog
This commit is contained in:
parent
f339498f97
commit
c9407f9407
5 changed files with 120 additions and 222 deletions
|
|
@ -1,6 +1,15 @@
|
|||
from typing import List, Dict
|
||||
|
||||
from PyQt6.QtWidgets import QWidget, QDialog
|
||||
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
|
||||
|
|
@ -20,32 +29,47 @@ class TieDialog(QDialog):
|
|||
) -> None:
|
||||
super().__init__(parent)
|
||||
self._context_id = context_id
|
||||
self._p1_id = players[0].id
|
||||
self._p2_id = players[1].id
|
||||
self._checkboxes: Dict[str, QCheckBox] = {}
|
||||
self.ui: Ui_tieDialog = Ui_tieDialog()
|
||||
self.ui.setupUi(self) # type: ignore
|
||||
self.ui.tieContext.setText(self._get_context_title(context_type))
|
||||
icon_path = (RESOURCES_DIR / Icons._paths[IconName.TOKENS]).as_posix()
|
||||
html = f'<img src="{icon_path}" width="16" height="16"> Remaining token(s)'
|
||||
self.ui.label_2.setText(html)
|
||||
self.ui.label_2.setTextFormat(Qt.TextFormat.RichText)
|
||||
self.ui.label_3.setText(html)
|
||||
self.ui.label_3.setTextFormat(Qt.TextFormat.RichText)
|
||||
self.ui.groupBox_1.setTitle(players[0].name)
|
||||
self.ui.groupBox_2.setTitle(players[1].name)
|
||||
self.ui.tokenCount_1.setText(str(counters[0]))
|
||||
self.ui.tokenCount_2.setText(str(counters[1]))
|
||||
if counters[0] < 1:
|
||||
self.ui.tokenSpend_1.setDisabled(True)
|
||||
if counters[1] < 1:
|
||||
self.ui.tokenSpend_2.setDisabled(True)
|
||||
self.setWindowIcon(Icons.get(IconName.WARCHRON))
|
||||
self.ui.tieContext.setText(self._get_context_title(context_type))
|
||||
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 {
|
||||
self._p1_id: self.ui.tokenSpend_1.isChecked(),
|
||||
self._p2_id: self.ui.tokenSpend_2.isChecked(),
|
||||
}
|
||||
return {pid: checkbox.isChecked() for pid, checkbox in self._checkboxes.items()}
|
||||
|
||||
@staticmethod
|
||||
def _get_context_title(context_type: ContextType) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue