Enhancement: Faster save and exit using keyboard (#697)
* Enhancement: Faster save and exit using keyboard * Enhancement: faster chicken 1) Remove delay among key/mouse release (human can do it simutaneously 2) Save screenshot after save_and_exit
This commit is contained in:
BIN
assets/templates/ui/ingame_menu/game_menu_highlight.png
Normal file
BIN
assets/templates/ui/ingame_menu/game_menu_highlight.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user