Ignore:
Timestamp:
11/24/09 19:27:58 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #137 and #138. Patch by Beliar (confirmed by eliedebrauwer). Fixes footlocker animation, added support for opening/closing footlocker animations, added footlocker onto the map, isolates contents of containers. Added copyright notice to layer_fill_utility.py. fixes[s:trac, t:137] fixes[s:trac, t:138]

Location:
trunk/game/scripts/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/objects/action.py

    r360 r395  
    4848class OpenBoxAction(Action): 
    4949    """Open a box. Needs to be more generic, but will do for now.""" 
    50     def __init__(self, engine, box_title): 
     50    def __init__(self, engine, container): 
    5151        """@type engine: Engine reference 
    5252           @param engine: A reference to the engine. 
    53            @type box_title: String 
    54            @param box_title: Box title. 
     53           @param container: A reference to the container 
    5554           """ 
    5655        self.engine = engine 
    57         self.box_title = box_title 
     56        self.container = container 
     57         
     58    def execute(self): 
     59        """Open the box.""" 
     60        try: 
     61            self.container.open() 
     62        except ValueError: 
     63            self.engine.view.hud.createExamineBox(self.container.name, \ 
     64                                              "The container is locked") 
     65         
     66class UnlockBoxAction(Action): 
     67    """Unlocks a box. Needs to be more generic, but will do for now.""" 
     68    def __init__(self,  container): 
     69        """@param container: A reference to the container 
     70           """ 
     71        self.container = container 
    5872     
    5973    def execute(self): 
    6074        """Open the box.""" 
    61         self.engine.view.hud.createBoxGUI(self.box_title) 
     75        self.container.unlock() 
    6276         
     77class LockBoxAction(Action): 
     78    """Locks a box. Needs to be more generic, but will do for now.""" 
     79    def __init__(self, container): 
     80        """@param container: A reference to the container 
     81           """ 
     82        self.container = container 
     83    def execute(self): 
     84        """Lock the box.""" 
     85        self.container.lock() 
     86 
     87 
    6388class ExamineBoxAction(Action): 
    6489    """Examine a box. Needs to be more generic, but will do for now.""" 
  • trunk/game/scripts/objects/base.py

    r346 r395  
    5454from settings import Setting 
    5555from random import randrange 
     56from scripts.gui.popups import ExaminePopup, ContainerGUI 
    5657 
    5758class GameObject (object): 
     
    140141class Lockable (Openable): 
    141142    """Allows objects to be locked""" 
    142     def __init__ (self, locked = False, is_open=True, **kwargs): 
     143    def __init__ (self, locked = False, is_open = True, **kwargs): 
    143144        """Init operation for lockable objects 
    144145        @type locked: Boolean 
     
    148149        """ 
    149150        self.is_lockable = True 
     151        if locked == True: #HACK: For some reason locked appears to NOT be a bool. Needs investigation 
     152            locked = True 
     153        else: locked = False 
    150154        self.locked = locked 
    151155        if locked : 
     
    178182class Container (object): 
    179183    """Gives objects the capability to hold other objects""" 
    180     def __init__ (self, **kwargs): 
     184    def __init__ (self, 
     185                  events = {}, 
     186                  items = ["empty", "empty", "empty", "empty", "empty","empty", "empty", "empty", "empty"], 
     187                  engine = None, **kwargs): 
    181188        self.is_container = True 
    182         self.items = [] 
     189        self.items = items 
     190        self.events = events 
     191        if not self.events: 
     192            self.events = {'takeAllButton':self.hideContainer, 
     193                      'closeButton':self.hideContainer} 
     194        self.containergui = engine.view.hud.createBoxGUI(self.name, self.items, self.events) 
    183195         
    184196    def placeItem (self, item): 
     
    212224        return len(self.items) 
    213225 
     226    def showContainer (self):         
     227        self.containergui.showContainer() 
     228 
     229    def hideContainer(self): 
     230        self.containergui.hideContainer() 
    214231         
    215232class Living (object): 
  • trunk/game/scripts/objects/containers.py

    r262 r395  
    1919barrels, chests, etc.""" 
    2020 
    21 __all__ = ["WoodenCrate",] 
     21__all__ = ["WoodenCrate", "Footlocker"] 
     22 
     23_AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, _AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5) 
    2224 
    2325from composed import ImmovableContainer 
     26import fife 
    2427 
    2528class WoodenCrate (ImmovableContainer): 
    2629    def __init__ (self, ID, name = 'Wooden Crate', \ 
    2730            text = 'A battered crate', gfx = 'crate', **kwargs): 
     31        events = {'takeAllButton':self.close, 
     32          'closeButton':self.close} 
    2833        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    29                 text = text, **kwargs) 
     34                text = text, events = events, items = ["dagger01", "empty", "empty", "empty", "empty", 
     35                    "empty", "empty", "empty", "empty"], **kwargs) 
     36 
     37    def close(self, *args, **kwargs): 
     38        self.hideContainer() 
     39        super (WoodenCrate,self).close() 
     40 
     41    def open(self, *args, **kwargs): 
     42        super (WoodenCrate,self).open(*args,**kwargs) 
     43        self.showContainer() 
     44         
     45class Footlocker(ImmovableContainer, fife.InstanceActionListener): 
     46    def __init__ (self, ID, agent_layer=None, name = 'Footlocker', \ 
     47               text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 
     48        events = {'takeAllButton':self.close, 
     49                  'closeButton':self.close} 
     50        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
     51                text = text, events = events, items = ["dagger01", "empty", "empty", "empty", "empty", 
     52                                                       "empty", "empty", "empty", "empty"], **kwargs) 
     53        fife.InstanceActionListener.__init__(self) 
     54        self.layer = agent_layer 
     55        self.agent = self.layer.getInstance(self.ID) 
     56        self.agent.addActionListener(self) 
     57        self.state = _AGENT_STATE_CLOSED 
     58        self.agent.act('closed', self.agent.getLocation()) 
     59         
     60    def onInstanceActionFinished(self, instance, action): 
     61        """What the NPC does when it has finished an action. 
     62           Called by the engine and required for InstanceActionListeners. 
     63           @type instance: fife.Instance 
     64           @param instance: self.agent (the NPC listener is listening for this 
     65            instance) 
     66           @type action: ??? 
     67           @param action: ??? 
     68           @return: None""" 
     69        if self.state == _AGENT_STATE_OPENING: 
     70            self.agent.act('opened', self.agent.getFacingLocation(), True) 
     71            self.state = _AGENT_STATE_OPENED 
     72            self.showContainer() 
     73        if self.state == _AGENT_STATE_CLOSING: 
     74            self.agent.act('closed', self.agent.getFacingLocation(), True) 
     75            self.state = _AGENT_STATE_CLOSED 
     76         
     77    def open (self): 
     78        super (Footlocker,self).open() 
     79        if self.state != _AGENT_STATE_OPENED and self.state != _AGENT_STATE_OPENING: 
     80            self.agent.act('open', self.agent.getLocation()) 
     81            self.state = _AGENT_STATE_OPENING 
     82 
     83    def close(self): 
     84        super (Footlocker,self).close() 
     85        self.hideContainer() 
     86        if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 
     87            self.agent.act('close', self.agent.getLocation()) 
     88            self.state = _AGENT_STATE_CLOSING        
Note: See TracChangeset for help on using the changeset viewer.