Page 4 of 10

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 8:57 am
by Nash
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 10:20 am
by Nash
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 10:46 am
by Major Cooke
Try using Destroy() instead of Close().

I have a couple alternatives in mind in case that doesn't work, but try that first.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 10:54 am
by Nash
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 10:58 am
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:29 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:40 pm
by Nash
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);
    }
}
 

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:51 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:54 pm
by Nash
That input event code is copy/pasted directly from whatever Graf Zahl wrote from the internal MenuDef. I assume it's safe to use.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:58 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 12:58 pm
by Graf Zahl
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,.

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Feb 19, 2017 1:04 pm
by Nash
Ok, thanks for clarifying. No problem, it's not important. :)

Re: How To: ZSCRIPT MENUS?

PostPosted: Tue Mar 07, 2017 2:44 pm
by Nash
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Tue Mar 07, 2017 3:40 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 5:10 pm
by Nash
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!