Author Topic: UIPopupList not registering clicks on first value of a list  (Read 17844 times)

Ony

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
I've updated to NGUI 3.99 and my popup lists are no longer working correctly. They've been fine for over a year so I'm not sure what happened.

Basically, when I click an item in the popup list, if it's the first item in the list, it won't register an event. If I click a different item, it registers, and then I can click any of them and they'll work. The first item, in other words, won't register an event until another item is clicked.

Here's the code I've got on the popup list to intercept the clicks:

  1. using UnityEngine;
  2.  
  3. public class UIpopupList_For_Editor : MonoBehaviour {
  4.  
  5.         private UIPopupList popupList; 
  6.         public morphHandler theMorphHandler;
  7.  
  8.  
  9.     void Awake()
  10.     {
  11.         UIPopupList popupList = GetComponent<UIPopupList>();
  12.                 EventDelegate.Add(popupList.onChange, SetSliderWindow);
  13.     }
  14.  
  15.        
  16.         public void SetSliderWindow ()
  17.         {
  18.                 Debug.Log("Selection: " + UIPopupList.current.value);
  19.                
  20.                 theMorphHandler.SetupMorphSliders (UIPopupList.current.value);
  21.         }
  22.  
  23. }

Nothing happens when I click the first item in the list, not even the Debug.Log.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #1 on: June 28, 2016, 09:33:08 AM »
Do you have some code setting the popup's value anywhere? Check the UIPopupList's Set function. It only triggers if the value changes. Popup list doesn't have a value set by default. The 'value' is only valid during callbacks and should not be set by any user script at any point.

Ony

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #2 on: June 28, 2016, 11:41:27 AM »
Nope, nothing is setting the value. I just searched through my whole code base to see if I had anything in there doing that and there's nothing. The popup list has been working fine for over a year and only broke when I updated NGUI the other day. There have been no changes done in that section of my code.

Ony

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #3 on: June 28, 2016, 12:58:43 PM »
I'll try it on a fresh project and see if it still happens. In the mean time I solved it for now by adding a "-" as the last option in each popup list, then making that the default instead of the first entry. That seems to work so far, other than there being a blank entry at the end of each list.
« Last Edit: June 28, 2016, 01:06:42 PM by Ony »

Samuraisa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #4 on: July 18, 2016, 07:44:14 AM »
Hi! I have similar problem and have found this topic  :)
The reason is what UIPopupList do not updating it's label value for default pressetted value in editor.

In my example I have 2 popups on one screen:
1) "Difficulty" with coorsponding presets via Editor "Normal" and "High" (default "Normal")
2) "Language" with presetted value "English"

Then on game start all UIPopupList-s are cleared and refilled via code, but mSelectedItem is already set to "Normal" and "English" correspondingly. And if my selected value for any of this 2 popups will be the same as presetted, then there is will not be any corresponding UILabel value update and I'll see UILabel's default "value here" text.

For the time as the hack I've added 2 strings in the end of UIPopupList.Start function:
  1. if (mSelectedItem != null)
  2.         TriggerCallbacks();

...but I feel this is not the best solution, coz there is already could be some callbacks with unwanted extra call.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #5 on: July 20, 2016, 03:13:06 AM »
Nothing should be setting "mSelectedItem" outside of actual selection via user input. That entire part is intentionally commented out in the UIPopupList's Start() function.

I'm guessing you uncommented it, which is why you are running into this problem.

Samuraisa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #6 on: August 08, 2016, 11:54:30 AM »
Nope, I'm not changing anything while it's working right for me. And I've edited only strings which I mention here. It was v3.9.9

Samuraisa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #7 on: August 08, 2016, 12:54:08 PM »
Now every NGUI's update I'm editing this 2 things:
+ popup offset (the block in the end of UIPopupList with words "Ensure that everything fits into the panel's visible range" and yes - panel is fullscreen). UIPanel's Clipping is None and Adv. Options -> Visible is off.
+ the problem of this topic. Uncommenting the block in Start method on the contrary is the cure in my case.

Before:


After:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #8 on: August 08, 2016, 06:04:19 PM »
Your referenced images are broken.

Try changing the mSelectedItem to not be serialized:
  1. [System.NonSerialized] protected string mSelectedItem;

Samuraisa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #9 on: August 09, 2016, 08:41:59 AM »
Yes, it's doing the stuff

chrisfirefox

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 9
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #10 on: August 11, 2016, 04:06:57 AM »
Related question: Is this intentional, essentially clearing "value" of UIPopuplist every time it is changed in Line 17 (Original File Line 315)? Because it looks like a bug to me, and after the "onChange" event, "UIPopupList.value" is cleared, which doesn't make sense to me (hope it isn't a problem to post a minor part of the proprietary code, if so, please delete it)
  1.         /// <summary>
  2.         /// Set the current selection.
  3.         /// </summary>
  4.  
  5.         public void Set (string value, bool notify = true)
  6.         {
  7.                 if (mSelectedItem != value)
  8.                 {
  9.                         mSelectedItem = value;
  10.                         if (mSelectedItem == null) return;
  11. #if UNITY_EDITOR
  12.                         if (!Application.isPlaying) return;
  13. #endif
  14.                         if (notify && mSelectedItem != null)
  15.                                 TriggerCallbacks();
  16.  
  17.                         mSelectedItem = null;
  18.                 }
  19.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList not registering clicks on first value of a list
« Reply #11 on: August 13, 2016, 03:49:31 PM »
Yes, it's intentional. The popup's value is only valid during the event callback. If you need to access its value outside of that callback, save it somewhere.