comparison gamelib/gameboard.py @ 566:a8dde729000a

Add 'Save and Quit' option to quit dialog. Move game events from engine to constants to ease 'import engine' fun
author Neil Muller <drnlmuller@gmail.com>
date Sat, 28 Nov 2009 19:30:06 +0000
parents 32b6b66e114a
children 37f7454518d5
comparison
equal deleted inserted replaced
565:32b6b66e114a 566:a8dde729000a
16 import cursors 16 import cursors
17 import sprite_cursor 17 import sprite_cursor
18 import misc 18 import misc
19 import toolbar 19 import toolbar
20 import serializer 20 import serializer
21 import savegame
21 22
22 class VidWidget(gui.Widget): 23 class VidWidget(gui.Widget):
23 def __init__(self, gameboard, vid, **params): 24 def __init__(self, gameboard, vid, **params):
24 gui.Widget.__init__(self, **params) 25 gui.Widget.__init__(self, **params)
25 self.gameboard = gameboard 26 self.gameboard = gameboard
887 888
888 dialog = self.open_dialog(tbl, x=x, y=y) 889 dialog = self.open_dialog(tbl, x=x, y=y)
889 890
890 def event(self, e): 891 def event(self, e):
891 if e.type == KEYDOWN and e.key == K_ESCAPE: 892 if e.type == KEYDOWN and e.key == K_ESCAPE:
893 def check_saved(_widget):
894 if _widget.value:
895 # OK to quit, rely on pgu ordering that this happens in
896 # the right order
897 pygame.event.post(constants.GO_GAME_OVER)
898
892 def sure(val): 899 def sure(val):
893 if val: 900 if val == 2:
894 import engine 901 savedialog = savegame.SaveDialog(self)
895 pygame.event.post(engine.GO_GAME_OVER) 902 savedialog.connect(gui.CHANGE, check_saved)
903 savedialog.open()
904 elif val:
905 pygame.event.post(constants.GO_GAME_OVER)
906
896 dialog = misc.CheckDialog(sure, 907 dialog = misc.CheckDialog(sure,
897 "Do you REALLY want to exit this game?", 908 "Do you REALLY want to exit this game?",
898 "Yes, Quit", "No, Don't Quit", None) 909 "Yes, Quit", "No, Don't Quit", "Save & Quit")
899 self.disp.open(dialog) 910 self.disp.open(dialog)
900 return True 911 return True
901 elif e.type == KEYDOWN and e.key == K_n and self.day: 912 elif e.type == KEYDOWN and e.key == K_n and self.day:
902 import engine 913 pygame.event.post(constants.START_NIGHT)
903 pygame.event.post(engine.START_NIGHT)
904 return True 914 return True
905 elif e.type == KEYDOWN and e.key == K_d and self.night: 915 elif e.type == KEYDOWN and e.key == K_d and self.night:
906 import engine 916 pygame.event.post(constants.FAST_FORWARD)
907 pygame.event.post(engine.FAST_FORWARD)
908 return True 917 return True
909 elif e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: 918 elif e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
910 if e.key == K_UP: 919 if e.key == K_UP:
911 self.tvw.move_view(0, -constants.TILE_DIMENSIONS[1]) 920 self.tvw.move_view(0, -constants.TILE_DIMENSIONS[1])
912 if e.key == K_DOWN: 921 if e.key == K_DOWN:
1204 self.reset_states() 1213 self.reset_states()
1205 return serializer.simplify(self) 1214 return serializer.simplify(self)
1206 1215
1207 @staticmethod 1216 @staticmethod
1208 def restore_game(gameboard): 1217 def restore_game(gameboard):
1209 import engine 1218 pygame.event.post(pygame.event.Event(constants.DO_LOAD_SAVEGAME, gameboard=gameboard))
1210 pygame.event.post(pygame.event.Event(engine.DO_LOAD_SAVEGAME, gameboard=gameboard))
1211 1219
1212 1220
1213 class TextDialog(gui.Dialog): 1221 class TextDialog(gui.Dialog):
1214 def __init__(self, title, text, **params): 1222 def __init__(self, title, text, **params):
1215 title_label = gui.Label(title) 1223 title_label = gui.Label(title)