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