blob: baca5ca868776c6c646e162f1f8a94d7538a25d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import contextlib
import sys
import pygame
from .Screen import Screen
from ..controller import KeyboardController, JoystickController, Input
from ..misc import UnPause
def handle_input_pressed(controller, event):
if controller.get_input_down(event) == Input.PAUSE:
raise UnPause()
class Pause(Screen):
def __init__(self, screen):
self.event_handler = dict()
self.event_handler[pygame.QUIT] = lambda _: sys.exit()
self.event_handler[pygame.JOYBUTTONDOWN] = lambda evt: handle_input_pressed(JoystickController(evt.joy), evt)
self.event_handler[pygame.KEYDOWN] = lambda evt: handle_input_pressed(KeyboardController(pygame.key), evt)
def refresh(self):
pass
def oneframe(self):
try:
for event in pygame.event.get():
with contextlib.suppress(KeyError):
self.event_handler[event.type](event)
except UnPause:
pygame.event.clear()
raise
|