# HG changeset patch # User Neil Muller # Date 1259433604 0 # Node ID 7f037ee2a6c82ef89c1a0bd439886a023493a2f5 # Parent 8cd13b82585e6b4c991c1baab489656725d50ef2 Show count of selected chickens in buildings diff -r 8cd13b82585e -r 7f037ee2a6c8 gamelib/buildings.py --- a/gamelib/buildings.py Sat Nov 28 18:27:59 2009 +0000 +++ b/gamelib/buildings.py Sat Nov 28 18:40:04 2009 +0000 @@ -293,6 +293,13 @@ # Blit to the right x, y = text.get_size() image.blit(text, (w - x, h - y)) + sel_count = len([chick for chick in self.occupants() + if chick in self.gameboard.selected_chickens]) + if sel_count: + text = self._font.render(str(sel_count), True, + constants.SELECTED_COUNT_COLOR) + x, y = text.get_size() + image.blit(text, (0, h - y)) # Render predator count if self._predators: text = self._font.render(str(len(self._predators)), True, diff -r 8cd13b82585e -r 7f037ee2a6c8 gamelib/constants.py --- a/gamelib/constants.py Sat Nov 28 18:27:59 2009 +0000 +++ b/gamelib/constants.py Sat Nov 28 18:40:04 2009 +0000 @@ -17,6 +17,7 @@ SCREEN = (800, 600) FG_COLOR = (255, 255, 255) PREDATOR_COUNT_COLOR = (255, 100, 0) # Approximately fox coloured +SELECTED_COUNT_COLOR = (0, 128, 235) # Selection highlight colour BG_COLOR = (0, 0, 0) # Mixer constants diff -r 8cd13b82585e -r 7f037ee2a6c8 gamelib/gameboard.py --- a/gamelib/gameboard.py Sat Nov 28 18:27:59 2009 +0000 +++ b/gamelib/gameboard.py Sat Nov 28 18:40:04 2009 +0000 @@ -484,18 +484,25 @@ def select_animal(self, animal): self.selected_chickens.append(animal) + if animal.abode: + animal.abode.building.update_occupant_count() animal.equip(equipment.Spotlight()) def unselect_all(self): # Clear any highlights - for chick in self.selected_chickens: + old_sel = self.selected_chickens + self.selected_chickens = [] + for chick in old_sel: chick.unequip_by_name("Spotlight") - self.selected_chickens = [] + if chick.abode: + chick.abode.building.update_occupant_count() def unselect_animal(self, animal): if animal in self.selected_chickens: self.selected_chickens.remove(animal) animal.unequip_by_name("Spotlight") + if animal.abode: + animal.abode.building.update_occupant_count() def get_chicken_at_pos(self, tile_pos): chicken = self.get_outside_chicken(tile_pos)