Mercurial > wow > devian
comparison Devian.lua @ 14:5254d1ba6013 v1.2-r15
Multiple output windows can be created for different output prefixes, and prefixes can be designated to an existing or new "console" with /dvn <prefix> <console>
Frame objects are generated directly from XML data, and their state information is stored in the object itself to resolve issues with GetWidth() returning old info in some cases.
StackFrames and DistributeFrames methods can be invoked from /script to arrange the buffers.
author | Nenue |
---|---|
date | Sun, 20 Dec 2015 00:46:42 -0500 |
parents | 080dfa4990fb |
children | 48a1d9c14af5 |
comparison
equal
deleted
inserted
replaced
13:080dfa4990fb | 14:5254d1ba6013 |
---|---|
15 local db | 15 local db |
16 local defaults = { | 16 local defaults = { |
17 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, | 17 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, |
18 ['tags'] = {}, | 18 ['tags'] = {}, |
19 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}}, | 19 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}}, |
20 primary_channel = 1, | |
20 current_channel = 1, | 21 current_channel = 1, |
21 console = true, | 22 toggle = true, |
22 dnd_status = true, | 23 dnd_status = true, |
23 dnd_message = "Debugging. Your messages may get eaten.", | 24 dnd_message = "Debugging. Your messages may get eaten.", |
24 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], | 25 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], |
25 fontsize = 13, | 26 fontsize = 13, |
26 fontoutline = 'NONE', | 27 fontoutline = 'NONE', |
28 backdrop = {1,1,1,0.2}, | |
29 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5}, | |
30 backblend = 'BLEND', | |
31 frontdrop = {1,1,1,1}, | |
32 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9}, | |
33 frontblend = 'BLEND' | |
27 } | 34 } |
28 | 35 |
29 | 36 |
30 local function ScanAddOnList(cmd, ...) | 37 local function ScanAddOnList(cmd, ...) |
31 local list_state | 38 local list_state |
32 | 39 |
33 local mode = tonumber(cmd:match("%d")) | 40 local args = {} |
34 | 41 local arg, n = D:GetArgs(cmd, 1) |
35 | 42 while arg do |
36 print('Starting Addons scan. arg=', mode) | 43 table.insert(args, arg) |
44 arg, n = D:GetArgs(cmd,1,n) | |
45 end | |
46 local mode, tag, dest = unpack(args) | |
47 | |
48 | |
49 -- no args, toggle ui | |
37 if mode == nil then | 50 if mode == nil then |
38 list_state = db.enabled and STATE_LOW or STATE_HIGH | 51 list_state = db.enabled and STATE_LOW or STATE_HIGH |
39 db.enabled = (db.enabled == false) and true or false | 52 db.enabled = (db.enabled == false) and true or false |
40 print(list_state, db.enabled) | 53 print(list_state, db.enabled) |
41 | 54 |
42 if list_state == STATE_LOW then | 55 if list_state == STATE_LOW then |
43 end | 56 end |
44 | 57 elseif mode == 'stack' then |
45 else | 58 return D:StackFrames() |
59 elseif mode == 'grid' then | |
60 return D:DistributeFrames() | |
61 elseif mode == 'tag' then -- tagging | |
62 if tag ~= nil and dest ~= nil then | |
63 if not D.console[dest] and not D.sig[dest] then | |
64 local sig = dest:match('%a') | |
65 local id = dest:match('%d') | |
66 if not id then | |
67 id = self.last_channel + 1 | |
68 end | |
69 if not sig then | |
70 sig = tag | |
71 end | |
72 D:SetChannel(sig, id) | |
73 end | |
74 D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r') | |
75 else | |
76 D:Print('Usage: /dvn tag <prefix> <console name or number>') | |
77 end | |
78 return | |
79 elseif mode ~= nil then | |
80 mode = tonumber(mode) | |
46 if mode > 2 then | 81 if mode > 2 then |
47 print('Something has happened.') | 82 print('Something has happened.') |
48 return | 83 return |
49 end | 84 end |
50 list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH | 85 list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH |
51 | |
52 | |
53 end | 86 end |
54 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] | 87 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] |
55 | 88 |
56 local playername = UnitName("player") | 89 local playername = UnitName("player") |
57 | 90 |
108 | 141 |
109 local function Console_Minimize(self) | 142 local function Console_Minimize(self) |
110 self:SetHeight(20) | 143 self:SetHeight(20) |
111 self:SetMaxResize(GetScreenWidth(),20) | 144 self:SetMaxResize(GetScreenWidth(),20) |
112 self.minimized = true | 145 self.minimized = true |
113 return self.out:Hide() | 146 self.out:Hide() |
147 self:Save() | |
114 end | 148 end |
115 | 149 |
116 local function Console_Maximize(self) | 150 local function Console_Maximize(self) |
117 local db = db.channels[self.index] | 151 local db = db.channels[self.index] |
118 self:SetHeight(db.height) | 152 self:SetHeight(db.height) |
119 self:SetMaxResize(GetScreenWidth(),GetScreenHeight()) | 153 self:SetMaxResize(GetScreenWidth(),GetScreenHeight()) |
120 self.minimized = nil | 154 self.minimized = nil |
121 self.grip:SetTexture(0.5,0.5,0.5) | 155 self.out:Show() |
122 return self.out:Show() | 156 self:Save() |
123 end | 157 end |
124 | 158 |
125 | 159 |
126 local function Console_Save(self) | 160 local function Console_Save(self) |
127 local db = db.channels[self.index] | 161 local db = db.channels[self.index] |
128 db.y = (self:GetTop() - GetScreenHeight()) | 162 if self.x then |
129 db.x = self:GetLeft() | 163 db.x = self.x |
130 db.width = self:GetWidth() | 164 else |
165 db.x = self:GetLeft() | |
166 end | |
167 | |
168 if self.y then | |
169 db.y = self.y | |
170 else | |
171 db.y = (self:GetTop() - GetScreenHeight()) | |
172 end | |
173 | |
174 if self.width then | |
175 db.width = self.width | |
176 else | |
177 db.width = self:GetWidth() | |
178 end | |
179 | |
131 if not self.minimized then | 180 if not self.minimized then |
132 db.height = self:GetHeight() | 181 if self.height then |
133 db.minimized = nil | 182 db.height = self.height |
134 else | 183 else |
135 db.minimized = true | 184 db.height = self:GetHeight() |
136 end | 185 end |
137 if self:IsVisible() then | 186 self:SetHeight(db.height) |
138 db.enabled = true | 187 end |
139 else | 188 |
140 db.enabled = nil | 189 db.minimized = self.minimized and true or nil |
141 end | 190 db.enabled = self:IsVisible() and true or nil |
191 db.active = self.active and true or nil | |
192 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) | |
142 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) | 193 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) |
143 end | 194 self:SetWidth(db.width) |
144 | 195 end |
145 | 196 |
197 -- Console frame toggler | |
198 -- @paramsig [...] | |
199 -- @param ... one or more space-seperated channel keys | |
146 local function Console_Toggle(input) | 200 local function Console_Toggle(input) |
147 local key = input:gmatch("[%a%d]") | 201 local search = {} |
148 local search | 202 local key, n = D:GetArgs(input, 1) |
149 if key and D.sig[key] then | 203 if key then |
150 search = {D.sig[key]} | 204 repeat |
151 elseif D.console[key] then | 205 if D.sig[key] then |
152 search = {D.console[key]} | 206 table.insert(search, D.sig[key]) |
207 elseif D.console[key] then | |
208 table.insert(search, D.console[key]) | |
209 end | |
210 key, n = D:GetArgs(input,1,n) | |
211 until n == 1e9 | |
153 else | 212 else |
154 search = D.console | 213 search = D.console |
155 end | 214 end |
156 | 215 |
216 db.toggle = not db.toggle and true or nil | |
157 for _, c in ipairs(search) do | 217 for _, c in ipairs(search) do |
158 if c:IsVisible() then | 218 if db.toggle then |
219 c:Show() | |
220 else | |
221 c.enabled = nil | |
222 c.minimized = nil | |
223 c:Maximize() | |
159 c:Hide() | 224 c:Hide() |
160 else | 225 end |
161 c:Show() | 226 end |
162 c:Maximize() | 227 |
163 end | 228 if db.toggle then |
164 c:Save() | 229 D:Print('toggled on?') |
165 end | 230 else |
166 end | 231 D:Print('toggled off?') |
167 | 232 end |
168 -- | 233 end |
169 -- | 234 |
170 -- Construct a console frame | 235 -- Bring console to the front |
236 local function Console_ToFront(c) | |
237 --print(D.raise_ct, 'Raising', c.signature) | |
238 --print(unpack(db.frontdrop)) | |
239 --print(unpack(db.frontgrad)) | |
240 --print(db.frontblend) | |
241 D.raise_ct = D.raise_ct + 1 | |
242 c:Raise() | |
243 c.out.backdrop:SetTexture(unpack(db.frontdrop)) | |
244 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) | |
245 c.out.backdrop:SetBlendMode(db.frontblend) | |
246 | |
247 for id, bc in pairs(D.console) do | |
248 if id ~= c.index then | |
249 --print(D.raise_ct, 'Lowering', bc.signature) | |
250 --print(unpack(db.backdrop)) | |
251 --print(unpack(db.backgrad)) | |
252 --print(db.backblend) | |
253 bc.out.backdrop:SetTexture(unpack(db.backdrop)) | |
254 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) | |
255 bc.out.backdrop:SetBlendMode(db.backblend) | |
256 end | |
257 end | |
258 | |
259 end | |
260 | |
261 -- Generate a console frame | |
262 -- @paramsig id, vars | |
263 -- @param id channel number | |
264 -- @param vars alternative config, else uses db.channels[id] | |
171 local function CreateConsole(i, vars) | 265 local function CreateConsole(i, vars) |
266 | |
267 if not vars then | |
268 vars = db.channels[i] | |
269 end | |
270 | |
271 print('make:', vars.signature, '(', vars.x, vars.y, ')', vars.width, 'x', vars.height) | |
172 local f = CreateFrame('Frame', 'DevianChannelFrame' .. tostring(i), UIParent, DEVIAN_FRAME) | 272 local f = CreateFrame('Frame', 'DevianChannelFrame' .. tostring(i), UIParent, DEVIAN_FRAME) |
173 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.channels[i].x, db.channels[i].y) | 273 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y) |
174 f:SetSize(vars.width, vars.height) | 274 f:SetSize(vars.width, vars.height) |
175 f:Lower() | 275 f:Lower() |
176 f.out:SetFont(db.font, db.fontsize, db.fontoutline) | 276 f.out:SetFont(db.font, db.fontsize, db.fontoutline) |
177 f.Save = Console_Save | 277 f.Save = Console_Save |
178 f.Minimize = Console_Minimize | 278 f.Minimize = Console_Minimize |
179 f.Maximize = Console_Maximize | 279 f.Maximize = Console_Maximize |
180 f.MinMax = Console_MinMax | 280 f.MinMax = Console_MinMax |
281 f.ToFront = Console_ToFront | |
181 f.Toggle = D.Console_Toggle | 282 f.Toggle = D.Console_Toggle |
182 f.name = vars.name | 283 f.name = vars.name |
183 f.index = i | 284 f.index = i |
184 | 285 f.signature = vars.signature |
185 if db.channels[i].enabled then | 286 f.format = vars.header |
186 f:Show() | 287 f.x = vars.x |
187 end | 288 f.y = vars.y |
188 if db.channels[i].minimized then | 289 f.width = vars.width |
290 f.height = vars.height | |
291 | |
292 if vars.enabled then | |
293 f.enabled = true | |
294 if db.toggle then | |
295 f:Show() | |
296 end | |
297 end | |
298 if vars.minimized then | |
189 f:Minimize() | 299 f:Minimize() |
190 end | 300 end |
191 | 301 |
192 return f | 302 return f |
193 end | 303 end |
194 | 304 |
195 -- | 305 -- Print to Devian output |
196 -- | 306 -- @paramsig tag, ... |
197 -- Send a message somewhere | 307 -- @param tag channel signature or number used to select console |
308 -- @param ... print arguments | |
198 local function Message(prefix, ...) | 309 local function Message(prefix, ...) |
199 if prefix == nil then | 310 if prefix == nil then |
200 prefix = 1 | 311 prefix = 1 |
201 end | 312 end |
202 | 313 |
208 channel = D.console[prefix] | 319 channel = D.console[prefix] |
209 byName = nil | 320 byName = nil |
210 else | 321 else |
211 channel = D.console[1] | 322 channel = D.console[1] |
212 end | 323 end |
213 | |
214 | |
215 | |
216 -- color me timbers | 324 -- color me timbers |
217 local pcolor | 325 local pcolor |
218 if D.tags[prefix] then | 326 if D.tags[prefix] then |
219 pcolor = db.tags[prefix] | 327 pcolor = db.tags[prefix] |
220 elseif byName then | 328 elseif byName then |
255 end | 363 end |
256 channel.out:AddMessage(table.concat(buffer, ' ')) | 364 channel.out:AddMessage(table.concat(buffer, ' ')) |
257 table.wipe(buffer) | 365 table.wipe(buffer) |
258 end | 366 end |
259 | 367 |
368 -- Spaces each frame evenly across the screen | |
369 function D:DistributeFrames() -- | |
370 print('frame grid:', max, num_side) | |
371 local max = self.num_channels | |
372 local num_side = math.ceil(math.sqrt(max)) | |
373 local w = GetScreenWidth() / num_side | |
374 local h = GetScreenHeight() / num_side | |
375 for i, frame in pairs(D.console) do | |
376 local dx = (i-1) % num_side | |
377 local dy = math.floor((i-1) / num_side) | |
378 | |
379 print('move:', frame.signature, 'dx=', dx, 'dy=', dy) | |
380 print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w) | |
381 frame.width = w | |
382 frame.height = h | |
383 frame.x = dx * w | |
384 frame.y = -(dy * h) | |
385 frame:Save() | |
386 end | |
387 | |
388 end | |
389 | |
390 -- Place all frames stacked beneath the primary frame | |
391 -- @paramsig | |
392 function D:StackFrames() | |
393 local last | |
394 for i, frame in pairs(self.console) do | |
395 if last then | |
396 frame.x = last.x | |
397 frame.y = last.y - 20 | |
398 else | |
399 frame.x = (GetScreenWidth()-frame:GetWidth())/2 | |
400 frame.y = 0 | |
401 end | |
402 frame:Save() | |
403 last = frame | |
404 end | |
405 end | |
406 | |
407 -- Creates or updates a console frame | |
408 -- @paramsig cinfo [, i] | |
409 -- @param cinfo an array from db.channels[x] or the desired string signature | |
410 -- @param id when set, the console at that index will be assigned all parameters in cinfo | |
411 function D:SetChannel(cinfo, i) | |
412 print('join:', i , cinfo) | |
413 local t_info = {} | |
414 if type(cinfo) ~= 'table' then | |
415 t_info.signature = tostring(cinfo) | |
416 cinfo = {} | |
417 end | |
418 local srcdb = db.channels[self.primary_channel] | |
419 if i ~= nil then | |
420 i = tonumber(i) | |
421 if db.channels[i] then | |
422 print('pull vars from '..db.channels[i].signature) | |
423 cinfo = db.channels[i] | |
424 srcdb = cinfo | |
425 end | |
426 end | |
427 | |
428 for k,v in pairs(srcdb) do | |
429 if not t_info[k] then | |
430 if cinfo[k] then | |
431 print('- pulling', k..':',v) | |
432 t_info[k] = cinfo[k] | |
433 end | |
434 end | |
435 end | |
436 | |
437 if not db.channels[i] then | |
438 t_info.x = t_info.x + 20 | |
439 t_info.y = t_info.y - 20 | |
440 db.channels[i] = t_info | |
441 end | |
442 if not self.console[i] then | |
443 self.console[i] = CreateConsole(i, t_info) | |
444 end | |
445 | |
446 self.sig[cinfo.signature] = self.console[i] | |
447 self.sigID[cinfo.signature] = i | |
448 self.IDsig[i] = cinfo.signature | |
449 end | |
450 | |
260 function D:OnEnable() | 451 function D:OnEnable() |
261 -- commands | 452 -- commands |
262 local cmdlist = { | 453 local cmdlist = { |
263 ['dvn'] = ScanAddOnList, | 454 ['dvn'] = ScanAddOnList, |
264 ['devian'] = ScanAddOnList, | 455 ['devian'] = ScanAddOnList, |
274 D:Print('Development AddOn list active. Type /dvn to revert to regular operation.') | 465 D:Print('Development AddOn list active. Type /dvn to revert to regular operation.') |
275 end | 466 end |
276 | 467 |
277 end | 468 end |
278 | 469 |
279 | |
280 function D:OnInitialize() | 470 function D:OnInitialize() |
281 -- emergency button | 471 -- emergency button |
282 self:RegisterChatCommand("cleandvn", function(args) | 472 self:RegisterChatCommand("cleandvn", function(args) |
283 DevianDB = nil | 473 DevianDB = nil |
284 ReloadUI() | 474 ReloadUI() |
310 D.oldprint = getprinthandler() | 500 D.oldprint = getprinthandler() |
311 if not _G.oldprint then | 501 if not _G.oldprint then |
312 _G.oldprint = D.oldprint | 502 _G.oldprint = D.oldprint |
313 end | 503 end |
314 | 504 |
505 self.raise_ct = 0 | |
506 self.last_channel = 0 | |
507 self.num_channels = 0 | |
315 self.console = {} | 508 self.console = {} |
316 self.sig = {} | 509 self.sig = {} |
317 for i, cinfo in ipairs(db.channels) do | 510 self.sigID = {} |
318 self.console[i] = CreateConsole(i, cinfo) | 511 self.IDsig = {} |
319 self.sig[cinfo.signature] = self.console[i] | 512 for i, cinfo in pairs(db.channels) do |
513 i = tonumber(i) | |
514 if not self.primary_channel then | |
515 self.primary_channel = i | |
516 end | |
517 self:SetChannel(cinfo, i) | |
518 if i > self.last_channel then | |
519 self.last_channel = i | |
520 end | |
521 self.num_channels = self.num_channels + 1 | |
320 end | 522 end |
321 setprinthandler(Message) | 523 setprinthandler(Message) |
322 print(MAJOR, MINOR) | 524 print(MAJOR, MINOR) |
323 end | 525 end |