Skip to content

Commit

Permalink
#61 修改找不到区域时按方向滚动
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Oct 24, 2023
1 parent 451baec commit dbad343
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/basic/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def now_timestamp_str() -> str:
返回当前时间字符串
:return: 例如 20230915220515
"""
current_time = datetime.now()
current_time = datetime.datetime.now()
return current_time.strftime("%Y%m%d%H%M%S")


Expand All @@ -84,7 +84,7 @@ def get_dt() -> str:
返回当前日期字符串
:return: 例如 20230915
"""
current_time = datetime.now()
current_time = datetime.datetime.now()
return current_time.strftime("%Y%m%d")


Expand Down
2 changes: 1 addition & 1 deletion src/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def run_app(page: ft.Page):
ctx = get_context()
page.title = gt('崩坏:星穹铁道 自动代理器') + ' v0.3.2'
page.title = gt('崩坏:星穹铁道 自动代理器') + ' v0.3.3'

display_part = ft.Container(padding=20, content=world_patrol_view.get(page, ctx).component)

Expand Down
29 changes: 16 additions & 13 deletions src/sr/operation/unit/choose_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ChooseRegion(Operation):

scroll_distance = -300
scroll_distance = -800

def __init__(self, ctx: Context, region: Region):
"""
Expand All @@ -22,6 +22,7 @@ def __init__(self, ctx: Context, region: Region):
super().__init__(ctx, 10)
self.planet: Planet = region.planet
self.region: Region = region
self.scroll_direction: int = None

def run(self) -> int:
screen = self.screenshot()
Expand Down Expand Up @@ -82,7 +83,7 @@ def scroll_when_no_target_region(self, current_region_name):
:return:
"""
log.info('当前界面未发现 %s 准备滚动', self.region.cn)
if current_region_name is None: # 判断不了当前选择区域的情况 就先向下滚动5次 再向上滚动5次
if current_region_name is None and self.scroll_direction is None: # 判断不了当前选择区域的情况 就先向下滚动5次 再向上滚动5次
if self.op_round < 5:
self.scroll_region_area()
elif self.op_round == 5:
Expand All @@ -93,16 +94,18 @@ def scroll_when_no_target_region(self, current_region_name):
else:
self.scroll_region_area(-1)
else:
find_current: bool = False
region_list = PLANET_2_REGION.get(self.region.planet.np_id)
for r in region_list:
if r == self.region:
break
if current_region_name.find(gt(r.ocr_str)) != -1:
find_current = True

# 在找到目标区域前 当前区域已经出现 说明目标区域在下面 向下滚动
self.scroll_region_area(1 if find_current else -1)
if self.scroll_direction is None:
find_current: bool = False
region_list = PLANET_2_REGION.get(self.region.planet.np_id)
for r in region_list:
if r == self.region:
break
if current_region_name.find(gt(r.ocr_str)) != -1:
find_current = True

# 在找到目标区域前 当前区域已经出现 说明目标区域在下面 向下滚动
self.scroll_direction = 1 if find_current else -1
self.scroll_region_area(self.scroll_direction)

time.sleep(1)

Expand All @@ -112,7 +115,7 @@ def scroll_region_area(self, d: int = 1):
:param d: 滚动距离 正向下 负向上
:return:
"""
self.ctx.controller.scroll(ChooseRegion.scroll_distance * d, pos=large_map.REGION_LIST_PART_CENTER)
self.ctx.controller.scroll(-5 * d, pos=large_map.REGION_LIST_PART_CENTER) # TODO 有问题 一直滚动固定距离

def click_target_level(self, screen, target_level_str: str) -> bool:
"""
Expand Down

0 comments on commit dbad343

Please sign in to comment.