Mercurial > boomslang
comparison pyntnclick/gamescreen.py @ 627:8ff93e53c882 pyntnclick
XXX: this adds bugs.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Sat, 11 Feb 2012 22:13:56 +0200 |
parents | cc1085432faf |
children | a5f573002fb0 |
comparison
equal
deleted
inserted
replaced
626:cc1085432faf | 627:8ff93e53c882 |
---|---|
6 from pygame.color import Color | 6 from pygame.color import Color |
7 | 7 |
8 from pyntnclick.cursor import CursorWidget | 8 from pyntnclick.cursor import CursorWidget |
9 from pyntnclick.engine import Screen | 9 from pyntnclick.engine import Screen |
10 from pyntnclick.state import handle_result | 10 from pyntnclick.state import handle_result |
11 from pyntnclick.widgets.base import Widget | 11 from pyntnclick.widgets.base import Widget, Container |
12 from pyntnclick.widgets import ( | |
13 MessageDialog, BoomButton, HandButton, PopupMenu, PopupMenuButton) | |
14 | 12 |
15 # XXX: Need a way to get at the constants. | 13 # XXX: Need a way to get at the constants. |
16 from pyntnclick.constants import GameConstants | 14 from pyntnclick.constants import GameConstants |
17 constants = GameConstants() | 15 constants = GameConstants() |
18 SCREEN = constants.screen | 16 SCREEN = constants.screen |
25 # TODO: Make this work again | 23 # TODO: Make this work again |
26 | 24 |
27 sel_color = Color("yellow") | 25 sel_color = Color("yellow") |
28 sel_width = 2 | 26 sel_width = 2 |
29 | 27 |
30 def __init__(self, rect): | 28 def __init__(self, screen): |
29 Widget.__init__(self, Rect((0, 0) + screen.surface_size)) | |
31 self.screen = screen | 30 self.screen = screen |
32 self.game = screen.game | 31 self.game = screen.game |
33 self.state_widget = screen.state_widget | 32 self.state_widget = screen.state_widget |
34 | 33 |
35 def num_items(self): | 34 def num_items(self): |
108 self.game.current_scene.mouse_move(pos) | 107 self.game.current_scene.mouse_move(pos) |
109 self.game.old_pos = pos | 108 self.game.old_pos = pos |
110 | 109 |
111 def show_message(self, message, style=None): | 110 def show_message(self, message, style=None): |
112 # Display the message as a modal dialog | 111 # Display the message as a modal dialog |
113 MessageDialog(self.screen, message, 60, style=style).present() | 112 print message |
113 # XXX: MessageDialog(self.screen, message, 60, style=style).present() | |
114 # queue a redraw to show updated state | 114 # queue a redraw to show updated state |
115 self.invalidate() | 115 self.invalidate() |
116 # The cursor could have gone anywhere | 116 # The cursor could have gone anywhere |
117 if self.subwidgets: | 117 if self.subwidgets: |
118 self.subwidgets[0]._mouse_move(mouse.get_pos()) | 118 self.subwidgets[0]._mouse_move(mouse.get_pos()) |
137 def end_game(self): | 137 def end_game(self): |
138 self.screen.running = False | 138 self.screen.running = False |
139 self.screen.shell.show_screen(self.screen.shell.end_screen) | 139 self.screen.shell.show_screen(self.screen.shell.end_screen) |
140 | 140 |
141 | 141 |
142 class DetailWindow(Widget): | 142 class DetailWindow(Container): |
143 def __init__(self, screen): | 143 def __init__(self, screen): |
144 Widget.__init__(self) | 144 Container.__init__(self, Rect((0, 0) + screen.surface_size)) |
145 self.image_rect = None | 145 self.image_rect = None |
146 self.screen = screen | 146 self.screen = screen |
147 self.game = screen.game | 147 self.game = screen.game |
148 self.border_width = 5 | 148 self.border_width = 5 |
149 self.border_color = (0, 0, 0) | 149 self.border_color = (0, 0, 0) |
150 # parent only gets set when we get added to the scene | 150 # parent only gets set when we get added to the scene |
151 self.close = BoomButton('Close', self.close_but, screen) | 151 # XXX: self.close = BoomButton('Close', self.close_but, screen) |
152 self.add(self.close) | 152 # self.add(self.close) |
153 | 153 |
154 def close_but(self): | 154 def close_but(self): |
155 self.parent.clear_detail() | 155 self.parent.clear_detail() |
156 | 156 |
157 def end_game(self): | 157 def end_game(self): |
193 self.invalidate() | 193 self.invalidate() |
194 | 194 |
195 | 195 |
196 class ToolBar(Widget): | 196 class ToolBar(Widget): |
197 def __init__(self, items): | 197 def __init__(self, items): |
198 # XXX: ?o! | |
199 Widget.__init__(self, Rect(0, 0, 100, 100)) | |
198 for item in items: | 200 for item in items: |
199 item.height = BUTTON_SIZE | 201 item.height = BUTTON_SIZE |
200 self.bg_color = (31, 31, 31) | 202 self.bg_color = (31, 31, 31) |
201 | 203 |
202 def draw(self, surface): | 204 def draw(self, surface): |
203 surface.fill(self.bg_color) | 205 surface.fill(self.bg_color) |
204 Row.draw(self, surface) | 206 # Row.draw(self, surface) |
205 | 207 |
206 | 208 |
207 class GameScreen(Screen): | 209 class GameScreen(Screen): |
208 | 210 |
209 def setup(self): | 211 def setup(self): |
220 | 222 |
221 def start_game(self): | 223 def start_game(self): |
222 self._clear_all() | 224 self._clear_all() |
223 self.game = self.create_initial_state() | 225 self.game = self.create_initial_state() |
224 self.state_widget = StateWidget(self) | 226 self.state_widget = StateWidget(self) |
225 self.add(self.state_widget) | 227 self.container.add(self.state_widget) |
226 | 228 |
227 self.popup_menu = PopupMenu(self) | 229 # XXX: self.popup_menu = PopupMenu(self) |
228 self.menubutton = PopupMenuButton('Menu', | 230 # XXX: self.menubutton = PopupMenuButton('Menu', |
229 action=self.popup_menu.show_menu) | 231 # action=self.popup_menu.show_menu) |
230 | 232 |
231 self.handbutton = HandButton(action=self.hand_pressed) | 233 # XXX: self.handbutton = HandButton(action=self.hand_pressed) |
232 | 234 |
233 self.inventory = InventoryView(self) | 235 self.inventory = InventoryView(self) |
234 | 236 |
235 self.toolbar = ToolBar([ | 237 # XXX: self.toolbar = ToolBar([ |
236 self.menubutton, | 238 # self.menubutton, |
237 self.handbutton, | 239 # self.handbutton, |
238 self.inventory, | 240 # self.inventory, |
239 ]) | 241 # ]) |
240 self.toolbar.bottomleft = self.bottomleft | 242 # XXX: self.toolbar.bottomleft = self.bottomleft |
241 self.add(self.toolbar) | 243 # self.container.add(self.toolbar) |
242 | 244 |
243 self.running = True | 245 self.running = True |
244 | 246 |
245 # albow callback: | 247 # albow callback: |
246 def main_menu_cmd(self): | 248 def main_menu_cmd(self): |