Indev450 / SRB2Kart-Saturn

GNU General Public License v2.0
26 stars 9 forks source link

Add Lua functions for HUD customization #113

Closed GenericHeroGuy closed 8 months ago

GenericHeroGuy commented 8 months ago

Currently, supporting Saturn's HUD customization in Lua is kind of a pain. There's lots of cvars to deal with, like colorizedhud, colorizedhudcolor, xoffset, yoffset, lots of hardcode to copy and paste... It's especially painful for the item box, which has its own pair of cvars: colorizeditembox and darkitembox. And what if any of the above changes? Now you have to update your scripts to support it!

This PR introduces a set of new Lua functions that greatly simplifies supporting HUD customization.

x, y = hud.getOffsets(item) Returns the values of the given HUD item's offset cvars. Takes the same input as hud.enabled. Returns nil if the item doesn't support offsets. (TODO: error out instead?) Now it does, and supports HUD items not in hud.enabled.

x, y, flags = v.getDrawInfo(item) Returns the X, Y and flags where the given HUD item will be drawn. Currently supported are item, gametypeinfo (laps) and minimap. More can be added in the future. Some refactoring was done for this one; a new drawinfo_t has been introduced, so Lua and hardcode can share the same logic for positioning HUD items. This function might seem redundant, but it allows separating the offset cvars from the drawing logic. And I've got some plans for that 😛

v.drawItemBox(x, y, flags, small, dark, colormap) ~~Draws an item box. The size and darkness of the item box can be controlled, as well as the color. If no colormap is provided, it uses the default HUD colormap. Colorization is automatically enabled depending on the player's settings.~~

v.drawItemMul(x, y, flags, small, colormap) Draws the multi sticker. It's not as complex as the item box, but it's closely related, so it's included for convenience. (doesn't flip automatically, btw)

hudcolor = v.getHudColor() Returns the skincolor used for HUD colorization. Useful for colorizing your own HUD stuff.

colorized = v.useColorHud() Returns true if HUD colorization is enabled.

All in all, there's room for improvement, but the Lua side of things is pretty much done.

Some extras:

GenericHeroGuy commented 8 months ago

Aaaaand 20 seconds after pushing the branch, I realized new drawing functions are waaaay overkill :rage1: Would be a much better idea to just return the patch to use, since that's ultimately what the drawing functions do.

On the other hand, the automatic colormaps are pretty convenient. Not sure which is better...

GenericHeroGuy commented 8 months ago

Why not both? 😎

patch, colormap = v.getColorHudPatch(item) Returns the patch and colormap to use for the given HUD item. Different items may take different arguments.

Now that I've (hopefully) decided on the final set of functions, here's a sample script that shows everything in action: newhudtest.txt newhuddemo