Mercurial > wow > devian
comparison Devian.lua @ 47:eb7544afd77a
dock frame implementation
fixes to /dvc command
| author | Nenue |
|---|---|
| date | Mon, 04 Jan 2016 05:42:44 -0500 |
| parents | dcc57a7cabc9 |
| children | c3166f700438 |
comparison
equal
deleted
inserted
replaced
| 46:dcc57a7cabc9 | 47:eb7544afd77a |
|---|---|
| 7 end | 7 end |
| 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") | 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") |
| 9 local D = _G.Devian | 9 local D = _G.Devian |
| 10 D:SetDefaultModuleState(false) | 10 D:SetDefaultModuleState(false) |
| 11 | 11 |
| 12 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type | |
| 13 local max, rand, format = math.max, math.random, string.format | |
| 14 local insert, wipe, concat = table.insert, table.wipe, table.concat | |
| 15 local select, unpack = select, unpack | |
| 16 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn | |
| 17 local UnitName, DisableAddOn = UnitName, DisableAddOn | |
| 12 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' | 18 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' |
| 13 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' | 19 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' |
| 14 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 | 20 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 |
| 15 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 21 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
| 16 local print = _G.print | 22 local print = _G.print |
| 54 frontalpha = 1, | 60 frontalpha = 1, |
| 55 frontborder = {.07,.47,1,1}, | 61 frontborder = {.07,.47,1,1}, |
| 56 frontheader = {1,1,1,1}, | 62 frontheader = {1,1,1,1}, |
| 57 tagcolor = {}, -- tag color repository | 63 tagcolor = {}, -- tag color repository |
| 58 workspace = 2, -- current profile | 64 workspace = 2, -- current profile |
| 59 last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued | 65 last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued |
| 66 | |
| 67 dock_onshow_fade_time = 2.5, | |
| 68 dock_onshow_fade_from = 1, | |
| 69 dock_onshow_fade_to = 0.2, | |
| 70 | |
| 71 dock_alpha_on = 1, | |
| 72 dock_alpha_off = 0.2, | |
| 73 dock_fade_in = 0.15, | |
| 74 dock_fade_out = 0.45, | |
| 75 dock_button_alpha_on = 1, | |
| 76 dock_button_alpha_off = 0.2, | |
| 77 dock_button_fade_in = 0.15, | |
| 78 dock_button_fade_out = 0.45 | |
| 79 | |
| 60 } | 80 } |
| 61 | 81 |
| 62 local function ScanAddOnList(cmd, ...) | 82 local function ScanAddOnList(cmd, ...) |
| 63 local list_state | 83 local list_state |
| 64 | 84 |
| 65 local args = {} | 85 local args = {} |
| 66 local arg, n = D:GetArgs(cmd, 1) | 86 local arg, n = D:GetArgs(cmd, 1) |
| 67 while arg do | 87 while arg do |
| 68 table.insert(args, arg) | 88 insert(args, arg) |
| 69 arg, n = D:GetArgs(cmd,1,n) | 89 arg, n = D:GetArgs(cmd,1,n) |
| 70 end | 90 end |
| 71 local mode, tag, dest = unpack(args) | 91 local mode, tag, dest = unpack(args) |
| 72 | 92 |
| 73 | 93 |
| 102 return | 122 return |
| 103 end | 123 end |
| 104 --@debug@ | 124 --@debug@ |
| 105 --print(i, '->', ch.index, '-', ch.signature)--@end-debug@ | 125 --print(i, '->', ch.index, '-', ch.signature)--@end-debug@ |
| 106 if i > 2 then | 126 if i > 2 then |
| 107 table.insert(worklist, ch.index) | 127 insert(worklist, ch.index) |
| 108 else | 128 else |
| 109 target = ch | 129 target = ch |
| 110 | 130 |
| 111 --@debug@ | 131 --@debug@ |
| 112 --print('arg1', args[2], target)--@end-debug@ | 132 --print('arg1', args[2], target)--@end-debug@ |
| 113 end | 133 end |
| 114 end | 134 end |
| 115 D:Print("Docking |cFF88FFFF"..table.concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") | 135 D:Print("Docking |cFF88FFFF"..concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") |
| 116 return D:DockFrame(target.index, unpack(worklist)) | 136 return D:DockFrame(target.index, unpack(worklist)) |
| 117 | 137 |
| 118 | 138 |
| 119 elseif mode == 'stack' then | 139 elseif mode == 'stack' then |
| 120 if db.workspace == 1 then | 140 if db.workspace == 1 then |
| 172 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) | 192 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) |
| 173 else | 193 else |
| 174 db.tags[tag][dest] = dest | 194 db.tags[tag][dest] = dest |
| 175 D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) | 195 D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) |
| 176 end | 196 end |
| 197 D:UpdateDock() | |
| 177 else | 198 else |
| 178 D:Print('Usage: /dvn tag <prefix> <console name or number>') | 199 D:Print('Usage: /dvn tag <prefix> <console name or number>') |
| 179 end | 200 end |
| 180 return | 201 return |
| 181 elseif tonumber(mode) ~= nil or mode == 'save' then | 202 elseif tonumber(mode) ~= nil or mode == 'save' then |
| 240 end | 261 end |
| 241 elseif mode ~= 'save' then | 262 elseif mode ~= 'save' then |
| 242 if type(db.unlisted) ~= 'table' then | 263 if type(db.unlisted) ~= 'table' then |
| 243 db.unlisted = {} | 264 db.unlisted = {} |
| 244 end | 265 end |
| 245 table.insert(db.unlisted, name) | 266 insert(db.unlisted, name) |
| 246 end | 267 end |
| 247 | 268 |
| 248 end | 269 end |
| 249 end | 270 end |
| 250 | 271 |
| 300 | 321 |
| 301 -- color me timbers | 322 -- color me timbers |
| 302 local pcolor | 323 local pcolor |
| 303 if (not db.tagcolor[prefix]) and byName then | 324 if (not db.tagcolor[prefix]) and byName then |
| 304 local c = { | 325 local c = { |
| 305 math.random(64,255), math.random(64,255), math.random(64,255) | 326 rand(64,255), rand(64,255), rand(64,255) |
| 306 } | 327 } |
| 307 if c[1] > 223 and c[2] > 223 and c[3] > 223 then | 328 if c[1] > 223 and c[2] > 223 and c[3] > 223 then |
| 308 c[math.random(1,3)] = math.random(64,223) | 329 c[rand(1,3)] = rand(64,223) |
| 309 end | 330 end |
| 310 | 331 |
| 311 db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c)) | 332 db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c)) |
| 312 end | 333 end |
| 313 pcolor = db.tagcolor[prefix] | 334 pcolor = db.tagcolor[prefix] |
| 314 | 335 |
| 315 local buffer = {'|cFF'.. pcolor..prefix ..'|r'} | 336 local buffer = {'|cFF'.. pcolor..prefix ..'|r'} |
| 316 for i = 1, select('#',...) do | 337 for i = 1, select('#',...) do |
| 329 var = '<funcref>' | 350 var = '<funcref>' |
| 330 elseif type(var) == 'nil' then | 351 elseif type(var) == 'nil' then |
| 331 var = 'nil' | 352 var = 'nil' |
| 332 end | 353 end |
| 333 | 354 |
| 334 table.insert(buffer, var) | 355 insert(buffer, var) |
| 335 end | 356 end |
| 336 local message = table.concat(buffer, ' ') | 357 local message = concat(buffer, ' ') |
| 337 for id, channel in pairs(sendq) do | 358 for id, channel in pairs(sendq) do |
| 338 channel.out:AddMessage(message) | 359 channel.out:AddMessage(message) |
| 339 end | 360 UIFrameFadeIn(D.dock.buttons[id], db.dock_onshow_fade_time, db.dock_onshow_fade_from, db.dock_onshow_fade_to) |
| 340 table.wipe(buffer) | 361 UIFrameFadeIn(D.dock.buttons[id].caption, db.dock_onshow_fade_time, db.dock_onshow_fade_from, db.dock_onshow_fade_to) |
| 362 end | |
| 363 wipe(buffer) | |
| 341 end | 364 end |
| 342 | 365 |
| 343 | 366 |
| 344 | 367 |
| 345 | 368 |
| 346 function D:PrintHelp() | 369 function D:PrintHelp() |
| 347 D:Print("|cFFFFFF00/dvn|r", | 370 D:Print("|cFFFFFF00/dvn|r", |
| 348 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.") | 371 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.") |
| 372 D:Print("|cFFFFFF00/dvc|r [<key>, ...]", "- Hides and show consoles. A list of channel keys can be passed to specify which ones get toggled.") | |
| 349 | 373 |
| 350 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.") | 374 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.") |
| 351 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") | 375 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") |
| 352 end | 376 end |
| 353 | 377 |
| 355 | 379 |
| 356 function D:OnEnable() | 380 function D:OnEnable() |
| 357 print(MAJOR, MINOR) | 381 print(MAJOR, MINOR) |
| 358 | 382 |
| 359 if db.unlisted and #db.unlisted > 0 then | 383 if db.unlisted and #db.unlisted > 0 then |
| 360 D:Print('New AddOns have been found since the last profile update: '.. table.concat(db.unlisted, ', ')) | 384 D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', ')) |
| 361 table.wipe(db.unlisted) | 385 wipe(db.unlisted) |
| 362 end | 386 end |
| 363 | 387 |
| 364 if db.workspace == 1 then | 388 if db.workspace == 1 then |
| 365 D:Print('Gameplay mode active (list #'..db.workspace..'). Print handling turned |cFFFFFF00OFF|r.') | 389 D:Print('Gameplay mode active (list #'..db.workspace..'). Print handling turned |cFFFFFF00OFF|r.') |
| 366 else | 390 else |
| 367 D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.') | 391 D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.') |
| 368 end | 392 end |
| 369 | 393 |
| 394 --@debug@ | |
| 370 self:RegisterChatCommand("dvg", function(input) | 395 self:RegisterChatCommand("dvg", function(input) |
| 371 if not self.config then | 396 if not self.config then |
| 372 self.config = DevCon | 397 self.config = DevCon |
| 373 self:EnableModule("Config") | 398 self:EnableModule("Config") |
| 374 end | 399 end |
| 375 self.modules.Config:ChatCommand(input) | 400 self.modules.Config:ChatCommand(input) |
| 376 end) | 401 end) |
| 402 --@end-debug@ | |
| 377 | 403 |
| 378 end | 404 end |
| 379 | 405 |
| 380 function D:OnInitialize() | 406 function D:OnInitialize() |
| 381 -- commands | 407 -- commands |
| 413 -- pull defaults | 439 -- pull defaults |
| 414 if not _G.DevianDB then | 440 if not _G.DevianDB then |
| 415 _G.DevianDB = defaults | 441 _G.DevianDB = defaults |
| 416 end | 442 end |
| 417 db = _G.DevianDB | 443 db = _G.DevianDB |
| 444 self.db = db | |
| 418 self.tags = db.tags | 445 self.tags = db.tags |
| 419 self.channelinfo = db.channels | 446 self.channelinfo = db.channels |
| 420 | 447 |
| 421 if not db[PLAYER_REALM] then | 448 if not db[PLAYER_REALM] then |
| 422 db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}} | 449 db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}} |
| 442 self.num_channels = 0 | 469 self.num_channels = 0 |
| 443 self.console = {} | 470 self.console = {} |
| 444 self.sig = {} | 471 self.sig = {} |
| 445 self.sigID = {} | 472 self.sigID = {} |
| 446 self.IDsig = {} | 473 self.IDsig = {} |
| 474 self.dock = DevianDock | |
| 475 self.dock.buttons = {} | |
| 447 for i, cinfo in pairs(db.channels) do | 476 for i, cinfo in pairs(db.channels) do |
| 448 i = tonumber(i) | 477 i = tonumber(i) |
| 449 if not self.primary_channel then | 478 if not self.primary_channel then |
| 450 self.primary_channel = i | 479 self.primary_channel = i |
| 451 end | 480 end |
| 452 self:SetChannel(cinfo, i) | 481 self:SetChannel(cinfo, i) |
| 453 self.max_channel = math.max(i, self.max_channel) | 482 self.max_channel = max(i, self.max_channel) |
| 454 self.num_channels = self.num_channels + 1 | 483 self.num_channels = self.num_channels + 1 |
| 455 end | |
| 456 | |
| 457 for i, channel in pairs(db.channels) do | |
| 458 if type(channel.docked) == 'table' then | |
| 459 --oldprint('docking',i, unpack(channel.docked)) | |
| 460 self.DockFrame(i, unpack(channel.docked)) | |
| 461 end | |
| 462 end | 484 end |
| 463 | 485 |
| 464 if self.console[db.current_channel] then | 486 if self.console[db.current_channel] then |
| 465 self.console[db.current_channel]:ToFront() | 487 self.console[db.current_channel]:ToFront() |
| 466 -- bring the current channel to the front | 488 -- bring the current channel to the front |
| 467 end | 489 end |
| 468 self.dock = DevianDock | 490 DevianDock:Show() |
| 469 | 491 self:UpdateDock() |
| 470 | |
| 471 setprinthandler(Message) | 492 setprinthandler(Message) |
| 472 print = function(...) | 493 print = function(...) |
| 473 _G.print('Dvn', ...) | 494 _G.print('Dvn', ...) |
| 474 end | 495 end |
| 475 end | 496 end |
| 476 | 497 |
| 477 --- Console frame toggler | 498 --- Console frame toggler |
| 478 -- @paramsig [...] | 499 -- @paramsig [...] |
| 479 -- @param ... one or more space-seperated channel keys | 500 -- @param ... one or more space-seperated channel keys |
| 480 function D:Console_Toggle(input) | 501 function D:Console_Toggle(input, force) |
| 481 --oldprint(input) | 502 --oldprint(input) |
| 503 local setAll | |
| 482 if db.workspace == 1 then | 504 if db.workspace == 1 then |
| 483 return self:Print(MSG_NEED_DEV_MODE) | 505 return self:Print(MSG_NEED_DEV_MODE) |
| 484 end | 506 end |
| 485 local search = {} | 507 local search = {} |
| 508 local key | |
| 486 local n = 0 | 509 local n = 0 |
| 487 if self:GetArgs(input,1) then | 510 while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but |
| 488 repeat | 511 key, n = self:GetArgs(input,1,n) |
| 489 local key, n = self:GetArgs(input,1,n) | 512 |
| 490 if self.sig[key] then | 513 if self.sig[key] then |
| 491 table.insert(search, self.sigID[key]) | 514 --print(key, self.sigID[key]) |
| 492 elseif self.console[key] then | 515 insert(search, self.sigID[key]) |
| 493 table.insert(search, tonumber(key)) | 516 elseif self.console[tonumber(key)] then |
| 494 end | 517 --print(key, tonumber(key)) |
| 495 until n == 1e9 | 518 insert(search, tonumber(key)) |
| 496 else | 519 end |
| 520 | |
| 521 --oldprint(#search, key, n) | |
| 522 end | |
| 523 if #search < 1 then | |
| 497 search = self.sigID | 524 search = self.sigID |
| 498 end | 525 setAll = true |
| 499 | 526 end |
| 500 db.enabled = (not db.enabled) and true or nil | 527 if setAll then |
| 528 --oldprint('setall', setAll) | |
| 529 db.enabled = (not db.enabled) and true or nil | |
| 530 if force == 0 then | |
| 531 db.enabled = nil | |
| 532 end | |
| 533 end | |
| 534 | |
| 501 for i, id in pairs(search) do | 535 for i, id in pairs(search) do |
| 502 --oldprint(i, id) | 536 --oldprint(i, id) |
| 503 local c = self.console[id] | 537 local c = self.console[id] |
| 504 if db.enabled then | 538 if setAll then |
| 505 c.enabled = true | 539 c.enabled = db.enabled and db.enabled or nil |
| 540 else | |
| 541 | |
| 542 db.enabled = true | |
| 543 c.enabled = (not c.enabled) and true or nil | |
| 544 if force == 0 then | |
| 545 c.enabled = nil | |
| 546 end | |
| 547 --oldprint(id, ' ', force, c.enabled, db.enabled) | |
| 548 end | |
| 549 | |
| 550 if c.enabled or (setAll and db.enabled) then | |
| 506 c:Show() | 551 c:Show() |
| 507 if db.current_channel == c.index then | 552 if db.current_channel == c.index then |
| 508 c:ToFront() | 553 c:ToFront() |
| 509 end | 554 end |
| 510 c:Save() | 555 elseif not (c.enabled and db.enabled) then |
| 556 c:Hide() | |
| 557 end | |
| 558 c:Save() | |
| 559 end | |
| 560 | |
| 561 if setAll then | |
| 562 if db.enabled then | |
| 563 self:Print('toggled all consoles ON') | |
| 511 else | 564 else |
| 512 c:Hide() | 565 self:Print('toggled all consoles OFF') |
| 513 end | 566 end |
| 514 end | |
| 515 | |
| 516 if db.enabled then | |
| 517 self:Print('toggled on: '..table.concat(search, ', ')) | |
| 518 else | 567 else |
| 519 self:Print('toggled off: '..table.concat(search, ', ')) | 568 local result = {} |
| 520 end | 569 for i, id in pairs(search) do |
| 521 end | 570 result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF') |
| 571 end | |
| 572 self:Print('toggled: '..concat(result, ', ')) | |
| 573 end | |
| 574 end |
