Log in to reply
 

[Release/WIP] In-game Pause Menu Helper API



  • Since I have been using the pause menu as a way to interface settings in some of my recent mods, I figured it made sense to create a more portable solution that would make it easy for other mod creators to do the same. Hence, I created this little API which allows you to add your own custom settings panes to the pause menu (among other things).

    https://github.com/CamxxCore/PauseMenuHelper

    How to use it (for mod creators):

    First decide which area of the pause menu you want to extend and create an instance of the PauseMenu class with the relevant MenuType. In this example I will extend the settings area of the pause menu:

    _menu = new PauseMenu(MenuType.Settings);
    

    To create a sub menu, use the parameter-less constructor for PauseMenu:

    _subMenu = new PauseMenu();
    

    Adding new items to the menu is simple as

    var subItem = _subMenu.AddItem("My Toggle", MenuSettingType.Toggle);
    

    to handle the event when the setting is changed, you can subscribe to the items "ValueChanged" event:

    subItem.ValueChanged += MenuItem_ValueChanged
    

    and the corresponding method to handle the event would look like..

        private void MenuItem_ValueChanged(int menuId, int itemIndex, int value)
            {
                if (menuId == (int)menu.MenuID)
                {
                    var item = menu.ItemAt(itemIndex);
    
                    UI.ShowSubtitle(string.Format("MenuValueChanged: setting {0} to {1}", item.Text, value));
    
                }
            }
    

    You must be sure to explicity check the menuId so you don't end up handling events from other menus.

    When you are finished adding items to your menu, you will need to link it to an item on the parent menu you expanded. You can do this using an overloaded version of the "AddItem" function:

    _menu.AddItem("My Custom Menu", MenuItemType.Default, 0, _subMenu.MenuID);
    

    Also important: you need to call Dispose() on your menus when you are finished with them, so they get cleaned up and removed from the interface.. Generally it makes sense to do this in the dispose method of the parent script:

       protected override void Dispose(bool A_0)
            {
                _menu.Dispose();
                _subMenu.Dispose();
                base.Dispose(A_0);
            }
    

    And just like that you can interface mod settings through the native menu. Hope this is useful to somebody :P



  • @CamxxCore nice work



  • @Frazzlee thanks (:



  • this very useful , thank you for making this :)



  • Hi @CamxxCore , great work! I was just messing around with it and it's a lot of fun. It's pretty late where I am so I don't have time to explore it extensively, but is there a MenuSettingType that allows the user to type in a string? Also, what is a subtype (when using AddItem)?



  • @CamxxCore This is perfect!



  • @stillhere Hey (: Nothing like that no.. Unless there is a vanilla option that allows it (You can probably hijack it). But something that might be possible is if I allow scripts to run on the menu.. then you could just use native functions to open your own input box.

    And the subtype is the same thing as MenuSettingType, just relevant to all MenuItemTypes (besides settings). (MenuSettingType is only relevant if MenuItemType is a setting)



  • @CamxxCore Function.Call(Hash.SET_THIS_SCRIPT_CAN_BE_PAUSED, 0);



  • @stillhere Also, there are many setting types that are unaccounted for. I just added the first 8 or so. There are potentially many more useful ones..



  • @jedijosh920 That seems like it should work but I could never get it to :(



  • @CamxxCore Make a separate thread using Windows.Forms.Timer (this is a mediocre idea but it works), and when Game.IsPaused returns true, create a static event so that other scripts can listen to it, like GamePauseDetector.Paused += OnGamePaused; or GamePausedDetector.RunCodeWhilePaused(() => { // some code });



  • @sollaholla Awesome :D thank you! Better solution than having to patch the exe.


  • TRANSLATOR

    Damn, this looks awesome. Can be perfect as a NativeUI/in-game menus alternative, for configuring scripts matter. And makes more sense to have these kind of settings on the game pause>settings menu :D





  • @jedijosh920 Yeah no good. Can you show me your code?



  • @jedijosh920 And are you building the source or using the release version?



  • @CamxxCore Using the release version dll as reference and I sent you the code via PM.



  • @CamxxCore oh that makes sense, thank you!

    Edit: I seem to be having the same issue as Josh: changing any setting will crash my game, even if I'm changing a setting in a different mod that uses the API (ex: your extended camera mod). Then as soon as I comment out the pausemenu code from my own mod and rebuild it, I can use the extended camera settings without crashing the game. So needless to say, it's an issue with my own code; would you mind posting a very simple example script? I would greatly appreciate it!

    Edit 2: Trying to change the InVehicle Minimum pitch value also crashed my game, without having my script, so it seems it is a problem with my game, I suppose :open_mouth:

    Edit 3: Seems the culprit was ScriptManager.dll and PauseMenu.dll; after removing them, I had no issues with Extended Camera Settings at all!



  • @CamxxCore I love it! <3 Will you publish it at gta5-mods.com/tools when you squished the bugs or should I better fork the project in order to keep updated?



  • @stillhere Sorry I didn't see your message. I ended up figuring out the problem.

    Basically I wasn't doing enough null checks when checking the menu ID in the value changed event.

    It looked something like this:

            void MenuItem_ValueChanged(int menuId, int itemIndex, int value)
            {
                if (menuId == (int)menu1.MenuID)
                {
                    // handle script manager menu...
                }
    
                else if (menuId == (int)menu2.MenuID)
                {
                }
            }
    

    Problem was the second menu was always null (unused). And the second statement wouldn't be checked unless another menu existed (such as in your script) so I didn't notice it.

    But yeah.. lesson learned. Kind of seems like a textbook case as far as programming issues go..



  • @Cyron43 I'm not sure if I will release it there since it just means more work every time I want to update it :P I will try to keep updates versions on the github releases page though.



  • @CamxxCore said in [Release/WIP] In-game Pause Menu Helper API:

    @Cyron43 I'm not sure if I will release it there since it just means more work every time I want to update it :P I will try to keep updates versions on the github releases page though.

    Understandable. I know the woes. :slight_smile:
    So I am going to fork your repo. Thanks. :slight_smile:



  • @CamxxCore Oh no problem. Thank you for the explanation!



  • @CamxxCore IIRC doesn't NativeUI also have a PauseMenu API?
    https://github.com/Guad/NativeUI/wiki/Pause-Menu



  • @AHK1221 I've never used that but I can already tell you it offers a very different functionality. My extension is meant to allow you to edit and expand existing sections of the pause menu. I think the NativeUI one would be useful if you want to create a whole new pause menu interface.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.