Mercurial > rinkhals
changeset 561:7f037ee2a6c8
Show count of selected chickens in buildings
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 18:40:04 +0000 |
parents | 8cd13b82585e |
children | 80725d647569 |
files | gamelib/buildings.py gamelib/constants.py gamelib/gameboard.py |
diffstat | 3 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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
--- 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)