Changeset 451


Ignore:
Timestamp:
12/17/09 09:19:30 (10 years ago)
Author:
b0rland_parpg
Message:

Ticket #241: patch by b0rland
*Removed reference from containers to GUI
*Fixed SingleItemContainer? with the new type of exception

Location:
trunk/game
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/gui/hud.py

    r446 r451  
    580580        self.addAction(text) 
    581581         
    582     def createBoxGUI(self, title, container, events = ()): 
     582    def createBoxGUI(self, title, container): 
    583583        """Creates a window to display the contents of a box 
    584584           @type title: string 
    585585           @param title: The title for the window 
    586586           @param items: The box to display 
    587            @param events: The events of the window 
    588587           @return: A new ContainerGui""" 
    589         box_container = ContainerGUI(self.engine, \ 
     588        events = {'takeAllButton':self.hideContainer, 
     589                  'closeButton':self.hideContainer} 
     590        #hide previous container if any, to avoid orphaned dialogs 
     591        self.hideContainer() 
     592 
     593        self.box_container = ContainerGUI(self.engine, \ 
    590594                                              unicode(title), container) 
    591         box_container.container_gui.mapEvents(events) 
     595        self.box_container.container_gui.mapEvents(events) 
     596        self.box_container.showContainer() 
    592597        return box_container 
    593598 
     
    597602        if self.box_container: 
    598603            self.box_container.hideContainer() 
     604            #TODO: Move the close() call into OpenBoxAction(). This can be done  
     605            # after createBoxGUI becomes a blocking call or it's otherwise possible 
     606            # to wait till the box GUI is closed. 
     607            self.box_container.container.close() 
    599608 
    600609    def createExamineBox(self, title, desc): 
  • trunk/game/scripts/objects/action.py

    r395 r451  
    6060        try: 
    6161            self.container.open() 
     62            self.engine.view.hud.createBoxGUI(self.container.name, \ 
     63                                              self.container) 
     64 
    6265        except ValueError: 
    6366            self.engine.view.hud.createExamineBox(self.container.name, \ 
  • trunk/game/scripts/objects/base.py

    r449 r451  
    205205        pass 
    206206 
    207     def __init__ (self, 
    208                   events = {}, 
    209                   engine = None, capacity = 0, **kwargs): 
     207    def __init__ (self, capacity = 0, **kwargs): 
    210208        self.is_container = True 
    211209        self.items = {} 
    212         self.events = events 
    213         self.containergui = None 
    214210        self.capacity=capacity 
    215  
    216         if not self.events: 
    217             self.events = {'takeAllButton':self.hideContainer, 
    218                       'closeButton':self.hideContainer} 
    219         if engine : 
    220             self.containergui = engine.view.hud.createBoxGUI(self.name, self, self.events) 
    221211         
    222212    def placeItem (self, item, index=None): 
     
    272262        """Bulk of the container contents""" 
    273263        return sum((item.bulk for item in self.items.values())) 
    274  
    275     def showContainer (self): 
    276         if self.containergui: 
    277             self.containergui.showContainer() 
    278  
    279     def hideContainer(self): 
    280         if self.containergui: 
    281             self.containergui.hideContainer() 
    282264 
    283265    def findItemByID(self, ID): 
  • trunk/game/scripts/objects/composed.py

    r449 r451  
    6161 
    6262    def __repr__(self): 
    63         return "[%s"%self.name +str(reduce((lambda a,b: a +', '+str(b)), self.items,""))+" ]" 
     63        return "[%s"%self.name +str(reduce((lambda a,b: a +', '+ \ 
     64                                    str(self.items[b])), self.items,""))+" ]" 
    6465 
    6566 
     
    7172    def placeItem(self,item, index=None): 
    7273        if len(self.items) > 0 : 
    73             raise ValueError ('%s is already busy' % self) 
     74            raise self.SlotBusy ('%s is already busy' % self) 
    7475        CarryableContainer.placeItem(self, item) 
    7576 
  • trunk/game/scripts/objects/containers.py

    r424 r451  
    3030    def __init__ (self, ID, name = 'Wooden Crate', \ 
    3131            text = 'A battered crate', gfx = 'crate', **kwargs): 
    32         events = {'takeAllButton':self.close, 
    33           'closeButton':self.close} 
    3432        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    35                 text = text, events = events, **kwargs) 
     33                text = text, **kwargs) 
    3634        self.placeItem(CarryableItem(ID=987,name="Dagger456")) 
    37  
    38     def close(self, *args, **kwargs): 
    39         self.hideContainer() 
    40         super (WoodenCrate,self).close() 
    41  
    42     def open(self, *args, **kwargs): 
    43         super (WoodenCrate,self).open(*args,**kwargs) 
    44         self.showContainer() 
    4535         
    4636class Footlocker(ImmovableContainer, fife.InstanceActionListener): 
    4737    def __init__ (self, ID, agent_layer=None, name = 'Footlocker', \ 
    4838               text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 
    49         events = {'takeAllButton':self.close, 
    50                   'closeButton':self.close} 
    5139        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    52                 text = text, events = events, **kwargs) 
     40                text = text, **kwargs) 
    5341        self.placeItem(CarryableItem(ID=987,name="Dagger456")) 
    5442 
     
    7260            self.agent.act('opened', self.agent.getFacingLocation(), True) 
    7361            self.state = _AGENT_STATE_OPENED 
    74             self.showContainer() 
    7562        if self.state == _AGENT_STATE_CLOSING: 
    7663            self.agent.act('closed', self.agent.getFacingLocation(), True) 
     
    8572    def close(self): 
    8673        super (Footlocker,self).close() 
    87         self.hideContainer() 
    8874        if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 
    8975            self.agent.act('close', self.agent.getLocation()) 
  • trunk/game/tests/test_single_item_container.py

    r424 r451  
    4141        container = SingleItemContainer() 
    4242        container.placeItem(self.item) 
    43         self.assertRaises(ValueError, container.placeItem, self.item2) 
     43        self.assertRaises(container.SlotBusy, container.placeItem, self.item2) 
    4444        container.takeItem(self.item) 
    4545        self.assertEqual(container.items, {}) 
Note: See TracChangeset for help on using the changeset viewer.