Mercurial > wow > devian
diff UI.lua @ 66:516ceb31703d
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.
author | Nenue |
---|---|
date | Sat, 05 Mar 2016 13:35:51 -0500 |
parents | 8729d39f6a3d |
children | 1687ae1c6162 |
line wrap: on
line diff
--- 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