Changeset 395


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
Files:
6 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/maps/map.xml

    r394 r395  
    1414        <import file="../objects/buildings/container_house/container_house01.xml" /> 
    1515        <import file="../objects/buildings/container_house/container_house02.xml" /> 
     16+       <import file="../objects/objects/lock_box_metal/lock_box_metal.xml" /> 
    1617        <import file="../objects/ground/block/block.xml" /> 
    1718        <import file="../objects/objects/burning_barrel/burning_barrel.xml" /> 
     
    37273728                        <i o="block" r="0" x="5.0" y="-20.0" z="0.0" /> 
    37283729                        <i o="block" r="0" x="6.0" y="-20.0" z="0.0" /> 
     3730+                       <i id="lock_box01" is_open="False" locked="False" name="Footlocker" o="lock_box_metal01" object_type="Footlocker" r="225" target_map="None" target_map_name="None" target_x="None" target_y="None" text="A footlocker. There doesn&apos;t seem to be anything remarkable about it" x="-9.0" y="0.0" z="0.0" /> 
    37293731                        </instances> 
    37303732        </layer> 
  • trunk/game/objects/objects/lock_box_metal/close/animation.xml

    r363 r395  
    1 <animation delay="100" namespace="PAPRG" id="lock_box_metal:walk:225" x_offset="0" y_offset="-40"> 
    2         <frame source="lock_5.png" /> 
    3         <frame source="lock_4.png" /> 
    4         <frame source="lock_3.png" /> 
    5         <frame source="lock_2.png" /> 
    6         <frame source="lock_1.png" /> 
     1<animation delay="100" namespace="PAPRG" id="lock_box_metal:walk:225" x_offset="-3" y_offset="-15"> 
     2        <frame source="lock_05.png" /> 
     3        <frame source="lock_04.png" /> 
     4        <frame source="lock_03.png" /> 
     5        <frame source="lock_02.png" /> 
     6        <frame source="lock_01.png" /> 
    77</animation> 
  • trunk/game/objects/objects/lock_box_metal/lock_box_metal.xml

    r363 r395  
    11<?fife type="object"?> 
    22<object id="lock_box_metal01" namespace="PARPG" blocking="1" static="0"> 
     3        <action id="closed"> 
     4                <animation source="closed/animation.xml"/> 
     5        </action> 
    36        <action id="open"> 
    4                 <animation source="open/animation.xml" /> 
     7                <animation source="open/animation.xml"/> 
     8        </action> 
     9        <action id="opened"> 
     10                <animation source="opened/animation.xml"/> 
    511        </action> 
    612        <action id="close"> 
    7                 <animation source="close/animation.xml" /> 
     13                <animation source="close/animation.xml"/> 
    814        </action> 
    915</object> 
  • trunk/game/objects/objects/lock_box_metal/open/animation.xml

    r363 r395  
    1 <animation delay="100" namespace="PAPRG" id="lock_box_metal:walk:225" x_offset="0" y_offset="-40"> 
    2         <frame source="lock_1.png" /> 
    3         <frame source="lock_2.png" /> 
    4         <frame source="lock_3.png" /> 
    5         <frame source="lock_4.png" /> 
    6         <frame source="lock_5.png" /> 
     1<animation delay="100" namespace="PAPRG" id="lock_box_metal:open:225" x_offset="-3" y_offset="-15"> 
     2        <frame source="lock_01.png" /> 
     3        <frame source="lock_02.png" /> 
     4        <frame source="lock_03.png" /> 
     5        <frame source="lock_04.png" /> 
     6        <frame source="lock_05.png" /> 
    77</animation> 
  • trunk/game/scripts/engine.py

    r360 r395  
    243243                                    self.game_state.PC.approach, \ 
    244244                                    [obj.X, obj.Y], \ 
    245                                     OpenBoxAction(self, "Box")]) 
     245                                    OpenBoxAction(self, obj)]) 
     246                    actions.append(["Unlock", "Unlock",  
     247                                    self.game_state.PC.approach, \ 
     248                                    [obj.X, obj.Y], \ 
     249                                    UnlockBoxAction(obj)]) 
     250                    actions.append(["Lock", "Lock",  
     251                                    self.game_state.PC.approach, \ 
     252                                    [obj.X, obj.Y], \ 
     253                                    LockBoxAction(obj)]) 
    246254                # can you pick it up? 
    247255                if obj.trueAttr("carryable"): 
  • trunk/game/scripts/gui/hud.py

    r372 r395  
    572572        self.addAction(text) 
    573573         
    574     def createBoxGUI(self, title): 
     574    def createBoxGUI(self, title, items = [], events = ()): 
    575575        """Creates a window to display the contents of a box 
    576576           @type title: string 
    577577           @param title: The title for the window 
    578            @return: None""" 
    579         if self.box_container: 
    580             # if it has already been created, just show it 
    581             self.box_container.showContainer() 
    582         else: 
    583             # otherwise create it then show it 
    584             data = ["dagger01", "empty", "empty", "empty", "empty", 
    585                     "empty", "empty", "empty", "empty"] 
    586             self.box_container = ContainerGUI(self.engine, \ 
    587                                               unicode(title), data) 
    588             def closeAndDelete(): 
    589                 self.hideContainer() 
    590             events = {'takeAllButton':closeAndDelete, 
    591                       'closeButton':closeAndDelete} 
    592             self.box_container.container_gui.mapEvents(events) 
    593             self.box_container.showContainer() 
     578           @param items: The contents of the box 
     579           @param events: The events of the window 
     580           @return: A new ContainerGui""" 
     581        box_container = ContainerGUI(self.engine, \ 
     582                                              unicode(title), items) 
     583        box_container.container_gui.mapEvents(events) 
     584        return box_container 
    594585 
    595586    def hideContainer(self): 
  • 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        
  • trunk/game/utilities/layer_fill_utility.py

    r392 r395  
    11#!/usr/bin/env python 
     2 
     3#   This program is free software: you can redistribute it and/or modify 
     4#   it under the terms of the GNU General Public License as published by 
     5#   the Free Software Foundation, either version 3 of the License, or 
     6#   (at your option) any later version. 
     7 
     8#   This program is distributed in the hope that it will be useful, 
     9#   but WITHOUT ANY WARRANTY; without even the implied warranty of 
     10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     11#   GNU General Public License for more details. 
     12 
     13#   You should have received a copy of the GNU General Public License 
     14#   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     15 
    216import sys 
    317if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.