How To: ZSCRIPT MENUS?

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: How To: ZSCRIPT MENUS?

Postby phantombeta » Sat Sep 16, 2017 8:04 pm

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
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Tue Sep 26, 2017 10:03 am

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
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Thu Oct 12, 2017 8:04 pm

How can I perform word wrapping with strings?
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: How To: ZSCRIPT MENUS?

Postby AFADoomer » Thu Oct 12, 2017 8:16 pm

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 allExpand view
    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
AFADoomer
 
Joined: 15 Jul 2003

Re: How To: ZSCRIPT MENUS?

Postby Nash » Fri Oct 13, 2017 1:14 am

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
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: How To: ZSCRIPT MENUS?

Postby Gutawer » Fri Oct 13, 2017 5:23 am

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
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Oct 16, 2017 9:31 am

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
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: How To: ZSCRIPT MENUS?

Postby Gutawer » Mon Oct 16, 2017 4:59 pm

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
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Oct 16, 2017 5:03 pm

So (DTA_VirtualWidth,640,DTA_VirtualHeight,480) for the parameters?
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: How To: ZSCRIPT MENUS?

Postby Gutawer » Tue Oct 17, 2017 6:11 am

Yes.
User avatar
Gutawer
User Accounts Assistant
 
Joined: 16 Apr 2016
Discord: Gutawer#3431

Previous

Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest