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
Major Cooke
Posts: 8175
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 »

No worries.

That's just it though. Prevention from important things being overridden I suppose. That part I don't know fully.
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: How To: ZSCRIPT MENUS?

Post by AFADoomer »

I edited after you posted... Maybe Graf can weigh in, then? I may do a feature request...
User avatar
Major Cooke
Posts: 8175
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 »

No point. Graf will probably close it because either he cannot, or will not. For example, a will-not is the player menu: he kept all those functions internal to prevent abuse. A cannot: like the color picker menu, if it has a class, are just too complex so you cannot replace those either because it'll fuck things up. Your better off just replacing it on your own side and tell players "DONT use the internal menu!".
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: How To: ZSCRIPT MENUS?

Post by Nash »

AFADoomer wrote:Ah.

Damnit, you're right. Sorry.

So what is the difference between me adding a new Class there and replacing the old class for PlayerMenu with a class that inherits from PlayerMenu? Besides "the engine won't let you"? Shouldn't the inherited class have all of the same underlying code as the parent class? Is this actually something that should not be done, or a holdover from the old system where everything was in compiled code?
I have had to specifically request which class of menus to be overridable inside MenuDef in the past (for example, the generic MessageBox was hardcoded until I requested it and it got approved)... so I think the best bet is, if you want a particular class to be moddable, you'll have to request it.
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: How To: ZSCRIPT MENUS?

Post by AFADoomer »

Yeah, this was all good. I was mis-reading and mis-remembering code.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49066
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by Graf Zahl »

AFADoomer wrote:I edited after you posted... Maybe Graf can weigh in, then? I may do a feature request...
Please do. I do not feel like reading trough 2 pages of discussion to get to the bottom of it.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: How To: ZSCRIPT MENUS?

Post by Nash »

Can someone explain to me menu descriptors like I'm a 5 year old?

Despite being able to work with menus and produce somewhat usable widgets, I can't honestly say I truly understand the descriptor concept.
XxMiltenXx
Posts: 219
Joined: Wed Jan 08, 2014 8:40 am
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by XxMiltenXx »

Hey, I need some help.

I want to alter the look of a menu, but only a certain entry (or value).
From what I understand, the common way that menu items are drawn is like this:
Textures

Code: Select all

screen.DrawTexture (mTexture, true, x, mYpos, DTA_Clean, true);
Texts

Code: Select all

screen.DrawText(mFont, mColor, x, mYpos, text, DTA_Clean, true);
So, the whole menu uses the DTA_Clean tag. I simply want to change this tag to the DTA_320x200 tag, so that all menus use it. Is this easily possible, and if yes, how?
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: How To: ZSCRIPT MENUS?

Post by Nash »

No, there's no easy way to do it. You'll have to rewrite almost every menu just to change its drawing API to suit your needs. Or copy/paste all of the stock menus. And run the risk of having outdated menu code if there are engine menu fixes upstream.
XxMiltenXx
Posts: 219
Joined: Wed Jan 08, 2014 8:40 am
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by XxMiltenXx »

Hmm ... tried that, failed miserably :D. Jk, but it kinda seems complicated for such a simple change...

Another question about the menus though: Where are the names for the menu items stored?

e.g. MENUDEF entry:

Code: Select all

	TextItem "Set it up!","o", "OptionsMenu"
In this case the OptionsMenu will be visually shown ingame as "Set it up!". Is that string accessible via a menu class in ZScript so I can use it? And if so, how?
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: How To: ZSCRIPT MENUS?

Post by AFADoomer »

Each menu item is referenced in the menu descriptor's mItems array. You have to access the correct entry of that array, cast the item as the right type of control (ListMenuItemTextItem), and retrieve the mText value.

So something like this running in your list menu class's Init code should print the list menu text item values to the console every time the menu is opened:

Code: Select all

		for (int i = 0; i < mDesc.mItems.Size(); i++)
		{
			if (mDesc.mItems[i] is "ListMenuItemTextItem")
			{
				console.printf("%s",  ListMenuItemTextItem(mDesc.mItems[i]).mText);
			}
		}
If you want to select a specific item, you can experiment with the GetItem function - GetItem('OptionsMenu') should return the list item you use in your example (See the player menu for an example of this in action).



@Nash -
Nash wrote:Can someone explain to me menu descriptors like I'm a 5 year old?

Despite being able to work with menus and produce somewhat usable widgets, I can't honestly say I truly understand the descriptor concept.
I will try... Apologies if this is either too basic or not enough.

Essentially, the menu descriptors are used to store specific information used by the overall menu - selector graphic and offsets, base drawing position, etc. Most importantly, it includes an array of all of the menu items that are part of the menu, as defined in either MENUDEF or internally generated code. So, this is how the engine keeps track of what items are supposed to be on a particular menu, and the particulars of how that menu is drawn.
XxMiltenXx
Posts: 219
Joined: Wed Jan 08, 2014 8:40 am
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by XxMiltenXx »

AFADoomer wrote:Each menu item is referenced in the menu descriptor's mItems array. You have to access the correct entry of that array, cast the item as the right type of control (ListMenuItemTextItem), and retrieve the mText value.

So something like this running in your list menu class's Init code should print the list menu text item values to the console every time the menu is opened:

Code: Select all

		for (int i = 0; i < mDesc.mItems.Size(); i++)
		{
			if (mDesc.mItems[i] is "ListMenuItemTextItem")
			{
				console.printf("%s",  ListMenuItemTextItem(mDesc.mItems[i]).mText);
			}
		}
If you want to select a specific item, you can experiment with the GetItem function - GetItem('OptionsMenu') should return the list item you use in your example (See the player menu for an example of this in action).
Thanks, this is the information I needed :)
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

Re: How To: ZSCRIPT MENUS?

Post by Sarah »

Spoiler: Original Post
Update - Solved. I assumed this was going to require ZScript but a quick look at the MENUDEF documentation on the wiki showed that my needs are simpler. Z-Windows now has it's own options menu within Options!
GiveOneMoreChance
Posts: 19
Joined: Thu Aug 10, 2017 8:09 pm

Re: How To: ZSCRIPT MENUS?

Post by GiveOneMoreChance »

Hello, can anybody explain how to make scroll bars and possible convert int to string?
ZzZombo
Posts: 315
Joined: Mon Jul 16, 2012 2:02 am

Re: How To: ZSCRIPT MENUS?

Post by ZzZombo »

Do I understand it right you can use this outside of main menu enhancements? Like to do "Do you really want to buy <item> for <price>?" during gameplay. If yes, how?
Locked

Return to “Scripting”