# HG changeset patch # User KarstenBock@gmx.net # Date 1317389513 -7200 # Node ID 100a39fa64a23e6c611eb8ccf0b84e39c884ae79 # Parent edadf3ff8a9af7610760583473079fd78c1acb6c Added ExamineContentsAction. Added "Examine Contents" to the context menu, when the object is a container and does not have a characterstats component. diff -r edadf3ff8a9a -r 100a39fa64a2 gamemodel.py --- a/gamemodel.py Fri Sep 30 15:08:53 2011 +0200 +++ b/gamemodel.py Fri Sep 30 15:31:53 2011 +0200 @@ -307,11 +307,12 @@ """Read the agents of the map @param map_name: Name of the map @type map_name: str """ - #Get the agents of the map + #Get the agents of the map map_agents_file = self.map_files[map_name].\ replace(".xml", "_agents.yaml") agents_data = vfs.VFS.open(map_agents_file) agents = yaml.load_all(agents_data) + self.agents[map_name] = {} for agent in agents: if not agent == None: self.addAgent(map_name, agent) diff -r edadf3ff8a9a -r 100a39fa64a2 gamescenecontroller.py --- a/gamescenecontroller.py Fri Sep 30 15:08:53 2011 +0200 +++ b/gamescenecontroller.py Fri Sep 30 15:31:53 2011 +0200 @@ -30,7 +30,8 @@ from parpg.gui import drag_drop_data as data_drag from objects.action import (ChangeMapAction, ExamineAction, TalkAction, OpenAction, CloseAction, UnlockAction, LockAction, - PickUpAction, DropItemAction, + PickUpAction, DropItemAction, + ExamineContentsAction, ) from parpg.world import World @@ -486,6 +487,15 @@ player.fifeagent.behaviour.approach, [obj_pos.x, obj_pos.y], LockAction(self, obj)]) + if obj.container: + if obj.characterstats: + #TODO: This is reserved for a possible "Steal" action. + pass + elif not obj.lockable or not obj.lockable.closed: + actions.append(["Examine contents", "Examine Contents", + player.fifeagent.behaviour.approach, + [obj_pos.x, obj_pos.y], + ExamineContentsAction(self, obj)]) if obj.containable: actions.append(["Pick Up", "Pick Up", player.fifeagent.behaviour.approach, diff -r edadf3ff8a9a -r 100a39fa64a2 gui/containergui.py --- a/gui/containergui.py Fri Sep 30 15:08:53 2011 +0200 +++ b/gui/containergui.py Fri Sep 30 15:31:53 2011 +0200 @@ -14,7 +14,7 @@ from parpg.gui.containergui_base import ContainerGUIBase from parpg.gui import drag_drop_data as data_drag -from parpg.objects.base import Container +from parpg.components import container class ContainerGUI(ContainerGUIBase): def __init__(self, controller, title, container): @@ -24,7 +24,7 @@ @param title: The title of the window @type title: string @param container: A container to represent - @type container: Container + @type container: parpg.components.Container @return: None""" super(ContainerGUI, self).__init__(controller, "gui/container_base.xml") self.gui.findChild(name="topWindow").title = title @@ -38,15 +38,15 @@ def updateImages(self): for index, button in enumerate(self.buttons): - widget = self.gui.findChild(name=button) - widget.item = self.container.getItemAt(index) + widget = self.gui.findChild(name=button) + widget.item = container.get_item(self.container, index) self.updateImage(widget) def updateImage(self, button): if (button.item == None): image = self.empty_images[button.name] else: - image = button.item.getInventoryThumbnail() + image = button.item.image button.up_image = image button.down_image = image button.hover_image = image @@ -73,8 +73,7 @@ data_drag.dragging = True data_drag.dragged_widget = drag_widget data_drag.source_container = self.container - - self.container.takeItem(drag_widget.item) + container.take_item(self.container, drag_widget.item.slot) # after dragging the 'item', set the widgets' images # so that it has it's default 'empty' images @@ -90,16 +89,15 @@ try: drop_widget = self.gui.findChild(name = obj) drop_index = drop_widget.index - replace_item = drop_widget.item + replace_item = None if data_drag.dragging: - container = self.container drag_item = data_drag.dragged_item #this will get the replacement item and the data for drag_drop if ## there is an item all ready occupying the slot - if replace_item != None: - self.dragObject(obj) - container.placeItem(drag_item, drop_index) + replace_item = ( + container.put_item(self.container, drag_item, drop_index) + ) drop_widget.item = drag_item self.updateImage(drop_widget) @@ -108,7 +106,7 @@ data_drag.dragging = False #reset the mouse cursor to the normal cursor self.controller.resetMouseCursor() - except (Container.SlotBusy, Container.TooBig, Container.ItemSelf): + except (container.BulkLimitError): #Do we want to notify the player why the item can't be dropped? pass @@ -120,10 +118,11 @@ slot_count = 9 for counter in range(1, slot_count+1): slot_name = "Slot%i" % counter + index = counter - 1 self.empty_images[slot_name] = empty_image widget = self.gui.findChild(name=slot_name) - widget.item = self.container.items.get(counter-1) - widget.index = counter-1 + widget.item = container.get_item(self.container, index) + widget.index = index self.updateImage(widget) self.events_to_map[slot_name] = cbwa(self.dragDrop, slot_name) self.events_to_map[slot_name + "/mouseReleased"] = \ diff -r edadf3ff8a9a -r 100a39fa64a2 gui/hud.py --- a/gui/hud.py Fri Sep 30 15:08:53 2011 +0200 +++ b/gui/hud.py Fri Sep 30 15:31:53 2011 +0200 @@ -478,11 +478,6 @@ @return: None""" if self.box_container: self.box_container.hideContainer() - #TODO: Move the close() call into OpenBoxAction(). This can be done - # after createBoxGUI becomes a blocking call or it's otherwise - # possible to wait till the box GUI is closed. - if self.box_container.container.trueAttr("openable"): - self.box_container.container.close() self.box_container = None def createExamineBox(self, title, desc): diff -r edadf3ff8a9a -r 100a39fa64a2 objects/action.py --- a/objects/action.py Fri Sep 30 15:08:53 2011 +0200 +++ b/objects/action.py Fri Sep 30 15:31:53 2011 +0200 @@ -199,9 +199,6 @@ @type examine_desc: string @param commands: Special commands that are executed @type commands: Dictionary - @type view: class derived from parpg.ViewBase - @param view: The view - """ super(ExamineAction, self).__init__(controller, commands) self.view = controller.view @@ -225,6 +222,7 @@ place += 26 #plus 1 character to offset the new line else: place += 1 self.view.displayObjectText(self.examine_id, unicode(action_text), time=3000) + Action.execute(self) class ExamineItemAction(Action): """Examine an item.""" @@ -251,6 +249,28 @@ action_text = unicode(self.examine_desc) self.view.hud.addAction(action_text) logger.debug(action_text) + Action.execute(self) + +class ExamineContentsAction(Action): + """Examine the contens of an container""" + def __init__(self, controller, container, commands=None): + """ + @param controller: A reference to the GameSceneController. + @type controller: parpg.GameSceneController + @param container: The container + @type container: parpg.entities.General + @param commands: Special commands that are executed + @type commands: Dictionary + """ + Action.__init__(self, controller, commands) + self.view = controller.view + self.container = container + + def execute(self): + """Examine the contents""" + self.view.hud.createBoxGUI(self.container.description.view_name, + self.container.container) + Action.execute(self) class ReadAction(Action): """Read a text.""" @@ -567,4 +587,6 @@ "Use":UseAction, "PickUp":PickUpAction, "DropFromInventory":DropItemFromContainerAction, - "BrewBeer":BrewBeerAction} + "BrewBeer":BrewBeerAction, + "ExamineContents": ExamineContentsAction, + }