mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-29 12:47:13 +08:00
Chore: Cleanup code and assets of old UI
This commit is contained in:
@@ -6,19 +6,15 @@ import module.config.server as server
|
||||
from module.base.button import ButtonGrid
|
||||
from module.base.decorator import cached_property, del_cached_property
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import area_offset, rgb2gray
|
||||
from module.base.utils import rgb2gray
|
||||
from module.logger import logger
|
||||
from module.map_detection.utils import Points
|
||||
from module.ocr.ocr import Digit, DigitYuv, Ocr
|
||||
from module.shop.assets import *
|
||||
from module.shop.base import ShopItemGrid, ShopItemGrid_250814
|
||||
from module.shop.base import ShopItemGrid_250814
|
||||
from module.shop.clerk import ShopClerk
|
||||
from module.shop.shop_status import ShopStatus
|
||||
from module.ui.scroll import AdaptiveScroll, Scroll
|
||||
|
||||
MEDAL_SHOP_SCROLL = Scroll(MEDAL_SHOP_SCROLL_AREA, color=(247, 211, 66))
|
||||
MEDAL_SHOP_SCROLL.edge_threshold = 0.15
|
||||
MEDAL_SHOP_SCROLL.drag_threshold = 0.15
|
||||
from module.ui.scroll import AdaptiveScroll
|
||||
|
||||
|
||||
class ShopAdaptiveScroll(AdaptiveScroll):
|
||||
@@ -74,7 +70,7 @@ TEMPLATE_MEDAL_ICON_2 = Template('./assets/shop/cost/Medal_2.png')
|
||||
TEMPLATE_MEDAL_ICON_3 = Template('./assets/shop/cost/Medal_3.png')
|
||||
|
||||
|
||||
class MedalShop2(ShopClerk, ShopStatus):
|
||||
class MedalShop2_250814(ShopClerk, ShopStatus):
|
||||
@cached_property
|
||||
def shop_filter(self):
|
||||
"""
|
||||
@@ -83,22 +79,16 @@ class MedalShop2(ShopClerk, ShopStatus):
|
||||
"""
|
||||
return self.config.MedalShop2_Filter.strip()
|
||||
|
||||
# New UI in 2025-08-14
|
||||
def _get_medals(self):
|
||||
"""
|
||||
Returns:
|
||||
np.array: [[x1, y1], [x2, y2]], location of the medal icon upper-left corner.
|
||||
"""
|
||||
area = (472, 348, 1170, 648)
|
||||
area = (226, 317, 960, 635)
|
||||
# copy image because we gonna paint it
|
||||
image = self.image_crop(area, copy=True)
|
||||
# a random background thingy that may cause mis-detection in template matching
|
||||
paint = (869, 589, 913, 643)
|
||||
paint = area_offset(paint, (-area[0], -area[1]))
|
||||
# paint it black
|
||||
x1, y1, x2, y2 = paint
|
||||
image[y1:y2, x1:x2] = (0, 0, 0)
|
||||
|
||||
medals = TEMPLATE_MEDAL_ICON_2.match_multi(image, similarity=0.5, threshold=5)
|
||||
medals = TEMPLATE_MEDAL_ICON_3.match_multi(image, similarity=0.5, threshold=5)
|
||||
medals = Points([(0., m.area[1]) for m in medals]).group(threshold=5)
|
||||
logger.attr('Medals_icon', len(medals))
|
||||
return medals
|
||||
@@ -137,26 +127,26 @@ class MedalShop2(ShopClerk, ShopStatus):
|
||||
count = len(medals)
|
||||
if count == 0:
|
||||
logger.warning('Unable to find medal icon, assume item list is at top')
|
||||
origin_y = 246
|
||||
delta_y = 213
|
||||
origin_y = 228
|
||||
delta_y = 217
|
||||
row = 2
|
||||
elif count == 1:
|
||||
y_list = medals[:, 1]
|
||||
# +256, top of the crop area in _get_medals()
|
||||
# -125, from the top of medal icon to the top of shop item
|
||||
origin_y = y_list[0] + 348 - 127
|
||||
delta_y = 213
|
||||
origin_y = y_list[0] + 317 - 126
|
||||
delta_y = 217
|
||||
row = 1
|
||||
elif count == 2:
|
||||
y_list = medals[:, 1]
|
||||
y1, y2 = y_list[0], y_list[1]
|
||||
origin_y = min(y1, y2) + 348 - 127
|
||||
origin_y = min(y1, y2) + 317 - 126
|
||||
delta_y = abs(y1 - y2)
|
||||
row = 2
|
||||
else:
|
||||
logger.warning(f'Unexpected medal icon match result: {[m for m in medals]}')
|
||||
origin_y = 246
|
||||
delta_y = 213
|
||||
origin_y = 228
|
||||
delta_y = 217
|
||||
row = 2
|
||||
|
||||
# Make up a ButtonGrid
|
||||
@@ -164,7 +154,7 @@ class MedalShop2(ShopClerk, ShopStatus):
|
||||
# shop_grid = ButtonGrid(
|
||||
# origin=(476, 246), delta=(156, 213), button_shape=(98, 98), grid_shape=(5, 2), name='SHOP_GRID')
|
||||
shop_grid = ButtonGrid(
|
||||
origin=(476, origin_y), delta=(156, delta_y), button_shape=(98, 98), grid_shape=(5, row), name='SHOP_GRID')
|
||||
origin=(226, origin_y), delta=(162, delta_y), button_shape=(64, 64), grid_shape=(5, row), name='SHOP_GRID')
|
||||
return shop_grid
|
||||
|
||||
shop_template_folder = './assets/shop/medal'
|
||||
@@ -173,28 +163,34 @@ class MedalShop2(ShopClerk, ShopStatus):
|
||||
def shop_medal_items(self):
|
||||
"""
|
||||
Returns:
|
||||
ShopItemGrid:
|
||||
ShopItemGrid_250814:
|
||||
"""
|
||||
shop_grid = self.shop_grid
|
||||
shop_medal_items = ShopItemGrid(
|
||||
shop_medal_items = ShopItemGrid_250814(
|
||||
shop_grid,
|
||||
templates={}, amount_area=(60, 74, 96, 95),
|
||||
price_area=(52, 132, 132, 162))
|
||||
templates={},
|
||||
amount_area=(60, 74, 96, 95),
|
||||
cost_area=(-12, 115, 60, 155),
|
||||
price_area=(14, 122, 85, 149),
|
||||
)
|
||||
shop_medal_items.load_template_folder(self.shop_template_folder)
|
||||
shop_medal_items.load_cost_template_folder('./assets/shop/cost')
|
||||
shop_medal_items.similarity = 0.85 # Lower the threshold for consistent matches of PR/DRBP
|
||||
shop_medal_items.cost_similarity = 0.5
|
||||
shop_medal_items.price_ocr = PRICE_OCR
|
||||
shop_medal_items.price_ocr = PRICE_OCR_250814
|
||||
return shop_medal_items
|
||||
|
||||
def shop_items(self) -> ShopItemGrid:
|
||||
def shop_items(self) -> ShopItemGrid_250814:
|
||||
"""
|
||||
Shared alias name for all shops,
|
||||
so to use @Config must define
|
||||
a unique alias as cover
|
||||
Overriding to add type hint to
|
||||
accommodate unique func,
|
||||
get_soldout_count in run()
|
||||
|
||||
Returns:
|
||||
ShopItemGrid:
|
||||
ShopItemGrid_250814:
|
||||
"""
|
||||
return self.shop_medal_items
|
||||
|
||||
@@ -254,123 +250,6 @@ class MedalShop2(ShopClerk, ShopStatus):
|
||||
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run Medal Shop
|
||||
"""
|
||||
# Base case; exit run if filter empty
|
||||
if not self.shop_filter:
|
||||
return
|
||||
|
||||
# When called, expected to be in
|
||||
# correct Medal Shop interface
|
||||
logger.hr('Medal Shop', level=1)
|
||||
self.wait_until_medal_appear()
|
||||
|
||||
# Execute buy operations
|
||||
MEDAL_SHOP_SCROLL.set_top(main=self)
|
||||
while 1:
|
||||
self.shop_buy()
|
||||
if MEDAL_SHOP_SCROLL.at_bottom(main=self):
|
||||
logger.info('Medal shop reach bottom, stop')
|
||||
break
|
||||
else:
|
||||
MEDAL_SHOP_SCROLL.next_page(main=self, page=0.66)
|
||||
del_cached_property(self, 'shop_grid')
|
||||
del_cached_property(self, 'shop_medal_items')
|
||||
continue
|
||||
|
||||
|
||||
class MedalShop2_250814(MedalShop2):
|
||||
# New UI in 2025-08-14
|
||||
def _get_medals(self):
|
||||
"""
|
||||
Returns:
|
||||
np.array: [[x1, y1], [x2, y2]], location of the medal icon upper-left corner.
|
||||
"""
|
||||
area = (226, 317, 960, 635)
|
||||
# copy image because we gonna paint it
|
||||
image = self.image_crop(area, copy=True)
|
||||
medals = TEMPLATE_MEDAL_ICON_3.match_multi(image, similarity=0.5, threshold=5)
|
||||
medals = Points([(0., m.area[1]) for m in medals]).group(threshold=5)
|
||||
logger.attr('Medals_icon', len(medals))
|
||||
return medals
|
||||
|
||||
def shop_medal_grid(self):
|
||||
"""
|
||||
Returns:
|
||||
ButtonGrid:
|
||||
"""
|
||||
# (472, 348, 1170, 648)
|
||||
medals = self._get_medals()
|
||||
count = len(medals)
|
||||
if count == 0:
|
||||
logger.warning('Unable to find medal icon, assume item list is at top')
|
||||
origin_y = 228
|
||||
delta_y = 217
|
||||
row = 2
|
||||
elif count == 1:
|
||||
y_list = medals[:, 1]
|
||||
# +256, top of the crop area in _get_medals()
|
||||
# -125, from the top of medal icon to the top of shop item
|
||||
origin_y = y_list[0] + 317 - 126
|
||||
delta_y = 217
|
||||
row = 1
|
||||
elif count == 2:
|
||||
y_list = medals[:, 1]
|
||||
y1, y2 = y_list[0], y_list[1]
|
||||
origin_y = min(y1, y2) + 317 - 126
|
||||
delta_y = abs(y1 - y2)
|
||||
row = 2
|
||||
else:
|
||||
logger.warning(f'Unexpected medal icon match result: {[m for m in medals]}')
|
||||
origin_y = 228
|
||||
delta_y = 217
|
||||
row = 2
|
||||
|
||||
# Make up a ButtonGrid
|
||||
# Original grid is:
|
||||
# shop_grid = ButtonGrid(
|
||||
# origin=(476, 246), delta=(156, 213), button_shape=(98, 98), grid_shape=(5, 2), name='SHOP_GRID')
|
||||
shop_grid = ButtonGrid(
|
||||
origin=(226, origin_y), delta=(162, delta_y), button_shape=(64, 64), grid_shape=(5, row), name='SHOP_GRID')
|
||||
return shop_grid
|
||||
|
||||
@cached_property
|
||||
def shop_medal_items(self):
|
||||
"""
|
||||
Returns:
|
||||
ShopItemGrid_250814:
|
||||
"""
|
||||
shop_grid = self.shop_grid
|
||||
shop_medal_items = ShopItemGrid_250814(
|
||||
shop_grid,
|
||||
templates={},
|
||||
amount_area=(60, 74, 96, 95),
|
||||
cost_area=(-12, 115, 60, 155),
|
||||
price_area=(14, 122, 85, 149),
|
||||
)
|
||||
shop_medal_items.load_template_folder(self.shop_template_folder)
|
||||
shop_medal_items.load_cost_template_folder('./assets/shop/cost')
|
||||
shop_medal_items.similarity = 0.85 # Lower the threshold for consistent matches of PR/DRBP
|
||||
shop_medal_items.cost_similarity = 0.5
|
||||
shop_medal_items.price_ocr = PRICE_OCR_250814
|
||||
return shop_medal_items
|
||||
|
||||
def shop_items(self) -> ShopItemGrid_250814:
|
||||
"""
|
||||
Shared alias name for all shops,
|
||||
so to use @Config must define
|
||||
a unique alias as cover
|
||||
Overriding to add type hint to
|
||||
accommodate unique func,
|
||||
get_soldout_count in run()
|
||||
|
||||
Returns:
|
||||
ShopItemGrid_250814:
|
||||
"""
|
||||
return self.shop_medal_items
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run Medal Shop
|
||||
|
||||
Reference in New Issue
Block a user