From be5309f3286cd57fe0c3a2b37dff63241d322ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Thu, 28 Jul 2022 18:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=E6=9C=AA=E5=BA=94=E7=94=A8=E5=AD=98=E6=A1=A3=E5=86=85=E7=9A=84?= =?UTF-8?q?=E9=9F=B3=E6=95=88=E9=9F=B3=E9=87=8F=E8=AE=BE=E5=AE=9A=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/constants.py | 6 +++--- source/state/level.py | 22 +++++++++++----------- source/state/mainmenu.py | 22 ++++++++++++---------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/source/constants.py b/source/constants.py index 09901ce..2cf36e0 100755 --- a/source/constants.py +++ b/source/constants.py @@ -84,7 +84,7 @@ RESTART_BUTTON = 'restartButton' MAINMENU_BUTTON = 'mainMenuButton' LITTLEGAME_BUTTON = 'littleGameButton' OPTION_BUTTON = 'optionButton' -VOLUME_BUTTON = 'volumeButton' +SOUND_VOLUME_BUTTON = 'volumeButton' # 金银向日葵奖杯 TROPHY_SUNFLOWER = 'sunflowerTrophy' # 小铲子 @@ -105,7 +105,7 @@ LITTLEGAME_NUM = 'littleGame num' LEVEL_COMPLETIONS = 'level completions' LITTLEGAME_COMPLETIONS = 'littleGame completions' GAME_RATE = 'game rate' -VOLUME = 'volume' +SOUND_VOLUME = 'volume' # 整个游戏的状态 MAIN_MENU = 'main menu' @@ -667,7 +667,7 @@ INIT_USERDATA = { LEVEL_COMPLETIONS: 0, LITTLEGAME_COMPLETIONS: 0, GAME_RATE: 1, - VOLUME: 1.0, + SOUND_VOLUME: 1, } # 无穷大常量 diff --git a/source/state/level.py b/source/state/level.py index 2af72ac..4fb2685 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -381,7 +381,7 @@ class Level(tool.State): pg.mixer.music.stop() pg.mixer.music.load(os.path.join(c.PATH_MUSIC_DIR, "chooseYourSeeds.opus")) pg.mixer.music.play(-1, 0) - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) def choose(self, mouse_pos, mouse_click): # 如果暂停 @@ -403,7 +403,7 @@ class Level(tool.State): pg.mixer.music.stop() pg.mixer.music.load(os.path.join(c.PATH_MUSIC_DIR, self.bgm)) pg.mixer.music.play(-1, 0) - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) self.state = c.PLAY if self.bar_type == c.CHOOSEBAR_STATIC: @@ -536,7 +536,7 @@ class Level(tool.State): font = pg.font.Font(c.FONT_PATH, 35) font.bold = True # 音量+ - self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK) + self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK) sign = font.render("+", True, c.YELLOWGREEN) sign_rect = sign.get_rect() sign_rect.x = 8 @@ -545,7 +545,7 @@ class Level(tool.State): self.sound_volume_plus_button_rect = self.sound_volume_plus_button.get_rect() self.sound_volume_plus_button_rect.x = 500 # 音量- - self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK) + self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK) sign = font.render("-", True, c.YELLOWGREEN) sign_rect = sign.get_rect() sign_rect.x = 12 @@ -587,20 +587,20 @@ class Level(tool.State): c.SOUND_BUTTON_CLICK.play() # 音量+ elif self.inArea(self.sound_volume_plus_button_rect, *mouse_pos): - self.game_info[c.VOLUME] = min(self.game_info[c.VOLUME] + 0.1, 1) + self.game_info[c.SOUND_VOLUME] = round(min(self.game_info[c.SOUND_VOLUME] + 0.05, 1), 2) # 一般不会有人想把音乐和音效分开设置,故pg.mixer.Sound.set_volume()和pg.mixer.music.set_volume()需要一起用 - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) for i in c.SOUNDS: - i.set_volume(self.game_info[c.VOLUME]) + i.set_volume(self.game_info[c.SOUND_VOLUME]) c.SOUND_BUTTON_CLICK.play() # 将音量信息存档 self.saveUserData() elif self.inArea(self.sound_volume_minus_button_rect, *mouse_pos): - self.game_info[c.VOLUME] = max(self.game_info[c.VOLUME] - 0.1, 0) + self.game_info[c.SOUND_VOLUME] = round(max(self.game_info[c.SOUND_VOLUME] - 0.05, 0), 2) # 一般不会有人想把音乐和音效分开设置,故pg.mixer.Sound.set_volume()和pg.mixer.music.set_volume()需要一起用 - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) for i in c.SOUNDS: - i.set_volume(self.game_info[c.VOLUME]) + i.set_volume(self.game_info[c.SOUND_VOLUME]) c.SOUND_BUTTON_CLICK.play() # 将音量信息存档 self.saveUserData() @@ -1509,7 +1509,7 @@ class Level(tool.State): def showCurrentVolumeImage(self, surface): # 由于音量可变,因此这一内容不能在一开始就结束加载,而应当不断刷新不断显示 font = pg.font.Font(c.FONT_PATH, 30) - volume_tips = font.render(f"音量:{round(self.game_info[c.VOLUME]*100):3}%", True, c.LIGHTGRAY) + volume_tips = font.render(f"音量:{round(self.game_info[c.SOUND_VOLUME]*100):3}%", True, c.LIGHTGRAY) volume_tips_rect = volume_tips.get_rect() volume_tips_rect.x = 275 volume_tips_rect.y = 247 diff --git a/source/state/mainmenu.py b/source/state/mainmenu.py index db5291d..650e033 100644 --- a/source/state/mainmenu.py +++ b/source/state/mainmenu.py @@ -21,7 +21,9 @@ class Menu(tool.State): pg.mixer.music.load(os.path.join(c.PATH_MUSIC_DIR, "intro.opus")) pg.mixer.music.play(-1, 0) pg.display.set_caption(c.ORIGINAL_CAPTION) - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) + for i in c.SOUNDS: + i.set_volume(self.game_info[c.SOUND_VOLUME]) def saveUserData(self): with open(c.USERDATA_PATH, "w") as f: @@ -191,7 +193,7 @@ class Menu(tool.State): font = pg.font.Font(c.FONT_PATH, 35) font.bold = True # 音量+ - self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK) + self.sound_volume_plus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK) sign = font.render("+", True, c.YELLOWGREEN) sign_rect = sign.get_rect() sign_rect.x = 8 @@ -200,7 +202,7 @@ class Menu(tool.State): self.sound_volume_plus_button_rect = self.sound_volume_plus_button.get_rect() self.sound_volume_plus_button_rect.x = 500 # 音量- - self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.VOLUME_BUTTON], *frame_rect, c.BLACK) + self.sound_volume_minus_button = tool.get_image_menu(tool.GFX[c.SOUND_VOLUME_BUTTON], *frame_rect, c.BLACK) sign = font.render("-", True, c.YELLOWGREEN) sign_rect = sign.get_rect() sign_rect.x = 12 @@ -233,7 +235,7 @@ class Menu(tool.State): def showCurrentVolumeImage(self, surface): # 由于音量可变,因此这一内容不能在一开始就结束加载,而应当不断刷新不断显示 font = pg.font.Font(c.FONT_PATH, 30) - volume_tips = font.render(f"音量:{round(self.game_info[c.VOLUME]*100):3}%", True, c.LIGHTGRAY) + volume_tips = font.render(f"音量:{round(self.game_info[c.SOUND_VOLUME]*100):3}%", True, c.LIGHTGRAY) volume_tips_rect = volume_tips.get_rect() volume_tips_rect.x = 275 volume_tips_rect.y = 247 @@ -274,20 +276,20 @@ class Menu(tool.State): c.SOUND_BUTTON_CLICK.play() # 音量+ elif self.inArea(self.sound_volume_plus_button_rect, *mouse_pos): - self.game_info[c.VOLUME] = min(self.game_info[c.VOLUME] + 0.1, 1) + self.game_info[c.SOUND_VOLUME] = round(min(self.game_info[c.SOUND_VOLUME] + 0.05, 1), 2) # 一般不会有人想把音乐和音效分开设置,故pg.mixer.Sound.set_volume()和pg.mixer.music.set_volume()需要一起用 - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) for i in c.SOUNDS: - i.set_volume(self.game_info[c.VOLUME]) + i.set_volume(self.game_info[c.SOUND_VOLUME]) c.SOUND_BUTTON_CLICK.play() self.saveUserData() # 音量- elif self.inArea(self.sound_volume_minus_button_rect, *mouse_pos): - self.game_info[c.VOLUME] = max(self.game_info[c.VOLUME] - 0.1, 0) + self.game_info[c.SOUND_VOLUME] = round(max(self.game_info[c.SOUND_VOLUME] - 0.05, 0), 2) # 一般不会有人想把音乐和音效分开设置,故pg.mixer.Sound.set_volume()和pg.mixer.music.set_volume()需要一起用 - pg.mixer.music.set_volume(self.game_info[c.VOLUME]) + pg.mixer.music.set_volume(self.game_info[c.SOUND_VOLUME]) for i in c.SOUNDS: - i.set_volume(self.game_info[c.VOLUME]) + i.set_volume(self.game_info[c.SOUND_VOLUME]) c.SOUND_BUTTON_CLICK.play() self.saveUserData() # 没有点到前两者时常规行检测所有按钮的点击和高亮