changeset 47:eb7544afd77a

dock frame implementation fixes to /dvc command
author Nenue
date Mon, 04 Jan 2016 05:42:44 -0500
parents dcc57a7cabc9
children 2bf7eb1844cb
files Devian.lua Devian.xml Dock.lua UI.lua
diffstat 4 files changed, 281 insertions(+), 72 deletions(-) [+]
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
--- a/Devian.xml	Sun Jan 03 15:49:35 2016 -0500
+++ b/Devian.xml	Mon Jan 04 05:42:44 2016 -0500
@@ -25,16 +25,12 @@
     </Gradient>
   </Texture>
 
-  <Button virtual="true" name="DevianDDButton" alphaMode="BLEND">
-    <Scripts>
-      <OnClick>
-        ToggleDropDownMenu(1, nil, self:GetParent().menuFrame, self, 0, 0);
-      </OnClick>
-    </Scripts>
+
+  <Button virtual="true" name="DevianButton" alphaMode="BLEND">
     <Size x="32" y="16" />
     <Layers>
       <Layer level="ARTWORK">
-        <Texture parentKey="icon" file="Interface\Addons\Devian\menu-button.blp" setAllPoints="true" alphaMode="ADD">
+        <Texture name="$parentIcon" 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>
@@ -42,7 +38,20 @@
     </Layers>
   </Button>
 
+  <Button virtual="true" name="DevianDDButton" inherits="DevianButton" alphaMode="BLEND">
+    <Scripts>
+      <OnClick>
+        ToggleDropDownMenu(1, nil, self:GetParent().menuFrame, self, 0, 0);
+      </OnClick>
+    </Scripts>
+  </Button>
 
+  <Font name="DevianText" font="Interface\Addons\Devian\font\SourceCodePro-Regular.ttf" outline="NORMAL" virtual="true">
+    <FontHeight>
+      <AbsValue val="13" />
+    </FontHeight>
+    <Color r="1" g="1" b="1" a="1" />
+  </Font>
 
   <Frame name="DevianDDMenu" virtual="true" inherits="UIDropDownMenuTemplate" id="1">
     <Scripts>
@@ -62,7 +71,7 @@
       <Anchor point="TOPLEFT" y="-20" />
       <Anchor point="BOTTOMRIGHT" />
     </Anchors>
-    <FontString  font="Interface\Addons\Devian\font\SourceCodePro-Regular.ttf" wordwrap="true"
+    <FontString inherits="DevianFont" wordwrap="true"
                  justifyH="LEFT"
                  indented="true"
                  setAllPoints="true">
@@ -211,28 +220,115 @@
 
   <Frame
       name="DevianDock"
-      parent="UIParent" hidden="true">
+      parent="UIParent"
+      enableMouse="true"
+      alpha="0.1"
+      hidden="true"
+      frameStrata="LOW">
+    <Scripts>
+      <OnEnter>
+        Devian.DockHighlight(self)
+      </OnEnter>
+      <OnLeave>
+        Devian.DockHighlight(self)
+      </OnLeave>
+      <OnMouseDown>
+        print('click', button, 'down')
+      </OnMouseDown>
+      <OnMouseUp>
+        print('click', button, 'up')
+      </OnMouseUp>
+    </Scripts>
     <Anchors>
-      <Anchor point="TOP" relativePoint="TOP" />
+      <Anchor point="TOP" relativePoint="TOP" x="0" y="1" />
     </Anchors>
-    <Size x="400" y="40" />
+    <Size x="32" y="20" />
     <Layers>
       <Layer level="ARTWORK">
-        <Texture name="$parentBar" setAllPoints="true" parentKey="bar" alphaMode="MOD">
+        <Texture name="$parentBar" parent="DevianDock" setAllPoints="true" parentKey="bar" alphaMode="BLEND">
           <Color r="1" g="1" b="1" a="1" />
           <Gradient orientation="VERTICAL">
             <MaxColor r="0" g="0" b="0" a="1" />
-            <MinColor r="1" g="1" b="1" a="1" />
+            <MinColor r="0" g="0" b="0" a="0" />
           </Gradient>
         </Texture>
 
       </Layer>
       <Layer level="OVERLAY">
 
-        <Button name="$parentMenuButton"  parentKey="dropmenu" inherits="DevianDDButton" enableMouse="true">
-
-        </Button>
       </Layer>
     </Layers>
   </Frame>
+
+  <Button name="DevianBeacon" hidden="true" inherits="DevianButton" virtual="true" enableMouse="true" alpha="1" frameStrata="MEDIUM">
+    <Size x="64" y="32" />
+    <TexCoords top="0" left="0" bottom="1" right="1" />
+
+    <Scripts>
+      <OnShow>
+        if self.console.index ~= DevianDB.current_channel then
+          UIFrameFadeIn(self,DevianDB.dock_onshow_fade_time, DevianDB.dock_onshow_fade_from, DevianDB.dock_onshow_fade_to)
+          UIFrameFadeIn(self.caption,DevianDB.dock_onshow_fade_time, DevianDB.dock_onshow_fade_from, 0)
+        end
+      </OnShow>
+      <OnMouseDown>
+        --print("click", self:GetName(), button, self.console.index)
+        if button == "LeftButton" then
+          if IsShiftKeyDown() then
+            Devian:Console_Toggle(self.console.index, 0)
+          else
+            Devian:Console_Toggle(self.console.index)
+            if self.console.enabled then
+              if self.console.minimized then
+                self.console:MinMax()
+              end
+              self.console:ToFront()
+            else
+            end
+          end
+        elseif button == "RightButton" then
+          self.console:MinMax()
+        end
+        self.console:Save()
+      </OnMouseDown>
+      <OnEnter>
+        Devian.DockHighlight(self)
+      </OnEnter>
+      <OnLeave>
+        Devian.DockHighlight(self)
+      </OnLeave>
+    </Scripts>
+    <Layers>
+      <Layer level="OVERLAY">
+      </Layer>
+    </Layers>
+    <Frames>
+      <Frame name="$parentText" parentKey="caption" alpha="0" blendMode="BLEND">
+        <Size x="200" y="30" />
+        <Anchors>
+          <Anchor point="BOTTOM" relativePoint="BOTTOM" x="0" y="0" />
+        </Anchors>
+        <Layers>
+          <Layer level="OVERLAY">
+            <FontString text="Test String" inherits="DevianText" parentKey="name" setAllPoints="true">
+              <Color r="1" g="1" b="1" a="1" />
+              <Shadow>
+                <Color r="0" g="0" b="0" a="1" />
+                <Offset x="0" y="-2" />
+              </Shadow>
+              <Animations>
+                <AnimationGroup>
+                  <Scale scaleX="1.4" scaleY="1.4" looping="NONE">
+                    <Origin point="CENTER" x="0" y="0" />
+
+                  </Scale>
+                </AnimationGroup>
+              </Animations>
+            </FontString>
+          </Layer>
+        </Layers>
+      </Frame>
+    </Frames>
+  </Button>
+
 </Ui>
\ No newline at end of file
--- a/Dock.lua	Sun Jan 03 15:49:35 2016 -0500
+++ b/Dock.lua	Mon Jan 04 05:42:44 2016 -0500
@@ -7,7 +7,7 @@
 
 local D = LibStub("AceAddon-3.0"):GetAddon("Devian")
 local _G = _G
-local db = DevianDB
+local db
 
 local function Dock_MenuClick() end
 
@@ -110,17 +110,73 @@
 
 ---
 function D:UpdateDock()
-  local num_active, num_inactive = 0, 0
+  local pad_offset = 12
+  local draw_offset = pad_offset
+  for i = 1, #self.dock.buttons do
+    local d = self.dock.buttons[i]
+    d:SetPoint('TOPLEFT',  DevianDock, 'TOPLEFT', draw_offset, 0)
+    draw_offset=  draw_offset + d:GetWidth() + pad_offset
+  end
 
-  for id, ch in pairs(self.console) do
-    if not self.dock[id] then
-      self.dock[id] = self.dock:CreateTexture('DockButton'..id, 'OVERLAY')
+  self.dock:SetWidth(draw_offset)
+end
+
+--- Dock interactions
+function D.DockHighlight(beacon)
+  db = D.db
+  print('Dvn', 'dock mouse event', beacon)
+  local self = D.dock
+  local mouseOverDock
+    --for i, b in pairs(self.buttons) do
+      --print('polling', i, b:GetName())
+  if self:IsMouseOver() then
+    mouseOverDock = true
+  end
+
+
+  if beacon and beacon:IsMouseOver() then
+    mouseOverDock = true
+    --print('mouse is over', i, b:GetName())
+
+    if not beacon.raised then
+      beacon.raised = true
+      local a = (db.dock_button_alpha_on - self:GetAlpha())
+      local b = (db.dock_button_alpha_on-db.dock_button_alpha_off)
+      local dur = (a / b) * db.dock_button_fade_in
+      print(a, b, db.dock_button_fade_in, dur)
+      UIFrameFadeIn(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_on)
+      UIFrameFadeIn(beacon.caption, dur,beacon:GetAlpha(),1)
     end
+  elseif beacon.raised and beacon.index ~= db.current_channel then
+    beacon.raised = nil
+    local a = (self:GetAlpha() - db.dock_button_alpha_off)
+    local b = (db.dock_button_alpha_on-db.dock_button_alpha_off)
+    local dur = (a / b) * db.dock_button_fade_out
+    print(a, b, db.dock_button_fade_in, dur)
+    UIFrameFadeOut(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_off)
+    UIFrameFadeOut(beacon.caption, dur,beacon:GetAlpha(),0)
+  end
 
-    if ch.enabled then
-      num_active = num_active + 1
-    else
-      num_inactive = num_inactive + 1
+      --end
+    --end
+  if mouseOverDock then
+    if not self.raised then
+    print('rising')
+    self.raised = true
+    local a = (db.dock_alpha_on - self:GetAlpha())
+    local b = (db.dock_alpha_on-db.dock_alpha_off)
+    local dur = (a / b) * db.dock_fade_in
+    print(a, b, db.dock_fade_in, dur)
+    UIFrameFadeIn(self, dur,self:GetAlpha(),db.dock_alpha_on)
     end
+  elseif  self.raised then
+    print('dropping')
+    self.raised = nil
+    local a = (self:GetAlpha() - db.dock_alpha_off)
+    local b = (db.dock_alpha_on-db.dock_alpha_off)
+    local dur = (a / b) * db.dock_fade_out
+    print(a, b, db.dock_fade_in, dur)
+    UIFrameFadeOut(self, dur,self:GetAlpha(),db.dock_alpha_off)
   end
+
 end
\ No newline at end of file
--- a/UI.lua	Sun Jan 03 15:49:35 2016 -0500
+++ b/UI.lua	Mon Jan 04 05:42:44 2016 -0500
@@ -13,7 +13,7 @@
 
 
 local DEVIAN_FRAME = 'DevianConsole'
-local DEVIAN_DOCK_FRAME = 'DevianDockFrame'
+local DEVIAN_DOCK_FRAME = 'DevianDock'
 
 
 local function Console_MinMax(self)
@@ -164,11 +164,8 @@
     vars = D.channels[i] and D.channels[i] or D.channels[db.primary_channel]
   end
   local f
-  if vars.docked then
-    f = CreateFrame('Frame','DevianDockFrame' .. i, DEVIAN_DOCK_FRAME)
-  else
-    f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME)
-  end
+  f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME)
+
   --@debug@
   --print(f:GetName())
 
@@ -221,6 +218,13 @@
     end
   end, 'MENU')
 
+  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
+  D.dock.buttons[i].index = i
+  D.dock.buttons[i].caption.name:SetText(vars.signature)
+  D.dock.buttons[i]:Show()
+
   if vars.minimized then
     f:Minimize()
   else