diff --git a/assets/templates/ui/ingame_menu/game_menu_highlight.png b/assets/templates/ui/ingame_menu/game_menu_highlight.png new file mode 100644 index 0000000..7acd08a Binary files /dev/null and b/assets/templates/ui/ingame_menu/game_menu_highlight.png differ diff --git a/assets/templates/ui/ingame_menu/save_and_exit_highlight.png b/assets/templates/ui/ingame_menu/save_and_exit_highlight.png deleted file mode 100644 index e571422..0000000 Binary files a/assets/templates/ui/ingame_menu/save_and_exit_highlight.png and /dev/null differ diff --git a/assets/templates/ui/ingame_menu/save_and_exit_no_highlight.png b/assets/templates/ui/ingame_menu/save_and_exit_no_highlight.png deleted file mode 100644 index ea4b32c..0000000 Binary files a/assets/templates/ui/ingame_menu/save_and_exit_no_highlight.png and /dev/null differ diff --git a/config/game.ini b/config/game.ini index 9176723..54fb5a3 100644 --- a/config/game.ini +++ b/config/game.ini @@ -84,6 +84,7 @@ xp_bar_y=665 ; all rois are in [left, top, width, height] format chat_line_1=12,537,391,25 save_and_exit=500,233,273,173 +game_menu_left=530,250,20,134 play_btn=426,616,320,71 difficulty_select=536,236,210,320 gold_btn=997,521,20,18 diff --git a/src/game_recovery.py b/src/game_recovery.py index c90d8f0..435d30e 100644 --- a/src/game_recovery.py +++ b/src/game_recovery.py @@ -33,7 +33,7 @@ class GameRecovery: time.sleep(1) continue # check for save/exit button - if is_visible(ScreenObjects.SaveAndExit): + if is_visible(ScreenObjects.GameMenu): view.save_and_exit() continue # maybe we are in-game in stash/inventory, press escape diff --git a/src/health_manager.py b/src/health_manager.py index 7cfe5b4..19f8a67 100644 --- a/src/health_manager.py +++ b/src/health_manager.py @@ -57,19 +57,15 @@ class HealthManager: if self._callback is not None: self._callback() self._callback = None + # clean up key presses that might be pressed in the run_thread + keyboard.release(Config().char["stand_still"]) + keyboard.release(Config().char["show_items"]) + mouse.release(button="left") + mouse.release(button="right") + view.save_and_exit() if Config().general["info_screenshots"]: self._last_chicken_screenshot = "./info_screenshots/info_debug_chicken_" + time.strftime("%Y%m%d_%H%M%S") + ".png" cv2.imwrite(self._last_chicken_screenshot, img) - # clean up key presses that might be pressed in the run_thread - keyboard.release(Config().char["stand_still"]) - wait(0.02, 0.05) - keyboard.release(Config().char["show_items"]) - wait(0.02, 0.05) - mouse.release(button="left") - wait(0.02, 0.05) - mouse.release(button="right") - time.sleep(0.01) - view.save_and_exit() self._did_chicken = True set_pause_state(True) diff --git a/src/ui/view.py b/src/ui/view.py index a278d64..5fc21e4 100644 --- a/src/ui/view.py +++ b/src/ui/view.py @@ -36,24 +36,26 @@ def save_and_exit() -> bool: Performes save and exit action from within game :return: Bool if action was successful """ - # if exit button isn't detected already, press escape - attempts = 1 + attempts = 0 success = False - while attempts <= 2 and not success: - if not (exit_button := detect_screen_object(ScreenObjects.SaveAndExit)).valid: + while attempts < 2 and not success: + # if exit button isn't detected already, press escape + while not (highlight := detect_screen_object(ScreenObjects.GameMenu)).valid: keyboard.send("esc") - # wait for exit button to appear - exit_button = wait_until_visible(ScreenObjects.SaveAndExit, 3) - # if exit button is found, double click it to be sure - if exit_button.valid: - select_screen_object_match(exit_button, delay_factor=(0.1, 0.3)) - wait(0.1, 0.2) - mouse.click(button="left") - # if center icon on player bar disappears then save/exit was successful - success = wait_until_hidden(ScreenObjects.InGame, 3) + time.sleep(0.02) + roi = Config().ui_roi[ScreenObjects.GameMenu.roi] + y_pos = (highlight.center[1] - roi[1]) / roi[3] + if y_pos > 0.6: + keyboard.send("up") + time.sleep(0.005) + elif y_pos < 0.4: + keyboard.send("down") + time.sleep(0.005) + keyboard.send("enter") + # if center icon on player bar disappears then save/exit was successful + if not (success := wait_until_hidden(ScreenObjects.InGame, 3)): + Logger.debug("Failed to find or click save/exit button") attempts += 1 - if not success: - Logger.debug("Failed to find or click save/exit button") return success def dismiss_skills_icon() -> bool: @@ -78,7 +80,7 @@ def move_to_corpse(): mouse.move(*pos) def return_to_play() -> bool: - substrings = ["NPC", "Panel", "SaveAndExit"] + substrings = ["NPC", "Panel", "GameMenu"] img=grab() start=time.time() while (elapsed := (time.time() - start) < 8): diff --git a/src/ui_manager.py b/src/ui_manager.py index 46048c2..f7b3fe3 100644 --- a/src/ui_manager.py +++ b/src/ui_manager.py @@ -108,10 +108,12 @@ class ScreenObjects: ServerError=ScreenObject( ref=["SERVER_ISSUES"] ) - SaveAndExit=ScreenObject( - ref=["SAVE_AND_EXIT_NO_HIGHLIGHT", "SAVE_AND_EXIT_HIGHLIGHT"], - roi="save_and_exit", - threshold=0.85 + GameMenu=ScreenObject( + ref=["GAME_MENU_HIGHLIGHT"], + roi="game_menu_left", + best_match=True, + threshold=0.95, + normalize_monitor=False ) NeedRepair=ScreenObject( ref="REPAIR_NEEDED",