changeset 213:07b361ebd87f

Ensure we clean up highlights, etc.
author Neil Muller <drnlmuller@gmail.com>
date Fri, 04 Sep 2009 21:49:32 +0000
parents b999abd5993b
children 87a58da53b17
files gamelib/engine.py gamelib/gameboard.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/engine.py	Fri Sep 04 21:35:40 2009 +0000
+++ b/gamelib/engine.py	Fri Sep 04 21:49:32 2009 +0000
@@ -120,7 +120,7 @@
         if events_equal(e, START_NIGHT):
             return NightState(self.game)
         elif e.type is KEYDOWN and e.key == K_ESCAPE:
-            self.game.gameboard.set_cursor()
+            self.game.gameboard.reset_states()
             return GameOver(self.game)
         elif e.type is ANIM_ID:
             self.game.gameboard.run_animations()
@@ -148,7 +148,7 @@
         """Add some foxes to the farm"""
         sound.stop_background_music()
         self.game.gameboard.tv.sun(False)
-        self.game.gameboard.set_cursor()
+        self.game.gameboard.reset_states()
 
         sound.play_sound("nightfall.ogg")
         # Add a timer to the event queue
--- a/gamelib/gameboard.py	Fri Sep 04 21:35:40 2009 +0000
+++ b/gamelib/gameboard.py	Fri Sep 04 21:49:32 2009 +0000
@@ -249,6 +249,9 @@
 
     def set_selected_tool(self, tool, cursor):
         self.selected_tool = tool
+        if self.animal_to_place:
+            # Clear any highlights
+            self.animal_to_place.unequip_by_name("spotlight")
         self.select_animal_to_place(None)
         sprite_curs = None
         if buildings.is_building(tool):
@@ -266,7 +269,12 @@
         if sprite_curs:
             self.sprite_cursor = sprite_curs
             self.tv.sprites.append(self.sprite_cursor)
-            
+
+    def reset_states(self):
+        """Clear current states (highlights, etc.)"""
+        if self.animal_to_place:
+            self.animal_to_place.unequip_by_name("spotlight")
+        self.set_cursor()
 
     def update_sprite_cursor(self, e):
         tile_pos = self.tv.screen_to_tile(e.pos)