Mercurial > boomslang
annotate gamelib/scenes/game_widgets.py @ 681:497b6d7c55e7 pyntnclick
Reimplement JIM-style in gamelib
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sun, 12 Feb 2012 23:57:14 +0200 |
parents | c77d6aa29bee |
children | d6ded808cc33 |
rev | line source |
---|---|
242 | 1 """Generic, game specific widgets""" |
2 | |
263
3b4a78422201
Shuffled a bunch of stuff into more appropriate places.
Jeremy Thurgood <firxen@gmail.com>
parents:
252
diff
changeset
|
3 |
549 | 4 from pyntnclick.state import Thing, Result |
266
80cb577e38f2
Non-interactive things no longer highlight the cursor.
Jeremy Thurgood <firxen@gmail.com>
parents:
263
diff
changeset
|
5 |
681
497b6d7c55e7
Reimplement JIM-style in gamelib
Neil Muller <neil@dip.sun.ac.za>
parents:
655
diff
changeset
|
6 from gamelib.custom_widgets import JimLabel |
497b6d7c55e7
Reimplement JIM-style in gamelib
Neil Muller <neil@dip.sun.ac.za>
parents:
655
diff
changeset
|
7 |
242 | 8 |
9 class Door(Thing): | |
10 """A door somewhere""" | |
11 | |
12 DEST = "map" | |
252
dfc89bc64fdb
Start of walkthrough "unit test" and associated fixes and tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
242
diff
changeset
|
13 SCENE = None |
dfc89bc64fdb
Start of walkthrough "unit test" and associated fixes and tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
242
diff
changeset
|
14 |
dfc89bc64fdb
Start of walkthrough "unit test" and associated fixes and tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
242
diff
changeset
|
15 def __init__(self): |
dfc89bc64fdb
Start of walkthrough "unit test" and associated fixes and tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
242
diff
changeset
|
16 self.NAME = self.SCENE + '.door' |
dfc89bc64fdb
Start of walkthrough "unit test" and associated fixes and tweaks.
Jeremy Thurgood <firxen@gmail.com>
parents:
242
diff
changeset
|
17 Thing.__init__(self) |
242 | 18 |
519
8f3c82c685a4
Fix is_interactive() by adding tool param.
Jeremy Thurgood <firxen@gmail.com>
parents:
500
diff
changeset
|
19 def is_interactive(self, tool=None): |
242 | 20 return True |
21 | |
22 def interact_without(self): | |
23 """Go to map.""" | |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
549
diff
changeset
|
24 self.game.set_current_scene("map") |
242 | 25 |
26 def get_description(self): | |
27 return 'An open doorway leads to the rest of the ship.' | |
28 | |
29 def interact_default(self, item): | |
435 | 30 return self.interact_without() |
242 | 31 |
360
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
32 |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
33 def make_jim_dialog(mesg, game): |
360
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
34 "Utility helper function" |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
35 if game.data.get_jim_state() == 'online': |
681
497b6d7c55e7
Reimplement JIM-style in gamelib
Neil Muller <neil@dip.sun.ac.za>
parents:
655
diff
changeset
|
36 return Result(widget=JimLabel(game.gd, mesg)) |
360
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
37 else: |
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
38 return None |
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
39 |
452230d78541
Use make_jim_dialog everywhere
Neil Muller <neil@dip.sun.ac.za>
parents:
354
diff
changeset
|
40 |
350
125cb389ab90
Hook up poster. Add cameras to crew_quarters and bridge
Neil Muller <neil@dip.sun.ac.za>
parents:
296
diff
changeset
|
41 class BaseCamera(Thing): |
464 | 42 "Base class for the camera puzzles" |
499
cfd9c2bb4474
Make poster only work if JIM is online
Neil Muller <neil@dip.sun.ac.za>
parents:
464
diff
changeset
|
43 |
464 | 44 INITIAL = 'online' |
45 INITIAL_DATA = { | |
46 'state': 'online', | |
47 } | |
499
cfd9c2bb4474
Make poster only work if JIM is online
Neil Muller <neil@dip.sun.ac.za>
parents:
464
diff
changeset
|
48 |
464 | 49 def get_description(self): |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
50 status = self.state.get_jim_state() |
500
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
51 if status == 'online': |
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
52 return "A security camera watches over the room" |
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
53 elif status == 'looping': |
544 | 54 return "The security camera is currently offline but should be" \ |
55 " working soon" | |
500
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
56 else: |
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
57 return "The security camera is powered down" |
e49e4fe76241
Alter security camera description and is_interactive to match JIM's state
Stefano Rivera <stefano@rivera.za.net>
parents:
499
diff
changeset
|
58 |
519
8f3c82c685a4
Fix is_interactive() by adding tool param.
Jeremy Thurgood <firxen@gmail.com>
parents:
500
diff
changeset
|
59 def is_interactive(self, tool=None): |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
60 return self.state.get_jim_state() == 'online' |
499
cfd9c2bb4474
Make poster only work if JIM is online
Neil Muller <neil@dip.sun.ac.za>
parents:
464
diff
changeset
|
61 |
464 | 62 def interact_with_escher_poster(self, item): |
63 # Order matters here, because of helper function | |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
64 if self.state.get_jim_state() == 'online': |
544 | 65 ai_response = make_jim_dialog("3D scene reconstruction failed." |
66 " Critical error. Entering emergency shutdown.", | |
603
3ce19d33b51f
Rename state to game to not cause confusion with the other state
Neil Muller <neil@dip.sun.ac.za>
parents:
549
diff
changeset
|
67 self.game) |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
68 self.game.data.loop_ai() |
499
cfd9c2bb4474
Make poster only work if JIM is online
Neil Muller <neil@dip.sun.ac.za>
parents:
464
diff
changeset
|
69 return ai_response |
cfd9c2bb4474
Make poster only work if JIM is online
Neil Muller <neil@dip.sun.ac.za>
parents:
464
diff
changeset
|
70 |
464 | 71 def animate(self): |
655
c77d6aa29bee
Some code to kinda demonstrate the ever so cunning state handling plan
Neil Muller <neil@dip.sun.ac.za>
parents:
603
diff
changeset
|
72 ai_status = self.state.get_jim_state() |
464 | 73 if ai_status != self.get_data('status'): |
74 self.set_data('status', ai_status) | |
75 self.set_interact(ai_status) | |
76 super(BaseCamera, self).animate() |