+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 21
Like Tree3Likes

Thread: Updating for the new event model

  1. #1
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default Updating for the new event model

    As I'm going through the process of updating Gadgets for the new event model, I thought I'd post a quick description of how I've gone about doing it, in case anyone isn't entirely sure of how to update their own addons.

    Global Event Handlers

    These are the easiest ones. I did a search across the entire project looking for the text: table.insert(Event.

    Wherever I found this text, I altered it as follows

    Code:
    table.insert(Event.System.Update.Begin, { OnSystemUpdateBegin, AddonId, "SystemUpdate" })
    Becomes:

    Code:
    Command.Event.Attach(Event.System.Update.Begin, OnSystemUpdateBegin, "SystemUpdate")
    Then you find the event handler function, and add in a parameter for the event handle. I use hEvent for this.

    For example, if the function looked like:

    Code:
    function OnSystemUpdateBegin(alpha, beta)
    It simply becomes:

    Code:
    function OnSystemUpdateBegin(hEvent, alpha, beta)
    You can totally ignore the hEvent parameter within the function, you just need to add it to keep your parameter list correct.

    Frame Event Handlers

    This are harder to find, and harder to update. What I've done is search across my project for the text: .Event.

    I then check each matching line to see if it is actually registering a frame event.

    If you currently have:

    Code:
    myFrame.Event.LeftDown = function() print("clicked") end
    It becomes something like:

    Code:
    myFrame:EventAttach(Event.UI.Input.Mouse.Left.Down, function() print("clicked") end, "MouseDown")
    If the event provides parameters to the function, you need to add in the event handler, just like global events. The thing to be aware of here is that the first parameter is still the frame itself, the second parameter is the event handle.

    Therefore, if your event handler currently looks like this:

    Code:
    function myFrame:OnSomething(alpha, beta)
    end
    It will become:

    Code:
    function myFrame:OnSomething(hEvent, alpha, beta)
    end
    However, if you're not using the Lua colon ( : ) shortcut, and your function looks like this:

    Code:
    function myFrame.OnSomething(frame, alpha, beta)
    end
    It will need to look like:

    Code:
    function myFrame.OnSomething(frame, hEvent, alpha, beta)
    end
    A list of all of the various UI events is available here.

    I hope that makes sense, and may be useful to someone.

    - Wild
    Last edited by DoomSprout; 05-19-2013 at 01:24 AM.

    Gadgets: Unit Frames and Other Stuff for RIFT

  2. #2
    Plane Touched
    Join Date
    Jan 2011
    Posts
    281

    Default

    Are slash command events done like global events? So,

    table.insert(Command.Slash.Register("mycommand"), {callback, identifier, label})

    becomes

    Command.Event.Attach(Command.Slash.Register("mycom mand"), callback, label)

    Would this be correct?

  3. #3
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    Yep, that looks correct. This is out of my addon, and seems to work:

    Code:
    Command.Event.Attach(Command.Slash.Register("wt"), WT.OnSlashCommand, "OnSlashCommand")

    Gadgets: Unit Frames and Other Stuff for RIFT

  4. #4
    Soulwalker
    Join Date
    Apr 2012
    Posts
    19

    Default

    Once again Wild... you are awesome. Thanks for the helpful info.

  5. #5
    Rift Chaser
    Join Date
    Feb 2011
    Posts
    350

    Default

    This is very helpful - thanks

    I only have a few addons breaking on PTS, so I assume this is not a necessary change?

    If so, I fear I will have 20+ addons to try to fix (using this great guide) on day 1.

  6. #6
    Ascendant Credo's Avatar
    Join Date
    Jan 2011
    Posts
    4,172

    Default

    Thanks Doom! That clears up any questions I would answer by blundering through it for a half an hour of errors
    Even free cost too much now

  7. #7
    Rift Disciple
    Join Date
    Jan 2011
    Posts
    147

    Default

    For those of you who use LibSimpleWidgets, it does not yet support the new event system. You will have to keep using the old "frame.Event.EventName = function..." method until I can update the library to support the new system. I haven't had much success yet since there doesn't seem to be a way to (properly) register custom UI events.

  8. #8
    RIFT Community Ambassador the_real_seebs's Avatar
    Join Date
    Jan 2011
    Posts
    16,859

    Default

    This thread is super useful.

    And I believe Zorba's said that custom events aren't yet working, but are being worked on?
    You can play WoW in any MMO. You don't have to play WoW in RIFT. Oh, and no, RIFT is not a WoW clone. Not having fun any more? Learn to play, noob! I don't speak for Riftui, but I moderate stuff there. Just came back? Welcome back! Here's what's changed. (Updated for 2.5!)

  9. #9
    Shadowlander
    Join Date
    Mar 2013
    Posts
    28

    Default

    Quote Originally Posted by the_real_seebs View Post
    This thread is super useful.
    +vote for sticky

  10. #10
    Sword of Telara Semele's Avatar
    Join Date
    Mar 2011
    Posts
    872

    Default

    Quote Originally Posted by the_real_seebs View Post
    This thread is super useful.

    And I believe Zorba's said that custom events aren't yet working, but are being worked on?
    They should be working. There's no change in how you create them. You just attach to them in the new style.
    Rank 76 Guardian Mage

  11. #11
    RIFT Community Ambassador the_real_seebs's Avatar
    Join Date
    Jan 2011
    Posts
    16,859

    Default

    I got confused. I was thinking of the issues with custom events and frame events specifically.
    You can play WoW in any MMO. You don't have to play WoW in RIFT. Oh, and no, RIFT is not a WoW clone. Not having fun any more? Learn to play, noob! I don't speak for Riftui, but I moderate stuff there. Just came back? Welcome back! Here's what's changed. (Updated for 2.5!)

  12. #12
    Ascendant Credo's Avatar
    Join Date
    Jan 2011
    Posts
    4,172

    Default

    I can't seem to get some frame events to work if there's a Set operator in the function.

    This works:
    Code:
    function self.bookIcon.Event:MouseIn()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end
    This doesn't:
    Code:
    self.bookIcon.EventAttach(Event.UI.Input.Mouse.Cursor.In, function()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end, "MouseIn")
    Any clues?

    Also now all of my Mouse Events that were used in BOTF now throw an error about the global self from above in all of my Addons.
    Last edited by Credo; 07-10-2013 at 09:25 PM.
    Even free cost too much now

  13. #13
    Shield of Telara Adelea's Avatar
    Join Date
    Mar 2011
    Posts
    734

    Default

    Quote Originally Posted by Credo View Post
    I can't seem to get some frame events to work if there's a Set operator in the function.

    This works:
    Code:
    function self.bookIcon.Event:MouseIn()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end
    This doesn't:
    Code:
    self.bookIcon.EventAttach(Event.UI.Input.Mouse.Cursor.In, function()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end, "MouseIn")
    Any clues?

    Also now all of my Mouse Events that were used in BOTF now throw an error about the global self from above in all of my Addons.
    How about this :

    Code:
    self.bookIcon:EventAttach(Event.UI.Input.Mouse.Cursor.In, function(self, h)
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end, "MouseIn")
    http://forums.riftgame.com/image.php?type=sigpic&userid=125779&dateline=13553  38065

  14. #14
    Ascendant Credo's Avatar
    Join Date
    Jan 2011
    Posts
    4,172

    Default

    Ohhhhhh so you do have to pass in the frame! Thanks!
    Even free cost too much now

  15. #15
    Plane Walker Imhothar's Avatar
    Join Date
    Feb 2012
    Posts
    439

    Default

    Quote Originally Posted by Credo View Post
    I can't seem to get some frame events to work if there's a Set operator in the function.

    This works:
    Code:
    function self.bookIcon.Event:MouseIn()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end
    This doesn't:
    Code:
    self.bookIcon.EventAttach(Event.UI.Input.Mouse.Cursor.In, function()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end, "MouseIn")
    Any clues?

    Also now all of my Mouse Events that were used in BOTF now throw an error about the global self from above in all of my Addons.
    The difference is:
    in
    Code:
    function self.bookIcon.Event:MouseIn()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end
    The colon (:) is at self.bookIcon.Event. So when the frame handler gets called "self" (being the first implicit argument of colon calls) is self.bookIcon, the frame the Event was declared on. Which was dark Zorba magic. So it worked.

    But in
    Code:
    self.bookIcon.EventAttach(Event.UI.Input.Mouse.Cursor.In, function()
    self:SetTexture("BOTF", "media/book_icon_2.png")
    end, "MouseIn")
    The handler function() is defined as having no arguments, therefore Lua captures "self" from the enclosing lexical scope, which is the "self" that has "bookIcon" as a member, and taken from the error does not have a SetTexture method. It is not "self.bookIcon". Would you have used "self.bookIcon" instead of "self" in the handler it would have worked.
    Last edited by Imhothar; 07-11-2013 at 01:19 PM.
    Author of the Imhothar's Bags addon.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts