annotate Devian.lua @ 20:df098747b31d v1.4.1

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