From e734468df3a27c0535e55bbc14d3f2d9bc09a72b Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 4 Jul 2023 11:30:50 -0400 Subject: [PATCH] Option for start command to also reset --- res/settings.ui | 34 +++++++++++++++++++++++++++------- src/hotkeys.py | 13 +++++++++++-- src/menu_bar.py | 7 ++++++- src/user_profile.py | 6 ++++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/res/settings.ui b/res/settings.ui index 73d13bda..1711b9b1 100644 --- a/res/settings.ui +++ b/res/settings.ui @@ -8,7 +8,7 @@ 0 0 285 - 274 + 294 @@ -20,7 +20,7 @@ 310 - 290 + 294 @@ -41,7 +41,7 @@ -3 -3 291 - 281 + 301 @@ -551,7 +551,7 @@ reset image 144 - 205 + 220 71 31 @@ -599,7 +599,7 @@ reset image 10 - 153 + 170 261 24 @@ -691,9 +691,9 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be 10 - 180 + 200 261 - 71 + 61 @@ -801,6 +801,25 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be Default Delay Time (ms): + + + + 10 + 150 + 261 + 24 + + + + Start also Resets + + + false + + + false + + custom_image_settings_info_label default_delay_time_spinbox enable_auto_reset_image_checkbox @@ -813,6 +832,7 @@ It is highly recommended to NOT use pHash if you use masked images, or it'll be default_pause_time_label default_delay_time_label readme_link_button + start_also_resets_checkbox diff --git a/src/hotkeys.py b/src/hotkeys.py index 602c7ab4..1177ea8b 100644 --- a/src/hotkeys.py +++ b/src/hotkeys.py @@ -50,9 +50,18 @@ def after_setting_hotkey(autosplit: AutoSplit): def send_command(autosplit: AutoSplit, command: Commands): + # Note: Rather than having the start image able to also reset the timer, + # having the reset image check be active at all time would be a better, more organic solution, + # but that is dependant on migrating to an observer pattern (#219) and being able to reload all images. if autosplit.is_auto_controlled: + if command == "start" and autosplit.settings_dict["start_also_resets"]: + print("reset", flush=True) print(command, flush=True) - elif command in {"split", "start"}: + elif command == "start": + if autosplit.settings_dict["start_also_resets"]: + _send_hotkey(autosplit.settings_dict["reset_hotkey"]) + _send_hotkey(autosplit.settings_dict["split_hotkey"]) + elif command == "split": _send_hotkey(autosplit.settings_dict["split_hotkey"]) elif command == "pause": _send_hotkey(autosplit.settings_dict["pause_hotkey"]) @@ -64,7 +73,7 @@ def send_command(autosplit: AutoSplit, command: Commands): _send_hotkey(autosplit.settings_dict["undo_split_hotkey"]) else: - raise KeyError(f"{command!r} is not a valid LiveSplit.AutoSplitIntegration command") + raise KeyError(f"{command!r} is not a valid command") def _unhook(hotkey_callback: Callable[[], None] | None): diff --git a/src/menu_bar.py b/src/menu_bar.py index b4869053..0941e8a2 100644 --- a/src/menu_bar.py +++ b/src/menu_bar.py @@ -315,6 +315,7 @@ def hotkey_connect(hotkey: Hotkey): self.default_delay_time_spinbox.setValue(self.autosplit.settings_dict["default_delay_time"]) self.default_pause_time_spinbox.setValue(self.autosplit.settings_dict["default_pause_time"]) self.loop_splits_checkbox.setChecked(self.autosplit.settings_dict["loop_splits"]) + self.start_also_resets_checkbox.setChecked(self.autosplit.settings_dict["start_also_resets"]) self.enable_auto_reset_image_checkbox.setChecked(self.autosplit.settings_dict["enable_auto_reset"]) # endregion # region Binding @@ -350,6 +351,9 @@ def hotkey_connect(hotkey: Hotkey): self.loop_splits_checkbox.stateChanged.connect( lambda: self.__set_value("loop_splits", self.loop_splits_checkbox.isChecked()), ) + self.start_also_resets_checkbox.stateChanged.connect( + lambda: self.__set_value("start_also_resets", self.start_also_resets_checkbox.isChecked()), + ) self.enable_auto_reset_image_checkbox.stateChanged.connect( lambda: self.__set_value("enable_auto_reset", self.enable_auto_reset_image_checkbox.isChecked()), ) @@ -375,7 +379,6 @@ def get_default_settings_from_ui(autosplit: AutoSplit): "toggle_auto_reset_image_hotkey": default_settings_dialog.toggle_auto_reset_image_input.text(), "fps_limit": default_settings_dialog.fps_limit_spinbox.value(), "live_capture_region": default_settings_dialog.live_capture_region_checkbox.isChecked(), - "enable_auto_reset": default_settings_dialog.enable_auto_reset_image_checkbox.isChecked(), "capture_method": CAPTURE_METHODS.get_method_by_index( default_settings_dialog.capture_method_combobox.currentIndex(), ), @@ -386,6 +389,8 @@ def get_default_settings_from_ui(autosplit: AutoSplit): "default_delay_time": default_settings_dialog.default_delay_time_spinbox.value(), "default_pause_time": default_settings_dialog.default_pause_time_spinbox.value(), "loop_splits": default_settings_dialog.loop_splits_checkbox.isChecked(), + "start_also_resets": default_settings_dialog.start_also_resets_checkbox.isChecked(), + "enable_auto_reset": default_settings_dialog.enable_auto_reset_image_checkbox.isChecked(), "split_image_directory": autosplit.split_image_folder_input.text(), "screenshot_directory": default_settings_dialog.screenshot_directory_input.text(), "open_screenshot": default_settings_dialog.open_screenshot_checkbox.isChecked(), diff --git a/src/user_profile.py b/src/user_profile.py index 155ec562..92a28255 100644 --- a/src/user_profile.py +++ b/src/user_profile.py @@ -26,7 +26,6 @@ class UserProfileDict(TypedDict): toggle_auto_reset_image_hotkey: str fps_limit: int live_capture_region: bool - enable_auto_reset: bool capture_method: str | CaptureMethodEnum capture_device_id: int capture_device_name: str @@ -35,6 +34,8 @@ class UserProfileDict(TypedDict): default_delay_time: int default_pause_time: float loop_splits: bool + start_also_resets: bool + enable_auto_reset: bool split_image_directory: str screenshot_directory: str open_screenshot: bool @@ -52,7 +53,6 @@ class UserProfileDict(TypedDict): toggle_auto_reset_image_hotkey="", fps_limit=60, live_capture_region=True, - enable_auto_reset=True, capture_method=CAPTURE_METHODS.get_method_by_index(0), capture_device_id=0, capture_device_name="", @@ -61,6 +61,8 @@ class UserProfileDict(TypedDict): default_delay_time=0, default_pause_time=10, loop_splits=False, + start_also_resets=False, + enable_auto_reset=True, split_image_directory="", screenshot_directory="", open_screenshot=True,