From b4ea8c335e57e62c26f789c0408a18ea45666016 Mon Sep 17 00:00:00 2001 From: Chen Jin <243284244@qq.com> Date: Sat, 17 Oct 2026 16:54:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(GameUi):=20=E8=BF=87=E5=9B=BE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E7=AD=89=E5=BE=85=E5=8F=AF=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=B8=8D=E5=86=8D=E7=9B=B2=E7=82=B9?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/GameUi/navigator.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tasks/GameUi/navigator.py b/tasks/GameUi/navigator.py index 26fe85658..921f678cc 100644 --- a/tasks/GameUi/navigator.py +++ b/tasks/GameUi/navigator.py @@ -476,9 +476,12 @@ def _refresh_current_page(self, destination: Page, skip_first_screenshot: bool) context="goto_page", ) - def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool: + def _wait_for_destination(self, destination: Page, timeout: float = 15.0) -> bool: """等待下一页面稳定出现。 + 过图加载期间任何已知页面都识别不到,此时继续等而不是直接判失败; + 只有确认落到了别的已知页才提前返回失败,避免加载慢被误判成跳转失败。 + Args: destination: 目标页面。 timeout: 等待超时时间。 @@ -488,10 +491,20 @@ def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool """ timer = Timer(timeout).start() + last_probe = 0.0 while not timer.reached(): if self.confirm_page(destination, skip_first_screenshot=False): self.navigator.current_page = destination return True + now = time.time() + if now - last_probe >= 3.0: + last_probe = now + landed = self._detect_current_page( + skip_first_screenshot=True, + categories=self._navigation_detect_categories(destination), + ) + if landed is not None and landed.key != destination.key: + return False return False def _execute_transition(self, transition: Transition) -> bool: @@ -700,6 +713,19 @@ def detect_page_in(self, *targets: str | Page, include_global: bool = True) -> P return GameUi._detect_pages(self, pages, skip_first_screenshot=True) + def _wait_for_any_page(self, timeout: float = 15.0) -> bool: + """未知页(多半是过图加载)时静等可识别页面出现,期间不点任何关闭按钮。""" + + timer = Timer(timeout).start() + while not timer.reached(): + page = self._detect_current_page( + skip_first_screenshot=False, + categories=self._default_detect_categories(), + ) + if page is not None: + return True + return False + def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool: """尝试关闭未知页面。 @@ -712,6 +738,9 @@ def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool: self.maybe_screenshot(skip_first_screenshot) logger.warning("Try switch to a supported page") + if self._wait_for_any_page(timeout=15.0): + # 等待期间出现了可识别页面,无需关闭动作,交给外层重识别。 + return False for action in [*self.navigator.local_unknown_closers, *self.DEFAULT_UNKNOWN_CLOSERS]: action_name = self._action_name(action) # 若最后3次执行的都是该动作,则跳过该动作尝试其他动作