skin_menu.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. max_level = self.rougeOB_achievements["Highest"]["level"]
  63. max_level_hero = self.rougeOB_achievements["Highest"]["hero"]
  64. max_diff = self.rougeOB_achievements["Highest"]["diff"]
  65. cursor_dict["fire_cursor_gold_kubi"]["own"] = (diff_num[max_diff] >= 4 or (diff_num[max_diff] == 3 and max_level >= 15))
  66. cursor_dict["fire_cursor_kubi"]["own"] = (diff_num[max_diff] >= 3 or (diff_num[max_diff] == 2 and max_level >= 15))
  67. cursor_dict["fire_cursor2"]["own"] = (diff_num[max_diff] >= 2 or (diff_num[max_diff] == 1 and max_level >= 15))
  68. cursor_dict["fire_cursor1"]["own"] = True
  69. def load_other_data(self):
  70. global bomb_dict
  71. # 杂项第一次打开
  72. if not os.path.exists(self.other_file_path):
  73. self.rougeOB_other_data = {
  74. "Bomb": [],
  75. "Pet": [],
  76. "Hat": [],
  77. "LastRandom": 0,
  78. "Other": []
  79. }
  80. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  81. # 正常打开
  82. else:
  83. self.rougeOB_other_data = load_rouge_data(self.other_file_path)
  84. # 读取引路人
  85. if 'Cursor_Skin' not in self.rougeOB_other_data.keys():
  86. self.rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  87. self.current_cursor = "fire_cursor"
  88. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  89. else:
  90. self.current_cursor = self.rougeOB_other_data['Cursor_Skin']
  91. self.view_cursor = self.current_cursor
  92. # 读取糖泡皮肤
  93. if 'Bomb_Skin' not in self.rougeOB_other_data.keys():
  94. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  95. self.current_bomb = "bomb1"
  96. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  97. else:
  98. self.current_bomb = self.rougeOB_other_data['Bomb_Skin']
  99. for bomb in self.rougeOB_other_data['Bomb']:
  100. bomb_dict[bomb]["own"] = True
  101. print(f"rougeOB_other_data: {self.rougeOB_other_data}")
  102. def draw(self):
  103. # 引路人
  104. self.screen.buttons.append(PygameButtonBackIMG(
  105. 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')
  106. )
  107. # 藏宝阁
  108. self.screen.buttons.append(PygameButtonBackIMG(
  109. 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')
  110. )
  111. # 返回主界面
  112. self.screen.buttons.append(PygameButtonBackIMG(
  113. 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')
  114. )
  115. def draw_cursor(self):
  116. self.screen.buttons.clear()
  117. self.load_achievements_data()
  118. self.load_other_data()
  119. # ================================= 信息展示 =================================
  120. info_button = PygameButton(
  121. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  122. fg_color=(215,220,217), action=None,
  123. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  124. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  125. )
  126. # ================================= 选择 =================================
  127. choose_button = PygameButtonBackIMG(
  128. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  129. action=None, anchor='center'
  130. )
  131. # ================================= 展示框 =================================
  132. cy = 0.29
  133. button_blank = 0.13
  134. roll_button = PygameButtonBackIMGRoll(
  135. self.screen, self.screen.screen, 0.5, cy, "res/ui/button/cursor_board.png", cursor_list,
  136. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  137. 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,
  138. related_button=[info_button, choose_button],
  139. notify_action=[lambda x: cursor_update_notify(roll_button, x, self.current_cursor), lambda _: self.update_choose_btn(roll_button, choose_button, info_button)]
  140. )
  141. # ================================= 初始化 =================================
  142. choose_button.action = lambda: self.choose_cursor(roll_button, info_button, choose_button) # 追加action
  143. roll_button.set_current_text(cursor_dict[self.current_cursor]["name"])
  144. cursor_update_notify(roll_button, info_button, self.current_cursor)
  145. self.update_choose_btn(roll_button, choose_button, info_button)
  146. # ================================= 添加按钮 =================================
  147. self.screen.buttons.append(info_button)
  148. self.screen.buttons.append(choose_button)
  149. self.screen.buttons.append(roll_button)
  150. # ================================= 上翻页 =================================
  151. self.screen.buttons.append(PygameButtonBackIMG(
  152. 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)
  153. )
  154. # ================================= 下翻页 =================================
  155. self.screen.buttons.append(PygameButtonBackIMG(
  156. 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)
  157. )
  158. # ================================= 返回上一级 =================================
  159. self.screen.buttons.append(PygameButtonBackIMG(
  160. 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')
  161. )
  162. def draw_treasure(self):
  163. self.screen.buttons.clear()
  164. self.load_other_data()
  165. # ================================= 信息展示 =================================
  166. info_button = PygameButton(
  167. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  168. fg_color=(215,220,217), action=None,
  169. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  170. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  171. )
  172. # ================================= 图片 =================================
  173. img_button = PygameButtonBackIMG(
  174. self.screen, self.screen.screen, 0.65, 0.29, "res/ui/button/img_board.png", "res/ui/button/img_board.png",
  175. action=None, anchor='center', shiny_spark=False
  176. )
  177. img = PygameIMG(self.screen, self.screen.screen, 0.65, 0.29, py_img=bomb_dict["bomb1"]["img"], anchor='center')
  178. # ================================= 选择 =================================
  179. choose_button = PygameButtonBackIMG(
  180. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  181. action=None, anchor='center'
  182. )
  183. # ================================= 展示框 =================================
  184. cy = 0.29
  185. cx = 0.35
  186. button_blank = 0.13
  187. roll_button = PygameButtonBackIMGRoll(
  188. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", bomb_list,
  189. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  190. 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,
  191. related_button=[info_button, choose_button, img],
  192. 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)]
  193. )
  194. # ================================= 初始化 =================================
  195. choose_button.action = lambda: self.choose_bomb(roll_button, info_button, choose_button) # 追加action
  196. roll_button.set_current_text(bomb_dict[self.current_bomb]["name"])
  197. bomb_update_notify(roll_button, info_button, self.current_bomb)
  198. self.update_choose_bomb_btn(roll_button, choose_button, info_button)
  199. # ================================= 添加按钮 =================================
  200. self.screen.buttons.append(info_button)
  201. self.screen.buttons.append(choose_button)
  202. self.screen.buttons.append(roll_button)
  203. self.screen.buttons.append(img_button)
  204. self.screen.buttons.append(img)
  205. # ================================= 上翻页 =================================
  206. self.screen.buttons.append(PygameButtonBackIMG(
  207. 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)
  208. )
  209. # ================================= 下翻页 =================================
  210. self.screen.buttons.append(PygameButtonBackIMG(
  211. 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)
  212. )
  213. # ================================= 返回上一级 =================================
  214. self.screen.buttons.append(PygameButtonBackIMG(
  215. 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')
  216. )
  217. """
  218. self.hero_dic= {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"}
  219. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  220. if self.current_bomb == "bomb1":
  221. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-经典皮肤", bg="#C68E17", font=("Microsoft YaHei", 20))
  222. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  223. elif self.current_bomb == "bomb60":
  224. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-命运(伤害+50)", bg="#C68E17", font=("Microsoft YaHei", 20))
  225. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  226. elif self.current_bomb == "bomb1436":
  227. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-深林(生命+150)", bg="#C68E17", font=("Microsoft YaHei", 20))
  228. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  229. self.button100 = tk.Button(master, text= "▶糖泡-经典皮肤", command=self.choose_bomb1, bg="#A23BEC", font=("Microsoft YaHei", 12))
  230. self.button100.place(relx=0.5, rely=0.08, anchor='w')
  231. if has_bomb60:
  232. self.button160 = tk.Button(master, text= "▶糖泡-命运(伤害+50)", command=self.choose_bomb60, bg="#A23BEC", font=("Microsoft YaHei", 12))
  233. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  234. else:
  235. self.button160 = tk.Button(master, text= "(暂未获得) \n 糖泡-命运(伤害+50)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  236. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  237. if has_bomb1436:
  238. self.button1436 = tk.Button(master, text= "▶糖泡-深林(生命+150)", command=self.choose_bomb1436, bg="#A23BEC", font=("Microsoft YaHei", 12))
  239. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  240. else:
  241. self.button1436 = tk.Button(master, text= "(暂未获得) \n 糖泡-深林(生命+150)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  242. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  243. def choose_bomb1(self):
  244. self.current_bomb = "bomb1"
  245. R.bomb_skin = "bomb1"
  246. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  247. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  248. self.button_bomb.config(text = "(当前选择) \n 糖泡-经典皮肤")
  249. def choose_bomb60(self):
  250. self.current_bomb = "bomb60"
  251. R.bomb_skin = "bomb60"
  252. self.rougeOB_other_data['Bomb_Skin'] = "bomb60"
  253. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  254. self.button_bomb.config(text = "(当前选择) \n 糖泡-命运(伤害+50)")
  255. def choose_bomb1436(self):
  256. self.current_bomb = "bomb1436"
  257. R.bomb_skin = "bomb1436"
  258. self.rougeOB_other_data['Bomb_Skin'] = "bomb1436"
  259. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  260. self.button_bomb.config(text = "(当前选择) \n 糖泡-深林(生命+150)")
  261. """
  262. def choose_cursor(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  263. cn_name = roll_btn.get_current_text()
  264. current = cursor_cn[cn_name]
  265. self.current_cursor = current
  266. R.cursor_skin = current
  267. self.rougeOB_other_data['Cursor_Skin'] = current
  268. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  269. roll_btn.set_current_text(cursor_dict[self.current_cursor]["name"])
  270. cursor_update_notify(roll_btn, info_button, self.current_cursor)
  271. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  272. choose_btn.shiny_spark = False
  273. choose_btn.action = None
  274. def update_choose_btn(self, roll_button, choose_btn, info_button):
  275. # 拿到当前展示的中文名
  276. cn_name = roll_button.get_current_text()
  277. # 拿到内部 key
  278. key = cursor_cn[cn_name]
  279. # 拿到是否已解锁
  280. owned = cursor_dict[key]["own"]
  281. if owned:
  282. if self.current_cursor == key:
  283. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  284. choose_btn.shiny_spark = False
  285. choose_btn.action = None
  286. else:
  287. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  288. choose_btn.shiny_spark = True
  289. choose_btn.action = lambda cn=cn_name: self.choose_cursor(roll_button, info_button, choose_btn)
  290. else:
  291. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  292. choose_btn.shiny_spark = False
  293. choose_btn.action = None
  294. def choose_bomb(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  295. cn_name = roll_btn.get_current_text()
  296. current = bomb_cn[cn_name]
  297. self.current_bomb = current
  298. R.bomb_skin = current
  299. self.rougeOB_other_data['Bomb_Skin'] = current
  300. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  301. roll_btn.set_current_text(bomb_dict[self.current_bomb]["name"])
  302. bomb_update_notify(roll_btn, info_button, self.current_bomb)
  303. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  304. choose_btn.shiny_spark = False
  305. choose_btn.action = None
  306. def update_choose_bomb_btn(self, roll_button, choose_btn, info_button):
  307. # 拿到当前展示的中文名
  308. cn_name = roll_button.get_current_text()
  309. # 拿到内部 key
  310. key = bomb_cn[cn_name]
  311. # 拿到是否已解锁
  312. owned = bomb_dict[key]["own"]
  313. if owned:
  314. if self.current_bomb == key:
  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. else:
  319. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  320. choose_btn.shiny_spark = True
  321. choose_btn.action = lambda cn=cn_name: self.choose_bomb(roll_button, info_button, choose_btn)
  322. else:
  323. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  324. choose_btn.shiny_spark = False
  325. choose_btn.action = None
  326. def cursor_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  327. cn_name = board.get_current_text()
  328. current = cursor_cn[cn_name]
  329. is_chosen = "<当前选择>" if (current == chosen) else ""
  330. owned = "已拥有" if cursor_dict[current]["own"] else "未解锁"
  331. info = cursor_dict[current]["info"]
  332. condition = cursor_dict[current]["condition"]
  333. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition}({owned}) ")
  334. def bomb_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  335. cn_name = board.get_current_text()
  336. current = bomb_cn[cn_name]
  337. is_chosen = "<当前选择>" if (current == chosen) else ""
  338. owned = "已拥有" if bomb_dict[current]["own"] else "未解锁"
  339. info = bomb_dict[current]["info"]
  340. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n ({owned}) ")
  341. def bomb_img_update(board: PygameButtonBackIMGRoll, img: PygameIMG):
  342. cn_name = board.get_current_text()
  343. current = bomb_cn[cn_name]
  344. img.update_image(bomb_dict[current]["img"])