Author Topic: Drag-and-release Popup List for Touch  (Read 4244 times)

tyinus

  • Guest
Drag-and-release Popup List for Touch
« on: August 18, 2012, 04:49:21 PM »
Hey guys -

I have recently started to build my game's HUD using NGUI. The game is targeted for Android and iOS. I am trying to create a popup list that behaves differently than the default popup list in NGUI (which uses clicking to select, hovering to highlight, etc. - seems geared towards using a mouse).

However, I am having trouble creating my own slightly modified version of UIPopupList. I want the popup list to open when user presses down (I have that working) and then the user should drag and highlight to their desired item. Releasing the control would make the selection. I have been able to use an OnDrop() event to find the released item, but I cannot get the OnDrag() to work as the user drags through the popup options.

Any suggestions would be greatly appreciated!

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag-and-release Popup List for Touch
« Reply #1 on: August 18, 2012, 05:52:21 PM »
OnDrag event is sent to whatever received OnPress -- so your popup list by default. You can change that by altering UICamera.currentTouch.pressed

tyinus

  • Guest
Re: Drag-and-release Popup List for Touch
« Reply #2 on: August 18, 2012, 06:54:17 PM »
I am able to receive OnDrag() events from the master popuplist. However, the only parameter passed in is a Vector2 which shows the velocity of the drag. How do I figure out which of the popout items I am currently dragged onto/over?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag-and-release Popup List for Touch
« Reply #3 on: August 18, 2012, 07:12:04 PM »
UIPopupList.current
« Last Edit: August 19, 2012, 12:32:53 PM by ArenMook »

tyinus

  • Guest
Re: Drag-and-release Popup List for Touch
« Reply #4 on: August 18, 2012, 07:37:16 PM »
Thank you for the quick replies! It is very much appreciated.

It appears that UICheckbox.current is never set. Perhaps there something I need to do so that the UICheckboxes become set as they are dragged over?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag-and-release Popup List for Touch
« Reply #5 on: August 18, 2012, 09:02:07 PM »
It's set on line 175 of the UIPopupList class. It's available only within the callback function triggered by the popup list. If you need it outside of this, you need to cache the value.
« Last Edit: August 19, 2012, 12:32:43 PM by ArenMook »

tyinus

  • Guest
Re: Drag-and-release Popup List for Touch
« Reply #6 on: August 18, 2012, 10:19:40 PM »
I guess I'm not quite sure how the UICheckbox stuff fits in with the UIPopupList? I don't see a reference to it anywhere in UIPopupList.cs - are checkboxes being used behind the scenes somehow?

tyinus

  • Guest
Re: Drag-and-release Popup List for Touch
« Reply #7 on: August 19, 2012, 09:05:14 AM »
Looking though a few related forum posts, I have figured out a solution that does not involve UICheckbox.

I have created a slightly modified version of UIPopupList.cs modified for touch (drag-and-release) input. In the OnStart() method I have:

  1. UICamera.genericEventHandler = gameObject;

..and then on the OnDrag() event, I am able to grab the relevant gameobject through its collider:

  1. GameObject go = UICamera.currentTouch.current.collider.gameObject;

Does this seem like an OK approach to take? Is there anything I should watch out for?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag-and-release Popup List for Touch
« Reply #8 on: August 19, 2012, 12:31:47 PM »
Ha, sorry I meant UIPopupList.current. :D