annotate Devian.lua @ 88:7ff0579e5a6e

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