choose_hero_menu.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. import pygame
  2. import json
  3. import os
  4. import random
  5. from datetime import datetime
  6. from game.const import game as G
  7. from game.const import window as W
  8. from game.const import rouge as R
  9. from game.const.rouge import current_lv, remain_exp, current_remain_exp
  10. from game.sound import sound_player
  11. from game.algo import utils as util
  12. from game.utils import local_data_manager as DM
  13. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  14. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, PygameButtonBackIMGRoll, Particle, PygameIMG
  15. def check_rouge_ob_data(data):
  16. hero_data_dic = {
  17. "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1},
  18. "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Chunli": {"exp": 0, "lv": 1},
  19. "Titan": {"exp": 0, "lv": 1}, "Chris": {"exp": 0, "lv": 1}, "SeaPrince_old": {"exp": 0, "lv": 1},
  20. "Witch": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}
  21. }
  22. err_cnt = 0
  23. for k, v in hero_data_dic.items():
  24. if k not in data.keys():
  25. data[k] = v
  26. err_cnt += 1
  27. print(f"缺失{k}数据, 正在补充...")
  28. if err_cnt > 0:
  29. save_encrypt_single_rouge_file(data, "rougeOB")
  30. return data
  31. current_folder_path = os.getcwd()
  32. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  33. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  34. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  35. rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径
  36. rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  37. rougeOB_data = load_rouge_data(rouge_file_path)
  38. if G.IS_ONLINE:
  39. rougeOB_data = util.get_online_data()
  40. rougeOB_data = check_rouge_ob_data(rougeOB_data)
  41. diff_cn = {
  42. "练习": "Baby",
  43. "简单": "Easy",
  44. "困难": "Normal",
  45. "炼狱": "Hell",
  46. "炼狱+": "Hell+",
  47. }
  48. # diff_HP = {"Easy": 0.7, "Normal": 1, "Hell": 1.2, "Hell+": 1.3}
  49. # diff_Delta_Defense = {"Easy": -1200, "Normal": 0, "Hell": 800, "Hell+": 1000}
  50. # diff_speed = {"Easy": 0.9, "Normal": 1, "Hell": 1.05, "Hell+": 1.08}
  51. # diff_contact = {"Easy": 0.7, "Normal": 1, "Hell": 1.2, "Hell+": 1.3}
  52. # diff_exp = {"Easy": 1, "Normal": 1.5, "Hell": 2.2, "Hell+": 3}
  53. diff_dict = {
  54. "Baby": {"unlock": 1, "name": "练习", "info": f"经验效率{int(R.diff_exp['Baby']*100)}%, 怪物血量-50%, 防御-2000", "condition": "纯新手练习难度"},
  55. "Easy": {"unlock": 1, "name": "简单", "info": f"经验效率{int(R.diff_exp['Easy']*100)}%, 怪物血量-30%, 防御-1200", "condition": "最初的起点"},
  56. "Normal": {"unlock": R.pass_status["Easy"], "name": "困难", "info": f"经验效率{int(R.diff_exp['Normal']*100)}%, 怪物血量+0%, 防御+0", "condition": "通关简单难度解锁"},
  57. "Hell": {"unlock": R.pass_status["Normal"], "name": "炼狱", "info": f"经验效率{int(R.diff_exp['Hell']*100)}%, 怪物血量+20%, 防御+800", "condition": "通关困难难度解锁"},
  58. "Hell+": {"unlock": R.pass_status["Hell"], "name": "炼狱+", "info": f"经验效率{int(R.diff_exp['Hell+']*100)}%, 怪物血量+30%, 防御+1000", "condition": "通关炼狱难度解锁"},
  59. }
  60. diff_list = ["练习", "简单", "困难", "炼狱", "炼狱+"]
  61. hero_cn = {
  62. "小倩": "Fox",
  63. "波波丽": "Boboli",
  64. "火影": "Naruto_old",
  65. "阿莎": "Asha",
  66. "玛莉亚": "Maria",
  67. "春丽": "Chunli",
  68. "泰坦": "Titan",
  69. "克莉斯": "Chris",
  70. "海王子": "SeaPrince_old",
  71. "随机": "Random",
  72. }
  73. hero_dict = {
  74. "Fox": {
  75. "own": True, "name": "小倩",
  76. "exp": f"等级{current_lv(rougeOB_data['Fox']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Fox']['exp'])}",
  77. "info": f"技能: 自身血量减少1则糖泡伤害增加{R.FoxSkill(rougeOB_data['Fox']['lv'])}",
  78. "growth": f"成长: 血量: {R.growth['Fox']['HP']}, 伤害: {R.growth['Fox']['Damage']}",
  79. "img": pygame.image.load(r"res/img/ui/game/icon_xq.png").convert_alpha()
  80. },
  81. "Boboli": {
  82. "own": True, "name": "波波丽",
  83. "exp": f"等级{current_lv(rougeOB_data['Boboli']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Boboli']['exp'])}",
  84. "info": f"技能: 每次攻击额外造成{int(R.BoboliSkill(rougeOB_data['Boboli']['lv']) * 100)}%真实伤害",
  85. "growth": f"成长: 血量: {R.growth['Boboli']['HP']}, 伤害: {R.growth['Boboli']['Damage']}",
  86. "img": pygame.image.load(r"res/img/ui/game/icon_bbl.png").convert_alpha()
  87. },
  88. "Naruto_old": {
  89. "own": True, "name": "火影",
  90. "exp": f"等级{current_lv(rougeOB_data['Naruto_old']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Naruto_old']['exp'])}",
  91. "info": f"技能: 首次攻击每只怪物时攻击力变为{int(R.Naruto_oldSkill(rougeOB_data['Naruto_old']['lv']) * 100)}%",
  92. "growth": f"成长: 血量: {R.growth['Naruto_old']['HP']}, 伤害: {R.growth['Naruto_old']['Damage']}",
  93. "img": pygame.image.load(r"res/img/ui/game/icon_hy.png").convert_alpha()
  94. },
  95. "Asha": {
  96. "own": True, "name": "阿莎",
  97. "exp": f"等级{current_lv(rougeOB_data['Asha']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Asha']['exp'])}",
  98. "info": f"技能: 每次糖泡造成伤害恢复血量{R.AshaSkill(rougeOB_data['Asha']['lv']) * 100}%",
  99. "growth": f"成长: 血量: {R.growth['Asha']['HP']}, 伤害: {R.growth['Asha']['Damage']}",
  100. "img": pygame.image.load(r"res/img/ui/game/icon_as.png").convert_alpha()
  101. },
  102. "Maria": {
  103. "own": True, "name": "玛莉亚",
  104. "exp": f"等级{current_lv(rougeOB_data['Maria']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Maria']['exp'])}",
  105. "info": f"技能: 每次造成伤害降低怪物{R.MariaSkill2(rougeOB_data['Maria']['lv'])}防御",
  106. "growth": f"成长: 血量: {R.growth['Maria']['HP']}, 伤害: {R.growth['Maria']['Damage']}",
  107. "img": pygame.image.load(r"res/img/ui/game/icon_mly.png").convert_alpha()
  108. },
  109. "Chunli": {
  110. "own": True, "name": "春丽",
  111. "exp": f"等级{current_lv(rougeOB_data['Chunli']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Chunli']['exp'])}",
  112. "info": f"技能: 每{R.ChunliSkill(rougeOB_data['Chunli']['lv'])}个糖泡放置一个双倍伤害超级糖泡",
  113. "growth": f"成长: 血量: {R.growth['Chunli']['HP']}, 伤害: {R.growth['Chunli']['Damage']}",
  114. "img": pygame.image.load(r"res/img/ui/game/icon_cl.png").convert_alpha()
  115. },
  116. "Titan": {
  117. "own": True, "name": "泰坦",
  118. "exp": f"等级{current_lv(rougeOB_data['Titan']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Titan']['exp'])}",
  119. "info": f"技能: 初始获得{R.TitanSkill(rougeOB_data['Titan']['lv'])}防御",
  120. "growth": f"成长: 血量: {R.growth['Titan']['HP']}, 伤害: {R.growth['Titan']['Damage']}",
  121. "img": pygame.image.load(r"res/img/ui/game/icon_tt.png").convert_alpha()
  122. },
  123. "Chris": {
  124. "own": True, "name": "克莉斯",
  125. "exp": f"等级{current_lv(rougeOB_data['Chris']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Chris']['exp'])}",
  126. "info": f"技能: 灵净{R.ChrisLvSkill(rougeOB_data['Chris']['lv'])}(怪物死后变为光灵协同净化升华)", # 变身光灵, 自动寻敌(区域中)造成3x3 200%伤害, 无击杀则消失, 若无怪物目标则返回克莉丝处恢复1%生命
  127. "growth": f"成长: 血量: {R.growth['Chris']['HP']}, 伤害: {R.growth['Chris']['Damage']}",
  128. "img": pygame.image.load(r"res/img/ui/game/icon_kls.png").convert_alpha()
  129. },
  130. "SeaPrince_old": {
  131. "own": True, "name": "海王子",
  132. "exp": f"等级{current_lv(rougeOB_data['SeaPrince_old']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['SeaPrince_old']['exp'])}",
  133. "info": f"技能: 初始糖币+{R.SeaPrinceSkill1(rougeOB_data['SeaPrince_old']['lv'])}, 每持有1糖币伤害增加{R.SeaPrinceSkill2(rougeOB_data['SeaPrince_old']['lv'])}",
  134. "growth": f"成长: 血量: {R.growth['SeaPrince_old']['HP']}, 伤害: {R.growth['SeaPrince_old']['Damage']}",
  135. "img": pygame.image.load(r"res/img/ui/game/icon_hwz.png").convert_alpha()
  136. },
  137. "Random": {
  138. "own": False, "name": "随机",
  139. "exp": f"--",
  140. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  141. "growth": f"--",
  142. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  143. },
  144. "Surprise": {
  145. "own": True, "name": "随机",
  146. "exp": f"--",
  147. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  148. "growth": f"--",
  149. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  150. },
  151. "Witch": {
  152. "own": True, "name": "随机",
  153. "exp": f"--",
  154. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  155. "growth": f"--",
  156. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  157. },
  158. }
  159. hero_list = ["小倩", "波波丽", "火影", "阿莎", "玛莉亚", "春丽", "泰坦", "克莉斯", "海王子", "随机"]
  160. random_hero_list = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Chunli", "Titan", "Chris", "SeaPrince_old"] + ["Witch"]*9 + ["Surprise"]*9
  161. # random_hero_list = ["Surprise"]
  162. # ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
  163. # {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"}
  164. def reload_data():
  165. global rougeOB_data, diff_dict, hero_dict
  166. rougeOB_data = load_rouge_data(rouge_file_path)
  167. if G.IS_ONLINE:
  168. rougeOB_data = util.get_online_data()
  169. rougeOB_data = check_rouge_ob_data(rougeOB_data)
  170. rougeOB_achievements = load_rouge_data(rouge_achivements_file_path)
  171. max_level = 0
  172. max_diff = "Easy"
  173. diff_status = {"Baby": 1, "Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  174. if rougeOB_achievements["Highest"]["level"] != "":
  175. max_level = rougeOB_achievements["Highest"]["level"]
  176. if rougeOB_achievements["Highest"]["diff"] != "":
  177. max_diff = rougeOB_achievements["Highest"]["diff"]
  178. if max_level == 20:
  179. diff_status[max_diff] = 2
  180. if max_diff == "Hell+":
  181. R.pass_status["Easy"] = 1
  182. R.pass_status["Normal"] = 1
  183. R.pass_status["Hell"] = 1
  184. if max_level >= 15:
  185. R.pass_status["Hell+"] = 1
  186. elif max_diff == "Hell":
  187. R.pass_status["Easy"] = 1
  188. R.pass_status["Normal"] = 1
  189. if max_level >= 15:
  190. R.pass_status["Hell"] = 1
  191. elif max_diff == "Normal":
  192. R.pass_status["Easy"] = 1
  193. if max_level >= 15:
  194. R.pass_status["Normal"] = 1
  195. else:
  196. if max_level >= 15:
  197. R.pass_status["Easy"] = 1
  198. for dif in ["Easy", "Normal", "Hell", "Hell+"]:
  199. if diff_status[dif] == 2:
  200. R.pass_status[dif] = 2
  201. diff_dict = {
  202. "Baby": {"unlock": 1, "name": "练习", "info": f"经验效率{int(R.diff_exp['Baby']*100)}%, 怪物血量-50%, 防御-2000", "condition": "纯新手练习难度"},
  203. "Easy": {"unlock": 1, "name": "简单", "info": f"经验效率{int(R.diff_exp['Easy']*100)}%, 怪物血量-30%, 防御-1200", "condition": "最初的起点"},
  204. "Normal": {"unlock": R.pass_status["Easy"], "name": "困难", "info": f"经验效率{int(R.diff_exp['Normal']*100)}%, 怪物血量+0%, 防御+0", "condition": "通关简单难度解锁"},
  205. "Hell": {"unlock": R.pass_status["Normal"], "name": "炼狱", "info": f"经验效率{int(R.diff_exp['Hell']*100)}%, 怪物血量+20%, 防御+800", "condition": "通关困难难度解锁"},
  206. "Hell+": {"unlock": R.pass_status["Hell"], "name": "炼狱+", "info": f"经验效率{int(R.diff_exp['Hell+']*100)}%, 怪物血量+30%, 防御+1000", "condition": "通关炼狱难度解锁"},
  207. }
  208. hero_dict = {
  209. "Fox": {
  210. "own": True, "name": "小倩",
  211. "exp": f"等级{current_lv(rougeOB_data['Fox']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Fox']['exp'])}",
  212. "info": f"技能: 自身血量减少1则糖泡伤害增加{R.FoxSkill(rougeOB_data['Fox']['lv'])}",
  213. "growth": f"成长: 血量: {R.growth['Fox']['HP']}, 伤害: {R.growth['Fox']['Damage']}",
  214. "img": pygame.image.load(r"res/img/ui/game/icon_xq.png").convert_alpha()
  215. },
  216. "Boboli": {
  217. "own": True, "name": "波波丽",
  218. "exp": f"等级{current_lv(rougeOB_data['Boboli']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Boboli']['exp'])}",
  219. "info": f"技能: 每次攻击额外造成{int(R.BoboliSkill(rougeOB_data['Boboli']['lv']) * 100)}%真实伤害",
  220. "growth": f"成长: 血量: {R.growth['Boboli']['HP']}, 伤害: {R.growth['Boboli']['Damage']}",
  221. "img": pygame.image.load(r"res/img/ui/game/icon_bbl.png").convert_alpha()
  222. },
  223. "Naruto_old": {
  224. "own": True, "name": "火影",
  225. "exp": f"等级{current_lv(rougeOB_data['Naruto_old']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Naruto_old']['exp'])}",
  226. "info": f"技能: 首次攻击每只怪物时攻击力变为{int(R.Naruto_oldSkill(rougeOB_data['Naruto_old']['lv']) * 100)}%",
  227. "growth": f"成长: 血量: {R.growth['Naruto_old']['HP']}, 伤害: {R.growth['Naruto_old']['Damage']}",
  228. "img": pygame.image.load(r"res/img/ui/game/icon_hy.png").convert_alpha()
  229. },
  230. "Asha": {
  231. "own": True, "name": "阿莎",
  232. "exp": f"等级{current_lv(rougeOB_data['Asha']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Asha']['exp'])}",
  233. "info": f"技能: 每次糖泡造成伤害恢复血量{R.AshaSkill(rougeOB_data['Asha']['lv']) * 100}%",
  234. "growth": f"成长: 血量: {R.growth['Asha']['HP']}, 伤害: {R.growth['Asha']['Damage']}",
  235. "img": pygame.image.load(r"res/img/ui/game/icon_as.png").convert_alpha()
  236. },
  237. "Maria": {
  238. "own": True, "name": "玛莉亚",
  239. "exp": f"等级{current_lv(rougeOB_data['Maria']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Maria']['exp'])}",
  240. "info": f"技能: 每次造成伤害降低怪物{R.MariaSkill2(rougeOB_data['Maria']['lv'])}防御",
  241. "growth": f"成长: 血量: {R.growth['Maria']['HP']}, 伤害: {R.growth['Maria']['Damage']}",
  242. "img": pygame.image.load(r"res/img/ui/game/icon_mly.png").convert_alpha()
  243. },
  244. "Chunli": {
  245. "own": True, "name": "春丽",
  246. "exp": f"等级{current_lv(rougeOB_data['Chunli']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Chunli']['exp'])}",
  247. "info": f"技能: 每{R.ChunliSkill(rougeOB_data['Chunli']['lv'])}个糖泡放置一个双倍伤害超级糖泡",
  248. "growth": f"成长: 血量: {R.growth['Chunli']['HP']}, 伤害: {R.growth['Chunli']['Damage']}",
  249. "img": pygame.image.load(r"res/img/ui/game/icon_cl.png").convert_alpha()
  250. },
  251. "Titan": {
  252. "own": True, "name": "泰坦",
  253. "exp": f"等级{current_lv(rougeOB_data['Titan']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Titan']['exp'])}",
  254. "info": f"技能: 初始获得{R.TitanSkill(rougeOB_data['Titan']['lv'])}防御",
  255. "growth": f"成长: 血量: {R.growth['Titan']['HP']}, 伤害: {R.growth['Titan']['Damage']}",
  256. "img": pygame.image.load(r"res/img/ui/game/icon_tt.png").convert_alpha()
  257. },
  258. "Chris": {
  259. "own": True, "name": "克莉斯",
  260. "exp": f"等级{current_lv(rougeOB_data['Chris']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['Chris']['exp'])}",
  261. "info": f"技能: 灵净{R.ChrisLvSkill(rougeOB_data['Chris']['lv'])}(怪物死后变为光灵协同净化升华)", # 变身光灵, 自动寻敌(区域中)造成3x3 200%伤害, 无击杀则消失, 若无怪物目标则返回克莉丝处恢复1%生命
  262. "growth": f"成长: 血量: {R.growth['Chris']['HP']}, 伤害: {R.growth['Chris']['Damage']}",
  263. "img": pygame.image.load(r"res/img/ui/game/icon_kls.png").convert_alpha()
  264. },
  265. "SeaPrince_old": {
  266. "own": True, "name": "海王子",
  267. "exp": f"等级{current_lv(rougeOB_data['SeaPrince_old']['exp'])}, 升级还需经验: {current_remain_exp(rougeOB_data['SeaPrince_old']['exp'])}",
  268. "info": f"技能: 初始糖币+{R.SeaPrinceSkill1(rougeOB_data['SeaPrince_old']['lv'])}, 每持有1糖币伤害增加{R.SeaPrinceSkill2(rougeOB_data['SeaPrince_old']['lv'])}",
  269. "growth": f"成长: 血量: {R.growth['SeaPrince_old']['HP']}, 伤害: {R.growth['SeaPrince_old']['Damage']}",
  270. "img": pygame.image.load(r"res/img/ui/game/icon_hwz.png").convert_alpha()
  271. },
  272. "Random": {
  273. "own": False, "name": "随机",
  274. "exp": f"--",
  275. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  276. "growth": f"--",
  277. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  278. },
  279. "Surprise": {
  280. "own": True, "name": "随机",
  281. "exp": f"--",
  282. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  283. "growth": f"--",
  284. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  285. },
  286. "Witch": {
  287. "own": True, "name": "随机",
  288. "exp": f"--",
  289. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  290. "growth": f"--",
  291. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  292. },
  293. }
  294. class ChoosePage:
  295. def __init__(self):
  296. self.screen = W.MENU
  297. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  298. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  299. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  300. self.rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  301. self.other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  302. self.rougeOB_achievements = {}
  303. self.rougeOB_other_data = {}
  304. self.diff_map = {}
  305. self.is_random = False
  306. self.current_diff = None
  307. self.view_diff = None
  308. self.current_hero = R.rouge_hero
  309. self.diff_num = {"Baby": 1, "Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  310. self.diff_status = {"Baby": 1, "Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  311. self.max_diff = "Easy"
  312. self.init_choose_page()
  313. self.load_achievements_data()
  314. def init_choose_page(self):
  315. DM.init_achievement()
  316. self.rougeOB_achievements = load_rouge_data(self.rouge_achivements_file_path)
  317. def load_achievements_data(self):
  318. if self.rougeOB_achievements["Highest"]["diff"] != "":
  319. self.max_diff = self.rougeOB_achievements["Highest"]["diff"]
  320. if self.diff_num[self.max_diff] > 1:
  321. hero_dict["Random"]["own"] = True
  322. if self.diff_num[R.difficulty]-1 > self.diff_num[self.max_diff]: # 作弊
  323. print("作弊!!!")
  324. R.difficulty = "Easy"
  325. with open("config.json", "r", encoding="utf-8") as json_file:
  326. mapsetdata = json.load(json_file)
  327. mapsetdata["map_set"] = "rogueMapSet"
  328. mapsetdata["rogue_difficulty"] = "Easy"
  329. with open("config.json", "w", encoding="utf-8") as json_file:
  330. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  331. def draw(self):
  332. self.screen.buttons.clear()
  333. # ================================= 信息展示 =================================
  334. info_button = PygameButton(
  335. self.screen.screen, "", 0.25, 0.47, 18, "#2a2a2a",
  336. fg_color=(215,220,217), action=None,
  337. anchor="center", is_bold=True, fix_shape=(360,120), bg_alpha=159,
  338. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  339. )
  340. # ================================= 图片 =================================
  341. cx, cy = 0.35, 0.7
  342. img_button = PygameButtonBackIMG(
  343. self.screen, self.screen.screen, cx, cy, "res/ui/button/img_board.png", "res/ui/button/img_board.png",
  344. action=None, anchor='center', shiny_spark=False
  345. )
  346. img = PygameIMG(self.screen, self.screen.screen, cx, cy, py_img=hero_dict[R.rouge_hero]["img"], anchor='center')
  347. # ================================= 选择 =================================
  348. choose_button = PygameButtonBackIMG(
  349. self.screen, self.screen.screen, 0.13, 0.7, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  350. action=None, anchor='center'
  351. )
  352. # ================================= 展示框 =================================
  353. cy = 0.2
  354. cx = 0.25
  355. button_blank = 0.13
  356. roll_button = PygameButtonBackIMGRoll(
  357. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", hero_list,
  358. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  359. anchor='center', font_name="hk4e_zh-cn.ttf", font_size=24, small_scale=0.7, small_alpha=159, color=(0, 0, 0), shiny_spark=False,
  360. related_button=[info_button, choose_button, img],
  361. notify_action=[
  362. lambda x: hero_update_notify(roll_button, x, self.current_hero),
  363. lambda _: self.update_choose_hero_btn(roll_button, choose_button, info_button),
  364. lambda _: hero_img_update(roll_button, img)
  365. ]
  366. )
  367. # ================================= 初始化 =================================
  368. choose_button.action = lambda: self.choose_hero(roll_button, info_button, choose_button) # 追加action
  369. roll_button.set_current_text(hero_dict[self.current_hero]["name"])
  370. hero_update_notify(roll_button, info_button, self.current_hero)
  371. self.update_choose_hero_btn(roll_button, choose_button, info_button)
  372. # ================================= 添加按钮 =================================
  373. self.screen.buttons.append(info_button)
  374. self.screen.buttons.append(choose_button)
  375. self.screen.buttons.append(roll_button)
  376. self.screen.buttons.append(img_button)
  377. self.screen.buttons.append(img)
  378. # ================================= 上翻页 =================================
  379. self.screen.buttons.append(PygameButtonBackIMG(
  380. self.screen, self.screen.screen, cx, cy-button_blank, "res/ui/button/up.png", "res/ui/button/up_press.png", action=roll_button.roll_up, anchor='center', shiny_spark=False)
  381. )
  382. # ================================= 下翻页 =================================
  383. self.screen.buttons.append(PygameButtonBackIMG(
  384. self.screen, self.screen.screen, cx, cy+button_blank, "res/ui/button/down.png", "res/ui/button/down_press.png", action=roll_button.roll_down, anchor='center', shiny_spark=False)
  385. )
  386. # ===================================================================================
  387. # ===================================================================================
  388. # ===================================================================================
  389. # ================================= 信息展示 =================================
  390. diff_info_button = PygameButton(
  391. self.screen.screen, "", 0.75, 0.47, 18, "#2a2a2a",
  392. fg_color=(215,220,217), action=None,
  393. anchor="center", is_bold=True, fix_shape=(360,100), bg_alpha=159,
  394. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  395. )
  396. # ================================= 选择 =================================
  397. diff_choose_button = PygameButtonBackIMG(
  398. self.screen, self.screen.screen, 0.87, 0.22, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  399. action=None, anchor='center'
  400. )
  401. # ================================= 展示框 =================================
  402. cx, cy = 0.6, 0.2
  403. button_blank = 0.13
  404. diff_roll_button = PygameButtonBackIMGRoll(
  405. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", diff_list,
  406. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  407. anchor='center', font_name="hk4e_zh-cn.ttf", font_size=24, small_scale=0.7, small_alpha=159, color=(0, 0, 0), shiny_spark=False,
  408. related_button=[diff_info_button, diff_choose_button],
  409. notify_action=[
  410. lambda x: diff_update_notify(diff_roll_button, x, R.difficulty),
  411. lambda _: self.update_choose_diff_btn(diff_roll_button, diff_choose_button, diff_info_button)
  412. ]
  413. )
  414. # ================================= 初始化 =================================
  415. diff_choose_button.action = lambda: self.choose_diff(diff_roll_button, diff_info_button, diff_choose_button) # 追加action
  416. diff_roll_button.set_current_text(diff_dict[R.difficulty]["name"])
  417. diff_update_notify(diff_roll_button, diff_info_button, R.difficulty)
  418. self.update_choose_diff_btn(diff_roll_button, diff_choose_button, diff_info_button)
  419. # ================================= 添加按钮 =================================
  420. self.screen.buttons.append(diff_info_button)
  421. self.screen.buttons.append(diff_choose_button)
  422. self.screen.buttons.append(diff_roll_button)
  423. # ================================= 上翻页 =================================
  424. self.screen.buttons.append(PygameButtonBackIMG(
  425. self.screen, self.screen.screen, cx, cy-button_blank, "res/ui/button/up.png", "res/ui/button/up_press.png", action=diff_roll_button.roll_up, anchor='center', shiny_spark=False)
  426. )
  427. # ================================= 下翻页 =================================
  428. self.screen.buttons.append(PygameButtonBackIMG(
  429. self.screen, self.screen.screen, cx, cy+button_blank, "res/ui/button/down.png", "res/ui/button/down_press.png", action=diff_roll_button.roll_down, anchor='center', shiny_spark=False)
  430. )
  431. # ================================= 开始 =================================
  432. self.screen.buttons.append(
  433. PygameButtonBackIMG(
  434. self.screen, self.screen.screen, 0.75, 0.64, "res/ui/button/go.png", "res/ui/button/go_press.png",
  435. action=self.start, anchor='center'
  436. )
  437. )
  438. # ================================= 返回上一级 =================================
  439. self.screen.buttons.append(PygameButtonBackIMG(
  440. self.screen, self.screen.screen, 0.75, 0.8, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.refresh, anchor='center')
  441. )
  442. def start(self):
  443. if self.is_random or R.rouge_hero in {"Surprise", "Witch"}:
  444. if not self.is_random:
  445. current = random.choice(random_hero_list)
  446. R.rouge_hero = current
  447. self.current_hero = current
  448. with open("config.json", "r", encoding="utf-8") as json_file:
  449. mapsetdata = json.load(json_file)
  450. mapsetdata["map_set"] = "rogueMapSet"
  451. mapsetdata["your_hero"] = current
  452. with open("config.json", "w", encoding="utf-8") as json_file:
  453. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  454. R.show_cursor = True
  455. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata")
  456. if not os.path.exists(other_file_path):
  457. rougeOB_other_data = {
  458. "Bomb": [],
  459. "Pet": [],
  460. "Hat": [],
  461. "LastRandom": int(60*datetime.now().hour+datetime.now().minute),
  462. "Other": []
  463. }
  464. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  465. else:
  466. rougeOB_other_data = load_rouge_data(other_file_path)
  467. rougeOB_other_data["LastRandom"] = int(60*datetime.now().hour+datetime.now().minute)
  468. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  469. print(f">> R.show_cursor: {R.show_cursor}")
  470. self.screen.start()
  471. def choose_hero(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  472. cn_name = roll_btn.get_current_text()
  473. current = hero_cn[cn_name]
  474. if current == "Random":
  475. current = random.choice(random_hero_list)
  476. self.is_random = True
  477. else:
  478. self.is_random = False
  479. R.rouge_hero = current
  480. self.current_hero = current
  481. with open("config.json", "r", encoding="utf-8") as json_file:
  482. mapsetdata = json.load(json_file)
  483. mapsetdata["map_set"] = "rogueMapSet"
  484. mapsetdata["your_hero"] = current
  485. with open("config.json", "w", encoding="utf-8") as json_file:
  486. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  487. if self.is_random:
  488. roll_btn.set_current_text("随机")
  489. else:
  490. roll_btn.set_current_text(hero_dict[self.current_hero]["name"])
  491. hero_update_notify(roll_btn, info_button, self.current_hero)
  492. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  493. choose_btn.shiny_spark = False
  494. choose_btn.action = None
  495. def update_choose_hero_btn(self, roll_button, choose_btn, info_button):
  496. # 拿到当前展示的中文名
  497. cn_name = roll_button.get_current_text()
  498. # 拿到内部 key
  499. key = hero_cn[cn_name]
  500. if self.is_random:
  501. if cn_name != "随机":
  502. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  503. choose_btn.shiny_spark = True
  504. choose_btn.action = lambda cn=cn_name: self.choose_hero(roll_button, info_button, choose_btn)
  505. else:
  506. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  507. choose_btn.shiny_spark = False
  508. choose_btn.action = None
  509. return
  510. if R.rouge_hero in {"Surprise", "Witch"}:
  511. if cn_name == "随机":
  512. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  513. choose_btn.shiny_spark = False
  514. choose_btn.action = None
  515. return
  516. # 拿到是否已解锁
  517. owned = hero_dict[key]["own"]
  518. if owned:
  519. if self.current_hero == key: # 当前
  520. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  521. choose_btn.shiny_spark = False
  522. choose_btn.action = None
  523. else:
  524. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  525. choose_btn.shiny_spark = True
  526. choose_btn.action = lambda cn=cn_name: self.choose_hero(roll_button, info_button, choose_btn)
  527. else:
  528. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  529. choose_btn.shiny_spark = False
  530. choose_btn.action = None
  531. def choose_diff(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  532. cn_name = roll_btn.get_current_text()
  533. current = diff_cn[cn_name]
  534. R.difficulty = current
  535. with open("config.json", "r", encoding="utf-8") as json_file:
  536. mapsetdata = json.load(json_file)
  537. mapsetdata["map_set"] = "rogueMapSet"
  538. mapsetdata["rogue_difficulty"] = current
  539. with open("config.json", "w", encoding="utf-8") as json_file:
  540. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  541. roll_btn.set_current_text(diff_dict[R.difficulty]["name"])
  542. diff_update_notify(roll_btn, info_button, R.difficulty)
  543. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  544. choose_btn.shiny_spark = False
  545. choose_btn.action = None
  546. def update_choose_diff_btn(self, roll_button, choose_btn, info_button):
  547. # 拿到当前展示的中文名
  548. cn_name = roll_button.get_current_text()
  549. # 拿到内部 key
  550. key = diff_cn[cn_name]
  551. # 拿到是否已解锁
  552. # owned = (R.pass_status[key] > 0)
  553. owned = diff_dict[key]["unlock"]
  554. if key == "Easy":
  555. owned = True
  556. if owned:
  557. if R.difficulty == key: # 当前
  558. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  559. choose_btn.shiny_spark = False
  560. choose_btn.action = None
  561. else:
  562. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  563. choose_btn.shiny_spark = True
  564. choose_btn.action = lambda cn=cn_name: self.choose_diff(roll_button, info_button, choose_btn)
  565. else:
  566. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  567. choose_btn.shiny_spark = False
  568. choose_btn.action = None
  569. def hero_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  570. cn_name = board.get_current_text()
  571. current = hero_cn[cn_name]
  572. is_chosen = "<当前选择>" if (current == R.rouge_hero) else ""
  573. owned = "" if hero_dict[current]["own"] else "(通关困难1-1后解锁)--"
  574. exp = hero_dict[current]["exp"]
  575. info = hero_dict[current]["info"]
  576. growth = hero_dict[current]["growth"]
  577. observer.set_text(f" {is_chosen}{cn_name} \n {exp}{owned} \n {info} \n {growth} ")
  578. def hero_img_update(board: PygameButtonBackIMGRoll, img: PygameIMG):
  579. cn_name = board.get_current_text()
  580. current = hero_cn[cn_name]
  581. img.update_image(hero_dict[current]["img"])
  582. def diff_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  583. cn_name = board.get_current_text()
  584. current = diff_cn[cn_name]
  585. is_chosen = "<当前选择>" if (current == R.difficulty) else ""
  586. unlock = "" if (R.pass_status[current] > 0 or current == "Easy") else "(通关一次上一难度解锁)"
  587. info = diff_dict[current]["info"]
  588. condition = diff_dict[current]["condition"]
  589. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition} ")