Author Topic: Button -> Slide -> Release Button  (Read 8906 times)

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Button -> Slide -> Release Button
« on: June 27, 2012, 11:47:32 PM »
Is there anyway to detect a button release without having actually pressed the button?

For example, I have my big button and one I press it four more buttons pop out, one on each side. It then looks like a joypad shape. Pressing this button again folds the 4 buttons away.

Now at the moment these 4 buttons require a release of the big button and then another click. What I would like to happen is like a popup selector window.

What I have done now is create it so when the big button is held the 4 buttons appear and fold away when you release the press. Is there anyway of making it so I drag my thumb to left right etc and then register a button press on the other 4 buttons?

Thanks :)

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #1 on: June 28, 2012, 12:02:36 AM »
Hmm, can't figure it out. I think what I should do instead is calculate the screen coordinates of where the finger is when it is released and have bounding box checks as to whether or not it hit the button or not. That probably seems like a better way of doing it.
« Last Edit: June 28, 2012, 12:13:48 AM by ENAY »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #2 on: June 28, 2012, 04:50:37 AM »
UICamera.hoveredObject tells you what's under the mouse regardless of whether it will receive the OnPress(false) event or not. OnPress(false) is sent to whatever received OnPress(true).

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #3 on: June 28, 2012, 04:55:20 AM »
Thanks ArenMook I will take a look at that. :)

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #4 on: June 28, 2012, 11:44:54 PM »
Thanks ArenMook. That worked great.

Unfortunately once I held down the big button, it wouldn't update. However as soon as I released the button, it would check what was under the cursor, so I did my check then and everything turned out ok.

Not sure what will happen if I have multiple buttons held down, but we'll see later when I test it out.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #5 on: June 29, 2012, 03:17:08 AM »
Hurray for local changes that didn't get checked into the repo...

Change UICamera's hoveredObject function to this:

  1. static public GameObject hoveredObject { get { return mMouse[0].current; } }

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #6 on: June 29, 2012, 07:17:05 AM »
I was just about to post and say it doesn't work in iPhone and iPad. So I guess it was a bug that crept through that you thought you'd updated?

Well, I changed the NGUI source code and now it seems to be working. A problem solved before I even asked the question :)

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #7 on: June 29, 2012, 07:36:02 AM »
Actually no I was wrong.

Before the fix, I had to release the button to register the hoveredObject, after the fix it registered without having to release the button.

But it does not work on the iPhone or iPad at all.

Seems hoveredObject simply returns nothing on handheld devices. Not quite sure why that would be. Still investigating.

[edit]

Looked all through the UICamera.cs code and couldn't see anything. Maybe this feature really is mouse only? (like the name suggests) As it works on iOs and Windows with a mouse.

I did mention in my first post that I was dragging my thumb so I am guessing that this feature is supposed to be working on hand held devices as well. Odd one that.
« Last Edit: June 29, 2012, 08:09:44 AM by ENAY »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #8 on: June 29, 2012, 08:36:55 AM »
Hover event is only for the mouse. How can you detect a finger hovering over the screen? For dragging you get OnDrag instead.

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #9 on: June 29, 2012, 08:39:09 PM »
"How can you detect a finger hovering over the screen?"

Well that was my original question, but detection whilst a thumb has been pressed.

I will take a look at OnDrag instead.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #10 on: June 29, 2012, 10:18:19 PM »
That's like trying to detect when the player is looking at the monitor ;)

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #11 on: June 30, 2012, 05:13:43 AM »
Ok, still stuck with this.

[edit] Ok I seem to have fixed it now. Nothing more to see here. :)
« Last Edit: June 30, 2012, 08:10:45 AM by ENAY »

zazery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #12 on: July 01, 2012, 04:23:54 PM »
Hover event is only for the mouse. How can you detect a finger hovering over the screen? For dragging you get OnDrag instead.

OnDrag only works when it's the first object pressed, not when you press elsewhere and drag over the object. That makes sense. However, on mobile devices I'd like to implement the later: hover as pressing anywhere and dragging over objects. I've implemented this in my Ludum Dare entry, which does not use NGUI. You can try it here to see what I mean. Click play, then click anywhere and sweep your mouse over the tiles or citizens on the raft to see their info at the top. Is there a way to implement this functionality with NGUI or will I have to add this myself?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button -> Slide -> Release Button
« Reply #13 on: July 01, 2012, 04:51:15 PM »
You could just do a ray cast into the screen in OnDrag if you really wanted to. I'll think about it.