ZScript: Status Bar Questions
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
Looking at SetSize, what is the very first parameter (height) doing? In doom it's set to 32, hexen 38...
Also what's the best way to replicate the 'forcedscale' keyword?
Also what's the best way to replicate the 'forcedscale' keyword?
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
The first parameter is the actual height of the status bar, i.e. how much of the view it obstructs.
For forcedscale look at the definitions of
For forcedscale look at the definitions of
Code: Select all
void BeginStatusBar(int resW, int resH, int relTop, bool forceScaled);
void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false);
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
Okay I gave it a shot.
Here's the code to the SBARINFO for comparison's sake:
And here's my current translation to zscript.
Am I forgetting to do something that's causing this alignment to go out of whack? Or do we basically need to reposition it to the new system?
Here's the code to the SBARINFO for comparison's sake:
Code: Select all
height 0;
CompleteBorder True;
Resolution 1024,768;
InterpolateHealth false, 20;
InterpolateArmor false, 20;
//================================================================================================
//================================================================================================
// This version HAS the weapon bar and ammo counter
//================================================================================================
//================================================================================================
statusbar Normal, forcescaled
{
// Powerups
// Go first because otherwise they obscure HUD elements
inInventory PowerD4QuadDamage { drawimage "Shade2Ma", -171, 0; }
inInventory PowerD4Regen { drawimage "Shade2Cy", -171, 0; }
inInventory PowerD4Haste { drawimage "Shade2Ye", -171, 0; }
inInventory PowerD4Money { drawimage "Shade2Gr", -171, 0; }
// UAC Doomguy collectible uses
InInventory DollUses,1
{ drawimage "Ddoll", 1060,727; }
InInventory DollUses,2
{ drawimage "Ddoll", 1030,727; }
InInventory DollUses,3
{ drawimage "Ddoll", 1000,727; }
InInventory DollUses,4
{ drawimage "Ddoll", 970,727; }
InInventory DollUses,5
{ drawimage "Ddoll", 940,727; }
InInventory DollUses,6
{ drawimage "Ddoll", 910,727; }
InInventory DollUses,7
{ drawimage "Ddoll", 880,727; }
InInventory DollUses,8
{ drawimage "Ddoll", 850,727; }
InInventory DollUses,9
{ drawimage "Ddoll", 820,727; }
// The Usual
drawimage "BODYBAR0", -69,669;
// ...
}
Code: Select all
Class Doom4StatusBar : BaseStatusBar
{
DynamicValueInterpolator mHealthInterpolator;
DynamicValueInterpolator mHealthInterpolator2;
HUDFont mHUDFont;
HUDFont mIndexFont;
HUDFont mBigFont;
InventoryBarState diparms;
InventoryBarState diparms_sbar;
override void Init()
{
Super.Init();
SetSize(0, 1024, 768);
CompleteBorder = true;
// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_DOOM";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, true, 1, 1);
fnt = "INDEXFONT_DOOM";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
fnt = "BIGFONT";
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 2, 2);
diparms = InventoryBarState.Create(mIndexFont);
//diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
mHealthInterpolator2 = DynamicValueInterpolator.Create(0, 0.25, 1, 6); // the chain uses a maximum of 6, not 8.
}
override void NewGame ()
{
Super.NewGame();
mHealthInterpolator.Reset (0);
mHealthInterpolator2.Reset (0);
}
override void Tick()
{
Super.Tick();
mHealthInterpolator.Update(CPlayer.health);
}
override void Draw (int state, double TicFrac)
{
Super.Draw (state, TicFrac);
if (state == HUD_StatusBar)
{
BeginStatusBar(true);
DrawMainBar (TicFrac);
}
else if (state == HUD_Fullscreen)
{
BeginHUD(1.0, true);
DrawFullScreenStuff();
}
}
protected void DrawMainBar (double TicFrac)
{
}
protected void DrawFullScreenStuff ()
{
int imageAlignment = 0;
if (GetAmountOnly("PowerD4QuadDamage")) DrawImage("Shade2Ma", (-171, 0), imageAlignment);
if (GetAmountOnly("PowerD4Regen")) DrawImage("Shade2Cy", (-171, 0), imageAlignment);
if (GetAmountOnly("PowerD4Haste")) DrawImage("Shade2Ye", (-171, 0), imageAlignment);
if (GetAmountOnly("PowerD4Money")) DrawImage("Shade2Gr", (-171, 0), imageAlignment);
/* For comparison's sake.
inInventory PowerD4QuadDamage { drawimage "Shade2Ma", -171, 0; }
inInventory PowerD4Regen { drawimage "Shade2Cy", -171, 0; }
inInventory PowerD4Haste { drawimage "Shade2Ye", -171, 0; }
inInventory PowerD4Money { drawimage "Shade2Gr", -171, 0; }
*/
int DoomDollMax, DoomDollCount;
[DoomDollCount, DoomDollMax] = GetAmount("DollUses");
DoomDollCount = Min(DoomDollCount, DoomDollMax);
if (DoomDollCount > 0)
{
for (int i = 0; i < DoomDollCount; i++)
{
int DollX = 1060 - (30 * i);
DrawImage("Ddoll", (DollX, 727), imageAlignment);
}
}
DrawImage ("BODYBAR0", (-69, 669), imageAlignment);
/* UAC Doomguy collectible uses
InInventory DollUses,1
{ drawimage "Ddoll", 1060,727; }
InInventory DollUses,2
{ drawimage "Ddoll", 1030,727; }
InInventory DollUses,3
{ drawimage "Ddoll", 1000,727; }
InInventory DollUses,4
{ drawimage "Ddoll", 970,727; }
InInventory DollUses,5
{ drawimage "Ddoll", 940,727; }
InInventory DollUses,6
{ drawimage "Ddoll", 910,727; }
InInventory DollUses,7
{ drawimage "Ddoll", 880,727; }
InInventory DollUses,8
{ drawimage "Ddoll", 850,727; }
InInventory DollUses,9
{ drawimage "Ddoll", 820,727; }
*/
}
}
extend class Doom4StatusBar
{
int GetAmountOnly(class<Inventory> item)
{
let it = CPlayer.mo.FindInventory(item);
return (it ? it.Amount : 0);
}
}
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
What happens?
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
I just realized I put the hud stuff into the fullscreen stuff by mistake, whoops. That'll do it.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
So one thing I don't quite get is the coordinate system between status bar and full screen.
It's so much different than the other...
Por que?
Code: Select all
if (state == HUD_StatusBar)
{
BeginStatusBar(true);
DrawMainBar (TicFrac);
}
else if (state == HUD_Fullscreen)
{
BeginHUD(1.0, true);
DrawFullScreenStuff();
}
Por que?
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
The status bar is supposed to draw into a 320x200 screen with the status bar at the bottom.
The fullscreen HUD is supposed to align stuff to the screen's edges. This is copied verbatim from SBARINFO.
The fullscreen HUD is supposed to align stuff to the screen's edges. This is copied verbatim from SBARINFO.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
Why is that?Graf Zahl wrote:removed alpha parameter from BaseStatusBar.DrawBar because this cannot be used with this function.
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
The bar drawer is rather hacky to allow working with Hexen's badly designed graphics. For translucency a baggage-free version needs to be done that doesn't try to put a black fill overlay over the graphic.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
I take it that's planned? It would be highly appreciated.
-
- Posts: 469
- Joined: Sat Apr 16, 2016 6:01 am
- Preferred Pronouns: She/Her
Re: ZScript: Status Bar Questions
Code: Select all
SetClipRect(0, 1080 - 128, 64, 64);
DrawImage("STARTAN2", (0, 1080), DI_ITEM_LEFT_BOTTOM);
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript: Status Bar Questions
A bug maybe?
-
- Posts: 1337
- Joined: Tue Jul 15, 2003 4:18 pm
Re: ZScript: Status Bar Questions
This works... Also allows bars to be scaled...Major Cooke wrote:I take it that's planned? It would be highly appreciated.
I think some of the border stuff might still be unnecessary now, but it doesn't stop anything I've done from working - I haven't really tested with a border, though - it "works", but I don't know what the expected behavior is supposed to me.
Code: Select all
//Custom version of DrawBar that allows drawing with alpha - mostly copy/paste from original function, modified to allow alpha and scaling
void DrawBarEx(String ongfx, String offgfx, double curval, double maxval, Vector2 position, int border, int vertical, int flags = 0, double alpha = 1., double scale = 1.)
{
let ontex = TexMan.CheckForTexture(ongfx, TexMan.TYPE_MiscPatch);
if (!ontex.IsValid()) return;
let offtex = TexMan.CheckForTexture(offgfx, TexMan.TYPE_MiscPatch);
Vector2 texsize = TexMan.GetScaledSize(ontex);
texsize.x *= scale;
texsize.y *= scale;
[position, flags] = AdjustPosition(position, flags, texsize.X, texsize.Y);
double value = (maxval != 0) ? clamp(curval / maxval, 0, 1) : 0;
if(border != 0) value = 1. - value; //invert since the new drawing method requires drawing the bg on the fg.
// {cx, cb, cr, cy}
double Clip[4];
Clip[0] = Clip[1] = Clip[2] = Clip[3] = 0;
bool horizontal = !(vertical & SHADER_VERT);
bool reverse = !!(vertical & SHADER_REVERSE);
double sizeOfImage = (horizontal ? texsize.X - border*2 : texsize.Y - border*2);
Clip[(!horizontal) | ((!reverse)<<1)] = sizeOfImage - sizeOfImage * value;
// preserve the active clipping rectangle
int cx, cy, cw, ch;
[cx, cy, cw, ch] = screen.GetClipRect();
if(border != 0)
{
for(int i = 0; i < 4; i++) Clip[i] += border;
//Draw the whole foreground
DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha, scale: (scale, scale));
SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags);
}
if (offtex.IsValid()) { DrawTexture(offtex, position, flags | DI_ITEM_LEFT_TOP, alpha, scale: (scale, scale)); }
if (border == 0)
{
SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags);
DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha, scale: (scale, scale));
}
// restore the previous clipping rectangle
screen.SetClipRect(cx, cy, cw, ch);
}
-
- Posts: 469
- Joined: Sat Apr 16, 2016 6:01 am
- Preferred Pronouns: She/Her
Re: ZScript: Status Bar Questions
Probably, I guess. Since I haven't got any other responses here I suppose I'll go report it.Nash wrote:A bug maybe?
-
- Lead GZDoom+Raze Developer
- Posts: 49183
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
Nash wrote:A bug maybe?
Hard to say from a small fragment of code that doesn't say anything about the context. Just this: This code doesn't look correct at all, so I need to see more.