mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-25 10:01:10 +00:00
Refactor: Select next support character
This commit is contained in:
parent
18981f4e5b
commit
94dca8b9ce
BIN
assets/share/combat/support/SUPPORT_SELECTED.2.png
Normal file
BIN
assets/share/combat/support/SUPPORT_SELECTED.2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/share/combat/support/SUPPORT_SELECTED.3.png
Normal file
BIN
assets/share/combat/support/SUPPORT_SELECTED.3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/share/combat/support/SUPPORT_SELECTED.4.png
Normal file
BIN
assets/share/combat/support/SUPPORT_SELECTED.4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/share/combat/support/SUPPORT_SELECTED.SEARCH.png
Normal file
BIN
assets/share/combat/support/SUPPORT_SELECTED.SEARCH.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
assets/share/combat/support/SUPPORT_SELECTED.png
Normal file
BIN
assets/share/combat/support/SUPPORT_SELECTED.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
@ -53,3 +53,36 @@ COMBAT_SUPPORT_SELECTED = ButtonWrapper(
|
||||
button=(69, 114, 91, 116),
|
||||
),
|
||||
)
|
||||
SUPPORT_SELECTED = ButtonWrapper(
|
||||
name='SUPPORT_SELECTED',
|
||||
share=[
|
||||
Button(
|
||||
file='./assets/share/combat/support/SUPPORT_SELECTED.png',
|
||||
area=(54, 202, 60, 220),
|
||||
search=(40, 146, 68, 628),
|
||||
color=(125, 126, 131),
|
||||
button=(54, 202, 60, 220),
|
||||
),
|
||||
Button(
|
||||
file='./assets/share/combat/support/SUPPORT_SELECTED.2.png',
|
||||
area=(53, 547, 59, 565),
|
||||
search=(40, 146, 68, 628),
|
||||
color=(144, 146, 147),
|
||||
button=(53, 547, 59, 565),
|
||||
),
|
||||
Button(
|
||||
file='./assets/share/combat/support/SUPPORT_SELECTED.3.png',
|
||||
area=(54, 432, 61, 450),
|
||||
search=(40, 146, 68, 628),
|
||||
color=(139, 139, 141),
|
||||
button=(54, 432, 61, 450),
|
||||
),
|
||||
Button(
|
||||
file='./assets/share/combat/support/SUPPORT_SELECTED.4.png',
|
||||
area=(52, 417, 59, 435),
|
||||
search=(40, 146, 68, 628),
|
||||
color=(140, 138, 145),
|
||||
button=(52, 417, 59, 435),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@ -2,15 +2,15 @@ import cv2
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
|
||||
from module.base.button import Button, ButtonWrapper
|
||||
from module.base.button import ClickButton
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import area_size, crop, load_image, rgb2luma
|
||||
from module.base.utils import area_offset, area_size, crop, load_image, rgb2luma
|
||||
from module.logger import logger
|
||||
from module.ui.scroll import Scroll
|
||||
from tasks.base.assets.assets_base_popup import POPUP_CANCEL
|
||||
from tasks.base.ui import UI
|
||||
from tasks.combat.assets.assets_combat_support import COMBAT_SUPPORT_ADD, COMBAT_SUPPORT_LIST, \
|
||||
COMBAT_SUPPORT_LIST_GRID, COMBAT_SUPPORT_LIST_SCROLL, COMBAT_SUPPORT_SELECTED
|
||||
COMBAT_SUPPORT_LIST_GRID, COMBAT_SUPPORT_LIST_SCROLL, COMBAT_SUPPORT_SELECTED, SUPPORT_SELECTED
|
||||
from tasks.combat.assets.assets_combat_team import COMBAT_TEAM_DISMISSSUPPORT, COMBAT_TEAM_SUPPORT
|
||||
|
||||
|
||||
@ -84,64 +84,36 @@ class SupportCharacter:
|
||||
self.button[0], self.button[1] - 5, self.button[0] + 30, self.button[1]) if self.button else None
|
||||
|
||||
|
||||
class ArrowWrapper(ButtonWrapper):
|
||||
|
||||
def find_center(self, image):
|
||||
res = cv2.matchTemplate(
|
||||
self.matched_button.image, image, cv2.TM_CCOEFF_NORMED)
|
||||
_, max_val, _, max_loc = cv2.minMaxLoc(res)
|
||||
return (
|
||||
(
|
||||
(max_loc[0] + self.matched_button.image.shape[1] / 2),
|
||||
(max_loc[1] + self.matched_button.image.shape[0] / 2),
|
||||
)
|
||||
if max_val > 0.75
|
||||
else None
|
||||
)
|
||||
|
||||
|
||||
class NextSupportCharacter:
|
||||
_arrow = ArrowWrapper(
|
||||
name="NextSupportCharacterArrow",
|
||||
share=Button(
|
||||
file='./assets/support/selected_character_arrow.png',
|
||||
area=None,
|
||||
search=None,
|
||||
color=None,
|
||||
button=None,
|
||||
)
|
||||
)
|
||||
_crop_area = (290, 115, 435, 634)
|
||||
|
||||
def __init__(self, screenshot):
|
||||
self.name = "SupportCharacterArrow"
|
||||
self.screenshot = crop(screenshot, NextSupportCharacter._crop_area)
|
||||
self.arrow_center = self._find_center()
|
||||
self.button = self._get_next_support_character_button()
|
||||
self.name = "NextSupportCharacter"
|
||||
self.button = self.get_next_support_character_button(screenshot)
|
||||
|
||||
def __bool__(self):
|
||||
return self.button is not None
|
||||
|
||||
def _find_center(self):
|
||||
center = NextSupportCharacter._arrow.find_center(self.screenshot)
|
||||
center = get_position_in_original_image(
|
||||
center, NextSupportCharacter._crop_area) if center else None
|
||||
return center
|
||||
def get_next_support_character_button(self, screenshot) -> ClickButton | None:
|
||||
if SUPPORT_SELECTED.match_template(screenshot, similarity=0.75):
|
||||
# Move area to the next character card center
|
||||
area = SUPPORT_SELECTED.button
|
||||
area = area_offset((105, 85, 255, 170), offset=area[:2])
|
||||
if area[3] < COMBAT_SUPPORT_LIST_GRID.area[3]:
|
||||
return ClickButton(area, name=self.name)
|
||||
else:
|
||||
# Out of list
|
||||
logger.info('Next character is out of list')
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
def _get_next_support_character_button(self):
|
||||
area = (self.arrow_center[0] - 200, min(self.arrow_center[1] + 65, 615), self.arrow_center[0] + 10, min(
|
||||
self.arrow_center[1] + 80, 620)) if self.arrow_center and self.arrow_center[1] < 510 else None
|
||||
return ButtonWrapper(
|
||||
name="NextSupportCharacterButton",
|
||||
share=Button(
|
||||
file='./assets/support/selected_character_arrow.png',
|
||||
area=area,
|
||||
search=area,
|
||||
# if next support was selected, the average color of the button will larger than 220
|
||||
color=(220, 220, 220),
|
||||
button=area,
|
||||
)
|
||||
) if self.arrow_center and self.arrow_center[1] < 510 else None
|
||||
def is_next_support_character_selected(self, screenshot) -> bool:
|
||||
if self.button is None:
|
||||
return False
|
||||
area = self.button.area
|
||||
# Move area from the card center to the left edge of the card
|
||||
area = area_offset(area, offset=(-120, 0))
|
||||
image = crop(screenshot, area, copy=False)
|
||||
return SUPPORT_SELECTED.match_template(image, similarity=0.75, direct_match=True)
|
||||
|
||||
|
||||
class SupportListScroll(Scroll):
|
||||
@ -351,7 +323,7 @@ class CombatSupport(UI):
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
if next_support and self._next_support_selected(next_support):
|
||||
if next_support is not None and next_support.is_next_support_character_selected(self.device.image):
|
||||
return
|
||||
|
||||
if interval.reached():
|
||||
@ -367,13 +339,3 @@ class CombatSupport(UI):
|
||||
|
||||
interval.reset()
|
||||
continue
|
||||
|
||||
def _next_support_selected(self, next_support: NextSupportCharacter):
|
||||
"""
|
||||
Returns:
|
||||
bool: True if selected else False
|
||||
"""
|
||||
if self.match_color(next_support.button, threshold=20):
|
||||
logger.info("Next support selected")
|
||||
return True
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user