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] 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()