Changeset 164:ab90040013a7


Ignore:
Timestamp:
Sep 3, 2009, 10:34:26 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@165
Message:

Implement equipment selling.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/constants.py

    r158 r164  
    4242TOOL_PLACE_ANIMALS = 5
    4343TOOL_LOGGING = 6
     44TOOL_SELL_EQUIPMENT = 7
    4445
    4546NIGHT_LENGTH = 150
  • gamelib/gameboard.py

    r162 r164  
    6464        self.add_tool_button("Building", constants.TOOL_SELL_BUILDING,
    6565                cursors.cursors['select'])
     66        self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT)
    6667        self.add_spacer(20)
    6768
     
    221222        elif self.selected_tool == constants.TOOL_SELL_BUILDING:
    222223            self.sell_building(self.tv.screen_to_tile(e.pos))
     224        elif self.selected_tool == constants.TOOL_SELL_EQUIPMENT:
     225            self.sell_equipment(self.tv.screen_to_tile(e.pos))
    223226        elif self.selected_tool == constants.TOOL_LOGGING:
    224227            self.logging_forest(self.tv.screen_to_tile(e.pos))
     
    230233    def get_chicken(self, tile_pos):
    231234        for chick in self.chickens:
    232             if chick.covers(tile_pos):
     235            if chick.covers(tile_pos) and chick.outside():
    233236                return chick
    234237        return None
     
    258261           """
    259262        chicken = self.get_chicken(tile_pos)
    260         if chicken and chicken.abode is None:
     263        if chicken:
    261264            if chicken is self.animal_to_place:
    262265                self.animal_to_place = None
     
    335338        place_button_map = {}
    336339
    337         width, height = pygame.display.get_surface().get_size()
    338340        tbl = gui.Table()
    339341        columns = building.max_floor_width()
     
    411413        building.remove(self.tv)
    412414        self.remove_building(building)
     415
     416    def sell_equipment(self, tile_pos):
     417        chicken = self.get_chicken(tile_pos)
     418        if chicken is None or not chicken.equipment:
     419            return
     420        if len(chicken.equipment) == 1:
     421            item = chicken.equipment[0]
     422            self.add_cash(item.sell_price())
     423            chicken.unequip(item)
     424        else:
     425            self.open_equipment_dialog(chicken)
     426
     427    def open_equipment_dialog(self, chicken):
     428        tbl = gui.Table()
     429
     430        def sell_item(item, button):
     431            """Select item of equipment."""
     432            self.add_cash(item.sell_price())
     433            chicken.unequip(item)
     434            self.disp.close(tbl)
     435
     436        kwargs = { 'style': { 'padding_left': 10, 'padding_bottom': 10 }}
     437
     438        tbl.tr()
     439        tbl.td(gui.Button("Sell ...     "), align=-1, **kwargs)
     440
     441        for item in chicken.equipment:
     442            tbl.tr()
     443            button = gui.Button(item.name().title())
     444            button.connect(gui.CLICK, sell_item, item, button)
     445            tbl.td(button, align=1, **kwargs)
     446
     447        self.open_dialog(tbl)
    413448
    414449    def event(self, e):
Note: See TracChangeset for help on using the changeset viewer.