Ignore:
Timestamp:
09/03/09 02:03:40 (10 years ago)
Author:
orlandov
Message:

Fix Issue #78

  • Fully move the inventory display logic from World to Hud.
  • World will pass Hud an inventory model which will be passed to the Hud's Inventory object at creation time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/inventory.py

    r267 r270  
    2323class Inventory(object): 
    2424    """Main inventory class""" 
    25     def __init__(self, engine, items, readyCallback, toggleInventoryButtonCallback): 
     25    def __init__(self, engine, items, callbacks): 
    2626        """Initialise the instance. 
    2727           @type engine: fife.Engine 
     
    3030           @param items: A dictionary for every slot that goes '{slot:item, slot:item}' 
    3131                         if a slot is not included in the dict, it is assumed to be empty 
    32            @type readyCallback: function 
    33            @param readyCallback: The function that will make the 
    34                                  ready slots on the HUD reflect those 
    35                                  within the inventory 
    36            @type toggleInventoryButtonCallback: function 
    37            @param toggleInventoryButtonCallback: Function that will toggle the state of the inventory button 
     32           @type callbacks: dict 
     33           @param callbacks: a dict of callbacks 
     34               refreshReadyImages: 
     35                   Function that will make the ready slots on the HUD 
     36                   reflect those within the inventory 
     37               toggleInventoryButton: 
     38                   Function that will toggle the state of the inventory button 
    3839           @return: None""" 
    3940        pychan.init(engine, debug = True) 
    4041        self.engine = engine 
    41         self.readyCallback = readyCallback 
    42         self.toggleInventoryButtonCallback = toggleInventoryButtonCallback 
     42        self.readyCallback = callbacks['refreshReadyImages'] 
     43        self.toggleInventoryButtonCallback = callbacks['toggleInventoryButton'] 
    4344        self.original_cursor_id = self.engine.getCursor().getId() 
    4445        # TODO: remove hard-coded string? 
     
    132133        self.inventoryShown = False 
    133134 
    134     def displayInventory(self, callFromHud): 
     135    def toggleInventory(self, toggleImage=True): 
    135136        """Pause the game and enter the inventory screen, or close the 
    136            inventory screen and resume the game. callFromHud should be true 
    137            (must be True?) if you call this function from the HUD script 
    138            @type callFromHud: boolean 
    139            @param callFromHud: Whether this function is being called  
    140                                from the HUD script 
    141            @return: None""" 
    142         if (self.inventoryShown == False): 
     137           inventory screen and resume the game. 
     138           @type toggleImage: bool 
     139           @param toggleImage: 
     140               Call toggleInventoryCallback if True. Toggling via a 
     141               keypress requires that we toggle the Hud inventory image 
     142               explicitly. Clicking on the Hud inventory button toggles the 
     143               image implicitly, so we don't change it. 
     144           @return: None""" 
     145        if not self.inventoryShown: 
    143146            self.showInventory() 
    144147            self.inventoryShown = True 
     
    146149            self.closeInventory() 
    147150            self.inventoryShown = False 
    148         if (callFromHud == False): 
     151 
     152        if toggleImage: 
    149153            self.toggleInventoryButtonCallback() 
    150154 
     
    296300        return items 
    297301                 
    298  
     302    def getImage(self, name): 
     303        """Return a current image from the inventory 
     304           @type name: string 
     305           @param name: name of image to get 
     306           @return: None""" 
     307        return self.inventory.findChild(name=name) 
     308 
Note: See TracChangeset for help on using the changeset viewer.