2026-02-04 16:10:53 +01:00
|
|
|
from typing import cast, Callable, List
|
2026-01-19 11:16:23 +01:00
|
|
|
from pathlib import Path
|
2026-01-21 07:43:04 +01:00
|
|
|
import calendar
|
2026-01-19 11:16:23 +01:00
|
|
|
|
|
|
|
|
from PyQt6 import QtWidgets
|
2026-02-04 16:10:53 +01:00
|
|
|
from PyQt6.QtCore import Qt, QPoint
|
|
|
|
|
from PyQt6.QtWidgets import (
|
|
|
|
|
QWidget,
|
|
|
|
|
QDialog,
|
|
|
|
|
QFileDialog,
|
|
|
|
|
QTreeWidgetItem,
|
|
|
|
|
QMenu,
|
|
|
|
|
QComboBox,
|
|
|
|
|
)
|
2026-01-19 11:16:23 +01:00
|
|
|
from PyQt6.QtGui import QCloseEvent
|
|
|
|
|
|
2026-01-27 11:49:37 +01:00
|
|
|
from warchron.constants import ROLE_TYPE, ROLE_ID, ItemType
|
2026-02-04 16:10:53 +01:00
|
|
|
from warchron.controller.dtos import (
|
|
|
|
|
ParticipantOption,
|
|
|
|
|
TreeSelection,
|
|
|
|
|
WarDTO,
|
|
|
|
|
WarParticipantDTO,
|
|
|
|
|
ObjectiveDTO,
|
|
|
|
|
CampaignDTO,
|
|
|
|
|
CampaignParticipantDTO,
|
|
|
|
|
SectorDTO,
|
|
|
|
|
RoundDTO,
|
|
|
|
|
ChoiceDTO,
|
|
|
|
|
BattleDTO,
|
|
|
|
|
)
|
2026-01-19 11:16:23 +01:00
|
|
|
from warchron.view.ui.ui_main_window import Ui_MainWindow
|
|
|
|
|
from warchron.view.ui.ui_player_dialog import Ui_playerDialog
|
2026-01-20 08:46:58 +01:00
|
|
|
from warchron.view.ui.ui_war_dialog import Ui_warDialog
|
2026-01-21 07:43:04 +01:00
|
|
|
from warchron.view.ui.ui_campaign_dialog import Ui_campaignDialog
|
2026-01-28 16:25:40 +01:00
|
|
|
from warchron.view.ui.ui_objective_dialog import Ui_objectiveDialog
|
2026-01-30 00:34:22 +01:00
|
|
|
from warchron.view.ui.ui_war_participant_dialog import Ui_warParticipantDialog
|
2026-02-04 16:10:53 +01:00
|
|
|
from warchron.view.ui.ui_campaign_participant_dialog import (
|
|
|
|
|
Ui_campaignParticipantDialog,
|
|
|
|
|
)
|
2026-01-30 00:34:22 +01:00
|
|
|
from warchron.view.ui.ui_sector_dialog import Ui_sectorDialog
|
2026-01-30 10:52:19 +01:00
|
|
|
from warchron.view.ui.ui_choices_dialog import Ui_choicesDialog
|
2026-01-30 18:55:39 +01:00
|
|
|
from warchron.view.ui.ui_battle_result_dialog import Ui_battleResultDialog
|
2026-01-30 00:34:22 +01:00
|
|
|
|
|
|
|
|
# utils...
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def select_if_exists(combo: QComboBox, value: str | None) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
if value is None:
|
|
|
|
|
return
|
|
|
|
|
idx = combo.findData(value)
|
|
|
|
|
if idx != -1:
|
|
|
|
|
combo.setCurrentIndex(idx)
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def format_war_label(war: WarDTO) -> str:
|
2026-01-30 00:34:22 +01:00
|
|
|
return f"{war.name} ({war.year})"
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def format_campaign_label(camp: CampaignDTO) -> str:
|
2026-01-30 00:34:22 +01:00
|
|
|
return f"{camp.name} ({calendar.month_name[camp.month]})"
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def format_round_label(index: int) -> str:
|
2026-01-30 00:34:22 +01:00
|
|
|
if index is None:
|
|
|
|
|
return ""
|
|
|
|
|
return f"Round {index}"
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-19 11:16:23 +01:00
|
|
|
class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
2026-02-04 16:10:53 +01:00
|
|
|
def __init__(self, parent: QWidget | None = None) -> None:
|
2026-01-19 11:16:23 +01:00
|
|
|
super(View, self).__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.setupUi(self) # type: ignore
|
|
|
|
|
self.on_close_callback: Callable[[], bool] | None = None
|
|
|
|
|
self.on_tree_selection_changed: (
|
|
|
|
|
Callable[[TreeSelection | None], None] | None
|
|
|
|
|
) = None
|
|
|
|
|
self.on_add_campaign: Callable[[], None] | None = None
|
|
|
|
|
self.on_add_round: Callable[[], None] | None = None
|
|
|
|
|
self.on_edit_item: Callable[[str, str], None] | None = None
|
|
|
|
|
self.on_delete_item: Callable[[str, str], None] | None = None
|
2026-02-03 10:55:24 +01:00
|
|
|
self.splitter.setSizes([200, 800])
|
2026-01-27 11:49:37 +01:00
|
|
|
self.show_details(None)
|
2026-01-22 23:42:47 +01:00
|
|
|
self.playersTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
2026-02-02 10:41:16 +01:00
|
|
|
self.playersTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_players_table_context_menu
|
|
|
|
|
)
|
2026-01-30 10:52:19 +01:00
|
|
|
self.warsTree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
2026-02-02 10:41:16 +01:00
|
|
|
self.warsTree.customContextMenuRequested.connect(
|
|
|
|
|
self._on_wars_tree_context_menu
|
|
|
|
|
)
|
2026-01-30 10:52:19 +01:00
|
|
|
self.addCampaignBtn.clicked.connect(self._on_add_campaign_clicked)
|
|
|
|
|
self.addRoundBtn.clicked.connect(self._on_add_round_clicked)
|
|
|
|
|
# Pages
|
2026-02-02 10:41:16 +01:00
|
|
|
self.warParticipantsTable.setContextMenuPolicy(
|
|
|
|
|
Qt.ContextMenuPolicy.CustomContextMenu
|
|
|
|
|
)
|
|
|
|
|
self.warParticipantsTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_war_participants_table_context_menu
|
|
|
|
|
)
|
|
|
|
|
self.objectivesTable.setContextMenuPolicy(
|
|
|
|
|
Qt.ContextMenuPolicy.CustomContextMenu
|
|
|
|
|
)
|
|
|
|
|
self.objectivesTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_objectives_table_context_menu
|
|
|
|
|
)
|
|
|
|
|
self.campaignParticipantsTable.setContextMenuPolicy(
|
|
|
|
|
Qt.ContextMenuPolicy.CustomContextMenu
|
|
|
|
|
)
|
|
|
|
|
self.campaignParticipantsTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_campaign_participants_table_context_menu
|
|
|
|
|
)
|
2026-01-30 00:34:22 +01:00
|
|
|
self.sectorsTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
2026-02-02 10:41:16 +01:00
|
|
|
self.sectorsTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_sectors_table_context_menu
|
|
|
|
|
)
|
2026-01-30 10:52:19 +01:00
|
|
|
self.choicesTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
2026-02-02 10:41:16 +01:00
|
|
|
self.choicesTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_choices_table_context_menu
|
|
|
|
|
)
|
2026-01-30 18:55:39 +01:00
|
|
|
self.battlesTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
2026-02-02 10:41:16 +01:00
|
|
|
self.battlesTable.customContextMenuRequested.connect(
|
|
|
|
|
self._on_battles_table_context_menu
|
|
|
|
|
)
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _emit_selection_changed(self, current: QTreeWidgetItem | None) -> None:
|
2026-01-21 07:43:04 +01:00
|
|
|
if not self.on_tree_selection_changed:
|
|
|
|
|
return
|
|
|
|
|
if not current:
|
|
|
|
|
self.on_tree_selection_changed(None)
|
|
|
|
|
return
|
2026-02-02 10:41:16 +01:00
|
|
|
self.on_tree_selection_changed(
|
2026-02-04 16:10:53 +01:00
|
|
|
TreeSelection(
|
|
|
|
|
type=current.data(0, ROLE_TYPE),
|
|
|
|
|
id=current.data(0, ROLE_ID),
|
|
|
|
|
)
|
2026-02-02 10:41:16 +01:00
|
|
|
)
|
2026-01-22 23:42:47 +01:00
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def get_current_tab(self) -> str:
|
|
|
|
|
index = self.tabWidget.currentIndex()
|
|
|
|
|
if index == 0:
|
|
|
|
|
return "players"
|
|
|
|
|
elif index == 1:
|
|
|
|
|
return "wars"
|
|
|
|
|
return ""
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# General popups
|
2026-01-19 11:16:23 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def closeEvent(self, event: QCloseEvent | None = None) -> None:
|
|
|
|
|
if event is None:
|
|
|
|
|
return
|
2026-01-19 11:16:23 +01:00
|
|
|
if self.on_close_callback:
|
|
|
|
|
proceed = self.on_close_callback()
|
|
|
|
|
if not proceed:
|
|
|
|
|
event.ignore()
|
|
|
|
|
return
|
|
|
|
|
event.accept()
|
|
|
|
|
|
|
|
|
|
def ask_open_file(self) -> Path | None:
|
|
|
|
|
filename, _ = QFileDialog.getOpenFileName(
|
2026-02-02 10:41:16 +01:00
|
|
|
self, "Open war history", "", "WarChron files (*.json)"
|
2026-01-19 11:16:23 +01:00
|
|
|
)
|
|
|
|
|
return Path(filename) if filename else None
|
|
|
|
|
|
|
|
|
|
def ask_save_file(self) -> Path | None:
|
|
|
|
|
filename, _ = QFileDialog.getSaveFileName(
|
2026-02-02 10:41:16 +01:00
|
|
|
self, "Save war history", "", "WarChron files (*.json)"
|
2026-01-19 11:16:23 +01:00
|
|
|
)
|
|
|
|
|
return Path(filename) if filename else None
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# Players view
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_players_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
item = self.playersTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.playersTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
player_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.playersTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-28 16:25:40 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.PLAYER, player_id)
|
|
|
|
|
elif action == delete_action and self.on_delete_item:
|
|
|
|
|
self.on_delete_item(ItemType.PLAYER, player_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_players(self, players: List[ParticipantOption]) -> None:
|
2026-01-20 08:46:58 +01:00
|
|
|
table = self.playersTable
|
|
|
|
|
table.setRowCount(len(players))
|
|
|
|
|
for row, player in enumerate(players):
|
2026-01-22 23:57:01 +01:00
|
|
|
play_item = QtWidgets.QTableWidgetItem(player.name)
|
|
|
|
|
play_item.setData(Qt.ItemDataRole.UserRole, player.id)
|
|
|
|
|
table.setItem(row, 0, play_item)
|
2026-01-20 08:46:58 +01:00
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# Wars view
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_add_campaign_clicked(self) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
if self.on_add_campaign:
|
|
|
|
|
self.on_add_campaign()
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_add_round_clicked(self) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
if self.on_add_round:
|
|
|
|
|
self.on_add_round()
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_add_campaign_enabled(self, enabled: bool) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
self.addCampaignBtn.setEnabled(enabled)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def set_add_round_enabled(self, enabled: bool) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
self.addRoundBtn.setEnabled(enabled)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_wars_tree_context_menu(self, pos: QPoint) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
item = self.warsTree.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
item_type = item.data(0, ROLE_TYPE)
|
|
|
|
|
item_id = item.data(0, ROLE_ID)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = None
|
|
|
|
|
if item_type != ItemType.ROUND:
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.warsTree.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-28 16:25:40 +01:00
|
|
|
if action == edit_action:
|
|
|
|
|
if self.on_edit_item:
|
|
|
|
|
self.on_edit_item(item_type, item_id)
|
|
|
|
|
elif action == delete_action:
|
|
|
|
|
if self.on_delete_item:
|
|
|
|
|
self.on_delete_item(item_type, item_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_wars_tree(self, wars: List[WarDTO]) -> None:
|
2026-01-20 08:46:58 +01:00
|
|
|
tree = self.warsTree
|
|
|
|
|
tree.clear()
|
|
|
|
|
tree.setColumnCount(1)
|
|
|
|
|
tree.setHeaderLabels(["Wars"])
|
|
|
|
|
for war in wars:
|
2026-01-30 00:34:22 +01:00
|
|
|
war_item = QTreeWidgetItem([format_war_label(war)])
|
2026-01-27 11:49:37 +01:00
|
|
|
war_item.setData(0, ROLE_TYPE, ItemType.WAR)
|
2026-01-21 07:43:04 +01:00
|
|
|
war_item.setData(0, ROLE_ID, war.id)
|
2026-01-20 08:46:58 +01:00
|
|
|
tree.addTopLevelItem(war_item)
|
2026-01-21 07:43:04 +01:00
|
|
|
for camp in war.get_all_campaigns():
|
2026-01-30 00:34:22 +01:00
|
|
|
camp_item = QTreeWidgetItem([format_campaign_label(camp)])
|
2026-01-27 11:49:37 +01:00
|
|
|
camp_item.setData(0, ROLE_TYPE, ItemType.CAMPAIGN)
|
2026-01-21 07:43:04 +01:00
|
|
|
camp_item.setData(0, ROLE_ID, camp.id)
|
|
|
|
|
war_item.addChild(camp_item)
|
|
|
|
|
for index, rnd in enumerate(camp.get_all_rounds(), start=1):
|
2026-02-04 16:10:53 +01:00
|
|
|
rnd_item = QTreeWidgetItem([format_round_label(index)])
|
2026-01-27 11:49:37 +01:00
|
|
|
rnd_item.setData(0, ROLE_TYPE, ItemType.ROUND)
|
2026-01-21 07:43:04 +01:00
|
|
|
rnd_item.setData(0, ROLE_ID, rnd.id)
|
|
|
|
|
camp_item.addChild(rnd_item)
|
2026-01-27 11:49:37 +01:00
|
|
|
tree.currentItemChanged.connect(self._emit_selection_changed)
|
2026-01-20 08:46:58 +01:00
|
|
|
tree.expandAll()
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def select_tree_item(self, *, item_type: ItemType, item_id: str) -> None:
|
|
|
|
|
def walk(item: QTreeWidgetItem) -> bool:
|
2026-01-28 16:25:40 +01:00
|
|
|
if (
|
|
|
|
|
item.data(0, ROLE_TYPE) == item_type
|
|
|
|
|
and item.data(0, ROLE_ID) == item_id
|
|
|
|
|
):
|
|
|
|
|
self.warsTree.setCurrentItem(item)
|
|
|
|
|
return True
|
|
|
|
|
for i in range(item.childCount()):
|
2026-02-04 16:10:53 +01:00
|
|
|
# if walk(item.child(i)):
|
|
|
|
|
ytem = item.child(i)
|
|
|
|
|
if ytem is not None and walk(ytem):
|
2026-01-28 16:25:40 +01:00
|
|
|
return True
|
|
|
|
|
return False
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
for i in range(self.warsTree.topLevelItemCount()):
|
2026-02-04 16:10:53 +01:00
|
|
|
# if walk(self.warsTree.topLevelItem(i)):
|
|
|
|
|
item = self.warsTree.topLevelItem(i)
|
|
|
|
|
if item is not None and walk(item):
|
2026-01-28 16:25:40 +01:00
|
|
|
return
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def get_selected_tree_item(self) -> dict[str, str] | None:
|
2026-01-28 16:25:40 +01:00
|
|
|
item = self.warsTree.currentItem()
|
|
|
|
|
if not item:
|
|
|
|
|
return None
|
2026-02-02 10:41:16 +01:00
|
|
|
return {"type": item.data(0, ROLE_TYPE), "id": item.data(0, ROLE_ID)}
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def show_details(self, item_type: str | None) -> None:
|
2026-01-27 11:49:37 +01:00
|
|
|
if item_type == ItemType.WAR:
|
|
|
|
|
self.selectedDetailsStack.setCurrentWidget(self.pageWar)
|
|
|
|
|
elif item_type == ItemType.CAMPAIGN:
|
|
|
|
|
self.selectedDetailsStack.setCurrentWidget(self.pageCampaign)
|
|
|
|
|
elif item_type == ItemType.ROUND:
|
|
|
|
|
self.selectedDetailsStack.setCurrentWidget(self.pageRound)
|
|
|
|
|
else:
|
|
|
|
|
self.selectedDetailsStack.setCurrentWidget(self.pageEmpty)
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# War page
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_objectives_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
item = self.objectivesTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.objectivesTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
objective_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.objectivesTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-28 16:25:40 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.OBJECTIVE, objective_id)
|
|
|
|
|
elif action == delete_action and self.on_delete_item:
|
|
|
|
|
self.on_delete_item(ItemType.OBJECTIVE, objective_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_war_participants_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
item = self.warParticipantsTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.warParticipantsTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
participant_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.warParticipantsTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-28 16:25:40 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.WAR_PARTICIPANT, participant_id)
|
|
|
|
|
elif action == delete_action and self.on_delete_item:
|
|
|
|
|
self.on_delete_item(ItemType.WAR_PARTICIPANT, participant_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def show_war_details(self, *, name: str, year: int) -> None:
|
2026-01-27 11:49:37 +01:00
|
|
|
self.warName.setText(name)
|
2026-01-28 16:25:40 +01:00
|
|
|
self.warYear.setText(str(year))
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_war_objectives(self, objectives: List[ObjectiveDTO]) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
table = self.objectivesTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(objectives))
|
|
|
|
|
for row, obj in enumerate(objectives):
|
|
|
|
|
name_item = QtWidgets.QTableWidgetItem(obj.name)
|
|
|
|
|
desc_item = QtWidgets.QTableWidgetItem(obj.description)
|
|
|
|
|
name_item.setData(Qt.ItemDataRole.UserRole, obj.id)
|
|
|
|
|
table.setItem(row, 0, name_item)
|
|
|
|
|
table.setItem(row, 1, desc_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_war_participants(self, participants: List[WarParticipantDTO]) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
table = self.warParticipantsTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(participants))
|
2026-02-04 16:10:53 +01:00
|
|
|
for row, part in enumerate(participants):
|
|
|
|
|
name_item = QtWidgets.QTableWidgetItem(part.player_name)
|
|
|
|
|
fact_item = QtWidgets.QTableWidgetItem(part.faction)
|
|
|
|
|
name_item.setData(Qt.ItemDataRole.UserRole, part.id)
|
2026-01-28 16:25:40 +01:00
|
|
|
table.setItem(row, 0, name_item)
|
|
|
|
|
table.setItem(row, 1, fact_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# Campaign page
|
2026-01-27 11:49:37 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_sectors_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
item = self.sectorsTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.sectorsTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
sector_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.sectorsTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-30 00:34:22 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.SECTOR, sector_id)
|
|
|
|
|
elif action == delete_action and self.on_delete_item:
|
|
|
|
|
self.on_delete_item(ItemType.SECTOR, sector_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_campaign_participants_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
item = self.campaignParticipantsTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.campaignParticipantsTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
participant_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
|
|
|
|
delete_action = menu.addAction("Delete")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.campaignParticipantsTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-30 00:34:22 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.CAMPAIGN_PARTICIPANT, participant_id)
|
|
|
|
|
elif action == delete_action and self.on_delete_item:
|
|
|
|
|
self.on_delete_item(ItemType.CAMPAIGN_PARTICIPANT, participant_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def show_campaign_details(self, *, name: str, month: int) -> None:
|
2026-01-27 11:49:37 +01:00
|
|
|
self.campaignName.setText(name)
|
|
|
|
|
self.campaignMonth.setText(calendar.month_name[month])
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_campaign_sectors(self, sectors: List[SectorDTO]) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
table = self.sectorsTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(sectors))
|
2026-02-04 16:10:53 +01:00
|
|
|
for row, sect in enumerate(sectors):
|
|
|
|
|
name_item = QtWidgets.QTableWidgetItem(sect.name)
|
2026-02-02 10:41:16 +01:00
|
|
|
round_item = QtWidgets.QTableWidgetItem(
|
2026-02-04 16:10:53 +01:00
|
|
|
format_round_label(sect.round_index)
|
2026-02-02 10:41:16 +01:00
|
|
|
)
|
2026-02-04 16:10:53 +01:00
|
|
|
major_item = QtWidgets.QTableWidgetItem(sect.major)
|
|
|
|
|
minor_item = QtWidgets.QTableWidgetItem(sect.minor)
|
|
|
|
|
influence_item = QtWidgets.QTableWidgetItem(sect.influence)
|
|
|
|
|
name_item.setData(Qt.ItemDataRole.UserRole, sect.id)
|
2026-01-30 00:34:22 +01:00
|
|
|
table.setItem(row, 0, name_item)
|
|
|
|
|
table.setItem(row, 1, round_item)
|
|
|
|
|
table.setItem(row, 2, major_item)
|
|
|
|
|
table.setItem(row, 3, minor_item)
|
|
|
|
|
table.setItem(row, 4, influence_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
def display_campaign_participants(
|
2026-02-04 16:10:53 +01:00
|
|
|
self, participants: List[CampaignParticipantDTO]
|
|
|
|
|
) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
table = self.campaignParticipantsTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(participants))
|
2026-02-04 16:10:53 +01:00
|
|
|
for row, part in enumerate(participants):
|
|
|
|
|
name_item = QtWidgets.QTableWidgetItem(part.player_name)
|
|
|
|
|
lead_item = QtWidgets.QTableWidgetItem(part.leader)
|
|
|
|
|
theme_item = QtWidgets.QTableWidgetItem(part.theme)
|
|
|
|
|
name_item.setData(Qt.ItemDataRole.UserRole, part.id)
|
2026-01-30 00:34:22 +01:00
|
|
|
table.setItem(row, 0, name_item)
|
|
|
|
|
table.setItem(row, 1, lead_item)
|
|
|
|
|
table.setItem(row, 2, theme_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
# Round page
|
2026-01-28 16:25:40 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_choices_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-30 10:52:19 +01:00
|
|
|
item = self.choicesTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.choicesTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
choice_id = name_item.data(Qt.ItemDataRole.UserRole)
|
2026-01-30 15:32:44 +01:00
|
|
|
if choice_id is None:
|
|
|
|
|
return
|
2026-01-30 10:52:19 +01:00
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.choicesTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-30 10:52:19 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.CHOICE, choice_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def _on_battles_table_context_menu(self, pos: QPoint) -> None:
|
2026-01-30 18:55:39 +01:00
|
|
|
item = self.battlesTable.itemAt(pos)
|
|
|
|
|
if not item:
|
|
|
|
|
return
|
|
|
|
|
row = item.row()
|
|
|
|
|
name_item = self.battlesTable.item(row, 0)
|
|
|
|
|
if not name_item:
|
|
|
|
|
return
|
|
|
|
|
battle_id = name_item.data(Qt.ItemDataRole.UserRole)
|
|
|
|
|
if battle_id is None:
|
|
|
|
|
return
|
|
|
|
|
menu = QMenu(self)
|
|
|
|
|
edit_action = menu.addAction("Edit")
|
2026-02-04 16:10:53 +01:00
|
|
|
viewport = self.battlesTable.viewport()
|
|
|
|
|
assert viewport is not None
|
|
|
|
|
action = menu.exec(viewport.mapToGlobal(pos))
|
2026-01-30 18:55:39 +01:00
|
|
|
if action == edit_action and self.on_edit_item:
|
|
|
|
|
self.on_edit_item(ItemType.BATTLE, battle_id)
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def show_round_details(self, *, index: int) -> None:
|
2026-01-27 11:49:37 +01:00
|
|
|
self.roundNb.setText(f"Round {index}")
|
|
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_round_choices(self, participants: List[ChoiceDTO]) -> None:
|
2026-01-30 15:32:44 +01:00
|
|
|
table = self.choicesTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(participants))
|
2026-02-04 16:10:53 +01:00
|
|
|
for row, choice in enumerate(participants):
|
|
|
|
|
participant_item = QtWidgets.QTableWidgetItem(choice.participant_name)
|
|
|
|
|
priority_item = QtWidgets.QTableWidgetItem(choice.priority_sector)
|
|
|
|
|
secondary_item = QtWidgets.QTableWidgetItem(choice.secondary_sector)
|
|
|
|
|
participant_item.setData(Qt.ItemDataRole.UserRole, choice.id)
|
2026-01-30 15:32:44 +01:00
|
|
|
table.setItem(row, 0, participant_item)
|
|
|
|
|
table.setItem(row, 1, priority_item)
|
|
|
|
|
table.setItem(row, 2, secondary_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
2026-01-30 10:52:19 +01:00
|
|
|
|
2026-02-04 16:10:53 +01:00
|
|
|
def display_round_battles(self, sectors: List[BattleDTO]) -> None:
|
2026-01-30 18:55:39 +01:00
|
|
|
table = self.battlesTable
|
|
|
|
|
table.clearContents()
|
|
|
|
|
table.setRowCount(len(sectors))
|
2026-02-04 16:10:53 +01:00
|
|
|
for row, battle in enumerate(sectors):
|
|
|
|
|
sector_item = QtWidgets.QTableWidgetItem(battle.sector_name)
|
|
|
|
|
player_1_item = QtWidgets.QTableWidgetItem(battle.player_1)
|
|
|
|
|
player_2_item = QtWidgets.QTableWidgetItem(battle.player_2)
|
|
|
|
|
sector_item.setData(Qt.ItemDataRole.UserRole, battle.id)
|
2026-01-30 18:55:39 +01:00
|
|
|
table.setItem(row, 0, sector_item)
|
|
|
|
|
table.setItem(row, 1, player_1_item)
|
|
|
|
|
table.setItem(row, 2, player_2_item)
|
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-19 11:16:23 +01:00
|
|
|
class PlayerDialog(QDialog):
|
2026-02-04 16:10:53 +01:00
|
|
|
def __init__(
|
|
|
|
|
self, parent: QWidget | None = None, *, default_name: str = ""
|
|
|
|
|
) -> None:
|
2026-01-19 11:16:23 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_playerDialog = Ui_playerDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-22 23:42:47 +01:00
|
|
|
self.ui.playerName.setText(default_name)
|
2026-01-19 11:16:23 +01:00
|
|
|
|
|
|
|
|
def get_player_name(self) -> str:
|
|
|
|
|
return self.ui.playerName.text().strip()
|
2026-01-20 08:46:58 +01:00
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-20 08:46:58 +01:00
|
|
|
class WarDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
2026-02-04 16:10:53 +01:00
|
|
|
self,
|
|
|
|
|
parent: QWidget | None = None,
|
|
|
|
|
default_name: str = "",
|
|
|
|
|
default_year: int | None = None,
|
|
|
|
|
) -> None:
|
2026-01-20 08:46:58 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_warDialog = Ui_warDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-22 23:42:47 +01:00
|
|
|
self.ui.warName.setText(default_name)
|
|
|
|
|
if default_year is not None:
|
|
|
|
|
self.ui.warYear.setValue(default_year)
|
2026-01-20 08:46:58 +01:00
|
|
|
|
|
|
|
|
def get_war_name(self) -> str:
|
|
|
|
|
return self.ui.warName.text().strip()
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-22 23:42:47 +01:00
|
|
|
def get_war_year(self) -> int:
|
|
|
|
|
return int(self.ui.warYear.value())
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-21 07:43:04 +01:00
|
|
|
class CampaignDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
2026-02-04 16:10:53 +01:00
|
|
|
self,
|
|
|
|
|
parent: QWidget | None = None,
|
|
|
|
|
default_name: str = "",
|
|
|
|
|
default_month: int | None = None,
|
|
|
|
|
) -> None:
|
2026-01-21 07:43:04 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_campaignDialog = Ui_campaignDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-22 23:42:47 +01:00
|
|
|
self.ui.campaignName.setText(default_name)
|
|
|
|
|
if default_month is not None:
|
|
|
|
|
self.ui.campaignMonth.setValue(default_month)
|
2026-01-21 07:43:04 +01:00
|
|
|
|
|
|
|
|
def get_campaign_name(self) -> str:
|
|
|
|
|
return self.ui.campaignName.text().strip()
|
2026-01-22 23:42:47 +01:00
|
|
|
|
|
|
|
|
def get_campaign_month(self) -> int:
|
2026-01-28 16:25:40 +01:00
|
|
|
return int(self.ui.campaignMonth.value())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
class ObjectiveDialog(QDialog):
|
2026-02-04 16:10:53 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
parent: QWidget | None = None,
|
|
|
|
|
*,
|
|
|
|
|
default_name: str = "",
|
|
|
|
|
default_description: str | None = "",
|
|
|
|
|
) -> None:
|
2026-01-28 16:25:40 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_objectiveDialog = Ui_objectiveDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-28 16:25:40 +01:00
|
|
|
self.ui.objectiveName.setText(default_name)
|
|
|
|
|
self.ui.objectiveDescription.setPlainText(default_description)
|
|
|
|
|
|
|
|
|
|
def get_objective_name(self) -> str:
|
|
|
|
|
return self.ui.objectiveName.text().strip()
|
|
|
|
|
|
|
|
|
|
def get_objective_description(self) -> str:
|
|
|
|
|
return self.ui.objectiveDescription.toPlainText().strip()
|
2026-02-02 10:41:16 +01:00
|
|
|
|
|
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
class WarParticipantDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
parent: QWidget | None = None,
|
2026-02-02 10:41:16 +01:00
|
|
|
*,
|
2026-02-04 16:10:53 +01:00
|
|
|
players: List[ParticipantOption],
|
|
|
|
|
default_player_id: str | None = None,
|
|
|
|
|
default_faction: str | None = "",
|
|
|
|
|
editable_player: bool = True,
|
2026-02-02 10:41:16 +01:00
|
|
|
):
|
2026-01-28 16:25:40 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_warParticipantDialog = Ui_warParticipantDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-28 16:25:40 +01:00
|
|
|
for player in players:
|
|
|
|
|
self.ui.playerComboBox.addItem(player.name, player.id)
|
2026-01-30 00:34:22 +01:00
|
|
|
select_if_exists(self.ui.playerComboBox, default_player_id)
|
2026-01-28 16:25:40 +01:00
|
|
|
self.ui.playerComboBox.setEnabled(editable_player)
|
|
|
|
|
self.ui.faction.setText(default_faction)
|
|
|
|
|
|
|
|
|
|
def get_player_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.playerComboBox.currentData())
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def get_participant_faction(self) -> str:
|
2026-01-30 00:34:22 +01:00
|
|
|
return self.ui.faction.text().strip()
|
2026-02-02 10:41:16 +01:00
|
|
|
|
|
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
class CampaignParticipantDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
parent: QWidget | None = None,
|
2026-02-02 10:41:16 +01:00
|
|
|
*,
|
2026-02-04 16:10:53 +01:00
|
|
|
participants: List[ParticipantOption],
|
|
|
|
|
default_participant_id: str | None = None,
|
|
|
|
|
default_leader: str | None = "",
|
|
|
|
|
default_theme: str | None = "",
|
|
|
|
|
editable_player: bool = True,
|
|
|
|
|
) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_campaignParticipantDialog = Ui_campaignParticipantDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-30 00:34:22 +01:00
|
|
|
for part in participants:
|
|
|
|
|
self.ui.playerComboBox.addItem(part.name, part.id)
|
|
|
|
|
select_if_exists(self.ui.playerComboBox, default_participant_id)
|
|
|
|
|
self.ui.playerComboBox.setEnabled(editable_player)
|
|
|
|
|
self.ui.leader.setText(default_leader)
|
|
|
|
|
self.ui.theme.setText(default_theme)
|
|
|
|
|
|
|
|
|
|
def get_player_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.playerComboBox.currentData())
|
2026-01-30 00:34:22 +01:00
|
|
|
|
|
|
|
|
def get_participant_leader(self) -> str:
|
2026-02-02 10:41:16 +01:00
|
|
|
return self.ui.leader.text().strip()
|
|
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
def get_participant_theme(self) -> str:
|
|
|
|
|
return self.ui.theme.text().strip()
|
2026-02-02 10:41:16 +01:00
|
|
|
|
|
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
class SectorDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
parent: QWidget | None = None,
|
2026-02-02 10:41:16 +01:00
|
|
|
*,
|
2026-02-04 16:10:53 +01:00
|
|
|
default_name: str = "",
|
|
|
|
|
rounds: List[RoundDTO],
|
|
|
|
|
default_round_id: str | None = None,
|
|
|
|
|
objectives: List[ObjectiveDTO],
|
|
|
|
|
default_major_id: str | None = None,
|
|
|
|
|
default_minor_id: str | None = None,
|
|
|
|
|
default_influence_id: str | None = None,
|
|
|
|
|
) -> None:
|
2026-01-30 00:34:22 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_sectorDialog = Ui_sectorDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-30 00:34:22 +01:00
|
|
|
self.ui.majorComboBox.addItem("(none)", None)
|
|
|
|
|
self.ui.minorComboBox.addItem("(none)", None)
|
|
|
|
|
self.ui.influenceComboBox.addItem("(none)", None)
|
|
|
|
|
self.ui.sectorName.setText(default_name)
|
|
|
|
|
for index, rnd in enumerate(rounds, start=1):
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui.roundComboBox.addItem(format_round_label(index), rnd.id)
|
2026-01-30 00:34:22 +01:00
|
|
|
select_if_exists(self.ui.roundComboBox, default_round_id)
|
|
|
|
|
for obj in objectives:
|
|
|
|
|
self.ui.majorComboBox.addItem(obj.name, obj.id)
|
|
|
|
|
self.ui.minorComboBox.addItem(obj.name, obj.id)
|
|
|
|
|
self.ui.influenceComboBox.addItem(obj.name, obj.id)
|
|
|
|
|
select_if_exists(self.ui.majorComboBox, default_major_id)
|
|
|
|
|
select_if_exists(self.ui.minorComboBox, default_minor_id)
|
|
|
|
|
select_if_exists(self.ui.influenceComboBox, default_influence_id)
|
|
|
|
|
|
|
|
|
|
def get_sector_name(self) -> str:
|
|
|
|
|
return self.ui.sectorName.text().strip()
|
|
|
|
|
|
|
|
|
|
def get_round_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.roundComboBox.currentData())
|
2026-01-30 00:34:22 +01:00
|
|
|
|
|
|
|
|
def get_major_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.majorComboBox.currentData())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-30 00:34:22 +01:00
|
|
|
def get_minor_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.minorComboBox.currentData())
|
2026-01-30 00:34:22 +01:00
|
|
|
|
|
|
|
|
def get_influence_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.influenceComboBox.currentData())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-30 10:52:19 +01:00
|
|
|
|
|
|
|
|
class ChoicesDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
parent: QWidget | None = None,
|
2026-02-02 10:41:16 +01:00
|
|
|
*,
|
2026-02-04 16:10:53 +01:00
|
|
|
participants: List[ParticipantOption],
|
|
|
|
|
default_participant_id: str | None = None,
|
|
|
|
|
sectors: List[SectorDTO],
|
|
|
|
|
default_priority_id: str | None = None,
|
|
|
|
|
default_secondary_id: str | None = None,
|
|
|
|
|
default_comment: str | None = None,
|
|
|
|
|
) -> None:
|
2026-01-30 10:52:19 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_choicesDialog = Ui_choicesDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-01-30 10:52:19 +01:00
|
|
|
for part in participants:
|
|
|
|
|
self.ui.playerComboBox.addItem(part.name, part.id)
|
|
|
|
|
select_if_exists(self.ui.playerComboBox, default_participant_id)
|
|
|
|
|
self.ui.playerComboBox.setEnabled(False)
|
|
|
|
|
self.ui.priorityComboBox.addItem("(none)", None)
|
|
|
|
|
self.ui.secondaryComboBox.addItem("(none)", None)
|
|
|
|
|
for sect in sectors:
|
|
|
|
|
self.ui.priorityComboBox.addItem(sect.name, sect.id)
|
|
|
|
|
self.ui.secondaryComboBox.addItem(sect.name, sect.id)
|
|
|
|
|
select_if_exists(self.ui.priorityComboBox, default_priority_id)
|
|
|
|
|
select_if_exists(self.ui.secondaryComboBox, default_secondary_id)
|
2026-01-30 18:55:39 +01:00
|
|
|
self.ui.choiceComment.setPlainText(default_comment)
|
2026-01-30 10:52:19 +01:00
|
|
|
|
|
|
|
|
def get_participant_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.playerComboBox.currentData())
|
2026-01-30 10:52:19 +01:00
|
|
|
|
|
|
|
|
def get_priority_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.priorityComboBox.currentData())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-30 10:52:19 +01:00
|
|
|
def get_secondary_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.secondaryComboBox.currentData())
|
2026-01-30 18:55:39 +01:00
|
|
|
|
|
|
|
|
def get_comment(self) -> str:
|
2026-02-02 10:41:16 +01:00
|
|
|
return self.ui.choiceComment.toPlainText().strip()
|
|
|
|
|
|
2026-01-30 18:55:39 +01:00
|
|
|
|
|
|
|
|
class BattlesDialog(QDialog):
|
2026-02-02 10:41:16 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
2026-02-04 16:10:53 +01:00
|
|
|
parent: QWidget | None = None,
|
2026-02-02 10:41:16 +01:00
|
|
|
*,
|
2026-02-04 16:10:53 +01:00
|
|
|
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:
|
2026-01-30 18:55:39 +01:00
|
|
|
super().__init__(parent)
|
2026-02-04 16:10:53 +01:00
|
|
|
self.ui: Ui_battleResultDialog = Ui_battleResultDialog()
|
|
|
|
|
self.ui.setupUi(self) # type: ignore
|
2026-02-02 10:41:16 +01:00
|
|
|
for sect in sectors:
|
2026-01-30 18:55:39 +01:00
|
|
|
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:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.sectorComboBox.currentData())
|
2026-01-30 18:55:39 +01:00
|
|
|
|
|
|
|
|
def get_player_1_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.player1ComboBox.currentData())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-30 18:55:39 +01:00
|
|
|
def get_player_2_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.player2ComboBox.currentData())
|
2026-02-02 10:41:16 +01:00
|
|
|
|
2026-01-30 18:55:39 +01:00
|
|
|
def get_winner_id(self) -> str:
|
2026-02-04 16:10:53 +01:00
|
|
|
return cast(str, self.ui.winnerComboBox.currentData())
|
2026-01-30 18:55:39 +01:00
|
|
|
|
|
|
|
|
def get_score(self) -> str:
|
|
|
|
|
return self.ui.score.text().strip()
|
|
|
|
|
|
|
|
|
|
def get_victory_condition(self) -> str:
|
|
|
|
|
return self.ui.victoryCondition.text().strip()
|
|
|
|
|
|
|
|
|
|
def get_comment(self) -> str:
|
2026-02-02 10:41:16 +01:00
|
|
|
return self.ui.battleComment.toPlainText().strip()
|