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.

Re: ZScript: Status Bar Questions

Postby Major Cooke » Sun Mar 26, 2017 11:17 pm

Actually I meant "only the menus will draw at capped framerates". :P

And naturally it is harmless. Especially since we have to pick apart the stuff ourselves...
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Mar 27, 2017 1:54 am

Sometimes reading the already existing source may give good clues:

Code: Select allExpand view
   override void Draw (int state, double TicFrac)


See the TicFrac? ;)
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Mar 27, 2017 2:01 am

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.


1) MAPINFO's gameinfo section - check the repo.
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.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript: Status Bar Questions

Postby Xaser » Mon Mar 27, 2017 8:54 am

Well, this is progressing much quicker than expected. :D

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()?" :P

[also hey, a 'protected' keyword! :]
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Mar 27, 2017 11:12 am

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

Re: ZScript: Status Bar Questions

Postby Nash » Mon Mar 27, 2017 11:15 am

Image

First!!! :mrgreen: 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
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript: Status Bar Questions

Postby Graf Zahl » Mon Mar 27, 2017 11:34 am

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

Re: ZScript: Status Bar Questions

Postby Nash » Mon Mar 27, 2017 11:41 am

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.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript: Status Bar Questions

Postby Major Cooke » Mon Mar 27, 2017 2:16 pm

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.


If it's of any comfort, I'm holding off until it's actually done this time. I learned my lesson previously. :P
(Plus I need to work on documenting menus...)
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: ZScript: Status Bar Questions

Postby ZZYZX » Mon Mar 27, 2017 5:55 pm

Nash wrote:Image

First!!! :mrgreen: 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

DTA_Clip...something.
Use this viewtopic.php?p=986562#p986562
It does clipping automatically.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine

Re: ZScript: Status Bar Questions

Postby Nash » Mon Mar 27, 2017 6:57 pm

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...
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: ZScript: Status Bar Questions

Postby ZZYZX » Mon Mar 27, 2017 8:09 pm

It should work.
Also, basically:
Code: Select allExpand view
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
  }
}


In your status bar, call
Code: Select allExpand view
SpecialSbar sbd = new('SpecialSbar').Init();
Then 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.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine

Re: ZScript: Status Bar Questions

Postby Blue Shadow » Tue Mar 28, 2017 1:25 am

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:

Code: Select allExpand view
Can't call play function DrawFullScreenStuffCustom from ui context

Code: Select allExpand view
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.+= size.+ 2;
                roww = max(roww, size.X);
                if (++rowc == 3)
                {
                    keypos.= 2;
                    keypos.-= roww + 2;
                    roww = 0;
                    rowc = 0;
                }
            }
        }
        if (CPlayer.inventorytics != 0 && !level.NoInventoryBar)
        {
            DrawInventoryBar(diparms, (0, 0), 7, DI_SCREEN_CENTER_BOTTOM, HX_SHADOW);
        }
    }
}


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().

sbar_testing.pk3
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: ZScript: Status Bar Questions

Postby ZZYZX » Tue Mar 28, 2017 1:51 am

...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).
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine

Re: ZScript: Status Bar Questions

Postby Blue Shadow » Tue Mar 28, 2017 2:04 am

ZZYZX wrote:Anyway, this particular issue can be fixed by explicitly marking your draw function as ui (e.g. protected ui void DrawFullScreenStuffCustom).

With that done, I get this:

Code: Select allExpand view
Script error, "sbar_testing.pk3:zscript.txt" line 20:
Unexpected identifier
Expecting ';' or ','
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests