[ZS] Status bar code in or referred to by a weapon class?

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!)
Post Reply
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

[ZS] Status bar code in or referred to by a weapon class?

Post by Matt »

Here's what I want to do:

1. have a custom status bar/HUD.
2. have a base custom weapon.
3. have the custom status bar check which particular child class of that base custom weapon the player has.
4. upon finding that particular child weapon class, execute a piece of HUD (i.e., ui-scope) code specific to that class.
5. make this flexible so that anyone can create a new weapon class based on this base custom class and include their own status bar code.

I'm currently able to accomplish 1-4 using a long if/else that goes through every possible weapon, but there's no way for this to be expanded in a secondary mod without overwriting the entire custom status bar (with the additional mapinfo, etc. that ends up requiring).

Ideally I'd want to be able to do something like:

Code: Select all

let xxx=mycustomweapon(consoleplayer.readyweapon);
if(xxx) xxx.showhudstuff(self,consoleplayer.mo);
(in contrast to this cumbersome-looking thing) but that can't be done since weapon is play scope and there's no way to specify ui scope for just that one function.

Is there any way to set this up? Is there some kind of ui-scope "thinker"-like sort of deal that I'm supposed to be spawning or something?
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZS] Status bar code in or referred to by a weapon class

Post by phantombeta »

Maybe a virtual function like this?

Code: Select all

    virtual ui void DrawHUDStuff (BaseStatusBar sbar) { }
Then, the user could simply draw to the statusbar like this:

Code: Select all

    override void DrawHUDStuff (BaseStatusBar sbar) {
        let fnt = HUDFont.Create ("BigFont");
        sbar.DrawString (fnt, "BUTTS", (0, 0), BaseStatusBar.DI_SCREEN_CENTER | BaseStatusBar.DI_ITEM_CENTER);
    }
You'd call the function in the statusbar code like this:

Code: Select all

        weap.DrawHUDStuff (self);
I haven't done any in-depth tests, but from a simple test with that code, it seems to work pretty nicely.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: [ZS] Status bar code in or referred to by a weapon class

Post by Matt »

So that's where the "ui" is supposed to go, thanks!

Will give this a try.
Post Reply

Return to “Scripting”