diff gamelib/gameboard.py @ 548:27c09c58d89d

Remove gameboard and dialog event flow hacks.
author Simon Cross <hodgestar@gmail.com>
date Sat, 28 Nov 2009 11:25:56 +0000
parents 84964077626a
children 11c4cebfe4c5
line wrap: on
line diff
--- a/gamelib/gameboard.py	Sat Nov 28 11:12:45 2009 +0000
+++ b/gamelib/gameboard.py	Sat Nov 28 11:25:56 2009 +0000
@@ -3,7 +3,7 @@
 import pygame
 from pygame.locals import MOUSEBUTTONDOWN, MOUSEMOTION, KEYDOWN, K_UP, K_DOWN, \
         K_LEFT, K_RIGHT, KMOD_SHIFT, K_0, K_1, K_2, K_3, K_4, K_5, K_6, K_7, \
-        K_8, K_9, KMOD_CTRL, KMOD_ALT, KEYUP
+        K_8, K_9, K_ESCAPE, K_n, K_d, KMOD_CTRL, KMOD_ALT, KEYUP
 from pgu import gui
 
 import tiles
@@ -41,8 +41,7 @@
         elif e.type == MOUSEMOTION and self.gameboard.sprite_cursor:
             self.gameboard.update_sprite_cursor(e)
         else:
-            return self.gameboard.event(e)
-        return True
+            return False
 
 
 class AnimalPositionCache(object):
@@ -192,6 +191,15 @@
         tbl.td(self.toolbar, valign=-1)
         self.tvw = VidWidget(self, self.tv, width=width-constants.TOOLBAR_WIDTH, height=height)
         tbl.td(self.tvw)
+
+        # we should probably create a custom widget to be the top widget
+        # if we want to flow some events to the gameboard
+        def event(e):
+            if gui.Table.event(tbl, e):
+                return True
+            return self.event(e)
+        tbl.event = event
+
         self.top_widget = tbl
         self.redraw_counters()
 
@@ -820,7 +828,23 @@
         dialog = self.open_dialog(tbl, x=x, y=y)
 
     def event(self, e):
-        if e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
+        if e.type == KEYDOWN and e.key == K_ESCAPE:
+            def sure(val):
+                if val:
+                    import engine
+                    pygame.event.post(engine.GO_GAME_OVER)
+            dialog = misc.CheckDialog(sure)
+            self.disp.open(dialog)
+            return True
+        elif e.type == KEYDOWN and e.key == K_n and self.day:
+            import engine
+            pygame.event.post(engine.START_NIGHT)
+            return True
+        elif e.type == KEYDOWN and e.key == K_d and self.night:
+            import engine
+            pygame.event.post(engine.FAST_FORWARD)
+            return True
+        elif e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
             if e.key == K_UP:
                 self.tvw.move_view(0, -constants.TILE_DIMENSIONS[1])
             if e.key == K_DOWN: