comparison Console.lua @ 99:7d94df3804a7

- Console drag buttons for resizing - While dragging a console frame, other frames are ghosted out - Dropdown menu includes Toggle, Pin, and MinMax
author Nenue
date Thu, 27 Oct 2016 06:11:04 -0400
parents 33bc8baba858
children 790dca545f1d
comparison
equal deleted inserted replaced
98:33bc8baba858 99:7d94df3804a7
1 -- Mixin for console 1 -- Mixin for console
2 local _, D = ... 2 local _, D = ...
3 DevianConsoleMixin = {} 3 DevianConsoleMixin = {}
4 4
5 local print = function(...) print('Dvn', ...) end
6 function D.IterateChannels(callback, sender)
7 for index, channel in ipairs(D.console) do
8 if channel ~= sender then
9 callback(channel)
10 end
11 end
12 end
13
5 function DevianConsoleMixin:OnLoad() 14 function DevianConsoleMixin:OnLoad()
6 self:SetMaxResize(GetScreenWidth(), GetScreenHeight()) 15 self:SetMaxResize(GetScreenWidth(), GetScreenHeight())
7 self:SetMinResize(100, 24) 16 self:SetMinResize(100, 24)
8
9 self:EnableMouse(true) 17 self:EnableMouse(true)
10 self:RegisterForDrag('LeftButton') 18 self:RegisterForDrag('LeftButton')
11 self:SetMovable(true) 19 self:SetMovable(true)
12 self:SetResizable(true) 20 self:SetResizable(true)
21 self:SetClampedToScreen(true)
13 self.out:SetFont("Interface\\Addons\\Devian\\font\\SourceCodePro-Regular.ttf", 13, 'NORMAL') 22 self.out:SetFont("Interface\\Addons\\Devian\\font\\SourceCodePro-Regular.ttf", 13, 'NORMAL')
14 self.out:SetJustifyH('LEFT') 23 self.out:SetJustifyH('LEFT')
15 self.out:SetFading(false) 24 self.out:SetFading(false)
25 self.out:SetMaxLines(2048)
26
27 self:RegisterEvent('PLAYER_STARTED_MOVING')
28 self:RegisterEvent('PLAYER_STOPPED_MOVING')
29
30 UIDropDownMenu_Initialize(self.DropdownFrame, function()
31 local info = UIDropDownMenu_CreateInfo()
32 info.notCheckable = 1
33 info.text = 'Pin'
34 info.func = function() self:Pin() end
35 UIDropDownMenu_AddButton(info)
36 if self.minimized then
37 info.text = 'Maximize'
38 info.func = function() self:Maximize() end
39 else
40 info.text = 'Minimize'
41 info.func = function() self:Minimize() end
42 end
43 UIDropDownMenu_AddButton(info)
44 info.text = 'Close'
45 info.func = function() self:Toggle() end
46 UIDropDownMenu_AddButton(info)
47
48 end, 'MENU')
49 self.DropdownButton:SetScript('OnClick', function(button)
50 ToggleDropDownMenu(1, nil, self.DropdownFrame, button, 0, 0)
51 end)
16 52
17 self.width = self:GetWidth() 53 self.width = self:GetWidth()
18 self.height = self:GetWidth() 54 self.height = self:GetWidth()
19 end 55 end
20 56
25 end 61 end
26 self.Dock = DevianDock:GetDockButton(self) 62 self.Dock = DevianDock:GetDockButton(self)
27 self:Update() 63 self:Update()
28 end 64 end
29 65
30 function DevianConsoleMixin:Update() 66 local blockedType = {['table'] = true, ['function'] = true }
67 local blockedKey = {[0] = true }
68
69 -- Synchronize vars
70 function DevianConsoleMixin:Finalize()
71 local id = self:GetID()
72 for k,v in pairs(D.channels[id]) do
73 if not self[k] then
74 D.channels[id][k] = nil
75 end
76 end
77 for k,v in pairs(self) do
78 if not (blockedType[type(v)] or blockedKey[k]) then
79 if D.channels[id][k] ~= v then
80 D.channels[id][k] = v
81 end
82 end
83 end
84 end
85
86 function DevianConsoleMixin:Pin(pinned)
87 self.pinned = pinned or (not self.pinned)
88 self:Update(true)
89 end
90
91 function DevianConsoleMixin:Update(setFinal)
31 self.title:SetText(self.index..' '.. (self.signature or '?')) 92 self.title:SetText(self.index..' '.. (self.signature or '?'))
32 self:SetSize(self.width, self.height)
33 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', self.x, self.y) 93 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', self.x, self.y)
94
95 if self.minimized then
96 self:SetHeight(20)
97 self:SetMaxResize(GetScreenWidth(),20)
98 self.GripBottom:Hide()
99 self.GripSide:Hide()
100 else
101 self:SetSize(self.width, self.height)
102 self.GripBottom:Show()
103 self.GripSide:Show()
104 end
105
106
34 -- oldprint(self:GetName(), self.x, self.y) 107 -- oldprint(self:GetName(), self.x, self.y)
35 108
36 local isFront = D.currentProfile.current_channel == self.index 109 local isFront = D.currentProfile.current_channel == self.index
37 local r,g,b,a = unpack(D.db.backborder) 110 local r,g,b,a = unpack(D.db.backborder)
38 if isFront then 111 if isFront then
47 end 120 end
48 121
49 --oldprint(self:GetID(), self.enabled, self.minimized, self.x, self.y) 122 --oldprint(self:GetID(), self.enabled, self.minimized, self.x, self.y)
50 self.isFront = isFront 123 self.isFront = isFront
51 self:SetShown(self.enabled) 124 self:SetShown(self.enabled)
52 self.out:SetShown(self.enabled) 125 self.backdrop:SetShown(self.enabled)
53 end 126 self.out:SetShown((not self.minimized))
127
128
129 if setFinal then
130 self:Finalize()
131 end
132
133 end
134
54 135
55 136
56 function DevianConsoleMixin:OnShow() 137 function DevianConsoleMixin:OnShow()
57 self:Update() 138 self:Update()
58 end 139 end
83 self:Minimize() 164 self:Minimize()
84 end 165 end
85 end 166 end
86 167
87 function DevianConsoleMixin:Minimize() 168 function DevianConsoleMixin:Minimize()
88 self:SetHeight(20)
89 self:SetMaxResize(GetScreenWidth(),20)
90 self.minimized = true 169 self.minimized = true
91 self.out:Hide() 170 self:Update(true)
92 D.channels[self.index].minimized = true
93 end 171 end
94 172
95 function DevianConsoleMixin:Maximize() 173 function DevianConsoleMixin:Maximize()
96 local db = D.channels[self.index] 174 self.minimized = nilnil
97 self:SetHeight(db.height) 175 self:Update(true)
98 self:SetMaxResize(GetScreenWidth(),GetScreenHeight()) 176 end
99 self.minimized = nil 177
100 self.out:Show() 178 function DevianConsoleMixin:OnMouseDown(button)
101 D.channels[self.index].minimized = nil 179
102 end 180 if button == 'LeftButton' then
181 self:ToFront()
182 end
183 end
184
103 185
104 function DevianConsoleMixin:OnMouseUp(button) 186 function DevianConsoleMixin:OnMouseUp(button)
105 if button == 'LeftButton' then 187 if button == 'LeftButton' then
106 self:ToFront() 188 self:ToFront()
107 else 189 else
114 196
115 function DevianConsoleMixin:OnEnter() 197 function DevianConsoleMixin:OnEnter()
116 end 198 end
117 199
118 function DevianConsoleMixin:OnDragStart() 200 function DevianConsoleMixin:OnDragStart()
119 201 self:ToFront()
120 self:StartMoving() 202 self:StartMoving()
203 D.IterateChannels(function(frame)
204 frame.out:SetShown(false)
205 frame.backdrop:Hide()
206 end, self)
121 end 207 end
122 208
123 function DevianConsoleMixin:OnDragStop() 209 function DevianConsoleMixin:OnDragStop()
210
211 local channelEntry = D.channels[self:GetID()]
124 self.x = self:GetLeft() 212 self.x = self:GetLeft()
125 self.y = self:GetTop() - GetScreenHeight() 213 self.y = self:GetTop() - GetScreenHeight()
126 D.currentProfile.channels[self:GetID()].x = self:GetLeft() 214 if not self.minimized then
127 D.currentProfile.channels[self:GetID()].y = self:GetTop() - GetScreenHeight() 215 self.width = self:GetWidth()
216 self.height = self:GetHeight()
217 end
218
219 --print(channelEntry.x, channelEntry.y, channelEntry.width, channelEntry.height)
128 self:StopMovingOrSizing() 220 self:StopMovingOrSizing()
129 end 221 self:SetClampRectInsets(0,0,0,0)
130 222
131 function DevianConsoleMixin:Reset() 223 self:Update(true)
224
225 D.IterateChannels(function(frame)
226 frame:Update()
227 end, self)
132 end 228 end
133 229
134 function DevianConsoleMixin:ToFront() 230 function DevianConsoleMixin:ToFront()
135 self:Raise() 231 self:Raise()
136 D.currentProfile.current_channel = self.index 232 D.currentProfile.current_channel = self.index
142 function DevianConsoleMixin:Toggle() 238 function DevianConsoleMixin:Toggle()
143 self.enabled = (not self.enabled) 239 self.enabled = (not self.enabled)
144 --oldprint(self:GetID(), self.enabled) 240 --oldprint(self:GetID(), self.enabled)
145 self:Update() 241 self:Update()
146 end 242 end
243
244 function DevianConsoleMixin:OnEvent(event, arg)
245 oldprint(event, arg)
246 local db = D.db
247 if self.enabled then
248 if event == 'PLAYER_STARTED_MOVING' then
249 self.moveFade:GetProgress()
250 self.moveFade:Stop()
251 local F1 = self.moveFade.alphaOut
252 F1:SetFromAlpha(db.movement_fade_from)
253 F1:SetToAlpha(db.movement_fade_to)
254 F1:SetDuration(db.movement_fade_time)
255 self.moveFade:Play()
256 self:EnableMouse(false)
257 else
258 self.moveFade:Stop()
259 local F1 = self.moveFade.alphaOut
260 F1:SetToAlpha(db.movement_fade_from)
261 F1:SetFromAlpha(db.movement_fade_to)
262 F1:SetDuration(db.movement_fade_time)
263 self.moveFade:Play()
264 self:EnableMouse(true)
265 end
266 end
267 end
268
269 DevianConsoleSizeButtonMixin = {}
270 function DevianConsoleSizeButtonMixin:OnLoad()
271 self:RegisterForDrag('LeftButton')
272 end
273 function DevianConsoleSizeButtonMixin:OnDragStart()
274 local anchor = self:GetPoint(2)
275 local frame = self:GetParent()
276 if anchor == 'BOTTOMLEFT' then
277 frame:SetClampRectInsets(frame:GetLeft(), GetScreenWidth()- frame:GetRight(), GetScreenHeight() - frame:GetTop(), 0)
278 frame:SetMinResize(frame.width, 24)
279 frame:SetMaxResize(frame.width, GetScreenHeight())
280 elseif anchor == 'BOTTOM' then
281 frame:SetClampRectInsets(frame:GetLeft(), 0, GetScreenHeight() - frame:GetTop(), GetScreenHeight() - frame:GetBottom())
282 frame:SetMinResize(200, frame.height)
283 frame:SetMaxResize(GetScreenWidth(), frame.height)
284 end
285 frame:StartSizing()
286 end
287 function DevianConsoleSizeButtonMixin:OnDragStop()
288 local frame = self:GetParent()
289 frame:OnDragStop()
290 end