handbook_menu.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import json
  2. import os
  3. import pygame
  4. from game.const import game as G
  5. from game.const import window as W
  6. from game.const import rouge as R
  7. from datetime import datetime
  8. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle, PygameTaskBoard, PygameButtonBackIMGRoll, PygameIMG, PygameButtonBackIMGGuideBookRoll
  9. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  10. current_folder_path = os.getcwd()
  11. content = load_json(f"{G.GAME_PATH}/game/handbook/content.json")
  12. theme_dic = {
  13. "Field": {"cn": "", "path": "L1_Field"},
  14. "Mo1": {"cn": "", "path": "L1_Mo1"},
  15. "Park": {"cn": "", "path": "L1_Park"},
  16. "Sea": {"cn": "", "path": "L1_Sea"},
  17. "Castle": {"cn": "", "path": "L2_Castle"},
  18. "Forest": {"cn": "", "path": "L2_Forest"},
  19. "Glacier": {"cn": "", "path": "L2_Glacier"},
  20. "Library": {"cn": "", "path": "L2_Library"},
  21. "Gobi": {"cn": "", "path": "L3_Gobi"},
  22. "Lab": {"cn": "", "path": "L3_Lab"},
  23. "Mine": {"cn": "", "path": "L3_Mine"},
  24. "Destiny": {"cn": "", "path": "L4_Destiny"},
  25. "Eden": {"cn": "", "path": "L4_Eden"},
  26. "Skyland": {"cn": "", "path": "L4_Skyland"},
  27. "Wavend": {"cn": "", "path": "L4_Wavend"},
  28. }
  29. mon_type_dic = {"normal": "普通", "elite": "精英", "boss": "首领"}
  30. monster_dictonary = dict()
  31. for theme, mons in content.items():
  32. monster_dictonary[theme] = dict()
  33. theme_path = theme_dic[theme]['path']
  34. for mon in mons:
  35. try:
  36. mon_json = load_json(f"{G.GAME_PATH}/game/handbook/{theme_path}/{mon}.json")
  37. character = load_json(f"{G.GAME_PATH}/game/frame/character/{mon_json['character']}.json")["D"]["Cloth"]["IMG"][0]
  38. monster_dictonary[theme][mon] = {
  39. "name": mon_json.get("chs_name", "???"),
  40. "character": pygame.image.load(f"res/img/cloth/{character}").convert_alpha(),
  41. "type": mon_type_dic[mon_json.get("type", "normal")],
  42. "blood": mon_json.get("blood", 0),
  43. "speed": mon_json.get("speed", "???"),
  44. "contact": mon_json.get("contact", 0),
  45. "defense": mon_json.get("defense", 0),
  46. "sight": mon_json.get("resent_dist", "???"),
  47. "info": mon_json.get("info", "???"),
  48. "strategy": mon_json.get("strategy", "???")
  49. }
  50. except Exception as e:
  51. print(e)
  52. monster_dictonary[theme][mon] = {
  53. "name": "???",
  54. "character": pygame.image.load(f"res/img/cloth/null.png").convert_alpha(),
  55. "type": "normal",
  56. "blood": 0,
  57. "speed": "???",
  58. "contact": 0,
  59. "defense": 0,
  60. "sight": "???",
  61. "info": "???",
  62. "strategy": "???"
  63. }
  64. class HandbookPage:
  65. def __init__(self):
  66. self.current_theme = "Mo1"
  67. self.current_monster = "MoFaBingShuang"
  68. self.screen = W.MENU
  69. def draw(self):
  70. self.screen.buttons.append(
  71. PygameButton(
  72. self.screen.screen, "魔法王国", 0.2, 0.25, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Mo1"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  73. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  74. )
  75. )
  76. self.screen.buttons.append(
  77. PygameButton(
  78. self.screen.screen, "静涛海原", 0.4, 0.25, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Sea"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  79. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  80. )
  81. )
  82. self.screen.buttons.append(
  83. PygameButton(
  84. self.screen.screen, "废铁乐园", 0.6, 0.25, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Park"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  85. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  86. )
  87. )
  88. self.screen.buttons.append(
  89. PygameButton(
  90. self.screen.screen, "絮语森林", 0.8, 0.25, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Field"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  91. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  92. )
  93. )
  94. self.screen.buttons.append(
  95. PygameButton(
  96. self.screen.screen, "魔法古堡", 0.2, 0.35, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Castle"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  97. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  98. )
  99. )
  100. self.screen.buttons.append(
  101. PygameButton(
  102. self.screen.screen, "永东寒原", 0.4, 0.35, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Glacier"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  103. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  104. )
  105. )
  106. self.screen.buttons.append(
  107. PygameButton(
  108. self.screen.screen, "迷雾古林", 0.6, 0.35, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Forest"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  109. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  110. )
  111. )
  112. self.screen.buttons.append(
  113. PygameButton(
  114. self.screen.screen, "猩红书阁", 0.8, 0.35, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Library"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  115. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  116. )
  117. )
  118. self.screen.buttons.append(
  119. PygameButton(
  120. self.screen.screen, "熔岩深矿", 0.3, 0.45, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Mine"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  121. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  122. )
  123. )
  124. self.screen.buttons.append(
  125. PygameButton(
  126. self.screen.screen, "赤砂遗迹", 0.5, 0.45, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Gobi"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  127. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  128. )
  129. )
  130. self.screen.buttons.append(
  131. PygameButton(
  132. self.screen.screen, "械城之心", 0.7, 0.45, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Lab"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  133. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  134. )
  135. )
  136. self.screen.buttons.append(
  137. PygameButton(
  138. self.screen.screen, "枯朽荒原", 0.2, 0.55, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Eden"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  139. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  140. )
  141. )
  142. self.screen.buttons.append(
  143. PygameButton(
  144. self.screen.screen, "上古遗迹", 0.4, 0.55, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Destiny"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  145. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  146. )
  147. )
  148. self.screen.buttons.append(
  149. PygameButton(
  150. self.screen.screen, "渊海神殿", 0.6, 0.55, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Wavend"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  151. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  152. )
  153. )
  154. self.screen.buttons.append(
  155. PygameButton(
  156. self.screen.screen, "空岛圣殿", 0.8, 0.55, 24, "#2a2a2a", fg_color=(215,220,217), action=lambda: self.draw_monster(theme="Skyland"), anchor="center", is_bold=True, fix_shape=(120,34), bg_alpha=159,
  157. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen
  158. )
  159. )
  160. # 返回主界面
  161. self.screen.buttons.append(PygameButtonBackIMG(
  162. 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')
  163. )
  164. def draw_monster(self, theme=None):
  165. self.current_theme = theme
  166. monsters = content.get(theme, ["零零零零零", "壹壹壹壹壹", "贰贰贰贰贰", "叁叁叁叁叁", "捌捌捌捌捌"])
  167. self.current_monster = monsters[0]
  168. self.screen.buttons.clear()
  169. # ================================= 信息展示 =================================
  170. info_button = PygameButton(
  171. self.screen.screen, "", 0.68, 0.49, 18, "#2a2a2a",
  172. fg_color=(215,220,217), action=None,
  173. anchor="center", is_bold=True, fix_shape=(340,480), bg_alpha=159,
  174. frosted_glass=True, blur_radius=8, glass_alpha=167, glass_surf_color=(41,34,21), background=self.screen
  175. )
  176. # ================================= 图片 =================================
  177. img_button = PygameButtonBackIMG(
  178. self.screen, self.screen.screen, 0.25, 0.25, "res/ui/button/guide_book.png", "res/ui/button/guide_book.png",
  179. action=None, anchor='center', shiny_spark=False
  180. )
  181. monster_img = monster_dictonary[self.current_theme][self.current_monster]["character"]
  182. img = PygameIMG(self.screen, self.screen.screen, 0.25, 0.25, py_img=monster_img, anchor='center')
  183. # ================================= 展示框 =================================
  184. cy = 0.6
  185. cx = 0.25
  186. button_blank = 0.13
  187. roll_button = PygameButtonBackIMGGuideBookRoll(
  188. self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", monsters,
  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=22, small_scale=0.7, small_alpha=159, color=(0, 0, 0), shiny_spark=False,
  191. related_button=[info_button, img],
  192. notify_action=[lambda x: monster_update_notify(roll_button, x, self.current_monster, self.current_theme), lambda _: monster_img_update(roll_button, img, theme)],
  193. diction=monster_dictonary[self.current_theme]
  194. )
  195. # ================================= 初始化 =================================
  196. roll_button.set_current_text(self.current_monster)
  197. monster_update_notify(roll_button, info_button, self.current_monster, self.current_theme)
  198. # ================================= 添加按钮 =================================
  199. self.screen.buttons.append(info_button)
  200. self.screen.buttons.append(roll_button)
  201. self.screen.buttons.append(img_button)
  202. self.screen.buttons.append(img)
  203. # ================================= 上翻页 =================================
  204. self.screen.buttons.append(PygameButtonBackIMG(
  205. 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)
  206. )
  207. # ================================= 下翻页 =================================
  208. self.screen.buttons.append(PygameButtonBackIMG(
  209. 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)
  210. )
  211. # ================================= 返回上一级 =================================
  212. self.screen.buttons.append(PygameButtonBackIMG(
  213. self.screen, self.screen.screen, 0.25, 0.85, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.clear_and_draw, anchor='center')
  214. )
  215. def choose_monster(self, roll_btn: PygameButtonBackIMGGuideBookRoll, info_button, choose_btn, theme: str):
  216. cn_name = roll_btn.get_current_text()
  217. # current = bomb_cn[cn_name]
  218. current = str(cn_name)
  219. self.current_monster = current
  220. R.bomb_skin = current
  221. roll_btn.set_current_text(current)
  222. monster_update_notify(roll_btn, info_button, self.current_monster, theme)
  223. def clear_and_draw(self):
  224. self.screen.buttons.clear()
  225. self.draw()
  226. def monster_update_notify(board: PygameButtonBackIMGGuideBookRoll, observer: PygameButton, chosen, theme: str):
  227. name = board.get_current_text()
  228. new = f"\n {monster_dictonary[theme][name]['name']} \n <{monster_dictonary[theme][name]['type']}> \n\n " \
  229. f"血量: {monster_dictonary[theme][name]['blood']}, 速度: {monster_dictonary[theme][name]['speed']} \n " \
  230. f"碰撞: {monster_dictonary[theme][name]['contact']}, 防御: {monster_dictonary[theme][name]['defense']}, 视野: {monster_dictonary[theme][name]['sight']} \n\n " \
  231. f"{monster_dictonary[theme][name]['info']} \n\n {monster_dictonary[theme][name]['strategy']}"
  232. observer.set_text(new)
  233. def monster_img_update(board: PygameButtonBackIMGGuideBookRoll, img: PygameIMG, theme: str):
  234. name = board.get_current_text()
  235. monster_img = monster_dictonary[theme][name]["character"]
  236. img.update_image_and_reallocate_position(monster_img, 0.25, 0.25)
  237. # img.update_image(monster_img)