skin_menu.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. import pygame
  2. import json
  3. import os
  4. from datetime import datetime
  5. from game.const import game as G
  6. from game.const import window as W
  7. from game.const import rouge as R
  8. from game.sound import sound_player
  9. from game.utils import local_data_manager as DM
  10. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  11. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, PygameButtonBackIMGRoll, Particle, PygameIMG
  12. current_folder_path = os.getcwd()
  13. cursor_cn = {
  14. "引路人-黄色荧火": "fire_cursor1",
  15. "引路人-森绿荧火": "fire_cursor2",
  16. "引路人-小酷比": "fire_cursor_kubi",
  17. "引路人-金酷比": "fire_cursor_gold_kubi",
  18. }
  19. cursor_dict = {
  20. "fire_cursor1": {"own": True, "name": "引路人-黄色荧火", "info": "原初的黄色荧火,为旅者指引前路", "condition": "初始拥有"},
  21. "fire_cursor2": {"own": False, "name": "引路人-森绿荧火", "info": "俏皮的森绿荧火,为旅者指引前路", "condition": "通关简单难度获得"},
  22. "fire_cursor_kubi": {"own": False, "name": "引路人-小酷比", "info": "顽皮的小酷比,为旅者指引前路", "condition": "通关困难难度获得"},
  23. "fire_cursor_gold_kubi": {"own": False, "name": "引路人-金酷比", "info": "稀有的金酷比,为旅者指引前路", "condition": "通关炼狱难度获得"},
  24. }
  25. cursor_list = ["引路人-黄色荧火", "引路人-森绿荧火", "引路人-小酷比", "引路人-金酷比"]
  26. bomb_cn = {
  27. "糖泡-经典": "bomb1",
  28. "糖泡-命运": "bomb60",
  29. "糖泡-深林": "bomb1436",
  30. }
  31. bomb_dict = {
  32. "bomb1": {"own": True, "name": "糖泡-经典", "info": "陪伴旅人最初的糖泡外观", "img": pygame.image.load(r"res/img/bomb/bomb1_stand_0_0.png").convert_alpha()},
  33. "bomb60": {"own": False, "name": "糖泡-命运", "info": "糖泡伤害额外增加50", "img": pygame.image.load(r"res/img/bomb/bomb60_stand_0_0.png").convert_alpha()},
  34. "bomb1436": {"own": False, "name": "糖泡-深林", "info": "最大生命额外增加150", "img": pygame.image.load(r"res/img/bomb/bomb1436_stand_0_0.png").convert_alpha()},
  35. }
  36. bomb_list = ["糖泡-经典", "糖泡-命运", "糖泡-深林"]
  37. class SkinPage:
  38. def __init__(self):
  39. self.screen = W.MENU
  40. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  41. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  42. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  43. self.rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  44. self.other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  45. self.rougeOB_achievements = {}
  46. self.rougeOB_other_data = {}
  47. self.cursor_map = {}
  48. self.current_cursor = None
  49. self.view_cursor = None
  50. self.current_bomb = None
  51. self.init_skin_page()
  52. def init_skin_page(self):
  53. DM.init_achievement()
  54. self.rougeOB_achievements = load_rouge_data(self.rouge_achivements_file_path)
  55. def load_achievements_data(self):
  56. global cursor_dict
  57. max_level = 0
  58. max_diff = "Easy"
  59. max_diff_num = 1
  60. diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  61. diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  62. if self.rougeOB_achievements["Highest"]["level"] != "":
  63. max_level = self.rougeOB_achievements["Highest"]["level"]
  64. if self.rougeOB_achievements["Highest"]["hero"] != "":
  65. max_level_hero = self.rougeOB_achievements["Highest"]["hero"]
  66. if self.rougeOB_achievements["Highest"]["diff"] != "":
  67. max_diff = self.rougeOB_achievements["Highest"]["diff"]
  68. cursor_dict["fire_cursor_gold_kubi"]["own"] = (diff_num[max_diff] >= 4 or (diff_num[max_diff] == 3 and max_level >= 15))
  69. cursor_dict["fire_cursor_kubi"]["own"] = (diff_num[max_diff] >= 3 or (diff_num[max_diff] == 2 and max_level >= 15))
  70. cursor_dict["fire_cursor2"]["own"] = (diff_num[max_diff] >= 2 or (diff_num[max_diff] == 1 and max_level >= 15))
  71. cursor_dict["fire_cursor1"]["own"] = True
  72. def load_other_data(self):
  73. global bomb_dict
  74. # 杂项第一次打开
  75. if not os.path.exists(self.other_file_path):
  76. self.rougeOB_other_data = {
  77. "Bomb": [],
  78. "Pet": [],
  79. "Hat": [],
  80. "LastRandom": 0,
  81. "Other": []
  82. }
  83. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  84. # 正常打开
  85. else:
  86. self.rougeOB_other_data = load_rouge_data(self.other_file_path)
  87. # 读取引路人
  88. if 'Cursor_Skin' not in self.rougeOB_other_data.keys():
  89. self.rougeOB_other_data['Cursor_Skin'] = "fire_cursor1"
  90. self.current_cursor = "fire_cursor1"
  91. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  92. else:
  93. self.current_cursor = self.rougeOB_other_data['Cursor_Skin']
  94. if self.current_cursor not in cursor_dict.keys():
  95. self.current_cursor = "fire_cursor1"
  96. self.view_cursor = self.current_cursor
  97. # 读取糖泡皮肤
  98. if 'Bomb_Skin' not in self.rougeOB_other_data.keys():
  99. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  100. self.current_bomb = "bomb1"
  101. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  102. else:
  103. self.current_bomb = self.rougeOB_other_data['Bomb_Skin']
  104. for bomb in self.rougeOB_other_data['Bomb']:
  105. bomb_dict[bomb]["own"] = True
  106. print(f"rougeOB_other_data: {self.rougeOB_other_data}")
  107. def draw(self):
  108. # 引路人
  109. self.screen.buttons.append(PygameButtonBackIMG(
  110. self.screen, self.screen.screen, 0.5, 0.3, "res/ui/button/cursor.png", "res/ui/button/cursor_press.png", action=self.draw_cursor, anchor='center')
  111. )
  112. # 藏宝阁
  113. self.screen.buttons.append(PygameButtonBackIMG(
  114. self.screen, self.screen.screen, 0.5, 0.45, "res/ui/button/treasure.png", "res/ui/button/treasure_press.png", action=self.draw_treasure, anchor='center')
  115. )
  116. # 返回主界面
  117. self.screen.buttons.append(PygameButtonBackIMG(
  118. self.screen, self.screen.screen, 0.5, 0.6, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.refresh, anchor='center')
  119. )
  120. def draw_cursor(self):
  121. self.screen.buttons.clear()
  122. self.load_achievements_data()
  123. self.load_other_data()
  124. # ================================= 信息展示 =================================
  125. info_button = PygameButton(
  126. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  127. fg_color=(215,220,217), action=None,
  128. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  129. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  130. )
  131. # ================================= 选择 =================================
  132. choose_button = PygameButtonBackIMG(
  133. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  134. action=None, anchor='center'
  135. )
  136. # ================================= 展示框 =================================
  137. cy = 0.29
  138. button_blank = 0.13
  139. roll_button = PygameButtonBackIMGRoll(
  140. self.screen, self.screen.screen, 0.5, cy, "res/ui/button/cursor_board.png", cursor_list,
  141. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  142. 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,
  143. related_button=[info_button, choose_button],
  144. notify_action=[lambda x: cursor_update_notify(roll_button, x, self.current_cursor), lambda _: self.update_choose_btn(roll_button, choose_button, info_button)]
  145. )
  146. # ================================= 初始化 =================================
  147. choose_button.action = lambda: self.choose_cursor(roll_button, info_button, choose_button) # 追加action
  148. roll_button.set_current_text(cursor_dict[self.current_cursor]["name"])
  149. cursor_update_notify(roll_button, info_button, self.current_cursor)
  150. self.update_choose_btn(roll_button, choose_button, info_button)
  151. # ================================= 添加按钮 =================================
  152. self.screen.buttons.append(info_button)
  153. self.screen.buttons.append(choose_button)
  154. self.screen.buttons.append(roll_button)
  155. # ================================= 上翻页 =================================
  156. self.screen.buttons.append(PygameButtonBackIMG(
  157. self.screen, self.screen.screen, 0.5, cy-button_blank, "res/ui/button/up.png", "res/ui/button/up_press.png", action=roll_button.roll_up, anchor='center', shiny_spark=False)
  158. )
  159. # ================================= 下翻页 =================================
  160. self.screen.buttons.append(PygameButtonBackIMG(
  161. self.screen, self.screen.screen, 0.5, cy+button_blank, "res/ui/button/down.png", "res/ui/button/down_press.png", action=roll_button.roll_down, anchor='center', shiny_spark=False)
  162. )
  163. # ================================= 返回上一级 =================================
  164. self.screen.buttons.append(PygameButtonBackIMG(
  165. self.screen, self.screen.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.open_setting, anchor='center')
  166. )
  167. def draw_treasure(self):
  168. self.screen.buttons.clear()
  169. self.load_other_data()
  170. # ================================= 信息展示 =================================
  171. info_button = PygameButton(
  172. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  173. fg_color=(215,220,217), action=None,
  174. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  175. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  176. )
  177. # ================================= 图片 =================================
  178. img_button = PygameButtonBackIMG(
  179. self.screen, self.screen.screen, 0.65, 0.29, "res/ui/button/img_board.png", "res/ui/button/img_board.png",
  180. action=None, anchor='center', shiny_spark=False
  181. )
  182. img = PygameIMG(self.screen, self.screen.screen, 0.65, 0.29, py_img=bomb_dict["bomb1"]["img"], anchor='center')
  183. # ================================= 选择 =================================
  184. choose_button = PygameButtonBackIMG(
  185. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  186. action=None, anchor='center'
  187. )
  188. # ================================= 展示框 =================================
  189. cy = 0.29
  190. cx = 0.35
  191. button_blank = 0.13
  192. roll_button = PygameButtonBackIMGRoll(
  193. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", bomb_list,
  194. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  195. 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,
  196. related_button=[info_button, choose_button, img],
  197. notify_action=[lambda x: bomb_update_notify(roll_button, x, self.current_bomb), lambda _: self.update_choose_bomb_btn(roll_button, choose_button, info_button), lambda _: bomb_img_update(roll_button, img)]
  198. )
  199. # ================================= 初始化 =================================
  200. choose_button.action = lambda: self.choose_bomb(roll_button, info_button, choose_button) # 追加action
  201. roll_button.set_current_text(bomb_dict[self.current_bomb]["name"])
  202. bomb_update_notify(roll_button, info_button, self.current_bomb)
  203. self.update_choose_bomb_btn(roll_button, choose_button, info_button)
  204. # ================================= 添加按钮 =================================
  205. self.screen.buttons.append(info_button)
  206. self.screen.buttons.append(choose_button)
  207. self.screen.buttons.append(roll_button)
  208. self.screen.buttons.append(img_button)
  209. self.screen.buttons.append(img)
  210. # ================================= 上翻页 =================================
  211. self.screen.buttons.append(PygameButtonBackIMG(
  212. 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)
  213. )
  214. # ================================= 下翻页 =================================
  215. self.screen.buttons.append(PygameButtonBackIMG(
  216. 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)
  217. )
  218. # ================================= 返回上一级 =================================
  219. self.screen.buttons.append(PygameButtonBackIMG(
  220. self.screen, self.screen.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.open_setting, anchor='center')
  221. )
  222. """
  223. self.hero_dic= {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"}
  224. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  225. if self.current_bomb == "bomb1":
  226. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-经典皮肤", bg="#C68E17", font=("Microsoft YaHei", 20))
  227. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  228. elif self.current_bomb == "bomb60":
  229. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-命运(伤害+50)", bg="#C68E17", font=("Microsoft YaHei", 20))
  230. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  231. elif self.current_bomb == "bomb1436":
  232. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-深林(生命+150)", bg="#C68E17", font=("Microsoft YaHei", 20))
  233. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  234. self.button100 = tk.Button(master, text= "▶糖泡-经典皮肤", command=self.choose_bomb1, bg="#A23BEC", font=("Microsoft YaHei", 12))
  235. self.button100.place(relx=0.5, rely=0.08, anchor='w')
  236. if has_bomb60:
  237. self.button160 = tk.Button(master, text= "▶糖泡-命运(伤害+50)", command=self.choose_bomb60, bg="#A23BEC", font=("Microsoft YaHei", 12))
  238. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  239. else:
  240. self.button160 = tk.Button(master, text= "(暂未获得) \n 糖泡-命运(伤害+50)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  241. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  242. if has_bomb1436:
  243. self.button1436 = tk.Button(master, text= "▶糖泡-深林(生命+150)", command=self.choose_bomb1436, bg="#A23BEC", font=("Microsoft YaHei", 12))
  244. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  245. else:
  246. self.button1436 = tk.Button(master, text= "(暂未获得) \n 糖泡-深林(生命+150)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  247. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  248. def choose_bomb1(self):
  249. self.current_bomb = "bomb1"
  250. R.bomb_skin = "bomb1"
  251. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  252. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  253. self.button_bomb.config(text = "(当前选择) \n 糖泡-经典皮肤")
  254. def choose_bomb60(self):
  255. self.current_bomb = "bomb60"
  256. R.bomb_skin = "bomb60"
  257. self.rougeOB_other_data['Bomb_Skin'] = "bomb60"
  258. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  259. self.button_bomb.config(text = "(当前选择) \n 糖泡-命运(伤害+50)")
  260. def choose_bomb1436(self):
  261. self.current_bomb = "bomb1436"
  262. R.bomb_skin = "bomb1436"
  263. self.rougeOB_other_data['Bomb_Skin'] = "bomb1436"
  264. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  265. self.button_bomb.config(text = "(当前选择) \n 糖泡-深林(生命+150)")
  266. """
  267. def choose_cursor(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  268. cn_name = roll_btn.get_current_text()
  269. current = cursor_cn[cn_name]
  270. self.current_cursor = current
  271. R.cursor_skin = current
  272. self.rougeOB_other_data['Cursor_Skin'] = current
  273. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  274. roll_btn.set_current_text(cursor_dict[self.current_cursor]["name"])
  275. cursor_update_notify(roll_btn, info_button, self.current_cursor)
  276. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  277. choose_btn.shiny_spark = False
  278. choose_btn.action = None
  279. def update_choose_btn(self, roll_button, choose_btn, info_button):
  280. # 拿到当前展示的中文名
  281. cn_name = roll_button.get_current_text()
  282. # 拿到内部 key
  283. key = cursor_cn[cn_name]
  284. # 拿到是否已解锁
  285. owned = cursor_dict[key]["own"]
  286. if owned:
  287. if self.current_cursor == key:
  288. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  289. choose_btn.shiny_spark = False
  290. choose_btn.action = None
  291. else:
  292. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  293. choose_btn.shiny_spark = True
  294. choose_btn.action = lambda cn=cn_name: self.choose_cursor(roll_button, info_button, choose_btn)
  295. else:
  296. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  297. choose_btn.shiny_spark = False
  298. choose_btn.action = None
  299. def choose_bomb(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  300. cn_name = roll_btn.get_current_text()
  301. current = bomb_cn[cn_name]
  302. self.current_bomb = current
  303. R.bomb_skin = current
  304. self.rougeOB_other_data['Bomb_Skin'] = current
  305. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  306. roll_btn.set_current_text(bomb_dict[self.current_bomb]["name"])
  307. bomb_update_notify(roll_btn, info_button, self.current_bomb)
  308. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  309. choose_btn.shiny_spark = False
  310. choose_btn.action = None
  311. def update_choose_bomb_btn(self, roll_button, choose_btn, info_button):
  312. # 拿到当前展示的中文名
  313. cn_name = roll_button.get_current_text()
  314. # 拿到内部 key
  315. key = bomb_cn[cn_name]
  316. # 拿到是否已解锁
  317. owned = bomb_dict[key]["own"]
  318. if owned:
  319. if self.current_bomb == key:
  320. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  321. choose_btn.shiny_spark = False
  322. choose_btn.action = None
  323. else:
  324. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  325. choose_btn.shiny_spark = True
  326. choose_btn.action = lambda cn=cn_name: self.choose_bomb(roll_button, info_button, choose_btn)
  327. else:
  328. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  329. choose_btn.shiny_spark = False
  330. choose_btn.action = None
  331. def cursor_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  332. cn_name = board.get_current_text()
  333. current = cursor_cn[cn_name]
  334. is_chosen = "<当前选择>" if (current == chosen) else ""
  335. owned = "已拥有" if cursor_dict[current]["own"] else "未解锁"
  336. info = cursor_dict[current]["info"]
  337. condition = cursor_dict[current]["condition"]
  338. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition}({owned}) ")
  339. def bomb_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  340. cn_name = board.get_current_text()
  341. current = bomb_cn[cn_name]
  342. is_chosen = "<当前选择>" if (current == chosen) else ""
  343. owned = "已拥有" if bomb_dict[current]["own"] else "未解锁"
  344. info = bomb_dict[current]["info"]
  345. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n ({owned}) ")
  346. def bomb_img_update(board: PygameButtonBackIMGRoll, img: PygameIMG):
  347. cn_name = board.get_current_text()
  348. current = bomb_cn[cn_name]
  349. img.update_image(bomb_dict[current]["img"])