Răsfoiți Sursa

perf(game_ui): Add pop-up window when entering records

runhey 3 ani în urmă
părinte
comite
a2864648d7

BIN
tasks/GameUi/additional/additional_ad_disappear.png


BIN
tasks/GameUi/additional/additional_records_close.png


+ 20 - 0
tasks/GameUi/additional/records.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "ad_disappear",
+    "imageName": "additional_ad_disappear.png",
+    "roiFront": "412,405,37,40",
+    "roiBack": "412,405,37,40",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "records_close",
+    "imageName": "additional_records_close.png",
+    "roiFront": "914,143,30,30",
+    "roiBack": "914,143,30,30",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 7 - 0
tasks/GameUi/assets.py

@@ -10,6 +10,13 @@ from module.atom.list import RuleList
 class GameUiAssets: 
 class GameUiAssets: 
 
 
 
 
+	# Image Rule Assets
+	# description 
+	I_AD_DISAPPEAR = RuleImage(roi_front=(412,405,37,40), roi_back=(412,405,37,40), threshold=0.9, method="Template matching", file="./tasks/GameUi/additional/additional_ad_disappear.png")
+	# description 
+	I_RECORDS_CLOSE = RuleImage(roi_front=(914,143,30,30), roi_back=(914,143,30,30), threshold=0.8, method="Template matching", file="./tasks/GameUi/additional/additional_records_close.png")
+
+
 	# Image Rule Assets
 	# Image Rule Assets
 	# description 
 	# description 
 	I_CHECK_MAIN = RuleImage(roi_front=(801,109,38,37), roi_back=(49,98,1033,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")
 	I_CHECK_MAIN = RuleImage(roi_front=(801,109,38,37), roi_back=(49,98,1033,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")

+ 15 - 8
tasks/GameUi/game_ui.py

@@ -2,6 +2,7 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
+from time import sleep
 
 
 from module.base.decorator import run_once
 from module.base.decorator import run_once
 from module.base.timer import Timer
 from module.base.timer import Timer
@@ -197,6 +198,18 @@ class GameUi(BaseTask, GameUiAssets):
             for page in visited:
             for page in visited:
                 if page.parent is None or page.check_button is None:
                 if page.parent is None or page.check_button is None:
                     continue
                     continue
+                # 如果当前页面不出现可以检测当前按键的按钮,那可能是有一些弹窗,广告,这个时候额外处理
+                if page.additional:
+                    if not isinstance(page.additional, list):
+                        page.additional = [page.additional]
+                    for button in page.additional:
+                        if isinstance(button, RuleImage) and self.appear_then_click(button, interval=1):
+                            sleep(0.4)
+                            logger.info(f'Page {page} additional button {button} clicked')
+                        if isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=1):
+                            sleep(0.4)
+                            logger.info(f'Page {page} additional button {button} clicked')
+
                 # 获取当前页面的要点击的按钮
                 # 获取当前页面的要点击的按钮
                 if self.appear(page.check_button, interval=4):
                 if self.appear(page.check_button, interval=4):
                     logger.info(f'Page switch: {page} -> {page.parent}')
                     logger.info(f'Page switch: {page} -> {page.parent}')
@@ -206,13 +219,7 @@ class GameUi(BaseTask, GameUiAssets):
                         confirm_timer.reset()
                         confirm_timer.reset()
                         clicked = True
                         clicked = True
                         break
                         break
-                # 如果当前页面不出现可以检测当前按键的按钮,那可能是有一些弹窗,广告,这个时候额外处理
-                elif page.additional:
-                    for button in page.additional:
-                        if isinstance(button, RuleImage) and self.appear_then_click(button, interval=1):
-                            logger.info(f'Page {page} additional button {button} clicked')
-                        if isinstance(button, RuleOcr) and self.ocr_appear_click(button, interval=1):
-                            logger.info(f'Page {page} additional button {button} clicked')
+
             if clicked:
             if clicked:
                 continue
                 continue
 
 
@@ -232,4 +239,4 @@ if __name__ == '__main__':
     d = Device(c)
     d = Device(c)
     game = GameUi(config=c, device=d)
     game = GameUi(config=c, device=d)
     game.ui_get_current_page(skip_first_screenshot=True)
     game.ui_get_current_page(skip_first_screenshot=True)
-    game.ui_goto(page_delegation)
+    game.ui_goto(page_shikigami_records)

+ 1 - 0
tasks/GameUi/page.py

@@ -115,6 +115,7 @@ page_town.link(button=G.I_TOWN_GOTO_HYAKKISEN, destination=page_hyakkisen)
 # ************************************* 庭院部分 *****************************************#
 # ************************************* 庭院部分 *****************************************#
 # 式神录 shikigami_records
 # 式神录 shikigami_records
 page_shikigami_records = Page(G.I_CHECK_RECORDS)
 page_shikigami_records = Page(G.I_CHECK_RECORDS)
+page_shikigami_records.additional = [G.I_AD_DISAPPEAR, G.I_RECORDS_CLOSE]
 page_shikigami_records.link(button=G.I_BACK_Y, destination=page_main)
 page_shikigami_records.link(button=G.I_BACK_Y, destination=page_main)
 page_main.link(button=G.I_MAIN_GOTO_SHIKIGAMI_RECORDS, destination=page_shikigami_records)
 page_main.link(button=G.I_MAIN_GOTO_SHIKIGAMI_RECORDS, destination=page_shikigami_records)
 # 阴阳术 onmyodo
 # 阴阳术 onmyodo