add/edit/delete sectors and participants in campaign
This commit is contained in:
parent
495a5adb98
commit
2816da010c
22 changed files with 1799 additions and 923 deletions
|
|
@ -12,7 +12,30 @@ from warchron.view.ui.ui_player_dialog import Ui_playerDialog
|
|||
from warchron.view.ui.ui_war_dialog import Ui_warDialog
|
||||
from warchron.view.ui.ui_campaign_dialog import Ui_campaignDialog
|
||||
from warchron.view.ui.ui_objective_dialog import Ui_objectiveDialog
|
||||
from warchron.view.ui.ui_participant_dialog import Ui_participantDialog
|
||||
from warchron.view.ui.ui_war_participant_dialog import Ui_warParticipantDialog
|
||||
from warchron.view.ui.ui_campaign_participant_dialog import Ui_campaignParticipantDialog
|
||||
from warchron.view.ui.ui_sector_dialog import Ui_sectorDialog
|
||||
from warchron.controller.dtos import ParticipantOption
|
||||
|
||||
# utils...
|
||||
|
||||
def select_if_exists(combo, value):
|
||||
if value is None:
|
||||
return
|
||||
idx = combo.findData(value)
|
||||
if idx != -1:
|
||||
combo.setCurrentIndex(idx)
|
||||
|
||||
def format_war_label(war) -> str:
|
||||
return f"{war.name} ({war.year})"
|
||||
|
||||
def format_campaign_label(camp) -> str:
|
||||
return f"{camp.name} ({calendar.month_name[camp.month]})"
|
||||
|
||||
def format_round_label(round, index: int) -> str:
|
||||
if index is None:
|
||||
return ""
|
||||
return f"Round {index}"
|
||||
|
||||
class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
|
|
@ -31,6 +54,10 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
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)
|
||||
self.sectorsTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
self.sectorsTable.customContextMenuRequested.connect(self._on_sectors_table_context_menu)
|
||||
self.warsTree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
self.warsTree.customContextMenuRequested.connect(self._on_wars_tree_context_menu)
|
||||
self.addCampaignBtn.clicked.connect(self._on_add_campaign_clicked)
|
||||
|
|
@ -147,32 +174,23 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
if self.on_delete_item:
|
||||
self.on_delete_item(item_type, item_id)
|
||||
|
||||
def _format_war_label(self, war) -> str:
|
||||
return f"{war.name} ({war.year})"
|
||||
|
||||
def _format_campaign_label(self, camp) -> str:
|
||||
return f"{camp.name} ({calendar.month_name[camp.month]})"
|
||||
|
||||
def _format_round_label(self, round, index: int) -> str:
|
||||
return f"Round {index}"
|
||||
|
||||
def display_wars_tree(self, wars: list):
|
||||
tree = self.warsTree
|
||||
tree.clear()
|
||||
tree.setColumnCount(1)
|
||||
tree.setHeaderLabels(["Wars"])
|
||||
for war in wars:
|
||||
war_item = QTreeWidgetItem([self._format_war_label(war)])
|
||||
war_item = QTreeWidgetItem([format_war_label(war)])
|
||||
war_item.setData(0, ROLE_TYPE, ItemType.WAR)
|
||||
war_item.setData(0, ROLE_ID, war.id)
|
||||
tree.addTopLevelItem(war_item)
|
||||
for camp in war.get_all_campaigns():
|
||||
camp_item = QTreeWidgetItem([self._format_campaign_label(camp)])
|
||||
camp_item = QTreeWidgetItem([format_campaign_label(camp)])
|
||||
camp_item.setData(0, ROLE_TYPE, ItemType.CAMPAIGN)
|
||||
camp_item.setData(0, ROLE_ID, camp.id)
|
||||
war_item.addChild(camp_item)
|
||||
for index, rnd in enumerate(camp.get_all_rounds(), start=1):
|
||||
rnd_item = QTreeWidgetItem([self._format_round_label(rnd, index)])
|
||||
rnd_item = QTreeWidgetItem([format_round_label(rnd, index)])
|
||||
rnd_item.setData(0, ROLE_TYPE, ItemType.ROUND)
|
||||
rnd_item.setData(0, ROLE_ID, rnd.id)
|
||||
camp_item.addChild(rnd_item)
|
||||
|
|
@ -282,10 +300,78 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
|
||||
# Campaign page
|
||||
|
||||
def _on_sectors_table_context_menu(self, pos):
|
||||
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")
|
||||
action = menu.exec(self.sectorsTable.viewport().mapToGlobal(pos))
|
||||
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)
|
||||
|
||||
def _on_campaign_participants_table_context_menu(self, pos):
|
||||
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")
|
||||
action = menu.exec(self.campaignParticipantsTable.viewport().mapToGlobal(pos))
|
||||
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)
|
||||
|
||||
def show_campaign_details(self, *, name: str, month: int):
|
||||
self.campaignName.setText(name)
|
||||
self.campaignMonth.setText(calendar.month_name[month])
|
||||
|
||||
def display_campaign_sectors(self, sectors: list[tuple[str, str, str, str, str, str]]):
|
||||
table = self.sectorsTable
|
||||
table.clearContents()
|
||||
table.setRowCount(len(sectors))
|
||||
for row, (name, round_index, major, minor, influence, pid) in enumerate(sectors):
|
||||
name_item = QtWidgets.QTableWidgetItem(name)
|
||||
round_item = QtWidgets.QTableWidgetItem(format_round_label(None, round_index))
|
||||
major_item = QtWidgets.QTableWidgetItem(major)
|
||||
minor_item = QtWidgets.QTableWidgetItem(minor)
|
||||
influence_item = QtWidgets.QTableWidgetItem(influence)
|
||||
name_item.setData(Qt.ItemDataRole.UserRole, pid)
|
||||
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()
|
||||
|
||||
def display_campaign_participants(self, participants: list[tuple[str, str, str, str]]):
|
||||
table = self.campaignParticipantsTable
|
||||
table.clearContents()
|
||||
table.setRowCount(len(participants))
|
||||
for row, (name, leader, theme, pid) in enumerate(participants):
|
||||
name_item = QtWidgets.QTableWidgetItem(name)
|
||||
lead_item = QtWidgets.QTableWidgetItem(leader)
|
||||
theme_item = QtWidgets.QTableWidgetItem(theme)
|
||||
name_item.setData(Qt.ItemDataRole.UserRole, pid)
|
||||
table.setItem(row, 0, name_item)
|
||||
table.setItem(row, 1, lead_item)
|
||||
table.setItem(row, 2, theme_item)
|
||||
table.resizeColumnsToContents()
|
||||
|
||||
# Round page
|
||||
|
||||
def show_round_details(self, *, index: int):
|
||||
|
|
@ -346,17 +432,14 @@ class ObjectiveDialog(QDialog):
|
|||
def get_objective_description(self) -> str:
|
||||
return self.ui.objectiveDescription.toPlainText().strip()
|
||||
|
||||
class ParticipantDialog(QDialog):
|
||||
class WarParticipantDialog(QDialog):
|
||||
def __init__(self, parent=None, *, players: list, default_player_id=None, default_faction="", editable_player=True):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_participantDialog()
|
||||
self.ui = Ui_warParticipantDialog()
|
||||
self.ui.setupUi(self)
|
||||
for player in players:
|
||||
self.ui.playerComboBox.addItem(player.name, player.id)
|
||||
if default_player_id:
|
||||
index = self.ui.playerComboBox.findData(default_player_id)
|
||||
if index != -1:
|
||||
self.ui.playerComboBox.setCurrentIndex(index)
|
||||
select_if_exists(self.ui.playerComboBox, default_player_id)
|
||||
self.ui.playerComboBox.setEnabled(editable_player)
|
||||
self.ui.faction.setText(default_faction)
|
||||
|
||||
|
|
@ -364,4 +447,60 @@ class ParticipantDialog(QDialog):
|
|||
return self.ui.playerComboBox.currentData()
|
||||
|
||||
def get_participant_faction(self) -> str:
|
||||
return self.ui.faction.text().strip()
|
||||
return self.ui.faction.text().strip()
|
||||
|
||||
class CampaignParticipantDialog(QDialog):
|
||||
def __init__(self, parent=None, *, participants: list[ParticipantOption], default_participant_id=None, default_leader="", default_theme="", editable_player=True):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_campaignParticipantDialog()
|
||||
self.ui.setupUi(self)
|
||||
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:
|
||||
return self.ui.playerComboBox.currentData()
|
||||
|
||||
def get_participant_leader(self) -> str:
|
||||
return self.ui.leader.text().strip()
|
||||
|
||||
def get_participant_theme(self) -> str:
|
||||
return self.ui.theme.text().strip()
|
||||
|
||||
class SectorDialog(QDialog):
|
||||
def __init__(self, parent=None, *, default_name="", rounds: list, default_round_id=None, objectives: list, default_major_id=None, default_minor_id=None, default_influence_id=None):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_sectorDialog()
|
||||
self.ui.setupUi(self)
|
||||
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):
|
||||
self.ui.roundComboBox.addItem(format_round_label(rnd, index), rnd.id)
|
||||
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:
|
||||
return self.ui.roundComboBox.currentData()
|
||||
|
||||
def get_major_id(self) -> str:
|
||||
return self.ui.majorComboBox.currentData()
|
||||
|
||||
def get_minor_id(self) -> str:
|
||||
return self.ui.minorComboBox.currentData()
|
||||
|
||||
def get_influence_id(self) -> str:
|
||||
return self.ui.influenceComboBox.currentData()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue