Changeset 726


Ignore:
Timestamp:
02/12/11 20:30:48 (8 years ago)
Author:
technomage
Message:

Patch by Technomage

  • Merged in my inventory_view git branch which implements my inventory gui prototype;
Location:
branches/active/character_customization/game
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/gui/inventory.xml

    r479 r726  
    1 <Window title="Inventory" min_size="500,580"> 
    2   <Label text="Character Name Here" name="charName"/>/ 
    3  
    4   <!-- TODO: Document this mess --> 
    5  
    6   <HBox max_size="275,100"> 
    7     <Spacer /> 
    8     <ImageButton name="Head" up_image="gui/inv_images/inv_head.png" down_image="gui/inv_images/inv_head.png" hover_image="gui/inv_images/inv_head.png" text="" /> 
    9   </HBox> 
    10    
    11   <HBox max_size="460,320"> 
    12     <Spacer /> 
    13      
    14     <VBox max_size="50,300"> 
    15       <ImageButton name="LeftHeld" up_image="gui/inv_images/inv_litem.png" down_image="gui/inv_images/inv_litem.png" hover_image="gui/inv_images/inv_litem.png" text="" /> 
    16       <ImageButton name="Ready1" up_image="gui/inv_images/inv_belt_pouches.png" down_image="gui/inv_images/inv_belt_pouches.png" hover_image="gui/inv_images/inv_belt_pouches.png" text="" /> 
    17       <ImageButton name="Ready2" up_image="gui/inv_images/inv_belt_pouches.png" down_image="gui/inv_images/inv_belt_pouches.png" hover_image="gui/inv_images/inv_belt_pouches.png" text="" /> 
    18       <Spacer /> 
    19       <ImageButton name="LeftFoot" up_image="gui/inv_images/inv_lfoot.png" down_image="gui/inv_images/inv_lfoot.png" hover_image="gui/inv_images/inv_lfoot.png" text="" /> 
    20     </VBox> 
    21      
    22     <VBox max_size="50,165"> 
    23       <ImageButton name="LeftHand" up_image="gui/inv_images/inv_lhand.png" down_image="gui/inv_images/inv_lhand.png" hover_image="gui/inv_images/inv_lhand.png" text="" /> 
    24       <Spacer /> 
    25       <ImageButton name="Body" up_image="gui/inv_images/inv_torso.png" down_image="gui/inv_images/inv_torso.png" hover_image="gui/inv_images/inv_torso.png" text="" /> 
    26     </VBox> 
    27  
    28     <VBox min_size="200,350"> 
    29       <Spacer /> 
    30       <Icon name="charPreview" image="gui/inv_images/char_preview.png" /> 
    31     </VBox> 
    32      
    33     <VBox max_size="50,165"> 
    34       <ImageButton name="RightHand" up_image="gui/inv_images/inv_rhand.png" down_image="gui/inv_images/inv_rhand.png" hover_image="gui/inv_images/inv_rhand.png" text="" /> 
    35       <Spacer /> 
    36       <ImageButton name="Belt" up_image="gui/inv_images/inv_belt.png" down_image="gui/inv_images/inv_belt.png" hover_image="gui/inv_images/inv_belt.png" text="" /> 
    37     </VBox> 
    38      
    39     <VBox max_size="50,300"> 
    40       <ImageButton name="RightHeld" up_image="gui/inv_images/inv_ritem.png" down_image="gui/inv_images/inv_ritem.png" hover_image="gui/inv_images/inv_ritem.png" text="" /> 
    41       <ImageButton name="Ready3" up_image="gui/inv_images/inv_belt_pouches.png" down_image="gui/inv_images/inv_belt_pouches.png" hover_image="gui/inv_images/inv_belt_pouches.png" text="" /> 
    42       <ImageButton name="Ready4" up_image="gui/inv_images/inv_belt_pouches.png" down_image="gui/inv_images/inv_belt_pouches.png" hover_image="gui/inv_images/inv_belt_pouches.png" text="" /> 
    43       <Spacer /> 
    44       <ImageButton name="RightFoot" up_image="gui/inv_images/inv_rfoot.png" down_image="gui/inv_images/inv_rfoot.png" hover_image="gui/inv_images/inv_rfoot.png" text="" /> 
    45     </VBox> 
    46      
    47   </HBox> 
    48    
    49   <Spacer /> 
    50    
    51   <!-- Main Inventory !--> 
    52   <HBox> 
    53     <VBox> 
    54       <HBox max_size="385,90"> 
    55         <Spacer /> 
    56         <ImageButton name="A1" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    57         <ImageButton name="A2" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    58         <ImageButton name="A3" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    59         <ImageButton name="A4" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    60         <ImageButton name="A5" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    61       </HBox> 
    62        
    63       <HBox max_size="385,90"> 
    64         <Spacer /> 
    65         <ImageButton name="B1" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    66         <ImageButton name="B2" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    67         <ImageButton name="B3" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    68         <ImageButton name="B4" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    69         <ImageButton name="B5" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    70       </HBox> 
    71        
    72       <HBox max_size="385,90"> 
    73         <Spacer /> 
    74         <ImageButton name="C1" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    75         <ImageButton name="C2" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    76         <ImageButton name="C3" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    77         <ImageButton name="C4" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    78         <ImageButton name="C5" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    79       </HBox> 
    80        
    81       <HBox max_size="385,90"> 
    82         <Spacer /> 
    83         <ImageButton name="D1" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    84         <ImageButton name="D2" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    85         <ImageButton name="D3" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    86         <ImageButton name="D4" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    87         <ImageButton name="D5" up_image="gui/inv_images/inv_backpack.png" down_image="gui/inv_images/inv_backpack.png" hover_image="gui/inv_images/inv_backpack.png" text=""/> 
    88       </HBox> 
    89        
    90       <Spacer /> 
    91        
    92       <HBox min_size="500,0"> 
    93         <Spacer /> 
    94         <Button name="close_button" text="Close" /> 
    95       </HBox> 
    96        
     1<VBox background_image="gui/notebook/notebook_background.png" opaque="0" 
     2      min_size="780,545"> 
     3  <Spacer fixed_size="20"></Spacer> 
     4  <HBox opaque="0" padding="0"> 
     5    <HBox name="equipmentPage" min_size="380,510" max_size="380,510" opaque="0"> 
     6      <VBox name="equipmentTabs" min_size="20,545" max_size="20,545" opaque="0"> 
     7        <Spacer fixed_size="194"></Spacer> 
     8        <ImageButton name="characterButton" 
     9                     up_image="gui/notebook/character_plain.png" 
     10                     down_image="gui/notebook/character_back.png" 
     11                     hover_image="gui/notebook/character_hovered.png"> 
     12        </ImageButton> 
     13      </VBox> 
     14      <VBox name="equipmentContent" hexpand="1" opaque="0"> 
     15        <HBox min_size="0,120" padding="0" opaque="0"> 
     16          <Spacer fixed_size="25"></Spacer> 
     17          <VBox opaque="0"> 
     18            <Spacer fixed_size="20"></Spacer> 
     19            <VBox margins="1,1" opaque="0"> 
     20            <Icon name="equipmentIcon" border_size="1" 
     21                  image="gui/portraits/drunkard.png"></Icon> 
     22            </VBox> 
     23          </VBox> 
     24          <Label name="equipmentDescription" foreground_color="0,0,0" 
     25                 text="Equipment description here."></Label> 
     26        </HBox> 
     27        <HBox opaque="0" padding="0" vexpand="1"> 
     28          <Spacer fixed_size="20"></Spacer> 
     29          <VBox padding="20" opaque="0"> 
     30            <Spacer fixed_size="40"></Spacer> 
     31            <EquipmentSlot name="shirtSlot" label_text="shirt"> 
     32            </EquipmentSlot> 
     33            <EquipmentSlot name="rightHandSlot" label_text="rhand"> 
     34            </EquipmentSlot> 
     35            <EquipmentSlot name="beltSlot" label_text="belt"></EquipmentSlot> 
     36            <EquipmentSlot name="bootsSlot" label_text="boots"></EquipmentSlot> 
     37          </VBox> 
     38          <HBox opaque="0" vexpand="1"> 
     39            <Spacer fixed_size="10"></Spacer> 
     40            <Icon name="puppetIcon" image="gui/inv_images/char_preview.png"> 
     41            </Icon> 
     42          </HBox> 
     43          <VBox padding="20" opaque="0"> 
     44            <EquipmentSlot name="headSlot" label_text="head"></EquipmentSlot> 
     45            <EquipmentSlot name="neckSlot" label_text="back"></EquipmentSlot> 
     46            <EquipmentSlot name="leftHandSlot" label_text="lhand"></EquipmentSlot> 
     47            <EquipmentSlot name="pantsSlot" label_text="pants"></EquipmentSlot> 
     48          </VBox> 
     49          <Spacer fixed_size="20"></Spacer> 
     50        </HBox> 
     51      </VBox> 
     52    </HBox> 
     53    <Spacer fixed_size="24"></Spacer> 
     54    <VBox name="inventoryPage" min_size="376,510" max_size="376,510" 
     55          opaque="0"> 
     56      <VBox name="inventoryContent" hexpand="1" min_size="350,0" opaque="0"> 
     57        <HBox min_size="0,120" opaque="0"> 
     58          <Label text="Item description here."></Label> 
     59        </HBox> 
     60        <InventoryGrid grid_size="6,7"></InventoryGrid> 
     61      </VBox> 
     62      <Spacer fixed_size="20"></Spacer> 
    9763    </VBox> 
    9864  </HBox> 
    99    
    100 </Window> 
     65</VBox> 
  • branches/active/character_customization/game/scripts/gui/__init__.py

    r653 r726  
     1from fife.extensions import pychan 
     2from .inventorygui import EquipmentSlot, InventoryGrid 
     3 
     4pychan.registerWidget(EquipmentSlot) 
     5pychan.registerWidget(InventoryGrid) 
  • branches/active/character_customization/game/scripts/gui/hud.py

    r693 r726  
    149149    def initializeInventory(self): 
    150150        """Initialize the inventory""" 
    151         inv_callbacks = { 
    152             'refreshReadyImages': self.refreshReadyImages, 
    153             'toggleInventoryButton': self.toggleInventoryButton, 
    154         } 
    155         self.inventory_storage = \ 
    156             self.model.game_state.player_character.inventory 
    157         if self.inventory == None: 
     151        if not self.inventory: 
    158152            self.inventory = inventorygui.InventoryGUI(self.controller, 
    159                                                        self.inventory_storage, 
    160                                                        inv_callbacks) 
    161         else: 
    162             self.inventory.inventory_storage = self.inventory_storage 
    163         self.refreshReadyImages() 
     153                                                       None, 
     154                                                       None) 
     155#        inv_callbacks = { 
     156#            'refreshReadyImages': self.refreshReadyImages, 
     157#            'toggleInventoryButton': self.toggleInventoryButton, 
     158#        } 
     159#        self.inventory_storage = \ 
     160#            self.model.game_state.player_character.inventory 
     161#        if self.inventory == None: 
     162#            self.inventory = inventorygui.InventoryGUI(self.controller, 
     163#                                                       self.inventory_storage, 
     164#                                                       inv_callbacks) 
     165#        else: 
     166#            self.inventory.inventory_storage = self.inventory_storage 
     167#        self.refreshReadyImages() 
    164168     
    165169    def initializeCharacterScreen(self): 
  • branches/active/character_customization/game/scripts/gui/inventorygui.py

    r630 r726  
    1717 
    1818from fife.extensions.pychan.tools import callbackWithArguments as cbwa 
     19from fife.extensions import pychan 
     20from fife.extensions.pychan.attrs import UnicodeAttr 
    1921 
    2022from scripts.gui import drag_drop_data as data_drag 
     
    2325from scripts.objects.action import ACTIONS 
    2426 
     27class EquipmentSlot(pychan.VBox): 
     28    ATTRIBUTES = pychan.VBox.ATTRIBUTES + [UnicodeAttr('label_text')] 
     29     
     30    def _setLabelText(self, text): 
     31        label = self.findChild() 
     32        label.text = unicode(text) 
     33        label.resizeToContent() 
     34        self.margins = ( 
     35            int((self.width - label.width) / 2.0), 
     36            int((self.height - label.height) / 2.0) 
     37        ) 
     38     
     39    def _getLabelText(self): 
     40        label = self.findChild() 
     41        return label.text 
     42     
     43    label_text = property(fget=_getLabelText, fset=_setLabelText) 
     44     
     45    def __init__(self, label_text=u'equipment', min_size=(50, 50), 
     46                 max_size=(50, 50), margins=None, 
     47                 background_image="gui/inv_images/inv_background.png", 
     48                 **kwargs): 
     49        pychan.VBox.__init__(self, min_size=min_size, max_size=max_size, 
     50                             **kwargs) 
     51        self.background_image = background_image 
     52        label = pychan.Label(text=unicode(label_text)) 
     53        self.addChild(label) 
     54        self.label_text = label_text 
     55        self.adaptLayout() 
     56        if self.parent is not None: 
     57            self.beforeShow() 
     58 
     59 
     60class InventoryGrid(pychan.VBox): 
     61    ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size')] 
     62     
     63    def _setNColumns(self, n_columns): 
     64        n_rows = self.grid_size[1] 
     65        self.grid_size = (n_columns, n_rows) 
     66     
     67    def _getNColumns(self): 
     68        n_columns = self.grid_size[0] 
     69        return n_columns 
     70    n_columns = property(fget=_getNColumns, fset=_setNColumns) 
     71     
     72    def _setNRows(self, n_rows): 
     73        n_columns = self.grid_size[0] 
     74        self.grid_size = (n_columns, n_rows) 
     75     
     76    def _getNRows(self): 
     77        n_rows = self.grid_size[1] 
     78        return n_rows 
     79    n_rows = property(fget=_getNRows, fset=_getNColumns) 
     80     
     81    def _setGridSize(self, grid_size): 
     82        n_columns, n_rows = grid_size 
     83        self.removeAllChildren() 
     84        for row_n in range(n_rows): 
     85            row_size = (n_columns * 50, 50) 
     86            row = pychan.HBox(min_size=row_size, max_size=row_size, 
     87                              padding=self.padding) 
     88            row.border_size = 1 
     89            row.opaque = 0 
     90            for column_n in range(n_columns): 
     91                slot = pychan.Icon(min_size=(50, 50), max_size=(50, 50)) 
     92                slot.border_size = 1 
     93                row.addChild(slot) 
     94            self.addChild(row) 
     95        self.min_size = ((n_columns * 50) + 2, (n_rows * 50) + 2) 
     96        self.max_size = self.min_size 
     97     
     98    def _getGridSize(self): 
     99        n_rows = len(self.children) 
     100        n_columns = len(self.children[0].children) 
     101        return (n_rows, n_columns) 
     102    grid_size = property(fget=_getGridSize, fset=_setGridSize) 
     103     
     104    def __init__(self, grid_size=(2, 2), padding=0, **kwargs): 
     105        pychan.VBox.__init__(self, padding=padding, **kwargs) 
     106        self.opaque = 0 
     107        self.grid_size = grid_size 
     108        self.border_size = 1 
     109 
     110 
    25111class InventoryGUI(ContainerGUIBase): 
     112    def __init__(self, controller, inventory, callbacks): 
     113        super(InventoryGUI, self).__init__(controller, "gui/inventory.xml") 
     114        self.engine = controller.engine 
     115        self.inventory_shown = False 
     116        render_backend = self.engine.getRenderBackend() 
     117        screen_mode = render_backend.getCurrentScreenMode() 
     118        screen_width, screen_height = (screen_mode.getWidth(), 
     119                                       screen_mode.getHeight()) 
     120        widget_width, widget_height = self.gui.size 
     121        self.gui.position = ((screen_width - widget_width) / 2, 
     122                             (screen_height - widget_height) / 2) 
     123     
     124    def toggleInventory(self, toggleImage=True): 
     125        """Pause the game and enter the inventory screen, or close the 
     126           inventory screen and resume the game. 
     127           @type toggleImage: bool 
     128           @param toggleImage: 
     129               Call toggleInventoryCallback if True. Toggling via a 
     130               keypress requires that we toggle the Hud inventory image 
     131               explicitly. Clicking on the Hud inventory button toggles the 
     132               image implicitly, so we don't change it. 
     133           @return: None""" 
     134        if not self.inventory_shown: 
     135            self.showInventory() 
     136            self.inventory_shown = True 
     137        else: 
     138            self.closeInventory() 
     139            self.inventory_shown = False 
     140     
     141    def showInventory(self): 
     142        self.gui.show() 
     143     
     144    def closeInventory(self): 
     145        self.gui.hide() 
     146 
     147 
     148class _InventoryGUI(ContainerGUIBase): 
    26149    """Inventory GUI class""" 
    27150    def __init__(self, controller, inventory, callbacks): 
Note: See TracChangeset for help on using the changeset viewer.