Changeset 205


Ignore:
Timestamp:
07/11/09 15:02:55 (10 years ago)
Author:
bretzel_parpg
Message:

Inventory now takes an items argument which tells the inventory what items to put in each slot, and
then from the item name figures out what image to put in each slot

Location:
trunk/PARPG/scripts
Files:
2 edited

Legend:

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

    r202 r205  
    1919from scripts import drag_drop_data as data_drag 
    2020from pychan.tools import callbackWithArguments as cbwa 
     21from scripts.items import item_image_dict 
    2122 
    2223class Inventory(): 
    2324    """Main inventory class""" 
    24     def __init__(self, engine, readyCallback): 
     25    def __init__(self, engine, items, readyCallback): 
    2526        """Initialise the instance. 
    2627           @type engine: fife.Engine 
    2728           @param engine: An instance of the fife engine 
     29           @type items: dict 
     30           @param items: A dictionary for every slot that goes '{slot:item, slot:item}' 
     31                         if a slot is not included in the dict, it is assumed to be empty 
    2832           @type readyCallback: function 
    2933           @param readyCallback: The function that will make the 
     
    8993        self.locations = ['ready', 'head', 'foot', 'hand', 
    9094                          'belt', 'held', 'body'] 
     95 
     96        for key in items: 
     97            widget = self.inventory.findChild(name=key) 
     98            item = items[key] 
     99            image = item_image_dict[item] 
     100 
     101            widget.item = item 
     102            widget.up_image = image 
     103            widget.down_image = image 
     104            widget.hover_image = image             
     105 
    91106        for button in self.buttons: 
    92107            # make every button's callback be self.dragDrop 
    93108            self.events_to_map[button] = cbwa(self.dragDrop, button) 
    94109            ch = self.inventory.findChild(name = button) 
    95             # make every slot's item be empty 
    96             ch.item = "" 
     110            # make every slot's item be none if it has not already been set 
     111            if button not in items: 
     112                ch.item = "" 
     113 
    97114        self.inventory.mapEvents(self.events_to_map)    
    98115        self.resetMouseCursor() 
  • trunk/PARPG/scripts/world.py

    r201 r205  
    8383        self.action_number = 1 
    8484        # setup the inventory 
    85         self.inventory = inventory.Inventory(self.engine, self.refreshReadyImages) 
     85        # make slot 'A1' and 'A3' container daggers 
     86        inv_data = {'A1':'dagger01', 'A3':'dagger01'} 
     87        self.inventory = inventory.Inventory(self.engine, inv_data, self.refreshReadyImages) 
    8688        self.inventory.events_to_map['close_button'] = self.closeInventoryAndToggle 
    8789        self.inventory.inventory.mapEvents(self.inventory.events_to_map) 
Note: See TracChangeset for help on using the changeset viewer.