Changeset 200:67d10f7e0159


Ignore:
Timestamp:
Sep 4, 2009, 7:51:19 PM (11 years ago)
Author:
Adrianna Pińska <adrianna.pinska@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@201
Message:

selected chickens are selected

Location:
gamelib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gamelib/animal.py

    r199 r200  
    6666
    6767    def equip(self, item):
    68         self.equipment.append(item)
     68        if equipment.is_equipment(item):
     69            self.equipment.append(item)
     70        elif equipment.is_accoutrement(item):
     71            self.accoutrements.append(item)
    6972        self.redraw()
    7073
    7174    def unequip(self, item):
    72         self.equipment = [e for e in self.equipment if e != item]
     75        if equipment.is_equipment(item):
     76            self.equipment = [e for e in self.equipment if e != item]
     77        elif equipment.is_accoutrement(item):
     78            self.accoutrements = [e for e in self.accoutrements if e != item]
    7379        self.redraw()
     80
     81    def unequip_by_name(self, item_name):
     82        # only remove first match
     83        matches = [item for item in self.equipment + self.accoutrements if item.NAME == item_name]
     84        if matches:
     85            self.unequip(matches[0])
    7486
    7587    def redraw(self):
  • gamelib/equipment.py

    r198 r200  
    129129    """Things which are not equipment, but are displayed in the same way"""
    130130    IS_EQUIPMENT = False
     131    IS_ACCOUTREMENT = True
    131132    BUY_PRICE = 0
    132133    SELL_PRICE = 0
     
    158159    return is_equipment(obj) and getattr(obj, 'IS_ARMOUR', False)
    159160
     161def is_accoutrement(obj):
     162    return not getattr(obj, "IS_EQUIPMENT", False) and hasattr(obj, "NAME") and getattr(obj, 'IS_ACCOUTREMENT', False)
     163
    160164EQUIPMENT = []
    161165for name in dir():
  • gamelib/gameboard.py

    r197 r200  
    218218    def set_selected_tool(self, tool, cursor):
    219219        self.selected_tool = tool
    220         self.animal_to_place = None
     220        self.select_animal_to_place(None)
    221221        if cursor:
    222222            pygame.mouse.set_cursor(*cursor)
     
    322322            self.open_building_dialog(building, do_sell)
    323323
     324    def select_animal_to_place(self, animal):
     325        if self.animal_to_place:
     326            self.animal_to_place.unequip_by_name("spotlight")
     327        self.animal_to_place = animal
     328        if self.animal_to_place:
     329            self.animal_to_place.equip(equipment.Spotlight())
     330
    324331    def place_animal(self, tile_pos):
    325332        """Handle an TOOL_PLACE_ANIMALS click.
     
    331338        if chicken:
    332339            if chicken is self.animal_to_place:
    333                 self.animal_to_place = None
     340                self.select_animal_to_place(None)
    334341                pygame.mouse.set_cursor(*cursors.cursors['select'])
    335342            else:
    336                 self.animal_to_place = chicken
     343                self.select_animal_to_place(chicken)
    337344                pygame.mouse.set_cursor(*cursors.cursors['chicken'])
    338345            return
     
    343350                    place = building.first_empty_place()
    344351                    self.relocate_animal(self.animal_to_place, place=place)
    345                     self.animal_to_place = None
     352                    self.select_animal_to_place(None)
    346353                    pygame.mouse.set_cursor(*cursors.cursors['select'])
    347354                except buildings.BuildingFullError:
     
    401408            # sell_callback should return true if we need to remove the
    402409            # occupant
    403             self.animal_to_place = place.occupant
     410            self.select_animal_to_place(place.occupant)
    404411            if not sell_callback:
    405412                pygame.mouse.set_cursor(*cursors.cursors['chicken'])
    406413            else:
    407414                # Attempt to sell the occupant
    408                 self.animal_to_place = None
     415                self.select_animal_to_place(None)
    409416                if sell_callback(place.occupant):
    410417                    button.value = icons.EMPTY_NEST_ICON
Note: See TracChangeset for help on using the changeset viewer.