Mercurial > boomslang
comparison gamelib/gamescreen.py @ 63:3087be3463e0
Some framework support for better message handling
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 23 Aug 2010 18:32:15 +0200 |
parents | 9048cf43f613 |
children | cab924519037 |
comparison
equal
deleted
inserted
replaced
62:e32e2100ee52 | 63:3087be3463e0 |
---|---|
49 class StateWidget(Widget): | 49 class StateWidget(Widget): |
50 | 50 |
51 def __init__(self, state): | 51 def __init__(self, state): |
52 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) | 52 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) |
53 self.state = state | 53 self.state = state |
54 # current mouse-over thing description | |
55 self.description = None | |
54 | 56 |
55 def draw(self, surface): | 57 def draw(self, surface): |
56 self.state.draw(surface) | 58 self.state.draw(surface) |
59 if self.description: | |
60 print self.description | |
61 msg = self.state.get_message() | |
62 if msg: | |
63 # FIXME: add some timer to invalidate msgs | |
64 print msg | |
65 self.state.clear_message() | |
57 | 66 |
67 def mouse_move(self, event): | |
68 old_desc = self.description | |
69 self.description = self.state.get_description(event.pos) | |
70 if self.description != old_desc: | |
71 # queue a redraw | |
72 self.invalidate() | |
58 | 73 |
59 class GameScreen(Screen): | 74 class GameScreen(Screen): |
60 def __init__(self, shell): | 75 def __init__(self, shell): |
61 Screen.__init__(self, shell) | 76 Screen.__init__(self, shell) |
62 | 77 |
92 | 107 |
93 # Test items | 108 # Test items |
94 self.state.add_inventory_item('triangle') | 109 self.state.add_inventory_item('triangle') |
95 self.state.add_inventory_item('titanium_leg') | 110 self.state.add_inventory_item('titanium_leg') |
96 | 111 |
112 | |
97 # Albow uses magic method names (command + '_cmd'). Yay. | 113 # Albow uses magic method names (command + '_cmd'). Yay. |
98 # Albow's search order means they need to be defined here, not in | 114 # Albow's search order means they need to be defined here, not in |
99 # PopMenu, which is annoying. | 115 # PopMenu, which is annoying. |
100 def hide_cmd(self): | 116 def hide_cmd(self): |
101 # This option does nothing, but the method needs to exist for albow | 117 # This option does nothing, but the method needs to exist for albow |
109 | 125 |
110 def hand_pressed(self): | 126 def hand_pressed(self): |
111 self.handbutton.toggle_selected() | 127 self.handbutton.toggle_selected() |
112 self.inventory.unselect() | 128 self.inventory.unselect() |
113 | 129 |
130 |