Mercurial > boomslang
comparison pyntnclick/gamescreen.py @ 643:e81df1abf3b5 pyntnclick
Make detail windows display (not work, but display)
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sun, 12 Feb 2012 02:08:59 +0200 |
parents | fdc63049b08c |
children | 4aae15dedc29 |
comparison
equal
deleted
inserted
replaced
642:143c67501c79 | 643:e81df1abf3b5 |
---|---|
8 | 8 |
9 from pyntnclick.cursor import CursorWidget | 9 from pyntnclick.cursor import CursorWidget |
10 from pyntnclick.engine import Screen | 10 from pyntnclick.engine import Screen |
11 from pyntnclick.state import handle_result | 11 from pyntnclick.state import handle_result |
12 from pyntnclick.widgets.base import Widget, Container | 12 from pyntnclick.widgets.base import Widget, Container |
13 from pyntnclick.widgets.text import TextButton | |
13 | 14 |
14 # XXX: Need a way to get at the constants. | 15 # XXX: Need a way to get at the constants. |
15 from pyntnclick.constants import GameConstants | 16 from pyntnclick.constants import GameConstants |
16 constants = GameConstants() | 17 constants = GameConstants() |
17 SCREEN = constants.screen | 18 SCREEN = constants.screen |
25 | 26 |
26 sel_color = Color("yellow") | 27 sel_color = Color("yellow") |
27 sel_width = 2 | 28 sel_width = 2 |
28 | 29 |
29 def __init__(self, gd, screen): | 30 def __init__(self, gd, screen): |
30 Widget.__init__(self, Rect((0, 0) + screen.surface_size), gd) | 31 super(InventoryView, self).__init__(Rect((0, 0) + screen.surface_size), |
32 gd) | |
31 self.screen = screen | 33 self.screen = screen |
32 self.game = screen.game | 34 self.game = screen.game |
33 self.state_widget = screen.state_widget | 35 self.state_widget = screen.state_widget |
34 | 36 |
35 def num_items(self): | 37 def num_items(self): |
60 | 62 |
61 def unselect(self): | 63 def unselect(self): |
62 self.game.set_tool(None) | 64 self.game.set_tool(None) |
63 | 65 |
64 | 66 |
65 class StateWidget(Widget): | 67 class StateWidget(Container): |
66 | 68 |
67 def __init__(self, rect, gd, screen): | 69 def __init__(self, rect, gd, screen): |
68 Widget.__init__(self, rect, gd) | 70 super(StateWidget, self).__init__(rect, gd) |
69 self.screen = screen | 71 self.screen = screen |
70 self.game = screen.game | 72 self.game = screen.game |
71 self.detail = DetailWindow(rect, gd, screen) | 73 self.detail = DetailWindow(rect, gd, screen) |
72 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down) | 74 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down) |
73 self.add_callback(MOUSEMOTION, self.mouse_move) | 75 self.add_callback(MOUSEMOTION, self.mouse_move) |
74 | 76 |
75 def draw(self, surface): | 77 def draw(self, surface): |
76 self.animate() | 78 self.game.current_scene.draw(surface, self) |
77 if self.game.previous_scene and self.game.do_check == LEAVE: | 79 # Pass to container to draw children |
78 # We still need to handle leave events, so still display the scene | 80 super(StateWidget, self).draw(surface) |
79 self.game.previous_scene.draw(surface, self) | 81 #self.animate() |
80 else: | 82 # XXX: Work out if we still need this |
81 self.game.current_scene.draw(surface, self) | 83 # if self.game.previous_scene and self.game.do_check == LEAVE: |
84 # # We still need to handle leave events, so still display the scene | |
85 # self.game.previous_scene.draw(surface, self) | |
86 #else: | |
87 # self.game.current_scene.draw(surface, self) | |
82 | 88 |
83 def mouse_down(self, event, widget): | 89 def mouse_down(self, event, widget): |
84 self.mouse_move(event, widget) | 90 self.mouse_move(event, widget) |
85 if event.button != 1: # We have a right/middle click | 91 if event.button != 1: # We have a right/middle click |
86 self.game.cancel_doodah(self.screen) | 92 self.game.cancel_doodah(self.screen) |
116 | 122 |
117 def show_detail(self, detail): | 123 def show_detail(self, detail): |
118 self.clear_detail() | 124 self.clear_detail() |
119 detail_obj = self.game.set_current_detail(detail) | 125 detail_obj = self.game.set_current_detail(detail) |
120 self.detail.set_image_rect(Rect((0, 0), detail_obj.get_detail_size())) | 126 self.detail.set_image_rect(Rect((0, 0), detail_obj.get_detail_size())) |
121 self.add_centered(self.detail) | 127 self.add(self.detail) |
122 self.game.do_enter_detail() | 128 self.game.do_enter_detail() |
123 | 129 |
124 def clear_detail(self): | 130 def clear_detail(self): |
125 """Hide the detail view""" | 131 """Hide the detail view""" |
126 if self.game.current_detail is not None: | 132 if self.game.current_detail is not None: |
127 self.remove(self.detail) | 133 self.remove(self.detail) |
128 self.game.do_leave_detail() | 134 self.game.do_leave_detail() |
129 self.game.set_current_detail(None) | 135 self.game.set_current_detail(None) |
130 self._mouse_move(mouse.get_pos()) | 136 #self._mouse_move(mouse.get_pos()) |
131 | 137 |
132 def end_game(self): | 138 def end_game(self): |
133 self.screen.running = False | 139 self.screen.running = False |
134 self.screen.shell.show_screen(self.screen.shell.end_screen) | 140 self.screen.shell.show_screen(self.screen.shell.end_screen) |
135 | 141 |
136 | 142 |
137 class DetailWindow(Container): | 143 class DetailWindow(Container): |
138 def __init__(self, rect, gd, screen): | 144 def __init__(self, rect, gd, screen): |
139 Container.__init__(self, rect, gd) | 145 super(DetailWindow, self).__init__(rect, gd) |
140 self.image_rect = None | 146 self.image_rect = None |
141 self.screen = screen | 147 self.screen = screen |
142 self.game = screen.game | 148 self.game = screen.game |
143 self.border_width = 5 | 149 self.border_width = 5 |
144 self.border_color = (0, 0, 0) | 150 self.border_color = (0, 0, 0) |
145 # parent only gets set when we get added to the scene | 151 # parent only gets set when we get added to the scene |
146 # XXX: self.close = BoomButton('Close', self.close_but, screen) | 152 self.close = TextButton(Rect(0, 0, 0, 0), self.gd, |
147 # self.add(self.close) | 153 text='Close') |
148 | 154 self.close.add_callback('clicked', self.close_but) |
149 def close_but(self): | 155 self.add(self.close) |
156 | |
157 def close_but(self, ev, widget): | |
150 self.parent.clear_detail() | 158 self.parent.clear_detail() |
151 | 159 |
152 def end_game(self): | 160 def end_game(self): |
153 self.parent.end_game() | 161 self.parent.end_game() |
154 | 162 |
155 def set_image_rect(self, rect): | 163 def set_image_rect(self, rect): |
156 bw = self.border_width | 164 bw = self.border_width |
157 self.image_rect = rect | 165 self.image_rect = rect |
158 self.image_rect.topleft = (bw, bw) | 166 self.image_rect.topleft = (bw, bw) |
159 self.set_rect(rect.inflate(bw * 2, bw * 2)) | 167 self.rect = rect.inflate(bw * 2, bw * 2) |
160 self.close.rect.midbottom = rect.midbottom | 168 self.close.rect.midbottom = rect.midbottom |
161 | 169 |
162 def draw(self, surface): | 170 def draw(self, surface): |
163 scene_surface = self.get_root().surface.subsurface(self.parent.rect) | 171 # scene_surface = self.get_root().surface.subsurface(self.parent.rect) |
164 overlay = scene_surface.convert_alpha() | 172 # overlay = scene_surface.convert_alpha() |
165 overlay.fill(Color(0, 0, 0, 191)) | 173 # overlay.fill(Color(0, 0, 0, 191)) |
166 scene_surface.blit(overlay, (0, 0)) | 174 # scene_surface.blit(overlay, (0, 0)) |
167 self.game.current_detail.draw( | 175 self.game.current_detail.draw( |
168 surface.subsurface(self.image_rect), self) | 176 surface.subsurface(self.image_rect), self) |
177 super(DetailWindow, self).draw(surface) | |
169 | 178 |
170 def mouse_down(self, event): | 179 def mouse_down(self, event): |
171 self.mouse_move(event) | 180 self.mouse_move(event) |
172 if event.button != 1: # We have a right/middle click | 181 if event.button != 1: # We have a right/middle click |
173 self.game.cancel_doodah(self.screen) | 182 self.game.cancel_doodah(self.screen) |
189 | 198 |
190 | 199 |
191 class ToolBar(Widget): | 200 class ToolBar(Widget): |
192 def __init__(self, items): | 201 def __init__(self, items): |
193 # XXX: ?o! | 202 # XXX: ?o! |
194 Widget.__init__(self, Rect(0, 0, 100, 100)) | 203 super(ToolBar, self).__init__(Rect(0, 0, 100, 100)) |
195 for item in items: | 204 for item in items: |
196 item.height = BUTTON_SIZE | 205 item.height = BUTTON_SIZE |
197 self.bg_color = (31, 31, 31) | 206 self.bg_color = (31, 31, 31) |
198 | 207 |
199 def draw(self, surface): | 208 def draw(self, surface): |