Mercurial > wow > devian
view Dock.lua @ 111:5c591d9b4029 tip
Added tag v8.0.1-20181807-1 for changeset 930922e1ec5b
author | Nenue |
---|---|
date | Wed, 18 Jul 2018 15:02:50 -0400 |
parents | 790dca545f1d |
children |
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 CreateFrame, tinsert, random = CreateFrame, tinsert, math.random local ipairs, pairs = ipairs, pairs local db local print = DEVIAN_WORKSPACE and function(...) print('DvnDock', ...) end or nop local DOCK_BUTTON_PADDING = 6 DevianDockHandler = { usedButtons = {}, buttons = {}, } DevianDockTabMixin = {} function DevianDockTabMixin:OnMouseDown(button) --print("click", self:GetName(), button, self.console.index) local console = self.console if button == "LeftButton" then if IsShiftKeyDown() then DevianDock:ToggleAll(console) else console.newMessage = nil if console.isFront or (not console.enabled) then console:Toggle() if console.enabled then if console.minimized then console:MinMax() end console:ToFront() end else console:ToFront() end end elseif button == "RightButton" then console:MinMax() end DevianDock:Update() end function DevianDockTabMixin:OnShow() self:Update() end function DevianDockTabMixin:OnEnter() end function DevianDockTabMixin:Update() local console = self.console local isActive = (console.isFront or console.newMessage) if console.newMessage and (not self.pulse:IsPlaying()) then self.pulse:Play() elseif not console.newMessage then self.pulse:Stop() 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 isActive then self:SetAlpha(1) else self:SetAlpha(0.5) end self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING) end function DevianDockTabMixin:Select() 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 do local numBeacons = 0 function DevianDockHandler:GetDockButton(console) self.usedButtons = self.usedButtons or {} local index = console:GetID() local button = self.usedButtons[index] if not button then numBeacons = numBeacons + 1 button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianDockTabTemplate') button.color = {r = random(), g = random(), b = random()} button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1) button.console = console self.usedButtons[index] = button tinsert(self.buttons, button) --oldprint('create dock', index, console.signature) end button.index = console.index button.caption.name:SetText(console.signature) button:SetShown(true) return button end end function DevianDockHandler:OnMouseWheel(delta) if delta >= 1 then self.dockScale = (self.dockScale or 1) - 0.1 else self.dockScale = (self.dockScale or 1) + 0.1 end self:Update() end --- Space everything and set the dock size function DevianDockHandler:Update() local pad_offset = 12 local drawWidth = 0 local lastButton local numButtons = 0 local numOpen = 0 local numBackground = 0 local numClosed = 0 local numMinimized = 0 for i, d in ipairs(self.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 local console = d.console if console.enabled then numOpen = numOpen + 1 if not console.isFront then numBackground = numBackground + 1 end else numClosed = numClosed + 1 end if console.minimized then numMinimized = numMinimized + 1 end d:Update() drawWidth = drawWidth + d:GetWidth() + pad_offset lastButton = d numButtons = numButtons + 1 print(numButtons) end end self.numOpen, self.numMinimized, self.numClosed, self.numButtons, self.numBackground = numOpen, numMinimized, numClosed, numButtons, numBackground self:SetWidth(drawWidth) D.db.dockPoint = D.db.dockPoint or 'TOPLEFT' self:SetPoint(D.db.dockPoint , UIParent, D.db.dockPoint , 0, 0) end function DevianDockHandler:ToggleAll(sender) local keepSender = IsShiftKeyDown() and sender local senderID = sender and sender:GetID() local op, arg = 'Toggle', false if (keepSender and (self.numBackground == 0)) or (self.numOpen == 0) then arg = true elseif self.numClosed == 0 then arg = false end for index, button in ipairs(self.buttons) do local frame = button.console if frame then if not((frame.index == senderID) and keepSender) then frame[op](frame, arg) end end end self:Update() end