# HG changeset patch # User KarstenBock@gmx.net # Date 1317805479 -7200 # Node ID 2399a8c3da0cb72966fcb638b8232420751d2e10 # Parent 30dbbae653add2c4015af116b62d15ab16ecd855 Modified EquipmentSlot to display an image instead of a text. Added EquipmentGui class, which handles the equipment slots of the player screen. An EquipmentGui instance will be created in the InventoryGUI constructor. The initializeInventory method of the Hud class supplies the players inventory and equipment to the InventoryGUI constructor. diff -r 30dbbae653ad -r 2399a8c3da0c gui/hud.py --- a/gui/hud.py Wed Oct 05 10:57:31 2011 +0200 +++ b/gui/hud.py Wed Oct 05 11:04:39 2011 +0200 @@ -157,7 +157,9 @@ """Initialize the inventory""" if not self.inventory: xml_file = vfs.VFS.open('gui/inventory.xml') - self.inventory = InventoryGUI(self.controller, xml_file, None) + player = self.model.game_state.getObjectById("PlayerCharacter") + self.inventory = InventoryGUI(self.controller, xml_file, + player.container, player.equip, None) # inv_callbacks = { # 'refreshReadyImages': self.refreshReadyImages, # 'toggleInventoryButton': self.toggleInventoryButton, diff -r 30dbbae653ad -r 2399a8c3da0c gui/inventorygui.py --- a/gui/inventorygui.py Wed Oct 05 10:57:31 2011 +0200 +++ b/gui/inventorygui.py Wed Oct 05 11:04:39 2011 +0200 @@ -12,6 +12,7 @@ # You should have received a copy of the GNU General Public License # along with PARPG. If not, see . +import logging from fife.extensions.pychan.tools import callbackWithArguments as cbwa from fife.extensions import pychan @@ -21,42 +22,32 @@ #from parpg.objects.base import Container from parpg.gui.containergui_base import ContainerGUIBase from parpg.objects.action import ACTIONS - -import logging +from parpg.components import equip logger = logging.getLogger('action') class EquipmentSlot(pychan.VBox): - ATTRIBUTES = pychan.VBox.ATTRIBUTES + [UnicodeAttr('label_text')] - - def _setLabelText(self, text): - label = self.findChild() - label.text = unicode(text) - label.resizeToContent() - self.margins = ( - int((self.width - label.width) / 2.0), - int((self.height - label.height) / 2.0) - ) - - def _getLabelText(self): - label = self.findChild() - return label.text - - label_text = property(fget=_getLabelText, fset=_setLabelText) - - def __init__(self, label_text=u'equipment', min_size=(50, 50), + def __init__(self, min_size=(50, 50), max_size=(50, 50), margins=None, **kwargs): pychan.VBox.__init__(self, min_size=min_size, max_size=max_size, **kwargs) self.background_image = 'gui/inv_images/inv_background.png' - label = pychan.Label(text=unicode(label_text)) - self.addChild(label) - self.label_text = label_text + icon = pychan.Icon(name="Icon") + self.addChild(icon) self.adaptLayout() if self.parent is not None: self.beforeShow() + @property + def image(self): + icon = self.findChildByName("Icon") + return icon.image + + @image.setter + def image(self, image): + icon = self.findChildByName("Icon") + icon.image = image class InventoryGrid(pychan.VBox): ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size')] @@ -109,9 +100,39 @@ self.border_size = 1 +class EquipmentGui(ContainerGUIBase): + def __init__(self, controller, gui, equip, callbacks): + ContainerGUIBase.__init__(self, controller, gui) + self.equip = equip + self.equip_to_gui = { + "head": "headSlot", + "neck": "neckSlot", + "body": "shirtSlot", + "belt": "beltSlot", + "leg": "pantsSlot", + "feet": "bootsSlot", + "l_arm": "leftHandSlot", + "r_arm": "rightHandSlot", + } + + def updateImages(self): + for eq_slot, gui_slot in self.equip_to_gui.iteritems(): + widget = self.gui.findChild(name=gui_slot) + equipable = equip.get_equipable(self.equip, eq_slot) + widget.item = equipable.entity if equipable else None + self.updateImage(widget) + + def updateImage(self, slot): + assert(isinstance(slot, EquipmentSlot)) + if (slot.item): + image = slot.item.containable.image + else: + image = None + slot.image = image + class InventoryGUI(ContainerGUIBase): - def __init__(self, controller, inventory, callbacks): - super(InventoryGUI, self).__init__(controller, inventory) + def __init__(self, controller, gui, container, equip, callbacks): + super(InventoryGUI, self).__init__(controller, gui) self.engine = controller.engine self.inventory_shown = False render_backend = self.engine.getRenderBackend() @@ -121,6 +142,11 @@ widget_width, widget_height = self.gui.size self.gui.position = ((screen_width - widget_width) / 2, (screen_height - widget_height) / 2) + self.equip_gui = EquipmentGui( + controller, + self.gui.findChildByName("equipmentPage"), + equip, callbacks + ) def toggleInventory(self, toggleImage=True): """Pause the game and enter the inventory screen, or close the @@ -140,6 +166,7 @@ self.inventory_shown = False def showInventory(self): + self.equip_gui.updateImages() self.gui.show() def closeInventory(self):