How do I make a personalized hud?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
iAmGod01
Bob-omb
Bob-omb
Posts: 35
Joined: Wed May 20, 2020 8:37 am
Current Project: Super Mario Adventure 1

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

User avatar
CJ_RLushi
Swooper
Swooper
Posts: 120
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters
Current Project: Another Super Mario Bros. 3 Remake [SMBX2]

Re: How do I make a personalized hud?

Postby CJ_RLushi » 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?
My episode lol:
Image

TheTrueMarioMaster
Bit
Bit
Posts: 148
Joined: Mon Mar 19, 2018 11:58 pm
Chat Username: TheTrueMarioMaster

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.
Other places to find me at.
PureZC
MarioFanGameGalaxy

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8415
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: How do I make a personalized hud?

Postby Enjl » 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.
The ABC of Creation
________________________________________________________
Image

TheTrueMarioMaster
Bit
Bit
Posts: 148
Joined: Mon Mar 19, 2018 11:58 pm
Chat Username: TheTrueMarioMaster

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.
Other places to find me at.
PureZC
MarioFanGameGalaxy

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8415
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: How do I make a personalized hud?

Postby Enjl » 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!
The ABC of Creation
________________________________________________________
Image


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests