choose_hero_menu.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. rougeOB_data = load_rouge_data(rouge_file_path)
  19. def current_lv(lv):
  20. lv_list = R.lv_list
  21. if lv >= sum(lv_list):
  22. return "--"
  23. for k in range(0, 14):
  24. if sum(lv_list[:k]) <= lv < sum(lv_list[:k + 1]):
  25. return str(sum(lv_list[:k + 1]) - lv)
  26. diff_cn = {
  27. "简单": "Easy",
  28. "困难": "Normal",
  29. "炼狱": "Hell",
  30. "炼狱+": "Hell+",
  31. }
  32. # diff_HP = {"Easy": 0.7, "Normal": 1, "Hell": 1.2, "Hell+": 1.3}
  33. # diff_Delta_Defense = {"Easy": -1200, "Normal": 0, "Hell": 800, "Hell+": 1000}
  34. # diff_speed = {"Easy": 0.9, "Normal": 1, "Hell": 1.05, "Hell+": 1.08}
  35. # diff_contact = {"Easy": 0.7, "Normal": 1, "Hell": 1.2, "Hell+": 1.3}
  36. # diff_exp = {"Easy": 1, "Normal": 1.5, "Hell": 2.2, "Hell+": 3}
  37. diff_dict = {
  38. "Easy": {"unlock": R.pass_status["Easy"], "name": "简单", "info": "经验效率100%, 怪物血量-30%, 防御-1200", "condition": "最初的起点"},
  39. "Normal": {"unlock": R.pass_status["Normal"], "name": "困难", "info": "经验效率150%, 怪物血量+0%, 防御+0", "condition": "通关简单难度解锁"},
  40. "Hell": {"unlock": R.pass_status["Hell"], "name": "炼狱", "info": "经验效率220%, 怪物血量+20%, 防御+800", "condition": "通关困难难度解锁"},
  41. "Hell+": {"unlock": R.pass_status["Hell+"], "name": "炼狱+", "info": "经验效率300%, 怪物血量+30%, 防御+1000", "condition": "通关炼狱难度解锁"},
  42. }
  43. diff_list = ["简单", "困难", "炼狱", "炼狱+"]
  44. hero_cn = {
  45. "小倩": "Fox",
  46. "波波丽": "Boboli",
  47. "火影": "Naruto_old",
  48. "阿莎": "Asha",
  49. "玛莉亚": "Maria",
  50. "随机": "Random",
  51. }
  52. hero_dict = {
  53. "Fox": {
  54. "own": True, "name": "小倩",
  55. "exp": f"等级{rougeOB_data['Fox']['lv']}, 升级还需经验: {current_lv(rougeOB_data['Fox']['exp'])}",
  56. "info": f"技能: 自身血量减少1则糖泡伤害增加{R.FoxSkill(rougeOB_data['Fox']['lv'])}",
  57. "growth": f"成长: 血量: 100, 伤害: 50",
  58. "img": pygame.image.load(r"res/img/ui/game/icon_xq.png").convert_alpha()
  59. },
  60. "Boboli": {
  61. "own": True, "name": "波波丽",
  62. "exp": f"等级{rougeOB_data['Boboli']['lv']}, 升级还需经验: {current_lv(rougeOB_data['Boboli']['exp'])}",
  63. "info": f"技能: 每次攻击额外造成{int(R.BoboliSkill(rougeOB_data['Boboli']['lv']) * 100)}%真实伤害",
  64. "growth": f"成长: 血量: 60, 伤害: 90",
  65. "img": pygame.image.load(r"res/img/ui/game/icon_bbl.png").convert_alpha()
  66. },
  67. "Naruto_old": {
  68. "own": True, "name": "火影",
  69. "exp": f"等级{rougeOB_data['Naruto_old']['lv']}, 升级还需经验: {current_lv(rougeOB_data['Naruto_old']['exp'])}",
  70. "info": f"技能: 首次攻击每只怪物时攻击力变为{int(R.Naruto_oldSkill(rougeOB_data['Naruto_old']['lv']) * 100)}%",
  71. "growth": f"成长: 血量: 50, 伤害: 100",
  72. "img": pygame.image.load(r"res/img/ui/game/icon_hy.png").convert_alpha()
  73. },
  74. "Asha": {
  75. "own": True, "name": "阿莎",
  76. "exp": f"等级{rougeOB_data['Asha']['lv']}, 升级还需经验: {current_lv(rougeOB_data['Asha']['exp'])}",
  77. "info": f"技能: 每次糖泡造成伤害恢复血量{R.AshaSkill(rougeOB_data['Asha']['lv']) * 100}%",
  78. "growth": f"成长: 血量: 90, 伤害: 60",
  79. "img": pygame.image.load(r"res/img/ui/game/icon_as.png").convert_alpha()
  80. },
  81. "Maria": {
  82. "own": True, "name": "玛莉亚",
  83. "exp": f"等级{rougeOB_data['Maria']['lv']}, 升级还需经验: {current_lv(rougeOB_data['Maria']['exp'])}",
  84. "info": f"技能: 每次造成伤害降低怪物{R.MariaSkill2(rougeOB_data['Maria']['lv'])}防御",
  85. "growth": f"成长: 血量: 300, 伤害: 300",
  86. "img": pygame.image.load(r"res/img/ui/game/icon_mly.png").convert_alpha()
  87. },
  88. "Random": {
  89. "own": False, "name": "随机",
  90. "exp": f"--",
  91. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  92. "growth": f"--",
  93. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  94. },
  95. "Surprise": {
  96. "own": True, "name": "随机",
  97. "exp": f"--",
  98. "info": f"随机选择一个英雄(含隐藏角色)与引路人",
  99. "growth": f"--",
  100. "img": pygame.image.load(r"res/img/ui/game/icon_random.png").convert_alpha()
  101. },
  102. }
  103. hero_list = ["小倩", "波波丽", "火影", "阿莎", "玛莉亚", "随机"]
  104. random_hero_list = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise", "Surprise", "Surprise"]
  105. # random_hero_list = ["Surprise"]
  106. # ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
  107. # {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"}
  108. class ChoosePage:
  109. def __init__(self):
  110. self.screen = W.MENU
  111. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  112. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  113. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  114. self.rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  115. self.other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  116. self.rougeOB_achievements = {}
  117. self.rougeOB_other_data = {}
  118. self.diff_map = {}
  119. self.is_random = False
  120. self.current_diff = None
  121. self.view_diff = None
  122. self.current_hero = R.rouge_hero
  123. self.diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  124. self.diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  125. self.max_diff = {}
  126. self.init_choose_page()
  127. self.load_achievements_data()
  128. def init_choose_page(self):
  129. DM.init_achievement()
  130. self.rougeOB_achievements = load_rouge_data(self.rouge_achivements_file_path)
  131. def load_achievements_data(self):
  132. self.max_diff = self.rougeOB_achievements["Highest"]["diff"]
  133. if self.diff_num[self.max_diff] > 1:
  134. hero_dict["Random"]["own"] = True
  135. def draw(self):
  136. self.screen.buttons.clear()
  137. # ================================= 信息展示 =================================
  138. info_button = PygameButton(
  139. self.screen.screen, "", 0.25, 0.47, 18, "#2a2a2a",
  140. fg_color=(215,220,217), action=None,
  141. anchor="center", is_bold=True, fix_shape=(360,120), bg_alpha=159,
  142. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  143. )
  144. # ================================= 图片 =================================
  145. cx, cy = 0.35, 0.7
  146. img_button = PygameButtonBackIMG(
  147. self.screen, self.screen.screen, cx, cy, "res/ui/button/img_board.png", "res/ui/button/img_board.png",
  148. action=None, anchor='center', shiny_spark=False
  149. )
  150. img = PygameIMG(self.screen, self.screen.screen, cx, cy, py_img=hero_dict[R.rouge_hero]["img"], anchor='center')
  151. # ================================= 选择 =================================
  152. choose_button = PygameButtonBackIMG(
  153. self.screen, self.screen.screen, 0.13, 0.7, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  154. action=None, anchor='center'
  155. )
  156. # ================================= 展示框 =================================
  157. cy = 0.2
  158. cx = 0.25
  159. button_blank = 0.13
  160. roll_button = PygameButtonBackIMGRoll(
  161. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", hero_list,
  162. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  163. 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,
  164. related_button=[info_button, choose_button, img],
  165. notify_action=[
  166. lambda x: hero_update_notify(roll_button, x, self.current_hero),
  167. lambda _: self.update_choose_hero_btn(roll_button, choose_button, info_button),
  168. lambda _: hero_img_update(roll_button, img)
  169. ]
  170. )
  171. # ================================= 初始化 =================================
  172. choose_button.action = lambda: self.choose_hero(roll_button, info_button, choose_button) # 追加action
  173. roll_button.set_current_text(hero_dict[self.current_hero]["name"])
  174. hero_update_notify(roll_button, info_button, self.current_hero)
  175. self.update_choose_hero_btn(roll_button, choose_button, info_button)
  176. # ================================= 添加按钮 =================================
  177. self.screen.buttons.append(info_button)
  178. self.screen.buttons.append(choose_button)
  179. self.screen.buttons.append(roll_button)
  180. self.screen.buttons.append(img_button)
  181. self.screen.buttons.append(img)
  182. # ================================= 上翻页 =================================
  183. self.screen.buttons.append(PygameButtonBackIMG(
  184. 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)
  185. )
  186. # ================================= 下翻页 =================================
  187. self.screen.buttons.append(PygameButtonBackIMG(
  188. 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)
  189. )
  190. # ===================================================================================
  191. # ===================================================================================
  192. # ================================= 信息展示 =================================
  193. diff_info_button = PygameButton(
  194. self.screen.screen, "", 0.75, 0.47, 18, "#2a2a2a",
  195. fg_color=(215,220,217), action=None,
  196. anchor="center", is_bold=True, fix_shape=(360,100), bg_alpha=159,
  197. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  198. )
  199. # ================================= 选择 =================================
  200. diff_choose_button = PygameButtonBackIMG(
  201. self.screen, self.screen.screen, 0.87, 0.22, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  202. action=None, anchor='center'
  203. )
  204. # ================================= 展示框 =================================
  205. cx, cy = 0.6, 0.2
  206. button_blank = 0.13
  207. diff_roll_button = PygameButtonBackIMGRoll(
  208. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", diff_list,
  209. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  210. 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,
  211. related_button=[diff_info_button, diff_choose_button],
  212. notify_action=[
  213. lambda x: diff_update_notify(diff_roll_button, x, R.difficulty),
  214. lambda _: self.update_choose_diff_btn(diff_roll_button, diff_choose_button, diff_info_button)
  215. ]
  216. )
  217. # ================================= 初始化 =================================
  218. diff_choose_button.action = lambda: self.choose_diff(diff_roll_button, diff_info_button, diff_choose_button) # 追加action
  219. diff_roll_button.set_current_text(diff_dict[R.difficulty]["name"])
  220. diff_update_notify(diff_roll_button, diff_info_button, R.difficulty)
  221. self.update_choose_diff_btn(diff_roll_button, diff_choose_button, diff_info_button)
  222. # ================================= 添加按钮 =================================
  223. self.screen.buttons.append(diff_info_button)
  224. self.screen.buttons.append(diff_choose_button)
  225. self.screen.buttons.append(diff_roll_button)
  226. # ================================= 上翻页 =================================
  227. self.screen.buttons.append(PygameButtonBackIMG(
  228. 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)
  229. )
  230. # ================================= 下翻页 =================================
  231. self.screen.buttons.append(PygameButtonBackIMG(
  232. 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)
  233. )
  234. # ================================= 开始 =================================
  235. self.screen.buttons.append(
  236. PygameButtonBackIMG(
  237. self.screen, self.screen.screen, 0.75, 0.64, "res/ui/button/go.png", "res/ui/button/go_press.png",
  238. action=self.start, anchor='center'
  239. )
  240. )
  241. # ================================= 返回上一级 =================================
  242. self.screen.buttons.append(PygameButtonBackIMG(
  243. 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')
  244. )
  245. def start(self):
  246. if self.is_random or R.rouge_hero in {"Surprise"}:
  247. if not self.is_random:
  248. current = random.choice(random_hero_list)
  249. R.rouge_hero = current
  250. self.current_hero = current
  251. with open("config.json", "r", encoding="utf-8") as json_file:
  252. mapsetdata = json.load(json_file)
  253. mapsetdata["map_set"] = "rogueMapSet"
  254. mapsetdata["your_hero"] = current
  255. with open("config.json", "w", encoding="utf-8") as json_file:
  256. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  257. R.show_cursor = True
  258. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata")
  259. if not os.path.exists(other_file_path):
  260. rougeOB_other_data = {
  261. "Bomb": [],
  262. "Pet": [],
  263. "Hat": [],
  264. "LastRandom": int(60*datetime.now().hour+datetime.now().minute),
  265. "Other": []
  266. }
  267. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  268. else:
  269. rougeOB_other_data = load_rouge_data(other_file_path)
  270. rougeOB_other_data["LastRandom"] = int(60*datetime.now().hour+datetime.now().minute)
  271. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  272. print(f">> R.show_cursor: {R.show_cursor}")
  273. self.screen.start()
  274. def choose_hero(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  275. cn_name = roll_btn.get_current_text()
  276. current = hero_cn[cn_name]
  277. if current == "Random":
  278. current = random.choice(random_hero_list)
  279. self.is_random = True
  280. else:
  281. self.is_random = False
  282. R.rouge_hero = current
  283. self.current_hero = current
  284. with open("config.json", "r", encoding="utf-8") as json_file:
  285. mapsetdata = json.load(json_file)
  286. mapsetdata["map_set"] = "rogueMapSet"
  287. mapsetdata["your_hero"] = current
  288. with open("config.json", "w", encoding="utf-8") as json_file:
  289. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  290. if self.is_random:
  291. roll_btn.set_current_text("随机")
  292. else:
  293. roll_btn.set_current_text(hero_dict[self.current_hero]["name"])
  294. hero_update_notify(roll_btn, info_button, self.current_hero)
  295. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  296. choose_btn.shiny_spark = False
  297. choose_btn.action = None
  298. def update_choose_hero_btn(self, roll_button, choose_btn, info_button):
  299. # 拿到当前展示的中文名
  300. cn_name = roll_button.get_current_text()
  301. # 拿到内部 key
  302. key = hero_cn[cn_name]
  303. if self.is_random:
  304. if cn_name != "随机":
  305. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  306. choose_btn.shiny_spark = True
  307. choose_btn.action = lambda cn=cn_name: self.choose_hero(roll_button, info_button, choose_btn)
  308. else:
  309. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  310. choose_btn.shiny_spark = False
  311. choose_btn.action = None
  312. return
  313. if R.rouge_hero in {"Surprise"}:
  314. if cn_name == "随机":
  315. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  316. choose_btn.shiny_spark = False
  317. choose_btn.action = None
  318. return
  319. # 拿到是否已解锁
  320. owned = hero_dict[key]["own"]
  321. if owned:
  322. if self.current_hero == key: # 当前
  323. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  324. choose_btn.shiny_spark = False
  325. choose_btn.action = None
  326. else:
  327. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  328. choose_btn.shiny_spark = True
  329. choose_btn.action = lambda cn=cn_name: self.choose_hero(roll_button, info_button, choose_btn)
  330. else:
  331. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  332. choose_btn.shiny_spark = False
  333. choose_btn.action = None
  334. def choose_diff(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  335. cn_name = roll_btn.get_current_text()
  336. current = diff_cn[cn_name]
  337. R.difficulty = current
  338. with open("config.json", "r", encoding="utf-8") as json_file:
  339. mapsetdata = json.load(json_file)
  340. mapsetdata["map_set"] = "rogueMapSet"
  341. mapsetdata["rogue_difficulty"] = current
  342. with open("config.json", "w", encoding="utf-8") as json_file:
  343. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  344. roll_btn.set_current_text(diff_dict[R.difficulty]["name"])
  345. diff_update_notify(roll_btn, info_button, R.difficulty)
  346. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  347. choose_btn.shiny_spark = False
  348. choose_btn.action = None
  349. def update_choose_diff_btn(self, roll_button, choose_btn, info_button):
  350. # 拿到当前展示的中文名
  351. cn_name = roll_button.get_current_text()
  352. # 拿到内部 key
  353. key = diff_cn[cn_name]
  354. # 拿到是否已解锁
  355. owned = (R.pass_status[key] > 0)
  356. if owned:
  357. if R.difficulty == key: # 当前
  358. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  359. choose_btn.shiny_spark = False
  360. choose_btn.action = None
  361. else:
  362. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  363. choose_btn.shiny_spark = True
  364. choose_btn.action = lambda cn=cn_name: self.choose_diff(roll_button, info_button, choose_btn)
  365. else:
  366. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  367. choose_btn.shiny_spark = False
  368. choose_btn.action = None
  369. def hero_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  370. cn_name = board.get_current_text()
  371. current = hero_cn[cn_name]
  372. is_chosen = "<当前选择>" if (current == R.rouge_hero) else ""
  373. owned = "" if hero_dict[current]["own"] else "(通关一次游戏解锁)--"
  374. exp = hero_dict[current]["exp"]
  375. info = hero_dict[current]["info"]
  376. growth = hero_dict[current]["growth"]
  377. observer.set_text(f" {is_chosen}{cn_name} \n {exp}{owned} \n {info} \n {growth} ")
  378. def hero_img_update(board: PygameButtonBackIMGRoll, img: PygameIMG):
  379. cn_name = board.get_current_text()
  380. current = hero_cn[cn_name]
  381. img.update_image(hero_dict[current]["img"])
  382. def diff_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  383. cn_name = board.get_current_text()
  384. current = diff_cn[cn_name]
  385. is_chosen = "<当前选择>" if (current == R.difficulty) else ""
  386. unlock = "" if (R.pass_status[current] > 0) else "(通关一次游戏解锁)"
  387. info = diff_dict[current]["info"]
  388. condition = diff_dict[current]["condition"]
  389. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition} ")