Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: beorn on December 28, 2013, 06:33:07 AM

Title: Feature request: More standard button press events
Post by: beorn on December 28, 2013, 06:33:07 AM
Hi good NGUI folks,

Maybe I'm missing something, but NGUI button press handling seems to make it very hard to support *standard* UI behavior:


1) I'd like to track and show a different state for the button depending on whether OnClick will be called if OnPress(false) happens.  I've seen these states referred to as "armed" and "disarmed" before - armed means if I release the mouse button/finger it'll trigger the action of the button.

I'll need events to fire three different animations/tweens:


It seems the only way to do this is to try to mimic the logic of OnClick in my own script, and do it incompatibly (see point 2 below for example).  It seems this should be the normal behavior, so shouldn't NGUI support this out-of-the-box?  (Or, let me know how to do it if I missed something!)


2) In NGUI, if I press down over a button, drag the mouse pointer out of the button, back in again, and then release OnClick is not fired.  This isn't how most UIs that I know of work - they'll still trigger the action if you move the mouse pointer back into the button before you release.


See
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 28, 2013, 04:56:12 PM
Regarding #2: once the drag event begins, click event is canceled. NGUI has been like that from the very beginning so changing it now is likely to result in quite a few people saying "bug!".
Title: Re: Feature request: More standard button press events
Post by: beorn on December 28, 2013, 05:18:51 PM
Re 2 - isn't the current behavior a bug if it's inconsistent with what the end user expects? I can only verify OSX and iOS at the moment, but looks like that's how Java wants it as well.

Re 1 - any chance for something like OnArm making its way into NGUI? :)
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 28, 2013, 05:28:14 PM
Your #1 depends on #2. But even if I was to change #2, I wouldn't add OnArm stuff as you can already do this inside OnDragOver by checking UICamera.currentTouch.dragStarted.
Title: Re: Feature request: More standard button press events
Post by: beorn on December 28, 2013, 05:46:35 PM
#1 doesn't depend on #2. As long as the behavior of arming events are consistent with how ontrigger works, it's at least consistent from a visual / usability point of view.

#2 is the behavior in most games too, eg Candy Crush Saga and Hayday.

All I want to do is create a UI with buttons that work similarly to those games, which also works similarly to (all?) operating/windowing systems.
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 28, 2013, 05:54:28 PM
You can do that by commenting out line 1425 in UICamera.cs:
  1.                                         // If the touch should consider clicks, send out an OnClick notification
  2.                                         //if (currentTouch.clickNotification != ClickNotification.None)
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 28, 2013, 05:55:15 PM
...or, a more elegant solution that doesn't involve modifying NGUI code... inside OnPress function attached to your button:
  1. UICamera.currentTouch.clickNotification = ClickNotification.Always;
Title: Re: Feature request: More standard button press events
Post by: beorn on December 28, 2013, 11:36:09 PM
Re points 1 & 2:
Ideally, NGUI would help track the armed state of buttons as:
I've attached an updated script integrating some of your recommendations.  Given this is such a "standard" (and I guess recommended from a usability point of view) behavior, I just it was as easy as overriding OnArm and OnClick and adding animations into them.
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 29, 2013, 01:21:53 AM
OnDragOver is sent when you drag something over an object. OnDragOut is sent when you drag away. OnDrag is sent to the object being dragged with the delta. It's all covered in the doc page for UICamera.
Title: Re: Feature request: More standard button press events
Post by: beorn on December 29, 2013, 01:36:42 AM
Yes, so in this case, I'm not dragging anything over anything, so OnDragOver/Out won't work, right?  If I could make it work, that would of course be better since it means a lot fewer events to handle.  (See code attached in last post.)
Title: Re: Feature request: More standard button press events
Post by: ArenMook on December 29, 2013, 01:41:54 AM
OnDragOver/Out events are sent to what you dragged over/out, so yes if you wanted this handled on the object being dragged then it won't work for you, but your script that does the check in OnDrag will.