# HG changeset patch # User Neil Muller # Date 1282665927 -7200 # Node ID f125bb60d7de6987f7800fcdc3f18b40ff4ca521 # Parent d3ca34a664fd030889ee00ef1a33b4c9968a8e26 Move result handling to result object diff -r d3ca34a664fd -r f125bb60d7de gamelib/gamescreen.py --- a/gamelib/gamescreen.py Tue Aug 24 18:01:42 2010 +0200 +++ b/gamelib/gamescreen.py Tue Aug 24 18:05:27 2010 +0200 @@ -15,7 +15,6 @@ from hand import HandButton from popupmenu import PopupMenu, PopupMenuButton from state import initial_state, Item -from widgets import MessageDialog class InventoryView(PaletteView): @@ -56,24 +55,14 @@ def draw(self, surface): self.state.draw(surface) - def _process_result(self, result): - """Helper function to do the right thing with a result object""" - if result: - if result.sound: - result.sound.play() - if result.message: - # Display the message as a modal dialog - MessageDialog(result.message, 60).present() - # queue a redraw to show updated state - self.invalidate() - def mouse_down(self, event): if self.subwidgets: self.remove(self.detail) self.state.set_current_detail(None) else: result = self.state.interact(event.pos) - self._process_result(result) + if result: + result.process(self) def animate(self): if self.state.animate(): @@ -82,7 +71,8 @@ # We do this here so we can get enter and leave events regardless # of what happens result = self.state.check_enter_leave() - self._process_result(result) + if result: + result.process(self) def mouse_move(self, event): if not self.subwidgets: @@ -113,13 +103,7 @@ def mouse_down(self, event): result = self.state.interact_detail(self.global_to_local(event.pos)) if result: - if result.sound: - result.sound.play() - if result.message: - # Display the message as a modal dialog - MessageDialog(result.message, 60).present() - # queue a redraw to show updated state - self.invalidate() + result.process(self) def mouse_move(self, event): self.state.mouse_move_detail(event.pos) diff -r d3ca34a664fd -r f125bb60d7de gamelib/state.py --- a/gamelib/state.py Tue Aug 24 18:01:42 2010 +0200 +++ b/gamelib/state.py Tue Aug 24 18:05:27 2010 +0200 @@ -2,7 +2,7 @@ from albow.resource import get_image from albow.utils import frame_rect -from widgets import BoomLabel +from widgets import BoomLabel, MessageDialog from pygame.locals import BLEND_ADD from pygame.rect import Rect from pygame.color import Color @@ -20,6 +20,16 @@ if soundfile: self.sound = get_sound(soundfile) + def process(self, scene): + """Helper function to do the right thing with a result object""" + if self.sound: + self.sound.play() + if self.message: + # Display the message as a modal dialog + MessageDialog(self.message, 60).present() + # queue a redraw to show updated state + scene.invalidate() + def initial_state(): """Load the initial state."""