How do I make a personalized hud?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
iAmGod01
Fighter Fly
Fighter Fly
Posts: 40
Joined: Wed May 20, 2020 8:37 am
Flair: Assemble pixel art

How do I make a personalized hud?

Postby iAmGod01 » Mon Jun 15, 2020 6:38 pm

good night folks i want to make a custom hud a mix of sma2 hud (smw) and smas hud (smb1) but i don't know how i want to customize the time counter and also wanted to leave the level time activated on all episode levels in the case I also want to change the position of a hud element and also add a dragon coin counter and star coins

Lusho
Tweeter
Tweeter
Posts: 161
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters
Pronouns: he/him

Re: How do I make a personalized hud?

Postby Lusho » Mon Jun 15, 2020 9:20 pm

Ok, the thing is, how much do you know about coding?, like, actually making a custom HUD is a pretty good starter script, but I need to know how much do you know before actually start from the base

Oh shouldnt this be moved into lunalua help?

TheTrueMarioMaster
Blooper
Blooper
Posts: 199
Joined: Mon Mar 19, 2018 11:58 pm

Re: How do I make a personalized hud?

Postby TheTrueMarioMaster » Thu Jun 25, 2020 10:07 pm

I'm also looking to create a personalized hud though mine I want more like SMB All-Stars. I'm not as familiar with the lunalua language and not sure what code you would use to move and add things to the hud so any tutorials for that would help.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9728
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: How do I make a personalized hud?

Postby Emral » Fri Jun 26, 2020 6:26 am

Move is easy.
local hudoverride = require("hudoverride")
Within hudoverride.lua, you can find objects for all the UI elements, providing x and y coordinates, as well as a visibility flag. (They're near the top of the file.)
By changing their coordinates/visibility in your luna.lua where you load it, you are moving the object around.

Adding is a bit more involved.
There are no direct tutorials for making a HUD, because making a HUD is simply a different way of saying "drawing text and images to the screen", which are done with a single function each linked below.
Just like with any piece of code that you write yourself, you must first find out what exactly it is you're trying to add. Something like an icon or text for an existing variable is simple enough to do with Graphics.drawImageWP and Text.printWP, but once we get into more involved systems, like trying to draw a P-Meter, you will need to write the code for how to get that information first. In that example you might save a variable called pSpeedValue and set it to math.abs(player.speedX) (absolute value (meaning no negative numbers) of player x speed). Then you can use that to determine what images and text to draw with the aforementioned functions.

Hope this helps. A bit short on time right now so couldn't provide a code example. The legacy "hudoftime" which you can find somewhere in either the legacy or tweaks subfolder, while not having the best code ever written, might be something to look at if you wanna see image drawing and text printing in action.

TheTrueMarioMaster
Blooper
Blooper
Posts: 199
Joined: Mon Mar 19, 2018 11:58 pm

Re: How do I make a personalized hud?

Postby TheTrueMarioMaster » Mon Jun 29, 2020 3:20 pm

That should help though I think the hardest part for me would be the part of it which changes depending on what section the player is in and would it be easier to just have the hud text change with every section or have it the same with the number that needs to be changed based on what section the level is in. Also does it have to be in luna.lua or can I put it in its own file. Just wondering for if I am unable to finish the hud code on time I'll have to leave it out to prevent errors from happening in the level.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9728
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: How do I make a personalized hud?

Postby Emral » Mon Jun 29, 2020 3:34 pm

Generally speaking, all lua code that can be in luna.lua can also be in a library, and code from libraries can be exposed so that luna.lua can access it. For your per-section thing I recommend using a table.

For reference, a table like this (in a file called hud.lua)

Code: Select all

local hud = {}

hud.sections = {
	[0] = "First Section",
	"Second Section",
	"Third Section",
	[20] = "Last Section
}

return hud
maps a number to a string. Pay attention to the lefthandside of the = in the table. If you don't do them, the table entries are in-order starting at 1, so if you want gaps or want Section 0 to be recognized you have to make it explicit.
Anyway... now you can do something like this (above the return):

Code: Select all

function hud.onInitAPI()
	registerEvent(hud, "onDraw")
end

function hud.onDraw()
	Text.print((hud.sections[player.section] or ""), 0, 0)
end
The onInitAPI is just to make it so that onDraw can run in this library. And then in the onDraw, we substitute the 0 and 20 from before with whatever value the player's current section (0-20) is. So for Section 1 it says "Second Section", and in Section 15 it would print nothing, because of the "or" thing I put. What that does is catch if the lefthandside is not defined and then use the right side instead.

Now that's nice but there's one last step. I intentionally made the variable hud.sections instead of "local sections", so that it's part of the "hud" library table. The libary table is what's returned by require. So what you can do, in ANY luna.lua:

Code: Select all

local hud = require("hud")

hud.sections = {
	[0] = "The Beginning..."
}
This will OVERWRITE the assignment from the first code block in this post, allowing you to customize the values for each section on a per-level basis, by just putting different values for this into each luna.lua.

For more info on making libraries: https://wohlsoft.ru/wiki/index.php?titl ... ua_library

Hope this helps!

RadMetalMarioSMIX
Bit
Bit
Posts: 65
Joined: Sat Mar 14, 2015 6:42 pm
Flair: What kind of grave is this?
Pronouns: he/him

Re: How do I make a personalized hud?

Postby RadMetalMarioSMIX » Thu Mar 10, 2022 3:28 pm

Enjl wrote:
Fri Jun 26, 2020 6:26 am
Move is easy.
local hudoverride = require("hudoverride")
Within hudoverride.lua, you can find objects for all the UI elements, providing x and y coordinates, as well as a visibility flag. (They're near the top of the file.)
By changing their coordinates/visibility in your luna.lua where you load it, you are moving the object around.

Adding is a bit more involved.
There are no direct tutorials for making a HUD, because making a HUD is simply a different way of saying "drawing text and images to the screen", which are done with a single function each linked below.
Just like with any piece of code that you write yourself, you must first find out what exactly it is you're trying to add. Something like an icon or text for an existing variable is simple enough to do with Graphics.drawImageWP and Text.printWP, but once we get into more involved systems, like trying to draw a P-Meter, you will need to write the code for how to get that information first. In that example you might save a variable called pSpeedValue and set it to math.abs(player.speedX) (absolute value (meaning no negative numbers) of player x speed). Then you can use that to determine what images and text to draw with the aforementioned functions.

Hope this helps. A bit short on time right now so couldn't provide a code example. The legacy "hudoftime" which you can find somewhere in either the legacy or tweaks subfolder, while not having the best code ever written, might be something to look at if you wanna see image drawing and text printing in action.
So would total coin count a custom variable be an existing one?

ditditdit
Dolphin
Dolphin
Posts: 92
Joined: Sun Jan 02, 2022 4:25 pm
Flair: e
Pronouns: she/they
Contact:

Re: How do I make a personalized hud?

Postby ditditdit » Tue Mar 15, 2022 1:03 pm

I need to add a level counter, and I i already have a Level variable, what now???

BrokenAce
Swooper
Swooper
Posts: 51
Joined: Sat Feb 06, 2016 11:48 am

Re: How do I make a personalized hud?

Postby BrokenAce » Wed Aug 03, 2022 2:07 pm

Not sure if the right thread to ask this, but how would I remove the annoying 2 pixel gap between numbers on the counter? You know, so the numbers are actually touching like they would in a real Mario game. I couldn't find anything related to it in huboverride.lua.

Edit: I also found another bizarre quirk. For some reason the coin counter's number seem to use textplus (which cannot be customized within an episode) rather than using the hardcoded numbers. Would be great if there was a fix for all this.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari