This commit is contained in:
Auric Vente 2024-07-22 19:53:12 -06:00
parent 2b9eb8a4fd
commit d65916fc4e
4 changed files with 90 additions and 33 deletions

View File

@ -56,6 +56,7 @@ class Config:
merge_goal: int = 10 merge_goal: int = 10
manifest_path: Path manifest_path: Path
manifest: dict[str, str] manifest: dict[str, str]
separator_color: str = "rgb(120, 120, 120)"
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:

View File

@ -367,16 +367,6 @@ class Game:
Settings.set_speed(speed) Settings.set_speed(speed)
Game.start_loop() Game.start_loop()
@staticmethod
def update_mode() -> None:
mode = Window.mode.currentText().lower()
if mode == Settings.mode:
return
Settings.set_mode(mode)
Game.start_loop()
@staticmethod @staticmethod
def info() -> None: def info() -> None:
text = [] text = []
@ -469,19 +459,55 @@ class Game:
menu = QMenu(Window.root.widget()) menu = QMenu(Window.root.widget())
update = QAction("Update") update = QAction("Update")
restart = QAction("Restart") restart = QAction("Restart")
enable_all = QAction("Enable All")
disable_all = QAction("Disable All")
if Settings.merge: if Settings.merge:
merge = QAction("Merge: On") merge = QAction("Merge: On")
else: else:
merge = QAction("Merge: Off") merge = QAction("Merge: Off")
if Settings.score_enabled:
score = QAction("Score: On")
else:
score = QAction("Score: Off")
if Settings.travel_enabled:
travel = QAction("Travel: On")
else:
travel = QAction("Travel: Off")
if Settings.thoughts_enabled:
thoughts = QAction("Thoughts: On")
else:
thoughts = QAction("Thoughts: Off")
if Settings.words_enabled:
words = QAction("Words: On")
else:
words = QAction("Words: Off")
update.triggered.connect(Game.force_update) update.triggered.connect(Game.force_update)
restart.triggered.connect(Game.restart) restart.triggered.connect(Game.restart)
merge.triggered.connect(Settings.toggle_merge) merge.triggered.connect(Settings.toggle_merge)
score.triggered.connect(Settings.toggle_score_enabled)
travel.triggered.connect(Settings.toggle_travel_enabled)
thoughts.triggered.connect(Settings.toggle_thoughts_enabled)
words.triggered.connect(Settings.toggle_words_enabled)
enable_all.triggered.connect(Settings.enable_all)
disable_all.triggered.connect(Settings.disable_all)
menu.addAction(update) menu.addAction(update)
menu.addAction(restart) menu.addAction(restart)
menu.addSeparator()
menu.addAction(merge) menu.addAction(merge)
menu.addAction(score)
menu.addAction(travel)
menu.addAction(thoughts)
menu.addAction(words)
menu.addSeparator()
menu.addAction(enable_all)
menu.addAction(disable_all)
menu.exec_(QCursor.pos()) menu.exec_(QCursor.pos())
@staticmethod @staticmethod

View File

@ -9,6 +9,11 @@ class Settings:
mode: str mode: str
merge: bool merge: bool
score_enabled: bool
travel_enabled: bool
thoughts_enabled: bool
words_enabled: bool
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
settings = Storage.get_settings() settings = Storage.get_settings()
@ -17,9 +22,10 @@ class Settings:
speed = Settings.speed.capitalize() speed = Settings.speed.capitalize()
Window.speed.setCurrentText(speed) Window.speed.setCurrentText(speed)
Settings.mode = settings.get("mode", "all") Settings.score_enabled = settings.get("score_enabled", True)
mode = Settings.mode.capitalize() Settings.travel_enabled = settings.get("travel_enabled", True)
Window.mode.setCurrentText(mode) Settings.thoughts_enabled = settings.get("thoughts_enabled", True)
Settings.words_enabled = settings.get("words_enabled", True)
Settings.merge = settings.get("merge", True) Settings.merge = settings.get("merge", True)
@ -27,8 +33,11 @@ class Settings:
def save() -> None: def save() -> None:
settings = { settings = {
"speed": Settings.speed, "speed": Settings.speed,
"mode": Settings.mode,
"merge": Settings.merge, "merge": Settings.merge,
"score_enabled": Settings.score_enabled,
"travel_enabled": Settings.travel_enabled,
"thoughts_enabled": Settings.thoughts_enabled,
"words_enabled": Settings.words_enabled,
} }
Storage.save_settings(settings) Storage.save_settings(settings)
@ -38,12 +47,43 @@ class Settings:
Settings.speed = speed Settings.speed = speed
Settings.save() Settings.save()
@staticmethod
def set_mode(mode: str) -> None:
Settings.mode = mode
Settings.save()
@staticmethod @staticmethod
def toggle_merge() -> None: def toggle_merge() -> None:
Settings.merge = not Settings.merge Settings.merge = not Settings.merge
Settings.save() Settings.save()
@staticmethod
def toggle_score_enabled() -> None:
Settings.score_enabled = not Settings.score_enabled
Settings.save()
@staticmethod
def toggle_travel_enabled() -> None:
Settings.travel_enabled = not Settings.travel_enabled
Settings.save()
@staticmethod
def toggle_thoughts_enabled() -> None:
Settings.thoughts_enabled = not Settings.thoughts_enabled
Settings.save()
@staticmethod
def toggle_words_enabled() -> None:
Settings.words_enabled = not Settings.words_enabled
Settings.save()
@staticmethod
def enable_all() -> None:
Settings.score_enabled = True
Settings.travel_enabled = True
Settings.thoughts_enabled = True
Settings.words_enabled = True
Settings.save()
@staticmethod
def disable_all() -> None:
Settings.score_enabled = False
Settings.travel_enabled = False
Settings.thoughts_enabled = False
Settings.words_enabled = False
Settings.save()

View File

@ -87,7 +87,6 @@ class Window:
player: QMediaPlayer player: QMediaPlayer
audio: QAudioOutput audio: QAudioOutput
filter: QLineEdit filter: QLineEdit
mode: QComboBox
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
@ -210,6 +209,10 @@ class Window:
color: white; color: white;
}} }}
QMenu::separator {{
background-color: {Config.separator_color};
}}
""".strip() """.strip()
Window.app.setStyleSheet(style) Window.app.setStyleSheet(style)
@ -237,18 +240,6 @@ class Window:
Window.speed.setCurrentIndex(1) Window.speed.setCurrentIndex(1)
Window.speed.currentIndexChanged.connect(Game.update_speed) Window.speed.currentIndexChanged.connect(Game.update_speed)
Window.mode = QComboBox()
tooltip = "The type of updates\n"
tooltip += "All: All kind of updates\n"
tooltip += "Score: Only triumph and hit updates\n"
tooltip += "Travel: Only travel updates\n"
tooltip += "Thought: Only thought updates\n"
tooltip += "Words: Only sentences"
Window.mode.setToolTip(tooltip)
Window.mode.addItems(["All", "Score", "Travel", "Thought", "Words"])
Window.mode.setCurrentIndex(1)
Window.mode.currentIndexChanged.connect(Game.update_mode)
Window.filter = FilterLineEdit() Window.filter = FilterLineEdit()
Window.filter.setPlaceholderText("Filter") Window.filter.setPlaceholderText("Filter")
Window.filter.mousePressEvent = lambda e: Window.to_top() Window.filter.mousePressEvent = lambda e: Window.to_top()
@ -256,7 +247,6 @@ class Window:
container.addWidget(btn_menu, 1) container.addWidget(btn_menu, 1)
container.addWidget(Window.speed, 1) container.addWidget(Window.speed, 1)
container.addWidget(Window.mode, 1)
container.addWidget(Window.filter, 1) container.addWidget(Window.filter, 1)
root.setLayout(container) root.setLayout(container)