skin_menu.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import json
  2. import os
  3. from datetime import datetime
  4. import tkinter as tk
  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 import control
  11. from game.algo import rougeGen
  12. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  13. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, PygameButtonBackIMGRoll, Particle
  14. current_folder_path = os.getcwd()
  15. cursor_cn = {
  16. "引路人-黄色荧火": "fire_cursor1",
  17. "引路人-森绿荧火": "fire_cursor2",
  18. "引路人-小酷比": "fire_cursor_kubi",
  19. "引路人-金酷比": "fire_cursor_gold_kubi",
  20. }
  21. cursor_dict = {
  22. "fire_cursor1": {"own": True, "name": "引路人-黄色荧火", "info": "原初的黄色荧火,为旅者指引前路", "condition": "初始拥有"},
  23. "fire_cursor2": {"own": False, "name": "引路人-森绿荧火", "info": "俏皮的森绿荧火,为旅者指引前路", "condition": "通关简单难度获得"},
  24. "fire_cursor_kubi": {"own": False, "name": "引路人-小酷比", "info": "顽皮的小酷比,为旅者指引前路", "condition": "通关困难难度获得"},
  25. "fire_cursor_gold_kubi": {"own": False, "name": "引路人-金酷比", "info": "稀有的金酷比,为旅者指引前路", "condition": "通关炼狱难度获得"},
  26. }
  27. cursor_list = ["引路人-黄色荧火", "引路人-森绿荧火", "引路人-小酷比", "引路人-金酷比"]
  28. bomb_dict = {
  29. "bomb1": True,
  30. "bomb60": False,
  31. "bomb1436": False,
  32. }
  33. class SkinPage:
  34. def __init__(self):
  35. self.screen = W.MENU
  36. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  37. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  38. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  39. self.rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  40. self.other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  41. self.rougeOB_achievements = {}
  42. self.rougeOB_other_data = {}
  43. self.cursor_map = {}
  44. self.current_cursor = None
  45. self.view_cursor = None
  46. self.current_bomb = None
  47. self.init_skin_page()
  48. def init_skin_page(self):
  49. DM.init_achievement()
  50. self.rougeOB_achievements = load_rouge_data(self.rouge_achivements_file_path)
  51. def load_achievements_data(self):
  52. global cursor_dict
  53. max_level = 0
  54. max_diff = "Easy"
  55. max_diff_num = 1
  56. diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  57. diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  58. max_level = self.rougeOB_achievements["Highest"]["level"]
  59. max_level_hero = self.rougeOB_achievements["Highest"]["hero"]
  60. max_diff = self.rougeOB_achievements["Highest"]["diff"]
  61. cursor_dict["fire_cursor_gold_kubi"]["own"] = (diff_num[max_diff] >= 4 or (diff_num[max_diff] == 3 and max_level >= 15))
  62. cursor_dict["fire_cursor_kubi"]["own"] = (diff_num[max_diff] >= 3 or (diff_num[max_diff] == 2 and max_level >= 15))
  63. cursor_dict["fire_cursor2"]["own"] = (diff_num[max_diff] >= 2 or (diff_num[max_diff] == 1 and max_level >= 15))
  64. cursor_dict["fire_cursor1"]["own"] = True
  65. def load_other_data(self):
  66. # 杂项第一次打开
  67. if not os.path.exists(self.other_file_path):
  68. self.rougeOB_other_data = {
  69. "Bomb": [],
  70. "Pet": [],
  71. "Hat": [],
  72. "LastRandom": 0,
  73. "Other": []
  74. }
  75. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  76. # 正常打开
  77. else:
  78. self.rougeOB_other_data = load_rouge_data(self.other_file_path)
  79. # 读取引路人
  80. if 'Cursor_Skin' not in self.rougeOB_other_data.keys():
  81. self.rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  82. self.current_cursor = "fire_cursor"
  83. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  84. else:
  85. self.current_cursor = self.rougeOB_other_data['Cursor_Skin']
  86. self.view_cursor = self.current_cursor
  87. # 读取糖泡皮肤
  88. if 'Bomb_Skin' not in self.rougeOB_other_data.keys():
  89. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  90. self.current_bomb = "bomb1"
  91. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  92. else:
  93. self.current_bomb = self.rougeOB_other_data['Bomb_Skin']
  94. print(f"rougeOB_other_data: {self.rougeOB_other_data}")
  95. if "bomb60" in self.rougeOB_other_data['Bomb']:
  96. has_bomb60 = True
  97. if "bomb1436" in self.rougeOB_other_data['Bomb']:
  98. has_bomb1436 = True
  99. def draw(self):
  100. # 引路人
  101. self.screen.buttons.append(PygameButtonBackIMG(
  102. 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')
  103. )
  104. # 藏宝阁
  105. self.screen.buttons.append(PygameButtonBackIMG(
  106. 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')
  107. )
  108. # 返回主界面
  109. self.screen.buttons.append(PygameButtonBackIMG(
  110. 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')
  111. )
  112. def draw_cursor(self):
  113. self.screen.buttons.clear()
  114. self.load_achievements_data()
  115. self.load_other_data()
  116. # ================================= 信息展示 =================================
  117. info_button = PygameButton(
  118. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  119. fg_color=(215,220,217), action=None,
  120. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  121. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  122. )
  123. # ================================= 选择 =================================
  124. choose_button = PygameButtonBackIMG(
  125. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  126. action=None, anchor='center'
  127. )
  128. # ================================= 展示框 =================================
  129. cy = 0.29
  130. button_blank = 0.13
  131. roll_button = PygameButtonBackIMGRoll(
  132. self.screen, self.screen.screen, 0.5, cy, "res/ui/button/cursor_board.png", cursor_list,
  133. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  134. 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,
  135. related_button=[info_button, choose_button],
  136. notify_action=[lambda x: cursor_update_notify(roll_button, x, self.current_cursor), lambda _: self.update_choose_btn(roll_button, choose_button, info_button)]
  137. )
  138. # ================================= 初始化 =================================
  139. choose_button.action = lambda: self.choose_cursor(roll_button, info_button, choose_button) # 追加action
  140. roll_button.set_current_text(cursor_dict[self.current_cursor]["name"])
  141. cursor_update_notify(roll_button, info_button, self.current_cursor)
  142. self.update_choose_btn(roll_button, choose_button, info_button)
  143. # ================================= 添加按钮 =================================
  144. self.screen.buttons.append(info_button)
  145. self.screen.buttons.append(choose_button)
  146. self.screen.buttons.append(roll_button)
  147. # ================================= 上翻页 =================================
  148. self.screen.buttons.append(PygameButtonBackIMG(
  149. 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)
  150. )
  151. # ================================= 下翻页 =================================
  152. self.screen.buttons.append(PygameButtonBackIMG(
  153. 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)
  154. )
  155. # ================================= 返回上一级 =================================
  156. self.screen.buttons.append(PygameButtonBackIMG(
  157. 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')
  158. )
  159. def draw_treasure(self):
  160. self.screen.buttons.clear()
  161. self.load_other_data()
  162. # 返回主界面
  163. self.screen.buttons.append(PygameButtonBackIMG(
  164. 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')
  165. )
  166. """
  167. self.hero_dic= {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"}
  168. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  169. if self.current_bomb == "bomb1":
  170. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-经典皮肤", bg="#C68E17", font=("Microsoft YaHei", 20))
  171. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  172. elif self.current_bomb == "bomb60":
  173. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-命运(伤害+50)", bg="#C68E17", font=("Microsoft YaHei", 20))
  174. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  175. elif self.current_bomb == "bomb1436":
  176. self.button_bomb = tk.Button(master, text= "(当前选择) \n 糖泡-深林(生命+150)", bg="#C68E17", font=("Microsoft YaHei", 20))
  177. self.button_bomb.place(relx=0.7, rely=0.15, anchor='w')
  178. self.button100 = tk.Button(master, text= "▶糖泡-经典皮肤", command=self.choose_bomb1, bg="#A23BEC", font=("Microsoft YaHei", 12))
  179. self.button100.place(relx=0.5, rely=0.08, anchor='w')
  180. if has_bomb60:
  181. self.button160 = tk.Button(master, text= "▶糖泡-命运(伤害+50)", command=self.choose_bomb60, bg="#A23BEC", font=("Microsoft YaHei", 12))
  182. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  183. else:
  184. self.button160 = tk.Button(master, text= "(暂未获得) \n 糖泡-命运(伤害+50)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  185. self.button160.place(relx=0.5, rely=0.17, anchor='w')
  186. if has_bomb1436:
  187. self.button1436 = tk.Button(master, text= "▶糖泡-深林(生命+150)", command=self.choose_bomb1436, bg="#A23BEC", font=("Microsoft YaHei", 12))
  188. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  189. else:
  190. self.button1436 = tk.Button(master, text= "(暂未获得) \n 糖泡-深林(生命+150)", bg="#C6AEC7", font=("Microsoft YaHei", 12))
  191. self.button1436.place(relx=0.5, rely=0.26, anchor='w')
  192. def choose_bomb1(self):
  193. self.current_bomb = "bomb1"
  194. R.bomb_skin = "bomb1"
  195. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  196. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  197. self.button_bomb.config(text = "(当前选择) \n 糖泡-经典皮肤")
  198. def choose_bomb60(self):
  199. self.current_bomb = "bomb60"
  200. R.bomb_skin = "bomb60"
  201. self.rougeOB_other_data['Bomb_Skin'] = "bomb60"
  202. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  203. self.button_bomb.config(text = "(当前选择) \n 糖泡-命运(伤害+50)")
  204. def choose_bomb1436(self):
  205. self.current_bomb = "bomb1436"
  206. R.bomb_skin = "bomb1436"
  207. self.rougeOB_other_data['Bomb_Skin'] = "bomb1436"
  208. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  209. self.button_bomb.config(text = "(当前选择) \n 糖泡-深林(生命+150)")
  210. """
  211. def choose_cursor(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  212. cn_name = roll_btn.get_current_text()
  213. current = cursor_cn[cn_name]
  214. self.current_cursor = current
  215. R.cursor_skin = current
  216. self.rougeOB_other_data['Cursor_Skin'] = current
  217. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  218. roll_btn.set_current_text(cursor_dict[self.current_cursor]["name"])
  219. cursor_update_notify(roll_btn, info_button, self.current_cursor)
  220. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  221. choose_btn.shiny_spark = False
  222. choose_btn.action = None
  223. def update_choose_btn(self, roll_button, choose_btn, info_button):
  224. # 拿到当前展示的中文名
  225. cn_name = roll_button.get_current_text()
  226. # 拿到内部 key
  227. key = cursor_cn[cn_name]
  228. # 拿到是否已解锁
  229. owned = cursor_dict[key]["own"]
  230. if owned:
  231. if self.current_cursor == key:
  232. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  233. choose_btn.shiny_spark = False
  234. choose_btn.action = None
  235. else:
  236. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  237. choose_btn.shiny_spark = True
  238. choose_btn.action = lambda cn=cn_name: self.choose_cursor(roll_button, info_button, choose_btn)
  239. else:
  240. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  241. choose_btn.shiny_spark = False
  242. choose_btn.action = None
  243. def cursor_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  244. cn_name = board.get_current_text()
  245. current = cursor_cn[cn_name]
  246. is_chosen = "<当前选择>" if (current == chosen) else ""
  247. owned = "已拥有" if cursor_dict[current]["own"] else "未解锁"
  248. info = cursor_dict[current]["info"]
  249. condition = cursor_dict[current]["condition"]
  250. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition}({owned}) ")