diff options
Diffstat (limited to 'src/sliceitoff/game/settings.py')
-rw-r--r-- | src/sliceitoff/game/settings.py | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/src/sliceitoff/game/settings.py b/src/sliceitoff/game/settings.py index 53d0362..0b3bed8 100644 --- a/src/sliceitoff/game/settings.py +++ b/src/sliceitoff/game/settings.py @@ -1,86 +1,28 @@ """ game.settings - Settings dialog """ from enum import IntEnum -import pygame -from sliceitoff.screens import settings_screen -from sliceitoff.display import Scaling from sliceitoff.sfx import sfx +from sliceitoff.screens import settings_screen +from .menu import Menu -from .explodeout import ExplodeOutGroup - -MOUSE_TRESHOLD = 100 -class MenuItems(IntEnum): +class SettingsItems(IntEnum): """ Items in the menu. Should match settings_screen """ SFX = 0 MUSIC = 1 BACK = 2 -class SettingsMenu(ExplodeOutGroup): - """ sprite group with imputs to make selection """ +class SettingsMenu(Menu): + """ Settings menu """ def __init__(self): - super().__init__() - self.add(settings_screen(0,0,0)) - self.selection = 0 - self.mousey = 0 + super().__init__(settings_screen, len(SettingsItems)) def do_selection(self): - """ Actions for manu entries """ + """ Custom actions for menu entries """ match self.selection: - case MenuItems.BACK: + case SettingsItems.BACK: self.do_fadeout() - case MenuItems.SFX: + case SettingsItems.SFX: sfx.sfx_up() - case MenuItems.MUSIC: + case SettingsItems.MUSIC: sfx.music_up() - - def update(self, dt = 0, **kwargs): - """ Does it all. Reads keyboard and updates screen """ - if not super().update(dt = dt, **kwargs) or self.explode: - return - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - self.selection = MenuItems.BACK - self.do_fadeout() - break - if event.type == pygame.MOUSEBUTTONDOWN and event.button <= 3: - self.do_selection() - break - if event.type == pygame.KEYDOWN: - if self.process_key(event.key): - break - elif event.type == pygame.MOUSEMOTION: - self.process_mouse_motion() - self.empty() - self.add(settings_screen( - self.selection, - sfx.sfx_volume, - sfx.music_volume)) - - def process_mouse_motion(self): - """ Mouse movement up or down moves menu selection """ - self.mousey += pygame.mouse.get_rel()[1] - pygame.mouse.set_pos(Scaling.center) - if abs(self.mousey) > MOUSE_TRESHOLD: - self.selection += 1 if self.mousey > 0 else -1 - self.selection %= len(MenuItems) - self.mousey = 0 - - def process_key(self, key): - """ Processes known key presses """ - match key: - case pygame.K_KP_ENTER | pygame.K_RETURN | pygame.K_RIGHT: - self.do_selection() - return True - case pygame.K_ESCAPE | pygame.K_q | pygame.K_LEFT: - self.selection = MenuItems.BACK - self.do_fadeout() - return True - case pygame.K_UP: - self.selection -= 1 - self.selection %= len(MenuItems) - case pygame.K_DOWN: - self.selection += 1 - self.selection %= len(MenuItems) - return False |