annotate Devian.lua @ 92:4370eefcecdd

- display the correct profile name when it's changed through /dvn save
author Nenue
date Wed, 10 Aug 2016 07:12:43 -0400
parents bb403e03d82d
children f6fae1a4c66c
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@91 8 DEVIAN_WORKSPACE = false
Nenue@91 9 DEVIAN_PNAME = 'Dvn'
Nenue@91 10 DEVIAN_PID = 0
Nenue@79 11
Nenue@66 12 local ADDON, D = ...
Nenue@79 13 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
Nenue@79 14 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0")
Nenue@79 15 local L = D.L
Nenue@79 16 Devian = D
Nenue@72 17 local sub, GetTime, print, _G = string.sub, GetTime, print, _G
Nenue@72 18 local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
Nenue@79 19 local tinsert, tremove, rawset = tinsert, tremove, rawset
Nenue@66 20 local currentProfile
Nenue@66 21 local playerName = UnitName("player")
Nenue@66 22 local playerRealm = playerName .. '-' .. GetRealmName()
Nenue@66 23 local num_dock_tabs = 0
Nenue@79 24
Nenue@79 25
Nenue@79 26 DevianLoadMessage = setmetatable({}, {
Nenue@79 27 __call = function(t, msg)
Nenue@79 28 rawset(t, #t+1, msg)
Nenue@79 29 end,
Nenue@79 30 __index = function(t)
Nenue@79 31 return #t
Nenue@79 32 end
Nenue@79 33 })
Nenue@79 34
Nenue@66 35 --@debug@
Nenue@66 36 D.debugmode = true
Nenue@66 37 --@end-debug@
Nenue@66 38 D.print = function(...)
Nenue@66 39 if currentProfile and not currentProfile.workspace then
Nenue@66 40 return
Nenue@66 41 end
Nenue@66 42
Nenue@66 43 if D.debugmode then
Nenue@66 44 return print('Dvn', ...)
Nenue@66 45 else
Nenue@66 46 return function() end
Nenue@66 47 end
Nenue@0 48 end
Nenue@66 49 local print = D.print
Nenue@66 50
Nenue@66 51 D.L = setmetatable({}, {
Nenue@66 52 __index= function(t,k)
Nenue@66 53 return k
Nenue@66 54 end,
Nenue@66 55 __call = function(t,k,...)
Nenue@72 56 return format((t[k] or k) , ...)
Nenue@66 57 end
Nenue@66 58 })
Nenue@46 59 D:SetDefaultModuleState(false)
Nenue@66 60 D.oldprint = getprinthandler()
Nenue@66 61 if not _G.oldprint then _G.oldprint = D.oldprint end
Nenue@66 62
Nenue@47 63 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
Nenue@66 64 local max, rand, format, print = max, math.random, string.format, print
Nenue@47 65 local insert, wipe, concat = table.insert, table.wipe, table.concat
Nenue@47 66 local select, unpack = select, unpack
Nenue@47 67 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
Nenue@47 68 local UnitName, DisableAddOn = UnitName, DisableAddOn
Nenue@66 69
Nenue@9 70 local db
Nenue@13 71 local defaults = {
Nenue@66 72 global = {{}, {}},
Nenue@66 73 default_channel = {
Nenue@55 74 signature = 'Main',
Nenue@55 75 x = 100, y = 800,
Nenue@55 76 height = 500, width = 600,
Nenue@66 77 enabled = true},
Nenue@66 78 current_profile = 1,
Nenue@66 79 main_profile = 1,
Nenue@66 80 last_profile = 1,
Nenue@66 81 profilesName = {},
Nenue@66 82 profiles = {
Nenue@45 83 },
Nenue@33 84 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info
Nenue@13 85 fontsize = 13,
Nenue@13 86 fontoutline = 'NONE',
Nenue@45 87
Nenue@45 88 headergrad = {'VERTICAL', 0, 0, 0, 1,
Nenue@45 89 1, 0.1, 0.1, 1}, -- header info
Nenue@33 90 headerdrop = {1,1,1,1},
Nenue@45 91 headerblend = 'BLEND',
Nenue@33 92 headeralpha = 1,
Nenue@45 93 headerfontcolor = {1,1,1,1},
Nenue@45 94
Nenue@45 95 backdrop = {1,1,1,1}, -- background frame info
Nenue@56 96 backgrad = {'VERTICAL', 0, 0, 0, .75, 0,0,0, .65},
Nenue@55 97 backblend = 'BLEND',
Nenue@45 98 backalpha = 1,
Nenue@45 99 backborder = {.5,.5,.5,1},
Nenue@45 100 backheader = {.25,.25,.25,1},
Nenue@45 101
Nenue@45 102 frontdrop = {1,1,1,1}, -- foreground frame info
Nenue@56 103 frontgrad = {'VERTICAL', 0, 0, 0, 1, 0,0,0, 0.95},
Nenue@55 104 frontblend = 'BLEND',
Nenue@28 105 frontalpha = 1,
Nenue@45 106 frontborder = {.07,.47,1,1},
Nenue@45 107 frontheader = {1,1,1,1},
Nenue@33 108 tagcolor = {}, -- tag color repository
Nenue@36 109 workspace = 2, -- current profile
Nenue@47 110 last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued
Nenue@47 111
Nenue@47 112 dock_onshow_fade_time = 2.5,
Nenue@47 113 dock_onshow_fade_from = 1,
Nenue@47 114 dock_onshow_fade_to = 0.2,
Nenue@47 115
Nenue@47 116 dock_alpha_on = 1,
Nenue@47 117 dock_alpha_off = 0.2,
Nenue@47 118 dock_fade_in = 0.15,
Nenue@47 119 dock_fade_out = 0.45,
Nenue@47 120 dock_button_alpha_on = 1,
Nenue@47 121 dock_button_alpha_off = 0.2,
Nenue@50 122 dock_button_fade_in = 0.075,
Nenue@55 123 dock_button_fade_out = 0.075,
Nenue@47 124
Nenue@55 125 movement_fade = true,
Nenue@55 126 movement_fade_time = 0.15,
Nenue@60 127 movement_fade_from = 1,
Nenue@60 128 movement_fade_to = 0,
Nenue@60 129 movement_translation_x = 25,
Nenue@60 130 movement_translation_y = 25,
Nenue@13 131 }
Nenue@9 132
Nenue@66 133 D.console = {}
Nenue@66 134 D.max_channel = 0
Nenue@0 135
Nenue@67 136 D.InWorkspace = function ()
Nenue@67 137 return db.profiles[db.current_profile].workspace
Nenue@67 138 end
Nenue@67 139
Nenue@86 140 local profileTemplate = {
Nenue@86 141 name = function(id, name) return name end,
Nenue@86 142 workspace = function(id, name) return (id ~= 1) end,
Nenue@86 143 current_channel = 1,
Nenue@86 144 default_channel = 1,
Nenue@86 145 num_channels = 1,
Nenue@86 146 max_channel = 1, -- the highest created channel id
Nenue@86 147 enabled = true, -- allow enabled consoles to appear
Nenue@86 148 channels = {
Nenue@86 149 {
Nenue@86 150 index = 1,
Nenue@86 151 signature = 'Main',
Nenue@86 152 x = 100, y = 800,
Nenue@86 153 height = 500, width = 600,
Nenue@86 154 enabled = true
Nenue@86 155 }
Nenue@86 156 },
Nenue@86 157 loadouts = {},
Nenue@86 158 global = {},
Nenue@86 159 tags = {},
Nenue@86 160 char = {
Nenue@86 161 [playerRealm] = {}
Nenue@86 162 },
Nenue@86 163 unlisted = {}
Nenue@86 164 }
Nenue@86 165
Nenue@86 166 --- Applies complex template tables
Nenue@86 167 -- If he value is a function, then it will invoke f(...) and use whatever gets returned
Nenue@86 168 function D.DeepCopy(src, dest, ...)
Nenue@86 169
Nenue@86 170 for k,v in pairs(src) do
Nenue@86 171 if not dest[k] then
Nenue@86 172 oldprint('Rebuilding conf value', k)
Nenue@86 173 if type(v) == 'table' then
Nenue@86 174 dest[k] = {}
Nenue@86 175 D.DeepCopy(v, dest[k], ...)
Nenue@86 176
Nenue@86 177 else
Nenue@86 178 if type(v) == 'function' then
Nenue@86 179 v = v(...)
Nenue@86 180 end
Nenue@86 181 dest[k] = v
Nenue@86 182 end
Nenue@86 183 end
Nenue@86 184 end
Nenue@86 185 end
Nenue@86 186
Nenue@66 187 D.Profile = function (id, name)
Nenue@66 188
Nenue@66 189 if name and not id and db.profilesName[name] then
Nenue@66 190 id = db.profilesName[name]
Nenue@66 191 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
Nenue@66 192 end
Nenue@66 193
Nenue@66 194 if not id or not db.profiles[id] then
Nenue@66 195 if not id then
Nenue@66 196 id = #db.profiles+1
Nenue@66 197 print('Generated profile ID: |cFFFFFF00'.. id .. '|r')
Nenue@66 198 end
Nenue@66 199
Nenue@66 200 if not name or db.profilesName[name] then
Nenue@66 201 local newName = name or (id == 1 and 'Main' or 'Profile')
Nenue@66 202 local prefix = newName
Nenue@66 203 local i = 2
Nenue@66 204 while db.profilesName[newName] do
Nenue@66 205 i = i + 1
Nenue@66 206 newName = prefix .. i
Nenue@66 207 end
Nenue@66 208 name = newName
Nenue@66 209 print('Generated profile name: |cFF00FF00'..newName..'|r')
Nenue@66 210 end
Nenue@86 211
Nenue@86 212
Nenue@86 213
Nenue@66 214 print('Creating profile')
Nenue@66 215 db.profilesName[name] = id
Nenue@86 216 db.profiles[id] = {}
Nenue@66 217 end
Nenue@66 218
Nenue@86 219
Nenue@86 220
Nenue@66 221 D.currentProfile = db.profiles[id]
Nenue@66 222 currentProfile = D.currentProfile
Nenue@86 223
Nenue@86 224 D.DeepCopy(profileTemplate, currentProfile, id, name)
Nenue@86 225
Nenue@86 226
Nenue@66 227 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
Nenue@66 228 if currentProfile.workspace then
Nenue@79 229 DEVIAN_WORKSPACE = true
Nenue@91 230 DEVIAN_PNAME = currentProfile.name
Nenue@89 231 DEVIAN_PID = id
Nenue@66 232 setprinthandler(D.Message)
Nenue@66 233 else
Nenue@79 234 DEVIAN_WORKSPACE = false
Nenue@89 235 DEVIAN_PNAME = ''
Nenue@66 236 print = function() end
Nenue@66 237 end
Nenue@89 238 DEVIAN_PID =id
Nenue@66 239
Nenue@66 240 D.unlisted = currentProfile.unlisted
Nenue@66 241 D.channels = currentProfile.channels
Nenue@66 242 D.tags = currentProfile.tags
Nenue@66 243 D.channelinfo = currentProfile.channels
Nenue@66 244 D.char = currentProfile.char[playerRealm]
Nenue@66 245 D.global = currentProfile.global
Nenue@66 246 D.num_channels = currentProfile.num_channels
Nenue@66 247 D.enabled = currentProfile.enabled
Nenue@66 248 D.sig = {}
Nenue@66 249 D.sigID = {}
Nenue@66 250 D.IDsig = {}
Nenue@72 251 D.dock = _G.DevianDock
Nenue@66 252 D.dock.buttons = D.dock.buttons or {}
Nenue@66 253
Nenue@66 254 return id, name
Nenue@66 255 end
Nenue@66 256
Nenue@66 257 local targetGlobal, targetChar
Nenue@86 258 D.Command = function (cmd)
Nenue@66 259 local list_id, scan_func, reload
Nenue@86 260
Nenue@14 261 local args = {}
Nenue@86 262 if cmd then
Nenue@86 263 local i, j = 0, 0
Nenue@86 264 repeat
Nenue@86 265 i, j = cmd:find("%S+", j+1)
Nenue@86 266 if i and j then
Nenue@86 267 tinsert(args, cmd:sub(i, j))
Nenue@86 268 end
Nenue@86 269
Nenue@86 270 until not(i or j)
Nenue@14 271 end
Nenue@14 272 local mode, tag, dest = unpack(args)
Nenue@0 273
Nenue@86 274
Nenue@14 275 -- no args, toggle ui
Nenue@86 276 if mode == 'rc' then
Nenue@86 277 return D.ResetChannels(self, tag)
Nenue@86 278 elseif mode == 'stack' then
Nenue@14 279 return D:StackFrames()
Nenue@14 280 elseif mode == 'grid' then
Nenue@14 281 return D:DistributeFrames()
Nenue@14 282 elseif mode == 'tag' then -- tagging
Nenue@66 283 return D.Tag(self, tag, dest)
Nenue@73 284 elseif mode == 'new' then
Nenue@73 285 return D.New(self, tag)
Nenue@73 286 elseif mode == 'remove' then
Nenue@73 287 return D.Remove(self, tag)
Nenue@89 288 elseif mode ~= nil then
Nenue@89 289 -- profile selector or save command
Nenue@66 290 if mode == 'save' then
Nenue@66 291 list_id = tonumber(tag)
Nenue@89 292 else
Nenue@89 293 list_id = tonumber(mode)
Nenue@89 294 end
Nenue@89 295
Nenue@89 296 if not list_id then
Nenue@89 297 if db.profilesName[tostring(list_id)] then
Nenue@89 298 list_id = db.profilesName[tostring(list_id)]
Nenue@89 299 else
Nenue@89 300
Nenue@89 301 D:Print(L('Unable to resolve profile ID/name', list_id, dest))
Nenue@89 302 return
Nenue@66 303 end
Nenue@89 304 end
Nenue@89 305
Nenue@89 306
Nenue@89 307 if mode == 'save' then
Nenue@66 308 D.Profile(list_id, dest)
Nenue@66 309 scan_func = D.Save
Nenue@89 310
Nenue@89 311
Nenue@89 312 local name = currentProfile.name
Nenue@89 313 if dest then
Nenue@89 314 dest = dest:gsub("$%s+", ''):gsub("%s+^", '')
Nenue@89 315 if dest then
Nenue@89 316 if name then
Nenue@89 317 db.profilesName[name] = nil
Nenue@89 318 end
Nenue@89 319 db.profiles[list_id].name = dest
Nenue@89 320 db.profilesName[dest] = list_id
Nenue@92 321
Nenue@92 322 name = dest
Nenue@89 323 end
Nenue@89 324 end
Nenue@89 325
Nenue@89 326
Nenue@89 327 D:Print("Profile |cFFFFFF00".. list_id .."|r:|cFF00FFFF".. name .."|r saved.")
Nenue@66 328 else
Nenue@32 329
Nenue@89 330 if db.profiles[list_id] then
Nenue@89 331 D.LoadMessage ("Switched profiles.")
Nenue@89 332 if list_id ~= db.main_profile then
Nenue@89 333 db.last_profile = list_id
Nenue@89 334 end
Nenue@89 335 db.current_profile = list_id
Nenue@89 336 scan_func = D.Load
Nenue@89 337 else
Nenue@89 338 return D:PrintHelp()
Nenue@89 339 end
Nenue@36 340
Nenue@0 341 end
Nenue@32 342 elseif mode == nil then
Nenue@66 343 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
Nenue@77 344 D.LoadMessage ("Switched between main and recent profile ("..db.current_profile..' and '..list_id..')')
Nenue@66 345 db.current_profile = list_id
Nenue@66 346 scan_func = D.Load
Nenue@32 347 else
Nenue@89 348
Nenue@89 349
Nenue@32 350 return D:PrintHelp()
Nenue@0 351 end
Nenue@77 352
Nenue@77 353 if not db.profiles[list_id] then
Nenue@77 354 db.profiles[list_id] = {global = {}, char = {} }
Nenue@77 355 D.LoadMessage ("Starting profile #|cFF00FFFF".. list_id..'|r')
Nenue@77 356 end
Nenue@67 357 if not db.profiles[list_id].char[playerRealm] then
Nenue@67 358 db.profiles[list_id].char[playerRealm] = {}
Nenue@67 359 end
Nenue@67 360
Nenue@66 361 targetGlobal = db.profiles[list_id].global
Nenue@66 362 targetChar = db.profiles[list_id].char[playerRealm]
Nenue@32 363
Nenue@67 364
Nenue@66 365 if scan_func then
Nenue@66 366 for id, name, enableState, globalState in D.Addons() do
Nenue@66 367 scan_func(id, name, enableState, globalState)
Nenue@0 368 end
Nenue@0 369 end
Nenue@0 370
Nenue@66 371 if scan_func == D.Load then
Nenue@72 372 _G.ReloadUI()
Nenue@66 373 end
Nenue@66 374 D.Profile(db.current_profile)
Nenue@66 375 end
Nenue@66 376
Nenue@66 377 D.Addons = function()
Nenue@66 378 local playername = UnitName("player")
Nenue@66 379 return function(n, i)
Nenue@66 380 if i >= n then
Nenue@66 381 return nil
Nenue@66 382 end
Nenue@66 383
Nenue@66 384 i = i + 1
Nenue@66 385 local name = GetAddOnInfo(i)
Nenue@66 386 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
Nenue@66 387 return i, name, enableState, globalState
Nenue@66 388 end, GetNumAddOns(), 0
Nenue@66 389 end
Nenue@66 390
Nenue@66 391 D.Load = function(id, name, charState, globalState)
Nenue@66 392 if targetChar[name] or targetGlobal[name] then
Nenue@66 393 if targetGlobal[name] == 2 then
Nenue@66 394 EnableAddOn(id, true)
Nenue@66 395 elseif targetChar[name] == 2 then
Nenue@66 396 EnableAddOn(id, playerName)
Nenue@66 397 else
Nenue@71 398 if targetChar[name] == 2 and targetGlobal[name] ~= 2 then
Nenue@71 399 DisableAddOn(id)
Nenue@71 400 else
Nenue@71 401 DisableAddOn(id, true)
Nenue@71 402 end
Nenue@66 403 end
Nenue@70 404 --print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name])
Nenue@0 405 else
Nenue@66 406 tinsert(D.unlisted, name)
Nenue@66 407 end
Nenue@66 408 end
Nenue@66 409 D.Save = function(id, name, charState, globalState)
Nenue@70 410 --print('save', id, name, charState, globalState)
Nenue@66 411 targetGlobal[name] = globalState
Nenue@66 412 targetChar[name] = charState
Nenue@66 413 end
Nenue@57 414
Nenue@66 415 D.Tag = function(self, tag, dest)
Nenue@66 416 local sig
Nenue@66 417 if tag ~= nil and dest ~= nil then
Nenue@66 418 --@debug@
Nenue@66 419 --print(tag, dest)
Nenue@66 420 --@end-debug@
Nenue@66 421
Nenue@66 422 -- convert to ID
Nenue@66 423 if tonumber(dest) == nil then
Nenue@66 424 if D.sigID[dest] then
Nenue@66 425 dest = currentProfile.channels[D.sigID[dest]].index
Nenue@66 426 else
Nenue@66 427 sig = dest
Nenue@66 428 end
Nenue@57 429 else
Nenue@66 430 dest = tonumber(dest)
Nenue@32 431 end
Nenue@66 432 --@debug@
Nenue@66 433 --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@
Nenue@66 434
Nenue@66 435 -- make a new channel?
Nenue@66 436 local channel
Nenue@66 437 if not currentProfile.channels[dest] then
Nenue@66 438 dest = D.max_channel + 1
Nenue@66 439 D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
Nenue@66 440 channel = D:SetChannel(sig or tag,dest)
Nenue@66 441 else
Nenue@66 442 channel = D.channels[dest]
Nenue@66 443 end
Nenue@66 444 --@debug@
Nenue@66 445 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
Nenue@66 446
Nenue@66 447 if not currentProfile.tags[tag] then -- no tag table?
Nenue@66 448 currentProfile.tags[tag] = {}
Nenue@66 449 end
Nenue@66 450
Nenue@66 451 if currentProfile.tags[tag][dest] then -- is tag set?
Nenue@66 452 currentProfile.tags[tag][dest] = nil
Nenue@66 453 D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 454 else
Nenue@66 455 currentProfile.tags[tag][dest] = dest
Nenue@66 456 D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 457 end
Nenue@66 458 D:UpdateDock()
Nenue@66 459 else
Nenue@66 460 D:Print(L['Command tag help'])
Nenue@0 461 end
Nenue@0 462 end
Nenue@0 463
Nenue@86 464 D.ResetChannels = function(self, profile)
Nenue@86 465 currentProfile.current_channel = 1
Nenue@86 466 currentProfile.primary_channel = 1
Nenue@86 467 currentProfile.channels = {}
Nenue@86 468 D.DeepCopy(profileTemplate.channels, currentProfile.channels)
Nenue@86 469 currentProfile.tags = {}
Nenue@86 470 D.LoadMessage('Profile reset.')
Nenue@86 471 ReloadUI()
Nenue@86 472 end
Nenue@86 473
Nenue@73 474 D.New = function(self, tag)
Nenue@73 475 if tag and not self.sigID[tag] then
Nenue@73 476 local id = D.max_channel + 1
Nenue@73 477 D.SetChannel(tag, id)
Nenue@73 478 end
Nenue@73 479 end
Nenue@0 480
Nenue@73 481 D.Remove = function(self, dest)
Nenue@73 482 dest = D.sigID[dest] or tonumber(dest)
Nenue@73 483 if D.console[dest] and D.channels[dest] then
Nenue@73 484 for tag, tagDest in pairs(D.tags) do
Nenue@73 485 for i = #tagDest, 0 do
Nenue@73 486 -- work downward so we aren't skipping entries
Nenue@73 487 if tagDest[i] == dest then
Nenue@73 488 tremove(tagDest, i)
Nenue@73 489 end
Nenue@73 490 end
Nenue@73 491 end
Nenue@73 492 D.console[dest]:Hide()
Nenue@73 493 D.channels[dest] = nil
Nenue@73 494 tremove(D.console, dest)
Nenue@73 495 tremove(D.dock.buttons, dest)
Nenue@73 496 D:UpdateDock()
Nenue@73 497 D:Print('Removed channel #'..dest)
Nenue@73 498 end
Nenue@73 499 end
Nenue@13 500
Nenue@77 501 --- Queue up a message to appear after UI reload
Nenue@77 502 function D.LoadMessage(msg)
Nenue@77 503
Nenue@77 504 tinsert(_G.DevianLoadMessage, msg)
Nenue@77 505 end
Nenue@77 506
Nenue@18 507 --- Creates a Devian-style output.
Nenue@18 508 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
Nenue@18 509 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
Nenue@18 510 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
Nenue@18 511 -- @param ... Output contents.
Nenue@72 512
Nenue@66 513 function D.Message(prefix, ...)
Nenue@67 514 if not currentProfile.workspace then
Nenue@23 515 return D.oldprint(prefix, ...)
Nenue@23 516 end
Nenue@57 517 prefix = tostring(prefix)
Nenue@57 518 if prefix == nil then
Nenue@55 519 prefix = 'nil*'
Nenue@1 520 end
Nenue@9 521
Nenue@18 522 local sendq = {}
Nenue@30 523 local tag, id, tagged
Nenue@13 524 local byName = true
Nenue@18 525 if D.tags[prefix] then
Nenue@18 526 for _, id in pairs(D.tags[prefix]) do
Nenue@18 527 if D.console[id] then
Nenue@18 528 sendq[id] = D.console[id]
Nenue@30 529 tagged = true
Nenue@18 530 end
Nenue@18 531 end
Nenue@18 532 end
Nenue@18 533
Nenue@13 534 if D.sig[prefix] then
Nenue@18 535 sendq[D.sig[prefix].index] = D.sig[prefix]
Nenue@13 536 elseif D.console[prefix] then
Nenue@18 537 sendq[D.console[prefix]] = D.console[prefix]
Nenue@30 538 elseif not tagged then
Nenue@18 539 sendq[D.primary_channel] = D.console[D.primary_channel]
Nenue@13 540 end
Nenue@18 541
Nenue@9 542 -- color me timbers
Nenue@9 543 local pcolor
Nenue@18 544 if (not db.tagcolor[prefix]) and byName then
Nenue@86 545 -- numbers, use white
Nenue@86 546 if prefix:match('^%d+%.%d+') then
Nenue@73 547 pcolor = 'FFFFFF'
Nenue@73 548 else
Nenue@73 549 local c = {
Nenue@73 550 rand(64,255), rand(64,255), rand(64,255)
Nenue@73 551 }
Nenue@73 552 if c[1] > 223 and c[2] > 223 and c[3] > 223 then
Nenue@73 553 c[rand(1,3)] = rand(64,223)
Nenue@73 554 end
Nenue@73 555 db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c))
Nenue@73 556 pcolor = db.tagcolor[prefix]
Nenue@0 557 end
Nenue@73 558 else
Nenue@73 559 pcolor = db.tagcolor[prefix]
Nenue@0 560 end
Nenue@0 561
Nenue@55 562 local buffer = {}
Nenue@0 563 for i = 1, select('#',...) do
Nenue@0 564 local var = select(i, ...)
Nenue@0 565
Nenue@0 566 if type(var) == 'table' then
Nenue@20 567 if type(var.GetName) == 'function' then
Nenue@72 568 var = '[table:'..tostring(var:GetName())..']'
Nenue@20 569 else
Nenue@32 570 var = '<'..tostring(var)..'>'
Nenue@20 571 end
Nenue@20 572
Nenue@0 573 elseif type(var) == 'boolean' then
Nenue@75 574 var = var and 'true' or 'false'
Nenue@0 575 elseif type(var) == 'function' then
Nenue@72 576 var = '['..tostring(var)..']'
Nenue@0 577 elseif type(var) == 'nil' then
Nenue@75 578 var = 'nil'
Nenue@60 579 else
Nenue@60 580 var = tostring(var)
Nenue@0 581 end
Nenue@0 582
Nenue@47 583 insert(buffer, var)
Nenue@0 584 end
Nenue@47 585 local message = concat(buffer, ' ')
Nenue@18 586 for id, channel in pairs(sendq) do
Nenue@55 587 if channel.width < 250 then
Nenue@72 588 prefix = sub(prefix, 0,2)
Nenue@55 589 end
Nenue@73 590 --currentProfile.last_channel = channel.index
Nenue@58 591 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime())
Nenue@58 592 if not D.dock.buttons[id].newMessage then
Nenue@58 593 D.dock.buttons[id].newMessage = true
Nenue@58 594 D.UpdateBeacon(D.dock.buttons[id])
Nenue@58 595 end
Nenue@18 596 end
Nenue@47 597 wipe(buffer)
Nenue@0 598 end
Nenue@0 599
Nenue@14 600
Nenue@32 601
Nenue@14 602
Nenue@32 603 function D:PrintHelp()
Nenue@32 604 D:Print("|cFFFFFF00/dvn|r",
Nenue@32 605 "\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 606 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 607
Nenue@32 608 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.")
Nenue@32 609 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
Nenue@32 610 end
Nenue@32 611
Nenue@66 612 local blocked = {profiles = true, debugmode = true}
Nenue@66 613 D.SetDefaults = function()
Nenue@72 614 local DevianDB = _G.DevianDB
Nenue@66 615 for k,v in pairs(DevianDB) do
Nenue@66 616 if not blocked[k] then
Nenue@66 617 DevianDB[k] = nil
Nenue@60 618 end
Nenue@60 619 end
Nenue@66 620 for k,v in pairs(defaults) do
Nenue@66 621 if not blocked[k] then
Nenue@66 622 DevianDB[k] = v
Nenue@60 623 end
Nenue@60 624 end
Nenue@73 625
Nenue@77 626 D.LoadMessage "Non-user SavedVars have been reset."
Nenue@72 627 _G.ReloadUI()
Nenue@60 628 end
Nenue@66 629 D.SetDefaultsAll = function ()
Nenue@72 630 _G.DevianDB = nil
Nenue@77 631 D.LoadMessage "All SavedVars wiped."
Nenue@72 632 _G.ReloadUI()
Nenue@66 633 end
Nenue@73 634
Nenue@73 635 D.UnsetColors = function()
Nenue@73 636 db.tagcolor = {}
Nenue@73 637 D:Print('Tag color cache cleared.')
Nenue@73 638 end
Nenue@45 639
Nenue@33 640
Nenue@89 641 function D.ConsoleCommand (cmd)
Nenue@89 642 D:Console_Toggle(cmd)
Nenue@89 643 end
Nenue@87 644
Nenue@66 645
Nenue@66 646 function D:OnInitialize()
Nenue@81 647 L = D.L
Nenue@13 648
Nenue@33 649 -- pull defaults
Nenue@9 650 if not _G.DevianDB then
Nenue@13 651 _G.DevianDB = defaults
Nenue@9 652 end
Nenue@9 653 db = _G.DevianDB
Nenue@47 654 self.db = db
Nenue@0 655
Nenue@66 656 ---
Nenue@77 657 if #_G.DevianLoadMessage >= 1 then
Nenue@77 658 for i, msg in ipairs(_G.DevianLoadMessage) do
Nenue@77 659 D:Print(msg)
Nenue@77 660 end
Nenue@77 661
Nenue@77 662 table.wipe(_G.DevianLoadMessage)
Nenue@0 663 end
Nenue@0 664
Nenue@66 665
Nenue@89 666 -- commands
Nenue@89 667 local cmdlist = {
Nenue@89 668 ['dvn'] = "Command",
Nenue@89 669 ['devian'] = "Command",
Nenue@89 670 ['dvc'] = "ConsoleCommand",
Nenue@89 671 ['dvncolors'] = "UnsetColors",
Nenue@89 672 ['cleandvn'] = "SetDefaultsAll",
Nenue@89 673 ['resetdvn'] = "SetDefaults",
Nenue@89 674 }
Nenue@89 675 for cmd, func in pairs(cmdlist) do
Nenue@89 676 local CMD = cmd:upper()
Nenue@89 677 _G['SLASH_' .. CMD .. '1'] = "/"..cmd
Nenue@89 678
Nenue@89 679 if type(func == 'string') then
Nenue@89 680 print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 681 SlashCmdList[CMD] = D[func]
Nenue@89 682 else
Nenue@89 683 print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 684 SlashCmdList[CMD] = func
Nenue@89 685 end
Nenue@89 686 end
Nenue@89 687
Nenue@66 688 --- initialize the current profile
Nenue@66 689 local id, name = D.Profile(db.current_profile or 1)
Nenue@66 690 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r')
Nenue@66 691 if currentProfile.workspace then
Nenue@66 692 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.')
Nenue@86 693 if D.channels[currentProfile.default_channel] then
Nenue@86 694 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
Nenue@86 695 end
Nenue@0 696 end
Nenue@13 697
Nenue@86 698
Nenue@66 699 for i, cinfo in pairs(D.channels) do
Nenue@14 700 i = tonumber(i)
Nenue@66 701 if not D.primary_channel then
Nenue@66 702 D.primary_channel = i
Nenue@14 703 end
Nenue@66 704 D:SetChannel(cinfo, i)
Nenue@66 705 D.num_channels = D.num_channels + 1
Nenue@32 706 end
Nenue@86 707 D.primary_channel = D.primary_channel or 1
Nenue@32 708
Nenue@66 709 D.max_channel = max(D.max_channel, currentProfile.max_channel)
Nenue@66 710 if currentProfile.max_channel < D.max_channel then
Nenue@66 711 for i = currentProfile.max_channel, D.max_channel do
Nenue@66 712 D.console[i]:Hide()
Nenue@47 713 end
Nenue@36 714 end
Nenue@36 715
Nenue@66 716 if currentProfile.workspace then
Nenue@66 717 if D.console[currentProfile.current_channel] then
Nenue@69 718 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
Nenue@66 719 D.console[currentProfile.current_channel]:ToFront()
Nenue@66 720 -- bring the current channel to the front
Nenue@47 721 end
Nenue@72 722 _G.DevianDock:Show()
Nenue@66 723 D:UpdateDock()
Nenue@36 724 end
Nenue@66 725 end
Nenue@89 726