diff --git a/changelog.md b/changelog.md index 1b5d2386..fd71f412 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ Saves from 4.0.0 are compatible with 4.0.1. ## Features/Improvements +* **[UI]** Added ability to take notes and have those notes appear as a kneeboard page. * **[UI]** Hovering over the weather information now dispalys the cloud base (meters and feet). * **[UI]** Google search link added to unit information when there is no information provided. diff --git a/game/game.py b/game/game.py index 80867ecd..3a783e40 100644 --- a/game/game.py +++ b/game/game.py @@ -110,6 +110,7 @@ class Game: self.date = date(start_date.year, start_date.month, start_date.day) self.game_stats = GameStats() self.game_stats.update(self) + self.notes = "" self.ground_planners: dict[int, GroundPlanner] = {} self.informations = [] self.informations.append(Information("Game Start", "-" * 40, 0)) diff --git a/gen/kneeboard.py b/gen/kneeboard.py index 62fd9d25..9a074940 100644 --- a/gen/kneeboard.py +++ b/gen/kneeboard.py @@ -554,6 +554,28 @@ class StrikeTaskPage(KneeboardPage): ] +class NotesPage(KneeboardPage): + """A kneeboard page containing the campaign owner's notes.""" + + def __init__( + self, + game: "Game", + dark_kneeboard: bool, + ) -> None: + self.game = game + self.dark_kneeboard = dark_kneeboard + + def write(self, path: Path) -> None: + writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) + writer.title(f"Notes") + + try: + writer.text(self.game.notes) + except AttributeError: # old saves may not have .notes ;) + writer.text("") + writer.write(path) + + class KneeboardGenerator(MissionInfoGenerator): """Creates kneeboard pages for each client flight in the mission.""" @@ -621,6 +643,10 @@ class KneeboardGenerator(MissionInfoGenerator): self.mission.start_time, self.dark_kneeboard, ), + NotesPage( + self.game, + self.dark_kneeboard, + ), ] if (target_page := self.generate_task_page(flight)) is not None: diff --git a/qt_ui/uiconstants.py b/qt_ui/uiconstants.py index 30ee7adf..e36ffb7e 100644 --- a/qt_ui/uiconstants.py +++ b/qt_ui/uiconstants.py @@ -106,6 +106,7 @@ def load_icons(): ICONS["PluginsOptions"] = QPixmap( "./resources/ui/misc/" + get_theme_icons() + "/pluginsoptions.png" ) + ICONS["Notes"] = QPixmap("./resources/ui/misc/" + get_theme_icons() + "/notes.png") ICONS["TaskCAS"] = QPixmap("./resources/ui/tasks/cas.png") ICONS["TaskCAP"] = QPixmap("./resources/ui/tasks/cap.png") diff --git a/qt_ui/windows/QLiberationWindow.py b/qt_ui/windows/QLiberationWindow.py index e4d7f403..1cc946fd 100644 --- a/qt_ui/windows/QLiberationWindow.py +++ b/qt_ui/windows/QLiberationWindow.py @@ -36,6 +36,7 @@ from qt_ui.windows.preferences.QLiberationPreferencesWindow import ( ) from qt_ui.windows.settings.QSettingsWindow import QSettingsWindow from qt_ui.windows.stats.QStatsWindow import QStatsWindow +from qt_ui.windows.notes.QNotesWindow import QNotesWindow class QLiberationWindow(QMainWindow): @@ -158,6 +159,10 @@ class QLiberationWindow(QMainWindow): self.openStatsAction.setIcon(CONST.ICONS["Statistics"]) self.openStatsAction.triggered.connect(self.showStatsDialog) + self.openNotesAction = QAction("Notes", self) + self.openNotesAction.setIcon(CONST.ICONS["Notes"]) + self.openNotesAction.triggered.connect(self.showNotesDialog) + def initToolbar(self): self.tool_bar = self.addToolBar("File") self.tool_bar.addAction(self.newGameAction) @@ -171,6 +176,7 @@ class QLiberationWindow(QMainWindow): self.actions_bar = self.addToolBar("Actions") self.actions_bar.addAction(self.openSettingsAction) self.actions_bar.addAction(self.openStatsAction) + self.actions_bar.addAction(self.openNotesAction) def initMenuBar(self): self.menu = self.menuBar() @@ -351,6 +357,10 @@ class QLiberationWindow(QMainWindow): self.dialog = QStatsWindow(self.game) self.dialog.show() + def showNotesDialog(self): + self.dialog = QNotesWindow(self.game) + self.dialog.show() + def onDebriefing(self, debrief: Debriefing): logging.info("On Debriefing") self.debriefing = QDebriefingWindow(debrief) diff --git a/qt_ui/windows/notes/QNotesWindow.py b/qt_ui/windows/notes/QNotesWindow.py new file mode 100644 index 00000000..cb1419b5 --- /dev/null +++ b/qt_ui/windows/notes/QNotesWindow.py @@ -0,0 +1,67 @@ +from PySide2.QtWidgets import ( + QDialog, + QPlainTextEdit, + QVBoxLayout, + QHBoxLayout, + QPushButton, + QLabel, +) +from PySide2.QtGui import QTextCursor +from PySide2.QtCore import QTimer + +import qt_ui.uiconstants as CONST +from game.game import Game + +from time import sleep + + +class QNotesWindow(QDialog): + def __init__(self, game: Game): + super(QNotesWindow, self).__init__() + + self.game = game + self.setWindowTitle("Notes") + self.setWindowIcon(CONST.ICONS["Notes"]) + self.setMinimumSize(400, 100) + self.resize(600, 450) + + self.vbox = QVBoxLayout() + self.setLayout(self.vbox) + + self.vbox.addWidget( + QLabel("Saved notes are available as a page in your kneeboard.") + ) + + self.textbox = QPlainTextEdit(self) + try: + self.textbox.setPlainText(self.game.notes) + self.textbox.moveCursor(QTextCursor.End) + except AttributeError: # old save may not have game.notes + pass + self.textbox.move(10, 10) + self.textbox.resize(600, 450) + self.textbox.setStyleSheet("background: #1D2731;") + self.vbox.addWidget(self.textbox) + + self.button_row = QHBoxLayout() + self.vbox.addLayout(self.button_row) + + self.clear_button = QPushButton(self) + self.clear_button.setText("CLEAR") + self.clear_button.setProperty("style", "btn-primary") + self.clear_button.clicked.connect(self.clearNotes) + self.button_row.addWidget(self.clear_button) + + self.save_button = QPushButton(self) + self.save_button.setText("SAVE") + self.save_button.setProperty("style", "btn-success") + self.save_button.clicked.connect(self.saveNotes) + self.button_row.addWidget(self.save_button) + + def clearNotes(self) -> None: + self.textbox.setPlainText("") + + def saveNotes(self) -> None: + self.game.notes = self.textbox.toPlainText() + self.save_button.setText("SAVED") + QTimer.singleShot(5000, lambda: self.save_button.setText("SAVE")) diff --git a/resources/ui/misc/dark/notes.png b/resources/ui/misc/dark/notes.png new file mode 100644 index 00000000..2bb0f1eb Binary files /dev/null and b/resources/ui/misc/dark/notes.png differ diff --git a/resources/ui/misc/light/notes.png b/resources/ui/misc/light/notes.png new file mode 100644 index 00000000..9f1300fc Binary files /dev/null and b/resources/ui/misc/light/notes.png differ diff --git a/resources/ui/misc/notes.png b/resources/ui/misc/notes.png new file mode 100644 index 00000000..9f1300fc Binary files /dev/null and b/resources/ui/misc/notes.png differ diff --git a/resources/ui/misc/original/notes.png b/resources/ui/misc/original/notes.png new file mode 100644 index 00000000..1223307a Binary files /dev/null and b/resources/ui/misc/original/notes.png differ