annotate Devian.lua @ 102:c3e7d2a3f4e9

Fix consoles disappearing after movement events.
author Nenue
date Mon, 10 Apr 2017 13:21:11 -0400
parents 790dca545f1d
children 8dc0c1917890
rev   line source
Nenue@50 1 --- Devian - Devian.lua
Nenue@32 2 -- @file-author@
Nenue@32 3 -- @project-revision@ @project-hash@
Nenue@32 4 -- @file-revision@ @file-hash@
Nenue@66 5
Nenue@91 6 --GLOBALS: Devian, DevianLoadMessage, DEVIAN_WORKSPACE, DEVIAN_PNAME, DEVIAN_PID
Nenue@91 7
Nenue@100 8 SLASH_RL1 = "/rl"
Nenue@100 9 SlashCmdList.RL = function() ReloadUI() end
Nenue@91 10 DEVIAN_WORKSPACE = false
Nenue@91 11 DEVIAN_PNAME = 'Dvn'
Nenue@91 12 DEVIAN_PID = 0
Nenue@79 13
Nenue@66 14 local ADDON, D = ...
Nenue@79 15 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
Nenue@98 16 local D_INITIALIZED
Nenue@98 17 local next = next
Nenue@72 18 local sub, GetTime, print, _G = string.sub, GetTime, print, _G
Nenue@72 19 local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
Nenue@79 20 local tinsert, tremove, rawset = tinsert, tremove, rawset
Nenue@66 21 local currentProfile
Nenue@66 22 local playerName = UnitName("player")
Nenue@66 23 local playerRealm = playerName .. '-' .. GetRealmName()
Nenue@66 24 local num_dock_tabs = 0
Nenue@93 25 local charStates ={}
Nenue@79 26
Nenue@100 27 local channels_report = {}
Nenue@98 28 local registeredTags = {}
Nenue@98 29
Nenue@98 30
Nenue@98 31 DevianCore = {}
Nenue@98 32
Nenue@98 33 function DevianCore:OnLoad ()
Nenue@98 34 self:RegisterEvent('ADDON_LOADED')
Nenue@98 35 self:RegisterEvent('PLAYER_LOGIN')
Nenue@98 36 self:SetShown(true)
Nenue@98 37 end
Nenue@98 38
Nenue@98 39 function DevianCore:OnEvent(event, arg)
Nenue@98 40 if event == 'ADDON_LOADED' or event == 'PLAYER_LOGIN' then
Nenue@98 41 --print(event, arg, DevianDB)
Nenue@98 42 if (arg == 'Devian') and not D_INITIALIZED then
Nenue@98 43 D_INITIALIZED = true
Nenue@98 44 self:Initialize()
Nenue@98 45 self:UnregisterAllEvents()
Nenue@98 46 end
Nenue@98 47 end
Nenue@98 48 end
Nenue@98 49
Nenue@79 50 DevianLoadMessage = setmetatable({}, {
Nenue@79 51 __call = function(t, msg)
Nenue@79 52 rawset(t, #t+1, msg)
Nenue@79 53 end,
Nenue@79 54 __index = function(t)
Nenue@79 55 return #t
Nenue@79 56 end
Nenue@79 57 })
Nenue@79 58
Nenue@66 59 --@debug@
Nenue@66 60 D.debugmode = true
Nenue@66 61 --@end-debug@
Nenue@66 62 D.print = function(...)
Nenue@66 63 if currentProfile and not currentProfile.workspace then
Nenue@98 64 return nop
Nenue@66 65 end
Nenue@66 66
Nenue@66 67 if D.debugmode then
Nenue@66 68 return print('Dvn', ...)
Nenue@66 69 else
Nenue@93 70 return nop
Nenue@66 71 end
Nenue@0 72 end
Nenue@66 73 local print = D.print
Nenue@66 74
Nenue@66 75 D.L = setmetatable({}, {
Nenue@66 76 __index= function(t,k)
Nenue@98 77 return tostring(k)
Nenue@66 78 end,
Nenue@66 79 __call = function(t,k,...)
Nenue@98 80 return format((t[k]) , ...)
Nenue@66 81 end
Nenue@66 82 })
Nenue@66 83 D.oldprint = getprinthandler()
Nenue@66 84 if not _G.oldprint then _G.oldprint = D.oldprint end
Nenue@66 85
Nenue@47 86 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
Nenue@66 87 local max, rand, format, print = max, math.random, string.format, print
Nenue@47 88 local insert, wipe, concat = table.insert, table.wipe, table.concat
Nenue@47 89 local select, unpack = select, unpack
Nenue@47 90 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
Nenue@47 91 local UnitName, DisableAddOn = UnitName, DisableAddOn
Nenue@66 92
Nenue@98 93 local db, L
Nenue@13 94 local defaults = {
Nenue@66 95 global = {{}, {}},
Nenue@66 96 default_channel = {
Nenue@55 97 signature = 'Main',
Nenue@98 98 x = 100, y = -200,
Nenue@55 99 height = 500, width = 600,
Nenue@66 100 enabled = true},
Nenue@66 101 current_profile = 1,
Nenue@66 102 main_profile = 1,
Nenue@66 103 last_profile = 1,
Nenue@66 104 profilesName = {},
Nenue@66 105 profiles = {
Nenue@45 106 },
Nenue@33 107 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info
Nenue@13 108 fontsize = 13,
Nenue@13 109 fontoutline = 'NONE',
Nenue@45 110
Nenue@45 111 headergrad = {'VERTICAL', 0, 0, 0, 1,
Nenue@45 112 1, 0.1, 0.1, 1}, -- header info
Nenue@33 113 headerdrop = {1,1,1,1},
Nenue@45 114 headerblend = 'BLEND',
Nenue@33 115 headeralpha = 1,
Nenue@45 116 headerfontcolor = {1,1,1,1},
Nenue@45 117
Nenue@45 118 backdrop = {1,1,1,1}, -- background frame info
Nenue@56 119 backgrad = {'VERTICAL', 0, 0, 0, .75, 0,0,0, .65},
Nenue@55 120 backblend = 'BLEND',
Nenue@45 121 backalpha = 1,
Nenue@45 122 backborder = {.5,.5,.5,1},
Nenue@45 123 backheader = {.25,.25,.25,1},
Nenue@45 124
Nenue@45 125 frontdrop = {1,1,1,1}, -- foreground frame info
Nenue@56 126 frontgrad = {'VERTICAL', 0, 0, 0, 1, 0,0,0, 0.95},
Nenue@55 127 frontblend = 'BLEND',
Nenue@28 128 frontalpha = 1,
Nenue@45 129 frontborder = {.07,.47,1,1},
Nenue@45 130 frontheader = {1,1,1,1},
Nenue@33 131 tagcolor = {}, -- tag color repository
Nenue@36 132 workspace = 2, -- current profile
Nenue@47 133 last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued
Nenue@47 134
Nenue@47 135 dock_onshow_fade_time = 2.5,
Nenue@47 136 dock_onshow_fade_from = 1,
Nenue@47 137 dock_onshow_fade_to = 0.2,
Nenue@47 138
Nenue@47 139 dock_alpha_on = 1,
Nenue@47 140 dock_alpha_off = 0.2,
Nenue@47 141 dock_fade_in = 0.15,
Nenue@47 142 dock_fade_out = 0.45,
Nenue@47 143 dock_button_alpha_on = 1,
Nenue@47 144 dock_button_alpha_off = 0.2,
Nenue@50 145 dock_button_fade_in = 0.075,
Nenue@55 146 dock_button_fade_out = 0.075,
Nenue@47 147
Nenue@55 148 movement_fade = true,
Nenue@55 149 movement_fade_time = 0.15,
Nenue@60 150 movement_fade_from = 1,
Nenue@60 151 movement_fade_to = 0,
Nenue@60 152 movement_translation_x = 25,
Nenue@60 153 movement_translation_y = 25,
Nenue@13 154 }
Nenue@9 155
Nenue@66 156 D.console = {}
Nenue@66 157 D.max_channel = 0
Nenue@0 158
Nenue@67 159 D.InWorkspace = function ()
Nenue@67 160 return db.profiles[db.current_profile].workspace
Nenue@67 161 end
Nenue@67 162
Nenue@86 163 local profileTemplate = {
Nenue@86 164 name = function(id, name) return name end,
Nenue@86 165 workspace = function(id, name) return (id ~= 1) end,
Nenue@86 166 current_channel = 1,
Nenue@86 167 default_channel = 1,
Nenue@86 168 num_channels = 1,
Nenue@86 169 max_channel = 1, -- the highest created channel id
Nenue@86 170 enabled = true, -- allow enabled consoles to appear
Nenue@86 171 channels = {
Nenue@86 172 {
Nenue@86 173 index = 1,
Nenue@86 174 signature = 'Main',
Nenue@98 175 x = 100, y = -200,
Nenue@86 176 height = 500, width = 600,
Nenue@86 177 enabled = true
Nenue@86 178 }
Nenue@86 179 },
Nenue@86 180 loadouts = {},
Nenue@86 181 global = {},
Nenue@86 182 tags = {},
Nenue@86 183 char = {
Nenue@86 184 [playerRealm] = {}
Nenue@86 185 },
Nenue@86 186 unlisted = {}
Nenue@86 187 }
Nenue@86 188
Nenue@86 189 --- Applies complex template tables
Nenue@86 190 -- If he value is a function, then it will invoke f(...) and use whatever gets returned
Nenue@86 191 function D.DeepCopy(src, dest, ...)
Nenue@86 192
Nenue@86 193 for k,v in pairs(src) do
Nenue@86 194 if not dest[k] then
Nenue@93 195 --oldprint('Rebuilding conf value', k)
Nenue@86 196 if type(v) == 'table' then
Nenue@86 197 dest[k] = {}
Nenue@86 198 D.DeepCopy(v, dest[k], ...)
Nenue@86 199
Nenue@86 200 else
Nenue@86 201 if type(v) == 'function' then
Nenue@86 202 v = v(...)
Nenue@86 203 end
Nenue@86 204 dest[k] = v
Nenue@86 205 end
Nenue@86 206 end
Nenue@86 207 end
Nenue@86 208 end
Nenue@86 209
Nenue@98 210 D.FixProfile = function(forced)
Nenue@98 211
Nenue@98 212 local numChannels = 0
Nenue@98 213 local minChannel = 400
Nenue@98 214 local sortedChannels = {}
Nenue@98 215 local sortedTags = {}
Nenue@98 216 local maxChannel = 0
Nenue@98 217 for k,v in pairs(currentProfile.channels) do
Nenue@98 218 numChannels = numChannels + 1
Nenue@98 219 maxChannel = max(tonumber(k), maxChannel)
Nenue@98 220 minChannel = min(tonumber(k), minChannel)
Nenue@98 221 tinsert(sortedChannels, v)
Nenue@98 222 end
Nenue@98 223 if (maxChannel > numChannels) or forced then
Nenue@98 224 oldprint('fixing channels data')
Nenue@98 225 table.sort(sortedChannels, function(a,b)
Nenue@98 226 return (b.index > a.index)
Nenue@98 227 end)
Nenue@98 228 for i, info in ipairs(sortedChannels) do
Nenue@99 229
Nenue@99 230 info.tags = info.tags or {}
Nenue@98 231 for tag, tagSet in pairs(currentProfile.tags) do
Nenue@98 232 for _, index in pairs(tagSet) do
Nenue@98 233 if index == info.index then
Nenue@98 234 sortedTags[tag] = sortedTags[tag] or {}
Nenue@98 235 sortedTags[tag][i] = i
Nenue@99 236 tinsert(info.tags, tag)
Nenue@98 237 end
Nenue@98 238 end
Nenue@98 239 end
Nenue@99 240 print('Set tags:', table.concat(info.tags, ', '))
Nenue@98 241
Nenue@98 242 info.index = i
Nenue@98 243 end
Nenue@98 244 currentProfile.channels = sortedChannels
Nenue@98 245 currentProfile.tags = sortedTags
Nenue@98 246 else
Nenue@98 247 minChannel = 2
Nenue@98 248 end
Nenue@98 249 currentProfile.lastUpdateFix = MINOR
Nenue@98 250 end
Nenue@98 251
Nenue@66 252 D.Profile = function (id, name)
Nenue@66 253
Nenue@66 254 if name and not id and db.profilesName[name] then
Nenue@66 255 id = db.profilesName[name]
Nenue@66 256 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
Nenue@66 257 end
Nenue@66 258
Nenue@66 259 if not id or not db.profiles[id] then
Nenue@66 260 if not id then
Nenue@66 261 id = #db.profiles+1
Nenue@66 262 print('Generated profile ID: |cFFFFFF00'.. id .. '|r')
Nenue@66 263 end
Nenue@66 264
Nenue@66 265 if not name or db.profilesName[name] then
Nenue@66 266 local newName = name or (id == 1 and 'Main' or 'Profile')
Nenue@66 267 local prefix = newName
Nenue@66 268 local i = 2
Nenue@66 269 while db.profilesName[newName] do
Nenue@66 270 i = i + 1
Nenue@66 271 newName = prefix .. i
Nenue@66 272 end
Nenue@66 273 name = newName
Nenue@66 274 print('Generated profile name: |cFF00FF00'..newName..'|r')
Nenue@66 275 end
Nenue@86 276
Nenue@86 277
Nenue@86 278
Nenue@66 279 print('Creating profile')
Nenue@66 280 db.profilesName[name] = id
Nenue@86 281 db.profiles[id] = {}
Nenue@66 282 end
Nenue@66 283
Nenue@86 284
Nenue@86 285
Nenue@66 286 D.currentProfile = db.profiles[id]
Nenue@66 287 currentProfile = D.currentProfile
Nenue@86 288
Nenue@86 289 D.DeepCopy(profileTemplate, currentProfile, id, name)
Nenue@86 290
Nenue@86 291
Nenue@66 292 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
Nenue@66 293 if currentProfile.workspace then
Nenue@79 294 DEVIAN_WORKSPACE = true
Nenue@91 295 DEVIAN_PNAME = currentProfile.name
Nenue@89 296 DEVIAN_PID = id
Nenue@66 297 setprinthandler(D.Message)
Nenue@66 298 else
Nenue@79 299 DEVIAN_WORKSPACE = false
Nenue@93 300 DEVIAN_PNAME = nil
Nenue@93 301 print = nop
Nenue@66 302 end
Nenue@89 303 DEVIAN_PID =id
Nenue@66 304
Nenue@98 305
Nenue@98 306 -- Attempt to fix bad data
Nenue@98 307 --@debug@
Nenue@98 308 MINOR = 70100
Nenue@98 309 --@end-debug@
Nenue@98 310 if (currentProfile.lastUpdateFix or 0) < MINOR then
Nenue@98 311 D.FixProfile(true)
Nenue@98 312 end
Nenue@98 313
Nenue@98 314
Nenue@66 315 D.unlisted = currentProfile.unlisted
Nenue@66 316 D.channels = currentProfile.channels
Nenue@66 317 D.tags = currentProfile.tags
Nenue@66 318 D.channelinfo = currentProfile.channels
Nenue@66 319 D.char = currentProfile.char[playerRealm]
Nenue@66 320 D.global = currentProfile.global
Nenue@66 321 D.num_channels = currentProfile.num_channels
Nenue@66 322 D.enabled = currentProfile.enabled
Nenue@66 323 D.sig = {}
Nenue@66 324 D.sigID = {}
Nenue@66 325 D.IDsig = {}
Nenue@72 326 D.dock = _G.DevianDock
Nenue@66 327 D.dock.buttons = D.dock.buttons or {}
Nenue@66 328
Nenue@98 329
Nenue@98 330
Nenue@66 331 return id, name
Nenue@66 332 end
Nenue@66 333
Nenue@66 334 local targetGlobal, targetChar
Nenue@86 335 D.Command = function (cmd)
Nenue@66 336 local list_id, scan_func, reload
Nenue@86 337
Nenue@14 338 local args = {}
Nenue@86 339 if cmd then
Nenue@86 340 local i, j = 0, 0
Nenue@86 341 repeat
Nenue@86 342 i, j = cmd:find("%S+", j+1)
Nenue@86 343 if i and j then
Nenue@86 344 tinsert(args, cmd:sub(i, j))
Nenue@86 345 end
Nenue@86 346
Nenue@86 347 until not(i or j)
Nenue@14 348 end
Nenue@14 349 local mode, tag, dest = unpack(args)
Nenue@0 350
Nenue@86 351
Nenue@14 352 -- no args, toggle ui
Nenue@86 353 if mode == 'rc' then
Nenue@93 354 return D:ResetChannels(tag)
Nenue@86 355 elseif mode == 'stack' then
Nenue@14 356 return D:StackFrames()
Nenue@14 357 elseif mode == 'grid' then
Nenue@14 358 return D:DistributeFrames()
Nenue@14 359 elseif mode == 'tag' then -- tagging
Nenue@93 360 return D:Tag(tag, dest)
Nenue@73 361 elseif mode == 'new' then
Nenue@93 362 return D:New(tag)
Nenue@93 363 elseif mode == 'dock' then
Nenue@93 364 D.db.dockPoint = tag
Nenue@93 365 return D:UpdateDock()
Nenue@73 366 elseif mode == 'remove' then
Nenue@93 367 return D:Remove(tag)
Nenue@89 368 elseif mode ~= nil then
Nenue@89 369 -- profile selector or save command
Nenue@66 370 if mode == 'save' then
Nenue@66 371 list_id = tonumber(tag)
Nenue@89 372 else
Nenue@89 373 list_id = tonumber(mode)
Nenue@89 374 end
Nenue@89 375
Nenue@89 376 if not list_id then
Nenue@89 377 if db.profilesName[tostring(list_id)] then
Nenue@89 378 list_id = db.profilesName[tostring(list_id)]
Nenue@89 379 else
Nenue@89 380
Nenue@89 381 D:Print(L('Unable to resolve profile ID/name', list_id, dest))
Nenue@89 382 return
Nenue@66 383 end
Nenue@89 384 end
Nenue@89 385
Nenue@89 386
Nenue@89 387 if mode == 'save' then
Nenue@66 388 D.Profile(list_id, dest)
Nenue@66 389 scan_func = D.Save
Nenue@89 390
Nenue@89 391
Nenue@89 392 local name = currentProfile.name
Nenue@89 393 if dest then
Nenue@89 394 dest = dest:gsub("$%s+", ''):gsub("%s+^", '')
Nenue@89 395 if dest then
Nenue@89 396 if name then
Nenue@89 397 db.profilesName[name] = nil
Nenue@89 398 end
Nenue@89 399 db.profiles[list_id].name = dest
Nenue@89 400 db.profilesName[dest] = list_id
Nenue@92 401
Nenue@92 402 name = dest
Nenue@89 403 end
Nenue@89 404 end
Nenue@89 405
Nenue@89 406
Nenue@89 407 D:Print("Profile |cFFFFFF00".. list_id .."|r:|cFF00FFFF".. name .."|r saved.")
Nenue@66 408 else
Nenue@32 409
Nenue@89 410 if db.profiles[list_id] then
Nenue@89 411 D.LoadMessage ("Switched profiles.")
Nenue@89 412 if list_id ~= db.main_profile then
Nenue@89 413 db.last_profile = list_id
Nenue@89 414 end
Nenue@89 415 db.current_profile = list_id
Nenue@89 416 scan_func = D.Load
Nenue@89 417 else
Nenue@89 418 return D:PrintHelp()
Nenue@89 419 end
Nenue@36 420
Nenue@0 421 end
Nenue@32 422 elseif mode == nil then
Nenue@66 423 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
Nenue@77 424 D.LoadMessage ("Switched between main and recent profile ("..db.current_profile..' and '..list_id..')')
Nenue@66 425 db.current_profile = list_id
Nenue@66 426 scan_func = D.Load
Nenue@32 427 else
Nenue@89 428
Nenue@89 429
Nenue@32 430 return D:PrintHelp()
Nenue@0 431 end
Nenue@77 432
Nenue@77 433 if not db.profiles[list_id] then
Nenue@77 434 db.profiles[list_id] = {global = {}, char = {} }
Nenue@77 435 D.LoadMessage ("Starting profile #|cFF00FFFF".. list_id..'|r')
Nenue@77 436 end
Nenue@67 437 if not db.profiles[list_id].char[playerRealm] then
Nenue@67 438 db.profiles[list_id].char[playerRealm] = {}
Nenue@67 439 end
Nenue@67 440
Nenue@66 441 targetGlobal = db.profiles[list_id].global
Nenue@66 442 targetChar = db.profiles[list_id].char[playerRealm]
Nenue@32 443
Nenue@67 444
Nenue@66 445 if scan_func then
Nenue@93 446 wipe(charStates)
Nenue@66 447 for id, name, enableState, globalState in D.Addons() do
Nenue@66 448 scan_func(id, name, enableState, globalState)
Nenue@0 449 end
Nenue@0 450 end
Nenue@0 451
Nenue@66 452 if scan_func == D.Load then
Nenue@72 453 _G.ReloadUI()
Nenue@93 454 if AddonList_Update then
Nenue@93 455 AddonList_Update()
Nenue@93 456 end
Nenue@93 457 elseif (scan_func == D.Save) then
Nenue@93 458 print('reckoning')
Nenue@93 459 local updated = {}
Nenue@93 460 for addon, newState in pairs(charStates) do
Nenue@93 461 for character, addons in pairs(db.profiles[list_id].char) do
Nenue@93 462 if addons[addon] then
Nenue@93 463 print(addon, addons[addon], '::', newState)
Nenue@93 464 if (addons[addon] ~= newState) then
Nenue@93 465 addons[addon] = newState
Nenue@93 466 updated[character] = (updated[character] or 0) + 1
Nenue@93 467 end
Nenue@93 468
Nenue@93 469 end
Nenue@93 470
Nenue@93 471 end
Nenue@93 472 end
Nenue@93 473 for character, numAddons in pairs(updated) do
Nenue@93 474 print(character, numAddons, 'settings')
Nenue@93 475 end
Nenue@93 476
Nenue@66 477 end
Nenue@93 478
Nenue@93 479
Nenue@66 480 D.Profile(db.current_profile)
Nenue@66 481 end
Nenue@66 482
Nenue@66 483 D.Addons = function()
Nenue@66 484 local playername = UnitName("player")
Nenue@66 485 return function(n, i)
Nenue@66 486 if i >= n then
Nenue@66 487 return nil
Nenue@66 488 end
Nenue@66 489
Nenue@66 490 i = i + 1
Nenue@66 491 local name = GetAddOnInfo(i)
Nenue@66 492 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
Nenue@66 493 return i, name, enableState, globalState
Nenue@66 494 end, GetNumAddOns(), 0
Nenue@66 495 end
Nenue@66 496
Nenue@66 497 D.Load = function(id, name, charState, globalState)
Nenue@93 498 print('load', tostring(name), tostring(charState), tostring(globalState))
Nenue@93 499 if targetGlobal[name] == 2 then
Nenue@93 500 EnableAddOn(id, true)
Nenue@93 501 elseif targetChar[name] == 2 then
Nenue@93 502 EnableAddOn(id, playerName)
Nenue@93 503 elseif targetGlobal[name] == 0 then
Nenue@93 504 DisableAddOn(id, true)
Nenue@93 505 elseif targetChar[name] == 0 then
Nenue@93 506 DisableAddOn(id, playerName)
Nenue@93 507 end
Nenue@93 508
Nenue@93 509 if not (targetChar[name] or targetGlobal[name]) then
Nenue@66 510 tinsert(D.unlisted, name)
Nenue@66 511 end
Nenue@93 512
Nenue@66 513 end
Nenue@93 514
Nenue@93 515
Nenue@66 516 D.Save = function(id, name, charState, globalState)
Nenue@93 517 if (charState ~= 0) or (globalState ~= 0) then
Nenue@93 518 print('save', id, name, playerRealm .. ': '.. charState, 'All: '.. globalState)
Nenue@93 519 end
Nenue@93 520
Nenue@66 521 targetGlobal[name] = globalState
Nenue@66 522 targetChar[name] = charState
Nenue@93 523
Nenue@93 524 -- if enabling/disabling globally
Nenue@93 525 if globalState ~= 1 then
Nenue@93 526 charStates[name] = globalState
Nenue@93 527 end
Nenue@66 528 end
Nenue@57 529
Nenue@98 530 D.UpdateTags = function()
Nenue@98 531 wipe(registeredTags)
Nenue@99 532 for index, channel in ipairs(D.channels) do
Nenue@99 533 for _, tag in ipairs(channel.tags) do
Nenue@99 534 registeredTags[tag] = registeredTags[tag] or {}
Nenue@99 535 tinsert(registeredTags[tag], D.console[index])
Nenue@98 536 end
Nenue@98 537 end
Nenue@98 538 end
Nenue@98 539
Nenue@99 540 D.Tag = function(self, tag, id)
Nenue@66 541 local sig
Nenue@99 542 if tag and id then
Nenue@66 543 --@debug@
Nenue@66 544 --print(tag, dest)
Nenue@66 545 --@end-debug@
Nenue@66 546
Nenue@66 547 -- convert to ID
Nenue@99 548 local channel, sig
Nenue@99 549 if tonumber(id) == nil then
Nenue@99 550 sig = id
Nenue@99 551 if D.sigID[id] then
Nenue@99 552 id = D.sigID[id]
Nenue@99 553 channel = D.channels[id]
Nenue@66 554 end
Nenue@57 555 else
Nenue@99 556 id = tonumber(id)
Nenue@99 557 channel = D.channels[id]
Nenue@32 558 end
Nenue@66 559
Nenue@99 560 -- if channel is still nil, create one
Nenue@99 561 if not channel then
Nenue@99 562 id = #D.channels + 1
Nenue@99 563 D:Print(L('New channel created', (sig and (id..':'..sig)) or id))
Nenue@99 564 channel = D:GetOrCreateChannel(id, sig)
Nenue@66 565 else
Nenue@99 566 sig = channel.signature
Nenue@66 567 end
Nenue@66 568 --@debug@
Nenue@66 569 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
Nenue@66 570
Nenue@66 571 if not currentProfile.tags[tag] then -- no tag table?
Nenue@99 572 currentProfile.tags[tag] = {}
Nenue@66 573 end
Nenue@66 574
Nenue@99 575 local existingTag = tContains(channel.tags, tag)
Nenue@99 576 if existingTag then -- is tag set?
Nenue@99 577
Nenue@99 578 for i, tag in ipairs(channel.tags) do
Nenue@99 579 if tag == tag then
Nenue@99 580 tremove(channel.tags, i)
Nenue@99 581 D:Print(L('Tag removed from channel', tag, channel.index, channel.signature))
Nenue@99 582 break
Nenue@99 583 end
Nenue@99 584 end
Nenue@66 585 else
Nenue@99 586 tinsert(channel.tags, tag)
Nenue@98 587 D:Print(L('Tag added to channel', tag, channel.index, channel.signature))
Nenue@66 588 end
Nenue@98 589 D.UpdateTags()
Nenue@98 590 DevianDock:Update()
Nenue@66 591 else
Nenue@66 592 D:Print(L['Command tag help'])
Nenue@0 593 end
Nenue@0 594 end
Nenue@0 595
Nenue@86 596 D.ResetChannels = function(self, profile)
Nenue@86 597 currentProfile.current_channel = 1
Nenue@86 598 currentProfile.primary_channel = 1
Nenue@86 599 currentProfile.channels = {}
Nenue@86 600 D.DeepCopy(profileTemplate.channels, currentProfile.channels)
Nenue@86 601 currentProfile.tags = {}
Nenue@86 602 D.LoadMessage('Profile reset.')
Nenue@86 603 ReloadUI()
Nenue@86 604 end
Nenue@86 605
Nenue@73 606 D.New = function(self, tag)
Nenue@73 607 if tag and not self.sigID[tag] then
Nenue@73 608 local id = D.max_channel + 1
Nenue@73 609 D.SetChannel(tag, id)
Nenue@73 610 end
Nenue@73 611 end
Nenue@0 612
Nenue@73 613 D.Remove = function(self, dest)
Nenue@73 614 dest = D.sigID[dest] or tonumber(dest)
Nenue@73 615 if D.console[dest] and D.channels[dest] then
Nenue@73 616 for tag, tagDest in pairs(D.tags) do
Nenue@73 617 for i = #tagDest, 0 do
Nenue@73 618 -- work downward so we aren't skipping entries
Nenue@73 619 if tagDest[i] == dest then
Nenue@73 620 tremove(tagDest, i)
Nenue@73 621 end
Nenue@73 622 end
Nenue@73 623 end
Nenue@73 624 D.console[dest]:Hide()
Nenue@73 625 D.channels[dest] = nil
Nenue@73 626 tremove(D.console, dest)
Nenue@93 627 D.dock.buttons[dest]:SetShown(false)
Nenue@73 628 D:UpdateDock()
Nenue@73 629 D:Print('Removed channel #'..dest)
Nenue@73 630 end
Nenue@73 631 end
Nenue@13 632
Nenue@77 633 --- Queue up a message to appear after UI reload
Nenue@77 634 function D.LoadMessage(msg)
Nenue@77 635
Nenue@77 636 tinsert(_G.DevianLoadMessage, msg)
Nenue@77 637 end
Nenue@77 638
Nenue@18 639 --- Creates a Devian-style output.
Nenue@18 640 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
Nenue@18 641 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
Nenue@18 642 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
Nenue@18 643 -- @param ... Output contents.
Nenue@98 644 local default_sendq = {}
Nenue@66 645 function D.Message(prefix, ...)
Nenue@67 646 if not currentProfile.workspace then
Nenue@23 647 return D.oldprint(prefix, ...)
Nenue@23 648 end
Nenue@98 649 local print = D.oldprint
Nenue@57 650 prefix = tostring(prefix)
Nenue@57 651 if prefix == nil then
Nenue@55 652 prefix = 'nil*'
Nenue@1 653 end
Nenue@9 654
Nenue@98 655 local sendq = default_sendq
Nenue@30 656 local tag, id, tagged
Nenue@13 657 local byName = true
Nenue@98 658
Nenue@98 659 if registeredTags[prefix] then
Nenue@98 660 sendq = registeredTags[prefix]
Nenue@98 661 else
Nenue@98 662 if D.sig[prefix] then
Nenue@98 663 sendq[D.sig[prefix].index] = D.sig[prefix]
Nenue@98 664 elseif not tagged then
Nenue@98 665 sendq[1] = D.console[D.primary_channel]
Nenue@18 666 end
Nenue@18 667 end
Nenue@18 668
Nenue@98 669
Nenue@18 670
Nenue@9 671 -- color me timbers
Nenue@9 672 local pcolor
Nenue@18 673 if (not db.tagcolor[prefix]) and byName then
Nenue@86 674 -- numbers, use white
Nenue@86 675 if prefix:match('^%d+%.%d+') then
Nenue@73 676 pcolor = 'FFFFFF'
Nenue@73 677 else
Nenue@73 678 local c = {
Nenue@73 679 rand(64,255), rand(64,255), rand(64,255)
Nenue@73 680 }
Nenue@73 681 if c[1] > 223 and c[2] > 223 and c[3] > 223 then
Nenue@73 682 c[rand(1,3)] = rand(64,223)
Nenue@73 683 end
Nenue@73 684 db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c))
Nenue@73 685 pcolor = db.tagcolor[prefix]
Nenue@0 686 end
Nenue@73 687 else
Nenue@73 688 pcolor = db.tagcolor[prefix]
Nenue@0 689 end
Nenue@0 690
Nenue@55 691 local buffer = {}
Nenue@0 692 for i = 1, select('#',...) do
Nenue@0 693 local var = select(i, ...)
Nenue@0 694
Nenue@0 695 if type(var) == 'table' then
Nenue@20 696 if type(var.GetName) == 'function' then
Nenue@72 697 var = '[table:'..tostring(var:GetName())..']'
Nenue@20 698 else
Nenue@32 699 var = '<'..tostring(var)..'>'
Nenue@20 700 end
Nenue@20 701
Nenue@0 702 elseif type(var) == 'boolean' then
Nenue@75 703 var = var and 'true' or 'false'
Nenue@0 704 elseif type(var) == 'function' then
Nenue@72 705 var = '['..tostring(var)..']'
Nenue@0 706 elseif type(var) == 'nil' then
Nenue@75 707 var = 'nil'
Nenue@60 708 else
Nenue@60 709 var = tostring(var)
Nenue@0 710 end
Nenue@0 711
Nenue@47 712 insert(buffer, var)
Nenue@0 713 end
Nenue@47 714 local message = concat(buffer, ' ')
Nenue@18 715 for id, channel in pairs(sendq) do
Nenue@55 716 if channel.width < 250 then
Nenue@72 717 prefix = sub(prefix, 0,2)
Nenue@55 718 end
Nenue@98 719 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8)
Nenue@100 720 if not channel.newMessage then
Nenue@100 721 channel.newMessage = true
Nenue@100 722 if channel.Dock then
Nenue@100 723 channel.Dock:Update()
Nenue@100 724 end
Nenue@58 725 end
Nenue@18 726 end
Nenue@47 727 wipe(buffer)
Nenue@0 728 end
Nenue@0 729
Nenue@14 730
Nenue@32 731
Nenue@14 732
Nenue@32 733 function D:PrintHelp()
Nenue@32 734 D:Print("|cFFFFFF00/dvn|r",
Nenue@32 735 "\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@47 736 D:Print("|cFFFFFF00/dvc|r [<key>, ...]", "- Hides and show consoles. A list of channel keys can be passed to specify which ones get toggled.")
Nenue@32 737
Nenue@32 738 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.")
Nenue@32 739 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
Nenue@32 740 end
Nenue@32 741
Nenue@66 742 local blocked = {profiles = true, debugmode = true}
Nenue@66 743 D.SetDefaults = function()
Nenue@72 744 local DevianDB = _G.DevianDB
Nenue@66 745 for k,v in pairs(DevianDB) do
Nenue@66 746 if not blocked[k] then
Nenue@66 747 DevianDB[k] = nil
Nenue@60 748 end
Nenue@60 749 end
Nenue@66 750 for k,v in pairs(defaults) do
Nenue@66 751 if not blocked[k] then
Nenue@66 752 DevianDB[k] = v
Nenue@60 753 end
Nenue@60 754 end
Nenue@73 755
Nenue@77 756 D.LoadMessage "Non-user SavedVars have been reset."
Nenue@72 757 _G.ReloadUI()
Nenue@60 758 end
Nenue@66 759 D.SetDefaultsAll = function ()
Nenue@72 760 _G.DevianDB = nil
Nenue@77 761 D.LoadMessage "All SavedVars wiped."
Nenue@72 762 _G.ReloadUI()
Nenue@66 763 end
Nenue@73 764
Nenue@73 765 D.UnsetColors = function()
Nenue@73 766 db.tagcolor = {}
Nenue@73 767 D:Print('Tag color cache cleared.')
Nenue@73 768 end
Nenue@45 769
Nenue@33 770
Nenue@89 771 function D.ConsoleCommand (cmd)
Nenue@100 772 DevianDock:ToggleAll()
Nenue@89 773 end
Nenue@87 774
Nenue@66 775
Nenue@98 776 function DevianCore:Initialize()
Nenue@81 777 L = D.L
Nenue@13 778
Nenue@33 779 -- pull defaults
Nenue@98 780 if not DevianDB then
Nenue@98 781 DevianDB = defaults
Nenue@9 782 end
Nenue@98 783 D.db = _G.DevianDB
Nenue@9 784 db = _G.DevianDB
Nenue@0 785
Nenue@66 786 ---
Nenue@77 787 if #_G.DevianLoadMessage >= 1 then
Nenue@77 788 for i, msg in ipairs(_G.DevianLoadMessage) do
Nenue@77 789 D:Print(msg)
Nenue@77 790 end
Nenue@77 791
Nenue@77 792 table.wipe(_G.DevianLoadMessage)
Nenue@0 793 end
Nenue@0 794
Nenue@66 795
Nenue@89 796 -- commands
Nenue@89 797 local cmdlist = {
Nenue@89 798 ['dvn'] = "Command",
Nenue@89 799 ['devian'] = "Command",
Nenue@89 800 ['dvc'] = "ConsoleCommand",
Nenue@89 801 ['dvncolors'] = "UnsetColors",
Nenue@89 802 ['cleandvn'] = "SetDefaultsAll",
Nenue@89 803 ['resetdvn'] = "SetDefaults",
Nenue@89 804 }
Nenue@89 805 for cmd, func in pairs(cmdlist) do
Nenue@89 806 local CMD = cmd:upper()
Nenue@89 807 _G['SLASH_' .. CMD .. '1'] = "/"..cmd
Nenue@89 808
Nenue@89 809 if type(func == 'string') then
Nenue@93 810 --print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 811 SlashCmdList[CMD] = D[func]
Nenue@89 812 else
Nenue@93 813 --print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 814 SlashCmdList[CMD] = func
Nenue@89 815 end
Nenue@89 816 end
Nenue@89 817
Nenue@66 818 --- initialize the current profile
Nenue@66 819 local id, name = D.Profile(db.current_profile or 1)
Nenue@66 820 if currentProfile.workspace then
Nenue@100 821 tinsert(channels_report, 'Profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name.. '|r')
Nenue@86 822 if D.channels[currentProfile.default_channel] then
Nenue@100 823 tinsert(channels_report, 'Primary: |cFFFFFF00#'..currentProfile.default_channel..'|r |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
Nenue@86 824 end
Nenue@0 825 end
Nenue@13 826
Nenue@86 827
Nenue@98 828
Nenue@98 829 for index, cinfo in ipairs(D.channels) do
Nenue@98 830 --oldprint(index, cinfo.signature)
Nenue@66 831 if not D.primary_channel then
Nenue@98 832 D.primary_channel = index
Nenue@14 833 end
Nenue@98 834 D:GetOrCreateChannel(index)
Nenue@98 835 D.num_channels = #D.channels
Nenue@32 836 end
Nenue@100 837 if #channels_report >= 1 then
Nenue@100 838 D:Print(concat(channels_report, ', '))
Nenue@100 839 end
Nenue@100 840
Nenue@86 841 D.primary_channel = D.primary_channel or 1
Nenue@66 842 D.max_channel = max(D.max_channel, currentProfile.max_channel)
Nenue@66 843 if currentProfile.max_channel < D.max_channel then
Nenue@66 844 for i = currentProfile.max_channel, D.max_channel do
Nenue@66 845 D.console[i]:Hide()
Nenue@47 846 end
Nenue@36 847 end
Nenue@36 848
Nenue@98 849 D.UpdateTags()
Nenue@98 850
Nenue@66 851 if currentProfile.workspace then
Nenue@66 852 if D.console[currentProfile.current_channel] then
Nenue@69 853 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
Nenue@66 854 D.console[currentProfile.current_channel]:ToFront()
Nenue@66 855 -- bring the current channel to the front
Nenue@47 856 end
Nenue@98 857 DevianDock:Update()
Nenue@36 858 end
Nenue@66 859 end
Nenue@89 860
Nenue@98 861 function D:Print (...)
Nenue@98 862 local msg = '|cFF00FF44Devian|r:'
Nenue@98 863 for i = 1, select('#', ...) do
Nenue@98 864 msg = msg .. ' ' .. tostring(select(i, ...))
Nenue@98 865 end
Nenue@98 866 DEFAULT_CHAT_FRAME:AddMessage(msg)
Nenue@98 867 end
Nenue@98 868
Nenue@98 869 function D:GetActiveChannel()
Nenue@98 870 return D.console[currentProfile.current_channel]
Nenue@98 871 end
Nenue@98 872
Nenue@98 873 function D:GetOrCreateChannel(id, name)
Nenue@99 874 id = id or (#D.channels + 1)
Nenue@99 875
Nenue@98 876 local info = D.channels[id]
Nenue@99 877 if not info then
Nenue@99 878 --print('new channel')
Nenue@99 879 name = name or ('Channel ' .. id)
Nenue@99 880 info = {
Nenue@99 881 index = id,
Nenue@99 882 signature = name,
Nenue@99 883 tags = {}
Nenue@99 884 }
Nenue@99 885 D.DeepCopy(defaults.default_channel, info)
Nenue@99 886 D.channels[id] = info
Nenue@99 887 elseif not info.tags then
Nenue@99 888 -- fix old data?
Nenue@99 889 info.tags = {info.signature}
Nenue@99 890 oldprint(D.db)
Nenue@99 891 for tag, tagSet in pairs(D.tags) do
Nenue@99 892 for _, index in pairs(tagSet) do
Nenue@99 893 if index == id then
Nenue@99 894 tinsert(info.tags, tag)
Nenue@99 895 end
Nenue@99 896 end
Nenue@99 897 end
Nenue@99 898 end
Nenue@99 899
Nenue@98 900 local frame = D.console[id]
Nenue@100 901
Nenue@98 902 if not frame then
Nenue@98 903
Nenue@99 904 if DEVIAN_WORKSPACE then
Nenue@100 905 tinsert(channels_report, (info.index) .. ':' .. (info.signature) .. ' (|cFF00FFFF'.. concat(info.tags, '|r; |cFF00FFFF')..'|r)')
Nenue@99 906 end
Nenue@98 907 frame = CreateFrame('Frame', 'DevianConsole'..id, Devian, 'DevianConsoleTemplate')
Nenue@98 908 frame:SetID(id)
Nenue@98 909 D.console[id] = frame
Nenue@99 910 D.sigID[info.signature] = id
Nenue@98 911 end
Nenue@98 912
Nenue@98 913 frame:Setup(info)
Nenue@98 914 return frame
Nenue@98 915 end