Mercurial > parpg-source
annotate gui/inventorygui.py @ 42:66a06de1bddc
Renamed dialog to dialogue
author | KarstenBock@gmx.net |
---|---|
date | Tue, 06 Sep 2011 14:37:54 +0200 |
parents | 06145a6ee387 |
children | c40d04cf6ed1 |
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/>. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 from fife.extensions.pychan.tools import callbackWithArguments as cbwa |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 from fife.extensions import pychan |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 from fife.extensions.pychan.attrs import UnicodeAttr |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 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
|
21 from parpg.objects.base import Container |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
22 from parpg.gui.containergui_base import ContainerGUIBase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 from parpg.objects.action import ACTIONS |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 import logging |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 logger = logging.getLogger('action') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
28 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 class EquipmentSlot(pychan.VBox): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 ATTRIBUTES = pychan.VBox.ATTRIBUTES + [UnicodeAttr('label_text')] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
31 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 def _setLabelText(self, text): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 label = self.findChild() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 label.text = unicode(text) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 label.resizeToContent() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 self.margins = ( |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 int((self.width - label.width) / 2.0), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 int((self.height - label.height) / 2.0) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 ) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 def _getLabelText(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 label = self.findChild() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 return label.text |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 label_text = property(fget=_getLabelText, fset=_setLabelText) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 def __init__(self, label_text=u'equipment', min_size=(50, 50), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 max_size=(50, 50), margins=None, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 **kwargs): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 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
|
51 **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
|
52 self.background_image = 'gui/inv_images/inv_background.png' |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 label = pychan.Label(text=unicode(label_text)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 self.addChild(label) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 self.label_text = label_text |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 self.adaptLayout() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 if self.parent is not None: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 self.beforeShow() |
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 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 class InventoryGrid(pychan.VBox): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size')] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 def _setNColumns(self, n_columns): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 n_rows = self.grid_size[1] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 self.grid_size = (n_columns, n_rows) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 def _getNColumns(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 n_columns = self.grid_size[0] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 return n_columns |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 n_columns = property(fget=_getNColumns, fset=_setNColumns) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 def _setNRows(self, n_rows): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 n_columns = self.grid_size[0] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 self.grid_size = (n_columns, n_rows) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 def _getNRows(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 n_rows = self.grid_size[1] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 return n_rows |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 n_rows = property(fget=_getNRows, fset=_getNColumns) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 def _setGridSize(self, grid_size): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 n_columns, n_rows = grid_size |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 self.removeAllChildren() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 for row_n in range(n_rows): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 row_size = (n_columns * 50, 50) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 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
|
88 padding=self.padding) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 row.border_size = 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 row.opaque = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
91 for column_n in range(n_columns): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
92 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
|
93 slot.border_size = 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
94 row.addChild(slot) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
95 self.addChild(row) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
96 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
|
97 self.max_size = self.min_size |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 def _getGridSize(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
100 n_rows = len(self.children) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
101 n_columns = len(self.children[0].children) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
102 return (n_rows, n_columns) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
103 grid_size = property(fget=_getGridSize, fset=_setGridSize) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
104 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
105 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
|
106 pychan.VBox.__init__(self, padding=padding, **kwargs) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
107 self.opaque = 0 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
108 self.grid_size = grid_size |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
109 self.border_size = 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
110 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
111 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
112 class InventoryGUI(ContainerGUIBase): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
113 def __init__(self, controller, inventory, callbacks): |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
114 super(InventoryGUI, self).__init__(controller, inventory) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
115 self.engine = controller.engine |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
116 self.inventory_shown = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
117 render_backend = self.engine.getRenderBackend() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
118 screen_mode = render_backend.getCurrentScreenMode() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
119 screen_width, screen_height = (screen_mode.getWidth(), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 screen_mode.getHeight()) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
121 widget_width, widget_height = self.gui.size |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
122 self.gui.position = ((screen_width - widget_width) / 2, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
123 (screen_height - widget_height) / 2) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
125 def toggleInventory(self, toggleImage=True): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
126 """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
|
127 inventory screen and resume the game. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
128 @type toggleImage: bool |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
129 @param toggleImage: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
130 Call toggleInventoryCallback if True. Toggling via a |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 keypress requires that we toggle the Hud inventory image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 explicitly. Clicking on the Hud inventory button toggles the |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 image implicitly, so we don't change it. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 if not self.inventory_shown: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 self.showInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
137 self.inventory_shown = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
139 self.closeInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
140 self.inventory_shown = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
141 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
142 def showInventory(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
143 self.gui.show() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
144 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
145 def closeInventory(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 self.gui.hide() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
147 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 class _InventoryGUI(ContainerGUIBase): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
150 """Inventory GUI class""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 def __init__(self, controller, inventory, callbacks): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
152 """Initialise the instance. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 @param controller: Current Controller |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 @type controller: Class derived from ControllerBase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 @type inventory: Inventory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 @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
|
157 @type callbacks: dict |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
158 @param callbacks: a dict of callbacks |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 refreshReadyImages: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
160 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
|
161 reflect those within the inventory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 toggleInventoryButton: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 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
|
164 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 super(InventoryGUI, self).__init__(controller, "gui/inventory.xml") |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
166 self.engine = controller.engine |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 self.readyCallback = callbacks['refreshReadyImages'] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 self.toggleInventoryButtonCallback = callbacks['toggleInventoryButton'] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 self.original_cursor_id = self.engine.getCursor().getId() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
170 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 self.inventory_shown = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
172 events_to_map = {} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
173 self.inventory_storage = inventory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
174 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
175 # Buttons of inventory arranged by slots |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
176 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
177 self.slot_buttons = {'head': ('Head',), 'chest': ('Body',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
178 'left_arm': ('LeftHand',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
179 'right_arm': ('RightHand',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
180 'hips' : ('Belt',), 'left_leg': ('LeftFoot',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
181 'right_leg': ('RightFoot',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
182 'left_hand': ('LeftHeld',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
183 'right_hand': ('RightHeld',), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
184 'backpack': ('A1', 'A2', 'A3', 'A4', 'A5', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
185 'B1', 'B2', 'B3', 'B4', 'B5', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
186 'C1', 'C2', 'C3', 'C4', 'C5', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
187 'D1', 'D2', 'D3', 'D4', 'D5'), |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
188 'ready': ('Ready1', 'Ready2', 'Ready3', 'Ready4') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
189 } |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
190 # 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
|
191 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
|
192 'chest':'gui/inv_images/inv_torso.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
193 'left_arm':'gui/inv_images/inv_lhand.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
194 'right_arm':'gui/inv_images/inv_rhand.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
195 'hips':'gui/inv_images/inv_belt.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
196 'left_leg':'gui/inv_images/inv_lfoot.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
197 'right_leg':'gui/inv_images/inv_rfoot.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
198 'left_hand':'gui/inv_images/inv_litem.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
199 'right_hand':'gui/inv_images/inv_ritem.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
200 'backpack':'gui/inv_images/inv_backpack.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
201 'ready':'gui/inv_images/inv_belt_pouches.png', |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
202 } |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
203 self.updateInventoryButtons() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
204 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
205 for slot in self.slot_buttons: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
206 for _, button in enumerate(self.slot_buttons[slot]): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
207 events_to_map[button] = cbwa(self.dragDrop, button) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
208 events_to_map[button + "/mouseReleased"] = \ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
209 self.showContextMenu |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
210 events_to_map['close_button'] = self.closeInventoryAndToggle |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
211 self.gui.mapEvents(events_to_map) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
212 # TODO: Why the commented out code? |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
213 # self.resetMouseCursor() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
214 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
215 def updateImages(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
216 self.updateInventoryButtons() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
217 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
218 def updateInventoryButtons (self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
219 for slot in self.slot_buttons: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
220 for index, button in enumerate(self.slot_buttons[slot]): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
221 widget = self.gui.findChild(name=button) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
222 widget.slot = slot |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
223 widget.index = index |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
224 widget.item = self.inventory_storage.getItemsInSlot(widget.slot, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
225 widget.index) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
226 self.updateImage(widget) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
227 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
228 def updateImage(self, button): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
229 if (button.item == None): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
230 image = self.slot_empty_images[button.slot] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
231 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
232 image = button.item.getInventoryThumbnail() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
233 button.up_image = image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
234 button.down_image = image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
235 button.hover_image = image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
236 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
237 def closeInventory(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
238 """Close the inventory. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
239 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
240 self.gui.hide() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
241 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
242 def closeInventoryAndToggle(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
243 """Close the inventory screen. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
244 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
245 self.closeInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
246 self.toggleInventoryButtonCallback() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
247 self.inventory_shown = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
248 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
249 def toggleInventory(self, toggleImage=True): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
250 """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
|
251 inventory screen and resume the game. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
252 @type toggleImage: bool |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
253 @param toggleImage: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
254 Call toggleInventoryCallback if True. Toggling via a |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
255 keypress requires that we toggle the Hud inventory image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
256 explicitly. Clicking on the Hud inventory button toggles the |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
257 image implicitly, so we don't change it. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
258 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
259 if not self.inventory_shown: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
260 self.showInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
261 self.inventory_shown = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
262 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
263 self.closeInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
264 self.inventory_shown = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
265 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
266 if toggleImage: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
267 self.toggleInventoryButtonCallback() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
268 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
269 def showInventory(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
270 """Show the inventory. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
271 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
272 self.updateInventoryButtons() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
273 self.gui.show() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
274 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
275 def dragObject(self, obj): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
276 """Drag the selected object. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
277 @type obj: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
278 @param obj: The name of the object within |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
279 the dictionary 'self.buttons' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
280 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
281 # 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
|
282 drag_widget = self.gui.findChild(name = obj) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
283 drag_item = drag_widget.item |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
284 # only drag if the widget is not empty |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
285 if (drag_item != None): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
286 # get the item that the widget is 'storing' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
287 data_drag.dragged_item = drag_widget.item |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
288 # get the up and down images of the widget |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
289 up_image = drag_widget.up_image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
290 down_image = drag_widget.down_image |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
291 # 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
|
292 self.controller.setMouseCursor(up_image.source,down_image.source) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
293 data_drag.dragged_image = up_image.source |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
294 data_drag.dragging = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
295 data_drag.dragged_widget = drag_widget |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
296 data_drag.source_container = self.inventory_storage |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
297 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
298 self.inventory_storage.takeItem(drag_widget.item) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
299 # after dragging the 'item', set the widgets' images |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
300 # so that it has it's default 'empty' images |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
301 drag_widget.item = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
302 self.updateImage(drag_widget) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
303 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
304 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
305 def dropObject(self, obj): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
306 """Drops the object being dropped |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
307 @type obj: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
308 @param obj: The name of the object within |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
309 the dictionary 'self.buttons' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
310 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
311 drop_widget = self.gui.findChild(name = obj) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
312 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
|
313 replace_item = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
314 try : |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
315 if data_drag.dragging: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
316 inventory = self.inventory_storage |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
317 drag_item = data_drag.dragged_item |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
318 #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
|
319 ## there is an item All ready occupying the slot |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
320 if not inventory.isSlotEmpty(drop_slot, drop_index): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
321 #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
|
322 replace_item = inventory.getItemsInSlot \ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
323 (drop_slot, drop_index) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
324 self.dragObject(obj) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
325 self.inventory_storage.moveItemToSlot(drag_item, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
326 drop_slot, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
327 drop_index) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
328 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
329 if drop_widget.slot == 'ready': |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
330 self.readyCallback() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
331 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
332 if replace_item == None: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
333 self.controller.resetMouseCursor() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
334 data_drag.dragging = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
335 except Container.TooBig : |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
336 logger.warning("%s too big to fit " |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
337 "into %s" % (data_drag.dragged_item, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
338 drop_widget.slot)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
339 except (Container.SlotBusy, Container.ItemSelf): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
340 pass |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
341 self.updateInventoryButtons() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
342 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
343 def createMenuItems(self, item, actions): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
344 """Creates context menu items for the InventoryGUI""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
345 menu_actions = super(InventoryGUI, self).createMenuItems(item, actions) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
346 param_dict = {} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
347 param_dict["controller"] = self.controller |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
348 param_dict["commands"] = {} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
349 param_dict["item"] = item |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
350 param_dict["container_gui"] = self |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
351 menu_actions.append(["Drop", |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
352 "Drop", |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
353 self.executeMenuItem, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
354 ACTIONS["DropFromInventory"](**param_dict)]) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
355 return menu_actions |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
356 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
357 def getImage(self, name): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
358 """Return a current image from the inventory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
359 @type name: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
360 @param name: name of image to get |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
361 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
362 return self.gui.findChild(name = name) |