annotate Devian.lua @ 28:31ca76e04766 v1.4.4

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