Mercurial > sypikslang
annotate gamelib/gamegui.py @ 262:6f96e28e6cfd pyweek final submission
Tweak text position
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 13 May 2012 01:55:08 +0200 |
parents | c949ac17cfd9 |
children | d2d1d9ccb22d |
rev | line source |
---|---|
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
3 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
4 """Gui for the actual game""" |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
5 |
88 | 6 try: |
7 import simplejson | |
8 json = simplejson | |
9 except ImportError: | |
10 import json | |
11 | |
57 | 12 |
243
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
13 from gamelib.data import load_image |
88 | 14 from gamelib.game_base import get_save_filename |
120
a79bba0dfcd8
Use TextBoxes for some stuff
Neil Muller <drnlmuller@gmail.com>
parents:
109
diff
changeset
|
15 from gamelib.gui_base import (Window, TextLabel, TextBox, font_small, |
a79bba0dfcd8
Use TextBoxes for some stuff
Neil Muller <drnlmuller@gmail.com>
parents:
109
diff
changeset
|
16 font_medium, font_large) |
145
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
17 from gamelib.gui import BigButton, ImageDrawable, IconTextButton |
98 | 18 from gamelib.engine import PopWindow, AddWindow, GameOver |
138
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
19 from gamelib.constants import WIDTH, HEIGHT, FAILURE, SUCCESS, GAME_WIN, INFO |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
20 from gamelib.gamestate import Game |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
21 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
22 |
109
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
23 def _lookup_reputation(rep): |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
24 """Turn reputation in a nice string""" |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
25 |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
26 if rep < 0: |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
27 return 'Mindless Thug' |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
28 if rep < 10: |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
29 return 'Fringe Lunatic' |
173 | 30 if rep < 20: |
31 return 'Batty Experimenter' | |
32 if rep < 50: | |
33 return 'Demented Analyst' | |
34 if rep < 70: | |
35 return 'Deranged Researcher' | |
36 if rep < 150: | |
109
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
37 return 'Mad Scientist' |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
38 return 'Major Threat to World Peace' |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
39 |
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
40 |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
41 class PopWindowButton(BigButton): |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
42 |
125
c224057befff
put 'End Turn' & 'Next Turn' buttons in the same place. Move 'Exit' button away from the action
Neil Muller <drnlmuller@gmail.com>
parents:
124
diff
changeset
|
43 def __init__(self, pos, text): |
c224057befff
put 'End Turn' & 'Next Turn' buttons in the same place. Move 'Exit' button away from the action
Neil Muller <drnlmuller@gmail.com>
parents:
124
diff
changeset
|
44 super(PopWindowButton, self).__init__(pos, text) |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
45 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
46 def on_click(self): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
47 PopWindow.post() |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
48 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
49 |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
50 class ExitGameButton(PopWindowButton): |
262 | 51 |
52 HEIGHT = 72 | |
53 | |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
54 def __init__(self): |
125
c224057befff
put 'End Turn' & 'Next Turn' buttons in the same place. Move 'Exit' button away from the action
Neil Muller <drnlmuller@gmail.com>
parents:
124
diff
changeset
|
55 super(ExitGameButton, self).__init__((WIDTH - 128, HEIGHT - 60), |
c224057befff
put 'End Turn' & 'Next Turn' buttons in the same place. Move 'Exit' button away from the action
Neil Muller <drnlmuller@gmail.com>
parents:
124
diff
changeset
|
56 'Exit') |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
57 |
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
58 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
59 class EndTurnButton(BigButton): |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
60 |
262 | 61 HEIGHT = 72 |
62 | |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
63 def __init__(self, parent): |
222 | 64 super(EndTurnButton, self).__init__(((WIDTH - 128), 0), 'End Turn') |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
65 self.parent = parent |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
66 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
67 def on_click(self): |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
68 self.parent.end_turn() |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
69 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
70 |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
71 class NextTurnButton(PopWindowButton): |
262 | 72 |
73 HEIGHT = 72 | |
74 | |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
75 def __init__(self): |
222 | 76 super(NextTurnButton, self).__init__(((WIDTH - 128), 0), 'Next Turn') |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
77 |
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
78 |
156 | 79 class AssignButton(PopWindowButton): |
262 | 80 |
81 HEIGHT = 72 | |
82 | |
156 | 83 def __init__(self, parent): |
222 | 84 super(AssignButton, self).__init__(((WIDTH - 128), 0), |
169
a6ca82fa9c4c
Rename several UI elements
Neil Muller <drnlmuller@gmail.com>
parents:
168
diff
changeset
|
85 'Assign Scheme') |
156 | 86 self.parent = parent |
87 | |
88 def on_click(self): | |
89 self.parent.accept() | |
90 super(AssignButton, self).on_click() | |
91 | |
92 | |
93 class CancelButton(PopWindowButton): | |
262 | 94 |
95 HEIGHT = 72 | |
96 | |
156 | 97 def __init__(self, parent): |
222 | 98 super(CancelButton, self).__init__(((WIDTH - 256), 0), |
169
a6ca82fa9c4c
Rename several UI elements
Neil Muller <drnlmuller@gmail.com>
parents:
168
diff
changeset
|
99 'Cancel Scheme') |
156 | 100 self.parent = parent |
101 | |
102 def on_click(self): | |
103 self.parent.cancel() | |
104 super(CancelButton, self).on_click() | |
127
591a85a4edac
Use 'done' rather than exit in equipment selection screen
Neil Muller <drnlmuller@gmail.com>
parents:
126
diff
changeset
|
105 |
591a85a4edac
Use 'done' rather than exit in equipment selection screen
Neil Muller <drnlmuller@gmail.com>
parents:
126
diff
changeset
|
106 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
107 class ResetButton(BigButton): |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
108 |
262 | 109 HEIGHT = 72 |
110 | |
169
a6ca82fa9c4c
Rename several UI elements
Neil Muller <drnlmuller@gmail.com>
parents:
168
diff
changeset
|
111 def __init__(self, parent, text='Clear calendars'): |
222 | 112 super(ResetButton, self).__init__((10, 0), text) |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
113 self.parent = parent |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
114 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
115 def on_click(self): |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
116 self.parent.do_reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
117 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
118 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
119 class SwitchWinButton(BigButton): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
120 |
262 | 121 HEIGHT = 72 |
122 | |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
123 def __init__(self, pos, text, new_window): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
124 super(SwitchWinButton, self).__init__(pos, text) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
125 self.new_window = new_window |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
126 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
127 def on_click(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
128 PopWindow.post() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
129 # Refresh state |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
130 self.new_window.update() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
131 AddWindow.post(self.new_window) |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
132 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
133 |
145
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
134 class ScienceWidget(IconTextButton): |
57 | 135 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
136 def __init__(self, science, pos, parent): |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
137 self.science = science |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
138 self.points = 0 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
139 self.parent = parent |
145
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
140 super(ScienceWidget, self).__init__( |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
141 pos, science.get_image_name(), self.make_text(), font_small) |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
142 |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
143 def make_text(self): |
212 | 144 #name = self.science.NAME[:4] |
145 name = self.science.NAME | |
145
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
146 text = '%s: %d' % (name, self.science.points) |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
147 if self.points > 0: |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
148 text = "%s + %d" % (text, self.points) |
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
149 return text |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
150 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
151 def on_click(self): |
63
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
62
diff
changeset
|
152 if (self.parent.game.get_available_points() > 0 and |
59
977224a5c663
Check can_spend in science button
Neil Muller <drnlmuller@gmail.com>
parents:
57
diff
changeset
|
153 self.science.can_spend(self.parent.game.lab, self.points + 1)): |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
154 self.points += 1 |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
155 self.parent.game.cur_allocation.append(self.science) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
156 self.parent.update_labels() |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
157 self.set_text() |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
158 |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
159 def set_text(self): |
145
53277724645b
Science button juggling.
Jeremy Thurgood <firxen@gmail.com>
parents:
139
diff
changeset
|
160 self.text = self.make_text() |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
161 self._draw_text() |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
162 |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
163 def reset(self): |
63
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
62
diff
changeset
|
164 while self.points > 0: |
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
62
diff
changeset
|
165 self.parent.game.cur_allocation.remove(self.science) |
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
62
diff
changeset
|
166 self.points -= 1 |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
167 self.set_text() |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
168 self.parent.update_labels() |
65 | 169 |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
170 def restore_selection(self, old_selection): |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
171 points = old_selection.count(self.science) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
172 # We skip things we cannot allocate enoigh points to (temp points |
128
6a847f22a312
Don't restore selections if they're illegal
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
173 # boosts, etc.) or we cannot currently develop further |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
174 if (points != self.points and |
128
6a847f22a312
Don't restore selections if they're illegal
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
175 points <= self.parent.game.get_available_points() and |
6a847f22a312
Don't restore selections if they're illegal
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
176 self.science.can_spend(self.parent.game.lab, |
6a847f22a312
Don't restore selections if they're illegal
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
177 self.points + points)): |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
178 self.points = points |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
179 self.parent.game.cur_allocation.extend([self.science] * points) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
180 self.parent.update_labels() |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
181 self.set_text() |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
182 |
65 | 183 |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
184 class MissionWidget(BigButton): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
185 |
187 | 186 WIDTH = 260 |
223 | 187 HEIGHT = 48 |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
188 |
243
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
189 BG_IMAGE_NORMAL = load_image('images/science_normal.png') |
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
190 BG_IMAGE_DOWN = load_image('images/science_down.png') |
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
191 BG_IMAGE_SELECTED = load_image('images/mission_selected.png') |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
192 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
193 def __init__(self, mission, pos, parent): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
194 self.mission = mission |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
195 self.parent = parent |
124
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
196 self.game = self.parent.game |
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
197 self.minions = 0 |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
198 super(MissionWidget, self).__init__(pos, '%s' % mission.NAME, |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
199 font_small) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
200 selected = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
201 self.BG_IMAGE_SELECTED) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
202 self.add_state('SELECTED', selected) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
203 self.mode = 'NORMAL' |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
204 self.equipment = [] |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
205 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
206 def on_mouse_cancel(self, pos): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
207 self.set_state(self.mode) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
208 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
209 def on_mouse_up(self, pos): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
210 self.set_state(self.mode) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
211 self.on_click() |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
212 |
156 | 213 def select(self): |
214 if not self.selected(): | |
215 self.game.minions -= self.minions | |
216 self.mode = 'SELECTED' | |
217 self.set_state(self.mode) | |
218 self.parent.update_labels() | |
219 | |
220 def unselect(self): | |
221 if self.selected(): | |
222 # Unassign the minions from the main game | |
223 self.game.minions += self.minions | |
224 self.reset() | |
225 | |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
226 def on_click(self): |
156 | 227 # select mission and equipment |
228 if self.game.minions > 0 or self.selected(): | |
229 if not self.selected(): | |
230 # Assign the minions automatically | |
231 self.minions = self.mission.MINIONS_REQUIRED | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
232 equip = EquipWindow(self.parent.screen, self.mission, |
124
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
233 self.game, self) |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
234 AddWindow.post(equip) |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
235 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
236 def selected(self): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
237 return self.mode == 'SELECTED' |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
238 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
239 def get_equipment(self): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
240 return self.equipment |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
241 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
242 def reset(self): |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
243 for equip in self.equipment: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
244 # Release funds |
124
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
245 self.game.money += equip.COST |
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
246 self.minions = 0 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
247 self.parent.update() |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
248 self.equipment = [] |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
249 self.mode = 'NORMAL' |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
250 self.set_state('NORMAL') |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
251 |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
252 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
253 class EquipWidget(BigButton): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
254 |
187 | 255 WIDTH = 260 |
223 | 256 HEIGHT = 48 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
257 |
243
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
258 BG_IMAGE_NORMAL = load_image('images/science_normal.png') |
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
259 BG_IMAGE_DOWN = load_image('images/science_down.png') |
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
260 BG_IMAGE_UNAVAILABLE = load_image('images/equip_grey.png') |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
261 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
262 def __init__(self, equip, pos, parent, copies, available): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
263 self.equip = equip |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
264 self.parent = parent |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
265 self.available = available |
196
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
266 super(EquipWidget, self).__init__(pos, '[%s : %d] - %d' |
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
267 % (equip.NAME, equip.points, equip.COST), font_small) |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
268 if not self.available: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
269 unavailable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
270 self.BG_IMAGE_UNAVAILABLE) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
271 # Override the default |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
272 self.add_state('NORMAL', unavailable) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
273 self.set_state('NORMAL') |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
274 self.equipment = [] |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
275 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
276 def on_mouse_down(self, pos): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
277 if self.available: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
278 super(EquipWidget, self).on_mouse_down(pos) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
279 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
280 def on_mouse_up(self, pos): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
281 if self.available: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
282 super(EquipWidget, self).on_mouse_up(pos) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
283 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
284 def on_click(self): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
285 self.parent.buy(self.equip) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
286 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
287 |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
288 class ValueLabel(TextLabel): |
65 | 289 |
161
6fdc985429a7
Display research advice.
Jeremy Thurgood <firxen@gmail.com>
parents:
156
diff
changeset
|
290 def __init__(self, pos, description, width=300): |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
291 self.description = description |
161
6fdc985429a7
Display research advice.
Jeremy Thurgood <firxen@gmail.com>
parents:
156
diff
changeset
|
292 rect = (pos[0], pos[1], width, 20) |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
293 super(ValueLabel, self).__init__(rect, |
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
294 '%s : 0' % description, font_medium, (255, 255, 0)) |
65 | 295 |
296 def set_value(self, value): | |
97
069a2d34b8b5
I shall pretend I did not touch the GUI, even though I added a myriad copies of some extra widgets.
Jeremy Thurgood <firxen@gmail.com>
parents:
93
diff
changeset
|
297 self.text = '%s : %s' % (self.description, value) |
65 | 298 self._draw_text() |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
299 |
60 | 300 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
301 class EquipWindow(Window): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
302 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
303 def __init__(self, screen, mission, game, parent): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
304 super(EquipWindow, self).__init__(screen) |
156 | 305 assign = AssignButton(self) |
306 self.add_child(assign) | |
307 cancel = CancelButton(self) | |
308 self.add_child(cancel) | |
169
a6ca82fa9c4c
Rename several UI elements
Neil Muller <drnlmuller@gmail.com>
parents:
168
diff
changeset
|
309 reset = ResetButton(self, 'Clear inventory') |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
310 self.add_child(reset) |
223 | 311 title = TextBox((170, 10, 370, 50), "Choose equipment for %s" |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
312 % mission.NAME, font_medium, (255, 255, 255)) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
313 self.add_child(title) |
223 | 314 self.description = TextBox((10, 60, 790, 20), |
192
57bf6a5e31cb
A rival appears on the scene
Neil Muller <drnlmuller@gmail.com>
parents:
187
diff
changeset
|
315 mission.get_description(), font_medium, (255, 255, 255)) |
156 | 316 self.add_child(self.description) |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
317 self.parent = parent |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
318 self.game = game |
225 | 319 self.money = ValueLabel((10, self.description.rect.height + 58), |
156 | 320 'Money') |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
321 self.money.set_value(self.game.money) |
225 | 322 self.minions = ValueLabel((310, self.description.rect.height + 58), |
156 | 323 'Minions Assigned') |
324 self.minions.set_value(self.parent.minions) | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
325 self.add_child(self.money) |
156 | 326 self.add_child(self.minions) |
223 | 327 inventory = TextLabel((10, self.description.rect.height + 75, 400, 20), |
156 | 328 'Current Inventory', font_medium, (255, 255, 255)) |
329 self.add_child(inventory) | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
330 self._equip = [] |
156 | 331 self._inventory = [] |
332 self._update_widgets() | |
333 | |
334 def cancel(self): | |
335 self.do_reset() | |
336 self.parent.unselect() | |
337 | |
338 def accept(self): | |
339 self.parent.select() | |
340 | |
341 def _update_widgets(self): | |
342 self._make_inventory() | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
343 self._make_equip_widgets() |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
344 |
156 | 345 def _make_inventory(self): |
346 for widget in self._inventory: | |
347 self.remove_child(widget) | |
348 self._inventory = [] | |
349 x = 10 | |
240 | 350 y = 100 + self.description.rect.height |
156 | 351 # collections.Counter is python 2.7. This is a bother |
352 equipment = sorted(set(self.parent.equipment), key=lambda x: x.NAME) | |
353 for equip in equipment: | |
354 count = self.parent.equipment.count(equip) | |
355 widget = TextLabel((x, y, 700, 15), '%s x %s' | |
196
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
356 % (equip.NAME, count), font_medium, (255, 255, 128)) |
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
357 x += 270 |
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
358 if x > WIDTH: |
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
359 x = 10 |
eb4516169b3c
Tweak inventory window layout
Neil Muller <drnlmuller@gmail.com>
parents:
192
diff
changeset
|
360 y += 18 |
156 | 361 self._inventory.append(widget) |
362 self.add_child(widget) | |
363 | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
364 def _make_equip_widgets(self): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
365 for widget in self._equip: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
366 self.remove_child(widget) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
367 self._equip = [] |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
368 x = 0 |
240 | 369 y = max(240, 100 + self.description.rect.height + |
370 18 * (len(self._inventory) // 3 + 1)) | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
371 available = self.game.get_available_equipment() |
215
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
372 for equip in sorted(self.game.get_all_equipment(), |
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
373 key=lambda x: x.NAME): |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
374 copies = self.parent.equipment.count(equip) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
375 widget = EquipWidget(equip, (x, y), self, copies, |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
376 equip in available) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
377 self._equip.append(widget) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
378 self.add_child(widget) |
187 | 379 x += widget.WIDTH + 10 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
380 if x >= WIDTH: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
381 x = 0 |
223 | 382 y += 45 |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
383 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
384 def buy(self, equip): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
385 self.game.money -= equip.COST |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
386 self.money.set_value(self.game.money) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
387 self.parent.equipment.append(equip) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
388 self.parent.parent.update() |
156 | 389 self._update_widgets() |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
390 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
391 def do_reset(self): |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
392 for equip in self.parent.equipment: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
393 # Release funds |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
394 self.game.money += equip.COST |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
395 self.money.set_value(self.game.money) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
396 self.parent.equipment = [] |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
397 self.parent.parent.update() |
156 | 398 self._update_widgets() |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
399 |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
400 |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
401 class ResultsWindow(Window): |
139 | 402 message_colours = { |
403 INFO: (60, 60, 255), | |
404 FAILURE: (255, 60, 60), | |
405 SUCCESS: (60, 255, 60), | |
406 } | |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
407 |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
408 def __init__(self, screen, messages, turn): |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
409 super(ResultsWindow, self).__init__(screen) |
122
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
410 nextbut = NextTurnButton() |
acf3af761bbc
Rename 'Exit' button on results view to 'Next Turn' for clarity.
Simon Cross <hodgestar@gmail.com>
parents:
120
diff
changeset
|
411 self.add_child(nextbut) |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
412 title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn, |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
413 font_medium, (255, 255, 255)) |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
414 self.add_child(title) |
98 | 415 self.is_game_over = False |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
416 if not messages: |
120
a79bba0dfcd8
Use TextBoxes for some stuff
Neil Muller <drnlmuller@gmail.com>
parents:
109
diff
changeset
|
417 results = TextBox((200, 200, 400, 50), |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
418 "Nothing of interest happened", font_medium, |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
419 (255, 255, 255)) |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
420 self.add_child(results) |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
421 else: |
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
422 y = 200 |
224
e4f9513c9dd0
Include mission name in the results
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
423 for mission, msg_type, msg, loot in messages: |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
424 # FIXME: Better widgets |
139 | 425 if msg_type == GAME_WIN: |
98 | 426 self._make_win_screen(turn, msg) |
427 self.is_game_over = True | |
428 break | |
139 | 429 colour = self.message_colours.get(msg_type, (255, 255, 255)) |
224
e4f9513c9dd0
Include mission name in the results
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
430 if mission: |
e4f9513c9dd0
Include mission name in the results
Neil Muller <drnlmuller@gmail.com>
parents:
223
diff
changeset
|
431 msg = '%s: %s' % (mission, msg) |
139 | 432 y = self.display_message(y, msg, loot, colour) |
138
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
433 |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
434 def display_message(self, y, msg, loot, colour, font=font_medium): |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
435 text = TextBox((50, y, 700, 25), msg, font, colour) |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
436 y += text.rect.height + 5 |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
437 self.add_child(text) |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
438 for kind, value in loot.items(): |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
439 y += self.display_loot_item(y, kind, value) |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
440 return y + 5 |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
441 |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
442 def display_loot_item(self, y, kind, value): |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
443 if hasattr(value, 'NAME'): |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
444 value = value.NAME |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
445 msg = "* %s: %s" % (kind, value) |
139 | 446 text = TextBox((80, y, 670, 25), msg, font_medium, (255, 255, 60)) |
138
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
447 self.add_child(text) |
14917385a0fd
Better handling of mission results and turn-end messages.
Jeremy Thurgood <firxen@gmail.com>
parents:
134
diff
changeset
|
448 return text.rect.height + 5 |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
449 |
98 | 450 def _make_win_screen(self, turn, msg): |
451 # Clear existing widgets, and turn this into a won screen | |
452 for child in self.children[:]: | |
453 self.remove_child(child) | |
245
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
454 # Replace background |
252 | 455 self.background_image = load_image('images/win_background.jpg') |
98 | 456 exitbut = ExitGameButton() |
245
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
457 # FIXME: 1:20 minutes to hackery here |
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
458 exitbut.rect.topleft = (500, 350) |
98 | 459 self.add_child(exitbut) |
245
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
460 title = TextLabel((500, 20, 200, 50), "Results for turn %d" % turn, |
98 | 461 font_medium, (255, 255, 255)) |
462 self.add_child(title) | |
245
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
463 won = TextBox((400, 200, 400, 50), "You've succeeded in your quest", |
98 | 464 font_large, (255, 255, 255)) |
465 self.add_child(won) | |
245
c39599854a2d
Better 'You've Won' Screen
Neil Muller <drnlmuller@gmail.com>
parents:
243
diff
changeset
|
466 won = TextBox((450, 250, 400, 50), msg, font_large, |
98 | 467 (255, 255, 255)) |
468 self.add_child(won) | |
469 | |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
470 |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
471 class GameStateWindow(Window): |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
472 """Base class for windows that show a lot of game state info""" |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
473 |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
474 def __init__(self, screen, game): |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
475 super(GameStateWindow, self).__init__(screen) |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
476 self.game = game |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
477 self.screen = screen |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
478 exitbut = ExitGameButton() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
479 self.add_child(exitbut) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
480 end_turn = EndTurnButton(self) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
481 self.add_child(end_turn) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
482 reset = ResetButton(self) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
483 self.add_child(reset) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
484 |
222 | 485 self.points = ValueLabel((10, 60), 'Blue-Sky Research Projects') |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
486 self.add_child(self.points) |
222 | 487 self.minions = ValueLabel((310, 60), 'Minions available') |
124
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
488 self.add_child(self.minions) |
222 | 489 self.money = ValueLabel((510, 60), 'Money') |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
490 self.add_child(self.money) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
491 |
222 | 492 self.milestone = ValueLabel((10, 80), 'Currently taken over') |
97
069a2d34b8b5
I shall pretend I did not touch the GUI, even though I added a myriad copies of some extra widgets.
Jeremy Thurgood <firxen@gmail.com>
parents:
93
diff
changeset
|
493 self.add_child(self.milestone) |
222 | 494 self.reputation = ValueLabel((310, 80), 'Reputation') |
97
069a2d34b8b5
I shall pretend I did not touch the GUI, even though I added a myriad copies of some extra widgets.
Jeremy Thurgood <firxen@gmail.com>
parents:
93
diff
changeset
|
495 self.add_child(self.reputation) |
069a2d34b8b5
I shall pretend I did not touch the GUI, even though I added a myriad copies of some extra widgets.
Jeremy Thurgood <firxen@gmail.com>
parents:
93
diff
changeset
|
496 |
222 | 497 self.advice = ValueLabel((10, 100), 'Research advice', width=780) |
161
6fdc985429a7
Display research advice.
Jeremy Thurgood <firxen@gmail.com>
parents:
156
diff
changeset
|
498 self.add_child(self.advice) |
6fdc985429a7
Display research advice.
Jeremy Thurgood <firxen@gmail.com>
parents:
156
diff
changeset
|
499 |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
500 def update_labels(self): |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
501 self.points.set_value(self.game.get_available_points()) |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
502 self.money.set_value(self.game.money) |
124
685301e35f88
Add a minion cost to missions
Neil Muller <drnlmuller@gmail.com>
parents:
122
diff
changeset
|
503 self.minions.set_value(self.game.minions) |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
504 self.milestone.set_value(self.game.milestone) |
109
5bb711cdc569
Display strings for reputation (needs more levels)
Neil Muller <drnlmuller@gmail.com>
parents:
107
diff
changeset
|
505 self.reputation.set_value(_lookup_reputation(self.game.reputation)) |
161
6fdc985429a7
Display research advice.
Jeremy Thurgood <firxen@gmail.com>
parents:
156
diff
changeset
|
506 self.advice.set_value(self.game.advice) |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
507 |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
508 |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
509 class ActivityWindow(GameStateWindow): |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
510 |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
511 def __init__(self, screen, lab, develop): |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
512 super(ActivityWindow, self).__init__(screen, lab.game) |
250 | 513 self.background_image = load_image('images/schemes_background.jpg') |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
514 self.lab = lab |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
515 self.develop = develop |
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
516 |
222 | 517 labbut = SwitchWinButton((150, 0), 'SCIENCE!!', lab) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
518 self.add_child(labbut) |
222 | 519 devbut = SwitchWinButton((300, 0), 'Engineering', develop) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
520 self.add_child(devbut) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
521 |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
522 self.update_labels() |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
523 self._missions = [] |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
524 self._make_widgets() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
525 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
526 def _make_widgets(self): |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
527 for widget in self._missions: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
528 self.remove_child(widget) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
529 self._missions = [] |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
530 x = 0 |
222 | 531 y = 130 |
215
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
532 for mission in sorted(self.game.get_available_missions(), |
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
533 key=lambda x: x.NAME): |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
534 widget = MissionWidget(mission, (x, y), self) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
535 self._missions.append(widget) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
536 self.add_child(widget) |
187 | 537 x += widget.WIDTH + 10 |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
538 if x >= WIDTH: |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
539 x = 0 |
217 | 540 y += 55 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
541 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
542 def end_turn(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
543 # Drop back to the research screen |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
544 PopWindow.post() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
545 self.lab.update() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
546 AddWindow.post(self.lab) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
547 self.lab.end_turn() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
548 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
549 def update_widgets(self): |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
550 self._make_widgets() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
551 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
552 def update(self): |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
553 self.update_labels() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
554 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
555 def do_reset(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
556 self.lab.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
557 self.develop.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
558 self.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
559 |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
560 def get_mission_list(self): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
561 selected_missions = [] |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
562 for widget in self._missions: |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
563 if widget.selected(): |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
564 equipment = widget.get_equipment() |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
565 mission = widget.mission |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
566 selected_missions.append((mission, equipment)) |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
567 return selected_missions |
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
568 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
569 def reset(self): |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
570 for widget in self._missions: |
168
be346a080548
Fix bug in resetting activity window
Neil Muller <drnlmuller@gmail.com>
parents:
161
diff
changeset
|
571 widget.unselect() |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
572 widget.reset() |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
573 self.update_labels() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
574 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
575 |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
576 class DevelopmentWindow(GameStateWindow): |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
577 """Window for handling schematics research""" |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
578 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
579 def __init__(self, screen, lab): |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
580 super(DevelopmentWindow, self).__init__(screen, lab.game) |
246 | 581 self.background_image = load_image('images/engineering_background.jpg') |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
582 self.lab = lab |
97
069a2d34b8b5
I shall pretend I did not touch the GUI, even though I added a myriad copies of some extra widgets.
Jeremy Thurgood <firxen@gmail.com>
parents:
93
diff
changeset
|
583 |
222 | 584 labbut = SwitchWinButton((150, 0), 'SCIENCE!!', lab) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
585 self.add_child(labbut) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
586 self.activity = None |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
587 |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
588 self.update_labels() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
589 self._sciences = [] |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
590 self._make_science_widgets() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
591 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
592 def set_activity_window(self, activity): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
593 # Oh, what tangled webs we weave |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
594 if not self.activity: |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
595 self.activity = activity |
257
c949ac17cfd9
Standardise button positions
Neil Muller <drnlmuller@gmail.com>
parents:
252
diff
changeset
|
596 actbut = SwitchWinButton((450, 0), 'Schemes', activity) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
597 self.add_child(actbut) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
598 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
599 def _make_science_widgets(self): |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
600 for widget in self._sciences: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
601 self.remove_child(widget) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
602 self._sciences = [] |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
603 x = 0 |
222 | 604 y = 130 |
215
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
605 for science in sorted(self.game.lab.science, key=lambda x: x.NAME): |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
606 if science.SCIENCE_TYPE == 'schematic': |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
607 widget = ScienceWidget(science, (x, y), self) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
608 self.add_child(widget) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
609 self._sciences.append(widget) |
212 | 610 x += widget.WIDTH + 10 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
611 if x >= WIDTH: |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
612 x = 0 |
222 | 613 y += widget.HEIGHT |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
614 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
615 def end_turn(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
616 # Drop back to the research screen |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
617 PopWindow.post() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
618 self.lab.update() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
619 AddWindow.post(self.lab) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
620 self.lab.end_turn() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
621 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
622 def update_widgets(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
623 self._make_science_widgets() |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
624 self.update_labels() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
625 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
626 def update(self): |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
627 self.update_labels() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
628 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
629 def do_reset(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
630 self.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
631 self.lab.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
632 self.activity.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
633 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
634 def reset(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
635 for widget in self._sciences: |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
636 widget.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
637 |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
638 def restore_selection(self, old_selection): |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
639 for widget in self._sciences: |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
640 widget.restore_selection(old_selection) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
641 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
642 |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
643 class LabWindow(GameStateWindow): |
63
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
62
diff
changeset
|
644 """Window for the research lab""" |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
645 |
88 | 646 def __init__(self, screen, game_dict): |
647 self.game = Game(game_dict) | |
106
5977a709f8c8
Refactor out a bunch of common gui code stuff (since Jermery's not touching this)
Neil Muller <drnlmuller@gmail.com>
parents:
98
diff
changeset
|
648 super(LabWindow, self).__init__(screen, self.game) |
88 | 649 self.autosave = get_save_filename() |
243
05afa7ae5df3
Standardise image loading to use data.load_image
Neil Muller <drnlmuller@gmail.com>
parents:
242
diff
changeset
|
650 self.background_image = load_image('images/lab_background.jpg') |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
651 |
134
208a79a49c26
Fix a ordering bug triggered when restoring a game
Neil Muller <drnlmuller@gmail.com>
parents:
133
diff
changeset
|
652 # Ensure we setup everything with the correct state set |
208a79a49c26
Fix a ordering bug triggered when restoring a game
Neil Muller <drnlmuller@gmail.com>
parents:
133
diff
changeset
|
653 self.game.start_turn() |
208a79a49c26
Fix a ordering bug triggered when restoring a game
Neil Muller <drnlmuller@gmail.com>
parents:
133
diff
changeset
|
654 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
655 self.develop = DevelopmentWindow(screen, self) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
656 self.activity = ActivityWindow(screen, self, self.develop) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
657 self.develop.set_activity_window(self.activity) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
658 |
257
c949ac17cfd9
Standardise button positions
Neil Muller <drnlmuller@gmail.com>
parents:
252
diff
changeset
|
659 devbut = SwitchWinButton((300, 0), 'Engineering', self.develop) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
660 self.add_child(devbut) |
257
c949ac17cfd9
Standardise button positions
Neil Muller <drnlmuller@gmail.com>
parents:
252
diff
changeset
|
661 actbut = SwitchWinButton((450, 0), 'Schemes', self.activity) |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
662 self.add_child(actbut) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
663 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
664 self._sciences = [] |
65 | 665 # Setup for the first turn |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
666 self.update_labels() |
60 | 667 self._make_science_widgets() |
668 | |
669 def _make_science_widgets(self): | |
82
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
670 # FIXME: Horrible hackery |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
671 for widget in self._sciences: |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
672 self.remove_child(widget) |
b0d97d51df51
Hook up simplistic equipment screen
Neil Muller <drnlmuller@gmail.com>
parents:
81
diff
changeset
|
673 self._sciences = [] |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
674 x = 0 |
222 | 675 y = 130 |
215
0a441ded8a83
Always sort widgets, so jumping through json doesn't change the order
Neil Muller <drnlmuller@gmail.com>
parents:
212
diff
changeset
|
676 for science in sorted(self.game.lab.science, key=lambda x: x.NAME): |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
677 if science.SCIENCE_TYPE == 'research': |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
678 widget = ScienceWidget(science, (x, y), self) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
679 self.add_child(widget) |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
680 self._sciences.append(widget) |
212 | 681 x += widget.WIDTH + 10 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
682 if x >= WIDTH: |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
683 x = 0 |
212 | 684 y += widget.HEIGHT + 5 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
685 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
686 def update_widgets(self): |
60 | 687 self._make_science_widgets() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
688 |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
689 def restore_selection(self, old_selection): |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
690 for widget in self._sciences: |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
691 widget.restore_selection(old_selection) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
692 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
693 def end_turn(self): |
72
8b06b07a1477
Very basic mission support
Neil Muller <drnlmuller@gmail.com>
parents:
67
diff
changeset
|
694 self.game.cur_missions = self.activity.get_mission_list() |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
695 old_allocation = self.game.cur_allocation |
80
a40a76012bd7
Refactor message handling so we can deal with in the gui
Neil Muller <drnlmuller@gmail.com>
parents:
72
diff
changeset
|
696 messages = self.game.end_turn() |
81
59afe9f92383
Hook up basic results screen
Neil Muller <drnlmuller@gmail.com>
parents:
80
diff
changeset
|
697 results = ResultsWindow(self.screen, messages, self.game.turn) |
98 | 698 if results.is_game_over: |
699 PopWindow.post() | |
700 GameOver.post(results) | |
701 return | |
107
bdd11db41124
Save at the right place.
Jeremy Thurgood <firxen@gmail.com>
parents:
106
diff
changeset
|
702 self.save_game() |
60 | 703 self.game.start_turn() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
704 self.update_widgets() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
705 self.develop.update_widgets() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
706 self.activity.update_widgets() |
126
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
707 # restore previous allocation |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
708 self.restore_selection(old_allocation) |
0f205b1384db
Make science allocation sticky
Neil Muller <drnlmuller@gmail.com>
parents:
125
diff
changeset
|
709 self.develop.restore_selection(old_allocation) |
133
e1142e2289d8
Ensure labels in the correct state
Neil Muller <drnlmuller@gmail.com>
parents:
128
diff
changeset
|
710 self.update_labels() |
e1142e2289d8
Ensure labels in the correct state
Neil Muller <drnlmuller@gmail.com>
parents:
128
diff
changeset
|
711 self.develop.update_labels() |
107
bdd11db41124
Save at the right place.
Jeremy Thurgood <firxen@gmail.com>
parents:
106
diff
changeset
|
712 AddWindow.post(results) |
bdd11db41124
Save at the right place.
Jeremy Thurgood <firxen@gmail.com>
parents:
106
diff
changeset
|
713 |
bdd11db41124
Save at the right place.
Jeremy Thurgood <firxen@gmail.com>
parents:
106
diff
changeset
|
714 def save_game(self): |
88 | 715 game_data = self.game.save_data() |
716 if self.autosave: | |
90
0823e2529c23
Add robustness around the savefile stuff
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
717 # Don't corrupt the savefile if json crashes |
0823e2529c23
Add robustness around the savefile stuff
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
718 data = json.dumps(game_data) |
88 | 719 savefile = open(self.autosave, 'w') |
90
0823e2529c23
Add robustness around the savefile stuff
Neil Muller <drnlmuller@gmail.com>
parents:
88
diff
changeset
|
720 savefile.write(data) |
88 | 721 savefile.close() |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
722 |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
723 def update(self): |
67
06c8539df478
Tweak label handling. Show money as well
Neil Muller <drnlmuller@gmail.com>
parents:
66
diff
changeset
|
724 self.update_labels() |
65 | 725 |
66
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
726 def do_reset(self): |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
727 self.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
728 self.develop.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
729 self.activity.reset() |
43b34b013462
Add development and activity screens
Neil Muller <drnlmuller@gmail.com>
parents:
65
diff
changeset
|
730 |
56
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
731 def reset(self): |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
732 for widget in self._sciences: |
78dfd429b9a6
Start adding science buttons
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
733 widget.reset() |