annotate Devian.lua @ 32:c6a2c2df4790

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