Skip to content

Commit

Permalink
Rework how we cache extra data.
Browse files Browse the repository at this point in the history
Get rid of the fields on HudItem and use the extra data struct
directly. Expand the struct to hold the underlying data used
to do the percentage calculations, and make all that data
available as format vars for text fields.

The max shout cooldown time must still live on the hud item,
because we still have to snag the largest value we see there and
hold onto it separately.

Updated the docs to match.
  • Loading branch information
ceejbot committed Jan 5, 2024
1 parent 12b5c04 commit eb57df9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 168 deletions.
14 changes: 8 additions & 6 deletions docs/article-layouts-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@ Here are the fields a text element has:

The data that can be filled into a format string is:

- any regular text you'd like
- `{name}`: the item's full display name
- `{count}`: how many of the item the player has
- `{charge}`: the remaining enchantment charge for a weapon, expressed as a percentage of the full charge
- `{time_left}`: the percentage time left for an item with a lifespan, such as torches or fueled lanterns
- `{cooldown_time}`: the number of seconds left for a shout cooldown, counting down to zero
- `{cooldown_percent}`: the percentage of the full time left for a shout cooldown
- `{charge_max}`: the maximum charge this enchanted weapon or usable item has
- `{charge}`: the remaining enchantment charge for this item
- `{time_max}`: the longest lifespan or recharge time an item or shout has
- `{time_left}`: the number of seconds left for an item, or time left to recharge
- `{meter_level}`: the percentage that would be shown in a graphical meter: what percentage of enchantment charge is left, the percentage of remaining burn time for a torch, or the percentage of remaining recharge time for a shout
- `{poison}`: the string "poison" if poisoned; empty otherwise (this should be translated, I know)
- any regular text you'd like

Some examples of valid format strings:

- `ITEM: {name}`
- `{name}: {count}`
- `{name}: {charge}%`
- `{name}: {meter_level}%`
- `{name}: {time_left}s`
- `outfit`

Here's a full text element, which draws the name of the equipped shout or power for that slot:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ offset = { x = 0.0, y = 0.0 }
[[power.text]]
alignment = "left"
color = { r = 200, g = 200, b = 200, a = 255 }
contents = "{name} recharge: {time_left}%"
contents = "{name} recharged in {time_left} seconds"
font_size = 20.0
offset = { x = -35.0, y = 0.0 }

Expand Down Expand Up @@ -86,7 +86,7 @@ size = { x = 50.0, y = 50.0 }
[[left.text]]
alignment = "left"
color = { r = 200, g = 200, b = 200, a = 255 }
contents = "{name} {charge}% {poison}"
contents = "{name} {meter_level}% {poison}"
font_size = 20.0
offset = { x = -35.0, y = 0.0 }
wrap_width = 250.0
Expand All @@ -101,7 +101,7 @@ size = { x = 50.0, y = 50.0 }
[[right.text]]
alignment = "left"
color = { r = 200, g = 200, b = 200, a = 255 }
contents = "{name} {charge}% {poison}"
contents = "{name} {meter_level}% {poison}"
font_size = 20.0
offset = { x = -35.0, y = 0.0 }
wrap_width = 250.0
Expand All @@ -118,4 +118,4 @@ alignment = "left"
color = { r = 255, g = 255, b = 255, a = 255 }
contents = "{count} {name}"
font_size = 20.0
offset = { x = -35.0, y = -15.0 }
offset = { x = 5.0, y = -15.0 }
4 changes: 4 additions & 0 deletions src/controller/facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@ pub fn refresh_hud_items() {
/// Fill out some extra data info.
pub fn relevant_extra_data(
has_charge: bool,
max_charge: f32,
charge: f32,
is_poisoned: bool,
has_time_left: bool,
max_time: f32,
time_left: f32,
) -> Box<RelevantExtraData> {
Box::new(RelevantExtraData::new(
has_charge,
max_charge,
charge,
is_poisoned,
has_time_left,
max_time,
time_left,
))
}
Expand Down
Loading

0 comments on commit eb57df9

Please sign in to comment.