Mercurial > wow > devian
view Dock.lua @ 93:f6fae1a4c66c v2.2.95-rc1
- revision and simplification dock layout
- fixed character-specific addon choices getting erroneously toggled
The XML template was missing header information; that has been filled in, and it should be easier to catch problems arising from that area.
author | Nenue |
---|---|
date | Wed, 19 Oct 2016 16:47:38 -0400 |
parents | 3745540e8996 |
children | 33bc8baba858 |
line wrap: on
line source
--- Devian - Dock.lua -- @file-author@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 12/26/2015 12:32 PM -- Docking and arrangement calls local _, D = ... local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight local db local print = D.print local DOCK_BUTTON_PADDING = 6 DevianDockButtonMixin = {} --- Updates region visibility as needed local getFadeInArgs = function(sign, region) --print('Dvn', region) local db = D.db local alph = region:GetAlpha() local a = (db[sign..'_alpha_on'] - alph) local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) local dur = (a / b) * db[sign..'_fade_in'] return dur, alph, db[sign..'_alpha_on'] end local getFadeOutArgs = function(sign, region) local db = D.db local alph = region:GetAlpha() local a = (alph - db[sign..'_alpha_off']) local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) local dur = (a / b) * db[sign..'_fade_out'] return dur, alph, db[sign..'_alpha_off'] end local function queueFade (self, duration, from, to) self:SetAlpha(to) end local numBeacons = 0 function D:GetDockButton(console) self.dock.usedButtons = self.dock.usedButtons or {} local button = self.dock.usedButtons[console.index] if not button then numBeacons = numBeacons + 1 button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianBeacon') button.color = {r = math.random(), g = math.random(), b = math.random()} button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1) button.console = console self.dock.usedButtons[console.index] = button tinsert(self.dock.buttons, button) end button.index = console.index button.caption.name:SetText(console.signature) button:SetShown(true) return button end function DevianDockButtonMixin:OnMouseDown(button) --print("click", self:GetName(), button, self.console.index) if button == "LeftButton" then if IsShiftKeyDown() then D:Console_Toggle(self.console.index, 0) else if self.console.index == D.currentProfile.current_channel or (not self.console.enabled) then D:Console_Toggle(self.console.index) if self.console.enabled then if self.console.minimized then self.console:MinMax() end self.console:ToFront() end else self.console:ToFront() end end elseif button == "RightButton" then self.console:MinMax() end self.console:Save() end function DevianDockButtonMixin:OnShow() self:Update() end function DevianDockButtonMixin:OnEnter() end function DevianDockButtonMixin:Update() local db = D.db local isActive = (self.raised or self.selected or self.newMessage) if (self.showName or isActive) then self.caption:SetAlpha(1) else self.caption:SetAlpha(0.5) end if self.selected then self.Background:SetColorTexture(0.4,0.4,0.4,1) else self.Background:SetColorTexture(0,0,0,.5) end if (not self.showName) and (not isActive) then --print(self:GetName(), 'no name no active, fade out') self:SetAlpha(0.5) else self:SetAlpha(1) end self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING) end function DevianDockButtonMixin:Select() self.caption.pulse:Stop() self:Update() end --- Spaces each frame evenly across the screen. function D:DistributeFrames() -- local max = self.num_channels local num_side = ceil(sqrt(max)) local w = GetScreenWidth() / num_side local h = GetScreenHeight() / num_side for i, frame in pairs(D.console) do local dx = (i-1) % num_side local dy = floor((i-1) / num_side) frame.width = w frame.height = h frame.x = dx * w frame.y = -(dy * h) frame:Save() end end --- Place all frames stacked beneath the primary frame. function D:StackFrames() local last for _, frame in pairs(self.console) do if last then frame.x = last.x frame.y = last.y - 20 else frame.x = (GetScreenWidth()-frame:GetWidth())/2 frame.y = 0 end frame:Save() last = frame end end function D:Dock_OnMouseWheel(delta) if delta >= 1 then D.dockScale = (D.dockScale or 1) - 0.1 else D.dockScale = (D.dockScale or 1) + 0.1 end D:UpdateDock() end --- Space everything and set the dock size function D:UpdateDock() local pad_offset = 12 local drawWidth = 0 local lastButton local numButtons = 0 for i, d in ipairs(self.dock.buttons) do if d and d:IsShown() then d:SetScale(D.dockScale or 1) if lastButton then d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0) else d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', pad_offset, 0) end drawWidth = drawWidth + d:GetWidth() + pad_offset lastButton = d numButtons = numButtons + 1 print(numButtons) end end self.numButtons = numButtons self.dock:SetWidth(drawWidth) self.db.dockPoint = self.db.dockPoint or 'TOP' self.dock:SetPoint(self.db.dockPoint, UIParent, self.db.dockPoint, 0, 0) end local function FrameFade(frame) if not D.fader then D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn') end end