annotate Devian.lua @ 26:b0e8bd30575f v1.4.3

front channel persistence fixes
author Nenue
date Thu, 24 Dec 2015 02:59:53 -0500
parents 4085930d5f09
children 31ca76e04766
rev   line source
Nenue@0 1 -- User: Krakyn
Nenue@0 2 -- Created: 11/30/2015 7:46 AM
Nenue@0 3 if not LibStub then
Nenue@0 4 print('Something has happened...')
Nenue@0 5 end
Nenue@0 6 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
Nenue@13 7 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@'
Nenue@0 8 local D = _G.Devian
Nenue@0 9 local STATE_LOW, STATE_HIGH = 1, 2
Nenue@0 10 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
Nenue@13 11 local DEVIAN_FRAME = 'DevianConsole'
Nenue@18 12 local print = _G.print
Nenue@9 13 local db
Nenue@13 14 local defaults = {
Nenue@13 15 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}},
Nenue@13 16 ['tags'] = {},
Nenue@13 17 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}},
Nenue@14 18 primary_channel = 1,
Nenue@13 19 current_channel = 1,
Nenue@14 20 toggle = true,
Nenue@13 21 dnd_status = true,
Nenue@13 22 dnd_message = "Debugging. Your messages may get eaten.",
Nenue@13 23 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]],
Nenue@13 24 fontsize = 13,
Nenue@13 25 fontoutline = 'NONE',
Nenue@14 26 backdrop = {1,1,1,0.2},
Nenue@14 27 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5},
Nenue@14 28 backblend = 'BLEND',
Nenue@14 29 frontdrop = {1,1,1,1},
Nenue@14 30 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9},
Nenue@22 31 frontblend = 'BLEND',
Nenue@22 32 frontborder = {1,0,0,1},
Nenue@22 33 backborder = {0,0,1,0.75},
Nenue@13 34 }
Nenue@9 35
Nenue@4 36
Nenue@13 37 local function ScanAddOnList(cmd, ...)
Nenue@0 38 local list_state
Nenue@0 39
Nenue@14 40 local args = {}
Nenue@14 41 local arg, n = D:GetArgs(cmd, 1)
Nenue@14 42 while arg do
Nenue@14 43 table.insert(args, arg)
Nenue@14 44 arg, n = D:GetArgs(cmd,1,n)
Nenue@14 45 end
Nenue@14 46 local mode, tag, dest = unpack(args)
Nenue@0 47
Nenue@13 48
Nenue@14 49 -- no args, toggle ui
Nenue@0 50 if mode == nil then
Nenue@0 51 list_state = db.enabled and STATE_LOW or STATE_HIGH
Nenue@0 52 db.enabled = (db.enabled == false) and true or false
Nenue@17 53 --print(list_state, db.enabled)
Nenue@0 54
Nenue@0 55 if list_state == STATE_LOW then
Nenue@0 56 end
Nenue@14 57 elseif mode == 'stack' then
Nenue@14 58 return D:StackFrames()
Nenue@14 59 elseif mode == 'grid' then
Nenue@14 60 return D:DistributeFrames()
Nenue@14 61 elseif mode == 'tag' then -- tagging
Nenue@14 62 if tag ~= nil and dest ~= nil then
Nenue@18 63 local channel = D:SetChannel(dest:match('%a'), dest:match('%d'))
Nenue@18 64 if not D.tags[tag] then
Nenue@18 65 D.tags[tag] = {}
Nenue@14 66 end
Nenue@18 67 if D.tags[tag][channel.index] then
Nenue@18 68 D.tags[tag][channel.index] = nil
Nenue@18 69 D:Print('Removed |cFFFFFF00'..tag..'|r from |cFF00FFFF'.. dest .. '|r')
Nenue@18 70 else
Nenue@18 71 D.tags[tag][channel.index] = channel.index
Nenue@18 72 D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r')
Nenue@18 73 end
Nenue@18 74
Nenue@14 75 else
Nenue@14 76 D:Print('Usage: /dvn tag <prefix> <console name or number>')
Nenue@14 77 end
Nenue@14 78 return
Nenue@14 79 elseif mode ~= nil then
Nenue@14 80 mode = tonumber(mode)
Nenue@0 81 if mode > 2 then
Nenue@17 82 --print('Something has happened.')
Nenue@0 83 return
Nenue@0 84 end
Nenue@0 85 list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH
Nenue@0 86 end
Nenue@0 87 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state]
Nenue@0 88
Nenue@0 89 local playername = UnitName("player")
Nenue@0 90
Nenue@0 91 for i = 1, GetNumAddOns() do
Nenue@0 92 local name = GetAddOnInfo(i)
Nenue@0 93 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
Nenue@0 94
Nenue@0 95 if mode == STATE_LOW or mode == STATE_HIGH then
Nenue@0 96 char_list[name] = enableState
Nenue@0 97 global_list[name] = globalState
Nenue@0 98 else
Nenue@13 99 if char_list[name] or global_list[name] then
Nenue@0 100
Nenue@0 101 if char_list[name] ~= 0 and global_list[name] ~= 0 then
Nenue@0 102 local value = false
Nenue@0 103 if char_list[name] == 2 and global_list[name] == 1 then
Nenue@0 104 value = UnitName("player")
Nenue@0 105 elseif global_list[name] == 2 then
Nenue@0 106 value = true
Nenue@0 107 end
Nenue@17 108 --print('EnableAddOn(', i, ',', value,')')
Nenue@0 109 EnableAddOn(i, value)
Nenue@0 110 else
Nenue@0 111 local value = true
Nenue@0 112 if char_list[name] == 2 and global_list[name] == 1 then
Nenue@0 113 value = UnitName("player")
Nenue@0 114 end
Nenue@17 115 --print('DisableAddOn(', i, ',', value,')')
Nenue@0 116 DisableAddOn(i,value)
Nenue@0 117 end
Nenue@13 118 end
Nenue@0 119
Nenue@0 120 end
Nenue@0 121 end
Nenue@0 122
Nenue@0 123 if mode == nil then
Nenue@0 124 ReloadUI()
Nenue@0 125 end
Nenue@0 126 if mode == STATE_LOW then
Nenue@0 127 D:Print('Developement AddOn list saved.')
Nenue@0 128 else
Nenue@0 129 D:Print('Standard AddOn list saved.')
Nenue@0 130 end
Nenue@0 131 end
Nenue@0 132
Nenue@0 133
Nenue@13 134 local function Console_MinMax(self)
Nenue@13 135 if self.minimized then
Nenue@7 136 self:Maximize()
Nenue@7 137 else
Nenue@7 138 self:Minimize()
Nenue@7 139 end
Nenue@7 140 end
Nenue@13 141
Nenue@13 142 local function Console_Minimize(self)
Nenue@13 143 self:SetHeight(20)
Nenue@13 144 self:SetMaxResize(GetScreenWidth(),20)
Nenue@13 145 self.minimized = true
Nenue@14 146 self.out:Hide()
Nenue@14 147 self:Save()
Nenue@7 148 end
Nenue@0 149
Nenue@13 150 local function Console_Maximize(self)
Nenue@13 151 local db = db.channels[self.index]
Nenue@13 152 self:SetHeight(db.height)
Nenue@13 153 self:SetMaxResize(GetScreenWidth(),GetScreenHeight())
Nenue@13 154 self.minimized = nil
Nenue@14 155 self.out:Show()
Nenue@14 156 self:Save()
Nenue@13 157 end
Nenue@13 158
Nenue@13 159
Nenue@13 160 local function Console_Save(self)
Nenue@13 161 local db = db.channels[self.index]
Nenue@14 162 if self.x then
Nenue@14 163 db.x = self.x
Nenue@14 164 else
Nenue@14 165 db.x = self:GetLeft()
Nenue@14 166 end
Nenue@14 167
Nenue@14 168 if self.y then
Nenue@14 169 db.y = self.y
Nenue@14 170 else
Nenue@14 171 db.y = (self:GetTop() - GetScreenHeight())
Nenue@14 172 end
Nenue@14 173
Nenue@14 174 if self.width then
Nenue@14 175 db.width = self.width
Nenue@14 176 else
Nenue@14 177 db.width = self:GetWidth()
Nenue@14 178 end
Nenue@14 179
Nenue@13 180 if not self.minimized then
Nenue@14 181 if self.height then
Nenue@14 182 db.height = self.height
Nenue@14 183 else
Nenue@14 184 db.height = self:GetHeight()
Nenue@14 185 end
Nenue@14 186 self:SetHeight(db.height)
Nenue@13 187 end
Nenue@14 188
Nenue@14 189 db.minimized = self.minimized and true or nil
Nenue@14 190 db.enabled = self:IsVisible() and true or nil
Nenue@14 191 db.active = self.active and true or nil
Nenue@17 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)
Nenue@13 193 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y)
Nenue@14 194 self:SetWidth(db.width)
Nenue@13 195 end
Nenue@13 196
Nenue@14 197 -- Console frame toggler
Nenue@14 198 -- @paramsig [...]
Nenue@14 199 -- @param ... one or more space-seperated channel keys
Nenue@13 200 local function Console_Toggle(input)
Nenue@14 201 local search = {}
Nenue@14 202 local key, n = D:GetArgs(input, 1)
Nenue@14 203 if key then
Nenue@14 204 repeat
Nenue@14 205 if D.sig[key] then
Nenue@14 206 table.insert(search, D.sig[key])
Nenue@14 207 elseif D.console[key] then
Nenue@14 208 table.insert(search, D.console[key])
Nenue@14 209 end
Nenue@14 210 key, n = D:GetArgs(input,1,n)
Nenue@14 211 until n == 1e9
Nenue@13 212 else
Nenue@13 213 search = D.console
Nenue@13 214 end
Nenue@13 215
Nenue@14 216 db.toggle = not db.toggle and true or nil
Nenue@13 217 for _, c in ipairs(search) do
Nenue@14 218 if db.toggle then
Nenue@14 219 c:Show()
Nenue@26 220 if db.current_channel == c.index then
Nenue@26 221 c:ToFront()
Nenue@26 222 end
Nenue@14 223 else
Nenue@14 224 c.enabled = nil
Nenue@14 225 c.minimized = nil
Nenue@14 226 c:Maximize()
Nenue@13 227 c:Hide()
Nenue@13 228 end
Nenue@13 229 end
Nenue@14 230
Nenue@14 231 if db.toggle then
Nenue@14 232 D:Print('toggled on?')
Nenue@14 233 else
Nenue@14 234 D:Print('toggled off?')
Nenue@14 235 end
Nenue@13 236 end
Nenue@13 237
Nenue@18 238 --- Brings the console to the front.
Nenue@18 239 -- Frame method used to bring a console frame to the front of the display stack.
Nenue@14 240 local function Console_ToFront(c)
Nenue@14 241 --print(D.raise_ct, 'Raising', c.signature)
Nenue@14 242 --print(unpack(db.frontdrop))
Nenue@14 243 --print(unpack(db.frontgrad))
Nenue@14 244 --print(db.frontblend)
Nenue@22 245 -- D.raise_ct = D.raise_ct + 1
Nenue@14 246 c:Raise()
Nenue@14 247 c.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@14 248 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
Nenue@14 249 c.out.backdrop:SetBlendMode(db.frontblend)
Nenue@20 250 db.current_channel = c.index
Nenue@18 251
Nenue@18 252 for _, part in pairs(c.border) do
Nenue@24 253 part:SetTexture(unpack(db.frontborder))
Nenue@18 254 end
Nenue@14 255
Nenue@14 256 for id, bc in pairs(D.console) do
Nenue@14 257 if id ~= c.index then
Nenue@14 258 --print(D.raise_ct, 'Lowering', bc.signature)
Nenue@14 259 --print(unpack(db.backdrop))
Nenue@14 260 --print(unpack(db.backgrad))
Nenue@14 261 --print(db.backblend)
Nenue@14 262 bc.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@14 263 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
Nenue@14 264 bc.out.backdrop:SetBlendMode(db.backblend)
Nenue@18 265
Nenue@18 266 for _, part in pairs(bc.border) do
Nenue@24 267 part:SetTexture(unpack(db.backborder))
Nenue@14 268 end
Nenue@18 269 end
Nenue@18 270
Nenue@14 271 end
Nenue@14 272
Nenue@14 273 end
Nenue@14 274
Nenue@18 275 --- Constructs the frame object for a console channel
Nenue@18 276 -- Initializes the console channel at a specified index.
Nenue@18 277 -- Configuration data can be overridden by passing a desired settings table.
Nenue@18 278 -- @param i Numeric index of the channel as it manifests in db.channels
Nenue@18 279 -- @param vars Optional settings table to be used.
Nenue@13 280 local function CreateConsole(i, vars)
Nenue@14 281
Nenue@14 282 if not vars then
Nenue@14 283 vars = db.channels[i]
Nenue@14 284 end
Nenue@14 285
Nenue@17 286 --print('make:', vars.signature, '(', vars.x, vars.y, ')', vars.width, 'x', vars.height)
Nenue@13 287 local f = CreateFrame('Frame', 'DevianChannelFrame' .. tostring(i), UIParent, DEVIAN_FRAME)
Nenue@14 288 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y)
Nenue@13 289 f:SetSize(vars.width, vars.height)
Nenue@13 290 f:Lower()
Nenue@13 291 f.out:SetFont(db.font, db.fontsize, db.fontoutline)
Nenue@22 292 if (db.current_channel == i) then
Nenue@24 293 f.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@22 294 else
Nenue@24 295 f.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@22 296 end
Nenue@22 297
Nenue@13 298 f.Save = Console_Save
Nenue@13 299 f.Minimize = Console_Minimize
Nenue@13 300 f.Maximize = Console_Maximize
Nenue@13 301 f.MinMax = Console_MinMax
Nenue@14 302 f.ToFront = Console_ToFront
Nenue@13 303 f.Toggle = D.Console_Toggle
Nenue@13 304 f.name = vars.name
Nenue@13 305 f.index = i
Nenue@14 306 f.signature = vars.signature
Nenue@14 307 f.format = vars.header
Nenue@14 308 f.x = vars.x
Nenue@14 309 f.y = vars.y
Nenue@14 310 f.width = vars.width
Nenue@14 311 f.height = vars.height
Nenue@13 312
Nenue@14 313 if vars.enabled then
Nenue@14 314 f.enabled = true
Nenue@14 315 if db.toggle then
Nenue@14 316 f:Show()
Nenue@14 317 end
Nenue@13 318 end
Nenue@14 319 if vars.minimized then
Nenue@13 320 f:Minimize()
Nenue@22 321 else
Nenue@22 322 f:Maximize()
Nenue@13 323 end
Nenue@13 324
Nenue@13 325 return f
Nenue@13 326 end
Nenue@13 327
Nenue@18 328 --- Creates a Devian-style output.
Nenue@18 329 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
Nenue@18 330 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
Nenue@18 331 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
Nenue@18 332 -- @param ... Output contents.
Nenue@0 333 local function Message(prefix, ...)
Nenue@24 334 if db.enabled == true then
Nenue@23 335 return D.oldprint(prefix, ...)
Nenue@23 336 end
Nenue@23 337
Nenue@1 338 if prefix == nil then
Nenue@13 339 prefix = 1
Nenue@1 340 end
Nenue@9 341
Nenue@18 342 local sendq = {}
Nenue@18 343 local tag, id
Nenue@13 344 local byName = true
Nenue@18 345 if D.tags[prefix] then
Nenue@18 346 for _, id in pairs(D.tags[prefix]) do
Nenue@18 347 if D.console[id] then
Nenue@18 348 sendq[id] = D.console[id]
Nenue@18 349 end
Nenue@18 350 end
Nenue@18 351 end
Nenue@18 352
Nenue@13 353 if D.sig[prefix] then
Nenue@18 354 sendq[D.sig[prefix].index] = D.sig[prefix]
Nenue@13 355 elseif D.console[prefix] then
Nenue@18 356 sendq[D.console[prefix]] = D.console[prefix]
Nenue@13 357 else
Nenue@18 358 sendq[D.primary_channel] = D.console[D.primary_channel]
Nenue@13 359 end
Nenue@18 360
Nenue@9 361 -- color me timbers
Nenue@9 362 local pcolor
Nenue@18 363 if (not db.tagcolor[prefix]) and byName then
Nenue@0 364 local c = {0, 0, 0 }
Nenue@0 365 local max = string.len(prefix)
Nenue@0 366 for i = 1, max, 3 do
Nenue@0 367 for k, v in ipairs(c) do
Nenue@0 368 local j = i + (k - 1)
Nenue@0 369 c[k] = c[k] + (j <= max and string.byte(prefix,j) or 0)
Nenue@0 370 end
Nenue@0 371 end
Nenue@0 372 for k,v in ipairs(c) do
Nenue@0 373 c[k] = c[k] % 255
Nenue@0 374 if c[k] < 64 then
Nenue@0 375 c[k] = 0
Nenue@0 376 elseif c[k] > 127 then
Nenue@0 377 c[k] = 255
Nenue@0 378 end
Nenue@0 379 end
Nenue@18 380 db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c))
Nenue@0 381 end
Nenue@18 382 pcolor = db.tagcolor[prefix]
Nenue@0 383
Nenue@18 384 local buffer = {'|cFF'.. pcolor..prefix ..'|r'}
Nenue@0 385 for i = 1, select('#',...) do
Nenue@0 386 local var = select(i, ...)
Nenue@0 387
Nenue@0 388 if type(var) == 'table' then
Nenue@20 389 if type(var.GetName) == 'function' then
Nenue@20 390 var = '<table:'..(var:GetName() or '?')..'>'
Nenue@20 391 else
Nenue@20 392 var = '<table>'
Nenue@20 393 end
Nenue@20 394
Nenue@0 395 elseif type(var) == 'boolean' then
Nenue@0 396 var = var and 'true' or 'false'
Nenue@0 397 elseif type(var) == 'function' then
Nenue@0 398 var = '<funcref>'
Nenue@0 399 elseif type(var) == 'nil' then
Nenue@0 400 var = 'nil'
Nenue@0 401 end
Nenue@0 402
Nenue@0 403 table.insert(buffer, var)
Nenue@0 404 end
Nenue@18 405 local message = table.concat(buffer, ' ')
Nenue@18 406 for id, channel in pairs(sendq) do
Nenue@18 407 channel.out:AddMessage(message)
Nenue@18 408 end
Nenue@0 409 table.wipe(buffer)
Nenue@0 410 end
Nenue@0 411
Nenue@18 412 --- Spaces each frame evenly across the screen.
Nenue@14 413 function D:DistributeFrames() --
Nenue@17 414 --print('frame grid:', max, num_side)
Nenue@14 415 local max = self.num_channels
Nenue@14 416 local num_side = math.ceil(math.sqrt(max))
Nenue@14 417 local w = GetScreenWidth() / num_side
Nenue@14 418 local h = GetScreenHeight() / num_side
Nenue@14 419 for i, frame in pairs(D.console) do
Nenue@14 420 local dx = (i-1) % num_side
Nenue@14 421 local dy = math.floor((i-1) / num_side)
Nenue@14 422
Nenue@17 423 --print('move:', frame.signature, 'dx=', dx, 'dy=', dy)
Nenue@17 424 --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w)
Nenue@14 425 frame.width = w
Nenue@14 426 frame.height = h
Nenue@14 427 frame.x = dx * w
Nenue@14 428 frame.y = -(dy * h)
Nenue@14 429 frame:Save()
Nenue@14 430 end
Nenue@14 431
Nenue@14 432 end
Nenue@14 433
Nenue@18 434 --- Place all frames stacked beneath the primary frame.
Nenue@14 435 function D:StackFrames()
Nenue@14 436 local last
Nenue@14 437 for i, frame in pairs(self.console) do
Nenue@14 438 if last then
Nenue@14 439 frame.x = last.x
Nenue@14 440 frame.y = last.y - 20
Nenue@14 441 else
Nenue@14 442 frame.x = (GetScreenWidth()-frame:GetWidth())/2
Nenue@14 443 frame.y = 0
Nenue@14 444 end
Nenue@14 445 frame:Save()
Nenue@14 446 last = frame
Nenue@14 447 end
Nenue@14 448 end
Nenue@14 449
Nenue@18 450 --- Updates a console "channel" entry, generating a new one if necessary.
Nenue@18 451 -- 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.
Nenue@18 452 -- 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.
Nenue@18 453 -- @usage cinfo [, i]
Nenue@18 454 -- @param cinfo Config variables table, or a string to be used as channel signature
Nenue@18 455 -- @param i Console index. If valid, settings will be inherited from that channel.
Nenue@14 456 function D:SetChannel(cinfo, i)
Nenue@17 457 --print('join:', i , cinfo)
Nenue@14 458 local t_info = {}
Nenue@18 459 local dbvars = db.channels[self.primary_channel]
Nenue@18 460 if type(cinfo) == 'string' then
Nenue@18 461 local signame = tostring(cinfo)
Nenue@18 462 t_info.signature = signame
Nenue@18 463 end
Nenue@18 464
Nenue@14 465 if type(cinfo) ~= 'table' then
Nenue@14 466 cinfo = {}
Nenue@14 467 end
Nenue@18 468
Nenue@18 469 if i then
Nenue@14 470 i = tonumber(i)
Nenue@14 471 if db.channels[i] then
Nenue@18 472 dbvars = db.channels[i]
Nenue@18 473 else
Nenue@18 474 -- if there is no channels[i], then we need to check for sig collision
Nenue@18 475 local sigvar = signame
Nenue@18 476 local j = 2
Nenue@18 477 while D.sig[sigvar] do
Nenue@18 478 sigvar = signame .. j
Nenue@18 479 j = j + 1
Nenue@18 480 end
Nenue@18 481 t_info.signature = sigvar
Nenue@14 482 end
Nenue@14 483 end
Nenue@14 484
Nenue@18 485 if not (cinfo.signature or t_info.signature) then
Nenue@18 486 t_info.signature = 'Console'..i
Nenue@18 487 end
Nenue@18 488
Nenue@18 489 for k,v in pairs(dbvars) do
Nenue@14 490 if not t_info[k] then
Nenue@14 491 if cinfo[k] then
Nenue@14 492 t_info[k] = cinfo[k]
Nenue@18 493 elseif db.channels[self.primary_channel][k] then
Nenue@18 494 t_info[k] = db.channels[self.primary_channel][k]
Nenue@14 495 end
Nenue@14 496 end
Nenue@14 497 end
Nenue@14 498
Nenue@14 499 if not db.channels[i] then
Nenue@14 500 t_info.x = t_info.x + 20
Nenue@14 501 t_info.y = t_info.y - 20
Nenue@14 502 db.channels[i] = t_info
Nenue@14 503 end
Nenue@18 504
Nenue@14 505 if not self.console[i] then
Nenue@14 506 self.console[i] = CreateConsole(i, t_info)
Nenue@14 507 end
Nenue@18 508 local channel = self.console[i]
Nenue@18 509 self.sig[t_info.signature] = channel
Nenue@18 510 self.sigID[t_info.signature] = i
Nenue@18 511 self.IDsig[i] = t_info.signature
Nenue@20 512 if i == db.current_channel then
Nenue@20 513 channel:ToFront()
Nenue@26 514 end
Nenue@20 515
Nenue@18 516 return channel
Nenue@14 517 end
Nenue@14 518
Nenue@0 519 function D:OnEnable()
Nenue@13 520 -- commands
Nenue@13 521 local cmdlist = {
Nenue@13 522 ['dvn'] = ScanAddOnList,
Nenue@13 523 ['devian'] = ScanAddOnList,
Nenue@13 524 ['dvc'] = Console_Toggle,
Nenue@13 525 }
Nenue@13 526 for cmd, func in pairs(cmdlist) do
Nenue@13 527 self:RegisterChatCommand(cmd, func, true)
Nenue@13 528 end
Nenue@13 529
Nenue@11 530 if db.enabled == true then
Nenue@0 531 D:Print('Standard AddOn list active. Type /dvn to switch to development mode.')
Nenue@0 532 else
Nenue@0 533 D:Print('Development AddOn list active. Type /dvn to revert to regular operation.')
Nenue@0 534 end
Nenue@13 535
Nenue@0 536 end
Nenue@0 537
Nenue@0 538 function D:OnInitialize()
Nenue@13 539 -- emergency button
Nenue@13 540 self:RegisterChatCommand("cleandvn", function(args)
Nenue@13 541 DevianDB = nil
Nenue@13 542 ReloadUI()
Nenue@13 543 end)
Nenue@13 544
Nenue@13 545 -- savedvars
Nenue@13 546 local cherry = false
Nenue@9 547 if not _G.DevianDB then
Nenue@13 548 _G.DevianDB = defaults
Nenue@13 549 cherry = "Type /dvnsave to snapshot your current UI"
Nenue@9 550 end
Nenue@9 551 db = _G.DevianDB
Nenue@0 552
Nenue@0 553 if not db[PLAYER_REALM] then
Nenue@9 554 db[PLAYER_REALM] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}
Nenue@0 555 if not cherry then
Nenue@0 556 cherry = "This character didn't have an AddOn table."
Nenue@0 557 end
Nenue@0 558 end
Nenue@0 559
Nenue@18 560
Nenue@18 561 if not db.tags then
Nenue@18 562 db.tags = {}
Nenue@13 563 end
Nenue@18 564 self.tags = db.tags
Nenue@0 565 if cherry then
Nenue@0 566 D:Print(cherry)
Nenue@0 567 end
Nenue@0 568 D.oldprint = getprinthandler()
Nenue@0 569 if not _G.oldprint then
Nenue@0 570 _G.oldprint = D.oldprint
Nenue@0 571 end
Nenue@13 572
Nenue@22 573 --self.raise_ct = 0
Nenue@14 574 self.last_channel = 0
Nenue@14 575 self.num_channels = 0
Nenue@13 576 self.console = {}
Nenue@13 577 self.sig = {}
Nenue@14 578 self.sigID = {}
Nenue@14 579 self.IDsig = {}
Nenue@14 580 for i, cinfo in pairs(db.channels) do
Nenue@14 581 i = tonumber(i)
Nenue@14 582 if not self.primary_channel then
Nenue@14 583 self.primary_channel = i
Nenue@14 584 end
Nenue@14 585 self:SetChannel(cinfo, i)
Nenue@14 586 if i > self.last_channel then
Nenue@14 587 self.last_channel = i
Nenue@14 588 end
Nenue@14 589 self.num_channels = self.num_channels + 1
Nenue@13 590 end
Nenue@18 591
Nenue@18 592 if self.console[db.current_channel] then
Nenue@18 593 self.console[db.current_channel]:ToFront()
Nenue@18 594 end
Nenue@18 595
Nenue@23 596 if db.enabled then
Nenue@24 597 for i, c in pairs(self.console) do
Nenue@23 598 self.console[i]:Hide()
Nenue@23 599 end
Nenue@23 600 end
Nenue@23 601
Nenue@23 602
Nenue@18 603 -- only do this in dev mode
Nenue@18 604 if db.enabled == false then
Nenue@18 605 setprinthandler(Message)
Nenue@18 606 print = function(...)
Nenue@18 607 _G.print('Dvn', ...)
Nenue@18 608 end
Nenue@18 609 end
Nenue@13 610 print(MAJOR, MINOR)
Nenue@0 611 end