From 9f8247dc4da89219b6eede08d58d96964391a077 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 27 Apr 2024 16:26:22 +0300 Subject: refactor menus and screen showing under menu subpkg --- src/sliceitoff/menu/initials.py | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/sliceitoff/menu/initials.py (limited to 'src/sliceitoff/menu/initials.py') diff --git a/src/sliceitoff/menu/initials.py b/src/sliceitoff/menu/initials.py new file mode 100644 index 0000000..ca52b16 --- /dev/null +++ b/src/sliceitoff/menu/initials.py @@ -0,0 +1,50 @@ +""" menu.initials - Use will be asked for initials """ +import pygame + +from sliceitoff.screens import initials_screen + +from .explodeout import ExplodeOutGroup + +class Initials(ExplodeOutGroup): + """ Sprite group that asks initials to self.name from user """ + def __init__(self): + super().__init__() + self.add(initials_screen("")) + self.name = "" + + def update(self, dt = 0, **kwargs): + """ Does it all. Reads keyboard and updates screen """ + if not super().update(dt = dt, **kwargs): + return + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.do_fadeout() + break + if event.type == pygame.KEYDOWN: + if event.key in ( + pygame.K_ESCAPE, + pygame.K_KP_ENTER, + pygame.K_RETURN): + self.do_fadeout() + break + if event.key in ( + pygame.K_RSHIFT, + pygame.K_LSHIFT, + pygame.K_RCTRL, + pygame.K_LCTRL, + pygame.K_RALT, + pygame.K_LALT, + pygame.K_RMETA, + pygame.K_LMETA, + pygame.K_LSUPER, + pygame.K_RSUPER, + pygame.K_SPACE): + continue + if event.key in (pygame.K_BACKSPACE, pygame.K_DELETE): + self.name = self.name [:-1] + elif pygame.key.name(event.key): + self.name += pygame.key.name(event.key)[0].upper() + self.name = self.name[:3] + self.empty() + self.add(initials_screen(self.name)) -- cgit v1.2.3