How Do I SBARINFO? - A Tutorial

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

How Do I SBARINFO? - A Tutorial

Post by wildweasel »

Since the invention of SBARINFO for ZDoom, many have messed around with alternative HUDs for their mods. Although there are many HUDs available, and many mods that make use of them, I'm writing this tutorial to assist those who haven't yet figured the language out.

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
{
If you're familiar with Decorate or ACS, the structure here shouldn't be difficult to grasp; StatusBar starts a block of code, which is then opened with a brace (the { character - remember to close it afterwards). We could just close the block right away with no code in it, but since SBARINFO definitions outright replace whatever is already loaded (in this case, the default HUDs in zdoom.pk3), the HUD will appear blank anyway, so let's add something for it to draw. Let's add a [wiki]DrawNumber[/wiki] to it. Here's a simple one that draws your health near the bottom-left corner of the screen.

Code: Select all

StatusBar Normal
{
   DrawNumber 3, HUDFONT_DOOM, White, Health, fillzeros, 20, 160;
}
Let's break the command down by its arguments.
  • 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);
}
DrawString is set up in much the same way DrawNumber is, however, you do not need to specify the number of digits (since this is not a number), and the Flags argument is moved to the end, after the X/Y position and the Spacing argument. Save and run the file again; you'll see a nice green Health label under the number.

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);
}
I've given the DrawNumber command the same alignment(left) flag that DrawString has, and moved its position to X 0, Y 180. Save and run it again.

...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).
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: How Do I SBARINFO? - A Tutorial

Post by Gez »

wildweasel wrote: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.
SLADE 3 now has a "run" button as well.
Spoiler:
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

Ah. I guess I need to update my copy of SLADE then.
User avatar
Abba Zabba
Posts: 2166
Joined: Mon Sep 05, 2011 8:50 pm
Location: a place lol!
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by Abba Zabba »

Hey Weasel, I have a question; I'm trying to scale up the SHELA0 sprite on the HUD a slight pinch so that the middle space between the four shells is even with the other two spaces.

Code: Select all

drawimage "SHELA0", -84+center, -10, center
If I want to re-size the sprite for the HUD I'd add on two variables at the end right? But what would be a good starting number?

Thanks.
Last edited by Abba Zabba on Mon Sep 15, 2014 8:53 pm, edited 1 time in total.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

I'm going to be honest, I have no idea what you're trying to do there; I can't find anything on the wiki that says that "-84+center" is actually allowed. For scaling graphics, I seem to recall TEXTURES being required, or else setting the resolution of the HUD with the Resolution command. Perhaps you could clue me in with your complete SBARINFO lump?
User avatar
Abba Zabba
Posts: 2166
Joined: Mon Sep 05, 2011 8:50 pm
Location: a place lol!
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by Abba Zabba »

It's from Hideous Destructor, and I'm glad I'm not the only one confused.

Sbarinfo is attached, same as it is with the current update but with some red counters turned gold. Only thing I know is that the text editor format Vaecrius uses is used by WordPad rather than Notepad.
Attachments
sbarinfo.txt
(17.03 KiB) Downloaded 451 times
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

Holy shit. How...

As for resizing the one graphic on screen, DrawImage does not have a way to directly resize an onscreen graphic. You'll either need to create a new graphic and use that, or use Textures to create a rescaled version of it.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: How Do I SBARINFO? - A Tutorial

Post by Blue Shadow »

wildweasel wrote:DrawImage does not have a way to directly resize an onscreen graphic. You'll either need to create a new graphic and use that, or use Textures to create a rescaled version of it.
[wiki=DrawImage]Yes, it does[/wiki]; with the max-width and max-height paramters.


Edit:
wildweasel wrote:I can't find anything on the wiki that says that "-84+center" is actually allowed.
You can do that if your status bar definition uses the [wiki=StatusBar]fullscreenoffsets[/wiki] flag.
User avatar
zyzxzexe
Posts: 19
Joined: Sat Nov 22, 2014 11:13 pm

Re: How Do I SBARINFO? - A Tutorial

Post by zyzxzexe »

I was wondering if some one could tell me how to set up an identifier for drawing switchable images.

"DrawSwitchableImage <#>, <image-off>, <image-on>, <x>, <y> [, {center|centerbottom}]"

This was what the Zdoom wiki has, but I don't know how to properly implement it.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

zyzxzexe wrote:I was wondering if some one could tell me how to set up an identifier for drawing switchable images.

"DrawSwitchableImage <#>, <image-off>, <image-on>, <x>, <y> [, {center|centerbottom}]"

This was what the Zdoom wiki has, but I don't know how to properly implement it.
I'm not entirely sure what you want to do here. Could you explain what you're looking to do?
User avatar
zyzxzexe
Posts: 19
Joined: Sat Nov 22, 2014 11:13 pm

Re: How Do I SBARINFO? - A Tutorial

Post by zyzxzexe »

wildweasel wrote:
zyzxzexe wrote:I was wondering if some one could tell me how to set up an identifier for drawing switchable images.

"DrawSwitchableImage <#>, <image-off>, <image-on>, <x>, <y> [, {center|centerbottom}]"

This was what the Zdoom wiki has, but I don't know how to properly implement it.
I'm not entirely sure what you want to do here. Could you explain what you're looking to do?
Sorry. What I'm trying to do is create an image on the player HUD that will change when hes given a power up. The image works sort of like an icon showing the players face, so when he is given the right power up the icon will change to show the player in his power state.
Double(Super)Shotgun
Posts: 75
Joined: Fri Jul 25, 2014 2:16 pm

Re: How Do I SBARINFO? - A Tutorial

Post by Double(Super)Shotgun »

Hey Wildweasel: Your tutorials are freaking awesome. Freaking. Awesome. Would there be any chance of a TEXTURES tutorial some time in the future? Your tutorials have so far served as kind of boost-up into being able to comprehend the wiki entries a little easier, which is nice.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

Hm, perhaps I'll consider it soon.
User avatar
Silentdarkness12
Posts: 1555
Joined: Thu Aug 15, 2013 5:34 pm
Location: Plains of Pride

Re: How Do I SBARINFO? - A Tutorial

Post by Silentdarkness12 »

And now for a series of questions that will hopefully help me learn how to fix DarkHud to work the way I want it to.

1. When there's no scaling involved, is the resolution of a graphic for HUD images on a 1:1 ratio? I remember seeing Terminus put up a video regarding the pixel to resolution ratio once, but i'm not sure if it applies to HUD GFX as well.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: How Do I SBARINFO? - A Tutorial

Post by wildweasel »

If it's completely unscaled, then yes, the images are 1:1. However, this is at the mercy of user settings unless you define your status bar to your own resolution, which means that even the user setting will scale it to appear at that resolution instead of the default 320*200. And it's wise not to set the status bar resolution too high, since there are users who, for many reasons, have their screen resolution set lower than you might expect.
Post Reply

Return to “Tutorials”