From 840873ed356f43e169811c19e6153e7bc51dc31f Mon Sep 17 00:00:00 2001 From: yudonglin Date: Sun, 13 Jun 2021 10:53:14 -0700 Subject: [PATCH 1/4] using upcoming 3.1.0 api --- Source/gamemode/editor.py | 26 +++++++++++++------------- Source/gamemode/survival.py | 10 +++++----- Source/gamemode/turnBased.py | 25 ++++++++++++++----------- Source/gamemode/ui.py | 26 +++++++++++++------------- Source/mainMenu.py | 28 ++++++++++++++-------------- Source/scene.py | 4 ++-- main.py | 2 +- 7 files changed, 62 insertions(+), 59 deletions(-) diff --git a/Source/gamemode/editor.py b/Source/gamemode/editor.py index 03100b11..077cde20 100644 --- a/Source/gamemode/editor.py +++ b/Source/gamemode/editor.py @@ -43,10 +43,10 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec button_height:int = int(screen.get_height()*0.2) panding:int = int(screen.get_height()*0.01) font_size:int = int(button_width/3) - self.__button_select_block = linpg.load_button_with_text_in_center( + self.__button_select_block = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png",linpg.get_lang("MapEditor","block"),"black",font_size,(0,screen.get_width()*0.03),100 ) - self.__button_select_decoration = linpg.load_button_with_text_in_center( + self.__button_select_decoration = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png",linpg.get_lang("MapEditor","decoration"),"black",font_size,(0,screen.get_width()*0.03),100 ) self.__button_select_block.set_left( @@ -66,7 +66,7 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec None, int(container_width*0.075), int(screen.get_height()*0.1), int(container_width*0.85), int(screen.get_height()*0.85), "vertical" ) for imgPath in glob.glob(r'Assets/image/environment/block/*.png'): - self.__envImgContainer.set(os.path.basename(imgPath).replace(".png",""),linpg.load_img(imgPath,(self.MAP.block_width/3,None))) + self.__envImgContainer.set(os.path.basename(imgPath).replace(".png",""),linpg.load.img(imgPath,(self.MAP.block_width/3,None))) self.__envImgContainer.set_item_per_line(4) self.__envImgContainer.set_scroll_bar_pos("right") self.__envImgContainer.hidden = False @@ -76,7 +76,7 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec None, int(container_width*0.075), int(screen.get_height()*0.1), int(container_width*0.85), int(screen.get_height()*0.85), "vertical" ) for imgPath in glob.glob(r'Assets/image/environment/decoration/*.png'): - self.__decorationsImgContainer.set(os.path.basename(imgPath).replace(".png",""),linpg.load_img(imgPath,(self.MAP.block_width/3,None))) + self.__decorationsImgContainer.set(os.path.basename(imgPath).replace(".png",""),linpg.load.img(imgPath,(self.MAP.block_width/3,None))) self.__decorationsImgContainer.set_item_per_line(4) self.__decorationsImgContainer.set_scroll_bar_pos("right") self.__decorationsImgContainer.hidden = True @@ -88,10 +88,10 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec button_height = int(screen.get_height()*0.05) panding = int(screen.get_height()*0.01) font_size = int(button_height/2) - self.__button_select_character = linpg.load_button_with_text_in_center( + self.__button_select_character = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png",linpg.get_lang("General","griffin_Kryuger"),"black",font_size,(0,0),100 ) - self.__button_select_sangvisFerri = linpg.load_button_with_text_in_center( + self.__button_select_sangvisFerri = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png",linpg.get_lang("General","sangvis_ferri"),"black",font_size,(self.__button_select_character.get_width(),0),100 ) self.__UIContainerBottom = linpg.load_dynamic_image("Assets/image/UI/container.png",(0,0),container_width,container_height) @@ -109,7 +109,7 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec img_name = os.path.basename(imgPath) self.__charactersImgContainer.set( img_name, - linpg.cope_bounding(linpg.load_img(os.path.join(imgPath, "wait", "{}_wait_0.png".format(img_name)), (None, container_height*1.5))) + linpg.cope_bounding(linpg.load.img(os.path.join(imgPath, "wait", "{}_wait_0.png".format(img_name)), (None, container_height*1.5))) ) self.__charactersImgContainer.set_scroll_bar_pos("bottom") self.__charactersImgContainer.hidden = False @@ -122,13 +122,13 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec img_name = os.path.basename(imgPath) self.__sangvisFerrisImgContainer.set( img_name, - linpg.cope_bounding(linpg.load_img(os.path.join(imgPath, "wait", "{}_wait_0.png".format(img_name)), (None, container_height*1.5))) + linpg.cope_bounding(linpg.load.img(os.path.join(imgPath, "wait", "{}_wait_0.png".format(img_name)), (None, container_height*1.5))) ) self.__sangvisFerrisImgContainer.set_scroll_bar_pos("bottom") self.__sangvisFerrisImgContainer.hidden = True self.__sangvisFerrisImgContainer.distance_between_item = panding #绿色方块/方块标准 - self.greenBlock = linpg.load_img("Assets/image/UI/range/green.png",(self.MAP.block_width*0.8,None)) + self.greenBlock = linpg.load.img("Assets/image/UI/range/green.png",(self.MAP.block_width*0.8,None)) self.greenBlock.set_alpha(150) self.redBlock = linpg.load_img("Assets/image/UI/range/red.png",(self.MAP.block_width*0.8,None)) self.redBlock.set_alpha(150) @@ -139,19 +139,19 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec UI_x = self.MAP.block_width*0.5 UI_y = int(screen.get_height()*0.02) font_size = int(self.MAP.block_width*0.2) - self.UIButton["save"] = linpg.load_button_with_text_in_center( + self.UIButton["save"] = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png", linpg.get_lang("Global", "save"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["save"].get_width()+font_size - self.UIButton["back"] = linpg.load_button_with_text_in_center( + self.UIButton["back"] = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png", linpg.get_lang("Global", "back"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["back"].get_width()+font_size - self.UIButton["delete"] = linpg.load_button_with_text_in_center( + self.UIButton["delete"] = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png", linpg.get_lang("Global", "delete"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["delete"].get_width()+font_size - self.UIButton["reload"] = linpg.load_button_with_text_in_center( + self.UIButton["reload"] = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png", linpg.get_lang("Global", "reload_file"), "black", font_size, (UI_x, UI_y), 100 ) #其他函数 diff --git a/Source/gamemode/survival.py b/Source/gamemode/survival.py index 3f68f9d8..659f08ff 100644 --- a/Source/gamemode/survival.py +++ b/Source/gamemode/survival.py @@ -11,11 +11,11 @@ def __init__(self): self.window_x,self.window_y = linpg.display.get_size() self.DATABASE = linpg.loadCharacterData() self.original_UI_img = { - "green" : linpg.load_img("Assets/image/UI/range/green.png"), - "red" : linpg.load_img("Assets/image/UI/range/red.png"), - "yellow": linpg.load_img("Assets/image/UI/range/yellow.png"), - "blue": linpg.load_img("Assets/image/UI/range/blue.png"), - "orange": linpg.load_img("Assets/image/UI/range/orange.png"), + "green" : linpg.load.img("Assets/image/UI/range/green.png"), + "red" : linpg.load.img("Assets/image/UI/range/red.png"), + "yellow": linpg.load.img("Assets/image/UI/range/yellow.png"), + "blue": linpg.load.img("Assets/image/UI/range/blue.png"), + "orange": linpg.load.img("Assets/image/UI/range/orange.png"), "eyeImg": linpg.ProgressBarSurface("Assets/image/UI/eye_red.png","Assets/image/UI/eye_orange.png",0,0,0,0), "vigilanceImg": linpg.ProgressBarSurface("Assets/image/UI/vigilance_red.png","Assets/image/UI/vigilance_orange.png",0,0,0,0,"height"), "supplyBoard":linpg.load_dynamic_image("Assets/image/UI/score.png",((self.window_x-self.window_x/3)/2,-self.window_y/12),self.window_x/3,self.window_y/12), diff --git a/Source/gamemode/turnBased.py b/Source/gamemode/turnBased.py index c49a0dd4..a0d11b2e 100644 --- a/Source/gamemode/turnBased.py +++ b/Source/gamemode/turnBased.py @@ -180,9 +180,13 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: #加载UI: #加载结束回合的图片 self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.get_color_rbga("white")) - self.end_round_button = linpg.load_static_image("Assets/image/UI/end_round_button.png",(self.window_x*0.8,self.window_y*0.7),self.end_round_txt.get_width()*2,self.end_round_txt.get_height()*2.5) + self.end_round_button = linpg.load.static_image( + "Assets/image/UI/end_round_button.png", + (self.window_x*0.8, self.window_y*0.7), + (self.end_round_txt.get_width()*2, self.end_round_txt.get_height()*2.5) + ) #加载子弹图片 - #bullet_img = load_img("Assets/image/UI/bullet.png", get_block_width()/6, self.MAP.block_height/12) + #bullet_img = load.img("Assets/image/UI/bullet.png", get_block_width()/6, self.MAP.block_height/12) #加载显示获取到补给后的信息栏 supply_board_width:int = int(self.window_x/3) supply_board_height:int = int(self.window_y/12) @@ -198,11 +202,11 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.supply_board.stayingTime = 0 #用于表示范围的方框图片 self.range_ui_images = { - "green" : linpg.load_static_image(r"Assets/image/UI/range/green.png",(0,0)), - "red" : linpg.load_static_image(r"Assets/image/UI/range/red.png",(0,0)), - "yellow": linpg.load_static_image(r"Assets/image/UI/range/yellow.png",(0,0)), - "blue": linpg.load_static_image(r"Assets/image/UI/range/blue.png",(0,0)), - "orange": linpg.load_static_image(r"Assets/image/UI/range/orange.png",(0,0)), + "green" : linpg.load.static_image(r"Assets/image/UI/range/green.png",(0,0)), + "red" : linpg.load.static_image(r"Assets/image/UI/range/red.png",(0,0)), + "yellow": linpg.load.static_image(r"Assets/image/UI/range/yellow.png",(0,0)), + "blue": linpg.load.static_image(r"Assets/image/UI/range/blue.png",(0,0)), + "orange": linpg.load.static_image(r"Assets/image/UI/range/orange.png",(0,0)), } for key in self.range_ui_images: self.range_ui_images[key].set_width_with_size_locked(self.MAP.block_width*0.8) @@ -320,11 +324,10 @@ def updated_language(self, screen) -> None: self.battleModeUiTxt = linpg.get_lang("Battle_UI") self.RoundSwitchUI = RoundSwitch(self.window_x,self.window_y,self.battleModeUiTxt) self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.get_color_rbga("white")) - self.end_round_button = linpg.load_static_image( + self.end_round_button = linpg.load.static_image( r"Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), - self.end_round_txt.get_width()*2, - self.end_round_txt.get_height()*2.5 + (self.end_round_txt.get_width()*2, self.end_round_txt.get_height()*2.5) ) self.warnings_to_display = WarningSystem(int(screen.get_height()*0.03)) self._DIALOG.updated_language(screen) @@ -1220,7 +1223,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: self.__update_scene(screen) #展示暂停菜单 if not self.pause_menu.hidden: - progress_saved_text = linpg.load_static_image( + progress_saved_text = linpg.load.static_image( self.FONT.render(linpg.get_lang("Global","progress_has_been_saved"),linpg.get_antialias(),(255,255,255)), (0,0) ) diff --git a/Source/gamemode/ui.py b/Source/gamemode/ui.py index c0b64f92..c061b739 100644 --- a/Source/gamemode/ui.py +++ b/Source/gamemode/ui.py @@ -4,18 +4,18 @@ import time from typing import Union # 第三方 -import linpg -#from linpgdev import linpg +#import linpg +from linpgdev import linpg from collections import deque # 显示回合切换的UI class RoundSwitch: def __init__(self, window_x:int, window_y:int, battleUiTxt:dict): - self.lineRedDown = linpg.load_img(r"Assets/image/UI/lineRed.png", (window_x, window_y/50)) + self.lineRedDown = linpg.load.img(r"Assets/image/UI/lineRed.png", (window_x, window_y/50)) self.lineRedUp = linpg.rotate_img(self.lineRedDown, 180) - self.lineGreenDown = linpg.load_img(r"Assets/image/UI/lineGreen.png", (window_x, window_y/50)) + self.lineGreenDown = linpg.load.img(r"Assets/image/UI/lineGreen.png", (window_x, window_y/50)) self.lineGreenUp = linpg.rotate_img(self.lineGreenDown, 180) - self.baseImg = linpg.load_img(r"Assets/image/UI/roundSwitchBase.png", (window_x, window_y/5)) + self.baseImg = linpg.load.img(r"Assets/image/UI/roundSwitchBase.png", (window_x, window_y/5)) self.baseImg.set_alpha(0) self.x = -window_x self.y = int((window_y - self.baseImg.get_height())/2) @@ -148,7 +148,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: class SelectMenu: def __init__(self): selectMenuTxtDic:dict = linpg.get_lang("SelectMenu") - self.selectButtonImg = linpg.load_img("Assets/image/UI/menu.png") + self.selectButtonImg = linpg.load.img("Assets/image/UI/menu.png") #攻击 self.attackAP = linpg.AP_IS_NEEDED_TO_ATTACK self.attackTxt = selectMenuTxtDic["attack"] @@ -269,16 +269,16 @@ def draw(self, screen:linpg.ImageSurface, fontSize:Union[int,float], location:di #角色信息板 class CharacterInfoBoard: def __init__(self, window_x:int, window_y:int, text_size:int=20): - self.boardImg = linpg.load_img("Assets/image/UI/score.png",(window_x/5,window_y/6)) + self.boardImg = linpg.load.img("Assets/image/UI/score.png",(window_x/5,window_y/6)) self.characterIconImages = {} all_icon_file_list = glob.glob(r'Assets/image/npc_icon/*.png') for i in range(len(all_icon_file_list)): img_name = all_icon_file_list[i].replace("Assets","").replace("image","").replace("npc_icon","").replace(".png","").replace("\\","").replace("/","") - self.characterIconImages[img_name] = linpg.smoothly_resize_img(linpg.load_img(all_icon_file_list[i]),(window_y*0.08,window_y*0.08)) + self.characterIconImages[img_name] = linpg.smoothly_resize_img(linpg.load.img(all_icon_file_list[i]),(window_y*0.08,window_y*0.08)) del all_icon_file_list self.text_size = text_size self.informationBoard = None - hp_empty_img = linpg.load_img("Assets/image/UI/hp_empty.png") + hp_empty_img = linpg.load.img("Assets/image/UI/hp_empty.png") self.hp_red = linpg.ProgressBarSurface("Assets/image/UI/hp_red.png",hp_empty_img,0,0,window_x/15,text_size) self.hp_green = linpg.ProgressBarSurface("Assets/image/UI/hp_green.png",hp_empty_img,0,0,window_x/15,text_size) self.action_point_blue = linpg.ProgressBarSurface("Assets/image/UI/action_point.png",hp_empty_img,0,0,window_x/15,text_size) @@ -336,7 +336,7 @@ def __init__(self, finalResult:dict, font_size:int, is_win:bool=True): self.x = int(font_size*10) self.y = int(font_size*10) self.txt_x = int(font_size*12) - self.boardImg = linpg.load_img("Assets/image/UI/score.png",(font_size*16,font_size*32)) + self.boardImg = linpg.load.img("Assets/image/UI/score.png",(font_size*16,font_size*32)) self.total_kills = linpg.render_font(resultTxt["total_kills"]+": "+str(finalResult["total_kills"]),"white",font_size) self.total_time = linpg.render_font(resultTxt["total_time"]+": "+str(time.strftime('%M:%S',finalResult["total_time"])),"white",font_size) self.total_rounds_txt = linpg.render_font(resultTxt["total_rounds"]+": "+str(finalResult["total_rounds"]),"white",font_size) @@ -359,11 +359,11 @@ class LoadingTitle: def __init__(self, window_x:int, window_y:int, numChapter_txt:str, chapterId:int, chapterTitle_txt:str, chapterDesc_txt:str): self.black_bg = linpg.get_single_color_surface("black") title_chapterNum = linpg.render_font(numChapter_txt.format(chapterId),"white",window_x/38) - self.title_chapterNum = linpg.load_static_image(title_chapterNum,((window_x-title_chapterNum.get_width())/2,window_y*0.37)) + self.title_chapterNum = linpg.load.static_image(title_chapterNum,((window_x-title_chapterNum.get_width())/2,window_y*0.37)) title_chapterName = linpg.render_font(chapterTitle_txt,"white",window_x/38) - self.title_chapterName = linpg.load_static_image(title_chapterName,((window_x-title_chapterName.get_width())/2,window_y*0.46)) + self.title_chapterName = linpg.load.static_image(title_chapterName,((window_x-title_chapterName.get_width())/2,window_y*0.46)) title_description = linpg.render_font(chapterDesc_txt,"white",window_x/76) - self.title_description = linpg.load_static_image(title_description,((window_x-title_description.get_width())/2,window_y*0.6)) + self.title_description = linpg.load.static_image(title_description,((window_x-title_description.get_width())/2,window_y*0.6)) def draw(self, screen:linpg.ImageSurface, alpha:int=255) -> None: self.title_chapterNum.set_alpha(alpha) self.title_chapterName.set_alpha(alpha) diff --git a/Source/mainMenu.py b/Source/mainMenu.py index af8ea650..befc7141 100644 --- a/Source/mainMenu.py +++ b/Source/mainMenu.py @@ -39,7 +39,7 @@ def __init__(self, screen:linpg.ImageSurface): linpg.get_setting("Sound","background_music")/100.0 ) #初始化返回菜单判定参数 - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) #载入页面 - 渐出 dispaly_loading_screen(screen,250,0,int(-2*linpg.display.sfpsp)) #设置Discord状态 @@ -198,15 +198,15 @@ def __load_scene(self, chapterType:str, chapterId:int, screen:linpg.ImageSurface self.__background.stop() projectName = None if chapterType == "main_chapter" else self.current_selected_workshop_project dialog(screen, chapterType, chapterId, "dialog_before_battle", projectName) - if not linpg.get_glob_value("BackToMainMenu"): + if not linpg.global_value.get("BackToMainMenu"): battle(screen,chapterType,chapterId,projectName) - if not linpg.get_glob_value("BackToMainMenu"): + if not linpg.global_value.get("BackToMainMenu"): dialog(screen, chapterType, chapterId, "dialog_after_battle", projectName) - linpg.if_get_set_glob_value("BackToMainMenu",True,False) + linpg.global_value.if_get_set("BackToMainMenu",True,False) else: - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) else: - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) self.__reset_menu() if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #继续章节 @@ -222,23 +222,23 @@ def __continue_scene(self, screen:linpg.ImageSurface) -> None: startPoint = SAVE["type"] if startPoint == "dialog_before_battle": dialog(screen, None, None, None) - if not linpg.get_glob_value("BackToMainMenu"): + if not linpg.global_value.get("BackToMainMenu"): battle(screen,SAVE["chapter_type"],SAVE["chapter_id"],SAVE["project_name"]) - if not linpg.get_glob_value("BackToMainMenu"): + if not linpg.global_value.get("BackToMainMenu"): dialog(screen, SAVE["chapter_type"], SAVE["chapter_id"], "dialog_after_battle", SAVE["project_name"]) else: - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) else: - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) elif startPoint == "battle": battle(screen, None, None) - if not linpg.get_glob_value("BackToMainMenu"): + if not linpg.global_value.get("BackToMainMenu"): dialog(screen, SAVE["chapter_type"], SAVE["chapter_id"], "dialog_after_battle", SAVE["project_name"]) else: - linpg.set_glob_value("BackToMainMenu",False) + linpg.global_value.set("BackToMainMenu",False) elif startPoint == "dialog_after_battle": dialog(screen, None, None, None) - linpg.if_get_set_glob_value("BackToMainMenu",True,False) + linpg.global_value.if_get_set("BackToMainMenu",True,False) self.__reset_menu() if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #更新主菜单的部分元素 @@ -316,7 +316,7 @@ def __draw_background(self, screen:linpg.ImageSurface) -> None: break if cover_path is not None: if self.__cover_img_surface is None: - self.__cover_img_surface = linpg.load_static_image(cover_path, (0,0), screen.get_width(), screen.get_height(), cover_path) + self.__cover_img_surface = linpg.load.static_image(cover_path, (0,0), screen.get_size(), cover_path) self.__cover_img_surface.set_alpha(10) elif cover_path != self.__cover_img_surface.tag: self.__cover_img_surface.update_image(cover_path) diff --git a/Source/scene.py b/Source/scene.py index 2aca081b..15f0dabe 100644 --- a/Source/scene.py +++ b/Source/scene.py @@ -15,10 +15,10 @@ def save_progress(self) -> None: def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> dict: #加载闸门动画的图片素材 LoadingImgAbove:linpg.ImageSurface = linpg.smoothly_resize_img( - linpg.cope_bounding(linpg.quickly_load_img(r"Assets/image/UI/LoadingImgAbove.png")), (screen.get_width()+4, screen.get_height()/1.7) + linpg.cope_bounding(linpg.load.img(r"Assets/image/UI/LoadingImgAbove.png")), (screen.get_width()+4, screen.get_height()/1.7) ) LoadingImgBelow:linpg.ImageSurface = linpg.smoothly_resize_img( - linpg.cope_bounding(linpg.quickly_load_img(r"Assets/image/UI/LoadingImgBelow.png")), (screen.get_width()+4, screen.get_height()/2.05) + linpg.cope_bounding(linpg.load.img(r"Assets/image/UI/LoadingImgBelow.png")), (screen.get_width()+4, screen.get_height()/2.05) ) #开始加载-闸门关闭的效果 for i in range(101): diff --git a/main.py b/main.py index 34174c9e..ba6a3e87 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ #游戏主进程 if GAMESTART is True and __name__ == "__main__": #创建窗口 - screen = linpg.display.init_screen() + screen = linpg.display.init() #窗口标题图标 linpg.display.set_icon("Assets/image/UI/icon.png") linpg.display.set_caption(linpg.get_lang('General','game_title')) From 2c18244c4ba54c40f951b5e4194430adfa085a54 Mon Sep 17 00:00:00 2001 From: yudonglin Date: Thu, 24 Jun 2021 15:29:52 -0700 Subject: [PATCH 2/4] continue to modify api to support upcoming linpg update Maybe both 3.0.11 and 3.1.0? We will see. --- Source/component.py | 2 +- Source/gamemode/editor.py | 25 ++++++++++++------------ Source/gamemode/survival.py | 7 +++++-- Source/gamemode/turnBased.py | 37 ++++++++++++++++++------------------ Source/scene.py | 4 +--- main.py | 19 +++++++++++------- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/Source/component.py b/Source/component.py index adadd237..46953e2a 100644 --- a/Source/component.py +++ b/Source/component.py @@ -16,7 +16,7 @@ def dispaly_loading_screen(screen:linpg.ImageSurface, start:int, end:int, value: text2 = linpg.render_font(linpg.get_lang("title2"), "white", window_x/64) #主循环 for i in range(start,end,value): - screen.fill(linpg.get_color_rbga("black")) + screen.fill(linpg.Color.BLACK) text1.set_alpha(i) text2.set_alpha(i) screen.blits(((text1,(window_x/64,window_y*0.9)),(text2,(window_x/64,window_y*0.9-window_x/32)))) diff --git a/Source/gamemode/editor.py b/Source/gamemode/editor.py index 077cde20..a4890067 100644 --- a/Source/gamemode/editor.py +++ b/Source/gamemode/editor.py @@ -53,12 +53,13 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec int((container_width-self.__button_select_block.get_width()-self.__button_select_decoration.get_width()-panding)/2) ) self.__button_select_decoration.set_left(self.__button_select_block.right+panding) - self.__UIContainerRight = linpg.load_dynamic_image("Assets/image/UI/container.png",(0,0),container_width,container_height) - self.__UIContainerButtonRight = linpg.load_movable_image("Assets/image/UI/container_button.png", - (screen.get_width()-button_width,int((screen.get_height()-button_height)/2)), - (screen.get_width()-button_width-container_width,int((screen.get_height()-button_height)/2)), - (int(container_width/10),0),button_width,button_height - ) + self.__UIContainerRight = linpg.load.dynamic_image(r"Assets/image/UI/container.png", (0,0), (container_width,container_height)) + self.__UIContainerButtonRight = linpg.load.movable_image( + r"Assets/image/UI/container_button.png", + (int(screen.get_width()-button_width), int((screen.get_height()-button_height)/2)), + (int(screen.get_width()-button_width-container_width), int((screen.get_height()-button_height)/2)), + (int(container_width/10), 0), (button_width, button_height) + ) self.__UIContainerRight.rotate(90) self.__UIContainerButtonRight.rotate(90) #加载背景图片 @@ -94,12 +95,12 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec self.__button_select_sangvisFerri = linpg.load.button_with_text_in_center( "Assets/image/UI/menu.png",linpg.get_lang("General","sangvis_ferri"),"black",font_size,(self.__button_select_character.get_width(),0),100 ) - self.__UIContainerBottom = linpg.load_dynamic_image("Assets/image/UI/container.png",(0,0),container_width,container_height) - self.__UIContainerButtonBottom = linpg.load_movable_image( - "Assets/image/UI/container_button.png", - ((container_width-button_width)/2,screen.get_height()-button_height), - ((container_width-button_width)/2,screen.get_height()-button_height-container_height), - (0,container_height/10),button_width,button_height + self.__UIContainerBottom = linpg.load.dynamic_image(r"Assets/image/UI/container.png", (0,0), (container_width,container_height)) + self.__UIContainerButtonBottom = linpg.load.movable_image( + r"Assets/image/UI/container_button.png", + (int((container_width-button_width)/2), int(screen.get_height()-button_height)), + (int((container_width-button_width)/2), int(screen.get_height()-button_height-container_height)), + (0, int(container_height/10)), (button_width, button_height) ) #加载所有友方的角色的图片文件 self.__charactersImgContainer:object = linpg.SurfaceContainerWithScrollbar( diff --git a/Source/gamemode/survival.py b/Source/gamemode/survival.py index 659f08ff..5cfef4c0 100644 --- a/Source/gamemode/survival.py +++ b/Source/gamemode/survival.py @@ -18,7 +18,10 @@ def __init__(self): "orange": linpg.load.img("Assets/image/UI/range/orange.png"), "eyeImg": linpg.ProgressBarSurface("Assets/image/UI/eye_red.png","Assets/image/UI/eye_orange.png",0,0,0,0), "vigilanceImg": linpg.ProgressBarSurface("Assets/image/UI/vigilance_red.png","Assets/image/UI/vigilance_orange.png",0,0,0,0,"height"), - "supplyBoard":linpg.load_dynamic_image("Assets/image/UI/score.png",((self.window_x-self.window_x/3)/2,-self.window_y/12),self.window_x/3,self.window_y/12), + "supplyBoard":linpg.load.dynamic_image( + r"Assets/image/UI/score.png", + ((self.window_x-self.window_x/3)/2,-self.window_y/12),(self.window_x/3,self.window_y/12) + ), } """init""" #shutil.copyfile("Data/chapter_map_example.yaml","Save/map1.yaml") @@ -107,5 +110,5 @@ def draw(self, screen:linpg.ImageSurface) -> None: self._display_decoration(screen) pos_x,pos_y = self.MAP.calPosInMap(self.alliances["me"].x,self.alliances["me"].y) pos_x += linpg.display.get_width()/20 - #pygame.draw.line(screen,linpg.get_color_rbga("red"),(pos_x,pos_y),(mouse_x,mouse_y),5) + #pygame.draw.line(screen,linpg.Color.RED,(pos_x,pos_y),(mouse_x,mouse_y),5) linpg.display.flip() \ No newline at end of file diff --git a/Source/gamemode/turnBased.py b/Source/gamemode/turnBased.py index a0d11b2e..ea8ee350 100644 --- a/Source/gamemode/turnBased.py +++ b/Source/gamemode/turnBased.py @@ -119,7 +119,7 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: ) self.battleMode_info = DataTmp["battle_info"] #正在加载的gif动态图标 - nowLoadingIcon = linpg.load_gif( + nowLoadingIcon = linpg.load.gif( r"Assets/image/UI/sv98_walking.gif", (self.window_x*0.7, self.window_y*0.83), (self.window_x*0.003*15, self.window_x*0.003*21) @@ -173,13 +173,13 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self._calculate_darkness() #开始加载关卡设定 self.infoToDisplayDuringLoading.draw(screen) - now_loading = self.FONT.render(loading_info["now_loading_level"],linpg.get_antialias(),linpg.get_color_rbga("white")) + now_loading = self.FONT.render(loading_info["now_loading_level"],linpg.get_antialias(),linpg.Color.WHITE) screen.blit(now_loading,(self.window_x*0.75,self.window_y*0.9)) nowLoadingIcon.draw(screen) linpg.display.flip() #加载UI: #加载结束回合的图片 - self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.get_color_rbga("white")) + self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.Color.WHITE) self.end_round_button = linpg.load.static_image( "Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), @@ -191,12 +191,10 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: supply_board_width:int = int(self.window_x/3) supply_board_height:int = int(self.window_y/12) supply_board_x:int = int((self.window_x-supply_board_width)/2) - self.supply_board = linpg.load_movable_image( - "Assets/image/UI/score.png", - (supply_board_x,-supply_board_height), - (supply_board_x,0), - (0,int(self.window_y*0.005)), - supply_board_width, supply_board_height + self.supply_board = linpg.load.movable_image( + r"Assets/image/UI/score.png", + (supply_board_x, -supply_board_height), (supply_board_x, 0), + (0, int(self.window_y*0.005)), (supply_board_width, supply_board_height) ) self.supply_board.items = [] self.supply_board.stayingTime = 0 @@ -214,12 +212,13 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.characterInfoBoardUI = CharacterInfoBoard(self.window_x,self.window_y) #加载用于渲染电影效果的上下黑色帘幕 black_curtain = linpg.new_surface((self.window_x,self.window_y*0.15)).convert() - black_curtain.fill(linpg.get_color_rbga("black")) - self.__up_black_curtain = linpg.load_movable_image( - black_curtain,(0,-black_curtain.get_height()),(0,0),(0,black_curtain.get_height()*0.05) + black_curtain.fill(linpg.Color.BLACK) + self.__up_black_curtain = linpg.load.movable_image( + black_curtain, (0, -black_curtain.get_height()), (0, 0), (0, int(black_curtain.get_height()*0.05)) ) - self.__down_black_curtain = linpg.load_movable_image( - black_curtain,(0,self.window_y),(0,self.window_y-black_curtain.get_height()),(0,black_curtain.get_height()*0.051) + self.__down_black_curtain = linpg.load.movable_image( + black_curtain, (0, self.window_y), + (0, int(self.window_y-black_curtain.get_height())), (0, int(black_curtain.get_height()*0.051)) ) """-----加载音效-----""" #行走的音效 -- 频道0 @@ -323,7 +322,7 @@ def updated_language(self, screen) -> None: self.selectMenuUI = SelectMenu() self.battleModeUiTxt = linpg.get_lang("Battle_UI") self.RoundSwitchUI = RoundSwitch(self.window_x,self.window_y,self.battleModeUiTxt) - self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.get_color_rbga("white")) + self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.Color.WHITE) self.end_round_button = linpg.load.static_image( r"Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), @@ -940,10 +939,10 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: for each_enemy in self.enemiesGetAttack: if self.enemiesGetAttack[each_enemy] == "near" and linpg.get_random_int(1,100) <= 95 or self.enemiesGetAttack[each_enemy] == "middle" and linpg.get_random_int(1,100) <= 80 or self.enemiesGetAttack[each_enemy] == "far" and linpg.get_random_int(1,100) <= 65: the_damage = self.characterInControl.attack(self.sangvisFerrisData[each_enemy]) - self.damage_do_to_characters[each_enemy] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.get_color_rbga("red")) + self.damage_do_to_characters[each_enemy] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.Color.RED) self.sangvisFerrisData[each_enemy].alert(100) else: - self.damage_do_to_characters[each_enemy] = self.FONT.render("Miss",linpg.get_antialias(),linpg.get_color_rbga("red")) + self.damage_do_to_characters[each_enemy] = self.FONT.render("Miss",linpg.get_antialias(),linpg.Color.RED) self.sangvisFerrisData[each_enemy].alert(50) elif self.characterInControl.get_imgId("attack") == self.characterInControl.get_imgNum("attack")-1: self.characterInControl.current_bullets -= 1 @@ -995,9 +994,9 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: if not self.griffinCharactersData[self.current_instruction.target].is_alive(): self.resultInfo["times_characters_down"] += 1 #重新计算迷雾区域 self._calculate_darkness() - self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.get_color_rbga("red")) + self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.Color.RED) else: - self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("Miss",linpg.get_antialias(),linpg.get_color_rbga("red")) + self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("Miss",linpg.get_antialias(),linpg.Color.RED) self.current_instruction = None else: self.enemyInControl.set_action() diff --git a/Source/scene.py b/Source/scene.py index 15f0dabe..18f65d76 100644 --- a/Source/scene.py +++ b/Source/scene.py @@ -12,7 +12,7 @@ def save_progress(self) -> None: linpg.save_config(os.path.join(self.folder_for_save_file,"global.yaml"),DataTmp) #对话系统 -def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> dict: +def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> None: #加载闸门动画的图片素材 LoadingImgAbove:linpg.ImageSurface = linpg.smoothly_resize_img( linpg.cope_bounding(linpg.load.img(r"Assets/image/UI/LoadingImgAbove.png")), (screen.get_width()+4, screen.get_height()/1.7) @@ -45,8 +45,6 @@ def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, DIALOG.draw(screen) ALPHA_BUILD_WARNING.draw(screen) linpg.display.flip() - #返回玩家做出的选项 - return DIALOG.dialog_options #对话编辑器 def dialogEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> None: diff --git a/main.py b/main.py index ba6a3e87..3026fe99 100644 --- a/main.py +++ b/main.py @@ -6,8 +6,7 @@ from Source.mainMenu import MainMenu, linpg #读取并整理配置文件 -folders = ['Lang/*.yaml','Data/*.yaml','Data/main_chapter/*.yaml'] -for folderPath in folders: +for folderPath in (r'Lang/*.yaml', r'Data/*.yaml', r'Data/main_chapter/*.yaml'): #pass linpg.organize_config_in_folder(folderPath) @@ -19,15 +18,21 @@ #创建窗口 screen = linpg.display.init() #窗口标题图标 - linpg.display.set_icon("Assets/image/UI/icon.png") - linpg.display.set_caption(linpg.get_lang('General','game_title')) + linpg.display.set_icon(r"Assets/image/UI/icon.png") + linpg.display.set_caption(linpg.get_lang('General', 'game_title')) #初始化选项菜单 - linpg.init_option_menu(screen.get_width()*0.25,screen.get_height()*0.15,screen.get_width()*0.5,screen.get_height()*0.7) + linpg.init_option_menu( + int(screen.get_width()*0.25), + int(screen.get_height()*0.15), + int(screen.get_width()*0.5), + int(screen.get_height()*0.7) + ) #主菜单模块 mainMenu = MainMenu(screen) #主循环 while mainMenu.is_playing(): mainMenu.draw(screen) linpg.display.flip() - #释放内容占用 - linpg.display.quit() + +#释放内容占用 +linpg.display.quit() From 2a86a3f911ccb969831936c927b82a7d79bebac5 Mon Sep 17 00:00:00 2001 From: yudonglin Date: Tue, 29 Jun 2021 18:11:56 -0700 Subject: [PATCH 3/4] continue to implement new API --- README.md | 4 ++ Source/base.py | 8 +-- Source/component.py | 10 ++-- Source/gamemode/editor.py | 37 +++++++------- Source/gamemode/survival.py | 10 ++-- Source/gamemode/turnBased.py | 82 +++++++++++++++--------------- Source/gamemode/ui.py | 25 ++++------ Source/mainMenu.py | 97 ++++++++++++++++++------------------ Source/scene.py | 18 +++---- main.py | 4 +- 10 files changed, 146 insertions(+), 149 deletions(-) diff --git a/README.md b/README.md index 834dfa85..8817bb29 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ +# GirlsFrontLine-LastWish 少女前线-遗愿 + [![Total alerts](https://img.shields.io/lgtm/alerts/g/Tigeia-Workshop/GirlsFrontLine-LastWish.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Tigeia-Workshop/GirlsFrontLine-LastWish/alerts/) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Tigeia-Workshop/GirlsFrontLine-LastWish.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Tigeia-Workshop/GirlsFrontLine-LastWish/context:python) ![GitHub all releases](https://img.shields.io/github/downloads/Tigeia-Workshop/GirlsFrontLine-LastWish/total) ![GitHub](https://img.shields.io/github/license/Tigeia-Workshop/GirlsFrontLine-LastWish) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/Tigeia-Workshop/GirlsFrontLine-LastWish?include_prereleases) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/linpg) + + # :speech_balloon: Preamble / 前言 Their stories may be forgotten by history, but what they have done will be remembered forever. diff --git a/Source/base.py b/Source/base.py index e5a185bd..ecbab542 100644 --- a/Source/base.py +++ b/Source/base.py @@ -7,7 +7,7 @@ #discord接口 RPC:object #如果不想要展示Discord的Rich Presence -if linpg.try_get_setting("DiscordRichPresence") is False: +if linpg.setting.try_get("DiscordRichPresence") is False: RPC = None else: #尝试连接Discord @@ -15,12 +15,12 @@ from pypresence import Presence RPC = Presence(str(CLIENT_ID)) RPC.connect() - RPC.update(state=linpg.get_lang("DiscordStatus","game_is_initializing"),large_image=LARGE_IMAGE) + RPC.update(state=linpg.lang.get_text("DiscordStatus","game_is_initializing"),large_image=LARGE_IMAGE) except Exception: RPC = None #加载版本信息 -version_info:dict = linpg.load_config("Data/version.yaml") +version_info:dict = linpg.config.load("Data/version.yaml") VERSION:int = version_info["version"] REVISION:int = version_info["revision"] PATCH:int = version_info["patch"] @@ -31,7 +31,7 @@ #alpha构建警告 ALPHA_BUILD_WARNING = linpg.TextSurface( - linpg.render_font(linpg.get_lang("alpha_build_warning"),"white",linpg.get_standard_font_size("medium")/2),0,0 + linpg.render_font(linpg.lang.get_text("alpha_build_warning"),"white",linpg.get_standard_font_size("medium")/2),0,0 ) ALPHA_BUILD_WARNING.set_centerx(linpg.display.get_width()/2) ALPHA_BUILD_WARNING.set_bottom(linpg.display.get_height()-ALPHA_BUILD_WARNING.get_height()) diff --git a/Source/component.py b/Source/component.py index 46953e2a..bd899f89 100644 --- a/Source/component.py +++ b/Source/component.py @@ -5,18 +5,18 @@ def dispaly_loading_screen(screen:linpg.ImageSurface, start:int, end:int, value:int) -> None: window_x,window_y = screen.get_size() #获取健康游戏忠告 - HealthyGamingAdvice = linpg.try_get_lang("HealthyGamingAdvice") + HealthyGamingAdvice = linpg.lang.try_to_get_text("HealthyGamingAdvice") if HealthyGamingAdvice == "HealthyGamingAdvice": HealthyGamingAdvice = [] else: for i in range(len(HealthyGamingAdvice)): HealthyGamingAdvice[i] = linpg.render_font(HealthyGamingAdvice[i],"white",window_x/64) #其他载入页面需要的数据 - text1 = linpg.render_font(linpg.get_lang("title1"), "white", window_x/64) - text2 = linpg.render_font(linpg.get_lang("title2"), "white", window_x/64) + text1 = linpg.render_font(linpg.lang.get_text("title1"), "white", window_x/64) + text2 = linpg.render_font(linpg.lang.get_text("title2"), "white", window_x/64) #主循环 for i in range(start,end,value): - screen.fill(linpg.Color.BLACK) + screen.fill(linpg.color.BLACK) text1.set_alpha(i) text2.set_alpha(i) screen.blits(((text1,(window_x/64,window_y*0.9)),(text2,(window_x/64,window_y*0.9-window_x/32)))) @@ -34,7 +34,7 @@ def _check_command(self, conditions:list) -> None: elif conditions[1] == "battle": battle(linpg.display.screen_window, conditions[2], conditions[3], conditions[4]) else: - self.txtOutput.append("Error, do not know what to load.") + self._txt_output.append("Error, do not know what to load.") else: super()._check_command(conditions) diff --git a/Source/gamemode/editor.py b/Source/gamemode/editor.py index a4890067..b05518d0 100644 --- a/Source/gamemode/editor.py +++ b/Source/gamemode/editor.py @@ -1,5 +1,4 @@ # cython: language_level=3 -import os from .ui import * #地图编辑器系统 @@ -18,9 +17,9 @@ def __load_characters_data(self, mapFileData:dict) -> None: def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projectName:str=None) -> None: self._initialize(chapterType, chapterId, projectName) self.folder_for_save_file,self.name_for_save_file = os.path.split(self.get_map_file_location()) - self.decorations_setting = linpg.load_config("Data/decorations.yaml","decorations") + self.decorations_setting = linpg.config.load("Data/decorations.yaml","decorations") #载入地图数据 - mapFileData:dict = linpg.load_config(self.get_map_file_location()) + mapFileData:dict = linpg.config.load(self.get_map_file_location()) #初始化角色信息 self.__load_characters_data(mapFileData) #初始化地图 @@ -31,7 +30,7 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec block_x = 50 default_map = [[SnowEnvImg[linpg.get_random_int(0,5)] for a in range(block_x)] for i in range(block_y)] mapFileData["map"] = default_map - linpg.save_config(self.get_map_file_location(),mapFileData) + linpg.config.save(self.get_map_file_location(),mapFileData) #加载地图 self._create_map(mapFileData) del mapFileData @@ -44,10 +43,10 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec panding:int = int(screen.get_height()*0.01) font_size:int = int(button_width/3) self.__button_select_block = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png",linpg.get_lang("MapEditor","block"),"black",font_size,(0,screen.get_width()*0.03),100 + "Assets/image/UI/menu.png",linpg.lang.get_text("MapEditor","block"),"black",font_size,(0,screen.get_width()*0.03),100 ) self.__button_select_decoration = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png",linpg.get_lang("MapEditor","decoration"),"black",font_size,(0,screen.get_width()*0.03),100 + "Assets/image/UI/menu.png",linpg.lang.get_text("MapEditor","decoration"),"black",font_size,(0,screen.get_width()*0.03),100 ) self.__button_select_block.set_left( int((container_width-self.__button_select_block.get_width()-self.__button_select_decoration.get_width()-panding)/2) @@ -90,10 +89,10 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec panding = int(screen.get_height()*0.01) font_size = int(button_height/2) self.__button_select_character = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png",linpg.get_lang("General","griffin_Kryuger"),"black",font_size,(0,0),100 + "Assets/image/UI/menu.png",linpg.lang.get_text("General","griffin_Kryuger"),"black",font_size,(0,0),100 ) self.__button_select_sangvisFerri = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png",linpg.get_lang("General","sangvis_ferri"),"black",font_size,(self.__button_select_character.get_width(),0),100 + "Assets/image/UI/menu.png",linpg.lang.get_text("General","sangvis_ferri"),"black",font_size,(self.__button_select_character.get_width(),0),100 ) self.__UIContainerBottom = linpg.load.dynamic_image(r"Assets/image/UI/container.png", (0,0), (container_width,container_height)) self.__UIContainerButtonBottom = linpg.load.movable_image( @@ -141,19 +140,19 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec UI_y = int(screen.get_height()*0.02) font_size = int(self.MAP.block_width*0.2) self.UIButton["save"] = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png", linpg.get_lang("Global", "save"), "black", font_size, (UI_x, UI_y), 100 + "Assets/image/UI/menu.png", linpg.lang.get_text("Global", "save"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["save"].get_width()+font_size self.UIButton["back"] = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png", linpg.get_lang("Global", "back"), "black", font_size, (UI_x, UI_y), 100 + "Assets/image/UI/menu.png", linpg.lang.get_text("Global", "back"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["back"].get_width()+font_size self.UIButton["delete"] = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png", linpg.get_lang("Global", "delete"), "black", font_size, (UI_x, UI_y), 100 + "Assets/image/UI/menu.png", linpg.lang.get_text("Global", "delete"), "black", font_size, (UI_x, UI_y), 100 ) UI_x += self.UIButton["delete"].get_width()+font_size self.UIButton["reload"] = linpg.load.button_with_text_in_center( - "Assets/image/UI/menu.png", linpg.get_lang("Global", "reload_file"), "black", font_size, (UI_x, UI_y), 100 + "Assets/image/UI/menu.png", linpg.lang.get_text("Global", "reload_file"), "black", font_size, (UI_x, UI_y), 100 ) #其他函数 self.UI_local_x = 0 @@ -163,19 +162,19 @@ def load(self, screen:linpg.ImageSurface, chapterType:str, chapterId:int, projec #用于储存即将发下的物品的具体参数 self.data_to_edit = None #读取地图原始文件 - self.originalData = linpg.load_config(self.get_map_file_location()) + self.originalData = linpg.config.load(self.get_map_file_location()) #将地图制作器的界面画到屏幕上 def draw(self, screen:linpg.ImageSurface) -> None: mouse_x,mouse_y = linpg.controller.get_mouse_pos() block_get_click = self.MAP.calBlockInMap(mouse_x,mouse_y) for event in linpg.controller.events: - if event.type == linpg.KEY.DOWN: - if event.key == linpg.KEY.ESCAPE: + if event.type == linpg.key.DOWN: + if event.key == linpg.key.ESCAPE: self.object_to_put_down = None self.data_to_edit = None self.deleteMode = False self._check_key_down(event) - elif event.type == linpg.KEY.UP: + elif event.type == linpg.key.UP: self._check_key_up(event) elif event.type == linpg.MOUSE_BUTTON_DOWN: #上下滚轮-放大和缩小地图 @@ -207,7 +206,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: elif linpg.is_hover(self.UIButton["save"]) and self.object_to_put_down is None and not self.deleteMode: self.save_progress() elif linpg.is_hover(self.UIButton["back"]) and self.object_to_put_down is None and not self.deleteMode: - if linpg.load_config(self.get_map_file_location()) == self.originalData: + if linpg.config.load(self.get_map_file_location()) == self.originalData: self.stop() break else: @@ -219,7 +218,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: elif linpg.is_hover(self.UIButton["reload"]) and self.object_to_put_down is None and not self.deleteMode: tempLocal_x,tempLocal_y = self.MAP.get_local_pos() #读取地图数据 - mapFileData = linpg.load_config(self.get_map_file_location()) + mapFileData = linpg.config.load(self.get_map_file_location()) #初始化角色信息 self.__load_characters_data(mapFileData) #加载地图 @@ -227,7 +226,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: del mapFileData self.MAP.setPos(tempLocal_x,tempLocal_y) #读取地图 - self.originalData = linpg.load_config(self.get_map_file_location()) + self.originalData = linpg.config.load(self.get_map_file_location()) else: if linpg.controller.get_event("confirm") and block_get_click is not None and self.object_to_put_down is not None and\ not linpg.is_hover(self.__UIContainerRight,off_set_x=self.__UIContainerButtonRight.right) and\ diff --git a/Source/gamemode/survival.py b/Source/gamemode/survival.py index 5cfef4c0..51afe648 100644 --- a/Source/gamemode/survival.py +++ b/Source/gamemode/survival.py @@ -25,7 +25,7 @@ def __init__(self): } """init""" #shutil.copyfile("Data/chapter_map_example.yaml","Save/map1.yaml") - mapFileData = linpg.load_config("Save/map1.yaml") + mapFileData = linpg.config.load("Save/map1.yaml") SnowEnvImg = ["TileSnow01","TileSnow01ToStone01","TileSnow01ToStone02","TileSnow02","TileSnow02ToStone01","TileSnow02ToStone02"] block_y = 50 block_x = 50 @@ -94,11 +94,11 @@ def _display_decoration(self, screen:linpg.ImageSurface) -> None: self.MAP.displ #把所有内容画到屏幕上 def draw(self, screen:linpg.ImageSurface) -> None: for event in linpg.controller.events: - if event.type == linpg.KEY.DOWN: - if event.key == linpg.KEY.ESCAPE: + if event.type == linpg.key.DOWN: + if event.key == linpg.key.ESCAPE: self.stop() self._check_key_down(event) - elif event.type == linpg.KEY.UP: + elif event.type == linpg.key.UP: self._check_key_up(event) #其他移动的检查 self._check_right_click_move() @@ -110,5 +110,5 @@ def draw(self, screen:linpg.ImageSurface) -> None: self._display_decoration(screen) pos_x,pos_y = self.MAP.calPosInMap(self.alliances["me"].x,self.alliances["me"].y) pos_x += linpg.display.get_width()/20 - #pygame.draw.line(screen,linpg.Color.RED,(pos_x,pos_y),(mouse_x,mouse_y),5) + #pygame.draw.line(screen,linpg.color.RED,(pos_x,pos_y),(mouse_x,mouse_y),5) linpg.display.flip() \ No newline at end of file diff --git a/Source/gamemode/turnBased.py b/Source/gamemode/turnBased.py index ea8ee350..3026dae0 100644 --- a/Source/gamemode/turnBased.py +++ b/Source/gamemode/turnBased.py @@ -73,7 +73,7 @@ def enemyInControl(self) -> object: return self.enemies_data[self.sangvisFerris_ """加载与储存""" #从存档中加载游戏进程 def load(self, screen:linpg.ImageSurface) -> None: - DataTmp = linpg.load_config("Save/save.yaml") + DataTmp = linpg.config.load("Save/save.yaml") if DataTmp["type"] == "battle": self._initialize(DataTmp["chapter_type"], DataTmp["chapter_id"], DataTmp["project_name"]) self._initial_characters_loader(DataTmp["griffin"],DataTmp["sangvisFerri"]) @@ -101,15 +101,15 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.FONT = linpg.create_font(self.FONTSIZE) #加载按钮的文字 self.selectMenuUI = SelectMenu() - self.battleModeUiTxt = linpg.get_lang("Battle_UI") + self.battleModeUiTxt = linpg.lang.get_text("Battle_UI") self.warnings_to_display = WarningSystem(int(screen.get_height()*0.03)) - loading_info = linpg.get_lang("LoadingTxt") + loading_info = linpg.lang.get_text("LoadingTxt") #加载剧情 - DataTmp = linpg.load_config(self._DIALOG.get_dialog_file_location()) + DataTmp = linpg.config.load(self._DIALOG.get_dialog_file_location()) #如果暂时没有翻译 - if "title" not in DataTmp: DataTmp["title"] = linpg.get_lang("Global", "no_translation") - if "description" not in DataTmp: DataTmp["description"] = linpg.get_lang("Global", "no_translation") - if "battle_info" not in DataTmp: DataTmp["battle_info"] = linpg.load_config(r"Data/chapter_dialogs_example.yaml", "battle_info") + if "title" not in DataTmp: DataTmp["title"] = linpg.lang.get_text("Global", "no_translation") + if "description" not in DataTmp: DataTmp["description"] = linpg.lang.get_text("Global", "no_translation") + if "battle_info" not in DataTmp: DataTmp["battle_info"] = linpg.config.load(r"Data/chapter_dialogs_example.yaml", "battle_info") #章节标题显示 self.infoToDisplayDuringLoading = LoadingTitle( self.window_x, @@ -130,12 +130,12 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: linpg.display.flip() #开始加载地图场景 self.infoToDisplayDuringLoading.draw(screen) - now_loading = self.FONT.render(loading_info["now_loading_map"],linpg.get_antialias(),(255,255,255)) + now_loading = self.FONT.render(loading_info["now_loading_map"],linpg.setting.antialias,(255,255,255)) screen.blit(now_loading,(self.window_x*0.75,self.window_y*0.9)) nowLoadingIcon.draw(screen) linpg.display.flip() #读取并初始化章节信息 - DataTmp = linpg.load_config(self.get_map_file_location()) + DataTmp = linpg.config.load(self.get_map_file_location()) #背景音乐路径 self._background_music_folder_path:str = "Assets/music" #设置背景音乐 @@ -165,7 +165,7 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self._start_characters_loader() while self._is_characters_loader_alive(): self.infoToDisplayDuringLoading.draw(screen) - now_loading = self.FONT.render(loading_info["now_loading_characters"]+"({}/{})".format(self.characters_loaded,self.characters_total),linpg.get_antialias(),(255,255,255)) + now_loading = self.FONT.render(loading_info["now_loading_characters"]+"({}/{})".format(self.characters_loaded,self.characters_total),linpg.setting.antialias,(255,255,255)) screen.blit(now_loading,(self.window_x*0.75,self.window_y*0.9)) nowLoadingIcon.draw(screen) linpg.display.flip() @@ -173,13 +173,13 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self._calculate_darkness() #开始加载关卡设定 self.infoToDisplayDuringLoading.draw(screen) - now_loading = self.FONT.render(loading_info["now_loading_level"],linpg.get_antialias(),linpg.Color.WHITE) + now_loading = self.FONT.render(loading_info["now_loading_level"],linpg.setting.antialias,linpg.color.WHITE) screen.blit(now_loading,(self.window_x*0.75,self.window_y*0.9)) nowLoadingIcon.draw(screen) linpg.display.flip() #加载UI: #加载结束回合的图片 - self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.Color.WHITE) + self.end_round_txt = self.FONT.render(linpg.lang.get_text("Battle_UI","endRound"),linpg.setting.antialias,linpg.color.WHITE) self.end_round_button = linpg.load.static_image( "Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), @@ -212,9 +212,9 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.characterInfoBoardUI = CharacterInfoBoard(self.window_x,self.window_y) #加载用于渲染电影效果的上下黑色帘幕 black_curtain = linpg.new_surface((self.window_x,self.window_y*0.15)).convert() - black_curtain.fill(linpg.Color.BLACK) + black_curtain.fill(linpg.color.BLACK) self.__up_black_curtain = linpg.load.movable_image( - black_curtain, (0, -black_curtain.get_height()), (0, 0), (0, int(black_curtain.get_height()*0.05)) + black_curtain, (0, -black_curtain.get_height()), linpg.Origin, (0, int(black_curtain.get_height()*0.05)) ) self.__down_black_curtain = linpg.load.movable_image( black_curtain, (0, self.window_y), @@ -228,12 +228,12 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: #更新所有音效的音量 self.__update_sound_volume() #攻击的音效 -- 频道2 - self.attackingSounds = linpg.AttackingSoundManager(linpg.get_setting("Sound","sound_effects"),2) + self.attackingSounds = linpg.AttackingSoundManager(linpg.setting.get("Sound","sound_effects"),2) #切换回合时的UI self.RoundSwitchUI = RoundSwitch(self.window_x,self.window_y,self.battleModeUiTxt) #关卡背景介绍信息文字 for i in range(len(self.battleMode_info)): - self.battleMode_info[i] = self.FONT.render(self.battleMode_info[i],linpg.get_antialias(),(255,255,255)) + self.battleMode_info[i] = self.FONT.render(self.battleMode_info[i],linpg.setting.antialias,(255,255,255)) #显示章节信息 for a in range(0,250,2): self.infoToDisplayDuringLoading.draw(screen) @@ -241,7 +241,7 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.battleMode_info[i].set_alpha(a) screen.blit(self.battleMode_info[i],(self.window_x/20,self.window_y*0.75+self.battleMode_info[i].get_height()*1.2*i)) if i == 1: - temp_secode = self.FONT.render(time.strftime(":%S", time.localtime()),linpg.get_antialias(),(255,255,255)) + temp_secode = self.FONT.render(time.strftime(":%S", time.localtime()),linpg.setting.antialias,(255,255,255)) temp_secode.set_alpha(a) screen.blit(temp_secode,(self.window_x/20+self.battleMode_info[i].get_width(),self.window_y*0.75+self.battleMode_info[i].get_height()*1.2)) linpg.display.flip() @@ -260,7 +260,7 @@ def _get_data_need_to_save(self) -> dict: return linpg.merge_dict( ) """画面""" #新增需要在屏幕上画出的物品 - def __add_on_screen_object(self, image:linpg.ImageSurface, weight:int=-1, pos:Union[tuple,list]=(0,0), offSet:Union[tuple,list]=(0,0)) -> None: + def __add_on_screen_object(self, image:linpg.ImageSurface, weight:int=-1, pos:linpg.pos_liked=linpg.Origin, offSet:linpg.pos_liked=linpg.Origin) -> None: if weight < 0: self.__max_item_weight += 1 weight = self.__max_item_weight @@ -312,17 +312,17 @@ def __check_whether_player_win_or_lost(self) -> None: if not find_one: self.whose_round = "result_win" #更新音量 def __update_sound_volume(self) -> None: - self.footstep_sounds.set_volume(linpg.get_setting("Sound","sound_effects")/100) - self.environment_sound.set_volume(linpg.get_setting("Sound","sound_environment")/100.0) - self.set_bgm_volume(linpg.get_setting("Sound","background_music")/100.0) + self.footstep_sounds.set_volume(linpg.setting.get("Sound","sound_effects")/100) + self.environment_sound.set_volume(linpg.setting.get("Sound","sound_environment")/100.0) + self.set_bgm_volume(linpg.setting.get("Sound","background_music")/100.0) #更新语言 def updated_language(self, screen) -> None: super().updated_language() self.pause_menu.initialize(screen) self.selectMenuUI = SelectMenu() - self.battleModeUiTxt = linpg.get_lang("Battle_UI") + self.battleModeUiTxt = linpg.lang.get_text("Battle_UI") self.RoundSwitchUI = RoundSwitch(self.window_x,self.window_y,self.battleModeUiTxt) - self.end_round_txt = self.FONT.render(linpg.get_lang("Battle_UI","endRound"),linpg.get_antialias(),linpg.Color.WHITE) + self.end_round_txt = self.FONT.render(linpg.lang.get_text("Battle_UI","endRound"),linpg.setting.antialias,linpg.color.WHITE) self.end_round_button = linpg.load.static_image( r"Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), @@ -565,17 +565,17 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: mouse_x,mouse_y = linpg.controller.get_mouse_pos() skill_range = None for event in linpg.controller.events: - if event.type == linpg.KEY.DOWN: - if event.key == linpg.KEY.ESCAPE and self.characterGetClick is None: + if event.type == linpg.key.DOWN: + if event.key == linpg.key.ESCAPE and self.characterGetClick is None: self.pause_menu.hidden = False - if event.key == linpg.KEY.ESCAPE and self.__is_waiting is True: + if event.key == linpg.key.ESCAPE and self.__is_waiting is True: self.__if_draw_range = True self.characterGetClick = None self.action_choice = None skill_range = None self.reset_areaDrawColorBlock() self._check_key_down(event) - elif event.type == linpg.KEY.UP: + elif event.type == linpg.key.UP: self._check_key_up(event) #鼠标点击 elif event.type == linpg.MOUSE_BUTTON_DOWN: @@ -743,7 +743,7 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: #显示路径 self.areaDrawColorBlock["green"] = self.the_route xTemp,yTemp = self.MAP.calPosInMap(self.the_route[-1][0],self.the_route[-1][1]) - screen.blit(self.FONT.render(str(len(self.the_route)*2),linpg.get_antialias(),(255,255,255)),(xTemp+self.FONTSIZE*2,yTemp+self.FONTSIZE)) + screen.blit(self.FONT.render(str(len(self.the_route)*2),linpg.setting.antialias,(255,255,255)),(xTemp+self.FONTSIZE*2,yTemp+self.FONTSIZE)) self.characterInControl.draw_custom("move",(xTemp,yTemp),screen,self.MAP) #显示攻击范围 elif self.action_choice == "attack": @@ -902,10 +902,10 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: for itemType,itemData in decoration.items.items(): if itemType == "bullet": self.characterInControl.bullets_carried += itemData - self.supply_board.items.append(self.FONT.render(self.battleModeUiTxt["getBullets"]+": "+str(itemData),linpg.get_antialias(),(255,255,255))) + self.supply_board.items.append(self.FONT.render(self.battleModeUiTxt["getBullets"]+": "+str(itemData),linpg.setting.antialias,(255,255,255))) elif itemType == "hp": self.characterInControl.heal(itemData) - self.supply_board.items.append(self.FONT.render(self.battleModeUiTxt["getHealth"]+": "+str(itemData),linpg.get_antialias(),(255,255,255))) + self.supply_board.items.append(self.FONT.render(self.battleModeUiTxt["getHealth"]+": "+str(itemData),linpg.setting.antialias,(255,255,255))) #如果UI已经回到原位 if len(self.supply_board.items) > 0: self.supply_board.move_toward() #移除箱子 @@ -939,10 +939,10 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: for each_enemy in self.enemiesGetAttack: if self.enemiesGetAttack[each_enemy] == "near" and linpg.get_random_int(1,100) <= 95 or self.enemiesGetAttack[each_enemy] == "middle" and linpg.get_random_int(1,100) <= 80 or self.enemiesGetAttack[each_enemy] == "far" and linpg.get_random_int(1,100) <= 65: the_damage = self.characterInControl.attack(self.sangvisFerrisData[each_enemy]) - self.damage_do_to_characters[each_enemy] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.Color.RED) + self.damage_do_to_characters[each_enemy] = self.FONT.render("-"+str(the_damage),linpg.setting.antialias,linpg.color.RED) self.sangvisFerrisData[each_enemy].alert(100) else: - self.damage_do_to_characters[each_enemy] = self.FONT.render("Miss",linpg.get_antialias(),linpg.Color.RED) + self.damage_do_to_characters[each_enemy] = self.FONT.render("Miss",linpg.setting.antialias,linpg.color.RED) self.sangvisFerrisData[each_enemy].alert(50) elif self.characterInControl.get_imgId("attack") == self.characterInControl.get_imgNum("attack")-1: self.characterInControl.current_bullets -= 1 @@ -994,9 +994,9 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: if not self.griffinCharactersData[self.current_instruction.target].is_alive(): self.resultInfo["times_characters_down"] += 1 #重新计算迷雾区域 self._calculate_darkness() - self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("-"+str(the_damage),linpg.get_antialias(),linpg.Color.RED) + self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("-"+str(the_damage),linpg.setting.antialias,linpg.color.RED) else: - self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("Miss",linpg.get_antialias(),linpg.Color.RED) + self.damage_do_to_characters[self.current_instruction.target] = self.FONT.render("Miss",linpg.setting.antialias,linpg.color.RED) self.current_instruction = None else: self.enemyInControl.set_action() @@ -1153,8 +1153,8 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: self.resultInfo["total_time"] = time.localtime(time.time()-self.resultInfo["total_time"]) self.ResultBoardUI = ResultBoard(self.resultInfo,self.window_x/96) for event in linpg.controller.events: - if event.type == linpg.KEY.DOWN: - if event.key == linpg.KEY.SPACE: + if event.type == linpg.key.DOWN: + if event.key == linpg.key.SPACE: self.__is_battle_mode = False self.stop() self.__add_on_screen_object(self.ResultBoardUI) @@ -1164,14 +1164,14 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: self.resultInfo["total_time"] = time.localtime(time.time()-self.resultInfo["total_time"]) self.ResultBoardUI = ResultBoard(self.resultInfo,self.window_x/96,False) for event in linpg.controller.events: - if event.type == linpg.KEY.DOWN: - if event.key == linpg.KEY.SPACE: + if event.type == linpg.key.DOWN: + if event.key == linpg.key.SPACE: linpg.unload_all_music() chapter_info:dict = self.get_data_of_parent_game_system() self.__init__() self.new(screen,chapter_info["chapter_type"], chapter_info["chapter_id"], chapter_info["project_name"]) break - elif event.key == linpg.KEY.BACKSPACE: + elif event.key == linpg.key.BACKSPACE: linpg.unload_all_music() self.stop() self.__is_battle_mode = False @@ -1214,7 +1214,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: self.battleMode_info[i].set_alpha(self.txt_alpha) screen.blit(self.battleMode_info[i],(self.window_x/20,self.window_y*0.75+self.battleMode_info[i].get_height()*1.2*i)) if i == 1: - temp_secode = self.FONT.render(time.strftime(":%S", time.localtime()),linpg.get_antialias(),(255,255,255)) + temp_secode = self.FONT.render(time.strftime(":%S", time.localtime()),linpg.setting.antialias,(255,255,255)) temp_secode.set_alpha(self.txt_alpha) screen.blit(temp_secode,(self.window_x/20+self.battleMode_info[i].get_width(),self.window_y*0.75+self.battleMode_info[i].get_height()*1.2)) self.txt_alpha -= 5 @@ -1223,7 +1223,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: #展示暂停菜单 if not self.pause_menu.hidden: progress_saved_text = linpg.load.static_image( - self.FONT.render(linpg.get_lang("Global","progress_has_been_saved"),linpg.get_antialias(),(255,255,255)), + self.FONT.render(linpg.lang.get_text("Global","progress_has_been_saved"),linpg.setting.antialias,(255,255,255)), (0,0) ) progress_saved_text.set_alpha(0) diff --git a/Source/gamemode/ui.py b/Source/gamemode/ui.py index c061b739..258b9c84 100644 --- a/Source/gamemode/ui.py +++ b/Source/gamemode/ui.py @@ -1,12 +1,10 @@ # cython: language_level=3 -# python本体库 import glob import time -from typing import Union -# 第三方 +import os +from collections import deque #import linpg from linpgdev import linpg -from collections import deque # 显示回合切换的UI class RoundSwitch: @@ -32,7 +30,7 @@ def __init__(self, window_x:int, window_y:int, battleUiTxt:dict): def draw(self, screen:linpg.ImageSurface, whose_round:str, total_rounds:int) -> bool: #如果“第N回合”的文字surface还没有初始化,则初始化该文字 if self.now_total_rounds_surface is None: - self.now_total_rounds_surface = linpg.render_font(self.now_total_rounds_text.format(linpg.get_num_in_local_text(total_rounds)), "white",screen.get_width()/38) + self.now_total_rounds_surface = linpg.render_font(self.now_total_rounds_text.format(linpg.lang.get_num_in_local_text(total_rounds)), "white",screen.get_width()/38) self.now_total_rounds_surface.set_alpha(0) #如果UI底的alpha值在渐入阶段 if self.baseAlphaUp: @@ -122,7 +120,7 @@ def draw(self, screen:linpg.ImageSurface, whose_round:str, total_rounds:int) -> class WarningSystem: def __init__(self, font_size:int=30): self.__all_warnings:deque = deque() - self.__warnings_msg:dict = linpg.get_lang("Warnings") + self.__warnings_msg:dict = linpg.lang.get_text("Warnings") self.font_size:int = font_size #新增一个讯息 def add(self, the_warning:str) -> None: @@ -147,7 +145,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: #角色行动选项菜单 class SelectMenu: def __init__(self): - selectMenuTxtDic:dict = linpg.get_lang("SelectMenu") + selectMenuTxtDic:dict = linpg.lang.get_text("SelectMenu") self.selectButtonImg = linpg.load.img("Assets/image/UI/menu.png") #攻击 self.attackAP = linpg.AP_IS_NEEDED_TO_ATTACK @@ -176,7 +174,7 @@ def __init__(self): #所有按钮 self.allButton = None #初始化按钮 - def initialButtons(self, fontSize:Union[int,float]) -> None: + def initialButtons(self, fontSize:linpg.int_f) -> None: selectButtonBase = linpg.resize_img(self.selectButtonImg, (round(fontSize*5), round(fontSize*2.6))) selectButtonBaseWidth = selectButtonBase.get_width() sizeBig = int(fontSize) @@ -220,7 +218,7 @@ def initialButtons(self, fontSize:Union[int,float]) -> None: self.allButton["interact"].blit(txt_temp,((selectButtonBaseWidth-txt_temp.get_width())/2,txt_temp.get_height()*0.15)) self.allButton["interact"].blit(txt_temp2,((selectButtonBaseWidth-txt_temp2.get_width())/2,txt_temp.get_height()*1.1)) #将菜单按钮画出 - def draw(self, screen:linpg.ImageSurface, fontSize:Union[int,float], location:dict, kind:str, friendsCanSave:list, thingsCanReact:list) -> str: + def draw(self, screen:linpg.ImageSurface, fontSize:linpg.int_f, location:dict, kind:str, friendsCanSave:list, thingsCanReact:list) -> str: #如果按钮没有初始化,则应该立刻初始化按钮 if self.allButton is None: self.initialButtons(fontSize) buttonGetHover:str = "" @@ -271,11 +269,8 @@ class CharacterInfoBoard: def __init__(self, window_x:int, window_y:int, text_size:int=20): self.boardImg = linpg.load.img("Assets/image/UI/score.png",(window_x/5,window_y/6)) self.characterIconImages = {} - all_icon_file_list = glob.glob(r'Assets/image/npc_icon/*.png') - for i in range(len(all_icon_file_list)): - img_name = all_icon_file_list[i].replace("Assets","").replace("image","").replace("npc_icon","").replace(".png","").replace("\\","").replace("/","") - self.characterIconImages[img_name] = linpg.smoothly_resize_img(linpg.load.img(all_icon_file_list[i]),(window_y*0.08,window_y*0.08)) - del all_icon_file_list + for img_path in glob.glob(r'Assets/image/npc_icon/*.png'): + self.characterIconImages[os.path.basename(img_path).replace(".png","")] = linpg.smoothly_resize_img(linpg.load.img(img_path),(window_y*0.08,window_y*0.08)) self.text_size = text_size self.informationBoard = None hp_empty_img = linpg.load.img("Assets/image/UI/hp_empty.png") @@ -332,7 +327,7 @@ def draw(self, screen:linpg.ImageSurface, theCharacterData:object) -> None: #计分板 class ResultBoard: def __init__(self, finalResult:dict, font_size:int, is_win:bool=True): - resultTxt:dict = linpg.get_lang("ResultBoard") + resultTxt:dict = linpg.lang.get_text("ResultBoard") self.x = int(font_size*10) self.y = int(font_size*10) self.txt_x = int(font_size*12) diff --git a/Source/mainMenu.py b/Source/mainMenu.py index befc7141..63bf5456 100644 --- a/Source/mainMenu.py +++ b/Source/mainMenu.py @@ -26,8 +26,8 @@ def __init__(self, screen:linpg.ImageSurface): #关卡选择的封面 self.__cover_img_surface = None #音效 - self.click_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_click_button.ogg",linpg.get_setting("Sound","sound_effects")/100.0) - self.hover_on_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_hover_on_button.ogg",linpg.get_setting("Sound","sound_effects")/100.0) + self.click_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_click_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) + self.hover_on_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_hover_on_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) self.hover_sound_play_on = None self.last_hover_sound_play_on = None #加载主菜单背景 @@ -36,14 +36,14 @@ def __init__(self, screen:linpg.ImageSurface): screen.get_width(),screen.get_height(), True,True, (32,103), - linpg.get_setting("Sound","background_music")/100.0 + linpg.setting.get("Sound","background_music")/100.0 ) #初始化返回菜单判定参数 linpg.global_value.set("BackToMainMenu",False) #载入页面 - 渐出 dispaly_loading_screen(screen,250,0,int(-2*linpg.display.sfpsp)) #设置Discord状态 - if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) + if RPC is not None: RPC.update(state=linpg.lang.get_text("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #当前在Data/workshop文件夹中可以读取的文件夹的名字(font的形式) def __reload_workshop_files_list(self, screen_size:tuple, createMode:bool=False) -> None: self.workshop_files.clear() @@ -52,36 +52,38 @@ def __reload_workshop_files_list(self, screen_size:tuple, createMode:bool=False) if createMode: self.workshop_files.append(self.main_menu_txt["other"]["new_project"]) for path in glob.glob(r"Data/workshop/*"): try: - info_data = linpg.load_config(os.path.join(path,"info.yaml")) + info_data = linpg.config.load(os.path.join(path,"info.yaml")) except Exception: - info_data = linpg.load_config(r"Data/info_example.yaml") - info_data["default_lang"] = linpg.get_setting("Language") - linpg.save_config(os.path.join(path,"info.yaml"),info_data) + info_data = linpg.config.load(r"Data/info_example.yaml") + info_data["default_lang"] = linpg.setting.get("Language") + linpg.config.save(os.path.join(path,"info.yaml"),info_data) self.workshop_files_text.append(os.path.basename(path)) - self.workshop_files.append(info_data["title"][linpg.get_setting("Language")]) - self.workshop_files.append(linpg.get_lang("Global","back")) + self.workshop_files.append(info_data["title"][linpg.setting.get("Language")]) + self.workshop_files.append(linpg.lang.get_text("Global","back")) txt_location:int = int(screen_size[0]*2/3) txt_y:int = int((screen_size[1]-len(self.workshop_files)*linpg.get_standard_font_size("medium")*2)/2) for i in range(len(self.workshop_files)): - self.workshop_files[i] = linpg.load_dynamic_text(self.workshop_files[i],"enable",(txt_location,txt_y),linpg.get_standard_font_size("medium")) + self.workshop_files[i] = linpg.load_dynamic_text( + self.workshop_files[i], linpg.color.WHITE, (txt_location,txt_y), linpg.get_standard_font_size("medium") + ) txt_y += linpg.get_standard_font_size("medium")*2 #获取章节id def __get_chapter_title(self, chapterType:str, chapterId:int) -> str: #生成dialog文件的路径 dialog_file_path:str = os.path.join( - "Data", chapterType, "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.get_setting("Language")) + "Data", chapterType, "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) ) if chapterType == "main_chapter" else os.path.join( "Data", chapterType, self.current_selected_workshop_project, - "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.get_setting("Language")) + "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) ) chapter_title:str if os.path.exists(dialog_file_path): - dialog_data = linpg.load_config(dialog_file_path) + dialog_data = linpg.config.load(dialog_file_path) #如果dialog文件中有title,则读取 - chapter_title = dialog_data["title"] if "title" in dialog_data else linpg.get_lang("Global","no_translation") + chapter_title = dialog_data["title"] if "title" in dialog_data else linpg.lang.get_text("Global","no_translation") else: - chapter_title = linpg.get_lang("Global","no_translation") - return "{0}: {1}".format(linpg.get_lang("Battle_UI", "numChapter").format(linpg.get_num_in_local_text(chapterId)), chapter_title) + chapter_title = linpg.lang.get_text("Global","no_translation") + return "{0}: {1}".format(linpg.lang.get_text("Battle_UI", "numChapter").format(linpg.lang.get_num_in_local_text(chapterId)), chapter_title) #重新加载章节选择菜单的选项 def __reload_chapter_select_list(self, screen_size:tuple, chapterType:str="main_chapter", createMode:bool=False) -> None: self.chapter_select.clear() @@ -93,19 +95,14 @@ def __reload_chapter_select_list(self, screen_size:tuple, chapterType:str="main_ else os.path.join("Data",chapterType,self.current_selected_workshop_project,"*_map.yaml") ): self.chapter_select.append(self.__get_chapter_title(chapterType,self.__find_chapter_id(path))) #将返回按钮放到菜单列表中 - self.chapter_select.append(linpg.get_lang("Global","back")) + self.chapter_select.append(linpg.lang.get_text("Global","back")) txt_y:int = int((screen_size[1]-len(self.chapter_select)*linpg.get_standard_font_size("medium")*2)/2) txt_x:int = int(screen_size[0]*2/3) #将菜单列表中的文字转换成文字surface for i in range(len(self.chapter_select)): - """ - if chapter is unlocked or this is back button: - mode = "enable" - else: - mode = "disable" - """ - mode = "enable" - self.chapter_select[i] = linpg.load_dynamic_text(self.chapter_select[i],mode,(txt_x,txt_y),linpg.get_standard_font_size("medium")) + self.chapter_select[i] = linpg.load_dynamic_text( + self.chapter_select[i], linpg.color.WHITE, (txt_x,txt_y), linpg.get_standard_font_size("medium") + ) txt_y += linpg.get_standard_font_size("medium")*2 #画出文字按钮 def __draw_buttons(self, screen:linpg.ImageSurface) -> None: @@ -159,20 +156,20 @@ def __create_new_project(self) -> None: #创建文件夹 os.makedirs(os.path.join("Data","workshop",fileName)) #储存数据 - info_data:dict = linpg.load_config(r"Data/info_example.yaml") - info_data["default_lang"] = linpg.get_setting("Language") - linpg.save_config(os.path.join("Data","workshop",fileName,"info.yaml"),info_data) + info_data:dict = linpg.config.load(r"Data/info_example.yaml") + info_data["default_lang"] = linpg.setting.get("Language") + linpg.config.save(os.path.join("Data","workshop",fileName,"info.yaml"),info_data) #创建新的对话文和地图文件 def __create_new_chapter(self) -> None: chapterId:int = len(glob.glob(os.path.join( - "Data", "workshop", self.current_selected_workshop_project, "*_dialogs_{}.yaml".format(linpg.get_setting("Language")) + "Data", "workshop", self.current_selected_workshop_project, "*_dialogs_{}.yaml".format(linpg.setting.get("Language")) ))) + 1 #复制视觉小说系统默认模板 shutil.copyfile( "Data/chapter_dialogs_example.yaml", os.path.join( "Data", "workshop", self.current_selected_workshop_project, - "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.get_setting("Language")) + "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) ) ) #复制战斗系统默认模板 @@ -190,7 +187,7 @@ def __find_chapter_id(self, path:str) -> int: #加载章节 def __load_scene(self, chapterType:str, chapterId:int, screen:linpg.ImageSurface) -> None: if RPC is not None: RPC.update( - details = linpg.get_lang('General','main_chapter') if chapterType == "main_chapter" else linpg.get_lang('General','workshop'), + details = linpg.lang.get_text('General','main_chapter') if chapterType == "main_chapter" else linpg.lang.get_text('General','workshop'), state = self.__get_chapter_title(chapterType,chapterId), large_image = LARGE_IMAGE, start = time.time() @@ -208,13 +205,13 @@ def __load_scene(self, chapterType:str, chapterId:int, screen:linpg.ImageSurface else: linpg.global_value.set("BackToMainMenu",False) self.__reset_menu() - if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) + if RPC is not None: RPC.update(state=linpg.lang.get_text("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #继续章节 def __continue_scene(self, screen:linpg.ImageSurface) -> None: self.__background.stop() - SAVE:dict = linpg.load_config(r"Save/save.yaml") + SAVE:dict = linpg.config.load(r"Save/save.yaml") if RPC is not None: RPC.update( - details = linpg.get_lang('General','main_chapter') if SAVE["chapter_type"] == "main_chapter" else linpg.get_lang('General','workshop'), + details = linpg.lang.get_text('General','main_chapter') if SAVE["chapter_type"] == "main_chapter" else linpg.lang.get_text('General','workshop'), state = self.__get_chapter_title(SAVE["chapter_type"],SAVE["chapter_id"]), large_image = LARGE_IMAGE, start = time.time() @@ -240,7 +237,7 @@ def __continue_scene(self, screen:linpg.ImageSurface) -> None: dialog(screen, None, None, None) linpg.global_value.if_get_set("BackToMainMenu",True,False) self.__reset_menu() - if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) + if RPC is not None: RPC.update(state=linpg.lang.get_text("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #更新主菜单的部分元素 def __reset_menu(self) -> None: self.__background = self.__background.copy() @@ -248,19 +245,19 @@ def __reset_menu(self) -> None: #是否可以继续游戏了(save文件是否被创建) if os.path.exists("Save/save.yaml") and not self.continueButtonIsOn: self.main_menu_txt["menu_main"]["0_continue"] = linpg.load_dynamic_text( - linpg.get_lang("MainMenu","menu_main")["0_continue"], "enable", + linpg.lang.get_text("MainMenu","menu_main")["0_continue"], linpg.color.WHITE, self.main_menu_txt["menu_main"]["0_continue"].get_pos(), linpg.get_standard_font_size("medium") ) self.continueButtonIsOn = True elif not os.path.exists("Save/save.yaml") and self.continueButtonIsOn is True: self.main_menu_txt["menu_main"]["0_continue"] = linpg.load_dynamic_text( - linpg.get_lang("MainMenu","menu_main")["0_continue"], "disable", + linpg.lang.get_text("MainMenu","menu_main")["0_continue"], linpg.color.GRAY, self.main_menu_txt["menu_main"]["0_continue"].get_pos(), linpg.get_standard_font_size("medium") ) self.continueButtonIsOn = False #重新加载主菜单文字 def __reset_menu_text(self, screen_size:tuple) -> None: - self.main_menu_txt = linpg.get_lang('MainMenu') + self.main_menu_txt = linpg.lang.get_text('MainMenu') #当前不可用的菜单选项 disabled_option = ["6_developer_team","2_dlc","4_collection"] if not os.path.exists("Save/save.yaml"): @@ -273,16 +270,18 @@ def __reset_menu_text(self, screen_size:tuple) -> None: font_size = linpg.get_standard_font_size("medium")*2 txt_y = (screen_size[1]-len(self.main_menu_txt["menu_main"])*font_size)/2 for key,txt in self.main_menu_txt["menu_main"].items(): - mode = "enable" if key not in disabled_option else "disable" - self.main_menu_txt["menu_main"][key] = linpg.load_dynamic_text(txt,mode,(txt_location,txt_y),linpg.get_standard_font_size("medium")) + color_of_text = linpg.color.WHITE if key not in disabled_option else linpg.color.GRAY + self.main_menu_txt["menu_main"][key] = linpg.load_dynamic_text( + txt, color_of_text, (txt_location,txt_y), linpg.get_standard_font_size("medium") + ) txt_y += font_size #加载创意工坊选择页面的文字 - self.main_menu_txt["menu_workshop_choice"]["map_editor"] = linpg.get_lang("General","map_editor") - self.main_menu_txt["menu_workshop_choice"]["dialog_editor"] = linpg.get_lang("General","dialog_editor") - self.main_menu_txt["menu_workshop_choice"]["back"] = linpg.get_lang("Global","back") + self.main_menu_txt["menu_workshop_choice"]["map_editor"] = linpg.lang.get_text("General","map_editor") + self.main_menu_txt["menu_workshop_choice"]["dialog_editor"] = linpg.lang.get_text("General","dialog_editor") + self.main_menu_txt["menu_workshop_choice"]["back"] = linpg.lang.get_text("Global","back") txt_y = (screen_size[1]-len(self.main_menu_txt["menu_workshop_choice"])*font_size)/2 for key,txt in self.main_menu_txt["menu_workshop_choice"].items(): - self.main_menu_txt["menu_workshop_choice"][key] = linpg.load_dynamic_text(txt,"enable",(txt_location,txt_y),linpg.get_standard_font_size("medium")) + self.main_menu_txt["menu_workshop_choice"][key] = linpg.load_dynamic_text(txt,linpg.color.WHITE,(txt_location,txt_y),linpg.get_standard_font_size("medium")) txt_y += font_size #加载退出确认消息框 self.exit_confirm_menu = linpg.Message( @@ -300,9 +299,9 @@ def updated_language(self, screen:linpg.ImageSurface) -> None: self.__reload_chapter_select_list(screen.get_size(), "workshop") #更新音量 def __update_sound_volume(self) -> None: - self.click_button_sound.set_volume(linpg.get_setting("Sound","sound_effects")/100.0) - self.hover_on_button_sound.set_volume(linpg.get_setting("Sound","sound_effects")/100.0) - self.__background.set_volume(linpg.get_setting("Sound","background_music")/100.0) + self.click_button_sound.set_volume(linpg.setting.get("Sound","sound_effects")/100.0) + self.hover_on_button_sound.set_volume(linpg.setting.get("Sound","sound_effects")/100.0) + self.__background.set_volume(linpg.setting.get("Sound","background_music")/100.0) #画出背景 def __draw_background(self, screen:linpg.ImageSurface) -> None: #开始播放背景视频 @@ -312,7 +311,7 @@ def __draw_background(self, screen:linpg.ImageSurface) -> None: if self.menu_type == 1: for i in range(len(self.chapter_select)-1): if linpg.is_hover(self.chapter_select[i]): - cover_path = linpg.load_config(r"Data/main_chapter/info.yaml", "cover_image")[i] + cover_path = linpg.config.load(r"Data/main_chapter/info.yaml", "cover_image")[i] break if cover_path is not None: if self.__cover_img_surface is None: diff --git a/Source/scene.py b/Source/scene.py index 18f65d76..461774f4 100644 --- a/Source/scene.py +++ b/Source/scene.py @@ -9,7 +9,7 @@ def save_progress(self) -> None: #检查global.yaml配置文件 if not os.path.exists(os.path.join(self.folder_for_save_file,"global.yaml")): DataTmp = {"chapter_unlocked":1} - linpg.save_config(os.path.join(self.folder_for_save_file,"global.yaml"),DataTmp) + linpg.config.save(os.path.join(self.folder_for_save_file,"global.yaml"),DataTmp) #对话系统 def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> None: @@ -51,9 +51,9 @@ def dialogEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part #卸载音乐 linpg.unload_all_music() #改变标题 - linpg.display.set_caption("{0} ({1})".format(linpg.get_lang('General','game_title'),linpg.get_lang('General','dialog_editor'))) + linpg.display.set_caption("{0} ({1})".format(linpg.lang.get_text('General','game_title'),linpg.lang.get_text('General','dialog_editor'))) if RPC is not None: - RPC.update(details=linpg.get_lang("DiscordStatus","now_playing"),state=linpg.get_lang('General','dialog_editor'),large_image=LARGE_IMAGE) + RPC.update(details=linpg.lang.get_text("DiscordStatus","now_playing"),state=linpg.lang.get_text('General','dialog_editor'),large_image=LARGE_IMAGE) #加载对话 DIALOG:object = linpg.DialogEditor() DIALOG.load(chapterType,chapterId,part,projectName) @@ -63,8 +63,8 @@ def dialogEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part ALPHA_BUILD_WARNING.draw(screen) linpg.display.flip() #改变标题回主菜单的样式 - linpg.display.set_caption(linpg.get_lang('General','game_title')) - if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) + linpg.display.set_caption(linpg.lang.get_text('General','game_title')) + if RPC is not None: RPC.update(state=linpg.lang.get_text("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) #战斗系统 def battle(screen:linpg.ImageSurface, chapterType:str, chapterId:int, projectName:str=None) -> dict: @@ -91,14 +91,14 @@ def mapEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, project MAP_EDITOR = MapEditor() MAP_EDITOR.load(screen, chapterType, chapterId, projectName) #改变标题 - linpg.display.set_caption("{0} ({1})".format(linpg.get_lang('General','game_title'),linpg.get_lang('General','map_editor'))) + linpg.display.set_caption("{0} ({1})".format(linpg.lang.get_text('General','game_title'),linpg.lang.get_text('General','map_editor'))) if RPC is not None: - RPC.update(details=linpg.get_lang("DiscordStatus","now_playing"),state=linpg.get_lang('General','map_editor'),large_image=LARGE_IMAGE) + RPC.update(details=linpg.lang.get_text("DiscordStatus","now_playing"),state=linpg.lang.get_text('General','map_editor'),large_image=LARGE_IMAGE) #战斗系统主要loop while MAP_EDITOR.is_playing(): MAP_EDITOR.draw(screen) ALPHA_BUILD_WARNING.draw(screen) linpg.display.flip() #改变标题回主菜单的样式 - linpg.display.set_caption(linpg.get_lang('General','game_title')) - if RPC is not None: RPC.update(state=linpg.get_lang("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) + linpg.display.set_caption(linpg.lang.get_text('General','game_title')) + if RPC is not None: RPC.update(state=linpg.lang.get_text("DiscordStatus","staying_at_main_menu"),large_image=LARGE_IMAGE) diff --git a/main.py b/main.py index 3026fe99..85604a56 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ #读取并整理配置文件 for folderPath in (r'Lang/*.yaml', r'Data/*.yaml', r'Data/main_chapter/*.yaml'): #pass - linpg.organize_config_in_folder(folderPath) + linpg.config.organize(folderPath) #是否启动游戏 GAMESTART:bool = True @@ -19,7 +19,7 @@ screen = linpg.display.init() #窗口标题图标 linpg.display.set_icon(r"Assets/image/UI/icon.png") - linpg.display.set_caption(linpg.get_lang('General', 'game_title')) + linpg.display.set_caption(linpg.lang.get_text('General', 'game_title')) #初始化选项菜单 linpg.init_option_menu( int(screen.get_width()*0.25), From f6ef2608c0f8781bf2e4b1bff84a84c5be1c3c00 Mon Sep 17 00:00:00 2001 From: yudonglin Date: Mon, 5 Jul 2021 16:58:10 -0700 Subject: [PATCH 4/4] continue to implement new api as well as fixing bugs --- Data/version.yaml | 2 +- Source/gamemode/editor.py | 2 +- Source/gamemode/turnBased.py | 56 ++++++++++++++++++------------------ Source/gamemode/ui.py | 24 ++++++++-------- Source/mainMenu.py | 20 ++++++------- Source/scene.py | 10 +++---- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Data/version.yaml b/Data/version.yaml index 6b255d71..f59d1cfc 100644 --- a/Data/version.yaml +++ b/Data/version.yaml @@ -1,3 +1,3 @@ -patch: 3 +patch: 4 revision: 0 version: 0 diff --git a/Source/gamemode/editor.py b/Source/gamemode/editor.py index b05518d0..7883af75 100644 --- a/Source/gamemode/editor.py +++ b/Source/gamemode/editor.py @@ -224,7 +224,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: #加载地图 self._create_map(mapFileData) del mapFileData - self.MAP.setPos(tempLocal_x,tempLocal_y) + self.MAP.set_local_pos(tempLocal_x, tempLocal_y) #读取地图 self.originalData = linpg.config.load(self.get_map_file_location()) else: diff --git a/Source/gamemode/turnBased.py b/Source/gamemode/turnBased.py index 3026dae0..09b7d307 100644 --- a/Source/gamemode/turnBased.py +++ b/Source/gamemode/turnBased.py @@ -73,7 +73,7 @@ def enemyInControl(self) -> object: return self.enemies_data[self.sangvisFerris_ """加载与储存""" #从存档中加载游戏进程 def load(self, screen:linpg.ImageSurface) -> None: - DataTmp = linpg.config.load("Save/save.yaml") + DataTmp = linpg.config.load(r"Save/save.yaml") if DataTmp["type"] == "battle": self._initialize(DataTmp["chapter_type"], DataTmp["chapter_id"], DataTmp["project_name"]) self._initial_characters_loader(DataTmp["griffin"],DataTmp["sangvisFerri"]) @@ -144,10 +144,9 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: self.mission_objectives = DataTmp["mission_objectives"] #初始化天气和环境的音效 -- 频道1 self.environment_sound = linpg.SoundManagement(1) - self.weatherController = None if DataTmp["weather"] is not None: self.environment_sound.add(os.path.join("Assets/sound/environment","{}.ogg".format(DataTmp["weather"]))) - self.weatherController = linpg.WeatherSystem(DataTmp["weather"],self.window_x,self.window_y) + self._weather_system.init(DataTmp["weather"]) #加载对话信息 self._dialog_dictionary = DataTmp["dialogs"]["dictionary"] self._dialog_data = DataTmp["dialogs"]["data"] @@ -181,7 +180,7 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: #加载结束回合的图片 self.end_round_txt = self.FONT.render(linpg.lang.get_text("Battle_UI","endRound"),linpg.setting.antialias,linpg.color.WHITE) self.end_round_button = linpg.load.static_image( - "Assets/image/UI/end_round_button.png", + r"Assets/image/UI/end_round_button.png", (self.window_x*0.8, self.window_y*0.7), (self.end_round_txt.get_width()*2, self.end_round_txt.get_height()*2.5) ) @@ -213,12 +212,12 @@ def __process_data(self, screen:linpg.ImageSurface) -> None: #加载用于渲染电影效果的上下黑色帘幕 black_curtain = linpg.new_surface((self.window_x,self.window_y*0.15)).convert() black_curtain.fill(linpg.color.BLACK) - self.__up_black_curtain = linpg.load.movable_image( - black_curtain, (0, -black_curtain.get_height()), linpg.Origin, (0, int(black_curtain.get_height()*0.05)) + self.__up_black_curtain = linpg.MovableImage( + black_curtain, 0, -black_curtain.get_height(), 0, 0, 0, int(black_curtain.get_height()*0.05) ) - self.__down_black_curtain = linpg.load.movable_image( - black_curtain, (0, self.window_y), - (0, int(self.window_y-black_curtain.get_height())), (0, int(black_curtain.get_height()*0.051)) + self.__down_black_curtain = linpg.MovableImage( + black_curtain, 0, self.window_y, 0,int(self.window_y-black_curtain.get_height()), + 0, int(black_curtain.get_height()*0.051) ) """-----加载音效-----""" #行走的音效 -- 频道0 @@ -419,15 +418,15 @@ def __play_dialog(self, screen:linpg.ImageSurface) -> None: self.sangvisFerrisData[enemies].draw(screen,self.MAP) #展示设施 self._display_decoration(screen) - #加载雪花 - self._display_weather(screen) - #营造电影视觉 - self.__up_black_curtain.move_toward() - self.__up_black_curtain.draw(screen) - self.__down_black_curtain.move_toward() - self.__down_black_curtain.draw(screen) + #展示天气 + self._weather_system.draw(screen,self.MAP.block_width) #如果战斗有对话 if self.dialog_key is not None: + #营造电影视觉 + self.__up_black_curtain.move_toward() + self.__up_black_curtain.draw(screen) + self.__down_black_curtain.move_toward() + self.__down_black_curtain.draw(screen) #设定初始化 if self.dialog_parameters is None: self.dialog_parameters = { @@ -561,8 +560,7 @@ def __play_dialog(self, screen:linpg.ImageSurface) -> None: self.__is_battle_mode = True #战斗模块 def __play_battle(self, screen:linpg.ImageSurface) -> None: - #获取鼠标坐标 - mouse_x,mouse_y = linpg.controller.get_mouse_pos() + #处理基础事件 skill_range = None for event in linpg.controller.events: if event.type == linpg.key.DOWN: @@ -592,6 +590,9 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: self.range_ui_images[area].set_pos(xTemp+self.MAP.block_width*0.1,yTemp) self.range_ui_images[area].draw(screen) + #获取鼠标坐标 + mouse_x,mouse_y = linpg.controller.mouse.pos + #玩家回合 if self.whose_round == "player": if linpg.controller.get_event("confirm"): @@ -1010,7 +1011,7 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: for key,value in linpg.merge_dict(self.griffinCharactersData,self.sangvisFerrisData).items(): #如果天亮的双方都可以看见/天黑,但是是友方角色/天黑,但是是敌方角色在可观测的范围内 -- 则画出角色 if value.faction == "character" or value.faction == "sangvisFerri" and self.MAP.inLightArea(value): - if self.__if_draw_range is True and linpg.controller.mouse_get_press(2): + if self.__if_draw_range is True and linpg.controller.mouse.get_pressed(2): block_get_click = self.MAP.calBlockInMap(mouse_x,mouse_y) if block_get_click is not None and block_get_click["x"] == value.x and block_get_click["y"] == value.y: rightClickCharacterAlphaDeduct = False @@ -1098,8 +1099,8 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: self.characterInfoBoardUI.draw(screen,self.characterInControl) #----选择菜单---- self.buttonGetHover = self.selectMenuUI.draw(screen,round(self.MAP.block_width/10),self.MAP.getBlockExactLocation(self.characterInControl.x,self.characterInControl.y),self.characterInControl.kind,self.friendsCanSave,self.thingsCanReact) - #加载雪花 - self._display_weather(screen) + #展示天气 + self._weather_system.draw(screen, self.MAP.block_width) #移除电影视觉 self.__up_black_curtain.move_back() self.__up_black_curtain.draw(screen) @@ -1166,13 +1167,13 @@ def __play_battle(self, screen:linpg.ImageSurface) -> None: for event in linpg.controller.events: if event.type == linpg.key.DOWN: if event.key == linpg.key.SPACE: - linpg.unload_all_music() + linpg.media.unload() chapter_info:dict = self.get_data_of_parent_game_system() self.__init__() self.new(screen,chapter_info["chapter_type"], chapter_info["chapter_id"], chapter_info["project_name"]) break elif event.key == linpg.key.BACKSPACE: - linpg.unload_all_music() + linpg.media.unload() self.stop() self.__is_battle_mode = False break @@ -1222,10 +1223,9 @@ def draw(self, screen:linpg.ImageSurface) -> None: self.__update_scene(screen) #展示暂停菜单 if not self.pause_menu.hidden: - progress_saved_text = linpg.load.static_image( - self.FONT.render(linpg.lang.get_text("Global","progress_has_been_saved"),linpg.setting.antialias,(255,255,255)), - (0,0) - ) + progress_saved_text = linpg.StaticImage(self.FONT.render( + linpg.lang.get_text("Global","progress_has_been_saved"),linpg.setting.antialias,(255,255,255) + ), 0, 0) progress_saved_text.set_alpha(0) progress_saved_text.set_center(screen.get_width()/2, screen.get_height()/2) while not self.pause_menu.hidden: @@ -1242,7 +1242,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: linpg.get_option_menu().hidden = False elif result == "back_to_mainMenu": linpg.get_option_menu().hidden = True - linpg.unload_all_music() + linpg.media.unload() progress_saved_text.set_alpha(0) self.stop() self.pause_menu.hidden = True diff --git a/Source/gamemode/ui.py b/Source/gamemode/ui.py index 258b9c84..d482d264 100644 --- a/Source/gamemode/ui.py +++ b/Source/gamemode/ui.py @@ -3,8 +3,8 @@ import time import os from collections import deque -#import linpg -from linpgdev import linpg +import linpg +#from linpgdev import linpg # 显示回合切换的UI class RoundSwitch: @@ -146,7 +146,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: class SelectMenu: def __init__(self): selectMenuTxtDic:dict = linpg.lang.get_text("SelectMenu") - self.selectButtonImg = linpg.load.img("Assets/image/UI/menu.png") + self.selectButtonImg = linpg.load.img(r"Assets/image/UI/menu.png") #攻击 self.attackAP = linpg.AP_IS_NEEDED_TO_ATTACK self.attackTxt = selectMenuTxtDic["attack"] @@ -267,17 +267,17 @@ def draw(self, screen:linpg.ImageSurface, fontSize:linpg.int_f, location:dict, k #角色信息板 class CharacterInfoBoard: def __init__(self, window_x:int, window_y:int, text_size:int=20): - self.boardImg = linpg.load.img("Assets/image/UI/score.png",(window_x/5,window_y/6)) + self.boardImg = linpg.load.img(r"Assets/image/UI/score.png",(window_x/5,window_y/6)) self.characterIconImages = {} for img_path in glob.glob(r'Assets/image/npc_icon/*.png'): self.characterIconImages[os.path.basename(img_path).replace(".png","")] = linpg.smoothly_resize_img(linpg.load.img(img_path),(window_y*0.08,window_y*0.08)) self.text_size = text_size self.informationBoard = None - hp_empty_img = linpg.load.img("Assets/image/UI/hp_empty.png") - self.hp_red = linpg.ProgressBarSurface("Assets/image/UI/hp_red.png",hp_empty_img,0,0,window_x/15,text_size) - self.hp_green = linpg.ProgressBarSurface("Assets/image/UI/hp_green.png",hp_empty_img,0,0,window_x/15,text_size) - self.action_point_blue = linpg.ProgressBarSurface("Assets/image/UI/action_point.png",hp_empty_img,0,0,window_x/15,text_size) - self.bullets_number_brown = linpg.ProgressBarSurface("Assets/image/UI/bullets_number.png",hp_empty_img,0,0,window_x/15,text_size) + hp_empty_img = linpg.load.img(r"Assets/image/UI/hp_empty.png") + self.hp_red = linpg.ProgressBarSurface(r"Assets/image/UI/hp_red.png",hp_empty_img,0,0,window_x/15,text_size) + self.hp_green = linpg.ProgressBarSurface(r"Assets/image/UI/hp_green.png",hp_empty_img,0,0,window_x/15,text_size) + self.action_point_blue = linpg.ProgressBarSurface(r"Assets/image/UI/action_point.png",hp_empty_img,0,0,window_x/15,text_size) + self.bullets_number_brown = linpg.ProgressBarSurface(r"Assets/image/UI/bullets_number.png",hp_empty_img,0,0,window_x/15,text_size) #标记需要更新 def update(self) -> None: self.informationBoard = None #更新信息板 @@ -354,11 +354,11 @@ class LoadingTitle: def __init__(self, window_x:int, window_y:int, numChapter_txt:str, chapterId:int, chapterTitle_txt:str, chapterDesc_txt:str): self.black_bg = linpg.get_single_color_surface("black") title_chapterNum = linpg.render_font(numChapter_txt.format(chapterId),"white",window_x/38) - self.title_chapterNum = linpg.load.static_image(title_chapterNum,((window_x-title_chapterNum.get_width())/2,window_y*0.37)) + self.title_chapterNum = linpg.StaticImage(title_chapterNum, (window_x-title_chapterNum.get_width())/2, window_y*0.37) title_chapterName = linpg.render_font(chapterTitle_txt,"white",window_x/38) - self.title_chapterName = linpg.load.static_image(title_chapterName,((window_x-title_chapterName.get_width())/2,window_y*0.46)) + self.title_chapterName = linpg.StaticImage(title_chapterName, (window_x-title_chapterName.get_width())/2, window_y*0.46) title_description = linpg.render_font(chapterDesc_txt,"white",window_x/76) - self.title_description = linpg.load.static_image(title_description,((window_x-title_description.get_width())/2,window_y*0.6)) + self.title_description = linpg.StaticImage(title_description, (window_x-title_description.get_width())/2, window_y*0.6) def draw(self, screen:linpg.ImageSurface, alpha:int=255) -> None: self.title_chapterNum.set_alpha(alpha) self.title_chapterName.set_alpha(alpha) diff --git a/Source/mainMenu.py b/Source/mainMenu.py index 63bf5456..6d1336f3 100644 --- a/Source/mainMenu.py +++ b/Source/mainMenu.py @@ -26,8 +26,8 @@ def __init__(self, screen:linpg.ImageSurface): #关卡选择的封面 self.__cover_img_surface = None #音效 - self.click_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_click_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) - self.hover_on_button_sound = linpg.load_sound(r"Assets/sound/ui/main_menu_hover_on_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) + self.click_button_sound = linpg.sound.load(r"Assets/sound/ui/main_menu_click_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) + self.hover_on_button_sound = linpg.sound.load(r"Assets/sound/ui/main_menu_hover_on_button.ogg",linpg.setting.get("Sound","sound_effects")/100.0) self.hover_sound_play_on = None self.last_hover_sound_play_on = None #加载主菜单背景 @@ -55,10 +55,10 @@ def __reload_workshop_files_list(self, screen_size:tuple, createMode:bool=False) info_data = linpg.config.load(os.path.join(path,"info.yaml")) except Exception: info_data = linpg.config.load(r"Data/info_example.yaml") - info_data["default_lang"] = linpg.setting.get("Language") + info_data["default_lang"] = linpg.setting.language linpg.config.save(os.path.join(path,"info.yaml"),info_data) self.workshop_files_text.append(os.path.basename(path)) - self.workshop_files.append(info_data["title"][linpg.setting.get("Language")]) + self.workshop_files.append(info_data["title"][linpg.setting.language]) self.workshop_files.append(linpg.lang.get_text("Global","back")) txt_location:int = int(screen_size[0]*2/3) txt_y:int = int((screen_size[1]-len(self.workshop_files)*linpg.get_standard_font_size("medium")*2)/2) @@ -71,10 +71,10 @@ def __reload_workshop_files_list(self, screen_size:tuple, createMode:bool=False) def __get_chapter_title(self, chapterType:str, chapterId:int) -> str: #生成dialog文件的路径 dialog_file_path:str = os.path.join( - "Data", chapterType, "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) + "Data", chapterType, "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.language) ) if chapterType == "main_chapter" else os.path.join( "Data", chapterType, self.current_selected_workshop_project, - "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) + "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.language) ) chapter_title:str if os.path.exists(dialog_file_path): @@ -157,19 +157,19 @@ def __create_new_project(self) -> None: os.makedirs(os.path.join("Data","workshop",fileName)) #储存数据 info_data:dict = linpg.config.load(r"Data/info_example.yaml") - info_data["default_lang"] = linpg.setting.get("Language") + info_data["default_lang"] = linpg.setting.language linpg.config.save(os.path.join("Data","workshop",fileName,"info.yaml"),info_data) #创建新的对话文和地图文件 def __create_new_chapter(self) -> None: chapterId:int = len(glob.glob(os.path.join( - "Data", "workshop", self.current_selected_workshop_project, "*_dialogs_{}.yaml".format(linpg.setting.get("Language")) + "Data", "workshop", self.current_selected_workshop_project, "*_dialogs_{}.yaml".format(linpg.setting.language) ))) + 1 #复制视觉小说系统默认模板 shutil.copyfile( "Data/chapter_dialogs_example.yaml", os.path.join( "Data", "workshop", self.current_selected_workshop_project, - "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.get("Language")) + "chapter{0}_dialogs_{1}.yaml".format(chapterId, linpg.setting.language) ) ) #复制战斗系统默认模板 @@ -376,7 +376,7 @@ def draw(self, screen:linpg.ImageSurface) -> None: elif linpg.is_hover(self.main_menu_txt["menu_main"]["6_developer_team"]): pass #退出 - elif linpg.is_hover(self.main_menu_txt["menu_main"]["7_exit"]) and self.exit_confirm_menu.draw() == 0: + elif linpg.is_hover(self.main_menu_txt["menu_main"]["7_exit"]) and self.exit_confirm_menu.show() == 0: self.__background.stop() self.stop() if RPC is not None: RPC.close() diff --git a/Source/scene.py b/Source/scene.py index 461774f4..f04d9350 100644 --- a/Source/scene.py +++ b/Source/scene.py @@ -26,7 +26,7 @@ def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, screen.blit(LoadingImgBelow,(-2,screen.get_height()-LoadingImgBelow.get_height()/100*i)) linpg.display.flip() #卸载音乐 - linpg.unload_all_music() + linpg.media.unload() #初始化对话系统模块 DIALOG:object = DialogSystem() if chapterType is not None: @@ -49,7 +49,7 @@ def dialog(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, #对话编辑器 def dialogEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part:str, projectName:str=None) -> None: #卸载音乐 - linpg.unload_all_music() + linpg.media.unload() #改变标题 linpg.display.set_caption("{0} ({1})".format(linpg.lang.get_text('General','game_title'),linpg.lang.get_text('General','dialog_editor'))) if RPC is not None: @@ -69,7 +69,7 @@ def dialogEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, part #战斗系统 def battle(screen:linpg.ImageSurface, chapterType:str, chapterId:int, projectName:str=None) -> dict: #卸载音乐 - linpg.unload_all_music() + linpg.media.unload() BATTLE:object = TurnBasedBattleSystem() if chapterType is not None: BATTLE.new(screen, chapterType, chapterId, projectName) @@ -81,13 +81,13 @@ def battle(screen:linpg.ImageSurface, chapterType:str, chapterId:int, projectNam ALPHA_BUILD_WARNING.draw(screen) linpg.display.flip() #暂停声效 - 尤其是环境声 - linpg.unload_all_music() + linpg.media.unload() return BATTLE.resultInfo #地图编辑器 def mapEditor(screen:linpg.ImageSurface, chapterType:str, chapterId:int, projectName:str=None) -> None: #卸载音乐 - linpg.unload_all_music() + linpg.media.unload() MAP_EDITOR = MapEditor() MAP_EDITOR.load(screen, chapterType, chapterId, projectName) #改变标题