|
1 | 1 | from module.base.button import ButtonGrid |
2 | 2 | from module.base.decorator import cached_property |
3 | | -from module.base.timer import Timer |
4 | 3 | from module.handler.assets import POPUP_CONFIRM |
5 | 4 | from module.logger import logger |
6 | 5 | from module.shop.assets import * |
@@ -72,44 +71,44 @@ def shop_tab_250814(self): |
72 | 71 | switch.add_state(TAB_PROTOTYPE, check_button=TAB_PROTOTYPE) |
73 | 72 | return switch |
74 | 73 |
|
75 | | - def shop_refresh(self, skip_first_screenshot=True): |
| 74 | + def shop_refresh(self): |
76 | 75 | """ |
77 | | - Args: |
78 | | - skip_first_screenshot: bool |
79 | | -
|
80 | 76 | Returns: |
81 | 77 | bool: If refreshed |
82 | 78 | """ |
| 79 | + logger.info('Shop refresh') |
83 | 80 | refreshed = False |
84 | | - exit_timer = Timer(3, count=6).start() |
85 | | - while 1: |
86 | | - if skip_first_screenshot: |
87 | | - skip_first_screenshot = False |
88 | | - else: |
89 | | - self.device.screenshot() |
90 | 81 |
|
91 | | - if self.appear_then_click(SHOP_REFRESH, interval=3): |
92 | | - exit_timer.reset() |
93 | | - continue |
94 | | - if self.appear(SHOP_BUY_CONFIRM_MISTAKE, interval=3, offset=(200, 200)) \ |
95 | | - and self.appear(POPUP_CONFIRM, offset=(3, 30)): |
| 82 | + # SHOP_REFRESH -> POPUP_CONFIRM |
| 83 | + for _ in self.loop(): |
| 84 | + if self.appear(POPUP_CONFIRM, offset=(30, 30)): |
| 85 | + break |
| 86 | + if self.appear(SHOP_REFRESH, offset=(30, 30), interval=3): |
| 87 | + # SHOP_REFRESH has two kinds of color when active |
| 88 | + if self.image_color_count(SHOP_REFRESH.button, color=(49, 142, 207), threshold=221, count=50): |
| 89 | + self.device.click(SHOP_REFRESH) |
| 90 | + continue |
| 91 | + if self.image_color_count(SHOP_REFRESH.button, color=(54, 117, 161), threshold=221, count=50): |
| 92 | + self.device.click(SHOP_REFRESH) |
| 93 | + continue |
| 94 | + # not available: (52, 74, 94) |
| 95 | + # no `continue`, act like SHOP_REFRESH not matched |
| 96 | + self.interval_clear(SHOP_REFRESH) |
| 97 | + |
| 98 | + # POPUP_CONFIRM -> SHOP_BACK_ARROW |
| 99 | + for _ in self.loop(): |
| 100 | + if self.appear(SHOP_BACK_ARROW, offset=(30, 30)): |
| 101 | + break |
| 102 | + if self.appear(SHOP_BUY_CONFIRM_MISTAKE, interval=3, offset=(200, 200)): |
| 103 | + logger.warning('SHOP_BUY_CONFIRM_MISTAKE') |
96 | 104 | self.ui_click(SHOP_CLICK_SAFE_AREA, appear_button=POPUP_CONFIRM, check_button=SHOP_BACK_ARROW, |
97 | 105 | offset=(20, 30), skip_first_screenshot=True) |
98 | | - exit_timer.reset() |
99 | 106 | refreshed = False |
100 | 107 | break |
101 | 108 | if self.handle_popup_confirm('SHOP_REFRESH_CONFIRM'): |
102 | | - exit_timer.reset() |
103 | 109 | refreshed = True |
104 | 110 | continue |
105 | 111 |
|
106 | | - # End |
107 | | - if self.appear(SHOP_BACK_ARROW, offset=(30, 30)): |
108 | | - if exit_timer.reached(): |
109 | | - break |
110 | | - else: |
111 | | - exit_timer.reset() |
112 | | - |
113 | 112 | self.handle_info_bar() |
114 | 113 | return refreshed |
115 | 114 |
|
|
0 commit comments