add campaign & round
This commit is contained in:
parent
9e966baf9b
commit
1218f32752
10 changed files with 365 additions and 24 deletions
50
src/warchron/view/ui/ui_campaign_dialog.py
Normal file
50
src/warchron/view/ui/ui_campaign_dialog.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Form implementation generated from reading ui file '.\src\warchron\view\ui\ui_campaign_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_campaignDialog(object):
|
||||
def setupUi(self, campaignDialog):
|
||||
campaignDialog.setObjectName("campaignDialog")
|
||||
campaignDialog.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
|
||||
campaignDialog.resize(378, 98)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
campaignDialog.setWindowIcon(icon)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=campaignDialog)
|
||||
self.buttonBox.setGeometry(QtCore.QRect(10, 60, 341, 32))
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.label = QtWidgets.QLabel(parent=campaignDialog)
|
||||
self.label.setGeometry(QtCore.QRect(10, 20, 47, 14))
|
||||
self.label.setObjectName("label")
|
||||
self.campaignName = QtWidgets.QLineEdit(parent=campaignDialog)
|
||||
self.campaignName.setGeometry(QtCore.QRect(60, 20, 113, 20))
|
||||
self.campaignName.setObjectName("campaignName")
|
||||
|
||||
self.retranslateUi(campaignDialog)
|
||||
self.buttonBox.accepted.connect(campaignDialog.accept) # type: ignore
|
||||
self.buttonBox.rejected.connect(campaignDialog.reject) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(campaignDialog)
|
||||
|
||||
def retranslateUi(self, campaignDialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
campaignDialog.setWindowTitle(_translate("campaignDialog", "Campaign"))
|
||||
self.label.setText(_translate("campaignDialog", "Name:"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
campaignDialog = QtWidgets.QDialog()
|
||||
ui = Ui_campaignDialog()
|
||||
ui.setupUi(campaignDialog)
|
||||
campaignDialog.show()
|
||||
sys.exit(app.exec())
|
||||
98
src/warchron/view/ui/ui_campaign_dialog.ui
Normal file
98
src/warchron/view/ui/ui_campaign_dialog.ui
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>campaignDialog</class>
|
||||
<widget class="QDialog" name="campaignDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>98</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Campaign</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>../resources/warchron_logo.png</normaloff>../resources/warchron_logo.png</iconset>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>47</width>
|
||||
<height>14</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="campaignName">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>20</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>campaignDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>campaignDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
@ -51,12 +51,16 @@ class Ui_MainWindow(object):
|
|||
self.addCampaignBtn.setEnabled(False)
|
||||
self.addCampaignBtn.setGeometry(QtCore.QRect(110, 20, 91, 23))
|
||||
self.addCampaignBtn.setObjectName("addCampaignBtn")
|
||||
self.addRoundBtn = QtWidgets.QPushButton(parent=self.warsTab)
|
||||
self.addRoundBtn.setEnabled(False)
|
||||
self.addRoundBtn.setGeometry(QtCore.QRect(220, 20, 91, 23))
|
||||
self.addRoundBtn.setObjectName("addRoundBtn")
|
||||
icon2 = QtGui.QIcon()
|
||||
icon2.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/swords-small.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.tabWidget.addTab(self.warsTab, icon2, "")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
|
||||
self.menubar.setObjectName("menubar")
|
||||
self.menuFile = QtWidgets.QMenu(parent=self.menubar)
|
||||
self.menuFile.setObjectName("menuFile")
|
||||
|
|
@ -144,6 +148,7 @@ class Ui_MainWindow(object):
|
|||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.playersTab), _translate("MainWindow", "Players"))
|
||||
self.addWarBtn.setText(_translate("MainWindow", "Add war"))
|
||||
self.addCampaignBtn.setText(_translate("MainWindow", "Add Campaign"))
|
||||
self.addRoundBtn.setText(_translate("MainWindow", "Add Round"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.warsTab), _translate("MainWindow", "Wars"))
|
||||
self.menuFile.setTitle(_translate("MainWindow", "File"))
|
||||
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
||||
|
|
|
|||
|
|
@ -124,6 +124,22 @@
|
|||
<string>Add Campaign</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="addRoundBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<y>20</y>
|
||||
<width>91</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add Round</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
@ -133,7 +149,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
|
|||
|
|
@ -1,18 +1,49 @@
|
|||
from pathlib import Path
|
||||
import calendar
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtWidgets import QDialog, QFileDialog, QTreeWidgetItem
|
||||
from PyQt6.QtGui import QCloseEvent
|
||||
|
||||
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
|
||||
from warchron.view.ui.ui_campaign_dialog import Ui_campaignDialog
|
||||
|
||||
ROLE_TYPE = Qt.ItemDataRole.UserRole
|
||||
ROLE_ID = Qt.ItemDataRole.UserRole + 1
|
||||
|
||||
class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super(View, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.on_close_callback = None
|
||||
self.on_selection_changed = None
|
||||
self.on_add_campaign = None
|
||||
self.on_add_round = None
|
||||
self.warsTree.currentItemChanged.connect(self._emit_selection_changed)
|
||||
self.addCampaignBtn.clicked.connect(self._on_add_campaign_clicked)
|
||||
self.addRoundBtn.clicked.connect(self._on_add_round_clicked)
|
||||
|
||||
def _emit_selection_changed(self, current, previous):
|
||||
if not self.on_tree_selection_changed:
|
||||
return
|
||||
if not current:
|
||||
self.on_tree_selection_changed(None)
|
||||
return
|
||||
self.on_tree_selection_changed({
|
||||
"type": current.data(0, ROLE_TYPE),
|
||||
"id": current.data(0, ROLE_ID),
|
||||
})
|
||||
|
||||
def _on_add_campaign_clicked(self):
|
||||
if self.on_add_campaign:
|
||||
self.on_add_campaign()
|
||||
|
||||
def _on_add_round_clicked(self):
|
||||
if self.on_add_round:
|
||||
self.on_add_round()
|
||||
|
||||
def closeEvent(self, event: QCloseEvent):
|
||||
if self.on_close_callback:
|
||||
|
|
@ -55,10 +86,36 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
tree.setHeaderLabels(["Wars"])
|
||||
for war in wars:
|
||||
war_item = QTreeWidgetItem([f"{war.name} ({war.year})"])
|
||||
war_item.setData(0, 1, war.id) # role=1 to store id
|
||||
war_item.setData(0, ROLE_TYPE, "war")
|
||||
war_item.setData(0, ROLE_ID, war.id)
|
||||
tree.addTopLevelItem(war_item)
|
||||
for camp in war.get_all_campaigns():
|
||||
camp_item = QTreeWidgetItem([f"{camp.name} ({calendar.month_name[camp.month]})"])
|
||||
camp_item.setData(0, ROLE_TYPE, "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([f"Round {index}"])
|
||||
rnd_item.setData(0, ROLE_TYPE, "round")
|
||||
rnd_item.setData(0, ROLE_ID, rnd.id)
|
||||
camp_item.addChild(rnd_item)
|
||||
tree.expandAll()
|
||||
|
||||
def get_selected_tree_item(self):
|
||||
item = self.warsTree.currentItem()
|
||||
if not item:
|
||||
return None
|
||||
return {
|
||||
"type": item.data(0, ROLE_TYPE),
|
||||
"id": item.data(0, ROLE_ID)
|
||||
}
|
||||
|
||||
def set_add_campaign_enabled(self, enabled: bool):
|
||||
self.addCampaignBtn.setEnabled(enabled)
|
||||
|
||||
def set_add_round_enabled(self, enabled: bool):
|
||||
self.addRoundBtn.setEnabled(enabled)
|
||||
|
||||
class PlayerDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
|
@ -76,3 +133,12 @@ class WarDialog(QDialog):
|
|||
|
||||
def get_war_name(self) -> str:
|
||||
return self.ui.warName.text().strip()
|
||||
|
||||
class CampaignDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_campaignDialog()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
def get_campaign_name(self) -> str:
|
||||
return self.ui.campaignName.text().strip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue