comparison 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
comparison
equal deleted inserted replaced
92:4370eefcecdd 93:f6fae1a4c66c
6 -- Docking and arrangement calls 6 -- Docking and arrangement calls
7 local _, D = ... 7 local _, D = ...
8 local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight 8 local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight
9 local db 9 local db
10 local print = D.print 10 local print = D.print
11 local DOCK_BUTTON_PADDING = 6
12
13 DevianDockButtonMixin = {}
14
15 --- Updates region visibility as needed
16 local getFadeInArgs = function(sign, region)
17 --print('Dvn', region)
18 local db = D.db
19 local alph = region:GetAlpha()
20 local a = (db[sign..'_alpha_on'] - alph)
21 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
22 local dur = (a / b) * db[sign..'_fade_in']
23 return dur, alph, db[sign..'_alpha_on']
24 end
25
26 local getFadeOutArgs = function(sign, region)
27 local db = D.db
28 local alph = region:GetAlpha()
29 local a = (alph - db[sign..'_alpha_off'])
30 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
31 local dur = (a / b) * db[sign..'_fade_out']
32 return dur, alph, db[sign..'_alpha_off']
33 end
34
35 local function queueFade (self, duration, from, to)
36 self:SetAlpha(to)
37 end
38
39 local numBeacons = 0
40 function D:GetDockButton(console)
41 self.dock.usedButtons = self.dock.usedButtons or {}
42
43 local button = self.dock.usedButtons[console.index]
44 if not button then
45 numBeacons = numBeacons + 1
46 button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianBeacon')
47 button.color = {r = math.random(), g = math.random(), b = math.random()}
48 button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1)
49 button.console = console
50 self.dock.usedButtons[console.index] = button
51 tinsert(self.dock.buttons, button)
52 end
53 button.index = console.index
54 button.caption.name:SetText(console.signature)
55 button:SetShown(true)
56 return button
57 end
58
59 function DevianDockButtonMixin:OnMouseDown(button)
60 --print("click", self:GetName(), button, self.console.index)
61 if button == "LeftButton" then
62 if IsShiftKeyDown() then
63 D:Console_Toggle(self.console.index, 0)
64 else
65 if self.console.index == D.currentProfile.current_channel or (not self.console.enabled) then
66 D:Console_Toggle(self.console.index)
67 if self.console.enabled then
68 if self.console.minimized then
69 self.console:MinMax()
70 end
71 self.console:ToFront()
72 end
73 else
74 self.console:ToFront()
75 end
76 end
77 elseif button == "RightButton" then
78 self.console:MinMax()
79 end
80 self.console:Save()
81 end
82 function DevianDockButtonMixin:OnShow()
83 self:Update()
84 end
85 function DevianDockButtonMixin:OnEnter()
86 end
87 function DevianDockButtonMixin:Update()
88 local db = D.db
89 local isActive = (self.raised or self.selected or self.newMessage)
90
91 if (self.showName or isActive) then
92 self.caption:SetAlpha(1)
93 else
94 self.caption:SetAlpha(0.5)
95 end
96
97 if self.selected then
98 self.Background:SetColorTexture(0.4,0.4,0.4,1)
99 else
100 self.Background:SetColorTexture(0,0,0,.5)
101 end
102
103 if (not self.showName) and (not isActive) then
104 --print(self:GetName(), 'no name no active, fade out')
105 self:SetAlpha(0.5)
106 else
107 self:SetAlpha(1)
108 end
109
110 self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING)
111 end
112
113 function DevianDockButtonMixin:Select()
114 self.caption.pulse:Stop()
115 self:Update()
116 end
11 117
12 --- Spaces each frame evenly across the screen. 118 --- Spaces each frame evenly across the screen.
13 function D:DistributeFrames() -- 119 function D:DistributeFrames() --
14 local max = self.num_channels 120 local max = self.num_channels
15 local num_side = ceil(sqrt(max)) 121 local num_side = ceil(sqrt(max))
40 frame:Save() 146 frame:Save()
41 last = frame 147 last = frame
42 end 148 end
43 end 149 end
44 150
151 function D:Dock_OnMouseWheel(delta)
152 if delta >= 1 then
153 D.dockScale = (D.dockScale or 1) - 0.1
154 else
155 D.dockScale = (D.dockScale or 1) + 0.1
156 end
157 D:UpdateDock()
158 end
45 159
46 --- Space everything and set the dock size 160 --- Space everything and set the dock size
47 function D:UpdateDock() 161 function D:UpdateDock()
48 local pad_offset = 12 162 local pad_offset = 12
49 local draw_offset = pad_offset 163 local drawWidth = 0
164 local lastButton
165 local numButtons = 0
166 for i, d in ipairs(self.dock.buttons) do
167 if d and d:IsShown() then
168 d:SetScale(D.dockScale or 1)
169 if lastButton then
170 d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0)
171 else
172 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', pad_offset, 0)
173 end
50 174
51 local dockn = 1 175 drawWidth = drawWidth + d:GetWidth() + pad_offset
52 for i, d in pairs(self.dock.buttons) do 176 lastButton = d
53 dockn = max(i, dockn) 177 numButtons = numButtons + 1
54 end 178 print(numButtons)
55 for i = 1, dockn do
56 local d = self.dock.buttons[i]
57 if d then
58 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0)
59 draw_offset= draw_offset + d:GetWidth() + pad_offset
60 end 179 end
61 end 180 end
62 self.dock:SetWidth(draw_offset) 181 self.numButtons = numButtons
182 self.dock:SetWidth(drawWidth)
183 self.db.dockPoint = self.db.dockPoint or 'TOP'
184 self.dock:SetPoint(self.db.dockPoint, UIParent, self.db.dockPoint, 0, 0)
63 end 185 end
64 186
65 --- Updates region visibility as needed
66 local getFadeInArgs = function(sign, region)
67 --print('Dvn', region)
68 local db = D.db
69 local alph = region:GetAlpha()
70 local a = (db[sign..'_alpha_on'] - alph)
71 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
72 local dur = (a / b) * db[sign..'_fade_in']
73 return dur, alph, db[sign..'_alpha_on']
74 end
75
76 local getFadeOutArgs = function(sign, region)
77 local db = D.db
78 local alph = region:GetAlpha()
79 local a = (alph - db[sign..'_alpha_off'])
80 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
81 local dur = (a / b) * db[sign..'_fade_out']
82 return dur, alph, db[sign..'_alpha_off']
83 end
84
85 local function queueFade (self, duration, from, to)
86 self:SetAlpha(to)
87 end
88
89 function D.UpdateBeacon(beacon)
90 local db = D.db
91 local isActive = (beacon.raised or beacon.selected or beacon.newMessage)
92 if isActive then
93 --print(beacon:GetName(), 'active, fade in')
94 queueFade(beacon, getFadeInArgs('dock_button', beacon))
95 end
96
97 if beacon.showName or isActive then
98 --print(beacon:GetName(), 'show name, fade in name')
99 queueFade(beacon.caption, getFadeInArgs('dock_button', beacon.caption))
100 end
101
102 if not isActive then
103 queueFade(beacon, getFadeOutArgs('dock_button', beacon))
104 end
105
106 if (not beacon.showName) and (not isActive) then
107 --print(beacon:GetName(), 'no name no active, fade out')
108 queueFade(beacon.caption,getFadeOutArgs('dock_button', beacon.caption))
109 end
110 end
111 187
112 local function FrameFade(frame) 188 local function FrameFade(frame)
113 if not D.fader then 189 if not D.fader then
114 D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn') 190 D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn')
115 end 191 end
116 end 192 end
117
118 --- Dock interaction framescript
119 function D.DockHighlight(beacon)
120 db = D.db
121 local self = D.dock
122 local mouseOverDock = false
123 if self:IsMouseOver() then
124 mouseOverDock = true
125 end
126
127 if beacon then
128 --print(beacon:GetName(), ' highlighter got beacon')
129 mouseOverDock = true
130 if not beacon.raised then
131 --print(beacon:GetName(), ' beacon not raised')
132 beacon.raised = true
133 D.UpdateBeacon(beacon)
134
135 -- IsMouseOver can still return false during its frame's OnEnter
136 beacon.inc = 0
137 beacon:SetScript('OnUpdate', function(self)
138 if not self:IsMouseOver() then
139 self.inc = self.inc + 1
140 --print(self:GetName(),self.inc)
141 if self.inc > 10 then
142 --print(self:GetName(), 'lost mouseover, terminating OnUpdate')
143 self.raised = nil
144 D.UpdateBeacon(self)
145 self:SetScript('OnUpdate', nil)
146 end
147 end
148 end)
149 end
150 elseif beacon.raised and beacon.index ~= db.current_channel then
151 beacon.raised = nil
152 D.UpdateBeacon(beacon)
153 --beacon:SetScript('OnUpdate', nil)
154 end
155
156 if mouseOverDock then
157 -- Raise it up
158 if not self.raised then
159
160 self.raised = true
161 queueFade(self, getFadeInArgs('dock', self))
162 end
163 elseif self.raised then
164 -- Drop it down
165 self.raised = nil
166 queueFade(self, getFadeOutArgs('dock', self))
167 for k, v in pairs(self.buttons) do
168 v.raised = nil
169 D.UpdateBeacon(v)
170 end
171 end
172
173 end