From 438ae6f488b419b0cc7d643b70ca1f35893e4406 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 3 Sep 2023 00:12:52 +0800 Subject: [PATCH] Opt: Reduce click retry when passing by page_main --- tasks/base/ui.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tasks/base/ui.py b/tasks/base/ui.py index 80bf47fe5..21abe365f 100644 --- a/tasks/base/ui.py +++ b/tasks/base/ui.py @@ -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