annotate pyntnclick/gamescreen.py @ 576:1b1ab71535bd pyntnclick

Classify constants, which involves a whole bunch of XXX comments
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 11 Feb 2012 16:02:06 +0200
parents ebb2efcb4ea7
children 7e4a20eb78b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
ad6f56bfa8b7 Cryo door, titanium leg and some interaction prototypes.
Jeremy Thurgood <firxen@gmail.com>
parents: 40
diff changeset
1 # gamescreen.py
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
2 # Copyright Boomslang team, 2010 (see COPYING File)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
3 # Main menu for the game
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
4
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
5 from albow.controls import Widget
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
6 from albow.layout import Row
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
7 from albow.palette_view import PaletteView
84
c76f2fad2af5 Draw CursorWidget on top of StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents: 83
diff changeset
8 from albow.screen import Screen
c76f2fad2af5 Draw CursorWidget on top of StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents: 83
diff changeset
9 from pygame import Rect, mouse
66
05346a412b55 A sprite cursor attempt
Stefano Rivera <stefano@rivera.za.net>
parents: 65
diff changeset
10 from pygame.color import Color
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
11
551
38fb04728ac5 Rearrange import.
Jeremy Thurgood <firxen@gmail.com>
parents: 548
diff changeset
12 from pyntnclick.cursor import CursorWidget
553
ebb2efcb4ea7 Create a re-usable main function.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 551
diff changeset
13 from pyntnclick.state import handle_result
551
38fb04728ac5 Rearrange import.
Jeremy Thurgood <firxen@gmail.com>
parents: 548
diff changeset
14 from pyntnclick.widgets import (
38fb04728ac5 Rearrange import.
Jeremy Thurgood <firxen@gmail.com>
parents: 548
diff changeset
15 MessageDialog, BoomButton, HandButton, PopupMenu, PopupMenuButton)
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
16
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
17 # XXX: Need a way to get at the constants.
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
18 from pyntnclick.constants import GameConstants
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
19 constants = GameConstants()
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
20 SCREEN = constants.screen
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
21 BUTTON_SIZE = constants.button_size
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
22 SCENE_SIZE = constants.scene_size
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
23 LEAVE = constants.leave
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 553
diff changeset
24
201
9531a22721d1 Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents: 195
diff changeset
25
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
26 class InventoryView(PaletteView):
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
27
40
9fdbfbc02a60 Minor build script and inventory fixes.
Jeremy Thurgood <firxen@gmail.com>
parents: 36
diff changeset
28 sel_color = Color("yellow")
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
29 sel_width = 2
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
30
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
31 def __init__(self, screen):
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
32 PaletteView.__init__(self, (BUTTON_SIZE, BUTTON_SIZE), 1, 6,
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
33 scrolling=True)
407
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
34 self.screen = screen
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
35 self.state = screen.state
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
36 self.state_widget = screen.state_widget
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
37
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
38 def num_items(self):
34
e5c043aeed65 Inventory and items. And stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 29
diff changeset
39 return len(self.state.inventory)
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
40
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
41 def draw_item(self, surface, item_no, rect):
40
9fdbfbc02a60 Minor build script and inventory fixes.
Jeremy Thurgood <firxen@gmail.com>
parents: 36
diff changeset
42 item_image = self.state.inventory[item_no].get_inventory_image()
411
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
43 surface.blit(item_image, rect, None)
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
44
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
45 def click_item(self, item_no, event):
384
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
46 item = self.state.inventory[item_no]
147
a039d3b81b3d Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents: 144
diff changeset
47 if self.item_is_selected(item_no):
a039d3b81b3d Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents: 144
diff changeset
48 self.unselect()
519
8f3c82c685a4 Fix is_interactive() by adding tool param.
Jeremy Thurgood <firxen@gmail.com>
parents: 517
diff changeset
49 elif item.is_interactive(self.state.tool):
512
b10dae40dc32 Fix items.
Jeremy Thurgood <firxen@gmail.com>
parents: 476
diff changeset
50 result = item.interact(self.state.tool)
384
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
51 handle_result(result, self.state_widget)
147
a039d3b81b3d Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents: 144
diff changeset
52 else:
384
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
53 self.state.set_tool(self.state.inventory[item_no])
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
54
407
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
55 def mouse_down(self, event):
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
56 if event.button != 1:
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
57 self.state.cancel_doodah(self.screen)
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
58 else:
411
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
59 PaletteView.mouse_down(self, event)
407
c7a6846262e3 Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 401
diff changeset
60
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
61 def item_is_selected(self, item_no):
73
932b0956e77a Make tools usable.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 71
diff changeset
62 return self.state.tool is self.state.inventory[item_no]
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
63
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents: 35
diff changeset
64 def unselect(self):
73
932b0956e77a Make tools usable.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 71
diff changeset
65 self.state.set_tool(None)
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
66
40
9fdbfbc02a60 Minor build script and inventory fixes.
Jeremy Thurgood <firxen@gmail.com>
parents: 36
diff changeset
67
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
68 class StateWidget(Widget):
29
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
69
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
70 def __init__(self, screen):
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
71 Widget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1]))
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
72 self.screen = screen
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
73 self.state = screen.state
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
74 self.detail = DetailWindow(screen)
29
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
75
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
76 def draw(self, surface):
517
26f9b4d10e3e Remove mouse motion logic from GameState.
Jeremy Thurgood <firxen@gmail.com>
parents: 515
diff changeset
77 if self.state.previous_scene and self.state.do_check == LEAVE:
515
fda2b3a2f2e9 Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 512
diff changeset
78 # We still need to handle leave events, so still display the scene
fda2b3a2f2e9 Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 512
diff changeset
79 self.state.previous_scene.draw(surface, self)
fda2b3a2f2e9 Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 512
diff changeset
80 else:
fda2b3a2f2e9 Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 512
diff changeset
81 self.state.current_scene.draw(surface, self)
fda2b3a2f2e9 Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 512
diff changeset
82
71
99c5506de7ea Start of interact handling.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 70
diff changeset
83 def mouse_down(self, event):
319
fd849354be58 Mouse handling refactorings.
Jeremy Thurgood <firxen@gmail.com>
parents: 314
diff changeset
84 self.mouse_move(event)
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
85 if event.button != 1: # We have a right/middle click
397
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
86 self.state.cancel_doodah(self.screen)
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
87 elif self.subwidgets:
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
88 self.clear_detail()
161
5184d30669b5 Fix handling of state on detail view dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
89 self._mouse_move(event.pos)
119
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
90 else:
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
91 result = self.state.interact(event.pos)
201
9531a22721d1 Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents: 195
diff changeset
92 handle_result(result, self)
71
99c5506de7ea Start of interact handling.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 70
diff changeset
93
105
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
94 def animate(self):
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
95 if self.state.animate():
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
96 # queue a redraw
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
97 self.invalidate()
120
48d24a48d0ce Enter and leave hooks
Neil Muller <neil@dip.sun.ac.za>
parents: 119
diff changeset
98 # We do this here so we can get enter and leave events regardless
48d24a48d0ce Enter and leave hooks
Neil Muller <neil@dip.sun.ac.za>
parents: 119
diff changeset
99 # of what happens
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
100 result = self.state.check_enter_leave(self.screen)
201
9531a22721d1 Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents: 195
diff changeset
101 handle_result(result, self)
105
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
102
63
3087be3463e0 Some framework support for better message handling
Neil Muller <neil@dip.sun.ac.za>
parents: 58
diff changeset
103 def mouse_move(self, event):
324
3476e8f3b100 Fixed mouse and cursor handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 319
diff changeset
104 self.state.highlight_override = False
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
105 if not self.subwidgets:
160
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
106 self._mouse_move(event.pos)
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
107
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
108 def _mouse_move(self, pos):
324
3476e8f3b100 Fixed mouse and cursor handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 319
diff changeset
109 self.state.highlight_override = False
517
26f9b4d10e3e Remove mouse motion logic from GameState.
Jeremy Thurgood <firxen@gmail.com>
parents: 515
diff changeset
110 self.state.current_scene.mouse_move(pos)
26f9b4d10e3e Remove mouse motion logic from GameState.
Jeremy Thurgood <firxen@gmail.com>
parents: 515
diff changeset
111 self.state.old_pos = pos
29
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
112
210
eb101b6fb3dd Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents: 204
diff changeset
113 def show_message(self, message, style=None):
133
0530547a131f Better map handling, detail_view stuff in Result.
Jeremy Thurgood <firxen@gmail.com>
parents: 129
diff changeset
114 # Display the message as a modal dialog
210
eb101b6fb3dd Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents: 204
diff changeset
115 MessageDialog(self.screen, message, 60, style=style).present()
133
0530547a131f Better map handling, detail_view stuff in Result.
Jeremy Thurgood <firxen@gmail.com>
parents: 129
diff changeset
116 # queue a redraw to show updated state
0530547a131f Better map handling, detail_view stuff in Result.
Jeremy Thurgood <firxen@gmail.com>
parents: 129
diff changeset
117 self.invalidate()
139
a5972444ad1e Improve cursor state handling, disable highlights on modal dialogs
Stefano Rivera <stefano@rivera.za.net>
parents: 137
diff changeset
118 # The cursor could have gone anywhere
160
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
119 if self.subwidgets:
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
120 self.subwidgets[0]._mouse_move(mouse.get_pos())
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
121 else:
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
122 self._mouse_move(mouse.get_pos())
133
0530547a131f Better map handling, detail_view stuff in Result.
Jeremy Thurgood <firxen@gmail.com>
parents: 129
diff changeset
123
119
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
124 def show_detail(self, detail):
384
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
125 self.clear_detail()
526
a984cf27b527 Defer some resource loading until it's actually necessary.
Jeremy Thurgood <firxen@gmail.com>
parents: 522
diff changeset
126 detail_obj = self.state.set_current_detail(detail)
a984cf27b527 Defer some resource loading until it's actually necessary.
Jeremy Thurgood <firxen@gmail.com>
parents: 522
diff changeset
127 self.detail.set_image_rect(Rect((0, 0), detail_obj.get_detail_size()))
119
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
128 self.add_centered(self.detail)
314
63e702d93e0e Call detail enter and leave hooks
Neil Muller <neil@dip.sun.ac.za>
parents: 264
diff changeset
129 self.state.do_enter_detail()
119
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
130
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
131 def clear_detail(self):
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
132 """Hide the detail view"""
384
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
133 if self.state.current_detail is not None:
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
134 self.remove(self.detail)
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
135 self.state.do_leave_detail()
56a05ae56574 Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents: 358
diff changeset
136 self.state.set_current_detail(None)
397
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
137 self._mouse_move(mouse.get_pos())
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
138
443
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
139 def end_game(self):
460
59f719cfccea Properly stop running
Neil Muller <neil@dip.sun.ac.za>
parents: 449
diff changeset
140 self.screen.running = False
443
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
141 self.screen.shell.show_screen(self.screen.shell.end_screen)
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
142
66
05346a412b55 A sprite cursor attempt
Stefano Rivera <stefano@rivera.za.net>
parents: 65
diff changeset
143
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
144 class DetailWindow(Widget):
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
145 def __init__(self, screen):
119
d5f7cccfdb6c Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents: 114
diff changeset
146 Widget.__init__(self)
476
c72946d3a59a Some minor pylint driven style fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 460
diff changeset
147 self.image_rect = None
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
148 self.screen = screen
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
149 self.state = screen.state
121
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
150 self.border_width = 5
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
151 self.border_color = (0, 0, 0)
217
146cec58ddd8 Highlight detailed view close button
Neil Muller <neil@dip.sun.ac.za>
parents: 210
diff changeset
152 # parent only gets set when we get added to the scene
146cec58ddd8 Highlight detailed view close button
Neil Muller <neil@dip.sun.ac.za>
parents: 210
diff changeset
153 self.close = BoomButton('Close', self.close_but, screen)
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
154 self.add(self.close)
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
155
217
146cec58ddd8 Highlight detailed view close button
Neil Muller <neil@dip.sun.ac.za>
parents: 210
diff changeset
156 def close_but(self):
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
157 self.parent.clear_detail()
121
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
158
443
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
159 def end_game(self):
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
160 self.parent.end_game()
3dab4984cbd7 Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents: 411
diff changeset
161
121
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
162 def set_image_rect(self, rect):
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
163 bw = self.border_width
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
164 self.image_rect = rect
2f672e98d488 Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents: 120
diff changeset
165 self.image_rect.topleft = (bw, bw)
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
166 self.set_rect(rect.inflate(bw * 2, bw * 2))
204
407d23635343 Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents: 201
diff changeset
167 self.close.rect.midbottom = rect.midbottom
74
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
168
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
169 def draw(self, surface):
398
1555677d86f6 Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 397
diff changeset
170 scene_surface = self.get_root().surface.subsurface(self.parent.rect)
1555677d86f6 Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 397
diff changeset
171 overlay = scene_surface.convert_alpha()
1555677d86f6 Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 397
diff changeset
172 overlay.fill(Color(0, 0, 0, 191))
1555677d86f6 Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 397
diff changeset
173 scene_surface.blit(overlay, (0, 0))
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
174 self.state.current_detail.draw(
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
175 surface.subsurface(self.image_rect), self)
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
176
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
177 def mouse_down(self, event):
319
fd849354be58 Mouse handling refactorings.
Jeremy Thurgood <firxen@gmail.com>
parents: 314
diff changeset
178 self.mouse_move(event)
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
179 if event.button != 1: # We have a right/middle click
397
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
180 self.state.cancel_doodah(self.screen)
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
181 else:
529
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
182 result = self.state.interact_detail(
a6f9b6edb6c7 PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents: 528
diff changeset
183 self.global_to_local(event.pos))
397
b1dc0caec668 Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents: 384
diff changeset
184 handle_result(result, self)
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
185
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
186 def mouse_move(self, event):
160
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
187 self._mouse_move(event.pos)
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
188
a5a7bb2b4b9b Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents: 147
diff changeset
189 def _mouse_move(self, pos):
324
3476e8f3b100 Fixed mouse and cursor handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 319
diff changeset
190 self.state.highlight_override = False
517
26f9b4d10e3e Remove mouse motion logic from GameState.
Jeremy Thurgood <firxen@gmail.com>
parents: 515
diff changeset
191 self.state.current_detail.mouse_move(self.global_to_local(pos))
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
192
210
eb101b6fb3dd Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents: 204
diff changeset
193 def show_message(self, message, style=None):
eb101b6fb3dd Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents: 204
diff changeset
194 self.parent.show_message(message, style)
134
faac82748f5a Put the leg inside the cryo unit.
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
195 self.invalidate()
faac82748f5a Put the leg inside the cryo unit.
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
196
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
197
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
198 class ToolBar(Row):
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
199 def __init__(self, items):
125
d3ca34a664fd Some detail view and data cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents: 124
diff changeset
200 for item in items:
d3ca34a664fd Some detail view and data cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents: 124
diff changeset
201 item.height = BUTTON_SIZE
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
202 Row.__init__(self, items, spacing=0, width=SCREEN[0])
411
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
203 self.bg_color = (31, 31, 31)
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
204
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
205 def draw(self, surface):
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
206 surface.fill(self.bg_color)
0fc208423b98 Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 407
diff changeset
207 Row.draw(self, surface)
74
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
208
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
209
114
13d8cb1d5962 Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents: 108
diff changeset
210 class GameScreen(Screen, CursorWidget):
553
ebb2efcb4ea7 Create a re-usable main function.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 551
diff changeset
211 def __init__(self, shell, create_initial_state):
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
212 CursorWidget.__init__(self, self)
84
c76f2fad2af5 Draw CursorWidget on top of StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents: 83
diff changeset
213 Screen.__init__(self, shell)
100
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
214 self.running = False
553
ebb2efcb4ea7 Create a re-usable main function.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 551
diff changeset
215 self.create_initial_state = create_initial_state
29
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
216
100
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
217 def _clear_all(self):
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
218 for widget in self.subwidgets[:]:
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
219 self.remove(widget)
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
220
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
221 def start_game(self):
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
222 self._clear_all()
553
ebb2efcb4ea7 Create a re-usable main function.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 551
diff changeset
223 self.state = self.create_initial_state()
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
224 self.state_widget = StateWidget(self)
29
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
225 self.add(self.state_widget)
6322d92dc8f0 Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 28
diff changeset
226
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
227 self.popup_menu = PopupMenu(self)
70
213e47dea4d0 Funkier cursor handling
Neil Muller <neil@dip.sun.ac.za>
parents: 69
diff changeset
228 self.menubutton = PopupMenuButton('Menu',
213e47dea4d0 Funkier cursor handling
Neil Muller <neil@dip.sun.ac.za>
parents: 69
diff changeset
229 action=self.popup_menu.show_menu)
74
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
230
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents: 35
diff changeset
231 self.handbutton = HandButton(action=self.hand_pressed)
74
75e1040a1121 Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents: 73
diff changeset
232
187
fbfd8e748ac0 Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents: 167
diff changeset
233 self.inventory = InventoryView(self)
93
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
234
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
235 self.toolbar = ToolBar([
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
236 self.menubutton,
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
237 self.handbutton,
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
238 self.inventory,
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
239 ])
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
240 self.toolbar.bottomleft = self.bottomleft
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
241 self.add(self.toolbar)
350ce4ebe122 Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents: 84
diff changeset
242
100
b5b6cbf556e6 Make start new game start a new game. Add Resume to main menu
Neil Muller <neil@dip.sun.ac.za>
parents: 99
diff changeset
243 self.running = True
34
e5c043aeed65 Inventory and items. And stuff.
Jeremy Thurgood <firxen@gmail.com>
parents: 29
diff changeset
244
144
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
245 def enter_screen(self):
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
246 CursorWidget.enter_screen(self)
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
247
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
248 def leave_screen(self):
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
249 CursorWidget.leave_screen(self)
29ba5456e8b3 Removed a bunch of cruft.
Jeremy Thurgood <firxen@gmail.com>
parents: 139
diff changeset
250
58
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
251 # Albow uses magic method names (command + '_cmd'). Yay.
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
252 # Albow's search order means they need to be defined here, not in
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
253 # PopMenu, which is annoying.
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
254 def hide_cmd(self):
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
255 # This option does nothing, but the method needs to exist for albow
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
256 return
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
257
9048cf43f613 Popup menu
Neil Muller <neil@dip.sun.ac.za>
parents: 54
diff changeset
258 def main_menu_cmd(self):
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
259 self.shell.show_screen(self.shell.menu_screen)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
260
69
d4bbb26099cc Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents: 66
diff changeset
261 def quit_cmd(self):
d4bbb26099cc Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents: 66
diff changeset
262 self.shell.quit()
d4bbb26099cc Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents: 66
diff changeset
263
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents: 35
diff changeset
264 def hand_pressed(self):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents: 35
diff changeset
265 self.inventory.unselect()
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents: 35
diff changeset
266
105
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
267 def begin_frame(self):
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
268 if self.running:
65976205fc2d Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 100
diff changeset
269 self.state_widget.animate()