35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from typing import cast, List
|
|
|
|
from PyQt6.QtWidgets import QWidget, QDialog
|
|
|
|
from warchron.constants import Icons, IconName
|
|
from warchron.controller.dtos import ParticipantOption
|
|
from warchron.view.helpers import select_if_exists
|
|
from warchron.view.ui.ui_war_participant_dialog import Ui_warParticipantDialog
|
|
|
|
|
|
class WarParticipantDialog(QDialog):
|
|
def __init__(
|
|
self,
|
|
parent: QWidget | None = None,
|
|
*,
|
|
players: List[ParticipantOption],
|
|
default_player_id: str | None = None,
|
|
default_faction: str | None = "",
|
|
editable_player: bool = True,
|
|
):
|
|
super().__init__(parent)
|
|
self.ui: Ui_warParticipantDialog = Ui_warParticipantDialog()
|
|
self.ui.setupUi(self) # type: ignore
|
|
for player in players:
|
|
self.ui.playerComboBox.addItem(player.name, player.id)
|
|
select_if_exists(self.ui.playerComboBox, default_player_id)
|
|
self.ui.playerComboBox.setEnabled(editable_player)
|
|
self.ui.faction.setText(default_faction)
|
|
self.setWindowIcon(Icons.get(IconName.WARCHRON))
|
|
|
|
def get_player_id(self) -> str:
|
|
return cast(str, self.ui.playerComboBox.currentData())
|
|
|
|
def get_participant_faction(self) -> str:
|
|
return self.ui.faction.text().strip()
|