diff --git a/assets/share/item/ui/SWITCH_SEARCH.png b/assets/share/item/ui/SWITCH_SEARCH.png new file mode 100644 index 000000000..a5d0dd7d9 Binary files /dev/null and b/assets/share/item/ui/SWITCH_SEARCH.png differ diff --git a/module/ui/switch.py b/module/ui/switch.py index eddc9472b..fd13c61c9 100644 --- a/module/ui/switch.py +++ b/module/ui/switch.py @@ -36,8 +36,8 @@ class Switch: """ Args: state (str): - check_button (Button): - click_button (Button): + check_button (ButtonWrapper): + click_button (ButtonWrapper): """ self.state_list.append({ 'state': state, diff --git a/tasks/item/assets/assets_item_ui.py b/tasks/item/assets/assets_item_ui.py index 15d57b2aa..63bf672f9 100644 --- a/tasks/item/assets/assets_item_ui.py +++ b/tasks/item/assets/assets_item_ui.py @@ -103,6 +103,16 @@ RELICS_CLICK = ButtonWrapper( button=(36, 298, 78, 319), ), ) +SWITCH_SEARCH = ButtonWrapper( + name='SWITCH_SEARCH', + share=Button( + file='./assets/share/item/ui/SWITCH_SEARCH.png', + area=(22, 60, 94, 672), + search=(2, 40, 114, 692), + color=(77, 81, 88), + button=(22, 60, 94, 672), + ), +) UPGRADE_MATERIAL_CHECK = ButtonWrapper( name='UPGRADE_MATERIAL_CHECK', share=Button( diff --git a/tasks/item/relics.py b/tasks/item/relics.py index d0b3d916b..9371ae71a 100644 --- a/tasks/item/relics.py +++ b/tasks/item/relics.py @@ -1,6 +1,7 @@ from module.base.timer import Timer from module.logger import logger from tasks.base.assets.assets_base_page import CLOSE +from tasks.base.page import page_item from tasks.item.assets.assets_item_relics import * from tasks.item.keywords import KEYWORDS_ITEM_TAB from tasks.item.ui import ItemUI @@ -48,6 +49,7 @@ class RelicsUI(ItemUI): out: page_item, GOTO_SALVAGE """ logger.hr('Salvage Relic', level=2) + self.ui_ensure(page_item) self.item_goto(KEYWORDS_ITEM_TAB.Relics, wait_until_stable=False) while 1: # relic tab -> salvage if skip_first_screenshot: diff --git a/tasks/item/ui.py b/tasks/item/ui.py index 23ae5561a..0fcc342e5 100644 --- a/tasks/item/ui.py +++ b/tasks/item/ui.py @@ -1,12 +1,32 @@ from module.logger import logger from module.ui.switch import Switch -from tasks.base.page import page_item from tasks.base.ui import UI from tasks.item.assets.assets_item_consumable_usage import SIMPLE_PROTECTIVE_GEAR from tasks.item.assets.assets_item_ui import * from tasks.item.keywords import KEYWORDS_ITEM_TAB -SWITCH_ITEM_TAB = Switch('ItemTab', is_selector=True) + +class SwitchItemTab(Switch): + def add_state(self, state, check_button, click_button=None): + # Load search + if check_button is not None: + check_button.load_search(SWITCH_SEARCH.area) + if click_button is not None: + click_button.load_search(SWITCH_SEARCH.area) + return super().add_state(state, check_button, click_button) + + def click(self, state, main): + """ + Args: + state (str): + main (ModuleBase): + """ + button = self.get_data(state)['click_button'] + _ = button.match_template_luma(main.device.image) # Search button to load offset + main.device.click(button) + + +SWITCH_ITEM_TAB = SwitchItemTab('ItemTab', is_selector=True) SWITCH_ITEM_TAB.add_state( KEYWORDS_ITEM_TAB.UpgradeMaterials, check_button=UPGRADE_MATERIAL_CHECK, @@ -53,16 +73,20 @@ class ItemUI(UI): inside the tab, wait_until_stable should set to True Returns: + bool: If switched + + Examples: self = ItemUI('alas') self.device.screenshot() self.item_goto(KEYWORDS_ITEM_TAB.Relics) self.item_goto(KEYWORDS_ITEM_TAB.Consumables) """ - logger.hr('Item tab goto', level=2) - self.ui_ensure(page_item) - SWITCH_ITEM_TAB.set(state, main=self) - if wait_until_stable: - logger.info(f'Tab goto {state}, wait until loaded') - self.wait_until_stable(SIMPLE_PROTECTIVE_GEAR) + if SWITCH_ITEM_TAB.set(state, main=self): + if wait_until_stable: + logger.info(f'Tab goto {state}, wait until loaded') + self.wait_until_stable(SIMPLE_PROTECTIVE_GEAR) + else: + logger.info(f'Tab goto {state}') + return True else: - logger.info(f'Tab goto {state}') + return False