changeset 115:2b2007e231da

Start of dialog for placing chickens in buildings. Remove chicken in hen house bug by not allowing chickens in hen houses.
author Simon Cross <hodgestar@gmail.com>
date Wed, 02 Sep 2009 19:40:28 +0000
parents 4c2fbab20abe
children d539ef5a3333
files gamelib/animal.py gamelib/gameboard.py
diffstat 2 files changed, 38 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Wed Sep 02 19:17:26 2009 +0000
+++ b/gamelib/animal.py	Wed Sep 02 19:40:28 2009 +0000
@@ -96,6 +96,9 @@
             sound.play_sound("kill-fox.ogg")
             gameboard.kill_fox(fox)
 
+    def outside(self):
+        return self.abode is None
+
 class Egg(Animal):
     """An egg"""
 
--- a/gamelib/gameboard.py	Wed Sep 02 19:17:26 2009 +0000
+++ b/gamelib/gameboard.py	Wed Sep 02 19:40:28 2009 +0000
@@ -230,14 +230,7 @@
             return
         building = self.get_building(tile_pos)
         if building:
-            if self.animal_to_place is not None:
-                occupant = self.animal_to_place
-                if occupant in self.tv.sprites:
-                    self.tv.sprites.remove(occupant)
-                building.add_occupant(occupant)
-                print building, building.occupants()
-            else:
-                self.select_animal_from_building(building)
+            self.open_building_dialog(building)
             return
         if self.tv.get(tile_pos) == self.GRASSLAND:
             if self.animal_to_place is not None:
@@ -246,10 +239,36 @@
                     occupant.abode.remove_occupant(occupant)
                 occupant.set_pos(tile_pos)
 
-    def select_animal_from_building(self, building):
-        """Create dialog for selecting an animal from a building."""
-        # XXX: unimplemented
-        print "Selecting animal from building %r" % (building,)
+    def open_dialog(self, widget):
+        """Open a dialog for the given widget. Add close button."""
+        tbl = gui.Table()
+
+        def close_dialog():
+            self.disp.close(tbl)
+
+        close_button = gui.Button("Close")
+        close_button.connect(gui.CLICK, close_dialog)
+
+        tbl = gui.Table()
+        tbl.tr()
+        tbl.td(widget, colspan=2)
+        tbl.tr()
+        tbl.td(gui.Spacer(100, 0))
+        tbl.td(close_button)
+
+        self.disp.open(tbl)
+
+    def open_building_dialog(self, building):
+        """Create dialog for manipulating the contents of a building."""
+        width, height = pygame.display.get_surface().get_size()
+        tbl = gui.Table()
+        for row in range(building.size[0]):
+            tbl.tr()
+            for col in range(building.size[1]):
+                button = gui.Button("%s, %s" % (row, col))
+                tbl.td(button)
+
+        self.open_dialog(tbl)
 
     def buy_fence(self, tile_pos):
         this_tile = self.tv.get(tile_pos)
@@ -330,7 +349,8 @@
 
     def add_chicken(self, chicken):
         self.chickens.append(chicken)
-        self.tv.sprites.append(chicken)
+        if chicken.outside():
+            self.tv.sprites.append(chicken)
         self.toolbar.update_chicken_counter(len(self.chickens))
 
     def add_fox(self, fox):
@@ -356,7 +376,8 @@
     def remove_chicken(self, chick):
         if chick in self.chickens:
             self.chickens.remove(chick)
-            self.tv.sprites.remove(chick)
+            if chick.outside():
+                self.tv.sprites.remove(chick)
             self.toolbar.update_chicken_counter(len(self.chickens))
 
     def remove_building(self, building):