1
0
mirror of https://github.com/sui-feng-cb/AzurLaneAutoScript1.git synced 2026-08-13 03:11:47 +08:00

Fix: swipe camera to avoid clicking map event grids overlapping with UI button

This commit is contained in:
positnuec
2026-08-11 18:00:19 +08:00
parent 819d417e98
commit dcd50696f4

View File

@@ -1012,12 +1012,36 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler):
self.clear_question() self.clear_question()
self.map_rescan() 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): def map_rescan_current(self, drop=None, _ui_avoid_count=0):
""" """
Args: Args:
drop: drop:
_ui_avoid_count (int): Internal counter for map options area avoidance attempts _ui_avoid_count (int):
Returns: Returns:
bool: If solved a map random event 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}') logger.info(f'Found Akashi on {grid}')
fleet = self.convert_radar_to_local((0, 0)) fleet = self.convert_radar_to_local((0, 0))
if fleet.distance_to(grid) > 1: if fleet.distance_to(grid) > 1:
# Avoid clicking grid that overlaps with map options area if self._swipe_camera_avoid_ui(grid, ref=fleet.location, _ui_avoid_count=_ui_avoid_count, name='Akashi'):
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)
return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1) return self.map_rescan_current(drop=drop, _ui_avoid_count=_ui_avoid_count + 1)
self.device.click(grid) self.device.click(grid)
with self.config.temporary(STORY_ALLOW_SKIP=False): 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') self._solved_map_event.add('is_scanning_device')
return True 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) self.device.click(grid)
with self.config.temporary(STORY_ALLOW_SKIP=False): with self.config.temporary(STORY_ALLOW_SKIP=False):
result = self.wait_until_walk_stable( 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: if 'is_logging_tower' not in self._solved_map_event and grids and grids[0].is_logging_tower:
grid = grids[0] grid = grids[0]
logger.info(f'Found logging tower on {grid}') 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) self.device.click(grid)
with self.config.temporary(STORY_ALLOW_SKIP=False): with self.config.temporary(STORY_ALLOW_SKIP=False):
result = self.wait_until_walk_stable( result = self.wait_until_walk_stable(
@@ -1119,6 +1142,8 @@ class OSMap(OSFleet, Map, GlobeCamera, StorageHandler, StrategicSearchHandler):
and grids[0].is_fleet_mechanism: and grids[0].is_fleet_mechanism:
grid = grids[0] grid = grids[0]
logger.info(f'Found fleet mechanism on {grid}') 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.device.click(grid)
self.wait_until_walk_stable(drop=drop, walk_out_of_step=False, confirm_timer=Timer(1.5, count=4)) self.wait_until_walk_stable(drop=drop, walk_out_of_step=False, confirm_timer=Timer(1.5, count=4))