From ade8f9486c418c92453aabaab623dbf9ebe1d168 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Fri, 19 Jul 2024 20:17:07 -0600 Subject: [PATCH] Mods --- cromulant/ants.py | 9 +++++++++ cromulant/config.py | 9 ++++++++- cromulant/window.py | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/cromulant/ants.py b/cromulant/ants.py index c88927e..518887c 100644 --- a/cromulant/ants.py +++ b/cromulant/ants.py @@ -65,6 +65,7 @@ class Ants: from .game import Game if len(Ants.ants) >= Config.max_ants: + Window.alert("Max ants reached\nTerminate some to hatch new ones") return now = Utils.now() @@ -152,12 +153,20 @@ class Ants: @staticmethod def get_ants() -> None: objs = Storage.get_ants() + changed = False + + if len(objs) > Config.max_ants: + objs = objs[: Config.max_ants] + changed = True for obj in objs: ant = Ant() ant.from_dict(obj) Ants.ants.append(ant) + if changed: + Ants.save() + @staticmethod def most_hits() -> Ant | None: if not len(Ants.ants): diff --git a/cromulant/config.py b/cromulant/config.py index 2aea5df..269b4af 100644 --- a/cromulant/config.py +++ b/cromulant/config.py @@ -9,7 +9,7 @@ class Config: title: str = "Cromulant" width: int = 900 height: int = 900 - max_ants: int = 100 + max_ants: int = 10 here: Path ants_json: Path icon_path: Path @@ -42,6 +42,13 @@ class Config: context_menu_text_color: str = "white" context_menu_hover_background_color: str = "rgb(36, 36, 36)" context_menu_hover_text_color: str = "white" + message_box_background_color: str = "rgb(22, 22, 22)" + message_box_text_color: str = "white" + message_box_label_text_color: str = "white" + message_box_button_background_color: str = "rgb(44, 44, 44)" + message_box_button_text_color: str = "white" + message_box_button_hover_background_color: str = "rgb(66, 66, 66)" + message_box_button_hover_text_color: str = "white" @staticmethod def prepare() -> None: diff --git a/cromulant/window.py b/cromulant/window.py index 0153984..0ed8e03 100644 --- a/cromulant/window.py +++ b/cromulant/window.py @@ -71,7 +71,11 @@ class Window: Window.root.setAlignment(Qt.AlignTop) Window.window.setCentralWidget(central_widget) Window.window.setWindowIcon(QIcon(str(Config.icon_path))) + Window.root.setContentsMargins(0, 0, 0, 0) + Window.set_style() + @staticmethod + def set_style() -> None: font_id = QFontDatabase.addApplicationFont(str(Config.font_path)) emoji_font_id = QFontDatabase.addApplicationFont(str(Config.emoji_font_path)) @@ -97,11 +101,30 @@ class Window: background-color: {Config.context_menu_hover_background_color}; color: {Config.context_menu_hover_text_color}; }} + + QMessageBox {{ + background-color: {Config.message_box_background_color}; + color: {Config.message_box_text_color}; + }} + + QMessageBox QLabel {{ + background-color: {Config.message_box_background_color}; + color: {Config.message_box_label_text_color}; + }} + + QMessageBox QPushButton {{ + background-color: {Config.message_box_button_background_color}; + color: {Config.message_box_button_text_color}; + }} + + QMessageBox QPushButton:hover {{ + background-color: {Config.message_box_button_hover_background_color}; + color: {Config.message_box_button_hover_text_color}; + }} """.strip() Window.app.setStyleSheet(style) Window.app.setFont(Window.font) - Window.root.setContentsMargins(0, 0, 0, 0) @staticmethod def add_buttons() -> None: @@ -245,3 +268,12 @@ class Window: @staticmethod def stop_audio() -> None: Window.player.stop() + + @staticmethod + def alert(message: str) -> None: + msg_box = QMessageBox() + msg_box.setIcon(QMessageBox.Information) + msg_box.setText(message) + msg_box.setWindowTitle("Information") + msg_box.setStandardButtons(QMessageBox.Ok) + msg_box.exec() \ No newline at end of file