From dcd50696f475553183b270ac2f372a4d02fbe0c1 Mon Sep 17 00:00:00 2001 From: positnuec <93694981+positnuec@users.noreply.github.com> Date: Tue, 11 Aug 2026 18:00:19 +0800 Subject: [PATCH] Fix: swipe camera to avoid clicking map event grids overlapping with UI button --- module/os/map.py | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/module/os/map.py b/module/os/map.py index 6d53378af..c01cf98cb 100644 --- a/module/os/map.py +++ b/module/os/map.py @@ -1012,12 +1012,36 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler): self.clear_question() self.map_rescan() + def _swipe_camera_avoid_ui(self, grid, ref=None, _ui_avoid_count=0, name='Grid'): + """ + Swipe camera to move a grid that overlaps with map options area out of it to avoid misclicks. + + Args: + grid (OSGrid): Grid to check + ref (tuple): Grid location to measure the swipe vector from, + defaults to the screen center (view.center_loca) + _ui_avoid_count (int): Internal counter for map options area avoidance attempts + name (str): Grid event name, used in log message + + Returns: + bool: True if the camera swiped and the map should be rescanned; False if the grid is safe to click. + """ + if _ui_avoid_count < 3 and area_cross_area(grid.button, MAP_OPTIONS_AREA.area, threshold=0): + if ref is None: + ref = self.view.center_loca + vector = np.array(grid.location) - np.array(ref) + vector = tuple((vector // 2).astype(int)) + logger.info(f'{name} grid {grid} overlaps with map options area, swipe {vector}') + self.map_swipe(vector) + return True + return False + def map_rescan_current(self, drop=None, _ui_avoid_count=0): """ Args: drop: - _ui_avoid_count (int): Internal counter for map options area avoidance attempts + _ui_avoid_count (int): Returns: bool: If solved a map random event @@ -1055,12 +1079,7 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler): logger.info(f'Found Akashi on {grid}') fleet = self.convert_radar_to_local((0, 0)) if fleet.distance_to(grid) > 1: - # Avoid clicking grid that overlaps with map options area - if _ui_avoid_count < 3 and area_cross_area(grid.button, MAP_OPTIONS_AREA.area, threshold=0): - logger.info(f'Akashi grid {grid} overlaps with map options area, swipe camera to avoid') - vector = np.array(grid.location) - np.array(fleet.location) - vector = tuple((vector // 2).astype(int)) - self.map_swipe(vector) + if self._swipe_camera_avoid_ui(grid, ref=fleet.location, _ui_avoid_count=_ui_avoid_count, name='Akashi'): return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1) self.device.click(grid) with self.config.temporary(STORY_ALLOW_SKIP=False): @@ -1087,6 +1106,8 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler): self._solved_map_event.add('is_scanning_device') return True + if self._swipe_camera_avoid_ui(grid, _ui_avoid_count=_ui_avoid_count, name='Scanning device'): + return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1) self.device.click(grid) with self.config.temporary(STORY_ALLOW_SKIP=False): result = self.wait_until_walk_stable( @@ -1102,6 +1123,8 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler): if 'is_logging_tower' not in self._solved_map_event and grids and grids[0].is_logging_tower: grid = grids[0] logger.info(f'Found logging tower on {grid}') + if self._swipe_camera_avoid_ui(grid, _ui_avoid_count=_ui_avoid_count, name='Logging tower'): + return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1) self.device.click(grid) with self.config.temporary(STORY_ALLOW_SKIP=False): result = self.wait_until_walk_stable( @@ -1119,6 +1142,8 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler): and grids[0].is_fleet_mechanism: grid = grids[0] logger.info(f'Found fleet mechanism on {grid}') + if self._swipe_camera_avoid_ui(grid, _ui_avoid_count=_ui_avoid_count, name='Fleet mechanism'): + return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1) self.device.click(grid) self.wait_until_walk_stable(drop=drop, walk_out_of_step=False, confirm_timer=Timer(1.5, count=4))