SBARINFO's structure is pretty simple; there are blocks of code for each screensize (normal and fullscreen), for other bars (inventory, automap, the Strife popups, etc). Within those blocks, you lay down drawing commands to insert the various parts of your status bar: images, numbers, strings, bars, switchable images, and the famous Doomguy mug shot. SBARINFO does not have a lot of especially complex behavior; you are literally deciding on a thing to draw, decide what specifically is drawn, what in-game element it is tied to (Health, Ammo, Keys, etc), and where it goes. Okay, it's a little more in-depth than that, but that's the simple version of it.
Let's start off with a simple fullscreen HUD that displays your current health and nothing else. Begin by telling ZDoom which statusbar you're working on:
Code: Select all
StatusBar Normal
{
Code: Select all
StatusBar Normal
{
DrawNumber 3, HUDFONT_DOOM, White, Health, fillzeros, 20, 160;
}
- DrawNumber - This is the actual command being fed to SBARINFO. I don't think the CamelCase capitalization is strictly necessary (SBARINFO is not case-sensitive) but I find that it makes things a bit more readable.
- 3 - This is the "digits" or "places" argument. If the number (Health) gets any larger than the number of digits (3), this caps the number at the highest that can be displayed (999, in our case). You could expand the Health counter by making it larger (say, to 4 or more digits), but with just the standard DoomPlayer class, your Health is never going to go above 200 anyway.
- HUDFONT_DOOM - This is where we specify the Font that is used for the number. This can be any font defined in FONTDEFS, a font generated using ImageTool, or any BMF-format font. HUDFONT_DOOM is predefined in zdoom.pk3 and uses the numbers from your Doom IWAD. Other useful predefined fonts include CONFONT (the console) and DBIGFONT (the large font used in menus).
- White - The color (or "translation") of the number. Color names are defined in [wiki]TEXTCOLO[/wiki]; ZDoom has a bunch of these already built in to zdoom.pk3, and a list of them can be found in the aforementioned wiki link. You can also specify "Untranslated" which should just display the numbers as in their original graphics with no color change.
- fillzeros - This is a Flag. The Flags section can have as many or few flags as you want, as long as they're all separated by commas. If you don't want any flags, you can simply ignore this argument and proceed to the next one. Other useful flags include Alignment(left|center|right), WhenNotZero, and Interpolate. The "fillzeros" flag will fill unused digits with a zero; in our case, if the player only has 9 health, it will display as "009" on the bar.
- 20, 160; - The X/Y coordinates on screen where the number will be drawn from. A status bar is drawn to the screen's canvas, which is by default 320 pixels wide by 200 pixels tall (though this can be changed with the Resolution top-level command). When drawing things to the screen, you will generally want to position them according to the upper-left corner of the thing being drawn (so if we were to draw Doom's STBAR to the screen, which is 320 pixels wide and 32 pixels tall, we would place it at X 0, Y 168). However, DrawNumber defaults to being aligned on the right side instead of the left (this is default behavior for Doom's status bar numbers), so in our case we would choose the upper-right corner.
- Finally, remember to end all commands with a semicolon.
Copy the above code into a text lump called SBARINFO, save it into your WAD or PK3, then run it in ZDoom. Make sure your screen is sized to where you would normally see the Doom status bar, and you should see a white number 100 appear in the bottom-left corner.
Feel free to mess with the parameters of [wiki]DrawNumber[/wiki]. Once you're finished, we'll try adding a nice label to it.
First, let's make it a little clearer what you're seeing on the HUD. You want your player to be able to tell what all the numbers on his screen are supposed to mean, after all.
In your status bar code, let's add a [wiki]DrawString[/wiki] command to give this number a label.
Code: Select all
StatusBar Normal
{
DrawNumber 3, HUDFONT_DOOM, White, Health, fillzeros, 20, 160;
DrawString CONFONT, Olive, "Health", 0, 190, 0, alignment(left);
}
But wait, the health number is too far away from the label! Even worse, even though we've set the label to draw from the very left edge of the screen, the health number goes even further left of that! This means that, if someone's playing at a really low screen resolution (like 320x200), the health number will be unreadable! We'd better fix that up...let's add another flag to DrawNumber and adjust the positioning.
Code: Select all
StatusBar Normal
{
DrawNumber 3, HUDFONT_DOOM, White, Health, fillzeros, alignment(left), 0, 180;
DrawString CONFONT, Olive, "Health", 0, 190, 0, alignment(left);
}
...Wait a second. Now the number is being overlapped by its label. Hmm, we'd better fiddle with the numbers a bit more...but I'll let you do that, since you're the one learning how to do this sort of thing. Don't despair if your positioning is all wrong. Trial and error is a big part of coding a useful status bar. You will need to get used to making small tweaks to the SBARINFO code, saving, launching ZDoom, making note of the changes, then quitting, making further tweaks, saving again, running again...you get the idea, I hope. There are some ways to help speed along the process of testing and re-testing your project; personally, I keep a ZDL window in the corner of my screen with the Launch button always visible behind SLADE's window, so that I need only click that Launch button to start the test. But enough about that.
If you're going to add Ammo and Armor counters, all you really need to do is copy and paste the existing DrawNumber and DrawString lines, adjust the X/Y coordinates of them (leave the Y coordinates alone and only change the X coordinates - this keeps them aligned), then change "Health" to Armor, Ammo1, or any other thing listed in DrawNumber. Bear in mind that, in DrawString's case, you only need to enclose the string in quotes if you want it to literally print that word. DrawString has other functions, such as printing the Tag of the currently selected weapon, or the name of the map, or the player name, which require the words to not be enclosed in quotation marks.
I think this should be sufficient knowledge to get you started. Perhaps some time later I will compose a tutorial about the finer points of status bar making, like adding a nice background image, how to use FullscreenOffsets, etc.
References:
[wiki]SBARINFO[/wiki] - Links to all of the SBARINFO commands and how to use them.
[wiki]Default status bars[/wiki] - The default HUD code for Doom, Heretic, and Hexen (but not yet Strife).