changeset 36:bec37163b7fe v2.0-beta

rewrote the blocks for '/dvn tag' and SetChannel to be more predictable; currently follows: /dvn tag <source> <dest> if <dest> matches a channel, then the tag for <source> is added or removed if <dest> is a string and it doesn't match a channel, then that channel is created with <dest> as a signature if <dest> is a number that doesn't match a channel index, then <dest> is set to <highest valid index + 1>, the channel is created under that, and <source> is used as its signature SetChannel(cinfo, key) start with an empty table t_info that is filled in as follows: if key doesn't match a valid index/signature, then a channel is being created if key does match a valid index, then a channel is being updated if cinfo is a string, then only the signature value is imposed if cinfo is a table, the values from that table are imposed if a channel is being created, then the new channel info is filled in from primary channel, the index is auto-generated, and the signature value is checked for collision, and the information is passed through CreateConsole to form internal assignments if a channel is being updated, then t_info is populated from the channel data, and any internal table assignments are switched over to t_info the old tables sink into garbage collection
author Nenue
date Sun, 27 Dec 2015 08:19:45 -0500
parents 3304455a3f45
children e3206e85ca70
files Devian.lua Devian.xml UI.lua
diffstat 3 files changed, 143 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/Devian.lua	Sun Dec 27 03:51:17 2015 -0500
+++ b/Devian.lua	Sun Dec 27 08:19:45 2015 -0500
@@ -8,6 +8,7 @@
 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@'
 local D = _G.Devian
+local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2
 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
 local print = _G.print
@@ -27,18 +28,19 @@
   headergrad = {'VERTICAL', 0, 0, 0, 0.5, 0.1, 0.1, 0.1, 0.3}, -- header info
   headerdrop = {1,1,1,1},
   headeralpha = 1,
-  backdrop = {0,0,0,1},                                        -- background frame info
+  headerfontcolor = {1,0.2,0.2,1},
+  backdrop = {1,1,1,1},                                        -- background frame info
   backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5},
   backblend = 'MOD',
   backalpha = 0.7,
   backborder = {0,0,1,0.75},
-  frontdrop = {0,0,0,1},                                       -- foreground frame info
-  frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9},
+  frontdrop = {1,1,1,1},                                       -- foreground frame info
+  frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.8, 0, 0, 0, 0.6},
   frontblend = 'MOD',
   frontalpha = 1,
   frontborder = {1,0,0,1},
   tagcolor = {},   -- tag color repository
-  workspace = 1,   -- current profile
+  workspace = 2,   -- current profile
   last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued
 }
 
@@ -114,18 +116,30 @@
       return D:Print(MSG_NEED_DEV_MODE)
     end
 
+    local sig
     if tag ~= nil and dest ~= nil then
+      --@debug@
+      print(tag, dest)
+      --@end-debug@
+
       -- convert to ID
-      if tonumber(dest) == nil and D.sigID[dest] then
-        dest = db.channels[D.sigID[dest]].index
+      if tonumber(dest) == nil then
+        if D.sigID[dest] then
+          dest = db.channels[D.sigID[dest]].index
+        else
+          sig = dest
+        end
       end
+      print('2 tag,dest,sig', tag, dest, sig)
 
       -- make a new channel?
+      local channel
       if not db.channels[dest] then
-        dest = db.max_channel + 1
-        D:Print('Creating a new channel for '.. tag)
-        D:SetChannel(tag, dest)
+        dest = D.max_channel + 1
+        D:Print('Created channel |cFF88FFFF'.. (sig and (dest..':'..sig) or dest ) .. '|r')
+        channel = D:SetChannel(sig or tag,dest)
       end
+      print('3',tag, dest)
 
       if db.tags[tag] and db.tags[tag][dest] then
         db.tags[tag][dest] = nil
@@ -165,6 +179,13 @@
   end
 
   -- 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")
 
@@ -332,23 +353,25 @@
     }
     ReloadUI()
     end)
+  local blocked = {global = true, [PLAYER_REALM] = true}
   self:RegisterChatCommand("resetdvn", function(args)
     for k,v in pairs(DevianDB) do
-      if k ~= 'global' then
+      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."
-    for k,v in pairs(defaults) do
-      DevianDB[k] = v
-    end
     ReloadUI()
   end)
   local cmdlist = {
     ['dvn'] = ScanAddOnList,
     ['devian'] = ScanAddOnList,
-    ['dvc'] = Console_Toggle,
+    ['dvc'] = "Console_Toggle",
   }
   for cmd, func in pairs(cmdlist) do
     self:RegisterChatCommand(cmd, func, true)
@@ -398,6 +421,7 @@
     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))
@@ -413,4 +437,50 @@
   print = function(...)
     _G.print('Dvn', ...)
   end
+end
+
+--- Console frame toggler
+-- @paramsig [...]
+-- @param ... one or more space-seperated channel keys
+function D:Console_Toggle(input)
+  oldprint(input)
+  if db.workspace == 1 then
+    return self:Print(MSG_NEED_DEV_MODE)
+  end
+  local search = {}
+  local n = 0
+  if self:GetArgs(input,1) then
+    repeat
+      local 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))
+      end
+    until n == 1e9
+  else
+    search = self.sigID
+  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
+      c:Show()
+      if db.current_channel == c.index then
+        c:ToFront()
+      end
+      c:Save()
+    else
+      c:Hide()
+    end
+  end
+
+  if db.enabled then
+    self:Print('toggled on: '..table.concat(search, ', '))
+  else
+    self:Print('toggled off: '..table.concat(search, ', '))
+  end
 end
\ No newline at end of file
--- a/Devian.xml	Sun Dec 27 03:51:17 2015 -0500
+++ b/Devian.xml	Sun Dec 27 08:19:45 2015 -0500
@@ -12,7 +12,7 @@
   </Texture>
 
 
-  <Texture virtual="true" name="DevianHeader" parentKey="titlebar" alphaMode="BLEND">
+  <Texture virtual="true" name="DevianHeader" alphaMode="BLEND">
     <Anchors>
       <Anchor point="TOPLEFT" />
       <Anchor point="TOPRIGHT" />
@@ -25,17 +25,18 @@
     </Gradient>
   </Texture>
 
-  <Button virtual="true" name="DevianDDButton" parentKey="button" alphaMode="BLEND">
+  <Button virtual="true" name="DevianDDButton" alphaMode="BLEND">
     <Scripts>
       <OnClick>
         ToggleDropDownMenu(1, nil, self:GetParent().menuFrame, self, 0, 0);
       </OnClick>
     </Scripts>
-    <Size x="16" y="16" />
+    <Size x="32" y="16" />
     <Layers>
       <Layer level="ARTWORK">
-        <Texture file="Interface\Addons\Devian\menu-button.blp" setAllPoints="true" alphaMode="ADD">
+        <Texture parentKey="icon" file="Interface\Addons\Devian\menu-button.blp" setAllPoints="true" alphaMode="ADD">
           <Color a="1" r="1" g="1" b="1" />
+          <TexCoords top="0.47" left="0" bottom="0.9" right="1" />
         </Texture>
       </Layer>
     </Layers>
@@ -46,18 +47,7 @@
   <Frame name="DevianDDMenu" virtual="true" inherits="UIDropDownMenuTemplate" id="1">
     <Scripts>
       <OnLoad>
-        local f = self:GetParent()
-        UIDropDownMenu_Initialize(self, function()
-          local info            = {
-            text       = "Some Text",
-            value      = "OptionVariable",
-            func       = function () print(self:GetParent().signature, 'how') end
-          }
-          -- can also be done as function() FunctionCalledWhenOptionIsClicked() end;
-
-          -- Add the above information to the options menu as a button.
-          UIDropDownMenu_AddButton(info);
-        end, 'MENU')</OnLoad>
+        </OnLoad>
     </Scripts>
   </Frame>
 
@@ -141,12 +131,19 @@
       </OnMouseWheel>
     </Scripts>
     <Layers>
-      <Layer level="ARTWORK">
+      <Layer level="OVERLAY">
+        <Texture parentKey="header" inherits="DevianHeader">
+          <Anchors>
+            <Anchor point="TOPLEFT" />
+            <Anchor point="TOPRIGHT" />
+            <Size y="20" />
+          </Anchors>
+        </Texture>
         <FontString parentKey="title" font="Interface\Addons\Devian\font\SourceCodePro-Bold.ttf" wordwrap="true"
                     justifyH="LEFT"
                     indented="true">
           <Anchors>
-            <Anchor point="TOPLEFT" x="4" y="-2" />
+            <Anchor point="TOPLEFT" x="4" y="0" />
           </Anchors>
           <Size y="20" />
           <FontHeight>
@@ -200,23 +197,14 @@
           </Anchors>
         </Texture>
       </Layer>
-      <Layer level="OVERLAY">
-        <Texture name="$parentHeader" parentKey="header" inherits="DevianHeader">
-          <Anchors>
-            <Anchor point="TOPLEFT" />
-            <Anchor point="TOPRIGHT" />
-            <Size y="20" />
-          </Anchors>
-        </Texture>
-      </Layer>
     </Layers>
     <Frames>
-      <Frame name="$parentDDMenu" parentKey="menuFrame" inherits="DevianDDMenu" />
-      <Button name="$parentMenuButton" parentKey="menuButton" inherits="DevianDDButton" enableMouse="true">
+      <Button name="$parentMenuButton"  parentKey="dropmenu" inherits="DevianDDButton" enableMouse="true">
         <Anchors>
           <Anchor point="TOPRIGHT" relativePoint="TOPRIGHT" x="-4" y="0" />
         </Anchors>
       </Button>
+      <Frame name="$parentDDMenu" parentKey="menuFrame" inherits="DevianDDMenu" />
       <ScrollingMessageFrame parentKey="out" inherits="DevianBuffer" />
     </Frames>
   </Frame>
--- a/UI.lua	Sun Dec 27 03:51:17 2015 -0500
+++ b/UI.lua	Sun Dec 27 08:19:45 2015 -0500
@@ -14,7 +14,6 @@
 
 local DEVIAN_FRAME = 'DevianConsole'
 local DEVIAN_DOCK_FRAME = 'DevianDockFrame'
-local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
 
 
 local function Console_MinMax(self)
@@ -83,51 +82,6 @@
   self:SetWidth(db.width)
 end
 
--- Console frame toggler
--- @paramsig [...]
--- @param ... one or more space-seperated channel keys
-local function Console_Toggle(input)
-  local db = D.db
-  if db.workspace == 1 then
-    return D:Print(MSG_NEED_DEV_MODE)
-  end
-  local search = {}
-  local n = 0
-  if D:GetArgs(input,1) then
-    repeat
-      key, n = D:GetArgs(input,1,n)
-      if D.sig[key] then
-        table.insert(search, D.sig[key])
-      elseif D.console[key] then
-        table.insert(search, D.console[key])
-      end
-    until n == 1e9
-  else
-    search = D.console
-  end
-
-  db.enabled = (not db.enabled) and true or nil
-  for i, c in ipairs(search) do
-    --print(i,c.index)
-    if db.enabled then
-      c.enabled = true
-      c:Show()
-      if db.current_channel == c.index then
-        c:ToFront()
-      end
-      c:Save()
-    else
-      c:Hide()
-    end
-  end
-
-  if db.enabled then
-    D:Print('toggled on?')
-  else
-    D:Print('toggled off?')
-  end
-end
-
 --- Brings the console to the front.
 -- Frame method used to bring a console frame to the front of the display stack.
 local function Console_ToFront(c)
@@ -142,6 +96,8 @@
   c.out.backdrop:SetTexture(unpack(db.frontdrop))
   c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
   c.out.backdrop:SetBlendMode(db.frontblend)
+  c.dropmenu.icon:SetVertexColor(unpack(db.headerfontcolor))
+  c.title:SetTextColor(unpack(db.headerfontcolor))
   db.current_channel = c.index
 
   for _, part in pairs(c.border) do
@@ -158,6 +114,8 @@
       bc.out.backdrop:SetTexture(unpack(db.backdrop))
       bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
       bc.out.backdrop:SetBlendMode(db.backblend)
+      bc.dropmenu.icon:SetVertexColor(unpack(db.backborder))
+      bc.title:SetTextColor(unpack(db.backborder))
 
       for _, part in pairs(bc.border) do
         part:SetTexture(unpack(db.backborder))
@@ -219,7 +177,7 @@
   for k,v in pairs(vars) do
     f[k] = v
     --@debug@
-    print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v))
+    --print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v))
   end
 
   f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y)
@@ -228,12 +186,12 @@
   f.out:SetFont(db.font, db.fontsize, db.fontoutline)
   if (db.current_channel == i) then
     f.out.backdrop:SetTexture(unpack(db.frontdrop))
+    f.dropmenu.icon:SetVertexColor(unpack(db.headerfontcolor))
+    f.title:SetTextColor(unpack(db.headerfontcolor))
   else
     f.out.backdrop:SetTexture(unpack(db.backdrop))
   end
 
-
-
   f.Save = Console_Save
   f.Minimize = Console_Minimize
   f.Maximize = Console_Maximize
@@ -243,6 +201,26 @@
   f:SetScript('OnMouseDown', Console_MouseDown)
   f:SetScript('OnMouseUp', Console_MouseUp)
 
+
+  UIDropDownMenu_Initialize(f.menuFrame, function()
+    local info = { {
+        text= "Close",
+        value = "OptClose",
+        func = function ()
+          f.enabled = nil
+          f:Hide()
+          f:Save()
+        end },
+      {
+        text = "Dock",
+        value = "OptDock",
+        func = function() print('Dvn', 'docking shenanary') end }
+    }
+    for _, v in ipairs(info) do
+      UIDropDownMenu_AddButton(v)
+    end
+  end, 'MENU')
+
   if vars.minimized then
     f:Minimize()
   else
@@ -268,6 +246,8 @@
   local db = self.db
   local t_info = {}
   local channel, isNew, id, sig, t_id
+  --@debug@
+  print('setchan(0) cinfo, key', cinfo, key)--@end-debug@
   -- obtain source data
   if tonumber(key) ~= nil and  db.channels[key] then
     id = tonumber(key)
@@ -281,7 +261,7 @@
   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
@@ -299,7 +279,7 @@
   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
@@ -324,23 +304,25 @@
     end
     t_info.signature = result
     end
-    t_id = db.max_channel + 1
+    t_id = self.max_channel + 1
     t_info.index = t_id
     --@debug@
-    --print('setchan(3a) isNew, sig, t_info.signature=', 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) isNew, sig, t_info.signature=', 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
-  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@
+    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