Ignore:
Timestamp:
10/24/09 06:17:27 (10 years ago)
Author:
b0rland_parpg
Message:

Ticket #107: patch by b0rland

  • Wrote initial version of the inventory storage class
  • Added some useful utility functions into container class and its derivatives
  • Created several combined classes for carryable containers
  • Extended tests and of course made new ones
  • Renamed old Inventory class to be InventoryGUI

Note: InventoryGUI still works the old way and doesn't use Inventory

File:
1 copied

Legend:

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

    r288 r346  
    1616#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
    1717 
    18 import sys, os, fife, fifelog, pychan 
     18import sys 
     19import os 
     20import fife 
     21import fifelog 
     22import pychan 
    1923from scripts import drag_drop_data as data_drag 
    2024from pychan.tools import callbackWithArguments as cbwa 
    2125from scripts.items import item_image_dict 
    2226 
    23 class Inventory(object): 
    24     """Main inventory class""" 
     27class InventoryGUI(object): 
     28    """Inventory GUI class""" 
    2529    def __init__(self, engine, items, callbacks): 
    2630        """Initialise the instance. 
     
    2832           @param engine: An instance of the fife engine 
    2933           @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 
     34           @param items: A dictionary for every slot that goes '{slot:item, 
     35                         slot:item}' if a slot is not included in the dict, 
     36                         it is assumed to be empty 
    3237           @type callbacks: dict 
    3338           @param callbacks: a dict of callbacks 
     
    4550        # TODO: remove hard-coded string? 
    4651        self.inventory = pychan.loadXML("gui/inventory.xml") 
    47         self.inventoryShown = False  
     52        self.inventory_shown = False 
    4853        self.events_to_map = {} 
    4954        # the images that should be used for the buttons when they are "empty" 
     
    112117            # make every button's callback be self.dragDrop 
    113118            self.events_to_map[button] = cbwa(self.dragDrop, button) 
    114             ch = self.inventory.findChild(name = button) 
     119            ch = self.inventory.findChild(name=button) 
    115120            # make every slot's item be none if it has not already been set 
    116121            if button not in items: 
     
    131136        self.closeInventory() 
    132137        self.toggleInventoryButtonCallback() 
    133         self.inventoryShown = False 
     138        self.inventory_shown = False 
    134139 
    135140    def toggleInventory(self, toggleImage=True): 
     
    143148               image implicitly, so we don't change it. 
    144149           @return: None""" 
    145         if not self.inventoryShown: 
     150        if not self.inventory_shown: 
    146151            self.showInventory() 
    147             self.inventoryShown = True 
     152            self.inventory_shown = True 
    148153        else: 
    149154            self.closeInventory() 
    150             self.inventoryShown = False 
     155            self.inventory_shown = False 
    151156 
    152157        if toggleImage: 
     
    158163        self.inventory.show() 
    159164 
    160     def setMouseCursor(self, image, dummy_image, type = "native"):  
     165    def setMouseCursor(self, image, dummy_image, type="native"):  
    161166        """Set the mouse cursor to an image. 
    162167           @type image: string 
     
    286291    def getItems(self): 
    287292        """ 
    288         Get the items in the inventory slots. If there is no item in the slot, it is skipped 
     293        Get the items in the inventory slots. If there is no item in the slot, 
     294        it is skipped 
    289295         
    290296        @rtype: dict 
Note: See TracChangeset for help on using the changeset viewer.