# HG changeset patch # User Nenue # Date 1457202951 18000 # Node ID 516ceb31703d2ea14a190577dc158b85e71070bf # Parent 4148c90986e775c2b6189ab46882eb8ca18e8f86 New profile system that stores channel and tag settings for each saved AddOn list. A boatload of structural revisions, making better use of the built-in table, and hopefully making console command issues easier to pick up. diff -r 4148c90986e7 -r 516ceb31703d Config.lua --- a/Config.lua Fri Mar 04 08:01:16 2016 -0500 +++ b/Config.lua Sat Mar 05 13:35:51 2016 -0500 @@ -3,15 +3,12 @@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 12/30/2015 1:35 AM - -if not LibStub then - print('Something has happened...') -end -local D = LibStub("AceAddon-3.0"):GetAddon("Devian") +local _, D = ... DevCon = D:NewModule("Config") local Cf, tinsert, ipairs, tostring = DevCon, table.insert, ipairs, tostring local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() local db +local print = D.print local SetOpt = function(info, value) diff -r 4148c90986e7 -r 516ceb31703d Devian.lua --- a/Devian.lua Fri Mar 04 08:01:16 2016 -0500 +++ b/Devian.lua Sat Mar 05 13:35:51 2016 -0500 @@ -2,46 +2,83 @@ -- @file-author@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -if not LibStub then - print('Something has happened...') + +--GLOBALS: Devian, DevCon, DevianLoadMessage +local ADDON, D = ... + +local currentProfile +local playerName = UnitName("player") +local playerRealm = playerName .. '-' .. GetRealmName() +local num_dock_tabs = 0 +local in_workspace = false +--@debug@ +D.debugmode = true +--@end-debug@ +D.print = function(...) + if currentProfile and not currentProfile.workspace then + return + end + + if D.debugmode then + return print('Dvn', ...) + else + return function() end + end end +local print = D.print + +setmetatable(D, { + __call = function(t,k) + if not k then + return t.in_workspace + end + + return function(value) + if value then + D[k] = value + end + return D[k] + end + end +}) +D.L = setmetatable({}, { + __index= function(t,k) + return k + end, + __call = function(t,k,...) + return string.format((t[k] or k) , ...) + end +}) + local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' -Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") -local D = _G.Devian +local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0") +local L = D.L +_G.Devian = D D:SetDefaultModuleState(false) -D.L = {} -setmetatable(D.L, {__index= function(t,k) return k end, __call = function(t,k,...) return string.format((t[k] or k) , ...) end}) -local L = D.L +D.oldprint = getprinthandler() +if not _G.oldprint then _G.oldprint = D.oldprint end + local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type -local max, rand, format = math.max, math.random, string.format +local max, rand, format, print = max, math.random, string.format, print local insert, wipe, concat = table.insert, table.wipe, table.concat local select, unpack = select, unpack local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn local UnitName, DisableAddOn = UnitName, DisableAddOn -local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 -local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() -local print = _G.print + local db local defaults = { - ['global'] = {{}, {}}, - ['tags'] = {}, - ['channels'] = {[1] = { + global = {{}, {}}, + default_channel = { signature = 'Main', - index = 1, x = 100, y = 800, height = 500, width = 600, - enabled = true}}, - ['profiles'] = { - {'Main', false}, - {'Devian', true}, - {'Turok', true}, - {'Bam', true} + enabled = true}, + current_profile = 1, + main_profile = 1, + last_profile = 1, + profilesName = {}, + profiles = { }, - primary_channel = 1, -- the channel to which default output is sent - current_channel = 1, -- the front channel - max_channel = 1, -- the highest created channel id - enabled = true, -- allow enabled consoles to appear - load_message = "Defaults loaded.", -- messages to be displayed after reload font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info fontsize = 13, fontoutline = 'NONE', @@ -91,9 +128,91 @@ movement_translation_y = 25, } -local function ScanAddOnList(cmd, ...) - local list_state +D.console = {} +D.max_channel = 0 +D.Profile = function (id, name) + + if name and not id and db.profilesName[name] then + id = db.profilesName[name] + print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r') + end + + if not id or not db.profiles[id] then + if not id then + id = #db.profiles+1 + print('Generated profile ID: |cFFFFFF00'.. id .. '|r') + end + + if not name or db.profilesName[name] then + local newName = name or (id == 1 and 'Main' or 'Profile') + local prefix = newName + local i = 2 + while db.profilesName[newName] do + i = i + 1 + newName = prefix .. i + end + name = newName + print('Generated profile name: |cFF00FF00'..newName..'|r') + end + print('Creating profile') + db.profilesName[name] = id + db.profiles[id] = { + name = name, + workspace = (id ~= 1), + current_channel = 1, + default_channel = 1, + num_channels = 1, + max_channel = 1, -- the highest created channel id + enabled = true, -- allow enabled consoles to appear + channels = { + { + index = 1, + signature = 'Main', + x = 100, y = 800, + height = 500, width = 600, + enabled = true + } + }, + loadouts = {}, + global = {}, + tags = {}, + char = { + [playerRealm] = {} + }, + unlisted = {} + } + end + + D.currentProfile = db.profiles[id] + currentProfile = D.currentProfile + currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} + if currentProfile.workspace then + setprinthandler(D.Message) + else + print = function() end + end + + D.unlisted = currentProfile.unlisted + D.channels = currentProfile.channels + D.tags = currentProfile.tags + D.channelinfo = currentProfile.channels + D.char = currentProfile.char[playerRealm] + D.global = currentProfile.global + D.num_channels = currentProfile.num_channels + D.enabled = currentProfile.enabled + D.sig = {} + D.sigID = {} + D.IDsig = {} + D.dock = DevianDock + D.dock.buttons = D.dock.buttons or {} + + return id, name +end + +local targetGlobal, targetChar +D.Command = function (self, cmd, ...) + local list_id, scan_func, reload local args = {} local arg, n = D:GetArgs(cmd, 1) while arg do @@ -102,151 +221,137 @@ end local mode, tag, dest = unpack(args) - -- no args, toggle ui if mode == 'stack' then - if db.workspace == 1 then - return D:Print(L['Need devmode']) - end return D:StackFrames() elseif mode == 'grid' then - if db.workspace == 1 then - return D:Print(L['Need devmode']) - end return D:DistributeFrames() elseif mode == 'tag' then -- tagging - if db.workspace == 1 then - return D:Print(L['Need devmode']) - end + return D.Tag(self, tag, dest) + elseif tonumber(mode) ~= nil or mode == 'save' then + -- either a number of the save command + if mode == 'save' then + list_id = tonumber(tag) + if list_id == nil then + D:Print(L('Invalid ID from arg', tag)) + end + D.Profile(list_id, dest) + scan_func = D.Save + D:Print("Profile |cFFFFFF00".. list_id .."|r saved.") + else - local sig - if tag ~= nil and dest ~= nil then - --@debug@ - --print(tag, dest) - --@end-debug@ + DevianLoadMessage = "Switched profiles." - -- convert to ID - if tonumber(dest) == nil then - if D.sigID[dest] then - dest = db.channels[D.sigID[dest]].index - else - sig = dest - end - else - dest = tonumber(dest) + list_id = tonumber(mode) + if list_id ~= db.main_profile then + db.last_profile = list_id end - --@debug@ - --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@ - - -- make a new channel? - local channel - if not D.db.channels[dest] then - dest = D.max_channel + 1 - D:Print(L('New channel created', sig and (dest..':'..sig) or dest )) - channel = D:SetChannel(sig or tag,dest) - else - - channel = D.db.channels[dest] - end - --@debug@ - --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@ - - if not db.tags[tag] then -- no tag table? - db.tags[tag] = {} - end - - if db.tags[tag][dest] then -- is tag set? - db.tags[tag][dest] = nil - D:Print(L('Tag removed from channel', tag, db.channels[dest].index, db.channels[dest].signature)) - else - db.tags[tag][dest] = dest - D:Print(L('Tag added to channel', tag, db.channels[dest].index, db.channels[dest].signature)) - end - D:UpdateDock() - else - D:Print(L['Command tag help']) - end - return - elseif tonumber(mode) ~= nil or mode == 'save' then - -- iterating for something - if mode == 'save' then - if tonumber(tag) == nil then - T:Print(L('Invalid ID from arg', tag)) - end - list_state = tonumber(tag) - else - list_state = tonumber(mode) - db.workspace = list_state - if list_state ~= 1 then - db.last_workspace = list_state - end - + db.current_profile = list_id + scan_func = D.Load end elseif mode == nil then - list_state = (db.workspace == 1) and db.last_workspace or 1 - db.workspace = list_state + list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile + DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')' + db.current_profile = list_id + scan_func = D.Load else return D:PrintHelp() end + targetGlobal = db.profiles[list_id].global + targetChar = db.profiles[list_id].char[playerRealm] - -- start the iterating - if not db[PLAYER_REALM][list_state] then - db[PLAYER_REALM][list_state] = {} - end - if not db.global[list_state] then - db.global[list_state] = {} - end - - local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] - local playername = UnitName("player") - - for i = 1, GetNumAddOns() do - local name = GetAddOnInfo(i) - local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) - - if mode == 'save' then - char_list[name] = enableState - global_list[name] = globalState - else - if char_list[name] or global_list[name] then - if char_list[name] ~= 0 and global_list[name] ~= 0 then - local value = false - if char_list[name] == 2 and global_list[name] == 1 then - value = UnitName("player") - elseif global_list[name] == 2 then - value = true - end - --print('EnableAddOn(', i, ',', value,')') - EnableAddOn(i, value) - else - local value = true - if char_list[name] == 2 and global_list[name] == 1 then - value = UnitName("player") - end - --print('DisableAddOn(', i, ',', value,')') - DisableAddOn(i,value) - end - elseif mode ~= 'save' then - if type(db.unlisted) ~= 'table' then - db.unlisted = {} - end - insert(db.unlisted, name) - end - + if scan_func then + for id, name, enableState, globalState in D.Addons() do + scan_func(id, name, enableState, globalState) end end - if mode ~= 'save' then - db.load_message = (mode == nil) and L("Toggled to profile", list_state) or L('Switched to profile number', list_state) + if scan_func == D.Load then ReloadUI() + end + D.Profile(db.current_profile) +end + +D.Addons = function() + local playername = UnitName("player") + return function(n, i) + if i >= n then + return nil + end + + i = i + 1 + local name = GetAddOnInfo(i) + local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) + return i, name, enableState, globalState + end, GetNumAddOns(), 0 +end + +D.Load = function(id, name, charState, globalState) + if targetChar[name] or targetGlobal[name] then + if targetGlobal[name] == 2 then + EnableAddOn(id, true) + elseif targetChar[name] == 2 then + EnableAddOn(id, playerName) + else + DisableAddOn(id, playerName) + end + print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name]) else + tinsert(D.unlisted, name) + end +end +D.Save = function(id, name, charState, globalState) + print('save', id, name, charState, globalState) + targetGlobal[name] = globalState + targetChar[name] = charState +end - if list_state == 1 then - D:Print(L['Profile main saved']) +D.Tag = function(self, tag, dest) + local sig + if tag ~= nil and dest ~= nil then + --@debug@ + --print(tag, dest) + --@end-debug@ + + -- convert to ID + if tonumber(dest) == nil then + if D.sigID[dest] then + dest = currentProfile.channels[D.sigID[dest]].index + else + sig = dest + end else - db.last_workspace = list_state - D:Print(L('Profile number saved', list_state, list_state)) + dest = tonumber(dest) end + --@debug@ + --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@ + + -- make a new channel? + local channel + if not currentProfile.channels[dest] then + dest = D.max_channel + 1 + D:Print(L('New channel created', sig and (dest..':'..sig) or dest )) + channel = D:SetChannel(sig or tag,dest) + else + channel = D.channels[dest] + end + --@debug@ + --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@ + + if not currentProfile.tags[tag] then -- no tag table? + currentProfile.tags[tag] = {} + end + + if currentProfile.tags[tag][dest] then -- is tag set? + currentProfile.tags[tag][dest] = nil + D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature)) + else + currentProfile.tags[tag][dest] = dest + D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature)) + end + D:UpdateDock() + else + D:Print(L['Command tag help']) end end @@ -257,8 +362,8 @@ -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. -- @param ... Output contents. -local function Message(prefix, ...) - if db.workspace == 1 then +function D.Message(prefix, ...) + if currentProfile.workspace then return D.oldprint(prefix, ...) end prefix = tostring(prefix) @@ -349,110 +454,51 @@ D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") end -local dot1, dot2 = CreateFrame('Frame', nil, UIParent), CreateFrame('Frame', nil, UIParent) -dot1:SetSize(5,5) -dot1:SetFrameStrata('TOOLTIP') -local a = dot1:CreateTexture('fill', nil) -a:SetAllPoints(dot1) -a:SetTexture(1,0,0,1) -dot2:SetSize(5,5) -dot2:SetFrameStrata('TOOLTIP') -a = dot2:CreateTexture('fill', nil) -a:SetAllPoints(dot2) -a:SetTexture(0,1,0,1) - -local OnStartedMoving = function() - for k, v in pairs(D.console) do - if v.enabled then - v.moveFade:Stop() - local F1 = v.moveFade.alphaOut - F1:SetFromAlpha(db.movement_fade_from) - F1:SetToAlpha(db.movement_fade_to) - F1:SetDuration(db.movement_fade_time) - v.moveFade:Play() - v:EnableMouse(false) +local blocked = {profiles = true, debugmode = true} +D.SetDefaults = function() + for k,v in pairs(DevianDB) do + if not blocked[k] then + DevianDB[k] = nil end end -end - -local OnStoppedMoving = function() - for k, v in pairs(D.console) do - if v.enabled then - v.moveFade:Stop() - local F1 = v.moveFade.alphaOut - F1:SetToAlpha(db.movement_fade_from) - F1:SetFromAlpha(db.movement_fade_to) - F1:SetDuration(db.movement_fade_time) - v.moveFade:Play() - v:EnableMouse(true) + for k,v in pairs(defaults) do + if not blocked[k] then + DevianDB[k] = v end end + DevianLoadMessage = "Non-user SavedVars have been reset." + ReloadUI() end - +D.SetDefaultsAll = function () + DevianDB = nil + DevianLoadMessage = "All SavedVars wiped." + ReloadUI() +end +D.ConfigCommand = function(input) + if not self.config then + self.config = DevCon + self:EnableModule("Config") + end + self.modules.Config:ChatCommand(input) +end function D:OnEnable() - if db.unlisted and #db.unlisted > 0 then - D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', ')) - wipe(db.unlisted) - end - - if db.workspace == 1 then - D:Print(L('Devian loaded on standby',MAJOR, MINOR)) - else - D:Print(L('Devian loaded in workspace', MAJOR, MINOR, db.workspace)) - -- movement fading - if db.movement_fade then - - self:RegisterEvent('PLAYER_STARTED_MOVING', OnStartedMoving) - self:RegisterEvent('PLAYER_STOPPED_MOVING', OnStoppedMoving) - end - end - - --@debug@ - self:RegisterChatCommand("dvg", function(input) - if not self.config then - self.config = DevCon - self:EnableModule("Config") - end - self.modules.Config:ChatCommand(input) - end) - --@end-debug@ - -end - -function D:OnInitialize() -- commands - self:RegisterChatCommand("cleandvn", function(args) - DevianDB = nil - DevianDB = { - load_message = "All SavedVars wiped." - } - ReloadUI() - end) - local blocked = {global = true, channels = true, tags = true, [PLAYER_REALM] = true} - self:RegisterChatCommand("resetdvn", function(args) - for k,v in pairs(DevianDB) do - if not blocked[k] then - DevianDB[k] = nil - end - end - for k,v in pairs(defaults) do - if not blocked[k] then - DevianDB[k] = v - end - end - DevianDB.load_message = "Non-user SavedVars have been reset." - ReloadUI() - end) local cmdlist = { - ['dvn'] = ScanAddOnList, - ['devian'] = ScanAddOnList, + ['dvn'] = "Command", + ['devian'] = "Command", ['dvc'] = "Console_Toggle", + ['cleandvn'] = "SetDefaultsAll", + ['resetdvn'] = "SetDefaults", + ['dvg'] = "ConfigCommand" } for cmd, func in pairs(cmdlist) do self:RegisterChatCommand(cmd, func, true) end +end + +function D:OnInitialize() -- pull defaults if not _G.DevianDB then @@ -460,135 +506,45 @@ end db = _G.DevianDB self.db = db - self.tags = db.tags - self.channelinfo = db.channels - if not db[PLAYER_REALM] then - db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}} + --- + if DevianLoadMessage then + D:Print(DevianLoadMessage) + DevianLoadMessage = nil end - if db.load_message then - D:Print(db.load_message) - db.load_message = nil - end - D.oldprint = getprinthandler() - if not _G.oldprint then - _G.oldprint = D.oldprint + + --- initialize the current profile + local id, name = D.Profile(db.current_profile or 1) + D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') + if currentProfile.workspace then + D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.') + D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r') end - -- Stop here in game mode - if db.workspace == 1 then - return - end - ----------------------------------------------------------------------- - self.db = db - self.channels = db.channels - self.max_channel = 0 - self.num_channels = 0 - self.console = {} - self.sig = {} - self.sigID = {} - self.IDsig = {} - self.dock = DevianDock - self.dock.buttons = {} - for i, cinfo in pairs(db.channels) do + for i, cinfo in pairs(D.channels) do i = tonumber(i) - if not self.primary_channel then - self.primary_channel = i + if not D.primary_channel then + D.primary_channel = i end - self:SetChannel(cinfo, i) - self.max_channel = max(i, self.max_channel) - self.num_channels = self.num_channels + 1 + D:SetChannel(cinfo, i) + D.num_channels = D.num_channels + 1 end - if self.console[db.current_channel] then - print('bringing', self.console[db.current_channel].signature, 'to the front') - self.console[db.current_channel]:ToFront() - -- bring the current channel to the front - end - DevianDock:Show() - self:UpdateDock() - setprinthandler(Message) - print = function(...) - _G.print('Dvn', ...) - end -end - ---- Console frame toggler --- @paramsig [...] --- @param ... one or more space-seperated channel keys -function D:Console_Toggle(input, force) - --oldprint(input) - local setAll - if db.workspace == 1 then - return self:Print(MSG_NEED_DEV_MODE) - end - local search = {} - local key - local n = 0 - while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but - key, n = self:GetArgs(input,1,n) - - if self.sig[key] then - --print(key, self.sigID[key]) - insert(search, self.sigID[key]) - elseif self.console[tonumber(key)] then - --print(key, tonumber(key)) - insert(search, tonumber(key)) - end - - --oldprint(#search, key, n) - end - if #search < 1 then - search = self.sigID - setAll = true - end - if setAll then - --oldprint('setall', setAll) - db.enabled = (not db.enabled) and true or nil - if force == 0 then - db.enabled = nil + D.max_channel = max(D.max_channel, currentProfile.max_channel) + if currentProfile.max_channel < D.max_channel then + for i = currentProfile.max_channel, D.max_channel do + D.console[i]:Hide() end end - for i, id in pairs(search) do - --oldprint(i, id) - local c = self.console[id] - if setAll then - c.enabled = db.enabled and db.enabled or nil - else - - db.enabled = true - c.enabled = (not c.enabled) and true or nil - if force == 0 then - c.enabled = nil - end - --oldprint(id, ' ', force, c.enabled, db.enabled) + if currentProfile.workspace then + if D.console[currentProfile.current_channel] then + print('bringing', D.console[currentProfile.current_channel].signature, 'to the front') + D.console[currentProfile.current_channel]:ToFront() + -- bring the current channel to the front end - - if c.enabled or (setAll and db.enabled) then - c:Show() - elseif not (c.enabled and db.enabled) then - c:Hide() - end - c:Save() + DevianDock:Show() + D:UpdateDock() end - - if setAll then - if db.enabled then - self:Print('toggled all consoles ON') - if D.console[db.current_channel] then - oldprint('push', D.console[db.current_channel].signature, 'to the front') - D.console[db.current_channel]:ToFront() - end - else - self:Print('toggled all consoles OFF') - end - else - local result = {} - for i, id in pairs(search) do - result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF') - end - self:Print('toggled: '..concat(result, ', ')) - end -end \ No newline at end of file +end diff -r 4148c90986e7 -r 516ceb31703d Dock.lua --- a/Dock.lua Fri Mar 04 08:01:16 2016 -0500 +++ b/Dock.lua Sat Mar 05 13:35:51 2016 -0500 @@ -4,11 +4,10 @@ -- @file-revision@ @file-hash@ -- Created: 12/26/2015 12:32 PM -- Docking and arrangement calls - -local D = LibStub("AceAddon-3.0"):GetAddon("Devian") +local _, D = ... local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight -local UIFrameFadeIn, UIFrameFadeOut = UIFrameFadeIn, UIFrameFadeOut local db +local print = D.print --- Spaces each frame evenly across the screen. function D:DistributeFrames() -- diff -r 4148c90986e7 -r 516ceb31703d Locale.lua --- a/Locale.lua Fri Mar 04 08:01:16 2016 -0500 +++ b/Locale.lua Sat Mar 05 13:35:51 2016 -0500 @@ -1,5 +1,5 @@ - -local L = Devian.L +local _, D = ... +local L = D.L L['Devian loaded on standby'] = "%s%s. Work mode |cFFFFFF00off|r. /dvn help for info." L['Devian loaded in workspace'] = "%s%s. Work mode |cFF00FF00on|r. Profile #%d loaded." diff -r 4148c90986e7 -r 516ceb31703d UI.lua --- a/UI.lua Fri Mar 04 08:01:16 2016 -0500 +++ b/UI.lua Sat Mar 05 13:35:51 2016 -0500 @@ -6,8 +6,38 @@ if not LibStub then print('Something has happened...') end -local D = LibStub("AceAddon-3.0"):GetAddon("Devian") +local _, D = ... local DEVIAN_FRAME = 'DevianConsole' +local insert, tonumber, pairs, concat = tinsert, tonumber, pairs, table.concat +local L = D.L +local print = D.print + + + + +local Console_OnMovementChanged = function(self, event) + local db = D.db + if self.enabled then + if event == 'PLAYER_STARTED_MOVING' then + self.moveFade:Stop() + local F1 = self.moveFade.alphaOut + F1:SetFromAlpha(db.movement_fade_from) + F1:SetToAlpha(db.movement_fade_to) + F1:SetDuration(db.movement_fade_time) + self.moveFade:Play() + self:EnableMouse(false) + else + self.moveFade:Stop() + local F1 = self.moveFade.alphaOut + F1:SetToAlpha(db.movement_fade_from) + F1:SetFromAlpha(db.movement_fade_to) + F1:SetDuration(db.movement_fade_time) + self.moveFade:Play() + self:EnableMouse(true) + end + end +end + local function Console_MinMax(self) @@ -177,6 +207,7 @@ f.Toggle = D.Console_Toggle f:SetScript('OnMouseDown', Console_MouseDown) f:SetScript('OnMouseUp', Console_MouseUp) + f.profileID = db.current_profile UIDropDownMenu_Initialize(f.menuFrame, function() @@ -198,6 +229,12 @@ end end, 'MENU') + if db.movement_fade then + f:RegisterEvent('PLAYER_STARTED_MOVING') + f:RegisterEvent('PLAYER_STOPPED_MOVING') + f:SetScript('OnEvent', Console_OnMovementChanged) + end + D.dock.buttons[i] = CreateFrame('Button', 'Channel'..i..'Beacon', UIParent, 'DevianBeacon') D.dock.buttons[i].icon:SetVertexColor(math.random(),math.random(),math.random()) D.dock.buttons[i].console = f @@ -227,25 +264,25 @@ -- @usage channel = D:SetChannel('new', nil) -- creates a new channel -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 function D:SetChannel(cinfo, key) - local db = self.db + local profile = D.currentProfile local t_info = {} local channel, isNew, id, sig, t_id --@debug@ - --print('setchan(0) cinfo, key', cinfo, key)--@end-debug@ + print('setchan(0) cinfo, key', cinfo, key)--@end-debug@ -- obtain source data - if tonumber(key) ~= nil and db.channels[key] then + if tonumber(key) ~= nil and D.channels[key] then id = tonumber(key) elseif D.sigID[tostring(key)] then id = D.sigID[tostring(key)] else - id = db.primary_channel + id = profile.default_channel isNew = true end - local dbvars = db.channels[id] + local dbvars = D.channels[id] t_id = id -- overridden later if new t_info.index = t_id -- --@debug@ - --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ + print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ -- obtain config info @@ -253,17 +290,17 @@ sig = cinfo cinfo = {signature = sig} elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed - error('Expecting table of string as arg1') + error('Expecting table of string as arg1') elseif cinfo.signature then -- new sig - sig = cinfo.signature + sig = cinfo.signature elseif isNew then -- new channel sig - sig = 'Ch' + sig = 'Ch' else -- old sig - sig = db.channels[id].signature + sig = D.channels[id].signature end t_info.signature = sig --@debug@ - --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ + print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ for k,v in pairs(cinfo) do -- allow all cinfo to pass t_info[k] = v @@ -291,29 +328,27 @@ t_id = self.max_channel + 1 t_info.index = t_id --@debug@ - --print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ + print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ else --@debug@ - --print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ + print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ end local channel if not self.console[t_id] then -- create a frame - if isNew then -- position the channel frame - self.max_channel = t_id - db.max_channel = t_id - t_info.x = t_info.x + 20 - t_info.y = t_info.y - 20 - db.channels[t_id] = t_info - --@debug@ - --print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ - end - channel = CreateConsole(t_id, t_info) - self.console[t_id] = channel - self.sig[t_info.signature] = channel - self.sigID[t_info.signature] = t_id - self.IDsig[t_id] = t_info.signature - + if isNew then -- position the channel frame + profile.max_channel = t_id + t_info.x = t_info.x + 20 + t_info.y = t_info.y - 20 + profile.channels[t_id] = t_info + --@debug@ + print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ + end + channel = CreateConsole(t_id, t_info) + self.console[t_id] = channel + self.sig[t_info.signature] = channel + self.sigID[t_info.signature] = t_id + self.IDsig[t_id] = t_info.signature end channel = self.console[t_id] if channel.minimized then @@ -323,14 +358,90 @@ end if channel.enabled then -- hide or show last since Min/Max mess with visibility - --print('setchan(5a) enable') + print('setchan(5a) enable') channel:Show() --channel:ToFront() else - --print('setchan(5a) disable') + print('setchan(5a) disable') channel:Hide() end --@debug@ - --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@ + print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, profile.enabled)--@end-debug@ return channel -end \ No newline at end of file +end + +--- Console frame toggler +-- @paramsig [...] +-- @param ... one or more space-seperated channel keys +function D:Console_Toggle(input, force) + local profile = D.currentProfile + --oldprint(input) + local setAll + local search = {} + local key + local n = 0 + while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but + key, n = self:GetArgs(input,1,n) + + if self.sig[key] then + --print(key, self.sigID[key]) + insert(search, self.sigID[key]) + elseif self.console[tonumber(key)] then + --print(key, tonumber(key)) + insert(search, tonumber(key)) + end + + --oldprint(#search, key, n) + end + if #search < 1 then + search = self.sigID + setAll = true + end + if setAll then + --oldprint('setall', setAll) + profile.enabled = (not profile.enabled) and true or nil + if force == 0 then + profile.enabled = nil + end + end + + for i, id in pairs(search) do + --oldprint(i, id) + local c = self.console[id] + if setAll then + c.enabled = profile.enabled and profile.enabled or nil + else + + profile.enabled = true + c.enabled = (not c.enabled) and true or nil + if force == 0 then + c.enabled = nil + end + --oldprint(id, ' ', force, c.enabled, db.enabled) + end + + if c.enabled or (setAll and profile.enabled) then + c:Show() + elseif not (c.enabled and profile.enabled) then + c:Hide() + end + c:Save() + end + + if setAll then + if profile.enabled then + self:Print('toggled all consoles ON') + if D.console[profile.current_channel] then + D.console[profile.current_channel]:ToFront() + end + else + self:Print('toggled all consoles OFF') + end + else + local result = {} + for i, id in pairs(search) do + result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF') + end + self:Print('toggled: '..concat(result, ', ')) + end +end