Drag[en]gine Script Module DragonScript  1.21
Dragengine.Scenery.ECBehaviorSkinSwitcher Class Reference

Behavior element behavior adding support to switch component skins. More...

Inheritance diagram for Dragengine.Scenery.ECBehaviorSkinSwitcher:
Dragengine.Scenery.DefaultECBehavior Dragengine.Scenery.ECBehavior Dragengine.Scenery.BehaviorCompatiblePersistency

Classes

class  BooleanListener
 Boolean listener switching skin. More...
 
class  Instance
 Behavior instance. More...
 

Public Member Functions

void dispose ()
 Dispose of behavior. More...
 
ECPInteger getActive ()
 Index of initially active skin property. More...
 
ECPBoolean getClamp ()
 Clamp property. More...
 
ECBehaviorComponent getComponent ()
 Component behavior. More...
 
ECPSkinList getSkins ()
 Skins property. More...
 
ECPString getTexture ()
 Texture property. More...
 
void listen (ECBehaviorAnimated behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorAnimated behavior. More...
 
void listen (ECBehaviorEvaluate behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorEvaluate behavior. More...
 
void listen (ECBehaviorTouching behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTouching behavior. More...
 
void listen (ECBehaviorTouchSensor behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTouchSensor behavior. More...
 
void listen (ECBehaviorTriggered behavior)
 Add listener factory with SwitchType.nextOnOff to ECBehaviorTriggered behavior. More...
 
void listen (ECBehaviorTriggered behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTriggered behavior. More...
 
void listen (ECBehaviorTwoStateAnimated behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTwoStateAnimated behavior. More...
 
ECBehaviorSkinSwitcher new (BehaviorElementClass eclass, ECBehaviorComponent component)
 Create behavior element class. More...
 
ECBehaviorSkinSwitcher new (BehaviorElementClass eclass, ECBehaviorComponent component, String id)
 
ECBehaviorSkinSwitcher new (BehaviorElementClass eclass, ECBehaviorComponent component, String id, String subId)
 
ECBehaviorSkinSwitcher new (BehaviorElementClass eclass, ECBehaviorComponent component, String id, String subId, String prefix)
 
- Public Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
void assignInstanceIndex (int instanceIndex)
 Assign instance index. More...
 
String getBehaviorID ()
 Unique identifier of behavior. More...
 
String getID ()
 Identifier. More...
 
int getInstanceIndex ()
 Instance index. More...
 
void loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance)
 Load instance data of another behavior. More...
 
bool supportsBehaviorID (String identifier)
 Behavior supports loading instance data of another behavior. More...
 
- Public Member Functions inherited from Dragengine.Scenery.ECBehavior
ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance. More...
 

Static Public Member Functions

static ECBehaviorSkinSwitcher getBehaviorIn (BehaviorElementClass eclass)
 Get behavior in element class or null if absent. More...
 

Public Attributes

ECPInteger pActive
 
ECPBoolean pClamp
 
ECBehaviorComponent pComponent
 
ECPSkinList pSkins
 
ECPString pTexture
 

Additional Inherited Members

- Protected Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
DefaultECBehavior new (BehaviorElementClass eclass)
 Create default composeable behavior with empty identifier. More...
 
DefaultECBehavior new (BehaviorElementClass eclass, String id)
 Create default composeable behavior. More...
 
void setBehaviorID (String identifier)
 Set behavior identifier. More...
 
void useClassNameAsBehaviorID ()
 Set behavior identifier to "<class-name>:<identifier>". More...
 
void useFullyQualifiedClassNameAsBehaviorID ()
 Set behavior identifier to "<fully-qualified-class-name>:<identifier>". More...
 

Detailed Description

Behavior element behavior adding support to switch component skins.

If a texture name is specified the matching component texture skin is switched instead of switching the skin for the entire component.

Switching skins can be used for example with monitors which show an offline skin and if used by the player switch to one or more online skins. Another use case is to create damageable objects which change skin the more they are damaged.

To use this behavior assign one or more skins to it. The first skin is used as the starting skin. By calling setActive() the active skin can be selected using the index of the skin in the list of defined skins. Furthermore activateNext() and activatePrevious() can be used to cycle through skins.

Optionally this behavior can be attached to various other behaviors supporting BooleanBehaviorListener. By doing so cycling though skins is attached to listener events called by other behaviors.

Skin switcher is set by default to wrap index around at the begin and end of the skin list. This allows to indefinitely cycle through all skins. By setting the "clamp" element class property to true the skins can cycle only once not wrapping around.

The example below switches the skin of a texture if the animated state become activate:

class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorTwoStateAnimated animated
public var ECBehaviorSkinSwitcher skinSwitcher
func new()
// Create component to switch texture
component = ECBehaviorComponent.new(this)
collider = ECBehaviorCollider.new(this, component)
// Create animated behavior which is used as trigger for the skin switcher
animated = ECBehaviorTwoStateAnimated.new(this, component)
// Create skin switcher for texture "display". If empty string is used instead
// the skin is switched for the entire component
skinSwitcher = ECBehaviorSkinSwitcher.new(this, component)
skinSwitcher.getTexture().setValue("display")
// Add skins to load. This example uses an "off" and an "on" skin. Other examples
// could use multiple skins to cycle through. For switching multiple skins more
// complex logic is usually required so it is better if you add your own listeners
// do the appropriate switching. The provided listeners are suited for the simple
// case of switching between two skins
skinSwitcher.getSkins().add("/content/skins/displayOff.deskin")
skinSwitcher.getSkins().add("/content/skins/displayOn.deskin")
// Add listener factory to ECBehaviorTwoStateAnimated. This makes the skin switch
// whenever the animated behavior enters or leaves "activated" state. This is only
// one possible way to connect to the ECBehaviorTwoStateAnimated but a common one.
skinSwitcher.listen(animated)
end
end
ECBehaviorSkinSwitcher new(BehaviorElementClass eclass, ECBehaviorComponent component)
Create behavior element class.
void listen(ECBehaviorTriggered behavior)
Add listener factory with SwitchType.nextOnOff to ECBehaviorTriggered behavior.
ECPString getTexture()
Texture property.
ECPSkinList getSkins()
Skins property.

Multiple instances of ECBehaviorSkinSwitcher can be used for example to switch skins of multiple component textures. To use multiple instances use code like this in your subclass constructor:

class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorTwoStateAnimated animated
public var ECBehaviorSkinSwitcher skinSwitcher
public var ECBehaviorSkinSwitcher subSkinSwitcher
func new()
component = ECBehaviorComponent.new(this)
collider = ECBehaviorCollider.new(this, component)
animated = ECBehaviorTwoStateAnimated.new(this, component)
skinSwitcher = ECBehaviorSkinSwitcher.new(this, component)
skinSwitcher.getTexture().setValue("display")
skinSwitcher.getSkins().add("/content/skins/displayOff.deskin")
skinSwitcher.getSkins().add("/content/skins/displayOn.deskin")
skinSwitcher.listen(animated)
// Add a second skin switcher affecting a different texture. This example attaches
// to the same animated behavior but you could instead attach to a different one.
subSkinSwitcher = ECBehaviorSkinSwitcher.new(this, component, "subSkinSwitcher)
subSkinSwitcher.getTexture().setValue("subDisplay")
subSkinSwitcher.getSkins().add("/content/skins/subDisplayOff.deskin")
subSkinSwitcher.getSkins().add("/content/skins/subDisplayOn.deskin")
subSkinSwitcher.listen(animated)
end
end

Element class properties have the prefix "skinSwitcher{(id)}.".

This behavior does support element class to be persistable (setPersistable). Saves active skin index.

Member Function Documentation

◆ dispose()

void Dragengine.Scenery.ECBehaviorSkinSwitcher.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

◆ getActive()

ECPInteger Dragengine.Scenery.ECBehaviorSkinSwitcher.getActive ( )

Index of initially active skin property.

◆ getBehaviorIn()

static ECBehaviorSkinSwitcher Dragengine.Scenery.ECBehaviorSkinSwitcher.getBehaviorIn ( BehaviorElementClass  eclass)
static

Get behavior in element class or null if absent.

Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorCollider.

◆ getClamp()

ECPBoolean Dragengine.Scenery.ECBehaviorSkinSwitcher.getClamp ( )

Clamp property.

If set to true prevents wrapping around when cycling skins.

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorSkinSwitcher.getComponent ( )

Component behavior.

◆ getSkins()

ECPSkinList Dragengine.Scenery.ECBehaviorSkinSwitcher.getSkins ( )

Skins property.

◆ getTexture()

ECPString Dragengine.Scenery.ECBehaviorSkinSwitcher.getTexture ( )

Texture property.

Name of texture to affect or empty string to affect entire component.

◆ listen() [1/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorAnimated  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorAnimated behavior.

◆ listen() [2/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorEvaluate  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorEvaluate behavior.

◆ listen() [3/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorTouching  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorTouching behavior.

◆ listen() [4/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorTouchSensor  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorTouchSensor behavior.

◆ listen() [5/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorTriggered  behavior)

Add listener factory with SwitchType.nextOnOff to ECBehaviorTriggered behavior.

◆ listen() [6/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorTriggered  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorTriggered behavior.

◆ listen() [7/7]

void Dragengine.Scenery.ECBehaviorSkinSwitcher.listen ( ECBehaviorTwoStateAnimated  behavior,
BooleanListener.SwitchType  switchType 
)

Add listener factory to ECBehaviorTwoStateAnimated behavior.

◆ new() [1/4]

ECBehaviorSkinSwitcher Dragengine.Scenery.ECBehaviorSkinSwitcher.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component 
)

Create behavior element class.

◆ new() [2/4]

ECBehaviorSkinSwitcher Dragengine.Scenery.ECBehaviorSkinSwitcher.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
String  id 
)

◆ new() [3/4]

ECBehaviorSkinSwitcher Dragengine.Scenery.ECBehaviorSkinSwitcher.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
String  id,
String  subId 
)

◆ new() [4/4]

ECBehaviorSkinSwitcher Dragengine.Scenery.ECBehaviorSkinSwitcher.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
String  id,
String  subId,
String  prefix 
)

Member Data Documentation

◆ pActive

ECPInteger Dragengine.Scenery.ECBehaviorSkinSwitcher.pActive

◆ pClamp

ECPBoolean Dragengine.Scenery.ECBehaviorSkinSwitcher.pClamp

◆ pComponent

ECBehaviorComponent Dragengine.Scenery.ECBehaviorSkinSwitcher.pComponent

◆ pSkins

ECPSkinList Dragengine.Scenery.ECBehaviorSkinSwitcher.pSkins

◆ pTexture

ECPString Dragengine.Scenery.ECBehaviorSkinSwitcher.pTexture

The documentation for this class was generated from the following file: