Mercurial > rinkhals
comparison gamelib/toolbar.py @ 446:0c523d384681
Basic load and save dialogs.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 19:33:12 +0000 |
parents | feb9b7a23ef2 |
children | f04a2490c35f |
comparison
equal
deleted
inserted
replaced
445:af2482444945 | 446:0c523d384681 |
---|---|
204 close_button.connect(gui.CLICK, dialog.close) | 204 close_button.connect(gui.CLICK, dialog.close) |
205 dialog.open() | 205 dialog.open() |
206 | 206 |
207 def save_game(self): | 207 def save_game(self): |
208 """Save game 'dialog'.""" | 208 """Save game 'dialog'.""" |
209 data = self.gameboard.save_game() | 209 dialog = gui.FileDialog("Save game ...", button_txt="Save") |
210 open("foxassault.json", "wb").write(json.dumps(data)) | 210 |
211 def save(): | |
212 if dialog.value is None: | |
213 return | |
214 data = self.gameboard.save_game() | |
215 open(dialog.value, "wb").write(json.dumps(data)) | |
216 | |
217 dialog.connect(gui.CHANGE, save) | |
218 dialog.open() | |
211 | 219 |
212 def load_game(self): | 220 def load_game(self): |
213 """Load game 'dialog'.""" | 221 """Load game 'dialog'.""" |
214 data = json.loads(open("foxassault.json", "rb").read()) | 222 dialog = gui.FileDialog("Load game ...", button_txt="Load") |
215 self.gameboard.restore_game(data) | 223 |
224 def restore(): | |
225 if dialog.value is None: | |
226 return | |
227 data = json.loads(open(dialog.value, "rb").read()) | |
228 self.gameboard.restore_game(data) | |
229 | |
230 dialog.connect(gui.CHANGE, restore) | |
231 dialog.open() | |
216 | 232 |
217 update_cash_counter = mkcountupdate('cash_counter') | 233 update_cash_counter = mkcountupdate('cash_counter') |
218 update_wood_counter = mkcountupdate('wood_counter') | 234 update_wood_counter = mkcountupdate('wood_counter') |
219 update_fox_counter = mkcountupdate('killed_foxes') | 235 update_fox_counter = mkcountupdate('killed_foxes') |
220 update_chicken_counter = mkcountupdate('chicken_counter') | 236 update_chicken_counter = mkcountupdate('chicken_counter') |