Mercurial > rinkhals
changeset 336:82a18615a0ab
Ask 'Are you sure?'
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 22:30:17 +0000 |
parents | efafe71dd261 |
children | e4059872ee59 |
files | TODO gamelib/engine.py gamelib/gameboard.py gamelib/misc.py |
diffstat | 4 files changed, 58 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO Sat Sep 05 22:27:13 2009 +0000 +++ b/TODO Sat Sep 05 22:30:17 2009 +0000 @@ -8,8 +8,6 @@ * Unix packaging (Hodgestar) -* Dialog for do you really want to give up. - == POST PYWEEK == * Add invalid cursor sprite
--- a/gamelib/engine.py Sat Sep 05 22:27:13 2009 +0000 +++ b/gamelib/engine.py Sat Sep 05 22:30:17 2009 +0000 @@ -9,6 +9,7 @@ import constants import mainmenu import helpscreen +from misc import check_exit class Engine(Game): def __init__(self, main_app): @@ -128,14 +129,24 @@ self.game.gameboard.clear_foxes() sound.background_music("daytime.ogg") self.game.gameboard.hatch_eggs() + self.dialog = None def event(self, e): + if self.dialog and self.dialog.running: + if self.dialog.event(e): + return + elif self.dialog: + if self.dialog.do_quit: + self.dialog = None + self.game.gameboard.reset_states() + return GameOver(self.game) + self.dialog=None + return if events_equal(e, START_NIGHT): self.game.gameboard.reset_states() return NightState(self.game) elif e.type is KEYDOWN and e.key == K_ESCAPE: - self.game.gameboard.reset_states() - return GameOver(self.game) + self.dialog = check_exit() elif e.type is ANIM_ID: self.game.gameboard.run_animations() elif e.type is KEYDOWN and e.key == K_n: @@ -188,8 +199,9 @@ pygame.time.set_timer(ANIM_ID, self.cycle_time) pygame.time.set_timer(MOVE_FOX_ID, 4*self.cycle_time) elif e.type is KEYDOWN and e.key == K_ESCAPE: - self.game.gameboard.set_cursor() - return GameOver(self.game) + if check_dialog(self.game.main_app): + self.game.gameboard.reset_states() + return GameOver(self.game) elif e.type is ANIM_ID: self.game.gameboard.run_animations() elif e.type is MOVE_FOX_ID:
--- a/gamelib/gameboard.py Sat Sep 05 22:27:13 2009 +0000 +++ b/gamelib/gameboard.py Sat Sep 05 22:30:17 2009 +0000 @@ -1091,3 +1091,5 @@ tbl.td(done_button, align=1) gui.Dialog.__init__(self, title_label, tbl, **params) + +
--- a/gamelib/misc.py Sat Sep 05 22:27:13 2009 +0000 +++ b/gamelib/misc.py Sat Sep 05 22:30:17 2009 +0000 @@ -2,6 +2,9 @@ import random +from pygame.locals import KEYDOWN, K_ESCAPE +from pgu import gui + class Position(object): """2D position / vector""" @@ -47,3 +50,40 @@ if roll < weight: return item roll -= weight + +class CheckDialog(gui.Dialog): + def __init__(self, **params): + title = gui.Label('Are You sure') + self.do_quit = False + self.running = True + tbl = gui.Table() + tbl.tr() + tbl.td(gui.Label("Do you REALLY want to exit this game?"), colspan=2) + tbl.tr() + tbl.td(gui.Spacer(0, 15), colspan=2) + tbl.tr() + yes_button = gui.Button('Yes') + yes_button.connect(gui.CLICK, self.clicked, True) + no_button = gui.Button('No') + no_button.connect(gui.CLICK, self.clicked, False) + tbl.td(no_button, align=-1) + tbl.td(yes_button, align=1) + gui.Dialog.__init__(self, title, tbl, **params) + + def clicked(self, val): + self.do_quit = val + self.running = False + self.close() + + def event(self, e): + if e.type == KEYDOWN and e.key == K_ESCAPE: + self.clicked(True) + return True + return gui.Dialog.event(self, e) + +def check_exit(): + dialog = CheckDialog() + dialog.open() + return dialog + +