ZScript: Status Bar Questions

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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 Apr 23, 2017 8:58 am

AFADoomer, I might suggest doing it a bit differently. At any point, Graf could alter the function if he needs to fix a bug or something. If said changes doesn't affect parameter count, you won't have to change anything. (Yes I know you used DrawBar, and I used DrawString. Concept is the same because it affects both equally.)

Code: Select allExpand view
// Uniform scaling.
void DrawStringScaled(HUDFont fontString stringVector2 posint flags 0int translation Font.CR_UNTRANSLATEDdouble Alpha 1.int wrapwidth = -1int linespacing 4double scaling 1.0)
{
    
Vector2 OldScale BaseSizeTempScale BaseSize;
    
Vector2 ScaledPos pos;
    
    if (
scaling == 0.0//Why draw anything? Also to prevent division by 0.
        
return;
    
    
scaling abs(scaling);
    
    
// Thankfully, scaling up is directly that -- smaller screen coordinates and 
    // larger texture size which is automatically handled by the engine.
    
bool sized = (scaling != 1.0);
    if (
sized)
    {
        
TempScale /= scaling;
        
ScaledPos /= scaling;
    }
    
    
// Change to the new scale, draw it, and then set it back.
    
if (sizedSetSize(0TempScale.XTempScale.Y);
    
DrawString(fontstringScaledPosflagstranslationAlphawrapwidthlinespacing);
    if (
sizedSetSize(0OldScale.XOldScale.Y);
    


This works for status bar sections, but I have yet to fully try it out on full screen huds which has a different coordinate system.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Xaser » Wed May 10, 2017 9:52 pm

Bit of a bump, but this seems like the right thread for it.

Would someone mind giving a quick explanation of what all the DI_ flags do? I'm trying to translate an old ACS HUD to ZScript but I'm having trouble figuring out how to get the offsets to translate correctly.


[EDIT] Maybe if it helps to ask a more specific series of questions: I'm effectively trying to place a 640x480 virtual screen at the bottom-center of the HUD, then draw some images to it. Bonus points if I can also set it up (for translation's sake) such that:
  • (0, 0) is the top-left of the virtual screen
  • Image coordinates correspond to the top-left corner of the image.

[DOUBLE-EDIT] Well, I've discovered "drawOffset" and figured out how to achieve my own use case, though some of the deeper bits are still a bit of a mystery.

[YET-ANOTHER-EDIT] Is it possible to make DrawString respect line breaks?

[HOLY-EDIT-STREAK-BATMAN] Whew, I'm on a roll on answering my own questions. Looks like DrawString needs some sort of value greater than zero in the "wrapwidth" field or else wrapping won't work (since V_BreakLines never gets called). Seems weird -- wince the default for this parameter is -1, would it be reasonable to suggest a value of 0 to mean "respect line breaks, but don't use a wrap width"? From a quick glance, it looks like V_BreakLines may need a tweak to support zero, though.
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript: Status Bar Questions

Postby Gutawer » Thu May 11, 2017 2:46 am

I only really know about the offset flags, but I believe I can explain those pretty well, so here goes:

The DI_ITEM_ flags control where the drawing position of the image is. So, for example, DI_ITEM_LEFT_TOP means that the specified position should be treated as the top left of the image, meaning that it will be drawn diagonally down-right. DI_ITEM_CENTER, then, would mean to treat the position as the centre of the image, meaning that it gets drawn from the centre outwards. I hope that that makes sense.

The DI_SCREEN_ flags only work with a full screen HUD, and control which corner the image is drawn from, since fullscreen huds use corner offsets for drawing. So, for example, DI_SCREEN_LEFT_BOTTOM would mean to start drawing from the coordinate (0, screen size y), with a position of (8, -8) meaning to start drawing 8 pixels away from the bottom left corner. DI_SCREEN_RIGHT_BOTTOM would mean to start drawing from coordinate (screen size x, screen size y), and position (-8, -8) would mean to start drawing 8 pixels away from the bottom right corner. You can combine the two types of flags, but remember - DI_SCREEN_ is for fullscreen HUDs only.

There's also DI_TEXT_ALIGN_, but those are pretty self explanatory.

About the other DI_ flags, I have no idea how those work, so I can't explain those, but I hope this helps at least a bit, heh.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: ZScript: Status Bar Questions

Postby Xaser » Thu May 11, 2017 9:13 am

Thanks there! I kinda vaguely had an idea of the DI_ITEM_* options, but wasn't mentally making the leap on DI_SCREEN since I'm used to the default SBARINFO story of "negative means start from bottom/right" -- which I suppose is implied by "DI_SCREEN_AUTO" (the default).
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript: Status Bar Questions

Postby Major Cooke » Fri May 12, 2017 8:54 pm

Thankfully this isn't rocket science like menus are. :P It's otherwise quite similar to sbarinfo but you can do a lot better and cleaner code with it. Even fancy effects like render style and alpha setting if you want, or colors, etc.

If you're really feeling adventurous, or outright insane, you could put the weapon drawing in there too. Not recommended though.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Blue Shadow » Sun May 28, 2017 12:50 pm

Is there a way I can draw the slot number of the weapon currently being equipped? I tried LocateWeapon(), but I ran into a scope issue (I think) when calling it. This is how I used it:

Code: Select allExpand view
bool nch_weaponfound;
int nch_weaponslot;

[
nch_weaponfound, nch_weaponslot] = CPlayer.weapons.LocateWeapon(CPlayer.ReadyWeapon.GetClass()); 

The error says:

Code: Select allExpand view
Readonly struct on left hand side of LocateWeapon not allowed
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010

Re: ZScript: Status Bar Questions

Postby Major Cooke » Sun May 28, 2017 2:00 pm

Status bars are UI only, and 'weapons' is defined within the player which is PLAY scoped. What you can try to do though is invoke a WeaponSlots struct within the status bars like this:

Code: Select allExpand view
WeaponSlots w;
int i1, i2;
bool weaponFound;

Class<Weapon> wep = CPlayer.ReadyWeapon.GetClass();
if (wep)
{
     [weaponFound, i1, i2] = w.LocateWeapon(wep);
}


Note, this is untested. Chances are it may not work, in which case the only other option is to inject an inventory item into the player that automatically changes its own amount with DoEffect()'s override (performing the LocateWeapon function as needed), grab the amount and go from there. That can be given on WorldSpawned event.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Blue Shadow » Sun May 28, 2017 2:52 pm

weapons is part of the PlayerInfo struct, the same struct ReadyWeapon is part of. Yet, ReadyWeapon can be used in a ui scope without problems (I know ReadyWeapon is not a struct).

As for the solution, I had already tried something like that, and the engine crashed with a "tried to access address 00000..." error or something (I can't really remember the details).

Major Cooke wrote:Note, this is untested. Chances are it may not work, in which case the only other option is to inject an inventory item into the player that automatically changes its own amount with DoEffect()'s override (performing the LocateWeapon function as needed), grab the amount and go from there. That can be given on WorldSpawned event.

I thought we are past the inventory hacks... If this is the only solution, then I might as well stick with the ACS-SBARINFO-DECORATE combo. :?
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010

Re: ZScript: Status Bar Questions

Postby Major Cooke » Sun May 28, 2017 3:03 pm

Blue Shadow wrote:I thought we are past the inventory hacks... If this is the only solution, then I might as well stick with the ACS-SBARINFO-DECORATE combo. :?


Terrible idea IMO. Face it, there will be hacks even with zscript. Shit happens, but at least ZScript helps minimize the need. You can't do anything about it unless you ask for a feature suggestion (provided Graf doesn't [No] it). This is just... LESS of a hack, by far. And it's a lot less likely to interfere with other mods if you seek compatibility.

Funny thing is, DamNums uses an inventory hack. Still works perfectly good.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby Xaser » Sun May 28, 2017 5:49 pm

@Blue Shadow: This looks like an oversight worth bugreporting. ZDoom normally blocks methods from being called on structs that are read-only (which CPlayer.weapons is when you're in the UI context), unless they're marked 'const'. Looks to me that "LocateWeapon" is safe to mark as 'const', but it isn't in gzdoom.pk3 (yet).

I really ought to get a development environment set up on this machine again. It's probably easier to patch, test, and PR this than it is to write about it. :P
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

Re: ZScript: Status Bar Questions

Postby Major Cooke » Mon Jun 12, 2017 4:27 pm

So I'm having some difficulty with status bars and I believe these were present since the beginning, though I never noticed because I never played on those resolutions. 1600x900 is my default.

Here's my sbar code which is more or less a straight port from sbarinfo to zscript itself.

Does anyone see me doing anything wrong here and why the huds stick out over the edges? I'm trying to figure this out without resorting to enabling full screen offsets, I even tried enabling force scale by adding DI_FORCESCALE to the imageAlignment variable. Nope.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript: Status Bar Questions

Postby cotton_disciple » Wed Jul 26, 2017 6:55 pm

Does anyone know how to use DrawPowerups? I can't see anything...
User avatar
cotton_disciple
 
Joined: 03 Jul 2015
Location: Russian Federation
Discord: cotton_disciple#2940

Re: ZScript: Status Bar Questions

Postby wildweasel » Wed Aug 09, 2017 7:02 pm

Okay, so, I'm currently in the process of learning ZScript to replace the increasingly-complicated HUD in ww-cola3 with something more sane, primarily to have a nicer way of doing stuff like this through a simple 4-line function instead of 30-some InInventory checks. What I'm presently trying to figure out, though: is there a way to make a ZScript HUD completely ignore the "Stretch HUD to aspect ratio" option? I'm planning to make this work like SBARINFO's FullscreenOffsets, and all of my HUD graphics are designed for an uncorrected aspect ratio, not the 1.2:1-corrected Doom aspect.

[edit] Actually, I have another, much larger question. Since I already have the one function I needed to make in ZScript for this HUD, I'm looking to do some porting of the existing SBARINFO to ZScript. As an absolute noob to ZScript in general, what are some tips you could give to make this a smoother process going into ZScript? Here is the existing SBARINFO for reference:
Spoiler:
User avatar
wildweasel
I love the smell of sourdough in the morning
Moderator Team Lead
 
Joined: 15 Jul 2003
Location: avatar by kurashiki

Re: ZScript: Status Bar Questions

Postby Matt » Fri Aug 11, 2017 9:42 pm

I found it easier to just recreate everything from scratch without any consideration for preserving the original aesthetic (though keeping most elements generally in more or less the same place), but I was already working with ZScript for a few months by then and was already a lot more comfortable with writing ZScript than even reading SBARINFO.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ZScript: Status Bar Questions

Postby wildweasel » Fri Aug 11, 2017 10:52 pm

Vaecrius wrote:I found it easier to just recreate everything from scratch without any consideration for preserving the original aesthetic (though keeping most elements generally in more or less the same place), but I was already working with ZScript for a few months by then and was already a lot more comfortable with writing ZScript than even reading SBARINFO.

Placement is essentially a non-issue, since it's fairly easy to guess which numbers are the on-screen coordinates. It's functionality that I'm having problems with. Key indicators, the inventory box, bars, that sort of thing. I have no idea how to do any of those things in ZScript right now.
User avatar
wildweasel
I love the smell of sourdough in the morning
Moderator Team Lead
 
Joined: 15 Jul 2003
Location: avatar by kurashiki

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest