skin_menu.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. "糖泡-狂沙": "bomb82",
  30. "糖泡-晶雪": "bomb86",
  31. "糖泡-炉心": "bomb91",
  32. "糖泡-炎魔": "bomb149",
  33. "糖泡-深林": "bomb1436",
  34. }
  35. bomb_dict = {
  36. "bomb1": {"own": True, "name": "糖泡-经典", "info": "陪伴旅人最初的糖泡外观", "img": pygame.image.load(r"res/img/bomb/bomb1_stand_0_0.png").convert_alpha()},
  37. "bomb60": {"own": False, "name": "糖泡-命运", "info": "糖泡伤害额外增加100", "img": pygame.image.load(r"res/img/bomb/bomb60_stand_0_0.png").convert_alpha()},
  38. "bomb82": {"own": False, "name": "糖泡-狂沙", "info": "最大生命额外增加200", "img": pygame.image.load(r"res/img/bomb/bomb82_stand_0_0.png").convert_alpha()},
  39. "bomb86": {"own": False, "name": "糖泡-晶雪", "info": "最大生命额外增加100且糖泡伤害额外增加20", "img": pygame.image.load(r"res/img/bomb/bomb86_stand_0_0.png").convert_alpha()},
  40. "bomb91": {"own": False, "name": "糖泡-炉心", "info": "防御力额外增加50", "img": pygame.image.load(r"res/img/bomb/bomb91_stand_0_0.png").convert_alpha()},
  41. "bomb149": {"own": False, "name": "糖泡-炎魔", "info": "糖泡伤害额外增加150但最大生命减少100", "img": pygame.image.load(r"res/img/bomb/bomb149_stand_0_0.png").convert_alpha()},
  42. "bomb1436": {"own": False, "name": "糖泡-深林", "info": "最大生命额外增加150", "img": pygame.image.load(r"res/img/bomb/bomb1436_stand_0_0.png").convert_alpha()},
  43. }
  44. bomb_list = ["糖泡-经典", "糖泡-命运", "糖泡-狂沙", "糖泡-晶雪", "糖泡-炉心", "糖泡-炎魔", "糖泡-深林"]
  45. class SkinPage:
  46. def __init__(self):
  47. self.screen = W.MENU
  48. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  49. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  50. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  51. self.rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  52. self.other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  53. self.rougeOB_achievements = {}
  54. self.rougeOB_other_data = {}
  55. self.cursor_map = {}
  56. self.current_cursor = None
  57. self.view_cursor = None
  58. self.current_bomb = None
  59. self.init_skin_page()
  60. def init_skin_page(self):
  61. DM.init_achievement()
  62. self.rougeOB_achievements = load_rouge_data(self.rouge_achivements_file_path)
  63. def load_achievements_data(self):
  64. global cursor_dict
  65. max_level = 0
  66. max_diff = "Easy"
  67. max_diff_num = 1
  68. diff_num = {"Baby": 1, "Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  69. diff_status = {"Baby": 1, "Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  70. if self.rougeOB_achievements["Highest"]["level"] != "":
  71. max_level = self.rougeOB_achievements["Highest"]["level"]
  72. if self.rougeOB_achievements["Highest"]["hero"] != "":
  73. max_level_hero = self.rougeOB_achievements["Highest"]["hero"]
  74. if self.rougeOB_achievements["Highest"]["diff"] != "":
  75. max_diff = self.rougeOB_achievements["Highest"]["diff"]
  76. cursor_dict["fire_cursor_gold_kubi"]["own"] = (diff_num[max_diff] >= 4 or (diff_num[max_diff] == 3 and max_level >= 15))
  77. cursor_dict["fire_cursor_kubi"]["own"] = (diff_num[max_diff] >= 3 or (diff_num[max_diff] == 2 and max_level >= 15))
  78. cursor_dict["fire_cursor2"]["own"] = (diff_num[max_diff] >= 2 or (diff_num[max_diff] == 1 and max_level >= 15))
  79. cursor_dict["fire_cursor1"]["own"] = True
  80. def load_other_data(self):
  81. global bomb_dict
  82. # 杂项第一次打开
  83. if not os.path.exists(self.other_file_path):
  84. self.rougeOB_other_data = {
  85. "Bomb": [],
  86. "Pet": [],
  87. "Hat": [],
  88. "LastRandom": 0,
  89. "Other": []
  90. }
  91. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  92. # 正常打开
  93. else:
  94. self.rougeOB_other_data = load_rouge_data(self.other_file_path)
  95. # 读取引路人
  96. if 'Cursor_Skin' not in self.rougeOB_other_data.keys():
  97. self.rougeOB_other_data['Cursor_Skin'] = "fire_cursor1"
  98. self.current_cursor = "fire_cursor1"
  99. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  100. else:
  101. self.current_cursor = self.rougeOB_other_data['Cursor_Skin']
  102. if self.current_cursor not in cursor_dict.keys():
  103. self.current_cursor = "fire_cursor1"
  104. self.view_cursor = self.current_cursor
  105. # 读取糖泡皮肤
  106. if 'Bomb_Skin' not in self.rougeOB_other_data.keys():
  107. self.rougeOB_other_data['Bomb_Skin'] = "bomb1"
  108. self.current_bomb = "bomb1"
  109. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  110. else:
  111. self.current_bomb = self.rougeOB_other_data['Bomb_Skin']
  112. for bomb in self.rougeOB_other_data['Bomb']:
  113. bomb_dict[bomb]["own"] = True
  114. print(f"rougeOB_other_data: {self.rougeOB_other_data}")
  115. def draw(self):
  116. # 引路人
  117. self.screen.buttons.append(PygameButtonBackIMG(
  118. 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')
  119. )
  120. # 藏宝阁
  121. self.screen.buttons.append(PygameButtonBackIMG(
  122. self.screen, self.screen.screen, 0.35, 0.45, "res/ui/button/treasure.png", "res/ui/button/treasure_press.png", action=self.draw_treasure, anchor='center')
  123. )
  124. # 图鉴
  125. self.screen.buttons.append(PygameButtonBackIMG(
  126. self.screen, self.screen.screen, 0.65, 0.45, "res/ui/button/handbook.png", "res/ui/button/handbook_press.png", action=self.draw_handbook, anchor='center')
  127. )
  128. # 返回主界面
  129. self.screen.buttons.append(PygameButtonBackIMG(
  130. 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')
  131. )
  132. def draw_handbook(self):
  133. self.screen.buttons.clear()
  134. from game.ui.menu.handbook_menu import HandbookPage
  135. page = HandbookPage()
  136. page.draw()
  137. del page
  138. def draw_cursor(self):
  139. self.screen.buttons.clear()
  140. self.load_achievements_data()
  141. self.load_other_data()
  142. # ================================= 信息展示 =================================
  143. info_button = PygameButton(
  144. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  145. fg_color=(215,220,217), action=None,
  146. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  147. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  148. )
  149. # ================================= 选择 =================================
  150. choose_button = PygameButtonBackIMG(
  151. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  152. action=None, anchor='center'
  153. )
  154. # ================================= 展示框 =================================
  155. cy = 0.29
  156. button_blank = 0.13
  157. roll_button = PygameButtonBackIMGRoll(
  158. self.screen, self.screen.screen, 0.5, cy, "res/ui/button/cursor_board.png", cursor_list,
  159. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  160. 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,
  161. related_button=[info_button, choose_button],
  162. notify_action=[lambda x: cursor_update_notify(roll_button, x, self.current_cursor), lambda _: self.update_choose_btn(roll_button, choose_button, info_button)]
  163. )
  164. # ================================= 初始化 =================================
  165. choose_button.action = lambda: self.choose_cursor(roll_button, info_button, choose_button) # 追加action
  166. roll_button.set_current_text(cursor_dict[self.current_cursor]["name"])
  167. cursor_update_notify(roll_button, info_button, self.current_cursor)
  168. self.update_choose_btn(roll_button, choose_button, info_button)
  169. # ================================= 添加按钮 =================================
  170. self.screen.buttons.append(info_button)
  171. self.screen.buttons.append(choose_button)
  172. self.screen.buttons.append(roll_button)
  173. # ================================= 上翻页 =================================
  174. self.screen.buttons.append(PygameButtonBackIMG(
  175. 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)
  176. )
  177. # ================================= 下翻页 =================================
  178. self.screen.buttons.append(PygameButtonBackIMG(
  179. 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)
  180. )
  181. # ================================= 返回上一级 =================================
  182. self.screen.buttons.append(PygameButtonBackIMG(
  183. 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')
  184. )
  185. def draw_treasure(self):
  186. self.screen.buttons.clear()
  187. self.load_other_data()
  188. # ================================= 信息展示 =================================
  189. info_button = PygameButton(
  190. self.screen.screen, "", 0.5, 0.56, 18, "#2a2a2a",
  191. fg_color=(215,220,217), action=None,
  192. anchor="center", is_bold=True, fix_shape=(320,80), bg_alpha=159,
  193. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self.screen
  194. )
  195. # ================================= 图片 =================================
  196. img_button = PygameButtonBackIMG(
  197. self.screen, self.screen.screen, 0.65, 0.29, "res/ui/button/img_board.png", "res/ui/button/img_board.png",
  198. action=None, anchor='center', shiny_spark=False
  199. )
  200. img = PygameIMG(self.screen, self.screen.screen, 0.65, 0.29, py_img=bomb_dict["bomb1"]["img"], anchor='center')
  201. # ================================= 选择 =================================
  202. choose_button = PygameButtonBackIMG(
  203. self.screen, self.screen.screen, 0.34, 0.72, "res/ui/button/choose.png", "res/ui/button/choose_press.png",
  204. action=None, anchor='center'
  205. )
  206. # ================================= 展示框 =================================
  207. cy = 0.29
  208. cx = 0.35
  209. button_blank = 0.13
  210. roll_button = PygameButtonBackIMGRoll(
  211. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", bomb_list,
  212. action=None, roll_action=None, hover_in_action=None, hover_out_action=None,
  213. 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,
  214. related_button=[info_button, choose_button, img],
  215. 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)]
  216. )
  217. # ================================= 初始化 =================================
  218. choose_button.action = lambda: self.choose_bomb(roll_button, info_button, choose_button) # 追加action
  219. roll_button.set_current_text(bomb_dict[self.current_bomb]["name"])
  220. bomb_update_notify(roll_button, info_button, self.current_bomb)
  221. self.update_choose_bomb_btn(roll_button, choose_button, info_button)
  222. # ================================= 添加按钮 =================================
  223. self.screen.buttons.append(info_button)
  224. self.screen.buttons.append(choose_button)
  225. self.screen.buttons.append(roll_button)
  226. self.screen.buttons.append(img_button)
  227. self.screen.buttons.append(img)
  228. # ================================= 上翻页 =================================
  229. self.screen.buttons.append(PygameButtonBackIMG(
  230. 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)
  231. )
  232. # ================================= 下翻页 =================================
  233. self.screen.buttons.append(PygameButtonBackIMG(
  234. 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)
  235. )
  236. # ================================= 返回上一级 =================================
  237. self.screen.buttons.append(PygameButtonBackIMG(
  238. 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')
  239. )
  240. def choose_cursor(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  241. cn_name = roll_btn.get_current_text()
  242. current = cursor_cn[cn_name]
  243. self.current_cursor = current
  244. R.cursor_skin = current
  245. self.rougeOB_other_data['Cursor_Skin'] = current
  246. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  247. roll_btn.set_current_text(cursor_dict[self.current_cursor]["name"])
  248. cursor_update_notify(roll_btn, info_button, self.current_cursor)
  249. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  250. choose_btn.shiny_spark = False
  251. choose_btn.action = None
  252. def update_choose_btn(self, roll_button, choose_btn, info_button):
  253. # 拿到当前展示的中文名
  254. cn_name = roll_button.get_current_text()
  255. # 拿到内部 key
  256. key = cursor_cn[cn_name]
  257. # 拿到是否已解锁
  258. owned = cursor_dict[key]["own"]
  259. if owned:
  260. if self.current_cursor == key:
  261. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  262. choose_btn.shiny_spark = False
  263. choose_btn.action = None
  264. else:
  265. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  266. choose_btn.shiny_spark = True
  267. choose_btn.action = lambda cn=cn_name: self.choose_cursor(roll_button, info_button, choose_btn)
  268. else:
  269. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  270. choose_btn.shiny_spark = False
  271. choose_btn.action = None
  272. def choose_bomb(self, roll_btn: PygameButtonBackIMGRoll, info_button, choose_btn):
  273. cn_name = roll_btn.get_current_text()
  274. current = bomb_cn[cn_name]
  275. self.current_bomb = current
  276. R.bomb_skin = current
  277. self.rougeOB_other_data['Bomb_Skin'] = current
  278. save_encrypt_single_rouge_file(self.rougeOB_other_data, "rougeOBOther")
  279. roll_btn.set_current_text(bomb_dict[self.current_bomb]["name"])
  280. bomb_update_notify(roll_btn, info_button, self.current_bomb)
  281. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  282. choose_btn.shiny_spark = False
  283. choose_btn.action = None
  284. def update_choose_bomb_btn(self, roll_button, choose_btn, info_button):
  285. # 拿到当前展示的中文名
  286. cn_name = roll_button.get_current_text()
  287. # 拿到内部 key
  288. key = bomb_cn[cn_name]
  289. # 拿到是否已解锁
  290. owned = bomb_dict[key]["own"]
  291. if owned:
  292. if self.current_bomb == key:
  293. choose_btn.update_image("res/ui/button/chosen.png", "res/ui/button/chosen.png")
  294. choose_btn.shiny_spark = False
  295. choose_btn.action = None
  296. else:
  297. choose_btn.update_image("res/ui/button/choose.png", "res/ui/button/choose_press.png")
  298. choose_btn.shiny_spark = True
  299. choose_btn.action = lambda cn=cn_name: self.choose_bomb(roll_button, info_button, choose_btn)
  300. else:
  301. choose_btn.update_image("res/ui/button/unlock.png", "res/ui/button/unlock.png")
  302. choose_btn.shiny_spark = False
  303. choose_btn.action = None
  304. def cursor_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  305. cn_name = board.get_current_text()
  306. current = cursor_cn[cn_name]
  307. is_chosen = "<当前选择>" if (current == chosen) else ""
  308. owned = "已拥有" if cursor_dict[current]["own"] else "未解锁"
  309. info = cursor_dict[current]["info"]
  310. condition = cursor_dict[current]["condition"]
  311. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n {condition}({owned}) ")
  312. def bomb_update_notify(board: PygameButtonBackIMGRoll, observer: PygameButton, chosen):
  313. cn_name = board.get_current_text()
  314. current = bomb_cn[cn_name]
  315. is_chosen = "<当前选择>" if (current == chosen) else ""
  316. owned = "已拥有" if bomb_dict[current]["own"] else "未解锁"
  317. info = bomb_dict[current]["info"]
  318. observer.set_text(f" {is_chosen}{cn_name} \n {info} \n ({owned}) ")
  319. def bomb_img_update(board: PygameButtonBackIMGRoll, img: PygameIMG):
  320. cn_name = board.get_current_text()
  321. current = bomb_cn[cn_name]
  322. img.update_image(bomb_dict[current]["img"])