Opt: Reduce click retry when passing by page_main

This commit is contained in:
LmeSzinc 2023-09-03 00:12:52 +08:00
parent 625e9b08f0
commit 438ae6f488

View File

@ -13,6 +13,7 @@ from tasks.combat.assets.assets_combat_prepare import COMBAT_PREPARE
class UI(PopupHandler):
ui_current: Page
ui_main_confirm_timer = Timer(0.2, count=0)
def ui_page_appear(self, page):
"""
@ -112,6 +113,8 @@ class UI(PopupHandler):
# Destination page
if self.ui_page_appear(destination):
logger.info(f'Page arrive: {destination}')
if self.ui_page_confirm(destination):
logger.info(f'Page arrive confirm {destination}')
break
# Other pages
@ -121,6 +124,8 @@ class UI(PopupHandler):
continue
if self.appear(page.check_button, interval=5):
logger.info(f'Page switch: {page} -> {page.parent}')
if self.ui_page_confirm(page):
logger.info(f'Page arrive confirm {page}')
button = page.links[page.parent]
self.device.click(button)
self.ui_button_interval_reset(button)
@ -287,6 +292,45 @@ class UI(PopupHandler):
return False
def _ui_button_confirm(
self,
button,
confirm=Timer(0.1, count=0),
timeout=Timer(2, count=6),
skip_first_screenshot=True
):
confirm.reset()
timeout.reset()
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if timeout.reached():
logger.warning(f'_ui_button_confirm({button}) timeout')
break
if self.appear(button):
if confirm.reached():
break
else:
confirm.reset()
def ui_page_confirm(self, page):
"""
Args:
page (Page):
Returns:
bool: If handled
"""
if page == page_main:
self._ui_button_confirm(page.check_button)
return True
return False
def ui_button_interval_reset(self, button):
"""
Reset interval of some button to avoid mistaken clicks