Author Topic: UIPopupList  (Read 38712 times)

Paul

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: UIPopupList
« Reply #30 on: October 27, 2015, 03:23:14 PM »
I've added a resolution dropdown list for a PC game with keyboard, mouse & controller input, however when using the arrow keys or controller to navigate the menu, I noticed the onValueChange callback gets called on each navigation.

Is it possible to instead treat this navigation like mouse over and only perform onValueChange when the user submits their choice (via the enter key or 'A' controller button for example)?

I'm currently changing the application's resolution in the onValueChange callback which causes jarring behavior when using the keyboard/controller. Aside from adding an 'Apply Changes' button to the options screen, I was wondering if there was another way.

Thanks!!
« Last Edit: October 27, 2015, 03:31:56 PM by Paul »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIPopupList
« Reply #31 on: October 29, 2015, 07:17:29 AM »
You could do it, but you'd need to modify the popup list's functionality... unfortunately I don't have any simple suggestions for you off the top of my head.

Although you could simply check if the UIPopupList.isOpen in your callback function to see if it should be responding to state changes or not.

Paul

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: UIPopupList
« Reply #32 on: November 20, 2015, 12:13:12 AM »
Thanks for the UIPopupList.isOpen tip -- I wasn't aware of that.

I ended up modifying UIPopupList by adding another EventDelegate that only fires after a selection has been made. Not the prettiest code, but it was a small change nonetheless. =)

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: UIPopupList
« Reply #33 on: January 22, 2016, 10:26:34 AM »
Is there anyway to specify a non-UIAtlas sprite for the drop down?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIPopupList
« Reply #34 on: January 25, 2016, 10:56:24 PM »
You can just change the UISprite's references within UIPopupList to something else if you like. Assuming you want to use UI2DSprites?

Edit: I've gone ahead and added support for 2D sprites. Replace UIPopupList.cs and UIPopupListInspector.cs files with these.
« Last Edit: January 25, 2016, 11:30:34 PM by ArenMook »

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: UIPopupList
« Reply #35 on: January 26, 2016, 05:00:25 AM »
You can just change the UISprite's references within UIPopupList to something else if you like. Assuming you want to use UI2DSprites?

Edit: I've gone ahead and added support for 2D sprites. Replace UIPopupList.cs and UIPopupListInspector.cs files with these.

I had gone ahead and rolled my own solution, but this is much better, thanks! One modification I did make which I think would be useful to add is the ability to set the drop-down list panel's sorting layer in the UIPopuplist inspector, as it currently defaults to "Default" which may be behind the sorting layer of the panel which creates the drop-down list.

Anyway, thanks again!

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: UIPopupList
« Reply #36 on: June 22, 2016, 06:13:50 AM »
Hey, I've noticed an issue with the Popuplist inspector. If I remove the reference to an UIAtlas, the options appear to use individual sprites like you implemented above. However, if I select another object, and then go back to the UIPopuplist, the reference to the UIAtlas is returned and is no longer null. The same happens after resetting the component.

I've uploaded a gif to demonstrate the issue.

I'm on version 3.9.9 but this issue may have been happening before, I've only noticed it now

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIPopupList
« Reply #37 on: June 24, 2016, 02:00:35 AM »
Nice catch, thanks. You can fix it by getting rid of the part that sets it in the OnEnable function of UIPopupListInspector:
  1.         void OnEnable ()
  2.         {
  3.                 SerializedProperty bit = serializedObject.FindProperty("bitmapFont");
  4.                 mType = (bit.objectReferenceValue != null) ? FontType.Bitmap : FontType.Dynamic;
  5.                 mList = target as UIPopupList;
  6.  
  7.                 if (mList.ambigiousFont == null)
  8.                 {
  9.                         mList.ambigiousFont = NGUISettings.ambigiousFont;
  10.                         mList.fontSize = NGUISettings.fontSize;
  11.                         mList.fontStyle = NGUISettings.fontStyle;
  12.                         EditorUtility.SetDirty(mList);
  13.                 }
  14.  
  15.                 //if (mList.atlas == null)
  16.                 //{
  17.                 //    mList.atlas = NGUISettings.atlas;
  18.                 //    mList.backgroundSprite = NGUISettings.selectedSprite;
  19.                 //    mList.highlightSprite = NGUISettings.selectedSprite;
  20.                 //    EditorUtility.SetDirty(mList);
  21.                 //}
  22.         }

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: UIPopupList
« Reply #38 on: June 24, 2016, 03:48:53 AM »
Great, thanks!

tree1891

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIPopupList
« Reply #39 on: September 23, 2016, 02:57:58 AM »
I have used UIPopupList.value member for select via code.
But after call it, UIPopupList.value is null because of mSelectedItem = null in Set function.
Then how to get current selected item later?

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIPopupList
« Reply #40 on: September 23, 2016, 03:38:45 PM »
search the forums  :P

It's intentional. The popup list only has a value during its callback function. I've mentioned this on several occasions in the past. If you want to store this value, do just that.
  1. public string savedValue;
  2.  
  3. void Start ()
  4. {
  5.     var popup = GetComponent<UIPopupList>();
  6.     EventDelegate.Add(popup.onChange, delegate () { savedValue = popup.value; });
  7. }

kendro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIPopupList
« Reply #41 on: December 04, 2016, 10:02:05 PM »
I countered an issue in the popuplist after upgrading to 3.10.2 (from 3.9.7).  If you select the FirstOption then nothing happens.  If you select either the SecondOption or ThirdOption then the event fires... and only then the next time you click FirstOption it will fire the event.

I have uploaded a gif to demonstrate the issue.

I haven't updated yet to the latest 3.11.x, but did not notice anything in release notes in reference to this bug.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIPopupList
« Reply #42 on: December 04, 2016, 10:28:35 PM »
The event only fires if you don't already have selection set to the same thing. By default the popup list has no selection. Did you set it manually yourself?

kendro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIPopupList
« Reply #43 on: December 05, 2016, 05:39:07 PM »
How do you set the popup list selection to "nothing" then... so that no matter what you select in the list it always fires the onChange event. The use case would be like a popup menu... so you would not have a "default or current selection" in that case.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIPopupList
« Reply #44 on: December 06, 2016, 05:58:48 AM »
That's exactly how it works though. The popup list has no selection explicitly for that reason -- so you can select the same thing repeatedly. Once the popup list is closed, the selection is cleared to null. Before the change it wasn't possible to select the same thing repeatedly, as selection value persisted from one time you opened the popup list to the next.