From 723723dea176827b66c3674da6decf3d6103a236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Fri, 30 Jan 2026 10:52:19 +0100 Subject: [PATCH 1/2] list round choices ; fix UI --- src/warchron/constants.py | 2 + src/warchron/controller/controller.py | 51 ++++++- src/warchron/model/campaign.py | 6 +- src/warchron/model/model.py | 12 ++ src/warchron/model/round.py | 21 ++- .../view/ui/ui_battle_result_dialog.py | 78 +++++++++++ .../view/ui/ui_battle_result_dialog.ui | 118 ++++++++++++++++ src/warchron/view/ui/ui_choices_dialog.py | 88 ++++++++++++ src/warchron/view/ui/ui_choices_dialog.ui | 132 ++++++++++++++++++ src/warchron/view/ui/ui_main_window.py | 74 +++++----- src/warchron/view/ui/ui_main_window.ui | 84 +++++------ src/warchron/view/ui/ui_sector_dialog.py | 19 ++- src/warchron/view/ui/ui_sector_dialog.ui | 30 +++- src/warchron/view/view.py | 67 ++++++++- 14 files changed, 683 insertions(+), 99 deletions(-) create mode 100644 src/warchron/view/ui/ui_battle_result_dialog.py create mode 100644 src/warchron/view/ui/ui_battle_result_dialog.ui create mode 100644 src/warchron/view/ui/ui_choices_dialog.py create mode 100644 src/warchron/view/ui/ui_choices_dialog.ui diff --git a/src/warchron/constants.py b/src/warchron/constants.py index dce34fd..9cf46a3 100644 --- a/src/warchron/constants.py +++ b/src/warchron/constants.py @@ -15,6 +15,8 @@ class ItemType(StrEnum): WAR_PARTICIPANT = "war_participant" SECTOR = "sector" CAMPAIGN_PARTICIPANT = "campaign_participant" + CHOICE = "choice" + BATTLE = "battle" class RefreshScope(Enum): NONE = auto() diff --git a/src/warchron/controller/controller.py b/src/warchron/controller/controller.py index 626e21c..46ef82f 100644 --- a/src/warchron/controller/controller.py +++ b/src/warchron/controller/controller.py @@ -5,8 +5,8 @@ from warchron.model.model import Model from warchron.view.view import View from warchron.constants import ItemType, RefreshScope -from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, ObjectiveDialog, WarParticipantDialog, CampaignParticipantDialog, SectorDialog from warchron.controller.dtos import ParticipantOption +from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, ObjectiveDialog, WarParticipantDialog, CampaignParticipantDialog, SectorDialog, ChoicesDialog class Controller: def __init__(self, model: Model, view: View): @@ -167,6 +167,24 @@ class Controller: def _fill_round_details(self, round_id: str): index = self.model.get_round_index(round_id) self.view.show_round_details(index=index) + camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id) + rows = [] + for part in participants: + player = self.model.get_player(part.id) + choice = rnd.get_choice(part.id) + priority_name = "" + secondary_name = "" + if choice and choice.priority_sector_id: + priority_name = self.model.get_sector(choice.priority_sector_id).name + if choice and choice.secondary_sector_id: + secondary_name = self.model.get_sector(choice.secondary_sector_id).name + rows.append({ + "participant_id": part.id, + "participant_name": player.name, + "priority": priority_name, + "secondary": secondary_name, + }) + self.view.display_round_choices(rows) def on_tree_selection_changed(self, selection): self.selected_war_id = None @@ -325,7 +343,9 @@ class Controller: theme = dialog.get_participant_theme() self.model.update_campaign_participant(item_id, leader=leader, theme=theme) self.refresh(RefreshScope.CAMPAIGN_DETAILS) - self.is_dirty = True + elif item_type == ItemType.CHOICE: + self.edit_round_choice(item_id) + self.refresh(RefreshScope.ROUND_DETAILS) def delete_item(self, item_type: str, item_id: str): reply = QMessageBox.question( @@ -556,4 +576,29 @@ class Controller: return rnd = self.model.add_round(self.selected_campaign_id) self.is_dirty = True - self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id) \ No newline at end of file + self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id) + + def edit_round_choice(self, choice_id: str): + round_id = self.selected_round_id + if not round_id: + return + camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id) + choice = rnd.get_choice(choice_id) + if not choice: + return + participant = camp.participants[choice.participant_id] + dialog = ChoicesDialog( + self.view, + participants=[participant], + default_participant_id=participant.id, + sectors=sectors, + default_priority_id=choice.priority_sector_id, + default_secondary_id=choice.secondary_sector_id, + ) + if dialog.exec() != QDialog.DialogCode.Accepted: + return + rnd.set_choice( + participant_id=participant.id, + priority_sector_id=dialog.get_priority_id(), + secondary_sector_id=dialog.get_secondary_id(), + ) \ No newline at end of file diff --git a/src/warchron/model/campaign.py b/src/warchron/model/campaign.py index e3b5e90..9c36808 100644 --- a/src/warchron/model/campaign.py +++ b/src/warchron/model/campaign.py @@ -155,9 +155,9 @@ class Sector: self.id: str = str(uuid4()) self.name: str = name self.round_id: str = round_id - self.major_objective_id: str = major_id - self.minor_objective_id: str = minor_id - self.influence_objective_id: str = influence_id + self.major_objective_id: str | None = major_id # ref to War.objectives + self.minor_objective_id: str | None = minor_id # ref to War.objectives + self.influence_objective_id: str | None = influence_id # ref to War.objectives def set_id(self, new_id: str): self.id = new_id diff --git a/src/warchron/model/model.py b/src/warchron/model/model.py index c05b8d1..4ed5087 100644 --- a/src/warchron/model/model.py +++ b/src/warchron/model/model.py @@ -290,3 +290,15 @@ class Model: def remove_round(self, round_id: str): camp = self.get_campaign_by_round(round_id) camp.remove_round(round_id) + +# Choices methods + + def get_round_choices_data(self, round_id: str): + camp = self.get_campaign_by_round(round_id) + rnd = self.get_round(round_id) + participants = camp.participants.values() + sectors = [ + s for s in camp.sectors.values() + if s.round_id == round_id + ] + return camp, rnd, participants, sectors diff --git a/src/warchron/model/round.py b/src/warchron/model/round.py index a32d0d6..e4c2173 100644 --- a/src/warchron/model/round.py +++ b/src/warchron/model/round.py @@ -1,10 +1,10 @@ +from __future__ import annotations from uuid import uuid4 class Round: def __init__(self): self.id: str = str(uuid4()) - self.sectors = {} - self.choices = {} + self.choices: dict[str, RoundChoice] = {} self.battles = {} self.is_over: bool = False @@ -14,6 +14,9 @@ class Round: def set_state(self, new_state: bool): self.is_over = new_state + def set_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None): + self.choices[participant_id] = RoundChoice(participant_id, priority_sector_id, secondary_sector_id) + def toDict(self): return { "id": self.id, @@ -31,4 +34,16 @@ class Round: # rnd.choices = data.get("choices", {}) # rnd.battles = data.get("battles", {}) rnd.set_state(data.get("is_over", False)) - return rnd \ No newline at end of file + return rnd + +# Choices methods + + def get_choice(self, participant_id: str) -> RoundChoice | None: + return self.choices.get(participant_id) + + +class RoundChoice: + def __init__(self, participant_id: str, priority_sector_id: str | None = None, secondary_sector_id: str | None = None): + self.participant_id: str = participant_id # ref to Campaign.participants + self.priority_sector_id: str | None = priority_sector_id # ref to Campaign.sectors + self.secondary_sector_id: str | None = secondary_sector_id # ref to Campaign.sectors diff --git a/src/warchron/view/ui/ui_battle_result_dialog.py b/src/warchron/view/ui/ui_battle_result_dialog.py new file mode 100644 index 0000000..8dcc6ec --- /dev/null +++ b/src/warchron/view/ui/ui_battle_result_dialog.py @@ -0,0 +1,78 @@ +# Form implementation generated from reading ui file '.\src\warchron\view\ui\ui_battle_result_dialog.ui' +# +# Created by: PyQt6 UI code generator 6.7.1 +# +# WARNING: Any manual changes made to this file will be lost when pyuic6 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt6 import QtCore, QtGui, QtWidgets + + +class Ui_battleResultDialog(object): + def setupUi(self, battleResultDialog): + battleResultDialog.setObjectName("battleResultDialog") + battleResultDialog.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) + battleResultDialog.resize(561, 246) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) + battleResultDialog.setWindowIcon(icon) + self.formLayout = QtWidgets.QFormLayout(battleResultDialog) + self.formLayout.setObjectName("formLayout") + self.label = QtWidgets.QLabel(parent=battleResultDialog) + self.label.setObjectName("label") + self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label) + self.winnerComboBox = QtWidgets.QComboBox(parent=battleResultDialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.winnerComboBox.sizePolicy().hasHeightForWidth()) + self.winnerComboBox.setSizePolicy(sizePolicy) + self.winnerComboBox.setObjectName("winnerComboBox") + self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.winnerComboBox) + self.label_2 = QtWidgets.QLabel(parent=battleResultDialog) + self.label_2.setObjectName("label_2") + self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_2) + self.score = QtWidgets.QLineEdit(parent=battleResultDialog) + self.score.setObjectName("score") + self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.score) + self.label_3 = QtWidgets.QLabel(parent=battleResultDialog) + self.label_3.setObjectName("label_3") + self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_3) + self.victoryCondition = QtWidgets.QLineEdit(parent=battleResultDialog) + self.victoryCondition.setObjectName("victoryCondition") + self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.victoryCondition) + self.label_4 = QtWidgets.QLabel(parent=battleResultDialog) + self.label_4.setObjectName("label_4") + self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_4) + self.battleComment = QtWidgets.QPlainTextEdit(parent=battleResultDialog) + self.battleComment.setObjectName("battleComment") + self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.FieldRole, self.battleComment) + self.buttonBox = QtWidgets.QDialogButtonBox(parent=battleResultDialog) + self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok) + self.buttonBox.setObjectName("buttonBox") + self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.SpanningRole, self.buttonBox) + + self.retranslateUi(battleResultDialog) + self.buttonBox.accepted.connect(battleResultDialog.accept) # type: ignore + self.buttonBox.rejected.connect(battleResultDialog.reject) # type: ignore + QtCore.QMetaObject.connectSlotsByName(battleResultDialog) + + def retranslateUi(self, battleResultDialog): + _translate = QtCore.QCoreApplication.translate + battleResultDialog.setWindowTitle(_translate("battleResultDialog", "Battle result")) + self.label.setText(_translate("battleResultDialog", "Winner")) + self.label_2.setText(_translate("battleResultDialog", "Score")) + self.label_3.setText(_translate("battleResultDialog", "Victory condition")) + self.label_4.setText(_translate("battleResultDialog", "Comment")) + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + battleResultDialog = QtWidgets.QDialog() + ui = Ui_battleResultDialog() + ui.setupUi(battleResultDialog) + battleResultDialog.show() + sys.exit(app.exec()) diff --git a/src/warchron/view/ui/ui_battle_result_dialog.ui b/src/warchron/view/ui/ui_battle_result_dialog.ui new file mode 100644 index 0000000..3902a26 --- /dev/null +++ b/src/warchron/view/ui/ui_battle_result_dialog.ui @@ -0,0 +1,118 @@ + + + battleResultDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 561 + 246 + + + + Battle result + + + + ../resources/warchron_logo.png../resources/warchron_logo.png + + + + + + Winner + + + + + + + + 0 + 0 + + + + + + + + Score + + + + + + + + + + Victory condition + + + + + + + + + + Comment + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + battleResultDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + battleResultDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/warchron/view/ui/ui_choices_dialog.py b/src/warchron/view/ui/ui_choices_dialog.py new file mode 100644 index 0000000..62f87b0 --- /dev/null +++ b/src/warchron/view/ui/ui_choices_dialog.py @@ -0,0 +1,88 @@ +# Form implementation generated from reading ui file '.\src\warchron\view\ui\ui_choices_dialog.ui' +# +# Created by: PyQt6 UI code generator 6.7.1 +# +# WARNING: Any manual changes made to this file will be lost when pyuic6 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt6 import QtCore, QtGui, QtWidgets + + +class Ui_choicesDialog(object): + def setupUi(self, choicesDialog): + choicesDialog.setObjectName("choicesDialog") + choicesDialog.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) + choicesDialog.resize(561, 246) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) + choicesDialog.setWindowIcon(icon) + self.gridLayout = QtWidgets.QGridLayout(choicesDialog) + self.gridLayout.setObjectName("gridLayout") + self.label = QtWidgets.QLabel(parent=choicesDialog) + self.label.setObjectName("label") + self.gridLayout.addWidget(self.label, 0, 0, 1, 1) + self.playerComboBox = QtWidgets.QComboBox(parent=choicesDialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.playerComboBox.sizePolicy().hasHeightForWidth()) + self.playerComboBox.setSizePolicy(sizePolicy) + self.playerComboBox.setObjectName("playerComboBox") + self.gridLayout.addWidget(self.playerComboBox, 0, 1, 1, 1) + self.label_2 = QtWidgets.QLabel(parent=choicesDialog) + self.label_2.setObjectName("label_2") + self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) + self.priorityComboBox = QtWidgets.QComboBox(parent=choicesDialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.priorityComboBox.sizePolicy().hasHeightForWidth()) + self.priorityComboBox.setSizePolicy(sizePolicy) + self.priorityComboBox.setObjectName("priorityComboBox") + self.gridLayout.addWidget(self.priorityComboBox, 1, 1, 1, 1) + self.label_3 = QtWidgets.QLabel(parent=choicesDialog) + self.label_3.setObjectName("label_3") + self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) + self.secondaryComboBox = QtWidgets.QComboBox(parent=choicesDialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.secondaryComboBox.sizePolicy().hasHeightForWidth()) + self.secondaryComboBox.setSizePolicy(sizePolicy) + self.secondaryComboBox.setObjectName("secondaryComboBox") + self.gridLayout.addWidget(self.secondaryComboBox, 2, 1, 1, 1) + self.label_4 = QtWidgets.QLabel(parent=choicesDialog) + self.label_4.setObjectName("label_4") + self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1) + self.choiceComment = QtWidgets.QPlainTextEdit(parent=choicesDialog) + self.choiceComment.setObjectName("choiceComment") + self.gridLayout.addWidget(self.choiceComment, 3, 1, 1, 1) + self.buttonBox = QtWidgets.QDialogButtonBox(parent=choicesDialog) + self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 2) + + self.retranslateUi(choicesDialog) + self.buttonBox.accepted.connect(choicesDialog.accept) # type: ignore + self.buttonBox.rejected.connect(choicesDialog.reject) # type: ignore + QtCore.QMetaObject.connectSlotsByName(choicesDialog) + + def retranslateUi(self, choicesDialog): + _translate = QtCore.QCoreApplication.translate + choicesDialog.setWindowTitle(_translate("choicesDialog", "Choices")) + self.label.setText(_translate("choicesDialog", "Player")) + self.label_2.setText(_translate("choicesDialog", "Priority")) + self.label_3.setText(_translate("choicesDialog", "Secondary")) + self.label_4.setText(_translate("choicesDialog", "Comment")) + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + choicesDialog = QtWidgets.QDialog() + ui = Ui_choicesDialog() + ui.setupUi(choicesDialog) + choicesDialog.show() + sys.exit(app.exec()) diff --git a/src/warchron/view/ui/ui_choices_dialog.ui b/src/warchron/view/ui/ui_choices_dialog.ui new file mode 100644 index 0000000..0259a2a --- /dev/null +++ b/src/warchron/view/ui/ui_choices_dialog.ui @@ -0,0 +1,132 @@ + + + choicesDialog + + + Qt::ApplicationModal + + + + 0 + 0 + 561 + 246 + + + + Choices + + + + ../resources/warchron_logo.png../resources/warchron_logo.png + + + + + + Player + + + + + + + + 0 + 0 + + + + + + + + Priority + + + + + + + + 0 + 0 + + + + + + + + Secondary + + + + + + + + 0 + 0 + + + + + + + + Comment + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + choicesDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + choicesDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/warchron/view/ui/ui_main_window.py b/src/warchron/view/ui/ui_main_window.py index 196353d..da43ca3 100644 --- a/src/warchron/view/ui/ui_main_window.py +++ b/src/warchron/view/ui/ui_main_window.py @@ -183,28 +183,6 @@ class Ui_MainWindow(object): self.gridLayout_4.addItem(spacerItem5, 5, 2, 1, 1) self.horizontalLayout_12 = QtWidgets.QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") - self.sectorsTable = QtWidgets.QTableWidget(parent=self.pageCampaign) - self.sectorsTable.setObjectName("sectorsTable") - self.sectorsTable.setColumnCount(5) - self.sectorsTable.setRowCount(0) - item = QtWidgets.QTableWidgetItem() - self.sectorsTable.setHorizontalHeaderItem(0, item) - item = QtWidgets.QTableWidgetItem() - self.sectorsTable.setHorizontalHeaderItem(1, item) - item = QtWidgets.QTableWidgetItem() - self.sectorsTable.setHorizontalHeaderItem(2, item) - item = QtWidgets.QTableWidgetItem() - self.sectorsTable.setHorizontalHeaderItem(3, item) - item = QtWidgets.QTableWidgetItem() - self.sectorsTable.setHorizontalHeaderItem(4, item) - self.horizontalLayout_12.addWidget(self.sectorsTable) - self.addSectorBtn = QtWidgets.QPushButton(parent=self.pageCampaign) - self.addSectorBtn.setEnabled(True) - self.addSectorBtn.setObjectName("addSectorBtn") - self.horizontalLayout_12.addWidget(self.addSectorBtn) - self.gridLayout_4.addLayout(self.horizontalLayout_12, 4, 0, 1, 3) - self.horizontalLayout_13 = QtWidgets.QHBoxLayout() - self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.campaignParticipantsTable = QtWidgets.QTableWidget(parent=self.pageCampaign) self.campaignParticipantsTable.setObjectName("campaignParticipantsTable") self.campaignParticipantsTable.setColumnCount(5) @@ -219,10 +197,32 @@ class Ui_MainWindow(object): self.campaignParticipantsTable.setHorizontalHeaderItem(3, item) item = QtWidgets.QTableWidgetItem() self.campaignParticipantsTable.setHorizontalHeaderItem(4, item) - self.horizontalLayout_13.addWidget(self.campaignParticipantsTable) + self.horizontalLayout_12.addWidget(self.campaignParticipantsTable) self.addCampaignParticipantBtn = QtWidgets.QPushButton(parent=self.pageCampaign) self.addCampaignParticipantBtn.setObjectName("addCampaignParticipantBtn") - self.horizontalLayout_13.addWidget(self.addCampaignParticipantBtn) + self.horizontalLayout_12.addWidget(self.addCampaignParticipantBtn) + self.gridLayout_4.addLayout(self.horizontalLayout_12, 4, 0, 1, 3) + self.horizontalLayout_13 = QtWidgets.QHBoxLayout() + self.horizontalLayout_13.setObjectName("horizontalLayout_13") + self.sectorsTable = QtWidgets.QTableWidget(parent=self.pageCampaign) + self.sectorsTable.setObjectName("sectorsTable") + self.sectorsTable.setColumnCount(5) + self.sectorsTable.setRowCount(0) + item = QtWidgets.QTableWidgetItem() + self.sectorsTable.setHorizontalHeaderItem(0, item) + item = QtWidgets.QTableWidgetItem() + self.sectorsTable.setHorizontalHeaderItem(1, item) + item = QtWidgets.QTableWidgetItem() + self.sectorsTable.setHorizontalHeaderItem(2, item) + item = QtWidgets.QTableWidgetItem() + self.sectorsTable.setHorizontalHeaderItem(3, item) + item = QtWidgets.QTableWidgetItem() + self.sectorsTable.setHorizontalHeaderItem(4, item) + self.horizontalLayout_13.addWidget(self.sectorsTable) + self.addSectorBtn = QtWidgets.QPushButton(parent=self.pageCampaign) + self.addSectorBtn.setEnabled(True) + self.addSectorBtn.setObjectName("addSectorBtn") + self.horizontalLayout_13.addWidget(self.addSectorBtn) self.gridLayout_4.addLayout(self.horizontalLayout_13, 2, 0, 1, 3) self.horizontalLayout_11 = QtWidgets.QHBoxLayout() self.horizontalLayout_11.setObjectName("horizontalLayout_11") @@ -385,7 +385,7 @@ class Ui_MainWindow(object): self.retranslateUi(MainWindow) self.tabWidget.setCurrentIndex(1) - self.selectedDetailsStack.setCurrentIndex(3) + self.selectedDetailsStack.setCurrentIndex(2) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): @@ -429,17 +429,6 @@ class Ui_MainWindow(object): self.labelSectors.setText(_translate("MainWindow", "Sectors")) self.labelParticipants_2.setText(_translate("MainWindow", "Participants")) self.endCampaignBtn.setText(_translate("MainWindow", "End campaign")) - item = self.sectorsTable.horizontalHeaderItem(0) - item.setText(_translate("MainWindow", "Name")) - item = self.sectorsTable.horizontalHeaderItem(1) - item.setText(_translate("MainWindow", "Round")) - item = self.sectorsTable.horizontalHeaderItem(2) - item.setText(_translate("MainWindow", "Major obj.")) - item = self.sectorsTable.horizontalHeaderItem(3) - item.setText(_translate("MainWindow", "Minor opp.")) - item = self.sectorsTable.horizontalHeaderItem(4) - item.setText(_translate("MainWindow", "Influence imp.")) - self.addSectorBtn.setText(_translate("MainWindow", "Add Sector")) item = self.campaignParticipantsTable.horizontalHeaderItem(0) item.setText(_translate("MainWindow", "Name")) item = self.campaignParticipantsTable.horizontalHeaderItem(1) @@ -451,6 +440,17 @@ class Ui_MainWindow(object): item = self.campaignParticipantsTable.horizontalHeaderItem(4) item.setText(_translate("MainWindow", "Theme pts.")) self.addCampaignParticipantBtn.setText(_translate("MainWindow", "Add participant")) + item = self.sectorsTable.horizontalHeaderItem(0) + item.setText(_translate("MainWindow", "Name")) + item = self.sectorsTable.horizontalHeaderItem(1) + item.setText(_translate("MainWindow", "Round")) + item = self.sectorsTable.horizontalHeaderItem(2) + item.setText(_translate("MainWindow", "Major obj.")) + item = self.sectorsTable.horizontalHeaderItem(3) + item.setText(_translate("MainWindow", "Minor opp.")) + item = self.sectorsTable.horizontalHeaderItem(4) + item.setText(_translate("MainWindow", "Influence imp.")) + self.addSectorBtn.setText(_translate("MainWindow", "Add Sector")) self.campaignName.setText(_translate("MainWindow", "campaignName")) self.campaignMonth.setText(_translate("MainWindow", "campaignMonth")) self.labelChoices.setText(_translate("MainWindow", "Choices")) @@ -466,7 +466,7 @@ class Ui_MainWindow(object): item = self.choicesTable.horizontalHeaderItem(0) item.setText(_translate("MainWindow", "Player")) item = self.choicesTable.horizontalHeaderItem(1) - item.setText(_translate("MainWindow", "Prioritary")) + item.setText(_translate("MainWindow", "Priority")) item = self.choicesTable.horizontalHeaderItem(2) item.setText(_translate("MainWindow", "Secondary")) self.resolvePairingBtn.setText(_translate("MainWindow", "Resolve pairing")) diff --git a/src/warchron/view/ui/ui_main_window.ui b/src/warchron/view/ui/ui_main_window.ui index 5c4df48..0c39e26 100644 --- a/src/warchron/view/ui/ui_main_window.ui +++ b/src/warchron/view/ui/ui_main_window.ui @@ -150,7 +150,7 @@ - 3 + 2 @@ -379,6 +379,46 @@ + + + + + Name + + + + + Leader + + + + + Theme + + + + + Victory pts. + + + + + Theme pts. + + + + + + + + Add participant + + + + + + + @@ -420,46 +460,6 @@ - - - - - - - Name - - - - - Leader - - - - - Theme - - - - - Victory pts. - - - - - Theme pts. - - - - - - - - Add participant - - - - - @@ -573,7 +573,7 @@ - Prioritary + Priority diff --git a/src/warchron/view/ui/ui_sector_dialog.py b/src/warchron/view/ui/ui_sector_dialog.py index b85e0a9..612be65 100644 --- a/src/warchron/view/ui/ui_sector_dialog.py +++ b/src/warchron/view/ui/ui_sector_dialog.py @@ -13,7 +13,7 @@ class Ui_sectorDialog(object): def setupUi(self, sectorDialog): sectorDialog.setObjectName("sectorDialog") sectorDialog.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) - sectorDialog.resize(514, 129) + sectorDialog.resize(602, 338) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) sectorDialog.setWindowIcon(icon) @@ -59,6 +59,13 @@ class Ui_sectorDialog(object): self.minorComboBox.setSizePolicy(sizePolicy) self.minorComboBox.setObjectName("minorComboBox") self.gridLayout.addWidget(self.minorComboBox, 1, 3, 1, 1) + self.label_7 = QtWidgets.QLabel(parent=sectorDialog) + self.label_7.setObjectName("label_7") + self.gridLayout.addWidget(self.label_7, 2, 0, 1, 1) + self.sectorMission = QtWidgets.QLineEdit(parent=sectorDialog) + self.sectorMission.setText("") + self.sectorMission.setObjectName("sectorMission") + self.gridLayout.addWidget(self.sectorMission, 2, 1, 1, 1) self.label_5 = QtWidgets.QLabel(parent=sectorDialog) self.label_5.setObjectName("label_5") self.gridLayout.addWidget(self.label_5, 2, 2, 1, 1) @@ -70,11 +77,17 @@ class Ui_sectorDialog(object): self.influenceComboBox.setSizePolicy(sizePolicy) self.influenceComboBox.setObjectName("influenceComboBox") self.gridLayout.addWidget(self.influenceComboBox, 2, 3, 1, 1) + self.label_6 = QtWidgets.QLabel(parent=sectorDialog) + self.label_6.setObjectName("label_6") + self.gridLayout.addWidget(self.label_6, 3, 0, 1, 1) + self.sectorDescription = QtWidgets.QPlainTextEdit(parent=sectorDialog) + self.sectorDescription.setObjectName("sectorDescription") + self.gridLayout.addWidget(self.sectorDescription, 3, 1, 1, 3) self.buttonBox = QtWidgets.QDialogButtonBox(parent=sectorDialog) self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok) self.buttonBox.setObjectName("buttonBox") - self.gridLayout.addWidget(self.buttonBox, 3, 2, 1, 2) + self.gridLayout.addWidget(self.buttonBox, 4, 2, 1, 2) self.retranslateUi(sectorDialog) self.buttonBox.accepted.connect(sectorDialog.accept) # type: ignore @@ -88,7 +101,9 @@ class Ui_sectorDialog(object): self.label_3.setText(_translate("sectorDialog", "Major objective")) self.label.setText(_translate("sectorDialog", "Round")) self.label_4.setText(_translate("sectorDialog", "Minor opportunity")) + self.label_7.setText(_translate("sectorDialog", "Mission")) self.label_5.setText(_translate("sectorDialog", "Influence")) + self.label_6.setText(_translate("sectorDialog", "Description")) if __name__ == "__main__": diff --git a/src/warchron/view/ui/ui_sector_dialog.ui b/src/warchron/view/ui/ui_sector_dialog.ui index 10aecfb..10bf9e6 100644 --- a/src/warchron/view/ui/ui_sector_dialog.ui +++ b/src/warchron/view/ui/ui_sector_dialog.ui @@ -9,8 +9,8 @@ 0 0 - 514 - 129 + 602 + 338 @@ -86,6 +86,20 @@ + + + + Mission + + + + + + + + + + @@ -103,7 +117,17 @@ - + + + + Description + + + + + + + Qt::Horizontal diff --git a/src/warchron/view/view.py b/src/warchron/view/view.py index 67b5708..1ac1198 100644 --- a/src/warchron/view/view.py +++ b/src/warchron/view/view.py @@ -7,6 +7,7 @@ from PyQt6.QtWidgets import QDialog, QFileDialog, QTreeWidgetItem, QMenu from PyQt6.QtGui import QCloseEvent from warchron.constants import ROLE_TYPE, ROLE_ID, ItemType +from warchron.controller.dtos import ParticipantOption from warchron.view.ui.ui_main_window import Ui_MainWindow from warchron.view.ui.ui_player_dialog import Ui_playerDialog from warchron.view.ui.ui_war_dialog import Ui_warDialog @@ -15,7 +16,7 @@ from warchron.view.ui.ui_objective_dialog import Ui_objectiveDialog 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 +from warchron.view.ui.ui_choices_dialog import Ui_choicesDialog # utils... @@ -50,6 +51,11 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): self.show_details(None) self.playersTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.playersTable.customContextMenuRequested.connect(self._on_players_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) + self.addRoundBtn.clicked.connect(self._on_add_round_clicked) + # Pages self.warParticipantsTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.warParticipantsTable.customContextMenuRequested.connect(self._on_war_participants_table_context_menu) self.objectivesTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) @@ -58,10 +64,8 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): 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) - self.addRoundBtn.clicked.connect(self._on_add_round_clicked) + self.choicesTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + self.choicesTable.customContextMenuRequested.connect(self._on_choices_table_context_menu) def _emit_selection_changed(self, current, previous): if not self.on_tree_selection_changed: @@ -374,10 +378,35 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): # Round page + def _on_choices_table_context_menu(self, pos): + 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) + menu = QMenu(self) + edit_action = menu.addAction("Edit") + action = menu.exec(self.choicesTable.viewport().mapToGlobal(pos)) + if action == edit_action and self.on_edit_item: + self.on_edit_item(ItemType.CHOICE, choice_id) + def show_round_details(self, *, index: int): self.roundNb.setText(f"Round {index}") - + def display_round_choices(self, rows: list[dict]): + self.choicesTable.setRowCount(len(rows)) + for row, data in enumerate(rows): + self.choicesTable.setItem(row, 0, QtWidgets.QTableWidgetItem(data["participant_name"])) + self.choicesTable.setItem(row, 1, QtWidgets.QTableWidgetItem(data["priority"])) + self.choicesTable.setItem(row, 2, QtWidgets.QTableWidgetItem(data["secondary"])) + self.choicesTable.item(row, 0).setData( + Qt.ItemDataRole.UserRole, + data["participant_id"] + ) + class PlayerDialog(QDialog): def __init__(self, parent=None, *, default_name: str = ""): super().__init__(parent) @@ -504,3 +533,29 @@ class SectorDialog(QDialog): def get_influence_id(self) -> str: return self.ui.influenceComboBox.currentData() + +class ChoicesDialog(QDialog): + def __init__(self, parent=None, *, participants: list, default_participant_id=None, sectors: list, default_priority_id=None, default_secondary_id=None): + super().__init__(parent) + self.ui = Ui_choicesDialog() + 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(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) + + def get_participant_id(self) -> str: + return self.ui.playerComboBox.currentData() + + def get_priority_id(self) -> str: + return self.ui.priorityComboBox.currentData() + + def get_secondary_id(self) -> str: + return self.ui.secondaryComboBox.currentData() From 9f676f6b9d6a56c98825add059dcf58b33f70809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Fri, 30 Jan 2026 15:32:44 +0100 Subject: [PATCH 2/2] auto create & edit choice --- src/warchron/controller/controller.py | 61 ++++++++++++++------------- src/warchron/model/campaign.py | 33 ++++++++++++--- src/warchron/model/model.py | 45 +++++++++++++++++--- src/warchron/model/round.py | 28 +++++++++--- src/warchron/model/war.py | 33 ++++++++++++--- src/warchron/view/view.py | 25 ++++++----- 6 files changed, 166 insertions(+), 59 deletions(-) diff --git a/src/warchron/controller/controller.py b/src/warchron/controller/controller.py index 46ef82f..64a4c9a 100644 --- a/src/warchron/controller/controller.py +++ b/src/warchron/controller/controller.py @@ -10,14 +10,14 @@ from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, Objectiv class Controller: def __init__(self, model: Model, view: View): - self.model = model - self.view = view + self.model: Model = model + self.view: View = view self.current_file: Path | None = None - self.selected_war_id = None - self.selected_campaign_id = None - self.selected_round_id = None + self.selected_war_id: str = None + self.selected_campaign_id: str = None + self.selected_round_id: str = None self.view.on_close_callback = self.on_app_close - self.is_dirty = False + self.is_dirty: bool = False self.__connect() self.refresh_players_view() self.refresh_wars_view() @@ -165,26 +165,24 @@ class Controller: self.view.display_campaign_participants(participants_for_display) def _fill_round_details(self, round_id: str): - index = self.model.get_round_index(round_id) - self.view.show_round_details(index=index) - camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id) - rows = [] + rnd = self.model.get_round(round_id) + camp = self.model.get_campaign_by_round(round_id) + self.view.show_round_details(index=camp.get_round_index(round_id)) + participants = self.model.get_round_participants(round_id) + choices_for_display = [] for part in participants: - player = self.model.get_player(part.id) choice = rnd.get_choice(part.id) - priority_name = "" - secondary_name = "" - if choice and choice.priority_sector_id: - priority_name = self.model.get_sector(choice.priority_sector_id).name - if choice and choice.secondary_sector_id: - secondary_name = self.model.get_sector(choice.secondary_sector_id).name - rows.append({ - "participant_id": part.id, - "participant_name": player.name, - "priority": priority_name, - "secondary": secondary_name, - }) - self.view.display_round_choices(rows) + if not choice: + choice=self.model.create_choice(round_id=rnd.id, participant_id=part.id) + priority_name = camp.get_sector_name(choice.priority_sector_id) if choice else "" + secondary_name = camp.get_sector_name(choice.secondary_sector_id) if choice else "" + choices_for_display.append(( + self.model.get_player_name(part.id), + priority_name, + secondary_name, + choice.participant_id + )) + self.view.display_round_choices(choices_for_display) def on_tree_selection_changed(self, selection): self.selected_war_id = None @@ -578,6 +576,8 @@ class Controller: self.is_dirty = True self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id) +# Choices methods + def edit_round_choice(self, choice_id: str): round_id = self.selected_round_id if not round_id: @@ -586,11 +586,13 @@ class Controller: choice = rnd.get_choice(choice_id) if not choice: return - participant = camp.participants[choice.participant_id] + part = camp.participants[choice.participant_id] + player = self.model.get_player(part.id) + part_opt = ParticipantOption(id=player.id, name=player.name) dialog = ChoicesDialog( self.view, - participants=[participant], - default_participant_id=participant.id, + participants=[part_opt], + default_participant_id=part.id, sectors=sectors, default_priority_id=choice.priority_sector_id, default_secondary_id=choice.secondary_sector_id, @@ -598,7 +600,8 @@ class Controller: if dialog.exec() != QDialog.DialogCode.Accepted: return rnd.set_choice( - participant_id=participant.id, + participant_id=part.id, priority_sector_id=dialog.get_priority_id(), secondary_sector_id=dialog.get_secondary_id(), - ) \ No newline at end of file + ) + diff --git a/src/warchron/model/campaign.py b/src/warchron/model/campaign.py index 9c36808..4a66536 100644 --- a/src/warchron/model/campaign.py +++ b/src/warchron/model/campaign.py @@ -1,7 +1,7 @@ from __future__ import annotations from uuid import uuid4 -from warchron.model.round import Round +from warchron.model.round import Round, Choice, Battle class Campaign: def __init__(self, name: str, month: int): @@ -10,7 +10,7 @@ class Campaign: self.month: int = month self.participants: dict[str, CampaignParticipant] = {} self.sectors: dict[str, Sector] = {} - self.rounds = [] + self.rounds: list[Round] = [] self.is_over = False def set_id(self, new_id: str): @@ -72,6 +72,8 @@ class Campaign: part.set_theme(theme) def remove_campaign_participant(self, player_id: str): + # TODO manage choices referring to it + # TODO manage battles referring to it del self.participants[player_id] # Sector methods @@ -81,12 +83,18 @@ class Campaign: self.sectors[sect.id] = sect return sect - def get_sector(self, id: str) -> Sector: - return self.sectors[id] + def get_sector(self, sector_id: str) -> Sector: + return self.sectors[sector_id] + + def get_sector_name(self, sector_id: str) -> str: + if sector_id is None: + return "" + return self.sectors[sector_id].name def get_all_sectors(self) -> list[Sector]: return list(self.sectors.values()) + # TODO manage choices referring to it (round order!) def update_sector(self, sector_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str): sect = self.get_sector(sector_id) sect.set_name(name) @@ -96,6 +104,8 @@ class Campaign: sect.set_influence(influence_id) def remove_sector(self, sector_id: str): + # TODO manage choices referring to it + # TODO manage battles referring to it del self.sectors[sector_id] # Round methods @@ -104,7 +114,10 @@ class Campaign: return any(r.id == round_id for r in self.rounds) def get_round(self, round_id: str) -> Round: - return self.rounds[round_id] + for rnd in self.rounds: + if rnd.id == round_id: + return rnd + raise KeyError(f"Round {round_id} not found") def get_all_rounds(self) -> list[Round]: return list(self.rounds) @@ -135,6 +148,16 @@ class Campaign: return rnd.name return "" +# Choice methods + + def create_choice(self, round_id: str, participant_id: str) -> Choice: + rnd = self.get_round(round_id) + return rnd.create_choice(participant_id) + + def remove_choice(self, round_id: str, participant_id: str) -> Choice: + rnd = self.get_round(round_id) + rnd.remove_choice(participant_id) + class CampaignParticipant: def __init__(self,player_id: str, leader: str, theme: str): self.id: str = player_id # ref to War.participants diff --git a/src/warchron/model/model.py b/src/warchron/model/model.py index 4ed5087..85713a6 100644 --- a/src/warchron/model/model.py +++ b/src/warchron/model/model.py @@ -6,7 +6,7 @@ from datetime import datetime from warchron.model.player import Player from warchron.model.war import War, Objective, WarParticipant from warchron.model.campaign import Campaign, Sector, CampaignParticipant -from warchron.model.round import Round +from warchron.model.round import Round, Choice, Battle class Model: def __init__(self): @@ -76,6 +76,7 @@ class Model: return list(self.players.values()) def remove_player(self, player_id: str): + # TODO manage war_participants referring to it del self.players[player_id] # War methods @@ -100,6 +101,22 @@ class Model: return war raise KeyError(f"Campaign {campaign_id} not found in any War") + def get_war_by_sector(self, sector_id: str) -> Campaign: + for war in self.wars.values(): + for camp in war.campaigns: + for sect in camp.sectors.values(): + if sect.id == sector_id: + return camp + raise KeyError(f"Sector {sector_id} not found in any War") + + def get_war_by_round(self, round_id: str) -> Campaign: + for war in self.wars.values(): + for camp in war.campaigns: + for rnd in camp.rounds: + if rnd.id == round_id: + return camp + raise KeyError(f"Round {round_id} not found in any War") + def get_war_by_objective(self, objective_id: str) -> War: for war in self.wars.values(): for obj in war.objectives.values(): @@ -107,6 +124,7 @@ class Model: return war raise KeyError(f"Objective {objective_id} not found in any War") + # TODO don't use this method as participant with same ID (player) can be in several wars! def get_war_by_war_participant(self, participant_id: str) -> War: for war in self.wars.values(): for part in war.participants.values(): @@ -199,6 +217,7 @@ class Model: return camp raise KeyError(f"Round {round_id} not found") + # TODO don't use this method as participant with same ID (player) can be in several campaigns! def get_campaign_by_campaign_participant(self, participant_id: str) -> Campaign: for war in self.wars.values(): camp = war.get_campaign_by_campaign_participant(participant_id) @@ -236,8 +255,8 @@ class Model: raise KeyError("Sector not found") def update_sector(self, sector_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str): - camp = self.get_campaign_by_sector(sector_id) - camp.update_sector(sector_id, name=name, round_id=round_id, major_id=major_id, minor_id=minor_id, influence_id=influence_id) + war = self.get_war_by_sector(sector_id) + war.update_sector(sector_id, name=name, round_id=round_id, major_id=major_id, minor_id=minor_id, influence_id=influence_id) def remove_sector(self, sector_id: str): camp = self.get_campaign_by_sector(sector_id) @@ -286,13 +305,29 @@ class Model: def get_round_index(self, round_id: str) -> int: camp = self.get_campaign_by_round(round_id) return camp.get_round_index(round_id) + + def get_round_sectors(self, round_id: str) -> list[Sector]: + camp = self.get_campaign_by_round(round_id) + return [s for s in camp.sectors.values() if s.round_id == round_id] + + def get_round_participants(self, round_id: str) -> list[CampaignParticipant]: + camp = self.get_campaign_by_round(round_id) + return list(camp.participants.values()) def remove_round(self, round_id: str): - camp = self.get_campaign_by_round(round_id) - camp.remove_round(round_id) + war = self.get_war_by_round(round_id) + war.remove_round(round_id) # Choices methods + def create_choice(self, round_id: str, participant_id: str) -> Choice: + war = self.get_war_by_round(round_id) + return war.create_choice(round_id, participant_id) + + def remove_choice(self, round_id: str, participant_id: str): + war = self.get_war_by_round(round_id) + war.remove_choice(round_id, participant_id) + def get_round_choices_data(self, round_id: str): camp = self.get_campaign_by_round(round_id) rnd = self.get_round(round_id) diff --git a/src/warchron/model/round.py b/src/warchron/model/round.py index e4c2173..d388856 100644 --- a/src/warchron/model/round.py +++ b/src/warchron/model/round.py @@ -4,8 +4,8 @@ from uuid import uuid4 class Round: def __init__(self): self.id: str = str(uuid4()) - self.choices: dict[str, RoundChoice] = {} - self.battles = {} + self.choices: dict[str, Choice] = {} + self.battles: dict[str, Battle] = {} self.is_over: bool = False def set_id(self, new_id: str): @@ -15,7 +15,7 @@ class Round: self.is_over = new_state def set_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None): - self.choices[participant_id] = RoundChoice(participant_id, priority_sector_id, secondary_sector_id) + self.choices[participant_id] = Choice(participant_id, priority_sector_id, secondary_sector_id) def toDict(self): return { @@ -38,12 +38,30 @@ class Round: # Choices methods - def get_choice(self, participant_id: str) -> RoundChoice | None: + def get_choice(self, participant_id: str) -> Choice | None: return self.choices.get(participant_id) + def create_choice(self, participant_id: str) -> Choice: + if participant_id not in self.choices: + choice = Choice( + participant_id=participant_id, + priority_sector_id=None, + secondary_sector_id=None + ) + self.choices[participant_id] = choice + return self.choices[participant_id] -class RoundChoice: + def remove_choice(self,participant_id: str): + del self.choices[participant_id] + +class Choice: def __init__(self, participant_id: str, priority_sector_id: str | None = None, secondary_sector_id: str | None = None): self.participant_id: str = participant_id # ref to Campaign.participants self.priority_sector_id: str | None = priority_sector_id # ref to Campaign.sectors self.secondary_sector_id: str | None = secondary_sector_id # ref to Campaign.sectors + +class Battle: + def __init__(self, sector_id: str, player_1_id: str | None = None, player_2_id: str | None = None): + self.sector_id: str = sector_id # ref to Campaign.sector + self.player_1_id: str | None = player_1_id # ref to Campaign.participants + self.player_2_id: str | None = player_2_id # ref to Campaign.participants diff --git a/src/warchron/model/war.py b/src/warchron/model/war.py index db14c78..8de9951 100644 --- a/src/warchron/model/war.py +++ b/src/warchron/model/war.py @@ -3,6 +3,7 @@ from uuid import uuid4 from datetime import datetime from warchron.model.campaign import Campaign, Sector, CampaignParticipant +from warchron.model.round import Round, Choice, Battle class War: @@ -12,7 +13,7 @@ class War: self.year: int = year self.participants: dict[str, WarParticipant] = {} self.objectives: dict[str, Objective] = {} - self.campaigns = [] + self.campaigns: list[Campaign] = [] self.is_over: bool = False def set_id(self, new_id: str): @@ -72,6 +73,7 @@ class War: obj.set_description(description) def remove_objective(self, objective_id: str): + # TODO manage sectors referring to it del self.objectives[objective_id] # War participant methods @@ -100,6 +102,7 @@ class War: part.set_faction(faction) def remove_war_participant(self, player_id: str): + # TODO manage campaign_participants referring to it del self.participants[player_id] # Campaign methods @@ -167,10 +170,10 @@ class War: def get_sector(self, id: str) -> Sector: return self.sectors[id] - def update_sector(self, objective_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str): - obj = self.get_objective(objective_id) - obj.set_name(name) - + def update_sector(self, sector_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str): + camp = self.get_campaign_by_sector(sector_id) + camp.update_sector(sector_id, name=name, round_id=round_id, major_id=major_id, minor_id=minor_id, influence_id=influence_id) + def remove_sector(self, sector_id: str): camp = self.get_campaign_by_sector(sector_id) camp.remove_sector(sector_id) @@ -204,6 +207,26 @@ class War: camp = self.get_campaign_by_campaign_participant(participant_id) camp.remove_campaign_participant(participant_id) +# Round methods + + def add_round(self, campaign_id: str) -> Round: + camp = self.get_campaign(campaign_id) + return camp.add_round() + + def remove_round(self, round_id: str): + camp = self.get_campaign_by_round(round_id) + camp.remove_round(round_id) + +# Choice methods + + def create_choice(self, round_id: str, participant_id: str) -> Choice: + camp = self.get_campaign_by_round(round_id) + return camp.create_choice(round_id, participant_id) + + def remove_choice(self, round_id: str, participant_id: str): + camp = self.get_campaign_by_round(round_id) + camp.remove_choice(round_id, participant_id) + class Objective: def __init__(self, name: str, description: str): self.id: str = str(uuid4()) diff --git a/src/warchron/view/view.py b/src/warchron/view/view.py index 1ac1198..2f3a452 100644 --- a/src/warchron/view/view.py +++ b/src/warchron/view/view.py @@ -387,6 +387,8 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): if not name_item: return choice_id = name_item.data(Qt.ItemDataRole.UserRole) + if choice_id is None: + return menu = QMenu(self) edit_action = menu.addAction("Edit") action = menu.exec(self.choicesTable.viewport().mapToGlobal(pos)) @@ -396,16 +398,19 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): def show_round_details(self, *, index: int): self.roundNb.setText(f"Round {index}") - def display_round_choices(self, rows: list[dict]): - self.choicesTable.setRowCount(len(rows)) - for row, data in enumerate(rows): - self.choicesTable.setItem(row, 0, QtWidgets.QTableWidgetItem(data["participant_name"])) - self.choicesTable.setItem(row, 1, QtWidgets.QTableWidgetItem(data["priority"])) - self.choicesTable.setItem(row, 2, QtWidgets.QTableWidgetItem(data["secondary"])) - self.choicesTable.item(row, 0).setData( - Qt.ItemDataRole.UserRole, - data["participant_id"] - ) + def display_round_choices(self, participants: list[tuple[str, str, str, str]]): + table = self.choicesTable + table.clearContents() + table.setRowCount(len(participants)) + for row, (participant, priority, secondary, choice_id) in enumerate(participants): + participant_item = QtWidgets.QTableWidgetItem(participant) + priority_item = QtWidgets.QTableWidgetItem(priority) + secondary_item = QtWidgets.QTableWidgetItem(secondary) + participant_item.setData(Qt.ItemDataRole.UserRole, choice_id) + table.setItem(row, 0, participant_item) + table.setItem(row, 1, priority_item) + table.setItem(row, 2, secondary_item) + table.resizeColumnsToContents() class PlayerDialog(QDialog): def __init__(self, parent=None, *, default_name: str = ""):