UI Toolbox logoUI Toolbox
Support

StatDelta and ItemCompare

A StatDelta shows the change of a stat, as in the item compare of a game. It shows one arrow for a small change, and two or three arrows stacked on top of each other for a medium or large change. Green is better, red is worse, and gray is no change.

Five stats with green gains and red lossesFive stats with green gains and red losses

A change can also show as a percent of the start value ("+12.5%"), and one slanted arrow can take the place of the stack, for the tiles of a dashboard such as the StatTile.

An ItemCompare is a table that compares the stats of the equipped item with the stats of a new item. Each row has a StatDelta.

How to add them:

<tb:StatDelta from="24" to="31" />
<tb:StatDelta from="12" to="6" higher-is-better="false" display="Both" />
<tb:StatDelta from="2600" to="2925" display="ArrowsAndPercent"
    arrow-style="Slanted" format-string="0.#" />
<tb:ItemCompare
    name="compare"
    show-total="true"
    total-title="Sum of stats" />
var compare = root.Q<ItemCompare>("compare");
var iron = new[]
{
    new ItemStat("Damage", 24),
    new ItemStat("Weight", 6, higherIsBetter: false)
};
var rune =
    new[] { new ItemStat("Damage", 52),
        new ItemStat("Weight", 5, higherIsBetter: false),
    // a row that only the new item has
    new ItemStat("Fire damage", 12) };
compare.SetStats(iron, rune);

// Compare the item under the pointer
slot.RegisterCallback<PointerEnterEvent>(_ =>
    compare.SetStats(equipped.Stats, item.Stats));

StatDelta

Member Description
From (from), To (to) The value before and after the change. SetValues(from, to) sets both.
Delta To minus From.
HigherIsBetter (higher-is-better) True (the default) makes a larger value green. False makes a smaller value green, as for a weight or a cooldown. The arrows always point the way the value goes.
DoubleAt (double-at) The change that shows two arrows (default 10). A smaller change shows one arrow.
TripleAt (triple-at) The change that shows three arrows (default 25).
Percent (percent) True (the default): DoubleAt and TripleAt are percents of From. False: they are values.
Display (display) A StatDeltaDisplay: Arrows (the default), Number ("+7"), Both (the arrows, then "+7"), Percent (the change as a percent of From, "+12.5%") or ArrowsAndPercent (the arrows, then the percent without a sign, "12.5%", as the arrows show the direction). The text has the color of the arrows.
ArrowStyle (arrow-style) A StatDeltaArrowStyle: Stacked (the default) is one, two or three arrows on top of each other. Slanted is one small arrow that points up and to the right, or down and to the right, for a change of any size.
FormatString (format-string) The .NET number format of the number and of the percent (default "0.##").
ChangePercent The change as a percent of From: 100 for a doubling, -50 for a halving. NaN when there is none (see below).
StatDelta.TryGetPercent(from, to, out percent) The same, with no element. False, and 0, when From is 0 or a value is not finite.
Arrows The number of arrows: 0 for no change, else 1, 2 or 3.
ShowsArrows True while the delta draws arrows: the display is not Number or Percent, and the value changes.
IsBetter, IsWorse True when the change is good or bad. Both are false for no change.
StatDelta.ArrowCount(from, to, doubleAt, tripleAt, percent) The number of arrows, with no element.

ItemCompare

An ItemCompare table comparing Iron Sword and Rune Blade across five stats with green gains and a red weight increaseAn ItemCompare table comparing Iron Sword and Rune Blade across five stats with green gains and a red weight increase

Member Description
SetStats(current, candidate) Compares two lists of ItemStat. Null or empty candidate shows the current values with no change.
ItemStat(name, value, higherIsBetter, format) One stat of an item. Set higherIsBetter to false for a stat where less is better.
Rows The rows, each an ItemCompareRow: the stats of the current item, then the stats that only the candidate has.
GetRow(name) The row of a stat, or null. A row has StatName, Current, Candidate (null when the item does not have the stat), CandidateCell and Delta.
ShowTotal (show-total) Adds a total row. The total adds the values, and subtracts the values of a stat where less is better. TotalRow is the row.
TotalTitle (total-title) The name of the total row. Null (the default) shows "Total", the ToolboxText.TOTAL text.
CurrentTitle (current-title), CandidateTitle (candidate-title) The column headers. Null (the default) shows "Equipped" and "New", the ToolboxText keys EQUIPPED and NEW, which follow a language change. A title that you set stays.
ShowCurrent (show-current) Shows the column of the current values (default true).
Display, DoubleAt, TripleAt, Percent The settings of the StatDelta of every row.
Layout (layout) An ItemCompareLayout: Auto (the default) is a table while the values and a name column of MIN_NAME_WIDTH (80 px, or the longest name when it is shorter) fit in the width. A narrower compare stacks each name above its values. Table and Stacked keep one layout at any width.

Tips:

Styling

Class Element
tb-stat-delta The StatDelta: bold small text in --tb-color-text-muted.
tb-stat-delta--better A good change, in --tb-color-success.
tb-stat-delta--worse A bad change, in --tb-color-danger.
tb-stat-delta--neutral No change.
tb-stat-delta--slanted The delta while ArrowStyle is Slanted.
tb-stat-delta--arrows The delta while it draws arrows. Its padding-left (13 px) is the room for the arrows: 9 px for the arrows and 4 px before the number.
tb-item-compare The table.
tb-item-compare__header The header row with the column titles.
tb-item-compare__row A row.
tb-item-compare__name, __value, __current, __delta The cells: the name, a value, the current value and the change.
tb-item-compare__value--better, --worse A new value that is better (--tb-color-success) or worse (--tb-color-text-danger) than the current value.
tb-item-compare__row--added, --removed A stat that only the new item has (a green name), or that only the current item has (a gray italic name).
tb-item-compare__total The total row, with a line above it.
tb-item-compare--no-current The table with ShowCurrent off. It hides the current column.
tb-item-compare--stacked The compare in the stacked layout: each name on a line of its own, with the values and the change under it at the right. The header shows only the column titles.

To show a good change in the accent color:

.tb-stat-delta--better { color: var(--tb-color-accent); }

The StatDeltaDemo scene shows one stat of a new sword with a delta that has only from and to, the stats of a level-up screen with the arrows, the number or both, a shop that compares each item with the equipped sword where less weight is better, the preview of a spell on an enemy with its mana and its cooldown, and four looks of a loot card, one of them for color blindness.