summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game/menu.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-27 16:26:22 +0300
committerViljami Ilola <+@hix.fi>2024-04-27 16:26:22 +0300
commit9f8247dc4da89219b6eede08d58d96964391a077 (patch)
treea6f7dc46275a3988fc528072f5e70caba461fae0 /src/sliceitoff/game/menu.py
parentd64c6b122eacd7b33bbda3a62093b492c786b1f9 (diff)
refactor menus and screen showing under menu subpkg
Diffstat (limited to 'src/sliceitoff/game/menu.py')
-rw-r--r--src/sliceitoff/game/menu.py70
1 files changed, 0 insertions, 70 deletions
diff --git a/src/sliceitoff/game/menu.py b/src/sliceitoff/game/menu.py
deleted file mode 100644
index 446e37f..0000000
--- a/src/sliceitoff/game/menu.py
+++ /dev/null
@@ -1,70 +0,0 @@
-""" game.menu - Skeleton for menus """
-import pygame
-
-from sliceitoff.display import Scaling
-
-from .explodeout import ExplodeOutGroup
-
-MOUSE_TRESHOLD = 100
-
-class Menu(ExplodeOutGroup):
- """ sprite group with imputs to make selection """
- def __init__(self, screen, items):
- super().__init__()
- self.items = items
- self.selection = 0
- self.mousey = 0
- self.screen = screen
- self.add(self.screen(self.selection))
-
- def do_selection(self):
- """ Default selection handler. Every action just ends menu. """
- self.do_fadeout()
-
- 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 = self.items - 1
- self.do_selection()
- 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(self.screen(self.selection))
-
- 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 %= self.items
- 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 = self.items - 1
- self.do_selection()
- return True
- case pygame.K_UP:
- self.selection -= 1
- self.selection %= self.items
- case pygame.K_DOWN:
- self.selection += 1
- self.selection %= self.items
- return False