2023-06-19 09:55:46 +00:00
|
|
|
from module.ocr.ocr import *
|
|
|
|
from module.ui.scroll import Scroll
|
2023-09-16 21:00:16 +00:00
|
|
|
from tasks.base.assets.assets_base_popup import POPUP_CONFIRM
|
2023-07-14 04:35:56 +00:00
|
|
|
from tasks.base.page import page_item
|
2023-06-19 15:18:12 +00:00
|
|
|
from tasks.daily.assets.assets_daily_synthesize_consumable import \
|
|
|
|
SIMPLE_PROTECTIVE_GEAR as SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR, \
|
|
|
|
SIMPLE_PROTECTIVE_GEAR_CHECK as SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR_CHECK
|
2023-07-14 04:35:56 +00:00
|
|
|
from tasks.daily.synthesize import SynthesizeConsumablesUI
|
|
|
|
from tasks.item.assets.assets_item_consumable_usage import *
|
|
|
|
from tasks.item.assets.assets_item_ui import CONSUMABLE_CHECK
|
|
|
|
from tasks.item.keywords import KEYWORD_ITEM_TAB
|
|
|
|
from tasks.item.ui import ItemUI
|
2023-06-19 09:55:46 +00:00
|
|
|
|
|
|
|
|
2023-07-14 04:35:56 +00:00
|
|
|
class ConsumableUsageUI(ItemUI):
|
2023-06-19 15:18:12 +00:00
|
|
|
def use_consumable(self, synthesize_or_not: bool = True) -> bool:
|
2023-06-19 09:55:46 +00:00
|
|
|
"""
|
2023-06-19 15:18:12 +00:00
|
|
|
Args:
|
|
|
|
synthesize_or_not(bool):
|
|
|
|
|
2023-06-19 09:55:46 +00:00
|
|
|
Returns:
|
2023-06-19 16:44:53 +00:00
|
|
|
bool: If success
|
2023-06-19 09:55:46 +00:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
self = ConsumableUsageUI('alas')
|
|
|
|
self.device.screenshot()
|
|
|
|
result = self.use_consumable()
|
|
|
|
"""
|
2023-06-19 16:44:53 +00:00
|
|
|
logger.hr('Use consumable', level=2)
|
2023-06-19 09:55:46 +00:00
|
|
|
self.ui_ensure(page_item)
|
2023-07-14 04:35:56 +00:00
|
|
|
self.item_goto(KEYWORD_ITEM_TAB.Consumables)
|
2023-06-19 09:55:46 +00:00
|
|
|
if self._search_and_select_consumable():
|
|
|
|
self._click_use()
|
|
|
|
self._confirm_use()
|
|
|
|
return True
|
|
|
|
else:
|
2023-06-19 15:18:12 +00:00
|
|
|
# Prevent matching errors from causing continuous synthesis of consumables
|
|
|
|
if not synthesize_or_not:
|
|
|
|
return False
|
|
|
|
if SynthesizeConsumablesUI(self.config, self.device).synthesize_consumables(
|
2023-07-14 04:35:56 +00:00
|
|
|
SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR, SYNTHESIZE_SIMPLE_PROTECTIVE_GEAR_CHECK
|
2023-06-19 15:18:12 +00:00
|
|
|
):
|
|
|
|
return self.use_consumable(synthesize_or_not=False)
|
|
|
|
else:
|
|
|
|
return False
|
2023-06-19 09:55:46 +00:00
|
|
|
|
|
|
|
def _search_and_select_consumable(self, skip_first_screenshot=True) -> bool:
|
2023-06-19 16:44:53 +00:00
|
|
|
logger.info('Search consumable')
|
2023-06-19 09:55:46 +00:00
|
|
|
# If the default subpage is the consumables page, it is necessary to screenshot and check subpage again,
|
|
|
|
# because in this scenario, scroll bar delay appears and the previous screenshot was
|
|
|
|
# taken after clicking on the "item" to determine whether to enter the "item", which may be inaccurate
|
2023-07-14 04:35:56 +00:00
|
|
|
# self._switch_tag_to_consumables(False)
|
|
|
|
self.item_goto(KEYWORD_ITEM_TAB.Consumables)
|
2023-06-19 09:55:46 +00:00
|
|
|
|
|
|
|
# Determine if there is a scroll bar. If there is a scroll bar,
|
|
|
|
# pull it down and check if the consumable to be used can be found
|
|
|
|
scroll = Scroll(area=ITEM_CONSUMABLE_SCROLL.button, color=(200, 200, 200), name=ITEM_CONSUMABLE_SCROLL.name)
|
|
|
|
if scroll.appear(main=self):
|
|
|
|
if not scroll.at_top(main=self):
|
|
|
|
scroll.set_top(main=self)
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
# Determine if the specified consumable can be found
|
|
|
|
if self.appear(SIMPLE_PROTECTIVE_GEAR_CHECK):
|
|
|
|
logger.info('The consumable to be used have been selected')
|
|
|
|
return True
|
|
|
|
if scroll.at_bottom(main=self) and not self.appear(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
|
|
|
logger.info('Can not find the consumable which to be used, just skip')
|
|
|
|
return False
|
2023-07-14 17:23:35 +00:00
|
|
|
if self.appear_then_click(SIMPLE_PROTECTIVE_GEAR, similarity=0.7, interval=2):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Select the consumable which to be used')
|
|
|
|
continue
|
|
|
|
# Scroll bar flipping
|
|
|
|
if not scroll.at_bottom(main=self):
|
|
|
|
scroll.next_page(main=self)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# Determine if the specified consumable can be found
|
|
|
|
if self.appear(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self.appear(SIMPLE_PROTECTIVE_GEAR_CHECK):
|
|
|
|
logger.info('The consumable to be used have been selected')
|
|
|
|
return True
|
2023-07-14 17:23:35 +00:00
|
|
|
if self.appear_then_click(SIMPLE_PROTECTIVE_GEAR, similarity=0.7, interval=2):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Select the consumable which to be used')
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
logger.info('Can not find the consumable which to be used, just skip')
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _click_use(self, skip_first_screenshot=True):
|
|
|
|
"""
|
|
|
|
Description:
|
|
|
|
Because after executing "using consumable",
|
|
|
|
there will be a brief animation that will directly return to the consumables page,
|
|
|
|
so "click to use" and "confirm to use" have been split into two steps
|
|
|
|
"""
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-09-16 21:00:16 +00:00
|
|
|
if self.appear(POPUP_CONFIRM):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Item consumable usage popup appear')
|
|
|
|
break
|
2023-07-14 17:23:35 +00:00
|
|
|
if self.appear_then_click(USE_CONSUMABLE, interval=2):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Click the "use" button')
|
|
|
|
continue
|
|
|
|
|
|
|
|
def _confirm_use(self, skip_first_screenshot=True):
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-07-14 04:35:56 +00:00
|
|
|
if self.appear(CONSUMABLE_CHECK):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Complete using consumables')
|
|
|
|
break
|
|
|
|
# If there is already consumable effect, a confirmation box will pop up again,
|
|
|
|
# so shorten the judgment interval of the confirmation box
|
2023-09-16 21:00:16 +00:00
|
|
|
if self.handle_popup_confirm(interval=1):
|
2023-06-19 09:55:46 +00:00
|
|
|
logger.info('Confirm the use of consumable')
|
|
|
|
continue
|