Author Topic: Popup List tutorial  (Read 16228 times)

mickyg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Popup List tutorial
« on: April 12, 2013, 12:32:08 AM »
I noticed that it is not available (greyed out). Will this be available again soon?

I am very new to scripting, all I want is to know how to capture the current popup menu item as a variable, when you click on it.

Or at least get the string so I can then do something with it. This seems to be catered for with the OnSelectionChange and UIPopupList.selection, however I have no idea where to put this or how to call it up.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup List tutorial
« Reply #1 on: April 12, 2013, 04:13:00 AM »
What popup list tutorial? You can create a popup list from the widget wizard.

mickyg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Popup List tutorial
« Reply #2 on: April 14, 2013, 06:05:29 PM »
I'm referring specifically to scripting. There seems to be a lack of examples in the documentation for basic tasks. For instance:

How do I call a specific event when an item in a Popup Menu is clicked on.

I thought I could use the OnSelectionChange function. But what happens when the user selects the item that is specified in the 'Selection' dropdown in the inspector? Then there is technically no selection change, and therefore nothing is called.

It makes sense for a Popup Menu to have no selection set at the start, does it not?


Put simply, I have a popup menu called 'file', with two options under it - 'Load' and 'Close':

File
____

Load
Close

And I want to call two different events when Load and Close are clicked on.

This seems to me to be the exact reason why a Popup Menu would be needed, and yet there is no documentation on how to make this work. After searching the forum, there are at least 3 other threads asking this very question with no resolving answer for any of them.

Thanks
« Last Edit: April 15, 2013, 01:54:31 AM by mickyg »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup List tutorial
« Reply #3 on: April 15, 2013, 09:36:53 AM »
You are describing a popup menu, not a popup list. Create it via the widget tool.

mickyg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Popup List tutorial
« Reply #4 on: April 15, 2013, 05:27:16 PM »
Yes, I am describing a Popup Menu.

Yes, I created a Popup Menu via the widget tool.

In my second post, I referred to a Popup Menu 4 times.

When a Popup Menu is created via the widget, it applies the UIPopupList.cs. As far as I can see, the only difference between the two is the fact that in a Popup List, the label object is fed back into the Text Label parameter.

Therefore, my problem is relevant regardless of whether it's a Popup Menu or a Popup List. To reiterate:

How can I capture a change via OnSelectionChange, if the user selects the same Option from the dropdown list that is highlighted in the Selection dropdown?

In that case, there is no selection change, and therefore no event is fired.

I know you must get a lot of questions every day, but it seems that you simply haven't read my second post. I described the issue succinctly and you made no effort to address or acknowledge it - instead you told me that I was using the wrong widget which was incorrect if you read my post, and irrelevant besides.

I hope I'm not coming across as aggressive or rude because that's not my intention - I just want to resolve this issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup List tutorial
« Reply #5 on: April 15, 2013, 06:24:03 PM »
The curse of a crazy workload... I tend to skim posts looking for keywords rather than read many of them if they are more than a simple question.

Hmm... looking at it a bit more, there may be an issue here. The selection should never be set for popup menus. Open up UIPopupList and add the following to the end of the 'selection' property's setter:
  1. if (textLabel == null) mSelectedItem = null;
I've also modified the Start() function to exit out early if textLabel is null. Lemme know if that helps.

tbrewerart

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Popup List tutorial
« Reply #6 on: May 02, 2013, 06:01:54 PM »
Thanks for the post.  I am new to coding and have a similar confusion: 

all I want is to know how to capture the current popup menu item as a variable, when you click on it.  Or at least get the string so I can then do something with it....... There seems to be a lack of examples in the documentation for basic tasks.

Could you show an example of how to access the chosen menu item?  Do I need to create another script with the "OnSelectionChange" method and then use conditional to respond to the selection?

General thought:  NGUI is beautifully conceived. I have the pro version. Thank You.  But, most of the tutorials are on aesthetics and design. I find this aspect of NGUI, because of its design, easy enough to figure out. Precious few tutorials (actually none) are about implementing NGUI with code: How to make our pretty buttons and sliders actually do something.   

If you could do one video on coding/implementing the button, slider, checkbox, popup-list/menu, etc...We neophytes would be most grateful!   

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup List tutorial
« Reply #7 on: May 03, 2013, 09:51:59 AM »
Yes, create a script with OnSelectionChange in it (or whatever callback you specified on the popup list).

tbrewerart

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Popup List tutorial
« Reply #8 on: May 03, 2013, 01:47:18 PM »
Thanks for the reply.  But what message is being sent?  It looks like the “value” of “mSelectedItem” is sent––meaning, the string name of the button selected? Or, is it returning a list number? 
  • ,[1],[2],[3]  If so, how would I access that precisely?


From UIPopupList:

if (mSelectedItem != value)
         {
            mSelectedItem = value;
            
            if (textLabel != null)
            {
               textLabel.text = (isLocalized) ? Localization.Localize(value) : value;
#if UNITY_EDITOR
               UnityEditor.EditorUtility.SetDirty(textLabel.gameObject);
#endif
            }

            current = this;
            if (onSelectionChange != null) onSelectionChange(mSelectedItem);

            if (eventReceiver != null && !string.IsNullOrEmpty(functionName) && Application.isPlaying)
            {
               eventReceiver.SendMessage(functionName, mSelectedItem, SendMessageOptions.DontRequireReceiver);
            }
            current = null;
         }
         
         if (textLabel == null) mSelectedItem = null;
      }



I have an empty game object with a script on it I want to access from another scene plugged in as my Event Receiver.  Within it I have the following...

public string mSelectedItem;

void OnSelectionChange()
   {   
      if (mSelectedItem == "Easy")
      {
         minA = 0;
         maxA = 9;
         minB = 0;
         maxB = 9;
      }

   ...etc..}


How should I approach this?  Am I missing the boat here?  Any help would be appreciated. 

Many thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup List tutorial
« Reply #9 on: May 03, 2013, 09:46:30 PM »
void OnSelectionChange(string selectedItem)