Hello Guest

Author Topic: Alternative message subscribing directly on tk2dUIManager  (Read 5870 times)

Izitmee

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
    • Holoville Games
Alternative message subscribing directly on tk2dUIManager
« on: June 11, 2013, 12:38:01 pm »
Would like to suggest something for future releases. It would be nice if we could listen for events directly from tk2dUIManager also (using the On..UIItem event which also returns the involved item).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #1 on: June 12, 2013, 11:07:01 pm »
Are you suggesting you hook things up using the UIManager? This could potentially get messy - eg. it would actually need to handle all the other events too. It would be quite confusing it did one and not other events, but there could be a giant explosion of events there.

Izitmee

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
    • Holoville Games
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #2 on: June 13, 2013, 09:08:28 am »
Yup, I'm suggesting exactly that :) If an event has no event listeners, then it's not dispatched, so no harm done anyway? :P Would be useful in case you have tons of UI elements and you want to manage them from a single place.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #3 on: June 13, 2013, 10:23:56 am »
Yup, I'm suggesting exactly that :) If an event has no event listeners, then it's not dispatched, so no harm done anyway? :P Would be useful in case you have tons of UI elements and you want to manage them from a single place.

I'll have a think about it. This could potentially be done much easier if you want to handle it this way, eg. create a base class with all the functions set up as virtuals, you only need to override the ones you want to. A catch-all would be much more convenient this way, no need to hook-up events at all, just register self to uimanager, and remove from uimanager. What do you think?

Izitmee

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
    • Holoville Games
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #4 on: June 13, 2013, 10:42:57 am »
I feel quite dumb, but I'm not sure I understand how that would work :B If you'd register to UIManager with some class that inherits from said base class, wouldn't UIManager end up calling every virtual function in there, even if not overridden, and thus be a waste? And wouldn't that prevent such usage in some situations where you're hindered by non-multiple inheritance, and don't want to inherit from said base class, but for example from MonoBehaviour?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #5 on: June 13, 2013, 10:58:52 am »
UIManager is event driven - I wouldn't consider calling a bunch of virtuals really an issue, at most you're gonna call 1-2 of those in a frame, and thats absolute worst case. It could be an interface too, or even a SendMessage target - the point I'm getting at is do you really want to subscribe to the events manually if you were to do this? Maybe should move this to support / private support :D

Izitmee

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
    • Holoville Games
Re: Alternative message subscribing directly on tk2dUIManager
« Reply #6 on: June 13, 2013, 11:19:07 am »
Oh I see! Yes, I would definitely prefer to have direct access to events: I already do it with my personal UIManager and I find it "cleaner" :) But if it's just me, feel free to ignore it. It's not superimportant, and for now I'm still not even using your UI system (will try it with the next project).