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.

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 8:57 am

Cool tip!

Code: Select allExpand view

    override void Ticker
(void)
    {
        menuactive = Menu.OnNoPause;
    }
 


Put that in your Menu's ticker and the menu won't pause the whole game when it's open. Perfect for your RPG menus and what-not.
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 10:20 am

Code: Select allExpand view
class StatsMenu MyOptionMenu
{
    
KeyBindings mBindings;

    
override bool MenuEvent (int mkeybool fromcontroller)
    {
        
int key mBindings.GetKeysForCommand("openmenu StatsMenu");

        if (
mkey == key)
        {
            
Close();
            return 
true;
        }

        return 
Super.MenuEvent(mkeyfromcontroller);
    }
}
 


QUESTION: How do I retrieve a specifically bound key? I want to make it so that if the user presses the same button that was bound to the command that opened this menu, it will just close the menu.

My code snippet above crashes the game as soon as there's some user input.
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Feb 19, 2017 10:46 am

Try using Destroy() instead of Close().

I have a couple alternatives in mind in case that doesn't work, but try that first.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 10:54 am

Nope, still crashes the game. It doesn't seem to like int key = mBindings.GetKeysForCommand("openmenu StatsMenu");
hence my question, how/if it's possible to even retrieve bounded keys.
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Feb 19, 2017 10:58 am

Do a check and see if mBindings is null -- call Console.Printf if any step of the way it is null.

Code: Select allExpand view
if (mBindings == null)    Console.Printf("Ruh roh!");


Also, GetKeysForCommand returns two ints because two keybinds can be assigned at any time.

Which means you might need to do this:

Code: Select allExpand view
int key1 = 0, key2 = 0;
[key1, key2] = mBindings.GetKeysForCommand(...);


Or something like that, I don't remember the exact schematics for it.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Feb 19, 2017 12:29 pm

Okay, here's a menu demonstrating how to make aesthetic(ally pleasing?) effects occur. Right now this only affects the main menu, but I plan on expanding it to also chain-affect every other menu if possible.

Try opening the different list items. You'll see that New/Load/Save game move the menu off to the right, Options moves it down and Quit moves it up. You can also cancel the in-transit effect with the escape key, and the menu will move right back to the starting position.

Small bonus, the list's text items (I replaced the patches with actual text, bear that in mind) now flash between two colors, set by the Font keyword in Menudef. Reminiscent of the Doomsday engine which I happened to really like.
You do not have the required permissions to view the files attached to this post.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 12:40 pm

I almost solved my previous problem... the responder is now receiving the keyboard input, but I can't seem to make the input event match the keybind...

Code: Select allExpand view
class StatsMenu MyOptionMenu
{
    
KeyBindings mBindings;

    
override bool Responder (InputEventData ev)
    {
        if (
ev.type == InputEventData.GUI_Event)
        {
            if (
ev.subtype == InputEventData.GUI_KeyDown)
            {
                
int ch ev.data1;

                
int key1key2;
                
mBindings bindings;

                [
key1key2] = mBindings.GetKeysForCommand("openmenu StatsMenu");

                
Console.Printf("%d - %d"chkey1); // they're not the same thing!!!

                
if (ch == key1 || ch == key2)
                {
                    
Close();
                    return 
true;
                }
            }
        }
        return 
Super.Responder(ev);
    }
}
 
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Feb 19, 2017 12:51 pm

Can't you just do "closemenu; openmenu StatsMenu", where it only has time to do one but not the other without the wait command?

Also, I wouldn't rely on input data if I were you. That whole system is being changed as we speak, and chances are will break your menu here wide open.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 12:54 pm

That input event code is copy/pasted directly from whatever Graf Zahl wrote from the internal MenuDef. I assume it's safe to use.
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Feb 19, 2017 12:58 pm

It doesn't mean ZZYZX won't change something about it, like the name going from InputEventData to UiEvent. Guess we'll find out when that comes around. :P

My previous question still stands, though.
Last edited by Major Cooke on Sun Feb 19, 2017 1:02 pm, edited 1 time in total.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Graf Zahl » Sun Feb 19, 2017 12:58 pm

The key binder uses raw key codes (what the play code needs), the GUI codes are different. The menu normally uses GUI codes in its event processing. What you are trying to do there cannot possibly work,.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How To: ZSCRIPT MENUS?

Postby Nash » Sun Feb 19, 2017 1:04 pm

Ok, thanks for clarifying. No problem, it's not important. :)
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Nash » Tue Mar 07, 2017 2:44 pm

How do I add a new parameter to a custom widget I inherit from? Let's say I wanted to make a custom version of OptionMenuItem that takes an extra parameter to set the "help/tooltip text" for it.
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Tue Mar 07, 2017 3:40 pm

It's all based on the Init function.

Code: Select allExpand view
OptionMenuItemCreditDisplay Init (Name command, CVar graycheck = null)
{
   Super.Init("Credits", command, graycheck);
   mCredit = CVar.FindCVar("D4DCash");
   return self;
}


Expand the parameters to how you see fit. In my case I actually removed some.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Wed Mar 08, 2017 5:10 pm

Major Cooke, if you have time - can you post a minimal example on how to safely manipulate the player with the recent systems and restrictions.

Perhaps just a simple menu that changes the player's health when you click on a button?

Thanks!
User avatar
Nash
Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: peewee_RotA and 6 guests