Tuller / FlyPaper

Library for sticking frames together
2 stars 1 forks source link

Multi-Addon Support #1

Open Goranaws opened 4 years ago

Goranaws commented 4 years ago

Would it be possible to create a variant of FlyPaper that would allow frames from different addons to stick to each other, seamlessly?

If we could, I'd be able to convert many of my addons to be more standalone... i'd like to rename my addons to drop the "Dominos_" prefix and decrease my heavy dependency on Dominos, but I don't want to loose the ability to have my unit frames being able to dock and stick to the action bars.

Tuller commented 4 years ago

Flypaper itself is just a helper to try and look at how close one frame is to another and anchor relative to the other frame if possible. It’s not Dominos specific.

Goranaws commented 4 years ago

I realize its not Dominos specific, but two separate addons using FlyPaper can't currently stick to each other.

Tuller commented 4 years ago

They could, if they knew about each other. That'll require the following bits. Something like this maybe:

Goranaws commented 4 years ago

I've begun work on this. I need to do some more testing after the servers reset, but I believe that I have a functional system(mostly). It still needs a few more touches, but the heavy lifting is done. Would you like me to send you what I have so far? It would be awesome if we could have Bagnon working with FlyPaper!

p.s. I look forward to being able to disassociate my addons from Dominos, and removing the confusion for users! I've tested it with Dominos and one of my own addons(that's never relied on Dominos), and it is allowing them to stick to each other.

Tuller commented 4 years ago

Jaliborc would be the maintainer of Bagnon. If you have a demo/branch of your stuff , feel free to link it and i can take a look.

Goranaws commented 4 years ago

I would love to post a fork on Github, but i can seem to get it to allow me to commit changes through the web. So here's a link to pastebin: https://pastebin.com/fMH1LXn

Goranaws commented 4 years ago

Do note that i only began work on this yesterday, so it's still an early version. And do feel free to make any changes you desire

Tuller commented 4 years ago

That link doesn't take me anywhere.

At the very least, this will be a new repo and possibly a LibFlyPaper-2.0 situation.

Goranaws commented 3 years ago

That was my intention: 2.0

For whatever reason, I'm having trouble with github letting my post new commits for anything. I can make edits, but the commit button never becomes clickable.

Currently traveling a few hours today. I'll see if I can post something properly tonight.

Goranaws commented 3 years ago

Well, my current account is having issues, and I can't find a way to actually contact GitHub support, so I made a new account just to post 2.0.

https://github.com/Swanarog/LibFlyPaper-2.0

Goranaws commented 3 years ago

My latest update includes a readme file, it is a detailed explanation of my code. Hopefully you can decipher what I've written. :-)

Goranaws commented 3 years ago

I would like to begin transitioning my add-ons away from reliance on Dominos soon, if we can get this finalized..

Tuller commented 3 years ago

Sorry for the delay on this,. I've been busy, and because of the pandemic work from home now. Sometimes I don't really want to work on code at home after an entire day of working on code at home.

When you do something like this (modifying built in frame methods), you need to be very careful. In the case of SetPoint

frame.oldSetPoint = frame.SetPoint
function frame:SetPoint(...)
   -- things
end

This will cause issues with frame tainting (see https://wow.gamepedia.com/Secure_Execution_and_Tainting). Lots of things will break in combat scenarios (even though we normally don't move frames until out of combat). If you want to react to a SetPoint or other frame method call, I would do something like this:

hooksecurefunc(frame, 'SetPoint', function(...)
 -- do stuff after set point is called
end)

If you want to do something different that might call it, maybe an API like this?

function LibFlyPaper:SetPoint(frame, ...)
 --- stuff
 frame:SetPoint(...)
end

If you want to continue the mixin approach, you'd need to do something like this:

function FlyPaperMixin:FlyPaperSetPoint(...)
 --- stuff
 self:SetPoint(...)
end

That is, you'd want a custom method name so that we don't stomp om the normal frame widget API

I would also investigate callbacks for notifying other add-ons when things have changed, so they can react, so say when someone registers a new addon frame they could do something like this:

LibFlyPaper.RegisterCallback(CoolAddon, 'OnFrameAdded')

function CoolAddon:OnFrameAdded(msg, frame)
   -- reposition our stuff that may be dependent on frame existing
end

That's probably more of something that will be a nice to have later than anything. I can think of cases where a frame may not exist immediately and then is created later.

Finally, you might also want to look at LibWindow. Other addons use that for frame movement/positioning (like Bartender4). It doesn't have the sticky behavior of FlyPaper but it might be worth reading through for API design inspiration

Goranaws commented 3 years ago

I've made the suggested changes. Now using secure hooks instead of overwrites, and changed away from the mixin approach.

Tuller commented 3 years ago

So see this, https://github.com/Tuller/FlyPaper/blob/registry/LibFlyPaper-1.1.lua

The main additions are AddFrame/RemoveFrame, and StickToClosestFrame. The latter will iterate through all frames, figure out which one is closest, and then attach to it. I also gave priority to frames on the same strata, and frames that belong to the same addon.

Goranaws commented 3 years ago

How does it restore frame anchoring between addons, after a reload? if I anchor a frame from addon A to one from addon B, will they still be anchored after a reload, or just positioned near each other?

Goranaws commented 3 years ago

Would it be possible to include frame repositioning and reanchoring, as to guarantee that all frames from all addons are re-anchoring too each other beween sessions? if left to each individual addon, I think it'd harder to make consistent.

Tuller commented 3 years ago

I don't think that FlyPaper should be in charge of saving/restoring frame positions, but that the screen edge snapping should be added. For the purposes of resticking, I'm thinking of something like this:

-- when the frame is activated
LibFyPaper.RegisterCallback(frame, "OnFlyPaperFrameAdded")
LibFyPaper.RegisterCallback(frame, "OnFlyPaperFrameRemove")

function Frame:OnFlyPaperFrameAdded(msg, frame, group, key)
   if self:GetAnchorFrame() == frame then
   -- restick
   end
end

function Frame:OnFlyPaperFrameRemoved(msg, frame, group, key)
   if self:GetAnchorFrame() == frame then
   -- unstick
   end
end

That is, you can restick to a frame as soon as flypaper knows about it.