Package horizons :: Package component :: Module coloroverlaycomponent :: Class ColorOverlayComponent
[hide private]
[frames] | no frames]

Class ColorOverlayComponent

source code

Component --+
            |
           ColorOverlayComponent

Change parts of graphics dynamically on runtime ("color overlays" in FIFE terminology).

Supports multiple overlay sets for the same instance, and also
supports changing more than one color in the same overlay set.

While technically possible, it is not recommended to use the former:
You will need to make sure animation overlays exist for that z_order,
else a color overlay cannot be visible.

Because there usually is no way to guarantee this, it is **very much**
recommended to use one overlay on z_order `0` featuring multiple areas
with different colors instead, and to then replace those colors one by one.
We can guarantee that z_order of 0 works because `convertToOverlays` is
called when adding new color overlays, which converts the base image of
the current action to an animation overlay at precisely depth 0.

Directives to change colors look like this (for every action):
- [z_order, overlay action name, color to be replaced, target color to draw]

When in doubt, use 0 as z_order.
The overlay action name is the folder located next to other actions (e.g. idle).
Color to be replaced: List with three (rgb) or four (rgba) int elements.
        In particular, [80, 0, 0] and [80, 0, 0, 128] are different colors!
Target color to draw: As above, or string interpreted as attribute of instance.
        To access player colors, you can usually employ "owner.color".

All in all, a multi-color replacement could look like this example:

        idle:
        # color_idle: action set with three differently colored areas
                # color red area in player color (alpha is set to 128 here)
                - [0, color_idle, [255, 0, 0], [owner.color, 128]]
                # also color green area *in the same images* in blue
                - [0, color_idle, [0, 255, 0], [0, 0, 255, 128]]
                # hide third (blue) area by setting alpha value to 0
                - [0, color_idle, [0, 0, 255], [0, 0, 0, 0]]

# multiple single-overlay example (usually not what you want):
#       idle:
#               # color magenta area in player color (needs animation overlay at order 1)
#               - [1, color1_idle, [255, 0, 255], [owner.color, 64]]
#               # also color some other teal area in blue (needs animation overlay at order 2)
#               - [2, color2_idle, [0, 255, 255], [0, 0, 255, 128]]

Instance Methods [hide private]
 
__init__(self, overlays=None)
Used for initialization code that does not require any other components.
source code
 
action_set(self)
E.g.
source code
 
fife_instance(self) source code
 
identifier(self)
E.g.
source code
 
initialize(self)
This is called by the ComponentHolder after it set the instance.
source code
 
update_overlay(self, message) source code
 
add_overlay(self, overlay_name, z_order)
Creates color overlay recoloring the area defined in *overlay_set*
source code
 
change_color(self, z_order, from_color, to_color)
Changes color of *from_color*ed area to *to_color*.
source code
 
remove_overlay(self)
Removes color overlay recoloring the *color*-colored area from fife instance.
source code
 
load(self, db, worldid)
This does on load what __init() and initalize() together do on constructions at runtime.
source code
 
remove(self)
Removes all color overlays from the fife instance.
source code
    Inherited from Component
 
__gt__(self, other) source code
 
__lt__(self, other) source code
 
save(self, db)
Will do nothing, but will be always called in componentholder code, even if not implemented.
source code
Class Methods [hide private]
    Inherited from Component
 
get_instance(cls, arguments=None)
This function is used to instantiate classes from yaml data.
source code
Class Variables [hide private]
  NAME = "coloroverlay"
hash(x)
  log = logging.getLogger('component.overlays')
    Inherited from Component
  DEPENDENCIES = []
Properties [hide private]
    Inherited from Component
  session
Method Details [hide private]

__init__(self, overlays=None)
(Constructor)

source code 

Used for initialization code that does not require any other components. This is always called first, on construction and on load.

Overrides: Component.__init__
(inherited documentation)

action_set(self)

source code 

E.g. 'as_lumberjack_barrack0'

Decorators:
  • @property

fife_instance(self)

source code 
Decorators:
  • @property

identifier(self)

source code 

E.g. 'idle_as_lumberjack_barrack0'

Decorators:
  • @property

initialize(self)

source code 

This is called by the ComponentHolder after it set the instance. Use this to initialize any needed infrastructure. When this is called, it is guaranteed that all other components this one has a dependency on have been added, but initalize may not have been called on them, only __init__. It is only called after construction, not on load().

Overrides: Component.initialize
(inherited documentation)

add_overlay(self, overlay_name, z_order)

source code 

Creates color overlay recoloring the area defined in *overlay_set*

and adds it to fife instance. Note that a color overlay on *z_order* can only be visible if an animation overlay with that specific order exists as well. For order 0, `convertToOverlays()` makes sure they do.

change_color(self, z_order, from_color, to_color)

source code 

Changes color of *from_color*ed area to *to_color*.

color parameters: fife.Color objects

load(self, db, worldid)

source code 

This does on load what __init() and initalize() together do on constructions at runtime. Has to set up everything that is not setup in __init__(). Note that on loading __init__() is called with the data needed by the component through get_instance(), but initialize() is not, so any work needed for loading as well should be moved to a separate method and called here.

Overrides: Component.load
(inherited documentation)

remove(self)

source code 

Removes all color overlays from the fife instance.

Overrides: Component.remove