-
Notifications
You must be signed in to change notification settings - Fork 4
Text
- color
- colorRed
- colorGreen
- colorPositive
- colorNegative
- colorDamage
- colorizeValue
- colorizeMult
- colorizeMultWithText
- colorizePct
File path: msu/utils/text.nut
Functions related to manipulating text e.g. in tooltips.
::MSU.Text.color( _color, _string );
// _color and _string are strings
_color
must either be a hexadecimal color string, e.g. #ffffff
, or one of the following keywords:
red green blue orange yellow black white brown gray silver purple maroon fushsia lime olive navy teal aqua
_string
is the string which should be colored.
This is equivalent to calling ::Const.UI.getColorized(_string, _color)
. As such, the element will be wrapped by the following BBCode expression: [color = _color]_string[/color]
. In JS, the expression will then be transformed into a span
element with the color
being passed as the CSS color
style value.
::MSU.Text.colorRed( _string );
// _string is a string
Returns _string
colored red (::MSU.Text.Color.Red
with hex #8f1e1e
).
::MSU.Text.colorGreen( _string );
// _string is a string
Returns _string
colored green (::MSU.Text.Color.Green
with hex #135213
).
::MSU.Text.colorPositive( _string );
// _string is a string
Returns _string
colored using the vanilla ::Const.UI.Color.PositiveValue
.
::MSU.Text.colorNegative( _string );
// _string is a string
Returns _string
colored using the vanilla ::Const.UI.Color.NegativeValue
.
::MSU.Text.colorNegative( _string );
// _string is a string
Returns _string
colored using the vanilla ::Const.UI.Color.DamageValue
.
::MSU.Text.colorizeValue( _value, _kwargs = null )
// _value is an integer or float
// _kwargs is an optional table to specify key/value parameters:
// - _kwargs.AddSign is a boolean that defaults to false
// - _kwargs.InvertColor is a boolean that defaults to false
// - _kwargs.CompareTo is an integer or float the defaults to 0
// - _kwargs.AddPercent is a boolean the defaults to false
Returns a string which is _value
colorized based on the given parameters in _kwargs
. If _value
is greater than or equal to _kwargs.CompareTo
then it is colored using colorPositive
otherwise using colorNegative
. These colors are reversed if _kwargs.InvertColor
is true. If _kwargs.AddSign
is true then the sign +
or -
is included with the value in the returned string. If _kwargs.AddPercent
is true then a percentage sign %
is included after the value in the returned string.
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]5[/color]"
// i.e. green colored 5
::MSU.Text.colorizeValue(5);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]+5[/color]"
// i.e. green colored +5
::MSU.Text.colorizeValue(5, {AddSign = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+5[/color]"
// i.e. red colored +5
::MSU.Text.colorizeValue(5, {AddSign = true, InvertColor = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+5%[/color]"
// i.e. red colored +5%
::MSU.Text.colorizeValue(5, {AddSign = true, InvertColor = true, AddPercent = true});
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]+5%[/color]"
// i.e. green colored +5%
// Note: would have been red colored if InvertColor was not true
::MSU.Text.colorizeValue(5, {AddSign = true, InvertColor = true, AddPercent = true, CompareTo = 10});
::MSU.Text.colorizeMult( _value, _kwargs = null )
// _value is an integer or float
// _kwargs is an optional table to specify key/value parameters:
// - _kwargs.AddSign is a boolean that defaults to false
// - _kwargs.InvertColor is a boolean that defaults to false
Returns a colorized string based on _value
and the parameters in _kwargs
using [colorizeValue](#colorizeValue]. For example a _value
of 0.75 will return "25%" colored using colorNegative
and 1.25 will return "25%" colored using colorPositive
. The use case for this function is to colorize multipliers which are meant to be applied to other values e.g. when you want to say that damage is reduced by 25% you pass a damage multiplier of 0.75 to this function and it will return a negative colored 25%.
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]25%[/color]"
// i.e. red colored 25%
::MSU.Text.colorizeMult(0.75);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]10%[/color]"
// i.e. green colored 10%
::MSU.Text.colorizeMult(1.1);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]+10%[/color]"
// i.e. green colored +10%
::MSU.Text.colorizeMult(1.1, {AddSign = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+10%[/color]"
// i.e. red colored +10%
::MSU.Text.colorizeMult(1.1, {AddSign = true, InvertColor = true});
::MSU.Text.colorizeMultWithText( _value, _kwargs = null )
// _value is an integer or float
// _kwargs is an optional table to specify key/value parameters:
// - _kwargs.AddSign is a boolean that defaults to false
// - _kwargs.InvertColor is a boolean that defaults to false
// - _kwargs.Text is a a len 2 array that defaults to ["more", "less"]
Returns a colorized string based on _value
and _kwargs
using colorizeMult but additionally adds the words more
or less
, or custom text specified in _kwargs.Text
, to the string based on whether it is a greater than 1.0 or less than 1.0 multiplier. See examples below.
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]25%[/color] less"
// i.e. red colored 25% followed by uncolored "less"
::MSU.Text.colorizeMultWithText(0.75);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]10%[/color] more"
// i.e. green colored 10% followed by uncolored "more"
::MSU.Text.colorizeMultWithText(1.1);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]+10%[/color] more"
// i.e. green colored +10% followed by uncolored "more"
::MSU.Text.colorizeMultWithText(1.1, {AddSign = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+10%[/color] more"
// i.e. red colored +10% followed by uncolored "more"
::MSU.Text.colorizeMultWithText(1.1, {AddSign = true, InvertColor = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+10%[/color] increased"
// i.e. red colored +10% followed by uncolored "increased"
::MSU.Text.colorizeMultWithText(1.1, {AddSign = true, InvertColor = true, Text = ["increased", "decreased"]});
::MSU.Text.colorizeMultWithText( _value, _kwargs = null )
// _value is an integer or float
// _kwargs is an optional table to specify key/value parameters:
// - _kwargs.AddSign is a boolean that defaults to false
// - _kwargs.InvertColor is a boolean that defaults to false
Returns a colorized string based on _value
and _kwargs
using colorizeValue but additionally adds a colorized %
sign after the value.F or example a _value
of 0.75 will return "75%" colored using colorPositive
and 1.25 will return 125% colored using colorPositive
. Similarly, 0.75 will return 75%
colored using colorPositive
and -1.25 will 25%
colored using colorNegative
. The use case for this function is to colorize fractions or percentages of other values e.g. when you want to say that Hitpoints are increased by 25% of Maximum Fatigue.
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]75%[/color]"
// i.e. red colored 75%
::MSU.Text.colorizePct(-0.75);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]75%[/color]"
// i.e. green colored 75%
::MSU.Text.colorizePct(0.75);
// returns "[color=" + ::Const.UI.Text.PositiveValue] + "]+75%[/color]"
// i.e. green colored 75%
::MSU.Text.colorizePct(0.75, {AddSign = true});
// returns "[color=" + ::Const.UI.Text.NegativeValue] + "]+75%[/color]"
// i.e. red colored 75%
::MSU.Text.colorizePct(0.75, {AddSign = true, InvertColor = true});
- NOTE: MSU guarantees backwards compatibility for documented features and code only. Undocumented features/code of MSU may be changed at any time without notice, so we advise against using/referencing such code in your projects.
- For bug reports or feature requests, please create issues.
- If you would like to join the team, write to us at msu.team@protonmail.com.