Page 3 of 9

Re: ZScript: Status Bar Questions

PostPosted: Tue Mar 28, 2017 2:09 am
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.

Re: ZScript: Status Bar Questions

PostPosted: Tue Mar 28, 2017 4:58 pm
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 Hudmessageonactor. If only one status bar is allowed, the method has to be hardcoded into the mod's only status bar and cannot be modular.

Re: ZScript: Status Bar Questions

PostPosted: Tue Mar 28, 2017 6:19 pm
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.

Re: ZScript: Status Bar Questions

PostPosted: Tue Mar 28, 2017 6:42 pm
by ZZYZX
HudMessages-like statusbar-independent drawing was promised later.

Re: ZScript: Status Bar Questions

PostPosted: Tue Mar 28, 2017 11:03 pm
by Nash
ZZYZX wrote:HudMessages-like statusbar-independent drawing was promised later.


Source?

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 1:17 am
by ZZYZX

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 3:46 am
by Nash
Code: Select allExpand view

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.

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 7:52 am
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,

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 8:06 am
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.

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 8:20 am
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.

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 1:57 pm
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!

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 2:21 pm
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.

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 3:16 pm
by Graf Zahl
I'm almost through. I think tomorrow I can end this chapter. I got the big things all resolved today.

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 3:27 pm
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).

Re: ZScript: Status Bar Questions

PostPosted: Wed Mar 29, 2017 3:35 pm
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.