ZScript: Status Bar Questions

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

Nash wrote: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...


You can use Screen.DrawTexture, but then you have to do all the nasty stuff yourself, like scaling coordinates etc. For specialty applications that is an option, but if you want to write some simple code to draw a status bar you want simple function calls that take reasonable defaults for most parameters and do the dirty stuff internally. Screen.DrawTexture requires you to lay out everything yourself in most verbose detail. Ultimately all those other draw functions call this as well, as it is the one central 2D sprite drawing function.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript: Status Bar Questions

Post by Nash »

Graf, will there be support for stacking multiple status bar classes, like AddEventHandlers? I can think of one use case right now: a ZScriptified version of [wiki]Hudmessageonactor[/wiki]. If only one status bar is allowed, the method has to be hardcoded into the mod's only status bar and cannot be modular.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

Only if you do it manually by creating a status bar that owns two others and draws them on top of each other.
The status bar is a vital system component and there can only be one.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript: Status Bar Questions

Post by ZZYZX »

HudMessages-like statusbar-independent drawing was promised later.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript: Status Bar Questions

Post by Nash »

ZZYZX wrote:HudMessages-like statusbar-independent drawing was promised later.
Source?
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript: Status Bar Questions

Post by ZZYZX »

User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript: Status Bar Questions

Post by Nash »

Code: Select all

class LADHUD : BaseStatusBar
{
    HUDFont mHUDFont;

    const HUD_WIDTH = 320;
    const HUD_HEIGHT = 200;
    const HUD_COMPASS_POS_Y = HUD_HEIGHT - 2;
    const barHeight = 0;

    override void Init()
    {
        Super.Init();
        SetSize(barHeight, HUD_WIDTH, HUD_HEIGHT);
        Font fnt = "SmallFont";
        mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 1, 1);
    }

    override void NewGame()
    {
        if (CPlayer != NULL)
        {
            AttachToPlayer(CPlayer);
        }
    }

    override void Draw(int state, double TicFrac)
    {
        Super.Draw(state, TicFrac);

        BeginHUD(HUD_WIDTH, HUD_HEIGHT, 1., false);

        CVar compassCvar = CVar.FindCVar("cl_compass", CPlayer);
        if (compassCvar.GetInt() > 0) DrawCompass();
    }

    void DrawCompass(void)
    {
        if (CPlayer)
        {
            int flags = DI_SCREEN_HCENTER | DI_SCREEN_BOTTOM;

            // draw background
            double backgroundAlpha = 0.35;
            Vector2 backgroundPos = (0, -2);
            DrawImage("graphics/hud/compass/background.png", backgroundPos, flags, backgroundAlpha);
        }
    }
}
 
How do I make the DrawImage'd image automatically adjust its scale according to the uiscale CVar? I looked at the Doom status bar and can't see it doing anything differently than just a plain DrawImage call... but the scaling works automatically on that one.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

DrawImage automatically adjusts to the HUD scale. This is not necessarily the same as the uiscale. It only uses the uiscale if hud_scale is 0.

That scaling stuff is in dire need of better menu exposure,
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript: Status Bar Questions

Post by Nash »

Graf Zahl wrote:It only uses the uiscale if hud_scale is 0.
Ah! That fixed it. Mine was set to -1 for some reason. Also IMO the various UI and HUD scaling combinations are a little confusing.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

Patience. I first need to do the features before doing a proper menu screen for them. It's the typical problem of having to preserve legacy features while fixing the design flaws.

All this code comes from a time when 640x480 was the most popular and 1024x768 the largest screen size and nothing ever got properly adjusted to growing monitor sizes until uiscale was introduced last year - unfortunately it was still an incomplete job, because the entire status bar stuff got skipped (presumably because it was far too messy.)

Don't forget, for me this has turned out to be more like a major cleanup job than scriptification of an existing feature.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US

Re: ZScript: Status Bar Questions

Post by Ed the Bat »

Graf Zahl wrote:forget, for me this has turned out to be more like a major cleanup job than scriptification of an existing feature.
And I'm very happy you've done it. Amazing work, sir!
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript: Status Bar Questions

Post by Major Cooke »

I don't think he's done yet, but yes. Magnificent stuff, Graf. Without you we'd be in a stone age.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

I'm almost through. I think tomorrow I can end this chapter. I got the big things all resolved today.
dpJudas
 
 
Posts: 3134
Joined: Sat May 28, 2016 1:01 pm

Re: ZScript: Status Bar Questions

Post by dpJudas »

Nash wrote:Ah! That fixed it. Mine was set to -1 for some reason. Also IMO the various UI and HUD scaling combinations are a little confusing.
I think part of the problem here is that the scale options are scattered throughout the menus. It would probably be better to have a single scaling menu. It would make it more clear that uiscale is the base scale setting, and the other ones are individual overrides.

The defaults should probably also all be changed so that uiscale is affecting everything unless the user explicitly decided it should not apply to some elements. And last I personally think the 'auto' mode for uiscale should scale more to what most people expect (i.e. a 2x scale at 1080p, 4x scale at 4K), not what Doom technically did at 320x200 (which was more like 4x scale at 1080p).
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49182
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Status Bar Questions

Post by Graf Zahl »

dpJudas wrote:
Nash wrote:Ah! That fixed it. Mine was set to -1 for some reason. Also IMO the various UI and HUD scaling combinations are a little confusing.
I think part of the problem here is that the scale options are scattered throughout the menus. It would probably be better to have a single scaling menu. It would make it more clear that uiscale is the base scale setting, and the other ones are individual overrides.

The defaults should probably also all be changed so that uiscale is affecting everything unless the user explicitly decided it should not apply to some elements. And last I personally think the 'auto' mode for uiscale should scale more to what most people expect (i.e. a 2x scale at 1080p, 4x scale at 4K), not what Doom technically did at 320x200 (which was more like 4x scale at 1080p).
That's already planned, but I first want to take care of the last remaining pieces of the status bar.
The auto mode here definitely needs work, too, and even with uiscale the code is still way too obtuse. But don't worry, now that the messed up scaling for the status bar is fixed, it will be a LOT easier to do this right.

Return to “Scripting”