import json import os import pygame from game.const import game as G from game.const import window as W from game.const import rouge as R from datetime import datetime from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle, PygameTaskBoard, PygameButtonBackIMGRoll, PygameIMG, PygameButtonBackIMGGuideBookRoll from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data current_folder_path = os.getcwd() content = load_json(f"{G.GAME_PATH}/game/handbook/content.json") theme_dic = { "Field": {"cn": "", "path": "L1_Field"}, "Mo1": {"cn": "", "path": "L1_Mo1"}, "Park": {"cn": "", "path": "L1_Park"}, "Sea": {"cn": "", "path": "L1_Sea"}, "Castle": {"cn": "", "path": "L2_Castle"}, "Forest": {"cn": "", "path": "L2_Forest"}, "Glacier": {"cn": "", "path": "L2_Glacier"}, "Library": {"cn": "", "path": "L2_Library"}, "Gobi": {"cn": "", "path": "L3_Gobi"}, "Lab": {"cn": "", "path": "L3_Lab"}, "Mine": {"cn": "", "path": "L3_Mine"}, "Destiny": {"cn": "", "path": "L4_Destiny"}, "Eden": {"cn": "", "path": "L4_Eden"}, "Skyland": {"cn": "", "path": "L4_Skyland"}, "Wavend": {"cn": "", "path": "L4_Wavend"}, } mon_type_dic = {"normal": "普通", "elite": "精英", "boss": "首领"} monster_dictonary = dict() for theme, mons in content.items(): monster_dictonary[theme] = dict() theme_path = theme_dic[theme]['path'] for mon in mons: try: mon_json = load_json(f"{G.GAME_PATH}/game/handbook/{theme_path}/{mon}.json") character = load_json(f"{G.GAME_PATH}/game/frame/character/{mon_json['character']}.json")["D"]["Cloth"]["IMG"][0] monster_dictonary[theme][mon] = { "name": mon_json.get("chs_name", "???"), "character": pygame.image.load(f"res/img/cloth/{character}").convert_alpha(), "type": mon_type_dic[mon_json.get("type", "normal")], "blood": mon_json.get("blood", 0), "speed": mon_json.get("speed", "???"), "contact": mon_json.get("contact", 0), "defense": mon_json.get("defense", 0), "sight": mon_json.get("resent_dist", "???"), "info": mon_json.get("info", "???"), "strategy": mon_json.get("strategy", "???") } except Exception as e: print(e) monster_dictonary[theme][mon] = { "name": "???", "character": pygame.image.load(f"res/img/cloth/null.png").convert_alpha(), "type": "normal", "blood": 0, "speed": "???", "contact": 0, "defense": 0, "sight": "???", "info": "???", "strategy": "???" } class HandbookPage: def __init__(self): self.current_theme = "Mo1" self.current_monster = "MoFaBingShuang" self.screen = W.MENU def draw(self): self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) self.screen.buttons.append( PygameButton( 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, frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen ) ) # 返回主界面 self.screen.buttons.append(PygameButtonBackIMG( 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') ) def draw_monster(self, theme=None): self.current_theme = theme monsters = content.get(theme, ["零零零零零", "壹壹壹壹壹", "贰贰贰贰贰", "叁叁叁叁叁", "捌捌捌捌捌"]) self.current_monster = monsters[0] self.screen.buttons.clear() # ================================= 信息展示 ================================= info_button = PygameButton( self.screen.screen, "", 0.68, 0.49, 18, "#2a2a2a", fg_color=(215,220,217), action=None, anchor="center", is_bold=True, fix_shape=(340,480), bg_alpha=159, frosted_glass=True, blur_radius=8, glass_alpha=167, glass_surf_color=(41,34,21), background=self.screen ) # ================================= 图片 ================================= img_button = PygameButtonBackIMG( self.screen, self.screen.screen, 0.25, 0.25, "res/ui/button/guide_book.png", "res/ui/button/guide_book.png", action=None, anchor='center', shiny_spark=False ) monster_img = monster_dictonary[self.current_theme][self.current_monster]["character"] img = PygameIMG(self.screen, self.screen.screen, 0.25, 0.25, py_img=monster_img, anchor='center') # ================================= 展示框 ================================= cy = 0.6 cx = 0.25 button_blank = 0.13 roll_button = PygameButtonBackIMGGuideBookRoll( self.screen, self.screen.screen, cx, cy, "res/ui/button/cursor_board.png", monsters, action=None, roll_action=None, hover_in_action=None, hover_out_action=None, 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, related_button=[info_button, img], notify_action=[lambda x: monster_update_notify(roll_button, x, self.current_monster, self.current_theme), lambda _: monster_img_update(roll_button, img, theme)], diction=monster_dictonary[self.current_theme] ) # ================================= 初始化 ================================= roll_button.set_current_text(self.current_monster) monster_update_notify(roll_button, info_button, self.current_monster, self.current_theme) # ================================= 添加按钮 ================================= self.screen.buttons.append(info_button) self.screen.buttons.append(roll_button) self.screen.buttons.append(img_button) self.screen.buttons.append(img) # ================================= 上翻页 ================================= self.screen.buttons.append(PygameButtonBackIMG( 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) ) # ================================= 下翻页 ================================= self.screen.buttons.append(PygameButtonBackIMG( 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) ) # ================================= 返回上一级 ================================= self.screen.buttons.append(PygameButtonBackIMG( 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') ) def choose_monster(self, roll_btn: PygameButtonBackIMGGuideBookRoll, info_button, choose_btn, theme: str): cn_name = roll_btn.get_current_text() # current = bomb_cn[cn_name] current = str(cn_name) self.current_monster = current R.bomb_skin = current roll_btn.set_current_text(current) monster_update_notify(roll_btn, info_button, self.current_monster, theme) def clear_and_draw(self): self.screen.buttons.clear() self.draw() def monster_update_notify(board: PygameButtonBackIMGGuideBookRoll, observer: PygameButton, chosen, theme: str): name = board.get_current_text() new = f"\n {monster_dictonary[theme][name]['name']} \n <{monster_dictonary[theme][name]['type']}> \n\n " \ f"血量: {monster_dictonary[theme][name]['blood']}, 速度: {monster_dictonary[theme][name]['speed']} \n " \ f"碰撞: {monster_dictonary[theme][name]['contact']}, 防御: {monster_dictonary[theme][name]['defense']}, 视野: {monster_dictonary[theme][name]['sight']} \n\n " \ f"{monster_dictonary[theme][name]['info']} \n\n {monster_dictonary[theme][name]['strategy']}" observer.set_text(new) def monster_img_update(board: PygameButtonBackIMGGuideBookRoll, img: PygameIMG, theme: str): name = board.get_current_text() monster_img = monster_dictonary[theme][name]["character"] img.update_image_and_reallocate_position(monster_img, 0.25, 0.25) # img.update_image(monster_img)