Mercurial > pyntnclick
comparison gamelib/gamescreen.py @ 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 | a2f6e975af67 |
comparison
equal
deleted
inserted
replaced
125:d3ca34a664fd | 126:f125bb60d7de |
---|---|
13 from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE | 13 from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE |
14 from cursor import CursorWidget | 14 from cursor import CursorWidget |
15 from hand import HandButton | 15 from hand import HandButton |
16 from popupmenu import PopupMenu, PopupMenuButton | 16 from popupmenu import PopupMenu, PopupMenuButton |
17 from state import initial_state, Item | 17 from state import initial_state, Item |
18 from widgets import MessageDialog | |
19 | 18 |
20 | 19 |
21 class InventoryView(PaletteView): | 20 class InventoryView(PaletteView): |
22 | 21 |
23 sel_color = Color("yellow") | 22 sel_color = Color("yellow") |
54 self.detail = DetailWindow(state) | 53 self.detail = DetailWindow(state) |
55 | 54 |
56 def draw(self, surface): | 55 def draw(self, surface): |
57 self.state.draw(surface) | 56 self.state.draw(surface) |
58 | 57 |
59 def _process_result(self, result): | |
60 """Helper function to do the right thing with a result object""" | |
61 if result: | |
62 if result.sound: | |
63 result.sound.play() | |
64 if result.message: | |
65 # Display the message as a modal dialog | |
66 MessageDialog(result.message, 60).present() | |
67 # queue a redraw to show updated state | |
68 self.invalidate() | |
69 | |
70 def mouse_down(self, event): | 58 def mouse_down(self, event): |
71 if self.subwidgets: | 59 if self.subwidgets: |
72 self.remove(self.detail) | 60 self.remove(self.detail) |
73 self.state.set_current_detail(None) | 61 self.state.set_current_detail(None) |
74 else: | 62 else: |
75 result = self.state.interact(event.pos) | 63 result = self.state.interact(event.pos) |
76 self._process_result(result) | 64 if result: |
65 result.process(self) | |
77 | 66 |
78 def animate(self): | 67 def animate(self): |
79 if self.state.animate(): | 68 if self.state.animate(): |
80 # queue a redraw | 69 # queue a redraw |
81 self.invalidate() | 70 self.invalidate() |
82 # We do this here so we can get enter and leave events regardless | 71 # We do this here so we can get enter and leave events regardless |
83 # of what happens | 72 # of what happens |
84 result = self.state.check_enter_leave() | 73 result = self.state.check_enter_leave() |
85 self._process_result(result) | 74 if result: |
75 result.process(self) | |
86 | 76 |
87 def mouse_move(self, event): | 77 def mouse_move(self, event): |
88 if not self.subwidgets: | 78 if not self.subwidgets: |
89 self.state.mouse_move(event.pos) | 79 self.state.mouse_move(event.pos) |
90 | 80 |
111 self.state.draw_detail(surface.subsurface(self.image_rect)) | 101 self.state.draw_detail(surface.subsurface(self.image_rect)) |
112 | 102 |
113 def mouse_down(self, event): | 103 def mouse_down(self, event): |
114 result = self.state.interact_detail(self.global_to_local(event.pos)) | 104 result = self.state.interact_detail(self.global_to_local(event.pos)) |
115 if result: | 105 if result: |
116 if result.sound: | 106 result.process(self) |
117 result.sound.play() | |
118 if result.message: | |
119 # Display the message as a modal dialog | |
120 MessageDialog(result.message, 60).present() | |
121 # queue a redraw to show updated state | |
122 self.invalidate() | |
123 | 107 |
124 def mouse_move(self, event): | 108 def mouse_move(self, event): |
125 self.state.mouse_move_detail(event.pos) | 109 self.state.mouse_move_detail(event.pos) |
126 | 110 |
127 | 111 |