Mercurial > wow > devian
comparison Devian.lua @ 32:c6a2c2df4790
v2 work
author | Nenue |
---|---|
date | Sat, 26 Dec 2015 21:51:57 -0500 |
parents | 6fcfe60bbd0f |
children | e6650821a2c0 |
comparison
equal
deleted
inserted
replaced
31:6fcfe60bbd0f | 32:c6a2c2df4790 |
---|---|
1 -- User: Krakyn | 1 --- ${PACKAGE_NAME} |
2 -- Created: 11/30/2015 7:46 AM | 2 -- @file-author@ |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
3 if not LibStub then | 5 if not LibStub then |
4 print('Something has happened...') | 6 print('Something has happened...') |
5 end | 7 end |
6 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") | 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") |
7 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' | 9 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' |
8 local D = _G.Devian | 10 local D = _G.Devian |
9 local STATE_LOW, STATE_HIGH = 1, 2 | 11 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 |
10 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 12 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
11 local DEVIAN_FRAME = 'DevianConsole' | 13 local DEVIAN_FRAME = 'DevianConsole' |
12 local print = _G.print | 14 local print = _G.print |
13 local db | 15 local db |
14 local defaults = { | 16 local defaults = { |
15 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, | 17 ['global'] = {{}, {}}, |
16 ['tags'] = {}, | 18 ['tags'] = {}, |
17 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}}, | 19 ['channels'] = {[1] = {signature = 'Main', index = 1, x = 100, y = 800, height = 500, width = 600, enabled = true}}, |
18 primary_channel = 1, | 20 primary_channel = 1, |
19 current_channel = 1, | 21 current_channel = 1, |
22 max_channel = 1, | |
20 toggle = true, | 23 toggle = true, |
21 dnd_status = true, | 24 load_message = "Defaults loaded.", |
22 dnd_message = "Debugging. Your messages may get eaten.", | |
23 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], | 25 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], |
24 fontsize = 13, | 26 fontsize = 13, |
25 fontoutline = 'NONE', | 27 fontoutline = 'NONE', |
28 headergrab = {'VERTICAL', 0, 0, 0, 0.5, 0.1, 0.1, 0.1, 0.3}, | |
26 backalpha = 0.5, | 29 backalpha = 0.5, |
27 backdrop = {0,0,0,0.4}, | 30 backdrop = {0,0,0,0.4}, |
28 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5}, | 31 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5}, |
29 backblend = 'BLEND', | 32 backblend = 'BLEND', |
30 frontdrop = {0,0,0,1}, | 33 frontdrop = {0,0,0,1}, |
31 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9}, | 34 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9}, |
32 frontblend = 'BLEND', | 35 frontblend = 'BLEND', |
33 frontalpha = 1, | 36 frontalpha = 1, |
34 frontborder = {1,0,0,1}, | 37 frontborder = {1,0,0,1}, |
35 backborder = {0,0,1,0.75}, | 38 backborder = {0,0,1,0.75}, |
39 tagcolor = {}, | |
40 workspace = 1, | |
36 } | 41 } |
37 | 42 |
38 | 43 |
39 local function ScanAddOnList(cmd, ...) | 44 local function ScanAddOnList(cmd, ...) |
40 local list_state | 45 local list_state |
47 end | 52 end |
48 local mode, tag, dest = unpack(args) | 53 local mode, tag, dest = unpack(args) |
49 | 54 |
50 | 55 |
51 -- no args, toggle ui | 56 -- no args, toggle ui |
52 if mode == nil then | 57 if mode == 'dock' then |
53 list_state = db.enabled and STATE_LOW or STATE_HIGH | 58 if #args <= 2 then |
54 db.enabled = (db.enabled == false) and true or false | 59 D:Print("Not enough arguments for dock command.") |
55 --print(list_state, db.enabled) | 60 return |
56 | 61 end |
57 if list_state == STATE_LOW then | 62 |
58 end | 63 local target |
64 local worklist = {} | |
65 for i = 2, #args do | |
66 local ch | |
67 local k = tostring(args[i]) | |
68 local j = tonumber(args[i]) | |
69 if db.channels[j] then | |
70 ch = db.channels[j] | |
71 elseif D.sig[k] then | |
72 ch = D.sig[k] | |
73 elseif D.sigID[k] then | |
74 ch = db.channels[D.sigID[k]] | |
75 elseif db.tags[k] and db.tags[k][1] then | |
76 ch = db.channels[db.tags[j][1]] | |
77 -- last resort | |
78 else | |
79 D:Print('No entry for argument #'..i..': '..tostring(args[i])) | |
80 return | |
81 end | |
82 oldprint(i, '->', ch.index, '-', ch.signature) | |
83 if i > 2 then | |
84 table.insert(worklist, ch.index) | |
85 else | |
86 target = ch | |
87 | |
88 oldprint('arg1', args[2], target) | |
89 end | |
90 end | |
91 D:Print("Docking |cFF88FFFF"..table.concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") | |
92 return D:DockFrame(target.index, unpack(worklist)) | |
93 | |
94 | |
59 elseif mode == 'stack' then | 95 elseif mode == 'stack' then |
60 return D:StackFrames() | 96 return D:StackFrames() |
61 elseif mode == 'grid' then | 97 elseif mode == 'grid' then |
62 return D:DistributeFrames() | 98 return D:DistributeFrames() |
63 elseif mode == 'tag' then -- tagging | 99 elseif mode == 'tag' then -- tagging |
100 | |
64 if tag ~= nil and dest ~= nil then | 101 if tag ~= nil and dest ~= nil then |
65 local channel = D:SetChannel(dest:match('%a+'), dest:match('%d+')) | 102 -- convert to ID |
66 if not D.tags[tag] then | 103 if tonumber(dest) == nil and D.sigID[dest] then |
67 D.tags[tag] = {} | 104 dest = db.channels[D.sigID[dest]].index |
68 end | 105 end |
69 if D.tags[tag][channel.index] then | 106 |
70 D.tags[tag][channel.index] = nil | 107 -- make a new channel? |
71 D:Print('Removed |cFFFFFF00'..tag..'|r to |cFF00FFFF['..channel.index..', '..channel.signature..']|r') | 108 if not db.channels[dest] then |
109 dest = db.max_channel + 1 | |
110 D:Print('Creating a new channel for '.. tag) | |
111 D:SetChannel(tag, dest) | |
112 end | |
113 | |
114 if db.tags[tag] and db.tags[tag][dest] then | |
115 db.tags[tag][dest] = nil | |
116 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].index) | |
72 else | 117 else |
73 D.tags[tag][channel.index] = channel.index | 118 if not db.tags[tag] then |
74 D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF['..channel.index..', '..channel.signature..']|r') | 119 db.tags[tag] = {} |
75 end | 120 end |
76 | 121 db.tags[tag][dest] = dest |
122 D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].index) | |
123 end | |
77 else | 124 else |
78 D:Print('Usage: /dvn tag <prefix> <console name or number>') | 125 D:Print('Usage: /dvn tag <prefix> <console name or number>') |
79 end | 126 end |
80 return | 127 return |
81 elseif mode ~= nil then | 128 elseif tonumber(mode) ~= nil or mode == 'save' then |
82 mode = tonumber(mode) | 129 -- iterating for something |
83 if mode > 2 then | 130 if mode == 'save' then |
84 --print('Something has happened.') | 131 if tonumber(tag) == nil then |
85 return | 132 T:Print('Save ID is invalid:', tag) |
86 end | 133 end |
87 list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH | 134 list_state = tonumber(tag) |
88 end | 135 else |
136 list_state = tonumber(mode) | |
137 db.workspace = list_state | |
138 end | |
139 elseif mode == nil then | |
140 list_state = db.last_workspace and db.last_workspace or 1 | |
141 else | |
142 return D:PrintHelp() | |
143 end | |
144 | |
145 -- start the iterating | |
89 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] | 146 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] |
90 | |
91 local playername = UnitName("player") | 147 local playername = UnitName("player") |
92 | 148 |
93 for i = 1, GetNumAddOns() do | 149 for i = 1, GetNumAddOns() do |
94 local name = GetAddOnInfo(i) | 150 local name = GetAddOnInfo(i) |
95 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) | 151 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) |
96 | 152 |
97 if mode == STATE_LOW or mode == STATE_HIGH then | 153 if mode == 'save' then |
98 char_list[name] = enableState | 154 char_list[name] = enableState |
99 global_list[name] = globalState | 155 global_list[name] = globalState |
100 else | 156 else |
101 if char_list[name] or global_list[name] then | 157 if char_list[name] or global_list[name] then |
102 | 158 if char_list[name] ~= 0 and global_list[name] ~= 0 then |
103 if char_list[name] ~= 0 and global_list[name] ~= 0 then | 159 local value = false |
104 local value = false | 160 if char_list[name] == 2 and global_list[name] == 1 then |
105 if char_list[name] == 2 and global_list[name] == 1 then | 161 value = UnitName("player") |
106 value = UnitName("player") | 162 elseif global_list[name] == 2 then |
107 elseif global_list[name] == 2 then | 163 value = true |
108 value = true | 164 end |
165 --print('EnableAddOn(', i, ',', value,')') | |
166 EnableAddOn(i, value) | |
167 else | |
168 local value = true | |
169 if char_list[name] == 2 and global_list[name] == 1 then | |
170 value = UnitName("player") | |
171 end | |
172 --print('DisableAddOn(', i, ',', value,')') | |
173 DisableAddOn(i,value) | |
109 end | 174 end |
110 --print('EnableAddOn(', i, ',', value,')') | |
111 EnableAddOn(i, value) | |
112 else | 175 else |
113 local value = true | 176 if type(db.unlisted) ~= 'table' then |
114 if char_list[name] == 2 and global_list[name] == 1 then | 177 db.unlisted = {} |
115 value = UnitName("player") | |
116 end | 178 end |
117 --print('DisableAddOn(', i, ',', value,')') | 179 table.insert(db.unlisted, name) |
118 DisableAddOn(i,value) | 180 end |
119 end | 181 |
120 end | 182 end |
121 | 183 end |
122 end | 184 |
123 end | 185 if mode ~= 'save' then |
124 | 186 db.load_message = "AddOn profile ".. list_state .." was loaded." |
125 if mode == nil then | |
126 ReloadUI() | 187 ReloadUI() |
127 end | 188 else |
128 if mode == STATE_LOW then | 189 D:Print('Profile #'.. (list_state)..' saved.') |
129 D:Print('Developement AddOn list saved.') | 190 if list_state == 1 then |
130 else | 191 D:Print('This will be your main AddOn list.') |
131 D:Print('Standard AddOn list saved.') | 192 elseif list_state == db.default_list then |
193 db.last_workspace = list_state | |
194 D:Print('This will be your default workspace') | |
195 end | |
132 end | 196 end |
133 end | 197 end |
134 | 198 |
135 | 199 |
136 local function Console_MinMax(self) | 200 local function Console_MinMax(self) |
185 else | 249 else |
186 db.height = self:GetHeight() | 250 db.height = self:GetHeight() |
187 end | 251 end |
188 self:SetHeight(db.height) | 252 self:SetHeight(db.height) |
189 end | 253 end |
254 | |
255 db.dockedTo = self.dockedTo | |
256 db.docked = self.docked | |
190 | 257 |
191 db.minimized = self.minimized and true or nil | 258 db.minimized = self.minimized and true or nil |
192 db.enabled = self:IsVisible() and true or nil | 259 db.enabled = self:IsVisible() and true or nil |
193 db.active = self.active and true or nil | 260 db.active = self.active and true or nil |
194 --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) | 261 --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) |
276 | 343 |
277 end | 344 end |
278 | 345 |
279 end | 346 end |
280 | 347 |
348 local function Console_MouseDown(self, button, up) | |
349 if button == 'LeftButton' then | |
350 if up then | |
351 self:StopMovingOrSizing() | |
352 self:ToFront() | |
353 self.x = nil | |
354 self.y = nil | |
355 self.width = nil | |
356 self.height = nil | |
357 self:Save() | |
358 elseif self.out.grip:IsMouseOver() then | |
359 self:StartSizing() | |
360 else | |
361 self:StartMoving() | |
362 end | |
363 else | |
364 if up then | |
365 self:MinMax() | |
366 end | |
367 end | |
368 end | |
369 local function Console_MouseUp(self, button) | |
370 return Console_MouseDown(self, button, true) | |
371 end | |
372 | |
373 --- Creates a Devian-style output. | |
374 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() | |
375 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). | |
376 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. | |
377 -- @param ... Output contents. | |
378 local function Message(prefix, ...) | |
379 if db.enabled == true then | |
380 return D.oldprint(prefix, ...) | |
381 end | |
382 | |
383 if prefix == nil then | |
384 prefix = 1 | |
385 end | |
386 | |
387 local sendq = {} | |
388 local tag, id, tagged | |
389 local byName = true | |
390 if D.tags[prefix] then | |
391 for _, id in pairs(D.tags[prefix]) do | |
392 if D.console[id] then | |
393 sendq[id] = D.console[id] | |
394 tagged = true | |
395 end | |
396 end | |
397 end | |
398 | |
399 if D.sig[prefix] then | |
400 sendq[D.sig[prefix].index] = D.sig[prefix] | |
401 elseif D.console[prefix] then | |
402 sendq[D.console[prefix]] = D.console[prefix] | |
403 elseif not tagged then | |
404 sendq[D.primary_channel] = D.console[D.primary_channel] | |
405 end | |
406 | |
407 -- color me timbers | |
408 local pcolor | |
409 if (not db.tagcolor[prefix]) and byName then | |
410 local c = { | |
411 math.random(64,255), math.random(64,255), math.random(64,255) | |
412 } | |
413 if c[1] > 223 and c[2] > 223 and c[3] > 223 then | |
414 c[math.random(1,3)] = math.random(64,223) | |
415 end | |
416 | |
417 db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c)) | |
418 end | |
419 pcolor = db.tagcolor[prefix] | |
420 | |
421 local buffer = {'|cFF'.. pcolor..prefix ..'|r'} | |
422 for i = 1, select('#',...) do | |
423 local var = select(i, ...) | |
424 | |
425 if type(var) == 'table' then | |
426 if type(var.GetName) == 'function' then | |
427 var = '<table:'..var:GetName()..'>' | |
428 else | |
429 var = '<'..tostring(var)..'>' | |
430 end | |
431 | |
432 elseif type(var) == 'boolean' then | |
433 var = var and 'true' or 'false' | |
434 elseif type(var) == 'function' then | |
435 var = '<funcref>' | |
436 elseif type(var) == 'nil' then | |
437 var = 'nil' | |
438 end | |
439 | |
440 table.insert(buffer, var) | |
441 end | |
442 local message = table.concat(buffer, ' ') | |
443 for id, channel in pairs(sendq) do | |
444 channel.out:AddMessage(message) | |
445 end | |
446 table.wipe(buffer) | |
447 end | |
448 | |
449 | |
281 --- Constructs the frame object for a console channel | 450 --- Constructs the frame object for a console channel |
282 -- Initializes the console channel at a specified index. | 451 -- Initializes the console channel at a specified index. |
283 -- Configuration data can be overridden by passing a desired settings table. | 452 -- Configuration data can be overridden by passing a desired settings table. |
284 -- @param i Numeric index of the channel as it manifests in db.channels | 453 -- @param i Numeric index of the channel as it manifests in db.channels |
285 -- @param vars Optional settings table to be used. | 454 -- @param vars Optional settings table to be used. |
313 f.format = vars.header | 482 f.format = vars.header |
314 f.x = vars.x | 483 f.x = vars.x |
315 f.y = vars.y | 484 f.y = vars.y |
316 f.width = vars.width | 485 f.width = vars.width |
317 f.height = vars.height | 486 f.height = vars.height |
318 | 487 f.docked = vars.docked |
488 f.dockedTo = vars.dockedTo | |
489 | |
490 f:SetScript('OnMouseDown', Console_MouseDown) | |
491 f:SetScript('OnMouseUp', Console_MouseUp) | |
319 if vars.enabled then | 492 if vars.enabled then |
320 f.enabled = true | 493 f.enabled = true |
321 if db.toggle then | 494 if db.toggle then |
322 f:Show() | 495 f:Show() |
323 end | 496 end |
327 else | 500 else |
328 f:Maximize() | 501 f:Maximize() |
329 end | 502 end |
330 | 503 |
331 return f | 504 return f |
332 end | |
333 | |
334 --- Creates a Devian-style output. | |
335 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() | |
336 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). | |
337 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. | |
338 -- @param ... Output contents. | |
339 local function Message(prefix, ...) | |
340 if db.enabled == true then | |
341 return D.oldprint(prefix, ...) | |
342 end | |
343 | |
344 if prefix == nil then | |
345 prefix = 1 | |
346 end | |
347 | |
348 local sendq = {} | |
349 local tag, id, tagged | |
350 local byName = true | |
351 if D.tags[prefix] then | |
352 for _, id in pairs(D.tags[prefix]) do | |
353 if D.console[id] then | |
354 sendq[id] = D.console[id] | |
355 tagged = true | |
356 end | |
357 end | |
358 end | |
359 | |
360 if D.sig[prefix] then | |
361 sendq[D.sig[prefix].index] = D.sig[prefix] | |
362 elseif D.console[prefix] then | |
363 sendq[D.console[prefix]] = D.console[prefix] | |
364 elseif not tagged then | |
365 sendq[D.primary_channel] = D.console[D.primary_channel] | |
366 end | |
367 | |
368 -- color me timbers | |
369 local pcolor | |
370 if (not db.tagcolor[prefix]) and byName then | |
371 local c = { | |
372 math.random(64,255), math.random(64,255), math.random(64,255) | |
373 } | |
374 if c[1] > 223 and c[2] > 223 and c[3] > 223 then | |
375 c[math.random(1,3)] = math.random(64,223) | |
376 end | |
377 | |
378 db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c)) | |
379 end | |
380 pcolor = db.tagcolor[prefix] | |
381 | |
382 local buffer = {'|cFF'.. pcolor..prefix ..'|r'} | |
383 for i = 1, select('#',...) do | |
384 local var = select(i, ...) | |
385 | |
386 if type(var) == 'table' then | |
387 if type(var.GetName) == 'function' then | |
388 var = '<table:'..(var:GetName() or '?')..'>' | |
389 else | |
390 var = '<table>' | |
391 end | |
392 | |
393 elseif type(var) == 'boolean' then | |
394 var = var and 'true' or 'false' | |
395 elseif type(var) == 'function' then | |
396 var = '<funcref>' | |
397 elseif type(var) == 'nil' then | |
398 var = 'nil' | |
399 end | |
400 | |
401 table.insert(buffer, var) | |
402 end | |
403 local message = table.concat(buffer, ' ') | |
404 for id, channel in pairs(sendq) do | |
405 channel.out:AddMessage(message) | |
406 end | |
407 table.wipe(buffer) | |
408 end | |
409 | |
410 --- Spaces each frame evenly across the screen. | |
411 function D:DistributeFrames() -- | |
412 --print('frame grid:', max, num_side) | |
413 local max = self.num_channels | |
414 local num_side = math.ceil(math.sqrt(max)) | |
415 local w = GetScreenWidth() / num_side | |
416 local h = GetScreenHeight() / num_side | |
417 for i, frame in pairs(D.console) do | |
418 local dx = (i-1) % num_side | |
419 local dy = math.floor((i-1) / num_side) | |
420 | |
421 --print('move:', frame.signature, 'dx=', dx, 'dy=', dy) | |
422 --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w) | |
423 frame.width = w | |
424 frame.height = h | |
425 frame.x = dx * w | |
426 frame.y = -(dy * h) | |
427 frame:Save() | |
428 end | |
429 | |
430 end | |
431 | |
432 --- Place all frames stacked beneath the primary frame. | |
433 function D:StackFrames() | |
434 local last | |
435 for i, frame in pairs(self.console) do | |
436 if last then | |
437 frame.x = last.x | |
438 frame.y = last.y - 20 | |
439 else | |
440 frame.x = (GetScreenWidth()-frame:GetWidth())/2 | |
441 frame.y = 0 | |
442 end | |
443 frame:Save() | |
444 last = frame | |
445 end | |
446 end | 505 end |
447 | 506 |
448 --- Updates a console "channel" entry, generating a new one if necessary. | 507 --- Updates a console "channel" entry, generating a new one if necessary. |
449 -- Config data will be take from cinfo. If cinfo is a string, then only channel signature is set. The remaining variables are filled in from the primary channel. | 508 -- Config data will be take from cinfo. If cinfo is a string, then only channel signature is set. The remaining variables are filled in from the primary channel. |
450 -- i can be given to select a specific channel table entry to work on. Otherwise, it will just create a new channel and the frame associated with it. | 509 -- i can be given to select a specific channel table entry to work on. Otherwise, it will just create a new channel and the frame associated with it. |
451 -- @usage cinfo [, i] | 510 -- @usage cinfo [, i] |
452 -- @param cinfo Config variables table, or a string to be used as channel signature | 511 -- @param cinfo Config variables table, or a string to be used as channel signature |
453 -- @param i Console index. If valid, settings will be inherited from that channel. | 512 -- @param i Console index. If valid, settings will be inherited from that channel. |
454 function D:SetChannel(cinfo, i) | 513 function D:SetChannel(cinfo, i) |
455 --print('join:', i , cinfo) | 514 -- try to resolve from arguments |
515 local dbvars | |
456 local t_info = {} | 516 local t_info = {} |
457 local dbvars = db.channels[self.primary_channel] | 517 local channel |
458 local signame | 518 local isNew |
459 | 519 if type(i) =='number' and db.channels[i] then |
520 dbvars = db.channels[i] | |
521 elseif type(i) == 'string' and D.sig[i] then | |
522 dbvars = db.channels[D.sig[i].index] | |
523 else | |
524 dbvars = db.channels[db.primary_channel] | |
525 isNew = true | |
526 end | |
527 | |
528 --@debug@ | |
529 print('setchan(1)', cinfo, i, isNew)--@end-debug@ | |
530 | |
531 if type(cinfo) == 'string' and not db.sig[cinfo] then | |
532 t_info.signature = cinfo | |
533 cinfo = {} | |
534 elseif type(cinfo) ~= 'table' then | |
535 error('Expecting table of string as arg1') | |
536 end | |
537 | |
538 --@debug@ | |
539 print('setchan(2)', cinfo, i, isNew)--@end-debug@ | |
540 | |
541 --TODO: figure out why tag assignments are getting eaten | |
460 -- is cinfo a table or signature? | 542 -- is cinfo a table or signature? |
461 if type(cinfo) == 'string' then | 543 |
462 signame = tostring(cinfo) | 544 |
463 t_info.signature = signame | |
464 elseif type(cinfo) ~= 'table' then | |
465 cinfo = {} | |
466 end | |
467 | 545 |
468 -- did we get a signature string? | 546 -- did we get a signature string? |
469 if not (cinfo.signature or t_info.signature) then | 547 if not (cinfo.signature or t_info.signature) then |
470 t_info.signature = 'Console' | 548 t_info.signature = 'noname' |
471 end | 549 end |
472 | 550 |
473 -- was an index given? | 551 --@debug@ |
474 if D.sigID[t_info.signature] then | 552 print('setchan(3)', cinfo, i, isNew, t_info.signature)--@end-debug@ |
475 i = D.sigID[t_info.signature] | 553 -- look for existing sigs |
476 -- the signature has one | 554 if D.sig[t_info.signature] then |
477 elseif not i then | 555 local sigvar = t_info.signature |
478 i = D.num_channels + 1 | 556 local j = 2 |
479 t_info.index = i | 557 while D.sig[sigvar] do |
480 -- or we need to make a new one | 558 sigvar = sigvar .. j |
481 else | 559 j = j + 1 |
482 i = tonumber(i) | 560 end |
483 -- is it valid? | 561 t_info.signature = sigvar |
484 if db.channels[i] then | 562 end |
485 dbvars = db.channels[i] | 563 |
486 -- that is our base vars | 564 --@debug@ |
487 else | 565 print('setchan(4)', cinfo, i, isNew, t_info.signature)--@end-debug@ |
488 if D.sig[t_info.signature] then | |
489 local sigvar = t_info.signature | |
490 local j = 2 | |
491 while D.sig[sigvar] do | |
492 sigvar = sigvar .. j | |
493 j = j + 1 | |
494 end | |
495 t_info.signature = sigvar | |
496 end | |
497 | |
498 i = D.num_channels + 1 | |
499 t_info.index = i | |
500 -- make a new index number and fix the signature | |
501 end | |
502 end | |
503 | |
504 -- can proceed to fill in from base vars here | 566 -- can proceed to fill in from base vars here |
505 for k,v in pairs(dbvars) do | 567 for k,v in pairs(dbvars) do |
506 if not t_info[k] then | 568 if not t_info[k] then |
507 if cinfo[k] then | 569 if cinfo[k] then |
508 t_info[k] = cinfo[k] | 570 t_info[k] = cinfo[k] |
571 --@debug@ | |
572 print('setchan(5a)', 'cinfo', k)--@end-debug@ | |
509 elseif db.channels[self.primary_channel][k] then | 573 elseif db.channels[self.primary_channel][k] then |
510 t_info[k] = db.channels[self.primary_channel][k] | 574 t_info[k] = db.channels[self.primary_channel][k] |
575 --@debug@ | |
576 print('setchan(5b)', 'db', self.primary_channel, k)--@end-debug@ | |
511 end | 577 end |
512 end | 578 end |
513 end | 579 end |
514 | 580 |
515 -- we're working with a fresh channel right? | 581 -- we're working with a fresh channel right? |
516 if not db.channels[i] then | 582 if isNew then |
583 i = D.num_channels + 1 | |
584 t_info.index = i | |
517 t_info.x = t_info.x + 20 | 585 t_info.x = t_info.x + 20 |
518 t_info.y = t_info.y - 20 | 586 t_info.y = t_info.y - 20 |
519 db.channels[i] = t_info | 587 db.channels[i] = t_info |
520 -- set its position just off of the base vars and store it | 588 --@debug@ |
589 print('setchan(6)', 'new index', i)--@end-debug@ | |
521 end | 590 end |
522 | 591 |
523 -- can proceed to display something from here | 592 -- can proceed to display something from here |
524 if not self.console[i] then | 593 if not self.console[i] then |
525 self.console[i] = CreateConsole(i, t_info) | 594 self.console[i] = CreateConsole(i, t_info) |
526 -- if it isn't already spawned, create the frame | 595 -- if it isn't already spawned, create the frame |
596 --@debug@ | |
597 print('setchan(7)', 'new console', i)--@end-debug@ | |
527 end | 598 end |
528 local channel = self.console[i] | 599 local channel = self.console[i] |
529 self.sig[t_info.signature] = channel | 600 self.sig[t_info.signature] = channel |
530 self.sigID[t_info.signature] = i | 601 self.sigID[t_info.signature] = i |
531 self.IDsig[i] = t_info.signature | 602 self.IDsig[i] = t_info.signature |
532 | 603 |
604 --@debug@ | |
605 print('setchan(8)', 'end', self.sig[t_info.signature], self.sigID[t_info.signature], self.IDsig[i], self.docked)--@end-debug@ | |
533 return channel | 606 return channel |
607 end | |
608 | |
609 function D:PrintHelp() | |
610 D:Print("|cFFFFFF00/dvn|r", | |
611 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.") | |
612 | |
613 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.") | |
614 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") | |
534 end | 615 end |
535 | 616 |
536 function D:OnEnable() | 617 function D:OnEnable() |
537 -- commands | 618 -- commands |
538 local cmdlist = { | 619 local cmdlist = { |
542 } | 623 } |
543 for cmd, func in pairs(cmdlist) do | 624 for cmd, func in pairs(cmdlist) do |
544 self:RegisterChatCommand(cmd, func, true) | 625 self:RegisterChatCommand(cmd, func, true) |
545 end | 626 end |
546 | 627 |
547 if db.enabled == true then | 628 if db.workspace == 1 then |
548 D:Print('Standard AddOn list active. Type /dvn to switch to development mode.') | 629 D:Print('Gameplay mode active. Print handling turned |cFFFFFF00OFF|r..') |
549 else | 630 else |
550 D:Print('Development AddOn list active. Type /dvn to revert to regular operation.') | 631 D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.') |
551 end | 632 end |
552 | 633 |
553 end | 634 end |
554 | 635 |
555 function D:OnInitialize() | 636 function D:OnInitialize() |
556 -- emergency button | 637 -- emergency button |
557 self:RegisterChatCommand("cleandvn", function(args) | 638 self:RegisterChatCommand("cleandvn", function(args) |
558 DevianDB = nil | 639 DevianDB = nil |
559 ReloadUI() | 640 ReloadUI() |
560 end) | 641 end) |
642 self:RegisterChatCommand("resetdvn", function(args) | |
643 for k,v in pairs(DevianDB) do | |
644 if k ~= 'global' then | |
645 DevianDB[k] = nil | |
646 end | |
647 end | |
648 | |
649 for k,v in pairs(defaults) do | |
650 DevianDB[k] = v | |
651 end | |
652 ReloadUI() | |
653 end) | |
561 | 654 |
562 -- savedvars | 655 -- savedvars |
563 local cherry = false | 656 local cherry = false |
564 if not _G.DevianDB then | 657 if not _G.DevianDB then |
565 _G.DevianDB = defaults | 658 _G.DevianDB = defaults |
566 cherry = "Type /dvnsave to snapshot your current UI" | |
567 end | 659 end |
568 db = _G.DevianDB | 660 db = _G.DevianDB |
661 self.tags = db.tags | |
662 self.channelinfo = db.channels | |
569 | 663 |
570 if not db[PLAYER_REALM] then | 664 if not db[PLAYER_REALM] then |
571 db[PLAYER_REALM] = {[STATE_LOW] = {}, [STATE_HIGH] = {}} | 665 db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}} |
572 if not cherry then | 666 end |
573 cherry = "This character didn't have an AddOn table." | 667 |
574 end | 668 if db.load_message then |
575 end | 669 D:Print(db.load_message) |
576 | 670 db.load_message = nil |
577 | |
578 if not db.tags then | |
579 db.tags = {} | |
580 end | |
581 self.tags = db.tags | |
582 if cherry then | |
583 D:Print(cherry) | |
584 end | 671 end |
585 D.oldprint = getprinthandler() | 672 D.oldprint = getprinthandler() |
586 if not _G.oldprint then | 673 if not _G.oldprint then |
587 _G.oldprint = D.oldprint | 674 _G.oldprint = D.oldprint |
588 end | 675 end |
589 | 676 |
590 --self.raise_ct = 0 | 677 --self.raise_ct = 0 |
591 self.last_channel = 0 | 678 self.max_channel = 0 |
592 self.num_channels = 0 | 679 self.num_channels = 0 |
593 self.console = {} | 680 self.console = {} |
594 self.sig = {} | 681 self.sig = {} |
595 self.sigID = {} | 682 self.sigID = {} |
596 self.IDsig = {} | 683 self.IDsig = {} |
598 i = tonumber(i) | 685 i = tonumber(i) |
599 if not self.primary_channel then | 686 if not self.primary_channel then |
600 self.primary_channel = i | 687 self.primary_channel = i |
601 end | 688 end |
602 self:SetChannel(cinfo, i) | 689 self:SetChannel(cinfo, i) |
603 if i > self.last_channel then | 690 self.max_channel = math.max(i, self.max_channel) |
604 self.last_channel = i | |
605 end | |
606 self.num_channels = self.num_channels + 1 | 691 self.num_channels = self.num_channels + 1 |
692 end | |
693 | |
694 for i, channel in pairs(db.channels) do | |
695 if type(channel.docked) == 'table' then | |
696 oldprint('docking',i, unpack(channel.docked)) | |
697 self.DockFrame(i, unpack(channel.docked)) | |
698 end | |
607 end | 699 end |
608 | 700 |
609 if self.console[db.current_channel] then | 701 if self.console[db.current_channel] then |
610 self.console[db.current_channel]:ToFront() | 702 self.console[db.current_channel]:ToFront() |
611 -- bring the current channel to the front | 703 -- bring the current channel to the front |
617 end | 709 end |
618 end | 710 end |
619 | 711 |
620 | 712 |
621 -- only do this in dev mode | 713 -- only do this in dev mode |
622 if db.enabled == false then | 714 if db.workspace > 1 then |
715 | |
623 setprinthandler(Message) | 716 setprinthandler(Message) |
624 print = function(...) | 717 print = function(...) |
625 _G.print('Dvn', ...) | 718 _G.print('Dvn', ...) |
626 end | 719 end |
627 end | 720 end |