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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47994
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to do things with the new menu functions?

Post by Graf Zahl »

Nash wrote:Graf - what are the key differences between ListMenu and OptionMenu and more importantly, which should I pick for a particular situation, if I want to make a completely new menu?
The main difference is how they work. The list menus are for widgets that have special design, like the main menu's patches and it allows positioning of each widget. Such a menu cannot scroll due to the explicit positioning

The option menus are pure text and the menu controls the entire layout. You only can use one font per menu and if the menu gets to large it automativally scrolls.

Obviously both need quite different widgets.
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to do things with the new menu functions?

Post by Major Cooke »

Code: Select all

Class ListMenuScroller : ListMenu
{
	double sineWave;
	Array<Double> px;
	bool saved;
	
	override void Ticker()
	{	
		if (px.Size() <= 0)
			px.Reserve(mDesc.mItems.Size());
		
		sineWave = (sineWave + (360.0 / 35.0)) % 360.0;
		
		for(int i=0; i < mDesc.mItems.Size(); i++)
		{
			if (!saved)
			{
				px[i] = mDesc.mItems[i].GetX();
			}
			mDesc.mItems[i].SetX(px[i] + sin(sineWave) * 5);
		}
		saved = true;
		Super.Ticker();
	}
}
And here's a menu that shifts itself left and right with a sine wave. The only problem is, they're ints... so it looks jagged when slowing down or speeding up.

But the main point here is how to offset the ENTIRE menu.

Take note, there is no SetY, only OffsetPositionY.
Accensus
Posts: 2352
Joined: Thu Feb 11, 2016 9:59 am

Re: How to do things with the new menu functions?

Post by Accensus »

Will ZMENUDEF allow for making proper weapon/upgrade/whatever buy menus, effectively replacing the ACS HudMessage hacks? If no, will we ever see a menu handling system that does this without hacks?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47994
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to do things with the new menu functions?

Post by Graf Zahl »

The menu system is fully programmable, so it's up to you to implement what you need. A generic advice cannot be given, because each mod is different.
Accensus
Posts: 2352
Joined: Thu Feb 11, 2016 9:59 am

Re: How to do things with the new menu functions?

Post by Accensus »

I see. Thanks for the quick reply, Graf. Definitely good to hear that I can now do a menu without having to cause a HudMessage mess. Gonna wait on the documentation before I start, though.
Accensus
Posts: 2352
Joined: Thu Feb 11, 2016 9:59 am

Re: How to do things with the new menu functions?

Post by Accensus »

Another question. Can I check for an item's quantity in real-time while in the menu? For example, the menu shows I have 1000 gold and then I buy something for 300. Is it possible for the value to update to reflect the remaning 700 gold or will I have to reopen the menu?
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to do things with the new menu functions?

Post by Major Cooke »

Yes. See Nash's example a page or two back.

Unfortunately, documenting the menu system is going to be a lot harder than other ZScript things, mainly because of all the possibilities -- not to mention I'm still trying to get the hang of it.
Accensus
Posts: 2352
Joined: Thu Feb 11, 2016 9:59 am

Re: How To: ZSCRIPT MENUS?

Post by Accensus »

Take your time, Cooke. Thanks for pointing me to the DL. Will definitely take the example apart and learn how to do a proper menu. Big thanks go to you too, Graf, for making this possible.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47994
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How to do things with the new menu functions?

Post by Graf Zahl »

Major Cooke wrote:Yes. See Nash's example a page or two back.

Unfortunately, documenting the menu system is going to be a lot harder than other ZScript things, mainly because of all the possibilities -- not to mention I'm still trying to get the hang of it.

Careful. Once safeguards are in place this won't be directly doable anymore. The inventory change action needs to be routed through the network protocol and that part hasn't been done yet.
If game state gets altered directly from the menu it won't be recorded in demos or transmitted in multiplayer games.

Right now you are seriously at risk to create stuff that won't work in an official release. Right now I cannot say how this will work precisely so please don't ask.
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

Okay, that settles it. I'm not doing a damn drop of documentation until it's guaranteed that it's all said and done. Thank you for the warning.

I'll hold off with D4D's menu changes except for implementing static text that just displays credits vs cost using the same cvar system. I was relying on this method:

Code: Select all

NumberField "Cost", Cost_U1Pistol, 0, 500000000, 	0.00000000000000000000000001
NumberField "Cash", D4DCash, -10, 500000000, 		0.00000000000000000000000001


...with a stupidly high decimal count adjuster to prevent price changing (as it would take like a year of holding one key direction). I knew it wouldn't hold forever, but it was the only way to display cost and credit the player had. At least I can start there.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47994
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by Graf Zahl »

You can change CVARs all you like. The problem is direct manipulation of game state.
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

Yeah. I was actually trying to prevent the numberfields from being adjustable with that huge decimal number, but that trick no longer appears to work.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47994
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: How To: ZSCRIPT MENUS?

Post by Graf Zahl »

I think the easier way is to subclass them and kill the input that change the values there.
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How to do things with the new menu functions?

Post by Major Cooke »

Yeah, was thinking the same thing too but with fancier text.
Also, an idea just hit me about what you said earlier...
Graf Zahl wrote:Right now I cannot say how this will work precisely.
You could go a similar route as DIALOGUE, since that will basically require allowing checking of actors somehow. Unless that's not multiplayer friendly?
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: How To: ZSCRIPT MENUS?

Post by Major Cooke »

Is there any way to, when calling Menu.SetMenu, transfer all strings and/or graphics used in a previous menu for the sake of 'making them go out'? They would just be purely decorative such as fading between menus.

Return to “Scripting”