Fix: Use ocr to check assignment groups instead

This commit is contained in:
Zebartin 2023-09-25 14:13:11 +08:00
parent 80b8b6acb7
commit b92ae0a143
5 changed files with 58 additions and 55 deletions

View File

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -50,6 +50,26 @@ EXP_MATERIALS_CREDITS = ButtonWrapper(
button=(310, 85, 447, 134), button=(310, 85, 447, 134),
), ),
) )
OCR_ASSIGNMENT_ENTRY_LIST = ButtonWrapper(
name='OCR_ASSIGNMENT_ENTRY_LIST',
share=Button(
file='./assets/share/assignment/ui/OCR_ASSIGNMENT_ENTRY_LIST.png',
area=(133, 139, 494, 620),
search=(113, 119, 514, 640),
color=(201, 199, 193),
button=(133, 139, 494, 620),
),
)
OCR_ASSIGNMENT_GROUP_LIST = ButtonWrapper(
name='OCR_ASSIGNMENT_GROUP_LIST',
share=Button(
file='./assets/share/assignment/ui/OCR_ASSIGNMENT_GROUP_LIST.png',
area=(106, 70, 848, 135),
search=(86, 50, 868, 155),
color=(73, 72, 70),
button=(106, 70, 848, 135),
),
)
OCR_ASSIGNMENT_LIMIT = ButtonWrapper( OCR_ASSIGNMENT_LIMIT = ButtonWrapper(
name='OCR_ASSIGNMENT_LIMIT', name='OCR_ASSIGNMENT_LIMIT',
share=Button( share=Button(
@ -60,16 +80,6 @@ OCR_ASSIGNMENT_LIMIT = ButtonWrapper(
button=(1095, 95, 1180, 119), button=(1095, 95, 1180, 119),
), ),
) )
OCR_ASSIGNMENT_LIST = ButtonWrapper(
name='OCR_ASSIGNMENT_LIST',
share=Button(
file='./assets/share/assignment/ui/OCR_ASSIGNMENT_LIST.png',
area=(133, 139, 494, 620),
search=(113, 119, 514, 640),
color=(201, 199, 193),
button=(133, 139, 494, 620),
),
)
OCR_ASSIGNMENT_TIME = ButtonWrapper( OCR_ASSIGNMENT_TIME = ButtonWrapper(
name='OCR_ASSIGNMENT_TIME', name='OCR_ASSIGNMENT_TIME',
share=Button( share=Button(

View File

@ -1,12 +1,37 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from module.base.base import ModuleBase
from module.base.timer import Timer from module.base.timer import Timer
from module.config.stored.classes import now from module.config.stored.classes import now
from module.logger import logger from module.logger import logger
from module.ui.switch import Switch
from tasks.assignment.assets.assets_assignment_dispatch import * from tasks.assignment.assets.assets_assignment_dispatch import *
from tasks.assignment.assets.assets_assignment_ui import DISPATCHED from tasks.assignment.assets.assets_assignment_ui import DISPATCHED
from tasks.assignment.keywords import * from tasks.assignment.keywords import *
from tasks.assignment.ui import AssignmentSwitch, AssignmentUI from tasks.assignment.ui import AssignmentUI
class AssignmentSwitch(Switch):
def __init__(self, name, active_color: tuple[int, int, int], is_selector=True):
super().__init__(name, is_selector)
self.active_color = active_color
def get(self, main: ModuleBase):
"""
Use image_color_count instead to determine whether the button is selected/active
Args:
main (ModuleBase):
Returns:
str: state name or 'unknown'.
"""
for data in self.state_list:
if main.image_color_count(data['check_button'], self.active_color):
return data['state']
return 'unknown'
ASSIGNMENT_DURATION_SWITCH = AssignmentSwitch( ASSIGNMENT_DURATION_SWITCH = AssignmentSwitch(
'AssignmentDurationSwitch', 'AssignmentDurationSwitch',

View File

@ -2,40 +2,16 @@ import re
from functools import cached_property from functools import cached_property
from typing import Iterator from typing import Iterator
from module.base.base import ModuleBase
from module.base.timer import Timer from module.base.timer import Timer
from module.exception import ScriptError from module.exception import ScriptError
from module.logger import logger from module.logger import logger
from module.ocr.ocr import DigitCounter, Duration, Ocr from module.ocr.ocr import DigitCounter, Duration, Ocr
from module.ui.draggable_list import DraggableList from module.ui.draggable_list import DraggableList
from module.ui.switch import Switch
from tasks.assignment.assets.assets_assignment_ui import * from tasks.assignment.assets.assets_assignment_ui import *
from tasks.assignment.keywords import * from tasks.assignment.keywords import *
from tasks.base.ui import UI from tasks.base.ui import UI
class AssignmentSwitch(Switch):
def __init__(self, name, active_color: tuple[int, int, int], is_selector=True):
super().__init__(name, is_selector)
self.active_color = active_color
def get(self, main: ModuleBase):
"""
Use image_color_count instead to determine whether the button is selected/active
Args:
main (ModuleBase):
Returns:
str: state name or 'unknown'.
"""
for data in self.state_list:
if main.image_color_count(data['check_button'], self.active_color):
return data['state']
return 'unknown'
class AssignmentOcr(Ocr): class AssignmentOcr(Ocr):
# EN has names in multiple rows # EN has names in multiple rows
merge_thres_y = 20 merge_thres_y = 20
@ -81,28 +57,19 @@ class AssignmentOcr(Ocr):
return matched return matched
ASSIGNMENT_TOP_SWITCH = AssignmentSwitch( ASSIGNMENT_GROUP_LIST = DraggableList(
'AssignmentTopSwitch', 'AssignmentGroupList',
(240, 240, 240) keyword_class=AssignmentGroup,
ocr_class=Ocr,
search_button=OCR_ASSIGNMENT_GROUP_LIST,
active_color=(240, 240, 240),
drag_direction='right'
) )
ASSIGNMENT_TOP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.Character_Materials,
check_button=CHARACTER_MATERIALS
)
ASSIGNMENT_TOP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.EXP_Materials_Credits,
check_button=EXP_MATERIALS_CREDITS
)
ASSIGNMENT_TOP_SWITCH.add_state(
KEYWORDS_ASSIGNMENT_GROUP.Synthesis_Materials,
check_button=SYNTHESIS_MATERIALS
)
ASSIGNMENT_ENTRY_LIST = DraggableList( ASSIGNMENT_ENTRY_LIST = DraggableList(
'AssignmentEntryList', 'AssignmentEntryList',
keyword_class=AssignmentEntry, keyword_class=AssignmentEntry,
ocr_class=AssignmentOcr, ocr_class=AssignmentOcr,
search_button=OCR_ASSIGNMENT_LIST, search_button=OCR_ASSIGNMENT_ENTRY_LIST,
check_row_order=False, check_row_order=False,
active_color=(40, 40, 40) active_color=(40, 40, 40)
) )
@ -120,7 +87,7 @@ class AssignmentUI(UI):
self.goto_group(KEYWORDS_ASSIGNMENT_GROUP.Character_Materials) self.goto_group(KEYWORDS_ASSIGNMENT_GROUP.Character_Materials)
""" """
logger.hr('Assignment group goto', level=3) logger.hr('Assignment group goto', level=3)
if ASSIGNMENT_TOP_SWITCH.set(group, main=self): if ASSIGNMENT_GROUP_LIST.select_row(group, self):
self._wait_until_entry_loaded() self._wait_until_entry_loaded()
def goto_entry(self, entry: AssignmentEntry): def goto_entry(self, entry: AssignmentEntry):
@ -176,8 +143,9 @@ class AssignmentUI(UI):
return current, remain, total return current, remain, total
def _iter_groups(self) -> Iterator[AssignmentGroup]: def _iter_groups(self) -> Iterator[AssignmentGroup]:
for state in ASSIGNMENT_TOP_SWITCH.state_list: ASSIGNMENT_GROUP_LIST.load_rows(main=self)
yield state['state'] for button in ASSIGNMENT_GROUP_LIST.cur_buttons:
yield button.matched_keyword
def _iter_entries(self) -> Iterator[AssignmentEntry]: def _iter_entries(self) -> Iterator[AssignmentEntry]:
""" """