Sfoglia il codice sorgente

refactor(GlobalGame): Reuse shared confirm button for exit and refresh dialogs
- replace task-specific confirmation assets with GlobalGameAssets.I_UI_CONFIRM
- remove obsolete exit and refresh confirmation definitions and templates
- update related image metadata

neptine 1 mese fa
parent
commit
cdde0e49de

+ 3 - 2
tasks/AbyssShadows/script_task.py

@@ -21,6 +21,7 @@ from tasks.GameUi.page import page_main, page_kekkai_toppa, page_shikigami_recor
 from tasks.RealmRaid.assets import RealmRaidAssets
 
 from module.logger import logger
+from tasks.GlobalGame.assets import GlobalGameAssets
 from module.exception import TaskEnd
 from module.atom.image_grid import ImageGrid
 from module.base.utils import point2str
@@ -547,13 +548,13 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AbyssShadowsAssets):
             self.screenshot()
             if self.appear_then_click(self.I_EXIT, interval=2):
                 continue
-            if self.appear_then_click(self.I_EXIT_ENSURE, interval=2):
+            if self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=2):
                 continue
             if self.appear_then_click(self.I_WIN, interval=2):
                 continue
             if self.appear(self.I_ABYSS_NAVIGATION):
                 break
-        logger.info(f"Click {self.I_EXIT_ENSURE.name}")
+        logger.info(f"Click {GlobalGameAssets.I_UI_CONFIRM.name}")
 
         return True
 

+ 0 - 2
tasks/Component/GeneralBattle/assets.py

@@ -109,8 +109,6 @@ class GeneralBattleAssets:
 	I_STATISTICS = RuleImage(roi_front=(70,630,33,28), roi_back=(35,28,411,661), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_statistics.png")
 	# 左上角的退出 
 	I_EXIT = RuleImage(roi_front=(14,12,43,41), roi_back=(14,12,43,41), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_exit.png")
-	# 退出确认 
-	I_EXIT_ENSURE = RuleImage(roi_front=(674,388,135,63), roi_back=(674,388,135,63), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_exit_ensure.png")
 	# 左上角好友图标 
 	I_FRIENDS = RuleImage(roi_front=(89,14,36,36), roi_back=(89,14,36,36), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_friends.png")
 	# 结算时左下角统计图标 

BIN
tasks/Component/GeneralBattle/gb/gb_exit_ensure.png


+ 0 - 9
tasks/Component/GeneralBattle/gb/image.json

@@ -152,15 +152,6 @@
     "threshold": 0.8,
     "description": "左上角的退出"
   },
-  {
-    "itemName": "exit_ensure",
-    "imageName": "gb_exit_ensure.png",
-    "roiFront": "674,388,135,63",
-    "roiBack": "674,388,135,63",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "退出确认"
-  },
   {
     "itemName": "friends",
     "imageName": "gb_friends.png",

+ 6 - 5
tasks/Component/GeneralBattle/general_battle.py

@@ -19,6 +19,7 @@ from tasks.Component.GeneralBuff.general_buff import GeneralBuff
 from tasks.Component.GeneralBattle.battle_wait import BattleWait
 
 from module.logger import logger
+from tasks.GlobalGame.assets import GlobalGameAssets
 
 
 class GeneralBattle(BattleWait, GeneralBuff):
@@ -102,18 +103,18 @@ class GeneralBattle(BattleWait, GeneralBuff):
             self.screenshot()
             if self.appear_then_click(self.I_EXIT, interval=1.5):
                 continue
-            if self.appear(self.I_EXIT_ENSURE):
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 break
         logger.info(f"Click {self.I_EXIT.name}")
 
         # 点击返回确认
         while 1:
             self.screenshot()
-            if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
+            if self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=1.5):
                 continue
             if self.appear(self.I_FALSE):
                 break
-        logger.info(f"Click {self.I_EXIT_ENSURE.name}")
+        logger.info(f"Click {GlobalGameAssets.I_UI_CONFIRM.name}")
 
         # 点击失败确认
         self.wait_until_appear(self.I_FALSE)
@@ -144,13 +145,13 @@ class GeneralBattle(BattleWait, GeneralBuff):
             self.screenshot()
             if self.appear_then_click(self.I_EXIT, interval=1.5):
                 continue
-            if self.appear(self.I_EXIT_ENSURE):
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 break
 
         # 点击返回确认
         while 1:
             self.screenshot()
-            if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
+            if self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=1.5):
                 continue
             if self.appear_then_click(self.I_FALSE, interval=1.5):
                 continue

+ 2 - 1
tasks/Duel/script_task.py

@@ -7,6 +7,7 @@ import random
 from datetime import time, datetime, timedelta
 
 from module.logger import logger
+from tasks.GlobalGame.assets import GlobalGameAssets
 from module.exception import TaskEnd
 from module.base.timer import Timer
 
@@ -207,7 +208,7 @@ class ScriptTask(GameUi, GeneralBattle, SwitchSoul, DuelAssets, SwitchOnmyoji):
             self.screenshot()
             if self.appear(self.I_D_FAIL) or self.appear(self.I_FALSE):
                 return
-            if self.appear_then_click(self.I_EXIT_ENSURE):
+            if self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM):
                 continue
             # 选式神界面退出或战斗内退出
             if self.appear_then_click(self.I_DUEL_EXIT, interval=1) or self.appear_then_click(self.I_EXIT, interval=1):

+ 0 - 2
tasks/RealmRaid/assets.py

@@ -39,8 +39,6 @@ class RealmRaidAssets:
 	I_FIRE = RuleImage(roi_front=(982,494,136,63), roi_back=(140,129,1024,584), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fire.png")
 	# 打完个后出现的领取奖励 
 	I_SOUL_RAID = RuleImage(roi_front=(577,502,100,100), roi_back=(577,502,100,100), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_soul_raid.png")
-	# 刷新确认 
-	I_FRESH_ENSURE = RuleImage(roi_front=(672,403,173,59), roi_back=(672,403,173,59), threshold=0.8, method="Template matching", file="./tasks/RealmRaid/res/res_fresh_ensure.png")
 	# 没有锁图片,适配呱太入侵 
 	I_UNLOCK_2 = RuleImage(roi_front=(1002,643,30,41), roi_back=(1002,643,30,41), threshold=0.9, method="Template matching", file="./tasks/RealmRaid/res/res_unlock_2.png")
 	# 以锁图片,适配呱太 

+ 1 - 10
tasks/RealmRaid/res/image.json

@@ -125,15 +125,6 @@
     "threshold": 0.8,
     "description": "打完个后出现的领取奖励"
   },
-  {
-    "itemName": "fresh_ensure",
-    "imageName": "res_fresh_ensure.png",
-    "roiFront": "672,403,173,59",
-    "roiBack": "672,403,173,59",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "刷新确认"
-  },
   {
     "itemName": "unlock_2",
     "imageName": "res_unlock_2.png",
@@ -179,4 +170,4 @@
     "threshold": 0.8,
     "description": "description"
   }
-]
+]

BIN
tasks/RealmRaid/res/res_fresh_ensure.png


+ 11 - 10
tasks/RealmRaid/script_task.py

@@ -10,6 +10,7 @@ from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_realm_raid, page_main, page_shikigami_records
 from tasks.RealmRaid.assets import RealmRaidAssets
+from tasks.GlobalGame.assets import GlobalGameAssets
 from tasks.RealmRaid.config import RealmRaid, RaidMode, AttackNumber, WhenAttackFail
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.Component.GeneralBattle.battle_wait import battle_wait_strategy
@@ -154,9 +155,9 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
         while 1:
             self.screenshot()
             #看到弹窗点掉,不然会卡死
-            if self.appear(self.I_FRESH_ENSURE):
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 logger.info("Pop-up detected: Refresh Confirmation. Clicking Confirm.")
-                self.appear_then_click(self.I_FRESH_ENSURE, interval=1.5)
+                self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=1.5)
                 continue
             # 检查票数
             if not self.check_ticket(con.raid_config.number_base):
@@ -179,10 +180,10 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
                 else:
                     logger.info('No one can attack, break')
                     # 检查是否有“刷新确认”弹窗挡路
-                    if self.appear(self.I_FRESH_ENSURE):
+                    if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                         logger.info("Closing obstructing refresh dialog (Click Ensure)...")
                         # 点击“确定”来完成刷新(或者你可以改成点取消)
-                        self.appear_then_click(self.I_FRESH_ENSURE, interval=2)
+                        self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=2)
                     success = False
                     break
             # 判断是不是左上角第一个
@@ -459,15 +460,15 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
             return False
         while 1:
             self.screenshot()
-            if self.appear(self.I_FRESH_ENSURE):
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 break
             if self.appear_then_click(self.I_FRESH, interval=1):
                 continue
         while 1:
             self.screenshot()
-            if not self.appear(self.I_FRESH_ENSURE):
+            if not self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 return True
-            if self.appear_then_click(self.I_FRESH_ENSURE, interval=1):
+            if self.appear_then_click(GlobalGameAssets.I_UI_CONFIRM, interval=1):
                 continue
 
     def fire(self, order: int):
@@ -483,8 +484,8 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
             
             logger.info("Title not found! Checking for popups or rewards...")
             
-            # 如果看到了“刷新确认”弹窗 (I_FRESH_ENSURE 是右边的确定)
-            if self.appear(self.I_FRESH_ENSURE):
+            # 如果看到了“刷新确认”弹窗 (GlobalGameAssets.I_UI_CONFIRM 是右边的确定)
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 logger.info("Refresh popup detected! Clicking CANCEL (Red Button).")
                 # 点击“取消”按钮的坐标 (基于1280x720分辨率)
                 self.device.click(x=530, y=460) 
@@ -506,7 +507,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RealmRaidAssets):
             self.screenshot()
             
             # 双重保险:如果在进攻阶段又弹出了窗口,也把它关掉
-            if self.appear(self.I_FRESH_ENSURE):
+            if self.appear(GlobalGameAssets.I_UI_CONFIRM):
                 logger.info("Refresh popup blocking attack! Clicking CANCEL.")
                 self.device.click(x=530, y=460) # 点取消
                 time.sleep(1.0)