Author Topic: UIPopupList getting/setting value  (Read 7570 times)

cardsfanlv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIPopupList getting/setting value
« on: March 24, 2016, 05:52:35 PM »
Updated to NGUI 3.9.8 yesterday and noticed that all my UIPopupLists are now broken.   

Setting the value worked as expected, but getting the value now returns null..

Digging into the code, it struck me that line 315 in UIPopupList.cs was likely the culprit here.    Commenting that line out did indeed fix the problems and now I'm retriving the value from the popup lists, and they are now working as expected again.

  1. public void Set (string value, bool notify = true)
  2.         {
  3.                 if (mSelectedItem != value)
  4.                 {
  5.                         mSelectedItem = value;
  6.                         if (mSelectedItem == null) return;
  7. #if UNITY_EDITOR
  8.                         if (!Application.isPlaying) return;
  9. #endif
  10.                         if (notify && mSelectedItem != null)
  11.                                 TriggerCallbacks();
  12.  
  13.                         mSelectedItem = null;
  14.                 }
  15.         }
  16.  

commenting out the line 'mSelectedItem = null', sure enough seemed to fix my problem but this begs the question if this is an NGUI bug or is there something on my end I am doing wrong.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList getting/setting value
« Reply #1 on: March 27, 2016, 03:05:51 AM »
The idea is that the popup list should only have an active selection within the event notification callback. One the callback is done, the popup list is generally closed anyway so there is no need for a value to stick around.

This fixed the issue of a popup list retaining its value, and as a result failing to select the same item from the popup list when used repeatedly (for example right-click, "Copy").

cardsfanlv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIPopupList getting/setting value
« Reply #2 on: March 28, 2016, 01:51:58 PM »
The idea is that the popup list should only have an active selection within the event notification callback. One the callback is done, the popup list is generally closed anyway so there is no need for a value to stick around.

This fixed the issue of a popup list retaining its value, and as a result failing to select the same item from the popup list when used repeatedly (for example right-click, "Copy").

This is what I've been doing..

I have a few of them in my game settings panel,  to offer the player some options. 

In my method that displays the settings panel, I set the popup's values with popupList.value = x, and in my method to close the settings panel, I update my settings properties from popupList.value.   

When I updated to 3.9.8, I could still set the popupList value correctly, but because that value no longer sticks around, when the settings panel is closed and I look for those values, it broke my code..

I suppose I can comment out that line and it still works for my purposes, but I'd like to use it correctly so this isn't an issue in the future.

Thanks!


Zyxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 37
    • View Profile
Re: UIPopupList getting/setting value
« Reply #3 on: July 17, 2016, 06:24:47 PM »
Doesn't setting mSelectedItem to null make this function worthless for notify = false calls?

I can comment it out, too. But, I think this is not fully thought out.

Zyxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 37
    • View Profile
Re: UIPopupList getting/setting value
« Reply #4 on: July 17, 2016, 08:23:58 PM »
Even with the line commented out, notify = false calls still do not set the value properly.

I worked around it.   ;)