2026-02-05 08:42:38 +01:00
|
|
|
from typing import cast, List
|
|
|
|
|
|
|
|
|
|
from PyQt6.QtWidgets import QWidget, QDialog
|
|
|
|
|
|
|
|
|
|
from warchron.controller.dtos import ParticipantOption, SectorDTO
|
|
|
|
|
from warchron.view.helpers import select_if_exists
|
2026-02-12 10:07:03 +01:00
|
|
|
from warchron.view.ui.ui_battle_dialog import Ui_battleDialog
|
2026-02-05 08:42:38 +01:00
|
|
|
|
|
|
|
|
|
2026-02-12 10:07:03 +01:00
|
|
|
class BattleDialog(QDialog):
|
2026-02-05 08:42:38 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
parent: QWidget | None = None,
|
|
|
|
|
*,
|
|
|
|
|
sectors: List[SectorDTO],
|
|
|
|
|
default_sector_id: str | None = None,
|
|
|
|
|
players: List[ParticipantOption],
|
|
|
|
|
default_player_1_id: str | None = None,
|
|
|
|
|
default_player_2_id: str | None = None,
|
|
|
|
|
default_winner_id: str | None = None,
|
|
|
|
|
default_score: str | None = None,
|
|
|
|
|
default_victory_condition: str | None = None,
|
|
|
|
|
default_comment: str | None = None,
|
|
|
|
|
) -> None:
|
|
|
|
|
super().__init__(parent)
|
2026-02-12 10:07:03 +01:00
|
|
|
self.ui: Ui_battleDialog = Ui_battleDialog()
|
2026-02-05 08:42:38 +01:00
|
|
|
self.ui.setupUi(self) # type: ignore
|
|
|
|
|
for sect in sectors:
|
|
|
|
|
self.ui.sectorComboBox.addItem(sect.name, sect.id)
|
|
|
|
|
select_if_exists(self.ui.sectorComboBox, default_sector_id)
|
|
|
|
|
self.ui.sectorComboBox.setEnabled(False)
|
|
|
|
|
|
|
|
|
|
self.ui.player1ComboBox.addItem("(none)", None)
|
|
|
|
|
self.ui.player2ComboBox.addItem("(none)", None)
|
|
|
|
|
for play in players:
|
|
|
|
|
self.ui.player1ComboBox.addItem(play.name, play.id)
|
|
|
|
|
self.ui.player2ComboBox.addItem(play.name, play.id)
|
|
|
|
|
select_if_exists(self.ui.player1ComboBox, default_player_1_id)
|
|
|
|
|
select_if_exists(self.ui.player2ComboBox, default_player_2_id)
|
|
|
|
|
self.ui.winnerComboBox.addItem("(none)", None)
|
|
|
|
|
for play in players:
|
|
|
|
|
if play.id in (default_player_1_id, default_player_2_id):
|
|
|
|
|
self.ui.winnerComboBox.addItem(play.name, play.id)
|
|
|
|
|
select_if_exists(self.ui.winnerComboBox, default_winner_id)
|
|
|
|
|
self.ui.score.setText(default_score)
|
|
|
|
|
self.ui.victoryCondition.setText(default_victory_condition)
|
|
|
|
|
self.ui.battleComment.setPlainText(default_comment)
|
|
|
|
|
|
|
|
|
|
def get_sector_id(self) -> str:
|
|
|
|
|
return cast(str, self.ui.sectorComboBox.currentData())
|
|
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_player_1_id(self) -> str | None:
|
|
|
|
|
text = cast(str, self.ui.player1ComboBox.currentData())
|
|
|
|
|
return text if text else None
|
2026-02-05 08:42:38 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_player_2_id(self) -> str | None:
|
|
|
|
|
text = cast(str, self.ui.player2ComboBox.currentData())
|
|
|
|
|
return text if text else None
|
2026-02-05 08:42:38 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_winner_id(self) -> str | None:
|
|
|
|
|
text = cast(str, self.ui.winnerComboBox.currentData())
|
|
|
|
|
return text if text else None
|
2026-02-05 08:42:38 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_score(self) -> str | None:
|
|
|
|
|
text = self.ui.score.text().strip()
|
|
|
|
|
return text if text else None
|
2026-02-05 08:42:38 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_victory_condition(self) -> str | None:
|
|
|
|
|
text = self.ui.victoryCondition.text().strip()
|
|
|
|
|
return text if text else None
|
2026-02-05 08:42:38 +01:00
|
|
|
|
2026-02-11 19:22:43 +01:00
|
|
|
def get_comment(self) -> str | None:
|
|
|
|
|
text = self.ui.battleComment.toPlainText().strip()
|
|
|
|
|
return text if text else None
|