How To: ZSCRIPT MENUS?

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!)
User avatar
phantombeta
Posts: 2117
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: How To: ZSCRIPT MENUS?

Post by phantombeta »

Does anyone have some kind of example of a simple buy/sell menu?
I'd like to convert my mod's shop system to ZScript, as right now it's a messy ACS script, but I don't really see much info on menus on the wiki...

(Also, please don't tell me to download a huge mod and look at its source code. I'm using my phone's internet connection, and it has an usage cap, so I can't download anything big. Right now I have less than 300 MB left, and if I use all that up it'll stop working completely.)
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

Well D4D has a custom purchase menu, although it's a bit primitive and difficult to understand.

And, sorry, but all I can recommend is you download it. Here's the thread, however the data itself has been split from the resources so at the very least, you can open the code package.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

How can I perform word wrapping with strings?
User avatar
AFADoomer
Posts: 1337
Joined: Tue Jul 15, 2003 4:18 pm

Re: How To: ZSCRIPT MENUS?

Post by AFADoomer »

Use the the Font.BreakLines function.

Something like this (untested - copy/pasted and simplified from working code in Blade of Agony's skill menus - variable names should be self explanatory):

Code: Select all

    double fontheight = SmallFont.GetHeight();

    BrokenLines message = SmallFont.BreakLines(inputstring, desiredmaxwidth);

    int c = message.Count();

    for (int i = 0; i < c; i++)
    {
        screen.DrawText (SmallFont, Font.CR_UNTRANSLATED, x, y, message.StringAt(i));
        y += fontheight;
    } 
This was cobbled together based on some exiting code in messagebox.txt (that's spread across two functions and uses a class level declaration).
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: How To: ZSCRIPT MENUS?

Post by Nash »

What is the second int parameter for BreakLines supposed to be? It's confusing. At first I thought it was maximum amount of characters, but it's not. So pixels (as in real pixels relative to your resolution)? Or scaled (virtual) pixels?
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: How To: ZSCRIPT MENUS?

Post by Gutawer »

Nash wrote:What is the second int parameter for BreakLines supposed to be? It's confusing. At first I thought it was maximum amount of characters, but it's not. So pixels (as in real pixels relative to your resolution)? Or scaled (virtual) pixels?
It's just pixels, no scaling. If the font has 8 pixel wide chars, 64 width would break it at roughly every 8 characters.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

Okay, next question. Say I want to draw text as if I did SetHudSize(640, 480, 1); in ACS. How do I do this?
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: How To: ZSCRIPT MENUS?

Post by Gutawer »

Use DTA_VirtualWidth and DTA_VirtualHeight in the draw calls. I can't remember whether SetHudSize preserves aspect ratio, but if you want that, you can use DTA_KeepRatio.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

So (DTA_VirtualWidth,640,DTA_VirtualHeight,480) for the parameters?
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: How To: ZSCRIPT MENUS?

Post by Gutawer »

Yes.

Return to “Scripting”