ZScript: Status Bar Questions

Discuss all aspects of editing for ZDoom.
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.

Re: ZScript: Status Bar Questions

Postby Major Cooke » Mon Apr 10, 2017 10:30 am

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?
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Apr 10, 2017 11:05 am

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
Code: Select allExpand view
   void BeginStatusBar(int resW, int resH, int relTop, bool forceScaled);
   void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false);
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Major Cooke » Mon Apr 10, 2017 12:35 pm

Okay I gave it a shot.

Here's the code to the SBARINFO for comparison's sake:

Code: Select allExpand view
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;
// ...
}


And here's my current translation to zscript.
Code: Select allExpand view

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);
    }


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?
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Apr 10, 2017 12:42 pm

What happens?
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Major Cooke » Mon Apr 10, 2017 12:45 pm

I just realized I put the hud stuff into the fullscreen stuff by mistake, whoops. That'll do it.
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Major Cooke » Thu Apr 20, 2017 1:42 pm

So one thing I don't quite get is the coordinate system between status bar and full screen.

Code: Select allExpand view
if (state == HUD_StatusBar)
{
   BeginStatusBar(true);
   DrawMainBar (TicFrac);
}
else if (state == HUD_Fullscreen)
{
   BeginHUD(1.0, true);
   DrawFullScreenStuff();
}


It's so much different than the other...
Por que?
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Thu Apr 20, 2017 3:54 pm

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Major Cooke » Fri Apr 21, 2017 6:56 am

Graf Zahl wrote:removed alpha parameter from BaseStatusBar.DrawBar because this cannot be used with this function.


Why is that?
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Fri Apr 21, 2017 7:25 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Major Cooke » Fri Apr 21, 2017 7:26 am

I take it that's planned? It would be highly appreciated.
User avatar
Major Cooke
Busiest college semester yet. On temporary hiatus.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Gutawer » Sat Apr 22, 2017 12:15 pm

Code: Select allExpand view
SetClipRect(0, 1080 - 128, 64, 64);
DrawImage("STARTAN2", (0, 1080), DI_ITEM_LEFT_BOTTOM);

Why isn't this clipping the texture vertically? It halves the texture horizontally as expected, but doesn't half it vertically, leaving a 64*128 texture on the screen when it should be 64*64. I tried messing around with the SetClipRect flags, but I couldn't get anything to work, would appreciate some help here.
User avatar
Gutawer
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: ZScript: Status Bar Questions

Postby Nash » Sat Apr 22, 2017 9:21 pm

A bug maybe?
User avatar
Nash
Nash Muhandes [Audio Engineer | Game Designer | Scripting]
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: ZScript: Status Bar Questions

Postby AFADoomer » Sat Apr 22, 2017 9:26 pm

Major Cooke wrote:I take it that's planned? It would be highly appreciated.


This works... Also allows bars to be scaled...
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 allExpand view
    //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.*= scale;
        texsize.*= 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.- border*: texsize.- 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.+ Clip[0], position.+ Clip[1], texsize.- Clip[0] - Clip[2], texsize.- 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.+ Clip[0], position.+ Clip[1], texsize.- Clip[0] - Clip[2], texsize.- 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);
    }
User avatar
AFADoomer
 
Joined: 15 Jul 2003

Re: ZScript: Status Bar Questions

Postby Gutawer » Sun Apr 23, 2017 4:58 am

Nash wrote:A bug maybe?

Probably, I guess. Since I haven't got any other responses here I suppose I'll go report it.
User avatar
Gutawer
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Sun Apr 23, 2017 5:23 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

PreviousNext

Return to Editing

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Yandex [Bot] and 2 guests