diff 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
line wrap: on
line diff
--- a/Devian.lua	Sun Jan 03 15:49:35 2016 -0500
+++ b/Devian.lua	Mon Jan 04 05:42:44 2016 -0500
@@ -9,6 +9,12 @@
 local D = _G.Devian
 D:SetDefaultModuleState(false)
 
+local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
+local max, rand, format = math.max, math.random, string.format
+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 MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@'
 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2
@@ -56,7 +62,21 @@
   frontheader = {1,1,1,1},
   tagcolor = {},   -- tag color repository
   workspace = 2,   -- current profile
-  last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued
+  last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued
+
+  dock_onshow_fade_time = 2.5,
+  dock_onshow_fade_from = 1,
+  dock_onshow_fade_to = 0.2,
+
+  dock_alpha_on = 1,
+  dock_alpha_off = 0.2,
+  dock_fade_in = 0.15,
+  dock_fade_out = 0.45,
+  dock_button_alpha_on = 1,
+  dock_button_alpha_off = 0.2,
+  dock_button_fade_in = 0.15,
+  dock_button_fade_out = 0.45
+
 }
 
 local function ScanAddOnList(cmd, ...)
@@ -65,7 +85,7 @@
   local args = {}
   local arg, n = D:GetArgs(cmd, 1)
   while arg do
-    table.insert(args, arg)
+    insert(args, arg)
     arg, n = D:GetArgs(cmd,1,n)
   end
   local mode, tag, dest = unpack(args)
@@ -104,7 +124,7 @@
       --@debug@
       --print(i, '->', ch.index, '-', ch.signature)--@end-debug@
       if i > 2 then
-        table.insert(worklist, ch.index)
+        insert(worklist, ch.index)
       else
         target = ch
 
@@ -112,7 +132,7 @@
         --print('arg1', args[2], target)--@end-debug@
       end
     end
-    D:Print("Docking |cFF88FFFF"..table.concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.")
+    D:Print("Docking |cFF88FFFF"..concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.")
     return D:DockFrame(target.index, unpack(worklist))
 
 
@@ -174,6 +194,7 @@
         db.tags[tag][dest] = dest
         D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature)
       end
+      D:UpdateDock()
     else
       D:Print('Usage: /dvn tag <prefix> <console name or number>')
     end
@@ -242,7 +263,7 @@
         if type(db.unlisted) ~= 'table' then
           db.unlisted = {}
         end
-        table.insert(db.unlisted, name)
+        insert(db.unlisted, name)
       end
 
     end
@@ -302,13 +323,13 @@
   local pcolor
   if (not db.tagcolor[prefix]) and byName then
     local c = {
-      math.random(64,255), math.random(64,255), math.random(64,255)
+      rand(64,255), rand(64,255), rand(64,255)
     }
     if c[1] > 223 and c[2] > 223 and c[3] > 223 then
-      c[math.random(1,3)] = math.random(64,223)
+      c[rand(1,3)] = rand(64,223)
     end
 
-    db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c))
+    db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c))
   end
   pcolor = db.tagcolor[prefix]
 
@@ -331,13 +352,15 @@
       var = 'nil'
     end
 
-    table.insert(buffer, var)
+    insert(buffer, var)
   end
-  local message = table.concat(buffer, ' ')
+  local message = concat(buffer, ' ')
   for id, channel in pairs(sendq) do
     channel.out:AddMessage(message)
+    UIFrameFadeIn(D.dock.buttons[id], db.dock_onshow_fade_time, db.dock_onshow_fade_from, db.dock_onshow_fade_to)
+    UIFrameFadeIn(D.dock.buttons[id].caption, db.dock_onshow_fade_time, db.dock_onshow_fade_from, db.dock_onshow_fade_to)
   end
-  table.wipe(buffer)
+  wipe(buffer)
 end
 
 
@@ -346,6 +369,7 @@
 function D:PrintHelp()
   D:Print("|cFFFFFF00/dvn|r",
     "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.")
+  D:Print("|cFFFFFF00/dvc|r [<key>, ...]", "- Hides and show consoles. A list of channel keys can be passed to specify which ones get toggled.")
 
   D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.")
   D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
@@ -357,8 +381,8 @@
   print(MAJOR, MINOR)
 
   if db.unlisted and #db.unlisted > 0 then
-    D:Print('New AddOns have been found since the last profile update: '.. table.concat(db.unlisted, ', '))
-    table.wipe(db.unlisted)
+    D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', '))
+    wipe(db.unlisted)
   end
 
   if db.workspace == 1 then
@@ -367,6 +391,7 @@
     D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.')
   end
 
+  --@debug@
   self:RegisterChatCommand("dvg", function(input)
     if not self.config then
       self.config = DevCon
@@ -374,6 +399,7 @@
     end
     self.modules.Config:ChatCommand(input)
   end)
+  --@end-debug@
 
 end
 
@@ -415,6 +441,7 @@
     _G.DevianDB = defaults
   end
   db = _G.DevianDB
+  self.db = db
   self.tags = db.tags
   self.channelinfo = db.channels
 
@@ -444,30 +471,24 @@
   self.sig = {}
   self.sigID = {}
   self.IDsig = {}
+  self.dock = DevianDock
+  self.dock.buttons = {}
   for i, cinfo in pairs(db.channels) do
     i = tonumber(i)
     if not self.primary_channel then
       self.primary_channel = i
     end
     self:SetChannel(cinfo, i)
-    self.max_channel = math.max(i, self.max_channel)
+    self.max_channel = max(i, self.max_channel)
     self.num_channels = self.num_channels + 1
   end
 
-  for i, channel in pairs(db.channels) do
-    if type(channel.docked) == 'table' then
-      --oldprint('docking',i, unpack(channel.docked))
-      self.DockFrame(i, unpack(channel.docked))
-    end
-  end
-
   if self.console[db.current_channel] then
     self.console[db.current_channel]:ToFront()
     -- bring the current channel to the front
   end
-  self.dock = DevianDock
-
-
+  DevianDock:Show()
+  self:UpdateDock()
   setprinthandler(Message)
   print = function(...)
     _G.print('Dvn', ...)
@@ -477,45 +498,77 @@
 --- Console frame toggler
 -- @paramsig [...]
 -- @param ... one or more space-seperated channel keys
-function D:Console_Toggle(input)
+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
-  if self:GetArgs(input,1) then
-    repeat
-      local key, n = self:GetArgs(input,1,n)
+  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
-        table.insert(search, self.sigID[key])
-      elseif self.console[key] then
-        table.insert(search, tonumber(key))
+        --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
-    until n == 1e9
-  else
+
+      --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
+    end
   end
 
-  db.enabled = (not db.enabled) and true or nil
   for i, id in pairs(search) do
     --oldprint(i, id)
     local c = self.console[id]
-    if db.enabled then
-      c.enabled = true
+    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)
+    end
+
+    if c.enabled or (setAll and db.enabled) then
       c:Show()
       if db.current_channel == c.index then
         c:ToFront()
       end
-      c:Save()
-    else
+    elseif not (c.enabled and db.enabled) then
       c:Hide()
     end
+    c:Save()
   end
 
-  if db.enabled then
-    self:Print('toggled on: '..table.concat(search, ', '))
+  if setAll then
+    if db.enabled then
+      self:Print('toggled all consoles ON')
+    else
+      self:Print('toggled all consoles OFF')
+    end
   else
-    self:Print('toggled off: '..table.concat(search, ', '))
+    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