Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented meters for enchantment charges, torches, & shouts
This too-large PR adds a *meter* feature for layouts. A meter is a UI element that shows how full or empty something is. For us, meters track an item's enchantment charge level if it's a weapon, its remaining burn time if it's a torch, or its remaining cooldown time if it's a shout. Any slot element can have a meter, but it's only meaningful for those kinds of items. A meter in its rectangular form looks like this: ```toml [left.meter] angle = 90 offset = { x = 65.0, y = 0.0 } [left.meter.background] color = { r = 255, g = 255, b = 255, a = 255 } size = { x = 100.0, y = 20.0 } svg = "meter_bar_empty.svg" [left.meter.filled] color = { r = 80, g = 0, b = 145, a = 255 } size = { x = 96.0, y = 18.0 } svg = "meter_bar_filled.svg" ``` All of the layouts that come with the fomod have been updated to show meter information in whatever way is appropriate for that meter. There also is an incomplete and untested implementation in the code for circular arc meters. None of the standard layouts use this, so I think we should ship what's working now and iterate. There are new format vars for use in text elements in layouts. The full list of format vars is: * `name`: the full display name of the item * `count`: the number of items of this kind in the player inventory * `charge`: the remaining charge percentage for a weapon * `time_left`: the percentage burn time left for a torch * `cooldown_time`: the number of seconds left for a shout cooldown * `cooldown_percent`: the percentage time left for a shout cooldown * `poison`: the string "poison" if poisoned; empty otherwise (this should be translated) A number of other changes were needed to support meters. - The v2 layout now has a new "MeterElement" sub-element that it deserializes. The v1 layouts *do not* have any support for meters. - The flattened version of the layouts now has additional fields to hold meter layout data. - HUD items now cache all of the extra data needed to support drawing a meter so we do not need to consult extra data on every draw loop. They cache whether an item is enchanted; what the charge percentage is; if an item has "time left" extra data (e.g., torches) and what percentage that is; what the total shout cooldown time is if one exists, and what the remaining shout cooldown is (in seconds). There are comments in `huditem.rs` explaining why this isn't consistent across the varieties of data. - Extra data is refreshed every N draw calls, where N is determined by the constant `REFRESH_DRAW_COUNT` in `ui_renderer.h`. - Extra data is also refreshed whenever an item becomes visible in the HUD, to ensure freshness. - There are new svgs in `resources/backgrounds` for use in the shipping meters. - The functions in `ui_renderer.cpp` that rotate elements for drawing have been golfed down to do considerably less arithmetic per rotation, because we're doing a lot more of it now. - Updated the documentation for layouts. Unrelated changes that I made along the way for tidiness reasons: - Every file in the `game` subdirectory was given its own namespace, named after the file. I did this because I was annoyed that I sometimes had to guess where something was implemented when memory failed me. - All listeners aka "event sinks" are now coalesced into a single listener class because I wanted to add several new ones. These are not yet in use, save for a menu open/close event listener that logs, but they will be soon. - Documented some undocumented struct fields and functions, whenever I happened to think about them long enough to notice they were undocumented. - Improved text alignment for bug #98. This isn't good enough yet, but it is not a blocker for meters.
- Loading branch information