def __init__(self, master: Window, **kwargs): Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs) self.text_title = Text("Options", ("calibri", 50)) params_for_all_scales = { "width": 0.45 * self.frame.w, "height": 30, "color": TRANSPARENT, "scale_color": GREEN, "from_": 0, "to": 100, "highlight_color": YELLOW, "outline": 3 } params_for_all_buttons = { "font": ("calibri", 30), "bg": GREEN, "hover_bg": GREEN_LIGHT, "active_bg": GREEN_DARK, "highlight_color": params_for_all_scales["highlight_color"], "outline": params_for_all_scales["outline"] } self.scale_music = Scale( self, **params_for_all_scales, default=Window.music_volume() * 100, callback=lambda value, percent: Window.set_music_volume(percent) ) self.scale_music.show_label("Music: ", Scale.S_LEFT, font=params_for_all_buttons["font"]) self.scale_music.show_value(Scale.S_RIGHT, font=params_for_all_buttons["font"]) self.scale_sound = Scale( self, **params_for_all_scales, default=Window.sound_volume() * 100, callback=lambda value, percent: Window.set_sound_volume(percent) ) self.scale_sound.show_label("SFX: ", Scale.S_LEFT, font=params_for_all_buttons["font"]) self.scale_sound.show_value(Scale.S_RIGHT, font=params_for_all_buttons["font"]) self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
def update_music_volume(self): Window.set_music_volume(self.scale_music_volume.percent)
def __init__(self, master: Window): Window.__init__(self, master=master, bg_music=master.bg_music) self.frame = RectangleShape(0.60 * self.width, 0.60 * self.height, GREEN, outline=3) self.title = Text("Options", font=(RESOURCES.FONT["algerian"], 70)) self.options_font = (RESOURCES.FONT["algerian"], 40) self.case_font = (RESOURCES.FONT["algerian"], 30) self.control_font = ("calibri", 20) params_for_all_scales = { "width": 0.45 * self.frame.w, "color": TRANSPARENT, "scale_color": GREEN_DARK, "from_": 0, "to": 100, "outline": 3, } params_for_all_buttons = { "highlight_color": YELLOW, "hover_sound": RESOURCES.SFX["select"], "disabled_sound": RESOURCES.SFX["block"] } params_for_option_buttons = { "on_click_sound": RESOURCES.SFX["validate"] } params_for_buttons = { "bg": GRAY_DARK, "fg": WHITE, "hover_bg": GRAY, "active_bg": BLACK } params_for_reset_button = { "bg": RED, "fg": WHITE, "hover_bg": RED_LIGHT, "active_bg": RED_DARK, } self.button_back = ImageButton(self, img=RESOURCES.IMG["blue_arrow"], on_click_sound=RESOURCES.SFX["back"], callback=self.stop, **params_for_all_buttons) self.button_change_page = Button(self, ">>", font=self.case_font, callback=self.change_page, **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.nb_pages = 2 self.page = 1 ## PAGE 1 ## valid_img = Image(RESOURCES.IMG["green_valid"]) self.text_music = Text("Music:", self.options_font) self.cb_music = CheckBox(self, 30, 30, TRANSPARENT, image=valid_img, value=self.get_music_state(), callback=self.set_music_state, **params_for_all_buttons, **params_for_option_buttons) self.scale_music = Scale( self, **params_for_all_scales, **params_for_all_buttons, height=self.cb_music.height, default=Window.music_volume() * 100, callback=lambda value, percent: Window.set_music_volume(percent)) self.text_sound = Text("SFX:", self.options_font) self.cb_sound = CheckBox(self, 30, 30, TRANSPARENT, image=valid_img, value=self.get_sound_state(), callback=self.set_sound_state, **params_for_all_buttons, **params_for_option_buttons) self.scale_sound = Scale( self, **params_for_all_scales, **params_for_all_buttons, height=self.cb_sound.height, default=Window.sound_volume() * 100, callback=lambda value, percent: Window.set_sound_volume(percent)) self.text_fps = Text("FPS:", self.options_font) self.cb_show_fps = CheckBox(self, 30, 30, TRANSPARENT, image=valid_img, value=Window.fps_is_shown(), callback=self.show_fps, **params_for_all_buttons, **params_for_option_buttons) self.button_reset = Button(self, "Reset Save", font=(RESOURCES.FONT["algerian"], 30), callback=SAVE.reset, state=Button.DISABLED, **params_for_all_buttons, **params_for_option_buttons, **params_for_reset_button) ## PAGE 2 ## self.text_acceleration = Text("Accélérer:", self.options_font) self.button_auto_acceleration = Button( self, font=self.case_font, callback=lambda: SAVE.update(auto_acceleration=not SAVE[ "auto_acceleration"]), **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.button_acceleration = Button( self, font=self.control_font, callback=lambda: self.choose_key("speed_up"), **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.text_brake = Text("Freiner:", self.options_font) self.button_brake = Button(self, font=self.control_font, callback=lambda: self.choose_key("brake"), **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.text_move_up = Text("Aller en haut:", self.options_font) self.button_move_up = Button(self, font=self.control_font, callback=lambda: self.choose_key("up"), **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.text_move_down = Text("Aller en bas:", self.options_font) self.button_move_down = Button( self, font=self.control_font, callback=lambda: self.choose_key("down"), **params_for_all_buttons, **params_for_option_buttons, **params_for_buttons) self.bind_key(pygame.K_ESCAPE, lambda event: self.stop(sound=RESOURCES.SFX["back"])) self.bind_joystick( 0, "B", lambda event: self.stop(sound=RESOURCES.SFX["back"]))