Mercurial > parpg-core
comparison src/parpg/gui/containergui.py @ 137:140e5e93f026
Added ExamineContentsAction.
Added "Examine Contents" to the context menu, when the object is a container and does not have a characterstats component.
author | KarstenBock@gmx.net |
---|---|
date | Fri, 30 Sep 2011 15:31:53 +0200 |
parents | 1fd2201f5c36 |
children | b96607c8be7f |
comparison
equal
deleted
inserted
replaced
136:e1fd4cda237d | 137:140e5e93f026 |
---|---|
12 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 12 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
13 from fife.extensions.pychan.tools import callbackWithArguments as cbwa | 13 from fife.extensions.pychan.tools import callbackWithArguments as cbwa |
14 | 14 |
15 from parpg.gui.containergui_base import ContainerGUIBase | 15 from parpg.gui.containergui_base import ContainerGUIBase |
16 from parpg.gui import drag_drop_data as data_drag | 16 from parpg.gui import drag_drop_data as data_drag |
17 from parpg.objects.base import Container | 17 from parpg.components import container |
18 | 18 |
19 class ContainerGUI(ContainerGUIBase): | 19 class ContainerGUI(ContainerGUIBase): |
20 def __init__(self, controller, title, container): | 20 def __init__(self, controller, title, container): |
21 """A class to create a window showing the contents of a container. | 21 """A class to create a window showing the contents of a container. |
22 @param controller: The current Controller | 22 @param controller: The current Controller |
23 @type controller: Class derived from ControllerBase | 23 @type controller: Class derived from ControllerBase |
24 @param title: The title of the window | 24 @param title: The title of the window |
25 @type title: string | 25 @type title: string |
26 @param container: A container to represent | 26 @param container: A container to represent |
27 @type container: Container | 27 @type container: parpg.components.Container |
28 @return: None""" | 28 @return: None""" |
29 super(ContainerGUI, self).__init__(controller, "gui/container_base.xml") | 29 super(ContainerGUI, self).__init__(controller, "gui/container_base.xml") |
30 self.gui.findChild(name="topWindow").title = title | 30 self.gui.findChild(name="topWindow").title = title |
31 | 31 |
32 self.empty_images = dict() | 32 self.empty_images = dict() |
36 "Slot4", "Slot5", "Slot6", | 36 "Slot4", "Slot5", "Slot6", |
37 "Slot7", "Slot8", "Slot9") | 37 "Slot7", "Slot8", "Slot9") |
38 | 38 |
39 def updateImages(self): | 39 def updateImages(self): |
40 for index, button in enumerate(self.buttons): | 40 for index, button in enumerate(self.buttons): |
41 widget = self.gui.findChild(name=button) | 41 widget = self.gui.findChild(name=button) |
42 widget.item = self.container.getItemAt(index) | 42 widget.item = container.get_item(self.container, index) |
43 self.updateImage(widget) | 43 self.updateImage(widget) |
44 | 44 |
45 def updateImage(self, button): | 45 def updateImage(self, button): |
46 if (button.item == None): | 46 if (button.item == None): |
47 image = self.empty_images[button.name] | 47 image = self.empty_images[button.name] |
48 else: | 48 else: |
49 image = button.item.getInventoryThumbnail() | 49 image = button.item.image |
50 button.up_image = image | 50 button.up_image = image |
51 button.down_image = image | 51 button.down_image = image |
52 button.hover_image = image | 52 button.hover_image = image |
53 | 53 |
54 def dragObject(self, obj): | 54 def dragObject(self, obj): |
71 self.controller.setMouseCursor(up_image.source, down_image.source) | 71 self.controller.setMouseCursor(up_image.source, down_image.source) |
72 data_drag.dragged_image = up_image.source | 72 data_drag.dragged_image = up_image.source |
73 data_drag.dragging = True | 73 data_drag.dragging = True |
74 data_drag.dragged_widget = drag_widget | 74 data_drag.dragged_widget = drag_widget |
75 data_drag.source_container = self.container | 75 data_drag.source_container = self.container |
76 | 76 container.take_item(self.container, drag_widget.item.slot) |
77 self.container.takeItem(drag_widget.item) | |
78 | 77 |
79 # after dragging the 'item', set the widgets' images | 78 # after dragging the 'item', set the widgets' images |
80 # so that it has it's default 'empty' images | 79 # so that it has it's default 'empty' images |
81 drag_widget.item = None | 80 drag_widget.item = None |
82 self.updateImage(drag_widget) | 81 self.updateImage(drag_widget) |
88 the dictionary 'self.buttons' | 87 the dictionary 'self.buttons' |
89 @return: None""" | 88 @return: None""" |
90 try: | 89 try: |
91 drop_widget = self.gui.findChild(name = obj) | 90 drop_widget = self.gui.findChild(name = obj) |
92 drop_index = drop_widget.index | 91 drop_index = drop_widget.index |
93 replace_item = drop_widget.item | 92 replace_item = None |
94 | 93 |
95 if data_drag.dragging: | 94 if data_drag.dragging: |
96 container = self.container | |
97 drag_item = data_drag.dragged_item | 95 drag_item = data_drag.dragged_item |
98 #this will get the replacement item and the data for drag_drop if | 96 #this will get the replacement item and the data for drag_drop if |
99 ## there is an item all ready occupying the slot | 97 ## there is an item all ready occupying the slot |
100 if replace_item != None: | 98 replace_item = ( |
101 self.dragObject(obj) | 99 container.put_item(self.container, drag_item, drop_index) |
102 container.placeItem(drag_item, drop_index) | 100 ) |
103 | 101 |
104 drop_widget.item = drag_item | 102 drop_widget.item = drag_item |
105 self.updateImage(drop_widget) | 103 self.updateImage(drop_widget) |
106 #if there was no item the stop dragging and reset cursor | 104 #if there was no item the stop dragging and reset cursor |
107 if replace_item == None: | 105 if replace_item == None: |
108 data_drag.dragging = False | 106 data_drag.dragging = False |
109 #reset the mouse cursor to the normal cursor | 107 #reset the mouse cursor to the normal cursor |
110 self.controller.resetMouseCursor() | 108 self.controller.resetMouseCursor() |
111 except (Container.SlotBusy, Container.TooBig, Container.ItemSelf): | 109 except (container.BulkLimitError): |
112 #Do we want to notify the player why the item can't be dropped? | 110 #Do we want to notify the player why the item can't be dropped? |
113 pass | 111 pass |
114 | 112 |
115 def showContainer(self): | 113 def showContainer(self): |
116 """Show the container | 114 """Show the container |
118 # Prepare slots 1 through 9 | 116 # Prepare slots 1 through 9 |
119 empty_image = "gui/inv_images/inv_backpack.png" | 117 empty_image = "gui/inv_images/inv_backpack.png" |
120 slot_count = 9 | 118 slot_count = 9 |
121 for counter in range(1, slot_count+1): | 119 for counter in range(1, slot_count+1): |
122 slot_name = "Slot%i" % counter | 120 slot_name = "Slot%i" % counter |
121 index = counter - 1 | |
123 self.empty_images[slot_name] = empty_image | 122 self.empty_images[slot_name] = empty_image |
124 widget = self.gui.findChild(name=slot_name) | 123 widget = self.gui.findChild(name=slot_name) |
125 widget.item = self.container.items.get(counter-1) | 124 widget.item = container.get_item(self.container, index) |
126 widget.index = counter-1 | 125 widget.index = index |
127 self.updateImage(widget) | 126 self.updateImage(widget) |
128 self.events_to_map[slot_name] = cbwa(self.dragDrop, slot_name) | 127 self.events_to_map[slot_name] = cbwa(self.dragDrop, slot_name) |
129 self.events_to_map[slot_name + "/mouseReleased"] = \ | 128 self.events_to_map[slot_name + "/mouseReleased"] = \ |
130 self.showContextMenu | 129 self.showContextMenu |
131 | 130 |