Author Topic: PopupList data structure  (Read 2624 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
PopupList data structure
« on: March 26, 2014, 12:59:02 AM »
I have a popuplist with a list of colors.
when the user selects a color from the list, I would like to make a sprite in another GO change its color.

Seems that the UIPopupList.current.value is only a string. 

1. How to send a custom data structure instead of a string ?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PopupList data structure
« Reply #1 on: March 26, 2014, 03:02:19 AM »
It's up to you to do something with that string. The string is the selected item. What you do with it is up to you.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: PopupList data structure
« Reply #2 on: March 26, 2014, 04:31:58 AM »
I'm coming from many years working with Adobe Flex Framework so this string is quite basic.  This is not really a solid approach to a modern GUI system.  Please have a look at how DaikonForge does its data binding. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PopupList data structure
« Reply #3 on: March 26, 2014, 07:15:26 PM »
In NGUI you can embed anything you want in labels via a url tag. Same goes for popup list text. As such, if you wanted to encode something hidden such as an ID, you can do just that:
  1. [url=123]First Option[/url]
This has nothing to do with data binding.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: PopupList data structure
« Reply #4 on: March 29, 2014, 04:00:51 AM »
This was the answer that I needed for now.

My issue with the using the text label string is in a multi-language app. 

With this Url approach, at least there is a way to encode more info. 

In a modern GUI system like Adobe Flex, a component like the UIPopupList has a built-in dataProvider component which works together with the databinding mechanism. The data provider can take in an xml or json object.  There is a "data" and "name" field in the dataprovider that can be used to populate the popupList accordingly.   The GUI design patterns of most of this GUI stuff is really old hat and has already been done in many places.  Adobe Flex was really nothing new, it came from the GUI system at microsoft.  So really it's already over 20 years old.  NGUI can benefit greatly if it can borrow some of these time tested solutions.  From your comments regarding how to encode data in the popupList, you really need to look at Flex then you will know which dinosaur genre NGUI belongs to.
« Last Edit: March 29, 2014, 04:47:09 AM by wallabie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PopupList data structure
« Reply #5 on: March 29, 2014, 06:18:29 AM »
"modern GUI system like Adobe Flex"

And yet Flash is a dying platform. Think about that. Complexity doesn't mean better. Localization only affects visible text for popup lists. You get the original non-localized values in the callback.

Although in all honesty, I've yet to encounter a valid use case where I needed to embed URLs in the popup list to begin with.

You will do yourself a favor by leaving all those adobe flex preconceptions behind when getting used to NGUI. That experience is an anchor that's holding you back. Step back and ask yourself... "why do I need to encode anything in the popup list's data?"

The only reason for it is if you've got several choices with the same exact text -- which is a ridiculous thing to have.

P.S. You do realize that your popup list choices can simply be IDs themselves, right? For example, you can do the following:
  1. ID001
  2. ID002
  3. ID003
  4. ID004
...and in your localization, you can set them up with proper text string values. Then your callbacks will just receive the "ID001" etc of your selection.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: PopupList data structure
« Reply #6 on: March 29, 2014, 07:21:07 AM »
Flash dying is a matter of commercial reasons where Apple/Google/Microsoft got together because they were afraid of Flash taking over as a platform.

If you had an xml or json file of info, which is more complex to work with, Flex or Ngui.  With your solution, there's quite a bit of fiddling around to make things work.  With Flex or any other Data Provider Gui based system ( Flex is just a copy of Microsoft forms) just feed the xml or json string into the popupList and it works.  No need for hackery.