Mercurial > wow > devian
comparison UI.lua @ 36:bec37163b7fe v2.0-beta
rewrote the blocks for '/dvn tag' and SetChannel to be more predictable; currently follows:
/dvn tag <source> <dest>
if <dest> matches a channel, then the tag for <source> is added or removed
if <dest> is a string and it doesn't match a channel, then that channel is created with <dest> as a signature
if <dest> is a number that doesn't match a channel index, then <dest> is set to <highest valid index + 1>, the channel is created under that, and <source> is used as its signature
SetChannel(cinfo, key)
start with an empty table t_info that is filled in as follows:
if key doesn't match a valid index/signature, then a channel is being created
if key does match a valid index, then a channel is being updated
if cinfo is a string, then only the signature value is imposed
if cinfo is a table, the values from that table are imposed
if a channel is being created, then the new channel info is filled in from primary channel, the index is auto-generated, and the signature value is checked for collision, and the information is passed through CreateConsole to form internal assignments
if a channel is being updated, then t_info is populated from the channel data, and any internal table assignments are switched over to t_info
the old tables sink into garbage collection
author | Nenue |
---|---|
date | Sun, 27 Dec 2015 08:19:45 -0500 |
parents | 3304455a3f45 |
children | d432f49e340e |
comparison
equal
deleted
inserted
replaced
35:3304455a3f45 | 36:bec37163b7fe |
---|---|
12 | 12 |
13 | 13 |
14 | 14 |
15 local DEVIAN_FRAME = 'DevianConsole' | 15 local DEVIAN_FRAME = 'DevianConsole' |
16 local DEVIAN_DOCK_FRAME = 'DevianDockFrame' | 16 local DEVIAN_DOCK_FRAME = 'DevianDockFrame' |
17 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' | |
18 | 17 |
19 | 18 |
20 local function Console_MinMax(self) | 19 local function Console_MinMax(self) |
21 if self.minimized then | 20 if self.minimized then |
22 self:Maximize() | 21 self:Maximize() |
79 db.enabled = self:IsVisible() and true or nil | 78 db.enabled = self:IsVisible() and true or nil |
80 db.active = self.active and true or nil | 79 db.active = self.active and true or nil |
81 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width) | 80 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width) |
82 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) | 81 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) |
83 self:SetWidth(db.width) | 82 self:SetWidth(db.width) |
84 end | |
85 | |
86 -- Console frame toggler | |
87 -- @paramsig [...] | |
88 -- @param ... one or more space-seperated channel keys | |
89 local function Console_Toggle(input) | |
90 local db = D.db | |
91 if db.workspace == 1 then | |
92 return D:Print(MSG_NEED_DEV_MODE) | |
93 end | |
94 local search = {} | |
95 local n = 0 | |
96 if D:GetArgs(input,1) then | |
97 repeat | |
98 key, n = D:GetArgs(input,1,n) | |
99 if D.sig[key] then | |
100 table.insert(search, D.sig[key]) | |
101 elseif D.console[key] then | |
102 table.insert(search, D.console[key]) | |
103 end | |
104 until n == 1e9 | |
105 else | |
106 search = D.console | |
107 end | |
108 | |
109 db.enabled = (not db.enabled) and true or nil | |
110 for i, c in ipairs(search) do | |
111 --print(i,c.index) | |
112 if db.enabled then | |
113 c.enabled = true | |
114 c:Show() | |
115 if db.current_channel == c.index then | |
116 c:ToFront() | |
117 end | |
118 c:Save() | |
119 else | |
120 c:Hide() | |
121 end | |
122 end | |
123 | |
124 if db.enabled then | |
125 D:Print('toggled on?') | |
126 else | |
127 D:Print('toggled off?') | |
128 end | |
129 end | 83 end |
130 | 84 |
131 --- Brings the console to the front. | 85 --- Brings the console to the front. |
132 -- Frame method used to bring a console frame to the front of the display stack. | 86 -- Frame method used to bring a console frame to the front of the display stack. |
133 local function Console_ToFront(c) | 87 local function Console_ToFront(c) |
140 c:Raise() | 94 c:Raise() |
141 c:SetAlpha(db.frontalpha) | 95 c:SetAlpha(db.frontalpha) |
142 c.out.backdrop:SetTexture(unpack(db.frontdrop)) | 96 c.out.backdrop:SetTexture(unpack(db.frontdrop)) |
143 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) | 97 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) |
144 c.out.backdrop:SetBlendMode(db.frontblend) | 98 c.out.backdrop:SetBlendMode(db.frontblend) |
99 c.dropmenu.icon:SetVertexColor(unpack(db.headerfontcolor)) | |
100 c.title:SetTextColor(unpack(db.headerfontcolor)) | |
145 db.current_channel = c.index | 101 db.current_channel = c.index |
146 | 102 |
147 for _, part in pairs(c.border) do | 103 for _, part in pairs(c.border) do |
148 part:SetTexture(unpack(db.frontborder)) | 104 part:SetTexture(unpack(db.frontborder)) |
149 end | 105 end |
156 --print(db.backblend) | 112 --print(db.backblend) |
157 bc:SetAlpha(db.backalpha) | 113 bc:SetAlpha(db.backalpha) |
158 bc.out.backdrop:SetTexture(unpack(db.backdrop)) | 114 bc.out.backdrop:SetTexture(unpack(db.backdrop)) |
159 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) | 115 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) |
160 bc.out.backdrop:SetBlendMode(db.backblend) | 116 bc.out.backdrop:SetBlendMode(db.backblend) |
117 bc.dropmenu.icon:SetVertexColor(unpack(db.backborder)) | |
118 bc.title:SetTextColor(unpack(db.backborder)) | |
161 | 119 |
162 for _, part in pairs(bc.border) do | 120 for _, part in pairs(bc.border) do |
163 part:SetTexture(unpack(db.backborder)) | 121 part:SetTexture(unpack(db.backborder)) |
164 end | 122 end |
165 end | 123 end |
217 | 175 |
218 --print('create(2)') | 176 --print('create(2)') |
219 for k,v in pairs(vars) do | 177 for k,v in pairs(vars) do |
220 f[k] = v | 178 f[k] = v |
221 --@debug@ | 179 --@debug@ |
222 print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v)) | 180 --print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v)) |
223 end | 181 end |
224 | 182 |
225 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y) | 183 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y) |
226 f:SetSize(vars.width, vars.height) | 184 f:SetSize(vars.width, vars.height) |
227 f:Lower() | 185 f:Lower() |
228 f.out:SetFont(db.font, db.fontsize, db.fontoutline) | 186 f.out:SetFont(db.font, db.fontsize, db.fontoutline) |
229 if (db.current_channel == i) then | 187 if (db.current_channel == i) then |
230 f.out.backdrop:SetTexture(unpack(db.frontdrop)) | 188 f.out.backdrop:SetTexture(unpack(db.frontdrop)) |
189 f.dropmenu.icon:SetVertexColor(unpack(db.headerfontcolor)) | |
190 f.title:SetTextColor(unpack(db.headerfontcolor)) | |
231 else | 191 else |
232 f.out.backdrop:SetTexture(unpack(db.backdrop)) | 192 f.out.backdrop:SetTexture(unpack(db.backdrop)) |
233 end | 193 end |
234 | |
235 | |
236 | 194 |
237 f.Save = Console_Save | 195 f.Save = Console_Save |
238 f.Minimize = Console_Minimize | 196 f.Minimize = Console_Minimize |
239 f.Maximize = Console_Maximize | 197 f.Maximize = Console_Maximize |
240 f.MinMax = Console_MinMax | 198 f.MinMax = Console_MinMax |
241 f.ToFront = Console_ToFront | 199 f.ToFront = Console_ToFront |
242 f.Toggle = D.Console_Toggle | 200 f.Toggle = D.Console_Toggle |
243 f:SetScript('OnMouseDown', Console_MouseDown) | 201 f:SetScript('OnMouseDown', Console_MouseDown) |
244 f:SetScript('OnMouseUp', Console_MouseUp) | 202 f:SetScript('OnMouseUp', Console_MouseUp) |
203 | |
204 | |
205 UIDropDownMenu_Initialize(f.menuFrame, function() | |
206 local info = { { | |
207 text= "Close", | |
208 value = "OptClose", | |
209 func = function () | |
210 f.enabled = nil | |
211 f:Hide() | |
212 f:Save() | |
213 end }, | |
214 { | |
215 text = "Dock", | |
216 value = "OptDock", | |
217 func = function() print('Dvn', 'docking shenanary') end } | |
218 } | |
219 for _, v in ipairs(info) do | |
220 UIDropDownMenu_AddButton(v) | |
221 end | |
222 end, 'MENU') | |
245 | 223 |
246 if vars.minimized then | 224 if vars.minimized then |
247 f:Minimize() | 225 f:Minimize() |
248 else | 226 else |
249 f:Maximize() | 227 f:Maximize() |
266 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 | 244 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 |
267 function D:SetChannel(cinfo, key) | 245 function D:SetChannel(cinfo, key) |
268 local db = self.db | 246 local db = self.db |
269 local t_info = {} | 247 local t_info = {} |
270 local channel, isNew, id, sig, t_id | 248 local channel, isNew, id, sig, t_id |
249 --@debug@ | |
250 print('setchan(0) cinfo, key', cinfo, key)--@end-debug@ | |
271 -- obtain source data | 251 -- obtain source data |
272 if tonumber(key) ~= nil and db.channels[key] then | 252 if tonumber(key) ~= nil and db.channels[key] then |
273 id = tonumber(key) | 253 id = tonumber(key) |
274 elseif D.sigID[tostring(key)] then | 254 elseif D.sigID[tostring(key)] then |
275 id = D.sigID[tostring(key)] | 255 id = D.sigID[tostring(key)] |
279 end | 259 end |
280 local dbvars = db.channels[id] | 260 local dbvars = db.channels[id] |
281 t_id = id -- overridden later if new | 261 t_id = id -- overridden later if new |
282 t_info.index = t_id -- | 262 t_info.index = t_id -- |
283 --@debug@ | 263 --@debug@ |
284 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ | 264 print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ |
285 | 265 |
286 | 266 |
287 -- obtain config info | 267 -- obtain config info |
288 if type(cinfo) == 'string' then | 268 if type(cinfo) == 'string' then |
289 sig = cinfo | 269 sig = cinfo |
297 else -- old sig | 277 else -- old sig |
298 sig = db.channels[id].signature | 278 sig = db.channels[id].signature |
299 end | 279 end |
300 t_info.signature = sig | 280 t_info.signature = sig |
301 --@debug@ | 281 --@debug@ |
302 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ | 282 print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ |
303 | 283 |
304 for k,v in pairs(cinfo) do -- allow all cinfo to pass | 284 for k,v in pairs(cinfo) do -- allow all cinfo to pass |
305 t_info[k] = v | 285 t_info[k] = v |
306 end | 286 end |
307 | 287 |
322 result = sig .. i | 302 result = sig .. i |
323 i = i + 1 | 303 i = i + 1 |
324 end | 304 end |
325 t_info.signature = result | 305 t_info.signature = result |
326 end | 306 end |
327 t_id = db.max_channel + 1 | 307 t_id = self.max_channel + 1 |
328 t_info.index = t_id | 308 t_info.index = t_id |
329 --@debug@ | 309 --@debug@ |
330 --print('setchan(3a) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@ | 310 print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ |
331 else | 311 else |
332 --@debug@ | 312 --@debug@ |
333 --print('setchan(3b) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@ | 313 print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ |
334 end | 314 end |
335 | 315 |
336 local channel | 316 local channel |
337 if not self.console[t_id] then -- create a frame | 317 if not self.console[t_id] then -- create a frame |
338 if isNew then -- position the channel frame | 318 if isNew then -- position the channel frame |
339 t_info.x = t_info.x + 20 | 319 self.max_channel = t_id |
340 t_info.y = t_info.y - 20 | 320 db.max_channel = t_id |
341 db.channels[t_id] = t_info | 321 t_info.x = t_info.x + 20 |
342 --@debug@ | 322 t_info.y = t_info.y - 20 |
343 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ | 323 db.channels[t_id] = t_info |
324 --@debug@ | |
325 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ | |
344 end | 326 end |
345 channel = CreateConsole(t_id, t_info) | 327 channel = CreateConsole(t_id, t_info) |
346 self.console[t_id] = channel | 328 self.console[t_id] = channel |
347 self.sig[t_info.signature] = channel | 329 self.sig[t_info.signature] = channel |
348 self.sigID[t_info.signature] = t_id | 330 self.sigID[t_info.signature] = t_id |