changeset 320:9bf0e701a36e

Switch between 'Finished Day' and 'Fast Forward' modes
author Neil Muller <drnlmuller@gmail.com>
date Sat, 05 Sep 2009 19:26:01 +0000
parents 61f6233bcf0f
children 306b20f3546c
files gamelib/engine.py gamelib/gameboard.py
diffstat 2 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/engine.py	Sat Sep 05 19:22:58 2009 +0000
+++ b/gamelib/engine.py	Sat Sep 05 19:26:01 2009 +0000
@@ -179,7 +179,8 @@
             if self.game.gameboard.is_game_over():
                 return GameOver(self.game)
             return DayState(self.game)
-        elif e.type is KEYDOWN and e.key == K_d:
+        elif (e.type is KEYDOWN and e.key == K_d) or \
+                events_equal(e, FAST_FORWARD):
             if self.cycle_time > FAST_ANIM_SPEED:
                 self.cycle_time = FAST_ANIM_SPEED
             else:
@@ -254,6 +255,7 @@
 START_NIGHT = pygame.event.Event(USEREVENT, name="START_NIGHT")
 GO_MAIN_MENU = pygame.event.Event(USEREVENT, name="GO_MAIN_MENU")
 GO_HELP_SCREEN = pygame.event.Event(USEREVENT, name="GO_HELP_SCREEN")
+FAST_FORWARD = pygame.event.Event(USEREVENT, name="FAST_FORWARD")
 MOVE_FOX_ID = USEREVENT + 1
 ANIM_ID = USEREVENT + 6
 MOVE_FOXES = pygame.event.Event(MOVE_FOX_ID, name="MOVE_FOXES")
--- a/gamelib/gameboard.py	Sat Sep 05 19:22:58 2009 +0000
+++ b/gamelib/gameboard.py	Sat Sep 05 19:26:01 2009 +0000
@@ -16,6 +16,7 @@
 import cursors
 import sprite_cursor
 import misc
+import engine
 
 class OpaqueLabel(gui.Label):
     def __init__(self, value, **params):
@@ -115,7 +116,7 @@
         self.add_tool("Price Reference", self.show_prices)
         self.add_spacer(20)
 
-        self.add_tool("Finished Day", self.day_done)
+        self.fin_tool = self.add_tool("Finished Day", self.day_done)
 
         self.anim_clear_tool = False # Flag to clear the tool on an anim loop
         # pgu's tool widget fiddling happens after the tool action, so calling
@@ -123,8 +124,19 @@
         # the anim loop
 
     def day_done(self):
-        import engine
-        pygame.event.post(engine.START_NIGHT)
+        if self.gameboard.day:
+            pygame.event.post(engine.START_NIGHT)
+        else:
+            self.anim_clear_tool = True
+            pygame.event.post(engine.FAST_FORWARD)
+
+    def update_fin_tool(self, day):
+        if day:
+            self.fin_tool.widget = gui.basic.Label('Finished Day')
+            self.fin_tool.resize()
+        else:
+            self.fin_tool.widget = gui.basic.Label('Fast Forward')
+            self.fin_tool.resize()
 
     def show_prices(self):
         """Popup dialog of prices"""
@@ -210,6 +222,7 @@
         tool.connect(gui.CLICK, func)
         self.tr()
         self.td(tool, align=-1, colspan=2)
+        return tool
 
     def clear_tool(self):
         self.group.value = None
@@ -386,11 +399,13 @@
         self.day, self.night = False, True
         self.tv.sun(False)
         self.reset_states()
+        self.toolbar.update_fin_tool(self.day)
 
     def start_day(self):
         self.day, self.night = True, False
         self.tv.sun(True)
         self.reset_states()
+        self.toolbar.update_fin_tool(self.day)
 
     def in_bounds(self, pos):
         """Check if a position is within the game boundaries"""