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
Actually I meant "only the menus will draw at capped framerates".
And naturally it is harmless. Especially since we have to pick apart the stuff ourselves...
And naturally it is harmless. Especially since we have to pick apart the stuff ourselves...
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
Sometimes reading the already existing source may give good clues:
See the TicFrac?
Code: Select all
override void Draw (int state, double TicFrac)
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
1) MAPINFO's gameinfo section - check the repo.ZZYZX wrote:How do I point the statusbar to a ZScript class?
Will it completely replace all statusbars or like SBARINFO did it (separate for fullscreen, separate for regular, and althud disables any custom statusbars)?
How do I make something draw over statusbar hudmessage-style that'd work with any statusbar even the internal ones? I made RenderOverlay for that, but then Graf said it's going to be in the statusbar.
2) A status bar is one object that contains all logic for drawing both the HUD and the status bar. This cannot be changed because otherwise all existing code would break. There's simply too much SBARINFO stuff out there that requires this handling.
3) Once the status bars are fully implemented, this will be addressed. The reason I disabled it is that it was done in the completely wrong spot - outside the HUD code. This needs to be done in DBaseStatusBar::DrawTopStuff - the function where HUD messages are being processed - and pass on some information about the current HUD. But since I haven't even touched that part of the code yet, it's still on hold.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: ZScript: Status Bar Questions
Well, this is progressing much quicker than expected.
A quick question: Are there any consequences to calling SetSize after the statusbar class has been initialized? I'm basically looking to call it in DrawMainBar/DrawFullScreenStuff to make the statbar and fullscreen HUD have different sizes.
[EDIT] Well, I'm now noticing that those two functions are just things in doom_sbar to simplify Draw() in doom_sbar.txt, so what I'm really asking is "can I safely call SetSize() in Draw()?"
[also hey, a 'protected' keyword! :]
A quick question: Are there any consequences to calling SetSize after the statusbar class has been initialized? I'm basically looking to call it in DrawMainBar/DrawFullScreenStuff to make the statbar and fullscreen HUD have different sizes.
[EDIT] Well, I'm now noticing that those two functions are just things in doom_sbar to simplify Draw() in doom_sbar.txt, so what I'm really asking is "can I safely call SetSize() in Draw()?"
[also hey, a 'protected' keyword! :]
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
Yes, you can. All you have to look out for is that the setting when returning is ok, because the status bar's height is used in far too many places in the code to deteming the view window size.
This really needs to be done differently, it's an open invitation for problems, but so far I do not have any good idea, because of SBARINFO considerations.
This code still needs a bit of cleanup from almost 20 years of non-maintenance.
This really needs to be done differently, it's an open invitation for problems, but so far I do not have any good idea, because of SBARINFO considerations.
This code still needs a bit of cleanup from almost 20 years of non-maintenance.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript: Status Bar Questions
First!!! Compass written in ZScript as a custom status bar.
Just gotta wait for the clipping rectangle and I can dump my ACS for good. >8D
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript: Status Bar Questions
I'm not even done with the status bar and some people still use it... Be careful that stuff doesn't break, right now I do not care about breaking changes and if something isn't good it gets changed.
The clipping rectangle will be the last thing I do, I only need it for the Hexen status bar which still waits for being converted.
The clipping rectangle will be the last thing I do, I only need it for the Hexen status bar which still waits for being converted.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript: Status Bar Questions
Hehe, I know. I even said in the last page that I'm expecting this stuff to break. I was just toying around with it to get a feel for writing status bar classes. It's just a tiny class anyway, nothing I won't mind to throw away.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript: Status Bar Questions
If it's of any comfort, I'm holding off until it's actually done this time. I learned my lesson previously.Graf Zahl wrote:I'm not even done with the status bar and some people still use it... Be careful that stuff doesn't break, right now I do not care about breaking changes and if something isn't good it gets changed.
(Plus I need to work on documenting menus...)
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript: Status Bar Questions
DTA_Clip...something.Nash wrote:
First!!! Compass written in ZScript as a custom status bar.
Just gotta wait for the clipping rectangle and I can dump my ACS for good. >8D
Use this viewtopic.php?p=986562#p986562
It does clipping automatically.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: ZScript: Status Bar Questions
ZZYZX: I'm aware of the clipping DTA tag, but I wasn't sure if Screen.DrawTexture can be used inside status bars. Right now I'm just using BaseStatusbar.DrawImage, like what gzdoom.pk3 is doing.
Will give your library a try later, I kinda don't understand how to use it yet...
Will give your library a try later, I kinda don't understand how to use it yet...
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript: Status Bar Questions
It should work.
Also, basically:
In your status bar, callThen store sbd somewhere and call sbd.OnDraw() from statusbar's draw function.
Then if you need statusbar data inside that object, just set some field to your sbar or wherever Graf stores the relevant info.
Note: there is no VirtualWidth/VirtualHeight directly because you generally don't want squished graphics. So mScale defines the scaling and VirtualWidth/VirtualHeight are readonly (using Element.GetClientRect).
Note that this kinda replaces half of the existing weird resolution/scaling heuristics in the statusbar. I won't be surprised if Graf suddenly appears and says that this won't work under some weird conditions.
Also, basically:
Code: Select all
class SpecialSbar : Element
{
override void OnCreate()
{
mRect = Rect.FromXYWH(0, 0, Screen.GetWidth(), Screen.GetHeight()); // these are coordinates in parent element's coordinates. for root element = screen coordinates
mScale = 1; // this is a float, change if you need to scale to some resolution, e.g. if you want to have virtual 1024x768, do mScale = double(Screen.GetHeight())/768.0;
// you can add other init stuff here
}
override void Draw()
{
Drawer d = GetDrawer();
// use Drawer methods here
}
}
Code: Select all
SpecialSbar sbd = new('SpecialSbar').Init();
Then if you need statusbar data inside that object, just set some field to your sbar or wherever Graf stores the relevant info.
Note: there is no VirtualWidth/VirtualHeight directly because you generally don't want squished graphics. So mScale defines the scaling and VirtualWidth/VirtualHeight are readonly (using Element.GetClientRect).
Note that this kinda replaces half of the existing weird resolution/scaling heuristics in the statusbar. I won't be surprised if Graf suddenly appears and says that this won't work under some weird conditions.
-
- Posts: 5032
- Joined: Sun Nov 14, 2010 12:59 am
Re: ZScript: Status Bar Questions
Is modifying existing status bars currently possible? I have this code which is based on DoomStatusBar, but GZDoom (2.5pre-178-ge865ba6) aborts with this error:
All I did was inherit from DoomStatusBar class, overriding Draw() so I can call DrawFullScreenStuffCustom(), whose definition is exactly the same as DoomStatusBar's DrawFullScreenStuff().
Code: Select all
Can't call play function DrawFullScreenStuffCustom from ui context
Code: Select all
class CustomDoomStatusBar : DoomStatusBar
{
override void Draw (int state, double TicFrac)
{
BaseStatusBar.Draw (state, TicFrac);
//Super.Draw (state, TicFrac);
if (state == HUD_StatusBar)
{
BeginStatusBar(320, 200, 32);
DrawMainBar (TicFrac);
}
else if (state == HUD_Fullscreen)
{
BeginHUD(320, 200, 1., false);
DrawFullScreenStuffCustom ();
}
}
protected void DrawFullScreenStuffCustom ()
{
Vector2 iconbox = (40, 20);
// Draw health
let berserk = CPlayer.mo.FindInventory("PowerStrength");
DrawImage(berserk? "PSTRA0" : "MEDIA0", (20, -2));
DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (44, -20));
let armor = CPlayer.mo.FindInventory("BasicArmor");
if (armor != null)
{
DrawInventoryIcon(armor, (20, -22));
DrawString(mHUDFont, FormatNumber(armor.Amount, 3), (44, -40));
}
Inventory ammotype1, ammotype2;
[ammotype1, ammotype2] = GetCurrentAmmo();
int invY = -20;
if (ammotype1 != null)
{
DrawInventoryIcon(ammotype1, (-14, -4));
DrawString(mHUDFont, FormatNumber(ammotype1.Amount, 3), (-30, -20), DI_TEXT_ALIGN_RIGHT);
invY -= 20;
}
if (ammotype2 != null && ammotype2 != ammotype1)
{
DrawInventoryIcon(ammotype2, (-14, invY + 17));
DrawString(mHUDFont, FormatNumber(ammotype2.Amount, 3), (-30, invY), DI_TEXT_ALIGN_RIGHT);
invY -= 20;
}
if (CPlayer.inventorytics == 0 && CPlayer.mo.InvSel != null && !level.NoInventoryBar)
{
DrawInventoryIcon(CPlayer.mo.InvSel, (-14, invY + 17));
DrawString(mHUDFont, FormatNumber(CPlayer.mo.InvSel.Amount, 3), (-30, invY), DI_TEXT_ALIGN_RIGHT);
}
if (deathmatch)
{
DrawString(mHUDFont, FormatNumber(CPlayer.FragCount, 3), (-3, 1), DI_TEXT_ALIGN_RIGHT, Font.CR_GOLD);
}
// Draw the keys. This does not use a special draw function like SBARINFO because the specifics will be different for each mod
// so it's easier to copy or reimplement the following piece of code instead of trying to write a complicated all-encompassing solution.
Vector2 keypos = (-10, 2);
int rowc = 0;
double roww = 0;
for(let i = CPlayer.mo.Inv; i != null; i = i.Inv)
{
if (i is "Key" && i.Icon.IsValid())
{
DrawTexture(i.Icon, keypos, DI_SCREEN_RIGHT_TOP|DI_ITEM_LEFT_TOP);
Vector2 size = TexMan.GetScaledSize(i.Icon);
keypos.Y += size.Y + 2;
roww = max(roww, size.X);
if (++rowc == 3)
{
keypos.Y = 2;
keypos.X -= roww + 2;
roww = 0;
rowc = 0;
}
}
}
if (CPlayer.inventorytics != 0 && !level.NoInventoryBar)
{
DrawInventoryBar(diparms, (0, 0), 7, DI_SCREEN_CENTER_BOTTOM, HX_SHADOW);
}
}
}
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: ZScript: Status Bar Questions
...ok, that's extremely weird. Are statusbars not ui? Why? I see BaseStatusBar is declared as ui but it doesn't work apparently.
Anyway, this particular issue can be fixed by explicitly marking your draw function as ui (e.g. protected ui void DrawFullScreenStuffCustom).
Anyway, this particular issue can be fixed by explicitly marking your draw function as ui (e.g. protected ui void DrawFullScreenStuffCustom).
-
- Posts: 5032
- Joined: Sun Nov 14, 2010 12:59 am
Re: ZScript: Status Bar Questions
With that done, I get this:ZZYZX wrote:Anyway, this particular issue can be fixed by explicitly marking your draw function as ui (e.g. protected ui void DrawFullScreenStuffCustom).
Code: Select all
Script error, "sbar_testing.pk3:zscript.txt" line 20:
Unexpected identifier
Expecting ';' or ','