choose_hero_menu.py 33 KB

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