Fix: Detect empty fuel

This commit is contained in:
LmeSzinc 2024-07-19 00:03:50 +08:00
parent 4a9e8066a0
commit be4c401913
5 changed files with 27 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -34,10 +34,10 @@ FUEL = ButtonWrapper(
name='FUEL', name='FUEL',
share=Button( share=Button(
file='./assets/share/combat/prepare/FUEL.png', file='./assets/share/combat/prepare/FUEL.png',
area=(592, 276, 688, 388), area=(592, 276, 688, 366),
search=(572, 256, 708, 408), search=(474, 271, 811, 396),
color=(113, 90, 123), color=(123, 96, 134),
button=(592, 276, 688, 388), button=(592, 276, 688, 366),
), ),
) )
FUEL_ENTRANCE = ButtonWrapper( FUEL_ENTRANCE = ButtonWrapper(
@ -74,10 +74,10 @@ FUEL_SELECTED = ButtonWrapper(
name='FUEL_SELECTED', name='FUEL_SELECTED',
share=Button( share=Button(
file='./assets/share/combat/prepare/FUEL_SELECTED.png', file='./assets/share/combat/prepare/FUEL_SELECTED.png',
area=(587, 271, 692, 395), area=(587, 271, 692, 368),
search=(474, 271, 811, 396), search=(474, 271, 811, 396),
color=(130, 111, 137), color=(136, 112, 144),
button=(587, 271, 692, 395), button=(587, 271, 692, 368),
), ),
) )
FUEL_SLIDER = ButtonWrapper( FUEL_SLIDER = ButtonWrapper(

View File

@ -1,4 +1,5 @@
import module.config.server as server import module.config.server as server
from module.base.timer import Timer
from module.base.utils import crop, area_offset from module.base.utils import crop, area_offset
from module.logger import logger from module.logger import logger
@ -122,9 +123,10 @@ class Fuel(UI):
skip_first_screenshot=True skip_first_screenshot=True
) )
def set_fuel_count(self, count, total): def set_fuel_count(self, count):
slider = Slider(main=self, slider=FUEL_SLIDER) slider = Slider(main=self, slider=FUEL_SLIDER)
slider.set(count, total) # Can only use 5 fuel at one time
slider.set(count, 5)
self.ui_ensure_index( self.ui_ensure_index(
count, letter=Digit(OCR_FUEL_COUNT, lang=server.lang), count, letter=Digit(OCR_FUEL_COUNT, lang=server.lang),
next_button=FUEL_PLUS, prev_button=FUEL_MINUS, next_button=FUEL_PLUS, prev_button=FUEL_MINUS,
@ -139,20 +141,29 @@ class Fuel(UI):
return return
logger.info("Use Fuel") logger.info("Use Fuel")
timeout = Timer(1, count=3)
has_fuel = False
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
skip_first_screenshot = False skip_first_screenshot = False
else: else:
self.device.screenshot() self.device.screenshot()
if self.appear(POPUP_CONFIRM) and not (self.appear(FUEL_SELECTED) and self.appear(FUEL)): if self.appear(FUEL_SELECTED):
logger.info('Fuel selected')
break
if self.appear(POPUP_CONFIRM):
timeout.start()
if self.appear(FUEL_SELECTED) or self.appear(FUEL):
has_fuel = True
if not has_fuel and timeout.reached():
logger.info("No fuel found") logger.info("No fuel found")
return return
if self.appear(FUEL_SELECTED):
break
if self.appear_then_click(FUEL): if self.appear_then_click(FUEL):
has_fuel = True
continue continue
if self.appear_then_click(FUEL_ENTRANCE): if not self.appear(POPUP_CONFIRM) and self.appear_then_click(FUEL_ENTRANCE):
continue continue
offset = FUEL_SELECTED.button_offset offset = FUEL_SELECTED.button_offset
@ -178,6 +189,8 @@ class Fuel(UI):
break break
if self.appear(FUEL) and self.handle_popup_confirm(): if self.appear(FUEL) and self.handle_popup_confirm():
continue continue
if self.appear(FUEL_SELECTED) and self.handle_popup_confirm():
continue
self.set_fuel_count(use, count) self.set_fuel_count(use)
self._fuel_confirm() self._fuel_confirm()