Mercurial > wow > buffalo2
changeset 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 |
files | Modules/WorldState.lua Modules/WorldState.xml Veneer.lua Veneer.xml |
diffstat | 4 files changed, 195 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/Modules/WorldState.lua Wed Oct 19 16:51:17 2016 -0400 +++ b/Modules/WorldState.lua Thu Oct 20 04:08:11 2016 -0400 @@ -63,8 +63,6 @@ function VeneerWorldStateMixin:OnLoad () self.modules = {self:GetChildren()} print('|cFFFFFF00'..self:GetName()..'|r!') - self:RegisterEvent('ARTIFACT_UPDATE') - self:RegisterEvent('ARTIFACT_XP_UPDATE') self:RegisterEvent('PLAYER_ENTERING_WORLD') self:RegisterEvent('PLAYER_REGEN_ENABLED') self:RegisterEvent('PLAYER_REGEN_DISABLED') @@ -80,13 +78,7 @@ function VeneerWorldStateMixin:OnEvent(event, arg) print(event, arg) - - if event == 'PLAYER_LOGIN' then - if IsLoggedIn() and not self.initialized then - self.initialized = true - self:Setup() - end - elseif event == 'ZONE_CHANGED_NEW_AREA' or event == 'ADDON_LOADED' then + if event == 'ZONE_CHANGED_NEW_AREA' or event == 'ADDON_LOADED' then if OrderHallCommandBar then self:UnregisterEvent('ZONE_CHANGED_NEW_AREA') self:UnregisterEvent('ADDON_LOADED') @@ -101,18 +93,19 @@ end end -function VeneerWorldStateMixin:Update() +function VeneerWorldStateMixin:Update(isBatchUpdate) print('|cFFFFFF00All:Update()|r') - for i, frame in ipairs(self.modules) do + for index, frame in ipairs(self.modules) do if frame.Update then - print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') - frame:Update() + print(' '..index..' |cFFFF00FFUpdate:|r '.. frame:GetName()) + frame:Update(isBatchUpdate) + print(' ', frame:IsVisible(), frame:IsShown()) end end end function VeneerWorldStateMixin:Reanchor(isUpdate) - print('|cFFFFFF00'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') + print(' |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') self.maxHeight = 0 for i, frame in ipairs(self.modules) do print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) @@ -141,12 +134,28 @@ function VeneerOrderHallMixin:Setup() print('|cFFFFFF00'..self:GetName()..':Setup()') - hooksecurefunc(OrderHallCommandBar,'Show', function() - self:Update() - end) - hooksecurefunc(OrderHallCommandBar,'Hide', function() - self:Update() - end) + self:SetParent(OrderHallCommandBar) + self:RegisterEvent("ZONE_CHANGED"); + self:RegisterEvent("ZONE_CHANGED_INDOORS"); + self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); + self:SetShown(true) +end + +function VeneerOrderHallMixin:OnEvent(event, ...) + + print('|cFF00AAFF'..self:GetName()..'|r:'.. event, ...) + self:Update() +end + +function VeneerOrderHallMixin:OnShow() + print('|cFF00AAFF'..self:GetName()..'|r:OnShow()', OrderHallCommandBar:IsShown(), self:IsShown()) + self:Update() + Veneer:InternalReanchor(self) +end + +function VeneerOrderHallMixin:OnHide() + print('|cFF00AAFF'..self:GetName()..'|r:OnHide()', OrderHallCommandBar:IsShown(), self:IsShown()) + Veneer:Reanchor() end function VeneerOrderHallMixin:Update() @@ -156,15 +165,17 @@ return end - print('|cFF0044FF'..self:GetName()..' update') OrderHallCommandBar:ClearAllPoints() - OrderHallCommandBar:SetPoint('TOP', self, 'TOP') + OrderHallCommandBar:SetPoint('TOP', UIParent, 'TOP') OrderHallCommandBar:SetWidth(600) OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) OrderHallCommandBar.WorldMapButton:Hide() OrderHallCommandBar:EnableMouse(false) + self:SetSize(OrderHallCommandBar:GetSize()) - self:SetSize(OrderHallCommandBar:GetSize()) + print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown()) + print(debugstack(6)) + end function VeneerWorldStateCurrencyMixin:OnLoad () @@ -183,7 +194,7 @@ end -function VeneerWorldStateCurrencyMixin:Update() +function VeneerWorldStateCurrencyMixin:Update(isBatchUpdate) print(' Zone:', GetZoneText()) if GetZoneText() == 'Suramar' then @@ -296,7 +307,7 @@ self.ProgressFlash:Play() end -function VeneerWorldStateProgressMixin:Update() +function VeneerWorldStateProgressMixin:Update(isBatchUpdate) local hasNewInfo = false local progressChange = false print(' current mode:', self.mode) @@ -320,7 +331,7 @@ end hasNewInfo = (self.progressAmount ~= xp) progressChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) - self.progressOverflow = bonusXP + self.progressOverflow = bonusXP or 0 self.progressAmount = xp self.progressMax = xpMax @@ -329,7 +340,7 @@ if itemID then local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 - print(' C_AUI:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) + print(' API:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) hasNewInfo = (self.progressAmount ~= totalXP) progressChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) @@ -348,6 +359,7 @@ self.progressAmount = totalXP self.progressMax = nextRankCost else + self.progressOverflow = 0 self.progressAmount = 0 self.progressMax = 1 self.progressText = '' @@ -371,11 +383,9 @@ end - print(self:IsVisible()) - print(self:GetWidth()) - print(self.ProgressBG:GetWidth()) - print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) + print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown()) + print(' Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth()) if progressChange then self:AnimateProgress(progressChange) @@ -390,9 +400,9 @@ self.progressLeft = self.progressMax - self.progressAmount if self.progressOverflow >= self.progressLeft then + self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) + else self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', (self.progressOverflow / self.progressMax) * self:GetWidth(), 0) - else - self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) end else @@ -469,6 +479,7 @@ end function WorldStateBlockMixin:Setup() print('|cFF0088FF'..self:GetName()..':Setup()|r -- nop') + self:Update() end function WorldStateBlockMixin:Reset() print('|cFF0088FF'..self:GetName()..':Reset()')
--- a/Modules/WorldState.xml Wed Oct 19 16:51:17 2016 -0400 +++ b/Modules/WorldState.xml Thu Oct 20 04:08:11 2016 -0400 @@ -3,7 +3,7 @@ <Script file="WorldState.lua" /> - <Frame name="VeneerWorldState" mixin="VeneerWorldStateMixin" parent="UIParent" inherits="VeneerMixinScripts"> + <Frame name="VeneerWorldState" mixin="VeneerWorldStateMixin" parent="UIParent" inherits="VeneerMixinScripts, VeneerAnimations"> <Anchors> <Anchor point="TOP" /> </Anchors> @@ -118,7 +118,7 @@ </Layers> </Frame> - <Frame name="$parentZoneCurrency" parentKey="ZoneCurrency" mixin="VeneerWorldStateCurrencyMixin" hidden="true" inherits="VeneerMixinScripts"> + <Frame name="$parentZoneCurrency" parentKey="ZoneCurrency" mixin="VeneerWorldStateCurrencyMixin" hidden="true" inherits="VeneerMixinScripts, VeneerAnimations"> <Anchors> <Anchor point="TOPRIGHT" /> </Anchors> @@ -141,8 +141,9 @@ </Layer> </Layers> </Frame> + </Frames> </Frame> + <Frame name="VeneerOrderHallHandler" hidden="true" parent="UIParent" mixin="VeneerOrderHallMixin" inherits="VeneerMixinScripts" /> - <Frame name="VeneerOrderHallHandler" parent="UIParent" mixin="VeneerOrderHallMixin" inherits="VeneerMixinScripts" /> </Ui> \ No newline at end of file
--- 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
--- a/Veneer.xml Wed Oct 19 16:51:17 2016 -0400 +++ b/Veneer.xml Thu Oct 20 04:08:11 2016 -0400 @@ -16,6 +16,19 @@ <Color a="1" r="1" g="0.4" b="0" /> </Font> + <Frame name="VeneerAnimations" virtual="true"> + + <Animations> + <AnimationGroup parentKey="BlockFade" looping="NONE" setToFinalAlpha="false"> + <Alpha parentKey="alpha" order="1" duration="1" fromAlpha="0.5" toAlpha="1" /> + <Scripts> + <OnPlay> + VeneerAnimationMixin.OnPlay(self) + </OnPlay> + </Scripts> + </AnimationGroup> + </Animations> + </Frame> <Frame name="VeneerMixinScripts" virtual="true"> <Scripts>