annotate src/parpg/gui/inventorygui.py @ 170:371b17bc9113

Added ReplaceItemAction, to dialogueactions, which replaces a single item in the players inventory.
author KarstenBock@gmx.net
date Sun, 09 Oct 2011 14:39:02 +0200
parents 6d07093e9d51
children 2d671e57badb
rev   line source
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 # This file is part of PARPG.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # (at your option) any later version.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # GNU General Public License for more details.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
15 import logging
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
16 from types import StringTypes
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 from fife.extensions.pychan.tools import callbackWithArguments as cbwa
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19 from fife.extensions import pychan
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 from fife.extensions.pychan.attrs import UnicodeAttr
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 from parpg.gui import drag_drop_data as data_drag
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 from parpg.gui.containergui_base import ContainerGUIBase
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
24 from parpg.objects.action import ACTIONS
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
25 from parpg.components import equip, container
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
26 from parpg.entities import General
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 logger = logging.getLogger('action')
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 class EquipmentSlot(pychan.VBox):
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
31 def __init__(self, min_size=(50, 50),
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32 max_size=(50, 50), margins=None,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33 **kwargs):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 pychan.VBox.__init__(self, min_size=min_size, max_size=max_size,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35 **kwargs)
12
d60f1dab8469 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
36 self.background_image = 'gui/inv_images/inv_background.png'
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
37 icon = pychan.Icon(name="Icon")
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
38 self.addChild(icon)
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 self.adaptLayout()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 if self.parent is not None:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 self.beforeShow()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
43 @property
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
44 def image(self):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
45 icon = self.findChildByName("Icon")
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
46 return icon.image
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
47
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
48 @image.setter
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
49 def image(self, image):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
50 icon = self.findChildByName("Icon")
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
51 icon.image = image
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 class InventoryGrid(pychan.VBox):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54 ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size')]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 def _setNColumns(self, n_columns):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 n_rows = self.grid_size[1]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 self.grid_size = (n_columns, n_rows)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 def _getNColumns(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 n_columns = self.grid_size[0]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 return n_columns
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 n_columns = property(fget=_getNColumns, fset=_setNColumns)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 def _setNRows(self, n_rows):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 n_columns = self.grid_size[0]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 self.grid_size = (n_columns, n_rows)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 def _getNRows(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 n_rows = self.grid_size[1]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 return n_rows
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 n_rows = property(fget=_getNRows, fset=_getNColumns)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 def _setGridSize(self, grid_size):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 n_columns, n_rows = grid_size
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 self.removeAllChildren()
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
77 for row_n in xrange(n_rows):
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78 row_size = (n_columns * 50, 50)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 row = pychan.HBox(min_size=row_size, max_size=row_size,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 padding=self.padding)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 row.border_size = 1
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 row.opaque = 0
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
83 for column_n in xrange(n_columns):
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
84 index = (row_n * n_columns + column_n)
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 slot = pychan.Icon(min_size=(50, 50), max_size=(50, 50))
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 slot.border_size = 1
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
87 slot.name = "Slot_%d" % index
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
88 slot.index = index
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89 row.addChild(slot)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
90 self.addChild(row)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 self.min_size = ((n_columns * 50) + 2, (n_rows * 50) + 2)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 self.max_size = self.min_size
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
93
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 def _getGridSize(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 n_rows = len(self.children)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 n_columns = len(self.children[0].children)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 return (n_rows, n_columns)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 grid_size = property(fget=_getGridSize, fset=_setGridSize)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
100 def getSlot(self, row_or_index, col=None):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
101 if col:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
102 index = row * self.n_columns + col
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
103 else:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
104 index = row_or_index
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
105 return self.findChildByName("Slot_%d" % index)
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
106
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 def __init__(self, grid_size=(2, 2), padding=0, **kwargs):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
108 pychan.VBox.__init__(self, padding=padding, **kwargs)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 self.opaque = 0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110 self.grid_size = grid_size
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
111 self.border_size = 1
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
113
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
114 class EquipmentGUI(ContainerGUIBase):
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
115 def __init__(self, controller, gui, equip, callbacks):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
116 ContainerGUIBase.__init__(self, controller, gui)
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
117 self.equip = equip
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
118 self.equip_to_gui = {
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
119 "head": "headSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
120 "neck": "neckSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
121 "body": "shirtSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
122 "belt": "beltSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
123 "leg": "pantsSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
124 "feet": "bootsSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
125 "l_arm": "leftHandSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
126 "r_arm": "rightHandSlot",
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
127 }
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
128
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
129 def updateImages(self):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
130 for eq_slot, gui_slot in self.equip_to_gui.iteritems():
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
131 widget = self.gui.findChild(name=gui_slot)
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
132 equipable = equip.get_equipable(self.equip, eq_slot)
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
133 widget.item = equipable.entity if equipable else None
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
134 self.updateImage(widget)
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
135
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
136 def updateImage(self, slot):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
137 assert(isinstance(slot, EquipmentSlot))
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
138 if (slot.item):
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
139 image = slot.item.containable.image
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
140 else:
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
141 image = None
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
142 slot.image = image
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
143
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
144 class InventoryGUI(ContainerGUIBase):
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
145 def __init__(self, controller, gui, container, callbacks):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
146 ContainerGUIBase.__init__(self, controller, gui)
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
147 self.grid = self.gui.findChildByName("Grid")
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
148 assert(isinstance(self.grid, InventoryGrid))
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
149 self.container = container
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
150 self.setSlotEvents()
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
151
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
152 def setSlotEvents(self):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
153 slot_count = self.grid.n_rows * self.grid.n_columns
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
154 events_to_map = {}
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
155 for counter in xrange(0, slot_count):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
156 widget = self.grid.getSlot(counter)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
157 slot_name = widget.name
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
158 widget.index = counter
165
6d07093e9d51 Added context menu to the inventory.
KarstenBock@gmx.net
parents: 163
diff changeset
159 events_to_map[slot_name + "/mousePressed"] = (
6d07093e9d51 Added context menu to the inventory.
KarstenBock@gmx.net
parents: 163
diff changeset
160 self.mousePressedOnSlot
6d07093e9d51 Added context menu to the inventory.
KarstenBock@gmx.net
parents: 163
diff changeset
161 )
6d07093e9d51 Added context menu to the inventory.
KarstenBock@gmx.net
parents: 163
diff changeset
162 events_to_map[slot_name + "/mouseReleased"] = self.showContextMenu
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
163
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
164 self.grid.mapEvents(events_to_map)
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
165
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
166 def updateImages(self):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
167 for index, child in enumerate(self.container.children):
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
168 slot = self.grid.getSlot(index)
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
169 if child:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
170 slot.item = child.entity
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
171 else:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
172 slot.item = None
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
173 self.updateImage(slot)
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
174
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
175 def updateImage(self, slot):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
176 assert(isinstance(slot, pychan.Icon))
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
177 if (slot.item):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
178 image = slot.item.containable.image
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
179 else:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
180 image = None
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
181 slot.image = image
153
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
182
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
183 def mousePressedOnSlot(self, event, widget):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
184 if event.getButton() == event.LEFT:
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
185 self.dragDrop(widget.name)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
186
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
187 def dragObject(self, obj):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
188 """Drag the selected object.
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
189 @type obj: string
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
190 @param obj: The name of the object within
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
191 the dictionary 'self.buttons'
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
192 @return: None"""
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
193 # get the widget from the gui with the name obj
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
194 drag_widget = self.gui.findChild(name = obj)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
195 drag_item = drag_widget.item
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
196 # only drag if the widget is not empty
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
197 if (drag_item != None):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
198 if isinstance(drag_item, General):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
199 drag_item = drag_item.containable
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
200 # get the image of the widget
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
201 image = drag_widget.image
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
202 self.setDragData(drag_item, image, image, self.container)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
203 container.take_item(self.container, drag_item.slot)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
204
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
205 # after dragging the 'item', set the widgets' images
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
206 # so that it has it's default 'empty' images
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
207 drag_widget.item = None
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
208 self.updateImage(drag_widget)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
209
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
210 def dropObject(self, obj):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
211 """Drops the object being dropped
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
212 @type obj: string
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
213 @param obj: The name of the object within
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
214 the dictionary 'self.buttons'
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
215 @return: None"""
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
216 try:
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
217 drop_widget = self.gui.findChildByName(obj)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
218 drop_index = drop_widget.index
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
219 replace_item = None
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
220
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
221 if data_drag.dragging:
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
222 drag_item = data_drag.dragged_item
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
223 #this will get the replacement item and the data for drag_drop if
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
224 ## there is an item all ready occupying the slot
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
225 replace_item = (
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
226 container.put_item(self.container, drag_item, drop_index)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
227 )
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
228
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
229 #if there was no item the stop dragging and reset cursor
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
230 if replace_item:
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
231 image = drop_widget.image
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
232 self.setDragData(replace_item, image, image, self.container)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
233 else:
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
234 data_drag.dragging = False
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
235 #reset the mouse cursor to the normal cursor
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
236 self.controller.resetMouseCursor()
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
237 drop_widget.item = drag_item.entity
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
238 self.updateImage(drop_widget)
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
239 except (container.BulkLimitError):
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
240 #Do we want to notify the player why the item can't be dropped?
2ba7c6d8f738 Added drag and drop functionality to the players inventory grid.
KarstenBock@gmx.net
parents: 150
diff changeset
241 pass
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
242
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
243 class CharacterGUI(object):
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
244 def __init__(self, controller, gui, container, equip, callbacks):
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
245 self.engine = controller.engine
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
246 self.inventory_shown = False
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
247 if isinstance(gui, pychan.Widget):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
248 self.gui = gui
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
249 elif isinstance(gui, StringTypes):
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
250 xml_file = vfs.VFS.open(gui)
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
251 self.gui = pychan.loadXML(xml_file)
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
252 else:
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
253 self.gui = pychan.loadXML(gui)
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
254
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
255 render_backend = self.engine.getRenderBackend()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
256 screen_mode = render_backend.getCurrentScreenMode()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
257 screen_width, screen_height = (screen_mode.getWidth(),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
258 screen_mode.getHeight())
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
259 widget_width, widget_height = self.gui.size
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
260 self.gui.position = ((screen_width - widget_width) / 2,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
261 (screen_height - widget_height) / 2)
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
262 self.equip_gui = EquipmentGUI(
149
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
263 controller,
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
264 self.gui.findChildByName("equipmentPage"),
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
265 equip, callbacks
eab3e1e52497 Modified EquipmentSlot to display an image instead of a text.
KarstenBock@gmx.net
parents: 142
diff changeset
266 )
150
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
267 self.inv_gui = InventoryGUI(
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
268 controller,
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
269 self.gui.findChildByName("inventoryPage"),
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
270 container, callbacks
3fc7cfa80771 Modified InventoryGrid to set a name for each slot containing the index.
KarstenBock@gmx.net
parents: 149
diff changeset
271 )
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
272
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
273 def toggleInventory(self, toggleImage=True):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
274 """Pause the game and enter the inventory screen, or close the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
275 inventory screen and resume the game.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
276 @type toggleImage: bool
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
277 @param toggleImage:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
278 Call toggleInventoryCallback if True. Toggling via a
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
279 keypress requires that we toggle the Hud inventory image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
280 explicitly. Clicking on the Hud inventory button toggles the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
281 image implicitly, so we don't change it.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
282 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
283 if not self.inventory_shown:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
284 self.showInventory()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
285 self.inventory_shown = True
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
286 else:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
287 self.closeInventory()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
288 self.inventory_shown = False
163
50c248656348 Added updateImages method to CharacterGUI.
KarstenBock@gmx.net
parents: 153
diff changeset
289
50c248656348 Added updateImages method to CharacterGUI.
KarstenBock@gmx.net
parents: 153
diff changeset
290 def updateImages(self):
50c248656348 Added updateImages method to CharacterGUI.
KarstenBock@gmx.net
parents: 153
diff changeset
291 self.equip_gui.updateImages()
50c248656348 Added updateImages method to CharacterGUI.
KarstenBock@gmx.net
parents: 153
diff changeset
292 self.inv_gui.updateImages()
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
293
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
294 def showInventory(self):
163
50c248656348 Added updateImages method to CharacterGUI.
KarstenBock@gmx.net
parents: 153
diff changeset
295 self.updateImages()
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
296 self.gui.show()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
297
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
298 def closeInventory(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
299 self.gui.hide()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
300
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
301
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
302 class _InventoryGUI(ContainerGUIBase):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
303 """Inventory GUI class"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
304 def __init__(self, controller, inventory, callbacks):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
305 """Initialise the instance.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
306 @param controller: Current Controller
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
307 @type controller: Class derived from ControllerBase
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
308 @type inventory: Inventory
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
309 @param inventory: An inventory object to be displayed and manipulated
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
310 @type callbacks: dict
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
311 @param callbacks: a dict of callbacks
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
312 refreshReadyImages:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
313 Function that will make the ready slots on the HUD
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
314 reflect those within the inventory
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
315 toggleInventoryButton:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
316 Function that will toggle the state of the inventory button
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
317 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
318 super(InventoryGUI, self).__init__(controller, "gui/inventory.xml")
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
319 self.engine = controller.engine
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
320 self.readyCallback = callbacks['refreshReadyImages']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
321 self.toggleInventoryButtonCallback = callbacks['toggleInventoryButton']
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
322 self.original_cursor_id = self.engine.getCursor().getId()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
323
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
324 self.inventory_shown = False
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
325 events_to_map = {}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
326 self.inventory_storage = inventory
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
327
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
328 # Buttons of inventory arranged by slots
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
329
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
330 self.slot_buttons = {'head': ('Head',), 'chest': ('Body',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
331 'left_arm': ('LeftHand',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
332 'right_arm': ('RightHand',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
333 'hips' : ('Belt',), 'left_leg': ('LeftFoot',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
334 'right_leg': ('RightFoot',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
335 'left_hand': ('LeftHeld',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
336 'right_hand': ('RightHeld',),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
337 'backpack': ('A1', 'A2', 'A3', 'A4', 'A5',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
338 'B1', 'B2', 'B3', 'B4', 'B5',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
339 'C1', 'C2', 'C3', 'C4', 'C5',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
340 'D1', 'D2', 'D3', 'D4', 'D5'),
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
341 'ready': ('Ready1', 'Ready2', 'Ready3', 'Ready4')
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
342 }
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
343 # the images that should be used for the buttons when they are "empty"
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
344 self.slot_empty_images = {'head':'gui/inv_images/inv_head.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
345 'chest':'gui/inv_images/inv_torso.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
346 'left_arm':'gui/inv_images/inv_lhand.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
347 'right_arm':'gui/inv_images/inv_rhand.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
348 'hips':'gui/inv_images/inv_belt.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
349 'left_leg':'gui/inv_images/inv_lfoot.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
350 'right_leg':'gui/inv_images/inv_rfoot.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
351 'left_hand':'gui/inv_images/inv_litem.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
352 'right_hand':'gui/inv_images/inv_ritem.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
353 'backpack':'gui/inv_images/inv_backpack.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
354 'ready':'gui/inv_images/inv_belt_pouches.png',
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
355 }
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
356 self.updateInventoryButtons()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
357
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
358 for slot in self.slot_buttons:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
359 for _, button in enumerate(self.slot_buttons[slot]):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
360 events_to_map[button] = cbwa(self.dragDrop, button)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
361 events_to_map[button + "/mouseReleased"] = \
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
362 self.showContextMenu
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
363 events_to_map['close_button'] = self.closeInventoryAndToggle
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
364 self.gui.mapEvents(events_to_map)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
365 # TODO: Why the commented out code?
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
366 # self.resetMouseCursor()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
367
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
368 def updateImages(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
369 self.updateInventoryButtons()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
370
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
371 def updateInventoryButtons (self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
372 for slot in self.slot_buttons:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
373 for index, button in enumerate(self.slot_buttons[slot]):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
374 widget = self.gui.findChild(name=button)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
375 widget.slot = slot
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
376 widget.index = index
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
377 widget.item = self.inventory_storage.getItemsInSlot(widget.slot,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
378 widget.index)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
379 self.updateImage(widget)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
380
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
381 def updateImage(self, button):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
382 if (button.item == None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
383 image = self.slot_empty_images[button.slot]
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
384 else:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
385 image = button.item.getInventoryThumbnail()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
386 button.up_image = image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
387 button.down_image = image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
388 button.hover_image = image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
389
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
390 def closeInventory(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
391 """Close the inventory.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
392 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
393 self.gui.hide()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
394
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
395 def closeInventoryAndToggle(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
396 """Close the inventory screen.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
397 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
398 self.closeInventory()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
399 self.toggleInventoryButtonCallback()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
400 self.inventory_shown = False
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
401
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
402 def toggleInventory(self, toggleImage=True):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
403 """Pause the game and enter the inventory screen, or close the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
404 inventory screen and resume the game.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
405 @type toggleImage: bool
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
406 @param toggleImage:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
407 Call toggleInventoryCallback if True. Toggling via a
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
408 keypress requires that we toggle the Hud inventory image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
409 explicitly. Clicking on the Hud inventory button toggles the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
410 image implicitly, so we don't change it.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
411 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
412 if not self.inventory_shown:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
413 self.showInventory()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
414 self.inventory_shown = True
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
415 else:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
416 self.closeInventory()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
417 self.inventory_shown = False
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
418
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
419 if toggleImage:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
420 self.toggleInventoryButtonCallback()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
421
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
422 def showInventory(self):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
423 """Show the inventory.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
424 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
425 self.updateInventoryButtons()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
426 self.gui.show()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
427
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
428 def dragObject(self, obj):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
429 """Drag the selected object.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
430 @type obj: string
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
431 @param obj: The name of the object within
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
432 the dictionary 'self.buttons'
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
433 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
434 # get the widget from the inventory with the name obj
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
435 drag_widget = self.gui.findChild(name = obj)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
436 drag_item = drag_widget.item
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
437 # only drag if the widget is not empty
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
438 if (drag_item != None):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
439 # get the item that the widget is 'storing'
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
440 data_drag.dragged_item = drag_widget.item
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
441 # get the up and down images of the widget
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
442 up_image = drag_widget.up_image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
443 down_image = drag_widget.down_image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
444 # set the mouse cursor to be the widget's image
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
445 self.controller.setMouseCursor(up_image.source,down_image.source)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
446 data_drag.dragged_image = up_image.source
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
447 data_drag.dragging = True
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
448 data_drag.dragged_widget = drag_widget
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
449 data_drag.source_container = self.inventory_storage
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
450
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
451 self.inventory_storage.takeItem(drag_widget.item)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
452 # after dragging the 'item', set the widgets' images
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
453 # so that it has it's default 'empty' images
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
454 drag_widget.item = None
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
455 self.updateImage(drag_widget)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
456
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
457
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
458 def dropObject(self, obj):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
459 """Drops the object being dropped
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
460 @type obj: string
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
461 @param obj: The name of the object within
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
462 the dictionary 'self.buttons'
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
463 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
464 drop_widget = self.gui.findChild(name = obj)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
465 drop_slot, drop_index = drop_widget.slot, drop_widget.index
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
466 replace_item = None
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
467 try :
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
468 if data_drag.dragging:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
469 inventory = self.inventory_storage
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
470 drag_item = data_drag.dragged_item
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
471 #this will get the replacement item and data for drag_drop if
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
472 ## there is an item All ready occupying the slot
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
473 if not inventory.isSlotEmpty(drop_slot, drop_index):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
474 #get the item and then remove it from the inventory
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
475 replace_item = inventory.getItemsInSlot \
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
476 (drop_slot, drop_index)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
477 self.dragObject(obj)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
478 self.inventory_storage.moveItemToSlot(drag_item,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
479 drop_slot,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
480 drop_index)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
481
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
482 if drop_widget.slot == 'ready':
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
483 self.readyCallback()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
484
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
485 if replace_item == None:
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
486 self.controller.resetMouseCursor()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
487 data_drag.dragging = False
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
488 except Container.TooBig :
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
489 logger.warning("%s too big to fit "
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
490 "into %s" % (data_drag.dragged_item,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
491 drop_widget.slot))
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
492 except (Container.SlotBusy, Container.ItemSelf):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
493 pass
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
494 self.updateInventoryButtons()
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
495
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
496 def createMenuItems(self, item, actions):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
497 """Creates context menu items for the InventoryGUI"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
498 menu_actions = super(InventoryGUI, self).createMenuItems(item, actions)
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
499 param_dict = {}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
500 param_dict["controller"] = self.controller
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
501 param_dict["commands"] = {}
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
502 param_dict["item"] = item
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
503 param_dict["container_gui"] = self
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
504 menu_actions.append(["Drop",
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
505 "Drop",
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
506 self.executeMenuItem,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
507 ACTIONS["DropFromInventory"](**param_dict)])
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
508 return menu_actions
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
509
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
510 def getImage(self, name):
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
511 """Return a current image from the inventory
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
512 @type name: string
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
513 @param name: name of image to get
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
514 @return: None"""
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
515 return self.gui.findChild(name = name)