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:
Fixed V_SPLITSCREEN on OpenGL. It's about time, huh?
Added stplyrnum to simplify HUD code. Also moved it (and stplyr) to st_stuff.h where it belongs.
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:
* Fixed `V_SPLITSCREEN` on OpenGL. It's about time, huh?
* Added `stplyrnum` to simplify HUD code. Also moved it (and `stplyr`) to st_stuff.h where it belongs.
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...
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...
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
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](https://github.com/Indev450/SRB2Kart-Saturn/files/14366309/newhudtest.txt)

Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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:
colorizeditemboxanddarkitembox.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 asNow it does, and supports HUD items not inhud.enabled. Returns nil if the item doesn't support offsets. (TODO: error out instead?)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) andminimap. More can be added in the future.Some refactoring was done for this one; a new
drawinfo_thas 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:
V_SPLITSCREENon OpenGL. It's about time, huh?stplyrnumto simplify HUD code. Also moved it (andstplyr) to st_stuff.h where it belongs.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...
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
