Mercurial > boomslang
annotate pyntnclick/gamescreen.py @ 639:fdc63049b08c pyntnclick
Add game_description to the widgets,, since it looks a useful thing to do
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sun, 12 Feb 2012 01:31:14 +0200 |
parents | c27087877c84 |
children | e81df1abf3b5 |
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 |
84
c76f2fad2af5
Draw CursorWidget on top of StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents:
83
diff
changeset
|
5 from pygame import Rect, mouse |
66
05346a412b55
A sprite cursor attempt
Stefano Rivera <stefano@rivera.za.net>
parents:
65
diff
changeset
|
6 from pygame.color import Color |
635
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
7 from pygame.locals import MOUSEBUTTONDOWN, MOUSEMOTION |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
8 |
551 | 9 from pyntnclick.cursor import CursorWidget |
600
fabce47e542f
Stop using albow (at least for the menu). Breaks the world. Please fix it, kthx
Stefano Rivera <stefano@rivera.za.net>
parents:
599
diff
changeset
|
10 from pyntnclick.engine import Screen |
553
ebb2efcb4ea7
Create a re-usable main function.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
551
diff
changeset
|
11 from pyntnclick.state import handle_result |
627 | 12 from pyntnclick.widgets.base import Widget, Container |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
13 |
576
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
553
diff
changeset
|
14 # 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
|
15 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
|
16 constants = GameConstants() |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
553
diff
changeset
|
17 SCREEN = constants.screen |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
553
diff
changeset
|
18 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
|
19 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
|
20 LEAVE = constants.leave |
1b1ab71535bd
Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents:
553
diff
changeset
|
21 |
201
9531a22721d1
Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents:
195
diff
changeset
|
22 |
613
44d4e3020874
Remove a lot of albow
Stefano Rivera <stefano@rivera.za.net>
parents:
603
diff
changeset
|
23 class InventoryView(Widget): |
44d4e3020874
Remove a lot of albow
Stefano Rivera <stefano@rivera.za.net>
parents:
603
diff
changeset
|
24 # TODO: Make this work again |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
25 |
40
9fdbfbc02a60
Minor build script and inventory fixes.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
26 sel_color = Color("yellow") |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
27 sel_width = 2 |
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
28 |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
29 def __init__(self, gd, screen): |
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
30 Widget.__init__(self, Rect((0, 0) + screen.surface_size), gd) |
407
c7a6846262e3
Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents:
401
diff
changeset
|
31 self.screen = screen |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
32 self.game = screen.game |
187
fbfd8e748ac0
Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents:
167
diff
changeset
|
33 self.state_widget = screen.state_widget |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
34 |
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
35 def num_items(self): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
36 return len(self.game.inventory) |
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 draw_item(self, surface, item_no, rect): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
39 item_image = self.game.inventory[item_no].get_inventory_image() |
411
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
40 surface.blit(item_image, rect, None) |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
41 |
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
42 def click_item(self, item_no, event): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
43 item = self.game.inventory[item_no] |
147
a039d3b81b3d
Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents:
144
diff
changeset
|
44 if self.item_is_selected(item_no): |
a039d3b81b3d
Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents:
144
diff
changeset
|
45 self.unselect() |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
46 elif item.is_interactive(self.game.tool): |
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
47 result = item.interact(self.game.tool) |
384
56a05ae56574
Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
358
diff
changeset
|
48 handle_result(result, self.state_widget) |
147
a039d3b81b3d
Deselect tools and get to the Mess.
Jeremy Thurgood <firxen@gmail.com>
parents:
144
diff
changeset
|
49 else: |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
50 self.game.set_tool(self.game.inventory[item_no]) |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
51 |
407
c7a6846262e3
Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents:
401
diff
changeset
|
52 def mouse_down(self, event): |
c7a6846262e3
Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents:
401
diff
changeset
|
53 if event.button != 1: |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
54 self.game.cancel_doodah(self.screen) |
407
c7a6846262e3
Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents:
401
diff
changeset
|
55 else: |
411
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
56 PaletteView.mouse_down(self, event) |
407
c7a6846262e3
Fix cursor handling after message dismissal.
Jeremy Thurgood <firxen@gmail.com>
parents:
401
diff
changeset
|
57 |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
58 def item_is_selected(self, item_no): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
59 return self.game.tool is self.game.inventory[item_no] |
26
0a68d137f509
Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents:
24
diff
changeset
|
60 |
36
31a431f795e1
Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
35
diff
changeset
|
61 def unselect(self): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
62 self.game.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
|
63 |
40
9fdbfbc02a60
Minor build script and inventory fixes.
Jeremy Thurgood <firxen@gmail.com>
parents:
36
diff
changeset
|
64 |
114
13d8cb1d5962
Better cursor handling using draw_all() and mouse_delta().
Jeremy Thurgood <firxen@gmail.com>
parents:
108
diff
changeset
|
65 class StateWidget(Widget): |
29
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
66 |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
67 def __init__(self, rect, gd, screen): |
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
68 Widget.__init__(self, rect, gd) |
187
fbfd8e748ac0
Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents:
167
diff
changeset
|
69 self.screen = screen |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
70 self.game = screen.game |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
71 self.detail = DetailWindow(rect, gd, screen) |
635
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
72 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down) |
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
73 self.add_callback(MOUSEMOTION, self.mouse_move) |
29
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
74 |
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
75 def draw(self, surface): |
616
25f3adbff00a
Note albow callbacks in GameScreen
Stefano Rivera <stefano@rivera.za.net>
parents:
615
diff
changeset
|
76 self.animate() |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
77 if self.game.previous_scene and self.game.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 |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
79 self.game.previous_scene.draw(surface, self) |
515
fda2b3a2f2e9
Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents:
512
diff
changeset
|
80 else: |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
81 self.game.current_scene.draw(surface, self) |
515
fda2b3a2f2e9
Remove drawing logic from State.
Jeremy Thurgood <firxen@gmail.com>
parents:
512
diff
changeset
|
82 |
635
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
83 def mouse_down(self, event, widget): |
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
84 self.mouse_move(event, widget) |
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 |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
86 self.game.cancel_doodah(self.screen) |
119
d5f7cccfdb6c
Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents:
114
diff
changeset
|
87 else: |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
88 result = self.game.interact(event.pos) |
201
9531a22721d1
Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents:
195
diff
changeset
|
89 handle_result(result, self) |
71
99c5506de7ea
Start of interact handling.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
70
diff
changeset
|
90 |
105
65976205fc2d
Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents:
100
diff
changeset
|
91 def animate(self): |
632
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
92 # XXX: if self.game.animate(): |
105
65976205fc2d
Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents:
100
diff
changeset
|
93 # queue a redraw |
632
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
94 # self.invalidate() |
120 | 95 # We do this here so we can get enter and leave events regardless |
96 # of what happens | |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
97 result = self.game.check_enter_leave(self.screen) |
201
9531a22721d1
Add support for lists of results
Neil Muller <neil@dip.sun.ac.za>
parents:
195
diff
changeset
|
98 handle_result(result, self) |
105
65976205fc2d
Rough Stab at basic animation support
Neil Muller <neil@dip.sun.ac.za>
parents:
100
diff
changeset
|
99 |
635
d9623d453fd9
Hook up events in StateWidget. (They still do nothing, though.)
Jeremy Thurgood <firxen@gmail.com>
parents:
634
diff
changeset
|
100 def mouse_move(self, event, widget): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
101 self.game.highlight_override = False |
637
c27087877c84
Mouse events propagate! Crashes galore!
Jeremy Thurgood <firxen@gmail.com>
parents:
635
diff
changeset
|
102 self.game.current_scene.mouse_move(event.pos) |
c27087877c84
Mouse events propagate! Crashes galore!
Jeremy Thurgood <firxen@gmail.com>
parents:
635
diff
changeset
|
103 self.game.old_pos = event.pos |
29
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
104 |
210
eb101b6fb3dd
Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents:
204
diff
changeset
|
105 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
|
106 # Display the message as a modal dialog |
627 | 107 print message |
108 # XXX: 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
|
109 # queue a redraw to show updated state |
632
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
110 # XXX: self.invalidate() |
139
a5972444ad1e
Improve cursor state handling, disable highlights on modal dialogs
Stefano Rivera <stefano@rivera.za.net>
parents:
137
diff
changeset
|
111 # The cursor could have gone anywhere |
632
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
112 # XXX: if self.subwidgets: |
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
113 # self.subwidgets[0]._mouse_move(mouse.get_pos()) |
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
114 # else: |
6ba418db1e84
XXX: now with even more bugs.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
630
diff
changeset
|
115 # 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
|
116 |
119
d5f7cccfdb6c
Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents:
114
diff
changeset
|
117 def show_detail(self, detail): |
384
56a05ae56574
Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
358
diff
changeset
|
118 self.clear_detail() |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
119 detail_obj = self.game.set_current_detail(detail) |
526
a984cf27b527
Defer some resource loading until it's actually necessary.
Jeremy Thurgood <firxen@gmail.com>
parents:
522
diff
changeset
|
120 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
|
121 self.add_centered(self.detail) |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
122 self.game.do_enter_detail() |
119
d5f7cccfdb6c
Hook up "detail view" scenes.
Jeremy Thurgood <firxen@gmail.com>
parents:
114
diff
changeset
|
123 |
204
407d23635343
Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents:
201
diff
changeset
|
124 def clear_detail(self): |
407d23635343
Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents:
201
diff
changeset
|
125 """Hide the detail view""" |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
126 if self.game.current_detail is not None: |
384
56a05ae56574
Initial manual implementation.
Jeremy Thurgood <firxen@gmail.com>
parents:
358
diff
changeset
|
127 self.remove(self.detail) |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
128 self.game.do_leave_detail() |
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
129 self.game.set_current_detail(None) |
397
b1dc0caec668
Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents:
384
diff
changeset
|
130 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
|
131 |
443
3dab4984cbd7
Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents:
411
diff
changeset
|
132 def end_game(self): |
460 | 133 self.screen.running = False |
443
3dab4984cbd7
Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents:
411
diff
changeset
|
134 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
|
135 |
66
05346a412b55
A sprite cursor attempt
Stefano Rivera <stefano@rivera.za.net>
parents:
65
diff
changeset
|
136 |
627 | 137 class DetailWindow(Container): |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
138 def __init__(self, rect, gd, screen): |
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
139 Container.__init__(self, rect, gd) |
476
c72946d3a59a
Some minor pylint driven style fixes
Neil Muller <neil@dip.sun.ac.za>
parents:
460
diff
changeset
|
140 self.image_rect = None |
187
fbfd8e748ac0
Remove screen reference from State.
Jeremy Thurgood <firxen@gmail.com>
parents:
167
diff
changeset
|
141 self.screen = screen |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
142 self.game = screen.game |
121
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
143 self.border_width = 5 |
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
144 self.border_color = (0, 0, 0) |
217
146cec58ddd8
Highlight detailed view close button
Neil Muller <neil@dip.sun.ac.za>
parents:
210
diff
changeset
|
145 # parent only gets set when we get added to the scene |
627 | 146 # XXX: self.close = BoomButton('Close', self.close_but, screen) |
147 # self.add(self.close) | |
204
407d23635343
Add a close button to the detail view
Neil Muller <neil@dip.sun.ac.za>
parents:
201
diff
changeset
|
148 |
217
146cec58ddd8
Highlight detailed view close button
Neil Muller <neil@dip.sun.ac.za>
parents:
210
diff
changeset
|
149 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
|
150 self.parent.clear_detail() |
121
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
151 |
443
3dab4984cbd7
Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents:
411
diff
changeset
|
152 def end_game(self): |
3dab4984cbd7
Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents:
411
diff
changeset
|
153 self.parent.end_game() |
3dab4984cbd7
Redo way of reaching end screen
Neil Muller <neil@dip.sun.ac.za>
parents:
411
diff
changeset
|
154 |
121
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
155 def set_image_rect(self, rect): |
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
156 bw = self.border_width |
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
157 self.image_rect = rect |
2f672e98d488
Added border to DetailWindow.
Jeremy Thurgood <firxen@gmail.com>
parents:
120
diff
changeset
|
158 self.image_rect.topleft = (bw, bw) |
529
a6f9b6edb6c7
PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents:
528
diff
changeset
|
159 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
|
160 self.close.rect.midbottom = rect.midbottom |
74
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
161 |
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
162 def draw(self, surface): |
398
1555677d86f6
Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
397
diff
changeset
|
163 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
|
164 overlay = scene_surface.convert_alpha() |
1555677d86f6
Dim non-interactive screen regions for "modal" stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
397
diff
changeset
|
165 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
|
166 scene_surface.blit(overlay, (0, 0)) |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
167 self.game.current_detail.draw( |
529
a6f9b6edb6c7
PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents:
528
diff
changeset
|
168 surface.subsurface(self.image_rect), self) |
93
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
169 |
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
170 def mouse_down(self, event): |
319
fd849354be58
Mouse handling refactorings.
Jeremy Thurgood <firxen@gmail.com>
parents:
314
diff
changeset
|
171 self.mouse_move(event) |
529
a6f9b6edb6c7
PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents:
528
diff
changeset
|
172 if event.button != 1: # We have a right/middle click |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
173 self.game.cancel_doodah(self.screen) |
397
b1dc0caec668
Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents:
384
diff
changeset
|
174 else: |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
175 result = self.game.interact_detail( |
529
a6f9b6edb6c7
PEP-8 gamescreen and state.
Jeremy Thurgood <firxen@gmail.com>
parents:
528
diff
changeset
|
176 self.global_to_local(event.pos)) |
397
b1dc0caec668
Improved mouse handling edge cases.
Jeremy Thurgood <firxen@gmail.com>
parents:
384
diff
changeset
|
177 handle_result(result, self) |
93
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
178 |
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
179 def mouse_move(self, event): |
160
a5a7bb2b4b9b
Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents:
147
diff
changeset
|
180 self._mouse_move(event.pos) |
a5a7bb2b4b9b
Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents:
147
diff
changeset
|
181 |
a5a7bb2b4b9b
Fix mouse_move() handling after dismissing message.
Jeremy Thurgood <firxen@gmail.com>
parents:
147
diff
changeset
|
182 def _mouse_move(self, pos): |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
183 self.game.highlight_override = False |
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
184 self.game.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
|
185 |
210
eb101b6fb3dd
Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents:
204
diff
changeset
|
186 def show_message(self, message, style=None): |
eb101b6fb3dd
Transparent message dialogs.
Jeremy Thurgood <firxen@gmail.com>
parents:
204
diff
changeset
|
187 self.parent.show_message(message, style) |
134
faac82748f5a
Put the leg inside the cryo unit.
Jeremy Thurgood <firxen@gmail.com>
parents:
133
diff
changeset
|
188 self.invalidate() |
faac82748f5a
Put the leg inside the cryo unit.
Jeremy Thurgood <firxen@gmail.com>
parents:
133
diff
changeset
|
189 |
93
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
190 |
613
44d4e3020874
Remove a lot of albow
Stefano Rivera <stefano@rivera.za.net>
parents:
603
diff
changeset
|
191 class ToolBar(Widget): |
93
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
192 def __init__(self, items): |
627 | 193 # XXX: ?o! |
194 Widget.__init__(self, Rect(0, 0, 100, 100)) | |
125
d3ca34a664fd
Some detail view and data cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
124
diff
changeset
|
195 for item in items: |
d3ca34a664fd
Some detail view and data cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
124
diff
changeset
|
196 item.height = BUTTON_SIZE |
411
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
197 self.bg_color = (31, 31, 31) |
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
198 |
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
199 def draw(self, surface): |
0fc208423b98
Fixed inventory drawing.
Jeremy Thurgood <firxen@gmail.com>
parents:
407
diff
changeset
|
200 surface.fill(self.bg_color) |
627 | 201 # Row.draw(self, surface) |
74
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
202 |
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
203 |
615 | 204 class GameScreen(Screen): |
205 | |
206 def setup(self): | |
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
|
207 self.running = False |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
208 self.create_initial_state = self.gd.initial_state |
29
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
209 |
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
|
210 def _clear_all(self): |
618
1a8dceccd98e
Use widget containers in _clear_all
Stefano Rivera <stefano@rivera.za.net>
parents:
616
diff
changeset
|
211 for widget in self.container.children[:]: |
1a8dceccd98e
Use widget containers in _clear_all
Stefano Rivera <stefano@rivera.za.net>
parents:
616
diff
changeset
|
212 self.container.remove(widget) |
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
|
213 |
619 | 214 def process_event(self, event_name, data): |
215 if event_name == 'restart': | |
216 self.start_game() | |
217 | |
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
|
218 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
|
219 self._clear_all() |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
220 toolbar_height = self.gd.constants.button_size |
634
b4007de091c5
Correct rect size for StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents:
632
diff
changeset
|
221 rect = Rect(0, 0, self.surface_size[0], |
b4007de091c5
Correct rect size for StateWidget
Stefano Rivera <stefano@rivera.za.net>
parents:
632
diff
changeset
|
222 self.surface_size[1] - toolbar_height) |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
600
diff
changeset
|
223 self.game = self.create_initial_state() |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
224 self.state_widget = StateWidget(rect, self.gd, self) |
627 | 225 self.container.add(self.state_widget) |
29
6322d92dc8f0
Add state widget for rendering state.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
28
diff
changeset
|
226 |
627 | 227 # XXX: self.popup_menu = PopupMenu(self) |
228 # XXX: self.menubutton = PopupMenuButton('Menu', | |
229 # action=self.popup_menu.show_menu) | |
74
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
230 |
627 | 231 # XXX: self.handbutton = HandButton(action=self.hand_pressed) |
74
75e1040a1121
Hacky "detail view" widget prototype.
Jeremy Thurgood <firxen@gmail.com>
parents:
73
diff
changeset
|
232 |
639
fdc63049b08c
Add game_description to the widgets,, since it looks a useful thing to do
Neil Muller <neil@dip.sun.ac.za>
parents:
637
diff
changeset
|
233 self.inventory = InventoryView(self.gd, self) |
93
350ce4ebe122
Detail view without any functionality.
Jeremy Thurgood <firxen@gmail.com>
parents:
84
diff
changeset
|
234 |
627 | 235 # XXX: self.toolbar = ToolBar([ |
236 # self.menubutton, | |
237 # self.handbutton, | |
238 # self.inventory, | |
239 # ]) | |
240 # XXX: self.toolbar.bottomleft = self.bottomleft | |
241 # self.container.add(self.toolbar) | |
93
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 |
616
25f3adbff00a
Note albow callbacks in GameScreen
Stefano Rivera <stefano@rivera.za.net>
parents:
615
diff
changeset
|
245 # albow callback: |
58 | 246 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
|
247 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
|
248 |
616
25f3adbff00a
Note albow callbacks in GameScreen
Stefano Rivera <stefano@rivera.za.net>
parents:
615
diff
changeset
|
249 # albow callback: |
69
d4bbb26099cc
Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
66
diff
changeset
|
250 def quit_cmd(self): |
d4bbb26099cc
Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
66
diff
changeset
|
251 self.shell.quit() |
d4bbb26099cc
Some debug object cleanup.
Jeremy Thurgood <firxen@gmail.com>
parents:
66
diff
changeset
|
252 |
36
31a431f795e1
Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
35
diff
changeset
|
253 def hand_pressed(self): |
31a431f795e1
Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
35
diff
changeset
|
254 self.inventory.unselect() |
31a431f795e1
Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
35
diff
changeset
|
255 |
599
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
256 |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
257 class DefEndScreen(Screen): |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
258 """A placeholder 'Game Over' screen so people can get started easily""" |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
259 |
600
fabce47e542f
Stop using albow (at least for the menu). Breaks the world. Please fix it, kthx
Stefano Rivera <stefano@rivera.za.net>
parents:
599
diff
changeset
|
260 def setup(self): |
625
85153f422522
Differently yuck get_image().
Jeremy Thurgood <firxen@gmail.com>
parents:
624
diff
changeset
|
261 self.background = self.resource.get_image('pyntnclick/end.png') |
599
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
262 |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
263 def draw(self, surface): |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
264 surface.blit(self.background, (0, 0)) |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
265 |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
266 |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
267 class DefMenuScreen(Screen): |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
268 """A placeholder Start screen so people can get started easily""" |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
269 |
600
fabce47e542f
Stop using albow (at least for the menu). Breaks the world. Please fix it, kthx
Stefano Rivera <stefano@rivera.za.net>
parents:
599
diff
changeset
|
270 def setup(self): |
625
85153f422522
Differently yuck get_image().
Jeremy Thurgood <firxen@gmail.com>
parents:
624
diff
changeset
|
271 self.background = self.resource.get_image('pyntnclick/start.png') |
599
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
272 |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
273 def draw(self, surface): |
2d2ea51b73ad
Move menu.py and endscreen.py to gamelib. Add default versions for new games
Neil Muller <neil@dip.sun.ac.za>
parents:
581
diff
changeset
|
274 surface.blit(self.background, (0, 0)) |