Fix button offset when window resizes (#354)

* Add button offsets.

* Add offset detection when there's no technique point.

* Remove offset calls for image_crop

* Fix bugs.

* Fix bugs.

* Fix corner case when technique points are being generated.

* Add png source for technique points.

* Remove duplicated assets.
This commit is contained in:
Jerry Lingjie Mei 2024-03-20 04:54:22 -05:00 committed by GitHub
parent e90f865674
commit d9fb903c89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 62 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -92,8 +92,9 @@ def iter_images():
for server in ASSET_SERVER:
for path, folders, files in os.walk(os.path.join(AzurLaneConfig.ASSETS_FOLDER, server)):
for file in files:
file = os.path.join(path, file).replace('\\', '/')
yield AssetsImage(file)
if not file.startswith('.'):
file = os.path.join(path, file).replace('\\', '/')
yield AssetsImage(file)
@dataclass

View File

@ -53,53 +53,63 @@ RUN_BUTTON = ButtonWrapper(
button=(1147, 591, 1195, 639),
),
)
TECHNIQUE_POINT_0 = ButtonWrapper(
name='TECHNIQUE_POINT_0',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_0.png',
area=(884, 597, 891, 604),
search=(831, 589, 944, 612),
color=(56, 56, 56),
button=(884, 597, 891, 604),
),
)
TECHNIQUE_POINT_1 = ButtonWrapper(
name='TECHNIQUE_POINT_1',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_1.png',
area=(881, 594, 894, 607),
search=(861, 574, 914, 627),
color=(149, 141, 186),
button=(881, 594, 894, 607),
area=(884, 597, 891, 604),
search=(831, 589, 944, 612),
color=(222, 213, 253),
button=(884, 597, 891, 604),
),
)
TECHNIQUE_POINT_2 = ButtonWrapper(
name='TECHNIQUE_POINT_2',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_2.png',
area=(889, 578, 903, 592),
search=(869, 558, 923, 612),
color=(139, 132, 174),
button=(889, 578, 903, 592),
area=(892, 581, 900, 589),
search=(872, 561, 920, 609),
color=(213, 203, 249),
button=(892, 581, 900, 589),
),
)
TECHNIQUE_POINT_3 = ButtonWrapper(
name='TECHNIQUE_POINT_3',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_3.png',
area=(902, 566, 916, 580),
search=(882, 546, 936, 600),
color=(138, 130, 173),
button=(902, 566, 916, 580),
area=(905, 569, 913, 577),
search=(885, 549, 933, 597),
color=(207, 195, 249),
button=(905, 569, 913, 577),
),
)
TECHNIQUE_POINT_4 = ButtonWrapper(
name='TECHNIQUE_POINT_4',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_4.png',
area=(918, 559, 932, 573),
search=(898, 539, 952, 593),
color=(138, 130, 173),
button=(918, 559, 932, 573),
area=(921, 562, 929, 570),
search=(901, 542, 949, 590),
color=(210, 198, 248),
button=(921, 562, 929, 570),
),
)
TECHNIQUE_POINT_5 = ButtonWrapper(
name='TECHNIQUE_POINT_5',
share=Button(
file='./assets/share/map/control/TECHNIQUE_POINT_5.png',
area=(935, 559, 948, 573),
search=(915, 539, 968, 593),
color=(71, 72, 77),
button=(935, 559, 948, 573),
area=(938, 562, 945, 570),
search=(918, 542, 965, 590),
color=(215, 203, 250),
button=(938, 562, 945, 570),
),
)

View File

@ -5,6 +5,7 @@ import cv2
import numpy as np
from module.base.timer import Timer
from module.base.utils import area_offset
from module.device.method.maatouch import MaatouchBuilder
from module.device.method.minitouch import CommandBuilder, insert_swipe, random_normal_distribution
from module.exception import ScriptError
@ -195,18 +196,35 @@ class MapControlJoystick(UI):
def map_get_technique_points(self):
"""
Returns:
int: 0 to 5.
int: 0 to 5
"""
points = [
self.image_color_count(button, color=(255, 255, 255), threshold=221, count=20)
for button in [
TECHNIQUE_POINT_1,
TECHNIQUE_POINT_2,
TECHNIQUE_POINT_3,
TECHNIQUE_POINT_4,
TECHNIQUE_POINT_5,
]
]
confirm = Timer(3, count=0).start()
while 1:
matched = TECHNIQUE_POINT_1.match_template(self.device.image)
if matched:
matched_button = TECHNIQUE_POINT_1
break
matched = TECHNIQUE_POINT_0.match_template(self.device.image)
if matched:
matched_button = TECHNIQUE_POINT_0
break
if confirm.reached():
logger.warning('Can not match technique points.')
return 0
else:
self.device.screenshot()
points = []
for button in [
TECHNIQUE_POINT_1,
TECHNIQUE_POINT_2,
TECHNIQUE_POINT_3,
TECHNIQUE_POINT_4,
TECHNIQUE_POINT_5,
]:
if matched_button is not None:
button.load_offset(matched_button)
points.append(self.image_color_count(area_offset(button.area, button.button_offset), color=(255, 255, 255),
threshold=221, count=20))
count = sum(points)
logger.attr('TechniquePoints', count)
return count