comparison gamelib/gamescreen.py @ 119:d5f7cccfdb6c

Hook up "detail view" scenes.
author Jeremy Thurgood <firxen@gmail.com>
date Tue, 24 Aug 2010 17:04:56 +0200
parents 13d8cb1d5962
children 48d24a48d0ce
comparison
equal deleted inserted replaced
118:e548f4a13741 119:d5f7cccfdb6c
68 class StateWidget(Widget): 68 class StateWidget(Widget):
69 69
70 def __init__(self, state): 70 def __init__(self, state):
71 Widget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1])) 71 Widget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1]))
72 self.state = state 72 self.state = state
73 self.detail = DetailWindow(state)
73 74
74 def draw(self, surface): 75 def draw(self, surface):
75 self.state.draw(surface) 76 self.state.draw(surface)
76 77
77 def mouse_down(self, event): 78 def mouse_down(self, event):
78 result = self.state.interact(event.pos) 79 if self.subwidgets:
79 if result: 80 self.remove(self.detail)
80 if result.sound: 81 self.state.set_current_detail(None)
81 result.sound.play() 82 else:
82 if result.message: 83 result = self.state.interact(event.pos)
83 # Display the message as a modal dialog 84 if result:
84 MessageDialog(result.message, 60).present() 85 if result.sound:
85 # queue a redraw to show updated state 86 result.sound.play()
86 self.invalidate() 87 if result.message:
88 # Display the message as a modal dialog
89 MessageDialog(result.message, 60).present()
90 # queue a redraw to show updated state
91 self.invalidate()
87 92
88 def animate(self): 93 def animate(self):
89 if self.state.animate(): 94 if self.state.animate():
90 # queue a redraw 95 # queue a redraw
91 self.invalidate() 96 self.invalidate()
92 97
93 def mouse_move(self, event): 98 def mouse_move(self, event):
94 if not self.subwidgets: 99 if not self.subwidgets:
95 self.state.mouse_move(event.pos) 100 self.state.mouse_move(event.pos)
96 101
102 def show_detail(self, detail):
103 w, h = self.state.set_current_detail(detail)
104 self.detail.set_rect(Rect(0, 0, w, h))
105 self.add_centered(self.detail)
106
97 107
98 class DetailWindow(Widget): 108 class DetailWindow(Widget):
99 def __init__(self, state): 109 def __init__(self, state):
100 Widget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1])) 110 Widget.__init__(self)
101 self.state = state 111 self.state = state
102 self.draw_area = Rect(0, 0, 300, 300)
103 self.draw_area.center = self.center
104 112
105 def draw(self, surface): 113 def draw(self, surface):
106 surface.fill(Color('green'), self.draw_area) 114 self.state.draw_detail(surface)
107 115
108 def mouse_down(self, event): 116 def mouse_down(self, event):
109 if self.draw_area.collidepoint(event.pos): 117 result = self.state.interact_detail(self.global_to_local(event.pos))
110 # TODO: Interact with detail view 118 if result:
111 pass 119 if result.sound:
112 else: 120 result.sound.play()
113 self.parent.remove(self) 121 if result.message:
122 # Display the message as a modal dialog
123 MessageDialog(result.message, 60).present()
124 # queue a redraw to show updated state
125 self.invalidate()
114 126
115 def mouse_move(self, event): 127 def mouse_move(self, event):
116 if self.draw_area.collidepoint(event.pos): 128 self.state.mouse_move_detail(event.pos)
117 # TODO: mouse_move stuff
118 pass
119 129
120 130
121 class ToolBar(Row): 131 class ToolBar(Row):
122 def __init__(self, items): 132 def __init__(self, items):
123 Row.__init__(self, items, spacing=0, width=SCREEN[0]) 133 Row.__init__(self, items, spacing=0, width=SCREEN[0])
146 156
147 self.handbutton = HandButton(action=self.hand_pressed) 157 self.handbutton = HandButton(action=self.hand_pressed)
148 158
149 self.inventory = InventoryView(self.state, self.handbutton) 159 self.inventory = InventoryView(self.state, self.handbutton)
150 160
151 self.testbutton = Button('Test', action=self.show_detail) 161 self.testbutton = Button('Test', lambda: self.state_widget.show_detail('cryo_detail'))
152 162
153 self.toolbar = ToolBar([ 163 self.toolbar = ToolBar([
154 self.menubutton, 164 self.menubutton,
155 self.handbutton, 165 self.handbutton,
156 self.inventory, 166 self.inventory,
157 self.testbutton, 167 self.testbutton,
158 ]) 168 ])
159 self.toolbar.bottomleft = self.bottomleft 169 self.toolbar.bottomleft = self.bottomleft
160 self.add(self.toolbar) 170 self.add(self.toolbar)
161 171
162 self.detail = DetailWindow(self.state)
163
164 self.running = True 172 self.running = True
165
166 def show_detail(self):
167 self.state_widget.add_centered(self.detail)
168 173
169 # Albow uses magic method names (command + '_cmd'). Yay. 174 # Albow uses magic method names (command + '_cmd'). Yay.
170 # Albow's search order means they need to be defined here, not in 175 # Albow's search order means they need to be defined here, not in
171 # PopMenu, which is annoying. 176 # PopMenu, which is annoying.
172 def hide_cmd(self): 177 def hide_cmd(self):