Mercurial > pyntnclick
changeset 126:f125bb60d7de
Move result handling to result object
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 18:05:27 +0200 |
parents | d3ca34a664fd |
children | 9646e7c8bb97 |
files | gamelib/gamescreen.py gamelib/state.py |
diffstat | 2 files changed, 16 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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."""