Mercurial > wow > buffalo2
diff Veneer.lua @ 88:b107b4df7eb6
- core:DynamicReanchor
- top-down evaluation of clustered frames
- core:InternalReanchor(module)
- bottom-up evaluation of target and frames anchored to it
author | Nenue |
---|---|
date | Thu, 20 Oct 2016 04:08:11 -0400 |
parents | 27db212af783 |
children | 74e714637d6a |
line wrap: on
line diff
--- a/Veneer.lua Wed Oct 19 16:51:17 2016 -0400 +++ b/Veneer.lua Thu Oct 20 04:08:11 2016 -0400 @@ -1,14 +1,16 @@ --- Veneer --- Base framework for making things draggable. - - - +-- Veneer Custom Interface Framework +-- 1. vn OnLoad +-- 2. OnEvent where IsLoggedIn() == true +-- 3. Setup() where (not self.initialized) +-- 4. Update() +-- 5. Reanchor() SLASH_VENEER1 = "/veneer" SLASH_VENEER2 = "/vn" SlashCmdList.VENEER = function(cmd) end + VeneerCore = { Frames = {}, ConfigLayers = {}, @@ -17,10 +19,18 @@ pendingCalls = {}, } VeneerHandlerMixin = { - Reanchor = nop, + anchorPoint = 'CENTER', -- indicates the initial cluster group point --anchorPath = 'BOTTOM', -- indicates the point from which the frame is anchored in a cluster arrangement + OnHide = function() + Veneer:DynamicReanchor() + end, + OnShow = function(self) + self:Reanchor() + Veneer:StaticReanchor(self) + end } +VeneerAnimationMixin = {} local print = DEVIAN_WORKSPACE and function(...) print('Veneer', ...) end or nop local wipe = table.wipe @@ -95,6 +105,8 @@ self.DEVIAN_PNAME = 'Veneer' self:RegisterForDrag('LeftButton') + + end function VeneerCore:OnEvent(event, ...) @@ -184,9 +196,6 @@ handler:Setup() handler.initialized = true end - if handler.Update then - handler:Update() - end self:InternalReanchor(handler) end @@ -194,10 +203,12 @@ function VeneerCore:Reanchor() self:ExecuteOnClusters(nil, 'Reanchor') + self:DynamicReanchor(self) end function VeneerCore:Update() self:ExecuteOnClusters(nil, 'Update') + self:Reanchor() end -- updates anchor relations to and from the target handler @@ -205,39 +216,119 @@ end +-- Evaluates frames visibility and chains them accordingly + +function VeneerCore:DynamicReanchor(parent) + parent = parent or self + print('|cFF88FF00DynamicReanchor()') + for anchorPoint, cluster in pairs(parent.FrameClusters) do + local lastFrame + for index, frame in ipairs(cluster) do + print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible()) + if frame:IsVisible() then + anchorPoint = frame.anchorPoint + + + frame:ClearAllPoints() + if lastFrame then + frame:SetPoint(anchorPoint, lastFrame, ANCHOR_OFFSET_POINT[anchorPoint], 0, 0) + else + frame:SetPoint(anchorPoint, UIParent, anchorPoint, 0, 0) + end + lastFrame = frame + end + + end + end +end + +-- Evaluates the current visibility state and re-anchors adjacent blocks accordingly function VeneerCore:InternalReanchor(handler, printFunc) print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')') local anchorPoint = handler.anchorPath or handler.anchorPoint local anchorParent, anchorTo = UIParent, anchorPoint - for i, frame in ipairs(handler.anchorCluster) do - if frame ~= handler then - anchorParent = frame - anchorTo = ANCHOR_OFFSET_POINT[anchorPoint] + local subPoint, subTo + local nextFrame + for index, frame in ipairs(handler.anchorCluster) do - else - local nextFrame = handler.anchorCluster[i+1] - if nextFrame then + print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible()) + if frame:IsVisible() then + if frame ~= handler then + anchorParent = frame + anchorTo = ANCHOR_OFFSET_POINT[anchorPoint] - local subPoint = nextFrame.anchorPath or nextFrame.anchorPoint - local subTo = ANCHOR_OFFSET_POINT[subPoint] - nextFrame:ClearAllPoints() - nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) - print(' -- pushing '..nextFrame:GetName()..' down the anchor chain', subPoint, subTo) + else + nextFrame = handler.anchorCluster[index+1] + if nextFrame then + + subPoint = nextFrame.anchorPath or nextFrame.anchorPoint + subTo = ANCHOR_OFFSET_POINT[subPoint] + nextFrame:ClearAllPoints() + nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) + print(' -- pushing '..nextFrame:GetName()..' down the anchor chain', subPoint, subTo) + end + break end - break end end - handler:ClearAllPoints() - handler:SetPoint(anchorPoint, anchorParent, anchorTo, 0, 0) + if handler:IsVisible() then + handler:SetPoint(anchorPoint, anchorParent, anchorTo, 0, 0) + else + if anchorParent and nextFrame then + nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) + end + end + print(handler.anchorPoint, anchorParent, anchorTo) if printFunc then printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo) end +end +function VeneerCore:SlideBlock(frame, ...) + + local anchorPoint, parent, anchorTo, pX,pY = ... + print(' |cFF0088FFSlide:|r', frame, 'to', parent, pX,pY) + local qX, qY = pX, pY + local bX, bY + local dX, dY = 0, 0 + local aX, aY = frame:GetLeft(), frame:GetTop() + local str = '' + if not aX then + dY = ((anchorPoint == 'TOP') and frame:GetHeight()) or (((anchorPoint == 'BOTTOM') and -frame:GetHeight()) or 0) + dX = ((anchorPoint == 'LEFT') and -frame:GetWidth()) or (((anchorPoint == 'RIGHT') and frame:GetWidth()) or 0) + qX = pX + dX + qY = pY + dY + aX, aY = qX, qY + bX, bY = pX, pY + str = '|cFFFFFF00relative|r' + else + frame:ClearAllPoints() + + bX, bY = frame:GetLeft(), frame:GetTop() + dX, dY = (bX-aX), (bY-aY) + + str = '|cFFFFFF00existing|r' + end + + if ((dX ~= 0) or (dY ~= 0)) and frame.BlockSlide then + print(' |cFF00FF88Slide result:|r',str, dX, dY) + + frame:ClearAllPoints() + frame:SetPoint(anchorPoint, parent, anchorTo, qX, qY) + frame.BlockSlide.dX = dX + frame.BlockSlide.dY = dY + frame.BlockSlide.sourcePoint = {anchorPoint, parent, anchorTo, qX, qY} + frame.BlockSlide.destPoint = {anchorPoint, parent, anchorTo, pX,pY} + frame.BlockSlide.translation:SetOffset(dX, dY) + frame.BlockSlide:Play() + return + end end + function VeneerCore:ExecuteOnClusters(layer, method) self.parserDepth = self.parserDepth + 1 if not layer then @@ -370,6 +461,7 @@ VeneerButton_Update(self) end +-- Takes frame handle and assigns a block to it function VeneerCore:Acquire (frame, template) if not frame then print('|cFFFF4400Unable to acquire frame...|r') @@ -399,9 +491,23 @@ return veneer end -local mixin_probe = { - 'ArtifactFrame', - 'ArtifactFrameUnderlay', -} +function VeneerHandlerMixin:Reanchor (anchorAll) + if not anchorAll then + Veneer:InternalReanchor(self) + end +end +function VeneerAnimationMixin:OnPlay() + PlaySoundKitID(229) + print('|cFF00FF00Anim:OnPlay|r @', unpack(self.sourcePoint)) +end +function VeneerAnimationMixin:OnStop() + PlaySoundKitID(229) +end +function VeneerAnimationMixin:OnFinished() + PlaySoundKitID(229) + print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint)) + self:GetParent():ClearAllPoints() + self:GetParent():SetPoint(unpack(self.destPoint)) +end \ No newline at end of file