allow interpolator gui commands
This commit is contained in:
parent
27467b393a
commit
a53f175d6f
|
@ -2,6 +2,7 @@ from pygame.event import get, pump, Event, post
|
|||
from pygame.locals import *
|
||||
|
||||
from GameChild import GameChild
|
||||
from Input import Input
|
||||
|
||||
class Delegate(GameChild):
|
||||
|
||||
|
@ -23,6 +24,7 @@ class Delegate(GameChild):
|
|||
|
||||
def enable(self):
|
||||
self.enabled = True
|
||||
self.interpolator = self.get_game().interpolator
|
||||
|
||||
def dispatch(self):
|
||||
if self.enabled:
|
||||
|
@ -31,8 +33,14 @@ class Delegate(GameChild):
|
|||
kind = evt.type
|
||||
if kind in subscribers:
|
||||
for subscriber in subscribers[kind]:
|
||||
self.print_debug("Passing %s to %s" % (evt, subscriber))
|
||||
subscriber(evt)
|
||||
if not self.interpolator.is_gui_active() or \
|
||||
hasattr(subscriber, "im_class") and \
|
||||
(subscriber.im_class == Input or \
|
||||
subscriber.im_class == \
|
||||
self.interpolator.gui.__class__):
|
||||
self.print_debug("Passing %s to %s" % (evt,
|
||||
subscriber))
|
||||
subscriber(evt)
|
||||
else:
|
||||
pump()
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from pygame import Surface
|
||||
from pygame.font import Font
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import GameChild
|
||||
|
@ -151,17 +153,25 @@ class GUI(GameChild):
|
|||
|
||||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
self.audio = self.get_audio()
|
||||
self.display_surface = self.get_display_surface()
|
||||
self.time_filter = self.get_game().time_filter
|
||||
self.delegate = self.get_delegate()
|
||||
self.set_background()
|
||||
self.subscribe(self.respond_to_command)
|
||||
self.subscribe(self.respond_to_mouse_down, MOUSEBUTTONDOWN)
|
||||
self.subscribe(self.respond_to_mouse_up, MOUSEBUTTONUP)
|
||||
self.active = False
|
||||
|
||||
def set_background(self):
|
||||
surface = Surface(self.display_surface.get_size())
|
||||
surface.fill((0, 0, 0))
|
||||
self.background = surface
|
||||
|
||||
def deactivate(self):
|
||||
self.active = False
|
||||
self.time_filter.open()
|
||||
self.get_audio().unmute()
|
||||
self.audio.muted = self.saved_mute_state
|
||||
|
||||
def respond_to_command(self, event):
|
||||
compare = self.delegate.compare
|
||||
|
@ -179,7 +189,8 @@ class GUI(GameChild):
|
|||
def activate(self):
|
||||
self.active = True
|
||||
self.time_filter.close()
|
||||
self.get_audio().mute()
|
||||
self.saved_mute_state = self.audio.muted
|
||||
self.audio.mute()
|
||||
|
||||
def respond_to_mouse_down(self, event):
|
||||
pass
|
||||
|
@ -188,7 +199,5 @@ class GUI(GameChild):
|
|||
pass
|
||||
|
||||
def update(self):
|
||||
from pygame.font import Font
|
||||
font = Font(None, 59)
|
||||
surface = font.render(str(self.time_filter.get_ticks()), False, (255, 255, 255), (0, 0, 0))
|
||||
self.get_display_surface().blit(surface, (0, 0))
|
||||
if self.active:
|
||||
self.display_surface.blit(self.background, (0, 0))
|
||||
|
|
Loading…
Reference in New Issue