Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorCustomColor
Behavior in action
Behavior element behavior adding custom color support.
Custom colors are typically used to allow players to customize the look of their player actor by altering the color of individual body parts. This behavior allows to define custom color slots the player or artist can manipulate. This behavior does not define how custom colors are applied. This is left for other behaviors or game scripts to do.
Custom colors compose of a display name and the currently assigned color. This color can be null to use the assigned default color. An optional list of colors can be used to restrict the colors the player can select. If the list is empty the player can choose the color unrestricted. In addition a display description can be added in case the game developer would like to communicate additional information about the custom color.
This behavior can be used multiple times on an element to add multiple custom colors to mainpulate. Use the behavior identifier to tell them apart.
Element class properties have the prefix customColor. or customColor({id}). if id is not empty.
Sets the name to show for the custom color in UI.
<string name='customColor(body).name'>Body Color</string>
Sets the optional description to show for the custom color in UI. This can be used to add additional information beyond the name of the color. Often this is though not used.
<string name='customColor(body).description'>Color of scales along the back of the body</string>
Optional list of allowed colors. If this list is not empty the player is only allowed to select one of the colors from this list. If the list is empty all colors are allowed. Typically this means the UI shows a list or combo box instead of a set of sliders for each color component. In XML Element Class files this is defined as a list-tag containing color-tag entries.
<list name='customColor(body).allowedColors'> <color r='1' g='0' b='0'/> <color r='0' g='1' b='0'/> <color r='0' g='0' b='1'/> </list>
<string name='customColor(body).allowedColors'>"1 0 0" "0 1 0" "0 0 1"</string>
In stub properties the coding is of the form “color1 color2 …” where color is encoded as “r g b”. Since both uses space to separate tokens colors have to be wrapped in double quotes. This looks like the second example above. For easier reading and editing the first version (list version) is recommended to be used in XML Element Class files. The second form can be used to directly copy/paste stub property strings between XML/stub without needing to change the formatting.
Sets the default color for the custom color. If the user selects no color (null value) then the default color is used. This can also be used to reset the color to the default color.
<color name='customColor(body).defaultColor' r='0' g='0.5' b='0'/>
Sets the initial selected color. This can be null to used the default color.
<color name='customColor(body).color' r='0' g='0.5' b='0'/>
<null name='customColor(body).color'/><!-- force no color set -->
Since this behavior provides no support to apply the chosen color listening is used. Behaviors knowing how to apply the color add a listener and are notified if the color changes. These events can be received:
Selected color changed. Use behavior to get the newly set color.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace customColor
with customColor(id)
.
Set one or more force field parameters.
Parameter | Value | Description |
---|---|---|
color | default , string | Set color. If value is default uses default color. Otherwise string value is required to have the form red green blue where each color component is in the range from 0 to 1 |
This is an example of using this action:
<action name='customColor.set'> <parameter name='color'>1 0.5 0.2</parameter> </action>
Check one or more force field parameters. Action succeeds if all parameter value matches their respective force field parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a force field parameter matches (or not).
Parameter | Value | Description |
---|---|---|
color.red.less | float | Red color component is less than float value |
color.red.greater | float | Red color component is greater than float value |
color.green.less | float | Green color component is less than float value |
color.green.greater | float | Green color component is greater than float value |
color.blue.less | float | Blue color component is less than float value |
color.blue.greater | float | Blue color component is greater than float value |
wait | If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled |
This is an example of using this action:
<sequence> <action name='customColor.check'> <parameter name='color.red.less'>0.5</parameter> <parameter name='color.green.less'>0.5</parameter> <parameter name='color.blue.less'>0.5</parameter> </action> <!-- actions here run only if all color components are less than 0.5 --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace customColor
with customColor(id)
.
Check one or more force field parameters. Conditions returns true if all parameter value match their respective force field parameter. This condition is typically used to run an action or sequence of actions as long as force field conditions are true.
Parameter | Value | Description |
---|---|---|
customColor.color.red.less | float | Red color component is less than float value |
customColor.color.red.greater | float | Red color component is greater than float value |
customColor.color.green.less | float | Green color component is less than float value |
customColor.color.green.greater | float | Green color component is greater than float value |
customColor.color.blue.less | float | Blue color component is less than float value |
customColor.color.blue.greater | float | Blue color component is greater than float value |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='customColor.color.red.less'>0.5</parameter> <parameter name='customColor.color.green.less'>0.5</parameter> <parameter name='customColor.color.blue.less'>0.5</parameter> <condition>customColor.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events. If behavior has non-empty identifier replace customColor
with customColor(id)
.
Color changed.
This behavior requires no other behaviors.
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable). Saves selected color.
Since DragonScript Module Version 1.5
This example defines an element which contains two custom colors the player can choose at will. You can now define the parameters to use for both custom colors using for example the properties “customColor(color1).color” for the first custom color and “customColor(color2).color” for the second custom color.
class MyElement extends BehaviorElementClass public func new() ECBehaviorCustomColor.new(this, "color1", "Color 1", Color.blue) ECBehaviorCustomColor.new(this, "color2", "Color 2", Color.red) end end
Using element class supporting adding behaviors the behavior can be added like this:
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorCustomColor'> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.name'>Color 1</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorCustomColor' id='second'/> </elementClass>