Drag[en]gine Script Module DragonScript 1.35
Loading...
Searching...
No Matches
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  Factory
 Behavior factory. More...
class  Instance
 Behavior instance. More...

Public Member Functions

void dispose ()
 Dispose of behavior.
ECPInteger getActive ()
 Index of initially active skin property.
ECComposeBTSM getBTSMs ()
 Compose behavior trees and state machines.
ECPBoolean getClamp ()
 Clamp property.
ECBehaviorComponent getComponent ()
 Component behavior.
String getPrefix ()
 Prefix.
ECPSkinList getSkins ()
 Skins property.
ECPString getTexture ()
 Texture property.
void listen (ECBehaviorAnimated behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorAnimated behavior.
void listen (ECBehaviorEvaluate behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorEvaluate behavior.
void listen (ECBehaviorTouching behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTouching behavior.
void listen (ECBehaviorTouchSensor behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTouchSensor behavior.
void listen (ECBehaviorTriggered behavior)
 Add listener factory with SwitchType.nextOnOff to ECBehaviorTriggered behavior.
void listen (ECBehaviorTriggered behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTriggered behavior.
void listen (ECBehaviorTwoStateAnimated behavior, BooleanListener.SwitchType switchType)
 Add listener factory to ECBehaviorTwoStateAnimated behavior.
ECBehaviorSkinSwitcher new (BehaviorElementClass eclass, ECBehaviorComponent component)
 Create behavior element class.
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.
String getBehaviorID ()
 Unique identifier of behavior.
String getID ()
 Identifier.
int getInstanceIndex ()
 Instance index.
void loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance)
 Load instance data of another behavior.
bool supportsBehaviorID (String identifier)
 Behavior supports loading instance data of another behavior.
Public Member Functions inherited from Dragengine.Scenery.ECBehavior
ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance.

Static Public Member Functions

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

Public Attributes

ECPInteger pActive
ECComposeBTSM pBTSMs
ECPBoolean pClamp
ECBehaviorComponent pComponent
String pPrefix
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.
DefaultECBehavior new (BehaviorElementClass eclass, String id)
 Create default composeable behavior.
void setBehaviorID (String identifier)
 Set behavior identifier.
void useClassNameAsBehaviorID ()
 Set behavior identifier to "<class-name>:<identifier>".
void useFullyQualifiedClassNameAsBehaviorID ()
 Set behavior identifier to "<fully-qualified-class-name>:<identifier>".

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
Behavior element element class.
Definition BehaviorElementClass.ds:54
Behavior element behavior adding collider support.
Definition ECBehaviorCollider.ds:147
Behavior element behavior adding component support.
Definition ECBehaviorComponent.ds:103
Behavior element behavior adding support to switch component skins.
Definition ECBehaviorSkinSwitcher.ds:138
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.
Behavior element behavior adding two state animation support.
Definition ECBehaviorTwoStateAnimated.ds:109

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.

See also
https://developer.dragondreams.ch/wiki/doku.php/dragengine:modules:dragonscript:behavior_skinswitcher

Member Function Documentation

◆ dispose()

void Dragengine.Scenery.ECBehaviorSkinSwitcher.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

References dispose(), getComponent(), pBTSMs, and pComponent.

Referenced by dispose(), getBehaviorIn(), and getPrefix().

◆ getActive()

ECPInteger Dragengine.Scenery.ECBehaviorSkinSwitcher.getActive ( )

Index of initially active skin property.

References pBTSMs.

Referenced by getBehaviorIn(), and Dragengine.Scenery.ECBehaviorSkinSwitcher.BooleanListener.new().

◆ getBehaviorIn()

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.

References Dragengine.Scenery.ECBehavior.createInstance(), dispose(), getActive(), getBehaviorIn(), getBTSMs(), getClamp(), getComponent(), getPrefix(), getSkins(), getTexture(), listen(), new(), pActive, pBTSMs, pClamp, pComponent, pPrefix, pSkins, and pTexture.

Referenced by getBehaviorIn().

◆ getBTSMs()

ECComposeBTSM Dragengine.Scenery.ECBehaviorSkinSwitcher.getBTSMs ( )

Compose behavior trees and state machines.

Version
1.26

Referenced by getBehaviorIn(), and getClamp().

◆ getClamp()

ECPBoolean Dragengine.Scenery.ECBehaviorSkinSwitcher.getClamp ( )

Clamp property.

If set to true prevents wrapping around when cycling skins.

References getBTSMs(), getPrefix(), new(), and pBTSMs.

Referenced by getBehaviorIn(), and getSkins().

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorSkinSwitcher.getComponent ( )

Component behavior.

References getSkins(), and new().

Referenced by dispose(), and getBehaviorIn().

◆ getPrefix()

String Dragengine.Scenery.ECBehaviorSkinSwitcher.getPrefix ( )

Prefix.

Version
1.26

References dispose().

Referenced by getBehaviorIn(), and getClamp().

◆ getSkins()

ECPSkinList Dragengine.Scenery.ECBehaviorSkinSwitcher.getSkins ( )

Skins property.

References getClamp(), pActive, and pClamp.

Referenced by getBehaviorIn(), getComponent(), and getTexture().

◆ getTexture()

ECPString Dragengine.Scenery.ECBehaviorSkinSwitcher.getTexture ( )

Texture property.

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

References getSkins(), getTexture(), and pTexture.

Referenced by getBehaviorIn(), and getTexture().

◆ listen() [1/7]

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

Add listener factory to ECBehaviorAnimated behavior.

References pActive, and pClamp.

◆ listen() [2/7]

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

Add listener factory to ECBehaviorEvaluate behavior.

References pSkins.

◆ 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.

Referenced by getBehaviorIn().

◆ 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.

Referenced by getBehaviorIn(), getClamp(), getComponent(), new(), and new().

◆ 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 )

References new().

◆ new() [4/4]

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

References new(), pActive, pClamp, and pSkins.

Member Data Documentation

◆ pActive

◆ pBTSMs

◆ pClamp

ECPBoolean Dragengine.Scenery.ECBehaviorSkinSwitcher.pClamp

◆ pComponent

ECBehaviorComponent Dragengine.Scenery.ECBehaviorSkinSwitcher.pComponent

Referenced by dispose(), and getBehaviorIn().

◆ pPrefix

String Dragengine.Scenery.ECBehaviorSkinSwitcher.pPrefix

Referenced by getBehaviorIn().

◆ pSkins

ECPSkinList Dragengine.Scenery.ECBehaviorSkinSwitcher.pSkins

Referenced by getBehaviorIn(), listen(), and new().

◆ pTexture

ECPString Dragengine.Scenery.ECBehaviorSkinSwitcher.pTexture

Referenced by getBehaviorIn(), and getTexture().


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