Mercurial > wow > devian
comparison Dock.lua @ 50:c3166f700438
dock beacons and text fader cleaned up
fixed OnLeave ending at mouseOverDock false and causing beacons to stick
fixed a nil argument in dock framescript
| author | Nenue |
|---|---|
| date | Tue, 05 Jan 2016 01:37:29 -0500 |
| parents | 2bf7eb1844cb |
| children | 0a9a6740ea5d |
comparison
equal
deleted
inserted
replaced
| 49:36290c315606 | 50:c3166f700438 |
|---|---|
| 1 --- ${PACKAGE_NAME} | 1 --- Devian - Dock.lua |
| 2 -- @file-author@ | 2 -- @file-author@ |
| 3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 -- Created: 12/26/2015 12:32 PM | 5 -- Created: 12/26/2015 12:32 PM |
| 6 -- Dock management functions | 6 -- Docking and arrangement calls |
| 7 | 7 |
| 8 local D = LibStub("AceAddon-3.0"):GetAddon("Devian") | 8 local D = LibStub("AceAddon-3.0"):GetAddon("Devian") |
| 9 local _G = _G | 9 local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight |
| 10 local UIFrameFadeIn, UIFrameFadeOut = UIFrameFadeIn, UIFrameFadeOut | |
| 10 local db | 11 local db |
| 11 | |
| 12 local function Dock_MenuClick() end | |
| 13 | |
| 14 local function Dock_MouseDown(self, button, up) | |
| 15 end | |
| 16 local function Dock_MouseUp (self, button) | |
| 17 Dock_MouseDown(self, button, true) | |
| 18 end | |
| 19 | |
| 20 --- Adjusts frame element alignments | |
| 21 local function PrepareForDock (frame, draw_x) | |
| 22 frame.left:SetPoint('TOPLEFT', frame.out, 'TOPLEFT', -2, 0) | |
| 23 frame.left:SetPoint('BOTTOMRIGHT', frame.out, 'BOTTOMLEFT', 0, 0) | |
| 24 frame.topleft:SetPoint('BOTTOMRIGHT', frame.out, 'TOPLEFT', 0, 0) | |
| 25 frame.top: SetPoint('TOPLEFT', frame.out, 'TOPLEFT', 0, 2) | |
| 26 frame.top:SetPoint('BOTTOMRIGHT', frame.out, 'TOPRIGHT', 0, 0) | |
| 27 frame.topright:SetPoint('BOTTOMLEFT', frame.out, 'TOPRIGHT', 0, 0) | |
| 28 frame.right:SetPoint('TOPLEFT', frame.out, 'TOPRIGHT', 0, 0) | |
| 29 frame.header:SetWidth(frame.header:GetStringWidth() * 1.2) | |
| 30 frame.header:SetPoint('TOPLEFT', frame, 'TOPLEFT', draw_x+4, 0) | |
| 31 frame.titlebar:SetPoint('TOPLEFT', frame.header, 'TOPLEFT', -4, 0) | |
| 32 frame.titlebar:SetPoint('TOPRIGHT', frame.header, 'TOPRIGHT', 0, 0) | |
| 33 | |
| 34 return (draw_x + frame.header:GetStringWidth() * 1.2 + 4) | |
| 35 end | |
| 36 | |
| 37 | |
| 38 --- Docks frames together | |
| 39 -- @param target frame on which to dock | |
| 40 -- @param ... frame objects to be docked | |
| 41 -- | |
| 42 function D:DockFrame(...) | |
| 43 local target = D.console[select(1,...)] | |
| 44 if target.dockedTo then | |
| 45 local t = D.c[target.dockedTo] | |
| 46 --print('channel',target.index,target.signature, 'is docked to',t.index, t.signature..'. using that instead') | |
| 47 target = D.console[target.DockedTo] | |
| 48 end | |
| 49 | |
| 50 target.docked = {} | |
| 51 local draw_x = PrepareForDock(target, 4) | |
| 52 for i = 2, select('#', ...) do | |
| 53 local frame = D.console[select(i, ...)] | |
| 54 frame.dockedTo = target.index | |
| 55 width, draw_x = MorphToDock (frame, draw_x) | |
| 56 table.insert(target.docked, frame.index) | |
| 57 frame:ClearAllPoints() | |
| 58 frame:SetPoint('TOPLEFT', target, 'TOPLEFT', 0, 0) | |
| 59 frame:SetSize(target:GetWidth(), target:GetHeight()) | |
| 60 frame.x = nil | |
| 61 frame.y = nil | |
| 62 frame.width = nil | |
| 63 frame.height = nil | |
| 64 frame.scriptsMD = frame:GetScript('OnMouseDown') | |
| 65 frame.scriptsMU = frame:GetScript('OnMouseUp') | |
| 66 frame:SetScript('OnMouseDown', nil) | |
| 67 frame:SetScript('OnMouseUp', nil) | |
| 68 frame:Save() | |
| 69 end | |
| 70 end | |
| 71 | 12 |
| 72 --- Spaces each frame evenly across the screen. | 13 --- Spaces each frame evenly across the screen. |
| 73 function D:DistributeFrames() -- | 14 function D:DistributeFrames() -- |
| 74 --print('frame grid:', max, num_side) | 15 local max = self.num_channels |
| 75 local max = self.num_channels | 16 local num_side = ceil(sqrt(max)) |
| 76 local num_side = math.ceil(math.sqrt(max)) | 17 local w = GetScreenWidth() / num_side |
| 77 local w = GetScreenWidth() / num_side | 18 local h = GetScreenHeight() / num_side |
| 78 local h = GetScreenHeight() / num_side | 19 for i, frame in pairs(D.console) do |
| 79 for i, frame in pairs(D.console) do | 20 local dx = (i-1) % num_side |
| 80 local dx = (i-1) % num_side | 21 local dy = floor((i-1) / num_side) |
| 81 local dy = math.floor((i-1) / num_side) | 22 frame.width = w |
| 82 | 23 frame.height = h |
| 83 --print('move:', frame.signature, 'dx=', dx, 'dy=', dy) | 24 frame.x = dx * w |
| 84 --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w) | 25 frame.y = -(dy * h) |
| 85 frame.width = w | 26 frame:Save() |
| 86 frame.height = h | 27 end |
| 87 frame.x = dx * w | |
| 88 frame.y = -(dy * h) | |
| 89 frame:Save() | |
| 90 end | |
| 91 | |
| 92 end | 28 end |
| 93 | 29 |
| 94 --- Place all frames stacked beneath the primary frame. | 30 --- Place all frames stacked beneath the primary frame. |
| 95 function D:StackFrames() | 31 function D:StackFrames() |
| 96 local last | 32 local last |
| 97 for i, frame in pairs(self.console) do | 33 for _, frame in pairs(self.console) do |
| 98 if last then | 34 if last then |
| 99 frame.x = last.x | 35 frame.x = last.x |
| 100 frame.y = last.y - 20 | 36 frame.y = last.y - 20 |
| 101 else | 37 else |
| 102 frame.x = (GetScreenWidth()-frame:GetWidth())/2 | 38 frame.x = (GetScreenWidth()-frame:GetWidth())/2 |
| 106 last = frame | 42 last = frame |
| 107 end | 43 end |
| 108 end | 44 end |
| 109 | 45 |
| 110 | 46 |
| 111 --- | 47 --- Space everything and set the dock size |
| 112 function D:UpdateDock() | 48 function D:UpdateDock() |
| 113 local pad_offset = 12 | 49 local pad_offset = 12 |
| 114 local draw_offset = pad_offset | 50 local draw_offset = pad_offset |
| 115 for i = 1, #self.dock.buttons do | 51 for i = 1, #self.dock.buttons do |
| 116 local d = self.dock.buttons[i] | 52 local d = self.dock.buttons[i] |
| 117 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0) | 53 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0) |
| 118 draw_offset= draw_offset + d:GetWidth() + pad_offset | 54 draw_offset= draw_offset + d:GetWidth() + pad_offset |
| 119 end | 55 end |
| 56 self.dock:SetWidth(draw_offset) | |
| 57 end | |
| 120 | 58 |
| 121 self.dock:SetWidth(draw_offset) | 59 --- Updates region visibility as needed |
| 60 local getFadeInArgs = function(sign, region) | |
| 61 --print('Dvn', region) | |
| 62 local db = D.db | |
| 63 local alph = region:GetAlpha() | |
| 64 local a = (db[sign..'_alpha_on'] - alph) | |
| 65 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) | |
| 66 local dur = (a / b) * db[sign..'_fade_in'] | |
| 67 return dur, alph, db[sign..'_alpha_on'] | |
| 68 end | |
| 69 | |
| 70 local getFadeOutArgs = function(sign, region) | |
| 71 local db = D.db | |
| 72 local alph = region:GetAlpha() | |
| 73 local a = (alph - db[sign..'_alpha_off']) | |
| 74 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) | |
| 75 local dur = (a / b) * db[sign..'_fade_out'] | |
| 76 return dur, alph, db[sign..'_alpha_off'] | |
| 77 end | |
| 78 | |
| 79 function D.UpdateBeacon(beacon) | |
| 80 local db = D.db | |
| 81 local isActive = (beacon.raised or beacon.selected) | |
| 82 if isActive then | |
| 83 UIFrameFadeIn(beacon, getFadeInArgs('dock_button', beacon)) | |
| 84 end | |
| 85 if beacon.showName or isActive then | |
| 86 UIFrameFadeIn(beacon.caption, getFadeInArgs('dock_button', beacon.caption)) | |
| 87 end | |
| 88 | |
| 89 if not isActive then | |
| 90 UIFrameFadeOut(beacon, getFadeOutArgs('dock_button', beacon)) | |
| 91 end | |
| 92 if (not beacon.showName) and (not isActive) then | |
| 93 UIFrameFadeOut(beacon.caption,getFadeOutArgs('dock_button', beacon.caption)) | |
| 94 end | |
| 122 end | 95 end |
| 123 | 96 |
| 124 --- Dock interactions | 97 --- Dock interactions |
| 125 function D.DockHighlight(beacon) | 98 function D.DockHighlight(beacon) |
| 126 db = D.db | 99 db = D.db |
| 127 --print('Dvn', 'dock mouse event', beacon) | |
| 128 local self = D.dock | 100 local self = D.dock |
| 129 local mouseOverDock | 101 local mouseOverDock |
| 130 --for i, b in pairs(self.buttons) do | |
| 131 --print('polling', i, b:GetName()) | |
| 132 if self:IsMouseOver() then | 102 if self:IsMouseOver() then |
| 133 mouseOverDock = true | 103 mouseOverDock = true |
| 134 end | 104 end |
| 135 | 105 |
| 136 | |
| 137 if beacon and beacon:IsMouseOver() then | 106 if beacon and beacon:IsMouseOver() then |
| 138 mouseOverDock = true | 107 mouseOverDock = true |
| 139 --print('mouse is over', i, b:GetName()) | |
| 140 | |
| 141 if not beacon.raised then | 108 if not beacon.raised then |
| 142 beacon.raised = true | 109 beacon.raised = true |
| 143 local a = (db.dock_button_alpha_on - self:GetAlpha()) | 110 D.UpdateBeacon(beacon) |
| 144 local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) | |
| 145 local dur = (a / b) * db.dock_button_fade_in | |
| 146 --print(a, b, db.dock_button_fade_in, dur) | |
| 147 UIFrameFadeIn(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_on) | |
| 148 UIFrameFadeIn(beacon.caption, dur,beacon:GetAlpha(),1) | |
| 149 end | 111 end |
| 150 elseif beacon.raised and beacon.index ~= db.current_channel then | 112 elseif beacon.raised and beacon.index ~= db.current_channel then |
| 151 beacon.raised = nil | 113 beacon.raised = nil |
| 152 local a = (self:GetAlpha() - db.dock_button_alpha_off) | 114 D.UpdateBeacon(beacon) |
| 153 local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) | |
| 154 local dur = (a / b) * db.dock_button_fade_out | |
| 155 --print(a, b, db.dock_button_fade_in, dur) | |
| 156 UIFrameFadeOut(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_off) | |
| 157 UIFrameFadeOut(beacon.caption, dur,beacon:GetAlpha(),0) | |
| 158 end | 115 end |
| 159 | 116 |
| 160 --end | |
| 161 --end | |
| 162 if mouseOverDock then | 117 if mouseOverDock then |
| 118 -- Raise it up | |
| 163 if not self.raised then | 119 if not self.raised then |
| 164 --print('rising') | |
| 165 self.raised = true | 120 self.raised = true |
| 166 local a = (db.dock_alpha_on - self:GetAlpha()) | 121 UIFrameFadeIn(self, getFadeInArgs('dock', self)) |
| 167 local b = (db.dock_alpha_on-db.dock_alpha_off) | |
| 168 local dur = (a / b) * db.dock_fade_in | |
| 169 --print(a, b, db.dock_fade_in, dur) | |
| 170 UIFrameFadeIn(self, dur,self:GetAlpha(),db.dock_alpha_on) | |
| 171 end | 122 end |
| 172 elseif self.raised then | 123 elseif self.raised then |
| 173 --print('dropping') | 124 -- Drop it down |
| 174 self.raised = nil | 125 self.raised = nil |
| 175 local a = (self:GetAlpha() - db.dock_alpha_off) | 126 UIFrameFadeOut(self, getFadeOutArgs('dock', self)) |
| 176 local b = (db.dock_alpha_on-db.dock_alpha_off) | |
| 177 local dur = (a / b) * db.dock_fade_out | |
| 178 --print(a, b, db.dock_fade_in, dur) | |
| 179 UIFrameFadeOut(self, dur,self:GetAlpha(),db.dock_alpha_off) | |
| 180 end | 127 end |
| 181 | 128 |
| 182 end | 129 end |
