Mercurial > wow > devian
comparison Devian.lua @ 35:3304455a3f45
code organizing; UI stuff is in the UI script, Devian prime just deals with config and print
corner menu elements placed and hooked, still needs follow-up code
| author | Nenue |
|---|---|
| date | Sun, 27 Dec 2015 03:51:17 -0500 |
| parents | 7441f3bce940 |
| children | bec37163b7fe |
comparison
equal
deleted
inserted
replaced
| 34:7441f3bce940 | 35:3304455a3f45 |
|---|---|
| 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 MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' | 9 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' |
| 10 local D = _G.Devian | 10 local D = _G.Devian |
| 11 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 | 11 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 |
| 12 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 12 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
| 13 local DEVIAN_FRAME = 'DevianConsole' | |
| 14 local DEVIAN_DOCK_FRAME = 'DevianDockFrame' | |
| 15 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' | |
| 16 local print = _G.print | 13 local print = _G.print |
| 17 local db | 14 local db |
| 18 local defaults = { | 15 local defaults = { |
| 19 ['global'] = {{}, {}}, | 16 ['global'] = {{}, {}}, |
| 20 ['tags'] = {}, | 17 ['tags'] = {}, |
| 43 tagcolor = {}, -- tag color repository | 40 tagcolor = {}, -- tag color repository |
| 44 workspace = 1, -- current profile | 41 workspace = 1, -- current profile |
| 45 last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued | 42 last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued |
| 46 } | 43 } |
| 47 | 44 |
| 48 | |
| 49 local function ScanAddOnList(cmd, ...) | 45 local function ScanAddOnList(cmd, ...) |
| 50 local list_state | 46 local list_state |
| 51 | 47 |
| 52 local args = {} | 48 local args = {} |
| 53 local arg, n = D:GetArgs(cmd, 1) | 49 local arg, n = D:GetArgs(cmd, 1) |
| 86 -- last resort | 82 -- last resort |
| 87 else | 83 else |
| 88 D:Print('No entry for argument #'..i..': '..tostring(args[i])) | 84 D:Print('No entry for argument #'..i..': '..tostring(args[i])) |
| 89 return | 85 return |
| 90 end | 86 end |
| 91 oldprint(i, '->', ch.index, '-', ch.signature) | 87 --@debug@ |
| 88 --print(i, '->', ch.index, '-', ch.signature)--@end-debug@ | |
| 92 if i > 2 then | 89 if i > 2 then |
| 93 table.insert(worklist, ch.index) | 90 table.insert(worklist, ch.index) |
| 94 else | 91 else |
| 95 target = ch | 92 target = ch |
| 96 | 93 |
| 97 oldprint('arg1', args[2], target) | 94 --@debug@ |
| 95 --print('arg1', args[2], target)--@end-debug@ | |
| 98 end | 96 end |
| 99 end | 97 end |
| 100 D:Print("Docking |cFF88FFFF"..table.concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") | 98 D:Print("Docking |cFF88FFFF"..table.concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.") |
| 101 return D:DockFrame(target.index, unpack(worklist)) | 99 return D:DockFrame(target.index, unpack(worklist)) |
| 102 | 100 |
| 219 end | 217 end |
| 220 end | 218 end |
| 221 end | 219 end |
| 222 | 220 |
| 223 | 221 |
| 224 local function Console_MinMax(self) | |
| 225 if self.minimized then | |
| 226 self:Maximize() | |
| 227 else | |
| 228 self:Minimize() | |
| 229 end | |
| 230 end | |
| 231 | |
| 232 local function Console_Minimize(self) | |
| 233 self:SetHeight(20) | |
| 234 self:SetMaxResize(GetScreenWidth(),20) | |
| 235 self.minimized = true | |
| 236 self.out:Hide() | |
| 237 self:Save() | |
| 238 end | |
| 239 | |
| 240 local function Console_Maximize(self) | |
| 241 local db = db.channels[self.index] | |
| 242 self:SetHeight(db.height) | |
| 243 self:SetMaxResize(GetScreenWidth(),GetScreenHeight()) | |
| 244 self.minimized = nil | |
| 245 self.out:Show() | |
| 246 self:Save() | |
| 247 end | |
| 248 | |
| 249 | |
| 250 local function Console_Save(self) | |
| 251 local db = db.channels[self.index] | |
| 252 if self.x then | |
| 253 db.x = self.x | |
| 254 else | |
| 255 db.x = self:GetLeft() | |
| 256 end | |
| 257 | |
| 258 if self.y then | |
| 259 db.y = self.y | |
| 260 else | |
| 261 db.y = (self:GetTop() - GetScreenHeight()) | |
| 262 end | |
| 263 | |
| 264 if self.width then | |
| 265 db.width = self.width | |
| 266 else | |
| 267 db.width = self:GetWidth() | |
| 268 end | |
| 269 | |
| 270 if not self.minimized then | |
| 271 if self.height then | |
| 272 db.height = self.height | |
| 273 else | |
| 274 db.height = self:GetHeight() | |
| 275 end | |
| 276 self:SetHeight(db.height) | |
| 277 end | |
| 278 | |
| 279 db.dockedTo = self.dockedTo | |
| 280 db.docked = self.docked | |
| 281 | |
| 282 db.minimized = self.minimized and true or nil | |
| 283 db.enabled = self:IsVisible() and true or nil | |
| 284 db.active = self.active and true or nil | |
| 285 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width) | |
| 286 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) | |
| 287 self:SetWidth(db.width) | |
| 288 end | |
| 289 | |
| 290 -- Console frame toggler | |
| 291 -- @paramsig [...] | |
| 292 -- @param ... one or more space-seperated channel keys | |
| 293 local function Console_Toggle(input) | |
| 294 if db.workspace == 1 then | |
| 295 return D:Print(MSG_NEED_DEV_MODE) | |
| 296 end | |
| 297 local search = {} | |
| 298 local n = 0 | |
| 299 if D:GetArgs(input,1) then | |
| 300 repeat | |
| 301 key, n = D:GetArgs(input,1,n) | |
| 302 if D.sig[key] then | |
| 303 table.insert(search, D.sig[key]) | |
| 304 elseif D.console[key] then | |
| 305 table.insert(search, D.console[key]) | |
| 306 end | |
| 307 until n == 1e9 | |
| 308 else | |
| 309 search = D.console | |
| 310 end | |
| 311 | |
| 312 db.enabled = (not db.enabled) and true or nil | |
| 313 for i, c in ipairs(search) do | |
| 314 --print(i,c.index) | |
| 315 if db.enabled then | |
| 316 c.enabled = true | |
| 317 c:Show() | |
| 318 if db.current_channel == c.index then | |
| 319 c:ToFront() | |
| 320 end | |
| 321 c:Save() | |
| 322 else | |
| 323 c:Hide() | |
| 324 end | |
| 325 end | |
| 326 | |
| 327 if db.enabled then | |
| 328 D:Print('toggled on?') | |
| 329 else | |
| 330 D:Print('toggled off?') | |
| 331 end | |
| 332 end | |
| 333 | |
| 334 --- Brings the console to the front. | |
| 335 -- Frame method used to bring a console frame to the front of the display stack. | |
| 336 local function Console_ToFront(c) | |
| 337 --print(D.raise_ct, 'Raising', c.signature) | |
| 338 --print(unpack(db.frontdrop)) | |
| 339 --print(unpack(db.frontgrad)) | |
| 340 --print(db.frontblend) | |
| 341 -- D.raise_ct = D.raise_ct + 1 | |
| 342 c:Raise() | |
| 343 c:SetAlpha(db.frontalpha) | |
| 344 c.out.backdrop:SetTexture(unpack(db.frontdrop)) | |
| 345 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) | |
| 346 c.out.backdrop:SetBlendMode(db.frontblend) | |
| 347 db.current_channel = c.index | |
| 348 | |
| 349 for _, part in pairs(c.border) do | |
| 350 part:SetTexture(unpack(db.frontborder)) | |
| 351 end | |
| 352 | |
| 353 for id, bc in pairs(D.console) do | |
| 354 if id ~= c.index then | |
| 355 --print(D.raise_ct, 'Lowering', bc.signature) | |
| 356 --print(unpack(db.backdrop)) | |
| 357 --print(unpack(db.backgrad)) | |
| 358 --print(db.backblend) | |
| 359 bc:SetAlpha(db.backalpha) | |
| 360 bc.out.backdrop:SetTexture(unpack(db.backdrop)) | |
| 361 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) | |
| 362 bc.out.backdrop:SetBlendMode(db.backblend) | |
| 363 | |
| 364 for _, part in pairs(bc.border) do | |
| 365 part:SetTexture(unpack(db.backborder)) | |
| 366 end | |
| 367 end | |
| 368 | |
| 369 end | |
| 370 | |
| 371 end | |
| 372 | |
| 373 local function Console_MouseDown(self, button, up) | |
| 374 if button == 'LeftButton' then | |
| 375 if up then | |
| 376 self:StopMovingOrSizing() | |
| 377 self:ToFront() | |
| 378 self.x = nil | |
| 379 self.y = nil | |
| 380 self.width = nil | |
| 381 self.height = nil | |
| 382 self:Save() | |
| 383 elseif self.out.grip:IsMouseOver() then | |
| 384 self:StartSizing() | |
| 385 else | |
| 386 self:StartMoving() | |
| 387 end | |
| 388 else | |
| 389 if up then | |
| 390 self:MinMax() | |
| 391 end | |
| 392 end | |
| 393 end | |
| 394 local function Console_MouseUp(self, button) | |
| 395 return Console_MouseDown(self, button, true) | |
| 396 end | |
| 397 | 222 |
| 398 --- Creates a Devian-style output. | 223 --- Creates a Devian-style output. |
| 399 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() | 224 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() |
| 400 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). | 225 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). |
| 401 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. | 226 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. |
| 470 end | 295 end |
| 471 table.wipe(buffer) | 296 table.wipe(buffer) |
| 472 end | 297 end |
| 473 | 298 |
| 474 | 299 |
| 475 --- Constructs the frame object for a console channel | 300 |
| 476 -- Initializes the console channel at a specified index. | |
| 477 -- Configuration data can be overridden by passing a desired settings table. | |
| 478 -- @param i Numeric index of the channel as it manifests in db.channels | |
| 479 -- @param vars Optional settings table to be used. | |
| 480 local function CreateConsole(i, vars) | |
| 481 if tonumber(i) == nil or math.floor(i) ~= i then | |
| 482 error('Non-integer index value.') | |
| 483 end | |
| 484 if not vars then | |
| 485 vars = db.channels[i] and db.channels[i] or db.channels[db.primary_channel] | |
| 486 end | |
| 487 local f | |
| 488 if vars.docked then | |
| 489 f = CreateFrame('Frame','DevianDockFrame' .. i, DEVIAN_DOCK_FRAME) | |
| 490 else | |
| 491 f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME) | |
| 492 end | |
| 493 --@debug@ | |
| 494 --print(f:GetName()) | |
| 495 | |
| 496 --print('create(2)') | |
| 497 for k,v in pairs(vars) do | |
| 498 f[k] = v | |
| 499 --@debug@ | |
| 500 --print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v)) | |
| 501 end | |
| 502 | |
| 503 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y) | |
| 504 f:SetSize(vars.width, vars.height) | |
| 505 f:Lower() | |
| 506 f.out:SetFont(db.font, db.fontsize, db.fontoutline) | |
| 507 if (db.current_channel == i) then | |
| 508 f.out.backdrop:SetTexture(unpack(db.frontdrop)) | |
| 509 else | |
| 510 f.out.backdrop:SetTexture(unpack(db.backdrop)) | |
| 511 end | |
| 512 | |
| 513 | |
| 514 | |
| 515 f.Save = Console_Save | |
| 516 f.Minimize = Console_Minimize | |
| 517 f.Maximize = Console_Maximize | |
| 518 f.MinMax = Console_MinMax | |
| 519 f.ToFront = Console_ToFront | |
| 520 f.Toggle = D.Console_Toggle | |
| 521 f:SetScript('OnMouseDown', Console_MouseDown) | |
| 522 f:SetScript('OnMouseUp', Console_MouseUp) | |
| 523 | |
| 524 if vars.minimized then | |
| 525 f:Minimize() | |
| 526 else | |
| 527 f:Maximize() | |
| 528 end | |
| 529 if db.enabled and f.enabled then | |
| 530 f:Show() | |
| 531 end | |
| 532 | |
| 533 return f | |
| 534 end | |
| 535 | |
| 536 --- Updates console information and returns the handle of the channel object that was worked on. | |
| 537 -- When key is nil or not a valid handle, a new channel is created using whatever signature can be found in cinfo. | |
| 538 -- The signature can be passed as a string, or as a table entry under the key 'signature' | |
| 539 -- If the signature of a new channel is also a tag, the channel will be added to that tag | |
| 540 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel | |
| 541 -- @param key string signature or index number of channel to operate on | |
| 542 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel | |
| 543 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 | |
| 544 function D:SetChannel(cinfo, key) | |
| 545 local t_info = {} | |
| 546 local channel, isNew, id, sig, t_id | |
| 547 -- obtain source data | |
| 548 if tonumber(key) ~= nil and db.channels[key] then | |
| 549 id = tonumber(key) | |
| 550 elseif D.sigID[tostring(key)] then | |
| 551 id = D.sigID[tostring(key)] | |
| 552 else | |
| 553 id = db.primary_channel | |
| 554 isNew = true | |
| 555 end | |
| 556 local dbvars = db.channels[id] | |
| 557 t_id = id -- overridden later if new | |
| 558 t_info.index = t_id -- | |
| 559 --@debug@ | |
| 560 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ | |
| 561 | |
| 562 | |
| 563 -- obtain config info | |
| 564 if type(cinfo) == 'string' then | |
| 565 sig = cinfo | |
| 566 cinfo = {signature = sig} | |
| 567 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed | |
| 568 error('Expecting table of string as arg1') | |
| 569 elseif cinfo.signature then -- new sig | |
| 570 sig = cinfo.signature | |
| 571 elseif isNew then -- new channel sig | |
| 572 sig = 'Ch' | |
| 573 else -- old sig | |
| 574 sig = db.channels[id].signature | |
| 575 end | |
| 576 t_info.signature = sig | |
| 577 --@debug@ | |
| 578 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ | |
| 579 | |
| 580 for k,v in pairs(cinfo) do -- allow all cinfo to pass | |
| 581 t_info[k] = v | |
| 582 end | |
| 583 | |
| 584 local blocked = { -- ignore these vars: | |
| 585 ['docked'] = true, -- table | |
| 586 ['dockedTo'] = true, -- table-related | |
| 587 ['signature'] = true} -- already determined | |
| 588 for k,v in pairs(dbvars) do | |
| 589 if not t_info[k] and not blocked[k] then -- already set or blocked? | |
| 590 t_info[k] = v | |
| 591 end | |
| 592 end | |
| 593 -- new channel overrides | |
| 594 if isNew then | |
| 595 if D.sigID[sig]then -- find a non-clashing signature | |
| 596 local result, i = sig, 1 | |
| 597 while D.sigID[result] do | |
| 598 result = sig .. i | |
| 599 i = i + 1 | |
| 600 end | |
| 601 t_info.signature = result | |
| 602 end | |
| 603 t_id = db.max_channel + 1 | |
| 604 t_info.index = t_id | |
| 605 --@debug@ | |
| 606 --print('setchan(3a) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@ | |
| 607 else | |
| 608 --@debug@ | |
| 609 --print('setchan(3b) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@ | |
| 610 end | |
| 611 | |
| 612 local channel | |
| 613 if not self.console[t_id] then -- create a frame | |
| 614 if isNew then -- position the channel frame | |
| 615 t_info.x = t_info.x + 20 | |
| 616 t_info.y = t_info.y - 20 | |
| 617 db.channels[t_id] = t_info | |
| 618 --@debug@ | |
| 619 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ | |
| 620 end | |
| 621 channel = CreateConsole(t_id, t_info) | |
| 622 self.console[t_id] = channel | |
| 623 self.sig[t_info.signature] = channel | |
| 624 self.sigID[t_info.signature] = t_id | |
| 625 self.IDsig[t_id] = t_info.signature | |
| 626 | |
| 627 end | |
| 628 channel = self.console[t_id] | |
| 629 if channel.minimized then | |
| 630 channel:Minimize() | |
| 631 else | |
| 632 channel:Maximize() | |
| 633 end | |
| 634 | |
| 635 if channel.enabled and db.enabled then -- hide or show last since Min/Max mess with visibility | |
| 636 print('setchan(5a) enable') | |
| 637 channel:Show() | |
| 638 else | |
| 639 print('setchan(5a) disable') | |
| 640 channel:Hide() | |
| 641 end | |
| 642 --@debug@ | |
| 643 --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@ | |
| 644 return channel | |
| 645 end | |
| 646 | 301 |
| 647 function D:PrintHelp() | 302 function D:PrintHelp() |
| 648 D:Print("|cFFFFFF00/dvn|r", | 303 D:Print("|cFFFFFF00/dvn|r", |
| 649 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.") | 304 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.") |
| 650 | 305 |
| 722 | 377 |
| 723 -- Stop here in game mode | 378 -- Stop here in game mode |
| 724 if db.workspace == 1 then | 379 if db.workspace == 1 then |
| 725 return | 380 return |
| 726 end | 381 end |
| 727 | 382 ----------------------------------------------------------------------- |
| 383 self.db = db | |
| 384 self.channels = db.channels | |
| 728 self.max_channel = 0 | 385 self.max_channel = 0 |
| 729 self.num_channels = 0 | 386 self.num_channels = 0 |
| 730 self.console = {} | 387 self.console = {} |
| 731 self.sig = {} | 388 self.sig = {} |
| 732 self.sigID = {} | 389 self.sigID = {} |
