Author Topic: Forcing fallThrough handler. Possible? Useful?  (Read 8180 times)

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Forcing fallThrough handler. Possible? Useful?
« on: September 17, 2012, 08:45:56 AM »
Hi there,

I'm creating a RTS game, where I have selectable buildings and the ground. I want the camera to be draggable at all times (except when handling 2D UI, but that's out of the topic), and selection on elements toggles (if you click an unselected item, it selects, if you click it again, it is deselected). It doesn't matter if I click an object, if I drag the camera, the camera dragging should be attended. How should I do this?

My current implementation:
I have 2 main layers: ground & entities. I set up my UICamera to handle events of entities layer, and I set my CameraController gameobject as the fallThrough, that actually handles camera dragging (as described here: http://www.tasharen.com/forum/index.php?topic=214.0) on the ground layer. So, I thought about a ForceFallThroughHandling() when my entity (gameobject on entities layer, that is handled by UICamera) hits OnDrag, so that the control is "gained" by the fall through listener.

Is this correct? There's a better way?

Thanks a LOT!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #1 on: September 17, 2012, 06:14:50 PM »
I'm not sure about the last part of what you said -- force fallthrough handling? Once an event starts via OnPress(true), all OnDrag events will be sent to it up until you get OnPress(false) on the same object, regardless of what else the mouse hovers over.

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #2 on: September 18, 2012, 03:00:24 AM »
Yes, that's why I'm asking if it's possible (and sensible) to force in that object (the one that received the event) to fall to the listener defined in UICamera.fallThrough.

If the answer is no, what you would propose to properly handle this situation?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #3 on: September 18, 2012, 05:35:03 AM »
I think what you're looking for is UICamera.genericEventHandler. It will receive a copy of all events whether they were handled or not.

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #4 on: September 18, 2012, 05:43:22 AM »
I can only see a definition for UICamera.eventHandler, and it needs to be a UIBaseCamera. How should I use it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #5 on: September 18, 2012, 07:51:18 AM »
UIBaseCamera exists only in the free version. It sounds like that's what you're using. Unfortunately it's really outdated and may be missing some functionality, such as this.

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #6 on: September 18, 2012, 07:56:57 AM »
Oh I see. I'm waiting to get my licensed version soon. Thanks!

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #7 on: September 19, 2012, 04:40:02 AM »
Now I'm using 2.2.0. I've set up genericEventHandler. Now, my "event handler" GameObject receives the events as well (it handles camera dragging). But what I really want is, from a GameObject residing in the eventReceiverMask that gets the OnDrag event, do something like:

  1. OnDrag (Vector2 d)
  2. {
  3.     StopEventsForThisObject ();
  4. }

So, my genericEventHandler / fallThrough objects gets the "focus" of the events. OR if there's a more pretty way of handling this situations (is this called event bubbling?)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Forcing fallThrough handler. Possible? Useful?
« Reply #8 on: September 19, 2012, 08:08:46 AM »
You can cancel the drag event by manually unpressing the object. UICamera.currentTouch.pressed is the value holding the currently pressed object. If nothing is pressed, Drag events won't be sent out.