Forum rules - please read before posting.

OnMouseOverMenu custom event changes

edited November 2023 in Technical Q&A

Hey Chris, a while ago I wrote the following script. This is what I used it for:

  • When the first scene of the game starts, the player is presented with a menu that displays 3 Player Profile icons to choose from. Empty profiles are represented by a menu element with an empty potion flask graphic, and already existing profiles are represented by a full flask. No more info is given by the menu element itself.
  • On mouseover, a second menu is displayed with information about the profile (location and time played). This is a fairly simple menu with 2 text labels that pull strings from global variables. The appear type is manual, and the transition type is "Fade". The intended effect is that when the mouse is over the a profile element, this text will fade in, and when the player moves the cursor away from the element, the text will fade out.
  • Essentially, the script below is used to (1) update the variables to display the correct data from each profile, and (2) to control whether the info text menu is supposed to be turned on or off.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class ProfileSetup : MonoBehaviour
    {
    
        AC.Menu myMenu;
    
    
        private void OnEnable() { EventManager.OnMouseOverMenu += OnMouseOverMenu; }
        private void OnDisable() { EventManager.OnMouseOverMenu -= OnMouseOverMenu; }
    
    
        private void OnMouseOverMenu(AC.Menu _menu, AC.MenuElement _element, int _slot)
        {
    
            AC.Menu myMenu = AC.PlayerMenus.GetMenuWithName("ProfileChoice time");
    
            if (_element != null && _menu.title == "ProfileChoice")
            {
    
                if (_menu.title == "ProfileChoice" && _element.title == "Profile 1")
                {
    
                    AC.GlobalVariables.SetStringValue(51, KickStarter.options.GetProfileIDName(1));
                    string location = AC.Options.GetProfileVariable(1, 52).PopUpValue;
                    AC.GlobalVariables.SetStringValue(53, location);
                    myMenu.TurnOn();
                }
    
                if (_menu.title == "ProfileChoice" && _element.title == "Profile 2")
                {
    
                    AC.GlobalVariables.SetStringValue(51, KickStarter.options.GetProfileIDName(2));
                    string location = AC.Options.GetProfileVariable(2, 52).PopUpValue;
                    AC.GlobalVariables.SetStringValue(53, location);
                    myMenu.TurnOn();
                }
    
                if (_menu.title == "ProfileChoice" && _element.title == "Profile 3")
                {
    
                    AC.GlobalVariables.SetStringValue(51, KickStarter.options.GetProfileIDName(3));
                    string location = AC.Options.GetProfileVariable(3, 52).PopUpValue;
                    AC.GlobalVariables.SetStringValue(53, location);
                    myMenu.TurnOn();
                }
    
            }
            else
            {
    
                myMenu.TurnOff();
                Debug.Log("element is null");
            }
    
        }
    
    }
    

This used to work perfectly, but now the menu never fades out when the you move the cursor away. The AC 1.79 patch notes include this fix:

Fixed: OnMouseOverMenu custom event sometimes being called when de-selecting an element

Which was the exact behaviour that I was using to make this work! Was this intended? And if so, is there a workaround? I thought about checking IsPointInside(invertedMouse), but this only seems to be available when you get a whole menu, not a specific element within it. I also checked if there was a custom event like OnElementDeselect (since the patch notes said my script was working BECAUSE the event was being called when deselecting an element), but no such custom event appears to exist.

Comments

  • Apologies - a change made without considering all side-effects.

    I'll look into it further, and may revert back in the next release. In the meantime, open PlayerMenus and replace line 2189:

    if (mouseOverMenu != null && (lastElementIdentifier != elementIdentifier || lastMenuIdentifier != menuIdentifier) && elementIdentifier != -1)
    

    with:

    if (mouseOverMenu != null && (lastElementIdentifier != elementIdentifier || lastMenuIdentifier != menuIdentifier))
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.