diff Dock.lua @ 93:f6fae1a4c66c v2.2.95-rc1

- revision and simplification dock layout - fixed character-specific addon choices getting erroneously toggled The XML template was missing header information; that has been filled in, and it should be easier to catch problems arising from that area.
author Nenue
date Wed, 19 Oct 2016 16:47:38 -0400
parents 3745540e8996
children 33bc8baba858
line wrap: on
line diff
--- a/Dock.lua	Wed Aug 10 07:12:43 2016 -0400
+++ b/Dock.lua	Wed Oct 19 16:47:38 2016 -0400
@@ -8,6 +8,112 @@
 local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight =  math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight
 local db
 local print = D.print
+local DOCK_BUTTON_PADDING = 6
+
+DevianDockButtonMixin = {}
+
+--- Updates region visibility as needed
+local getFadeInArgs = function(sign, region)
+  --print('Dvn', region)
+  local db = D.db
+  local alph = region:GetAlpha()
+  local a = (db[sign..'_alpha_on'] - alph)
+  local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
+  local dur = (a / b) * db[sign..'_fade_in']
+  return dur, alph, db[sign..'_alpha_on']
+end
+
+local getFadeOutArgs = function(sign, region)
+  local db = D.db
+  local alph = region:GetAlpha()
+  local a = (alph  - db[sign..'_alpha_off'])
+  local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
+  local dur = (a / b) * db[sign..'_fade_out']
+  return dur, alph, db[sign..'_alpha_off']
+end
+
+local function queueFade (self, duration, from, to)
+  self:SetAlpha(to)
+end
+
+local numBeacons = 0
+function D:GetDockButton(console)
+  self.dock.usedButtons = self.dock.usedButtons or {}
+
+  local button = self.dock.usedButtons[console.index]
+  if not button then
+    numBeacons = numBeacons + 1
+    button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianBeacon')
+    button.color = {r = math.random(), g = math.random(), b = math.random()}
+    button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1)
+    button.console = console
+    self.dock.usedButtons[console.index] = button
+    tinsert(self.dock.buttons, button)
+  end
+  button.index = console.index
+  button.caption.name:SetText(console.signature)
+  button:SetShown(true)
+  return button
+end
+
+function DevianDockButtonMixin:OnMouseDown(button)
+  --print("click", self:GetName(), button, self.console.index)
+  if button == "LeftButton" then
+    if IsShiftKeyDown() then
+      D:Console_Toggle(self.console.index, 0)
+    else
+      if self.console.index == D.currentProfile.current_channel or (not self.console.enabled) then
+        D:Console_Toggle(self.console.index)
+        if self.console.enabled then
+          if self.console.minimized then
+            self.console:MinMax()
+          end
+          self.console:ToFront()
+        end
+      else
+        self.console:ToFront()
+      end
+    end
+  elseif button == "RightButton" then
+    self.console:MinMax()
+  end
+  self.console:Save()
+end
+function DevianDockButtonMixin:OnShow()
+  self:Update()
+end
+function DevianDockButtonMixin:OnEnter()
+end
+function DevianDockButtonMixin:Update()
+  local db = D.db
+  local isActive = (self.raised or self.selected or self.newMessage)
+
+  if (self.showName or isActive) then
+    self.caption:SetAlpha(1)
+  else
+    self.caption:SetAlpha(0.5)
+  end
+
+  if self.selected then
+    self.Background:SetColorTexture(0.4,0.4,0.4,1)
+  else
+    self.Background:SetColorTexture(0,0,0,.5)
+  end
+
+  if (not self.showName) and (not isActive) then
+    --print(self:GetName(), 'no name no active, fade out')
+    self:SetAlpha(0.5)
+  else
+    self:SetAlpha(1)
+  end
+
+  self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING)
+end
+
+function DevianDockButtonMixin:Select()
+  self.caption.pulse:Stop()
+  self:Update()
+end
 
 --- Spaces each frame evenly across the screen.
 function D:DistributeFrames() --
@@ -42,132 +148,45 @@
   end
 end
 
+function D:Dock_OnMouseWheel(delta)
+  if delta >= 1 then
+    D.dockScale = (D.dockScale or 1) - 0.1
+  else
+    D.dockScale = (D.dockScale or 1) + 0.1
+  end
+  D:UpdateDock()
+end
 
 --- Space everything and set the dock size
 function D:UpdateDock()
   local pad_offset = 12
-  local draw_offset = pad_offset
+  local drawWidth = 0
+  local lastButton
+  local numButtons = 0
+  for i, d in ipairs(self.dock.buttons) do
+    if d and d:IsShown() then
+      d:SetScale(D.dockScale or 1)
+      if lastButton then
+        d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0)
+      else
+        d:SetPoint('TOPLEFT',  DevianDock, 'TOPLEFT', pad_offset, 0)
+      end
 
-  local dockn = 1
-  for i, d in pairs(self.dock.buttons) do
-    dockn = max(i, dockn)
-  end
-  for i = 1, dockn do
-    local d = self.dock.buttons[i]
-    if d then
-      d:SetPoint('TOPLEFT',  DevianDock, 'TOPLEFT', draw_offset, 0)
-      draw_offset=  draw_offset + d:GetWidth() + pad_offset
+      drawWidth =  drawWidth + d:GetWidth() + pad_offset
+      lastButton = d
+      numButtons = numButtons + 1
+      print(numButtons)
     end
   end
-  self.dock:SetWidth(draw_offset)
+  self.numButtons = numButtons
+  self.dock:SetWidth(drawWidth)
+  self.db.dockPoint = self.db.dockPoint or 'TOP'
+  self.dock:SetPoint(self.db.dockPoint, UIParent, self.db.dockPoint, 0, 0)
 end
 
---- Updates region visibility as needed
-local getFadeInArgs = function(sign, region)
-  --print('Dvn', region)
-  local db = D.db
-  local alph = region:GetAlpha()
-  local a = (db[sign..'_alpha_on'] - alph)
-  local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
-  local dur = (a / b) * db[sign..'_fade_in']
-  return dur, alph, db[sign..'_alpha_on']
-end
-
-local getFadeOutArgs = function(sign, region)
-  local db = D.db
-  local alph = region:GetAlpha()
-  local a = (alph  - db[sign..'_alpha_off'])
-  local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
-  local dur = (a / b) * db[sign..'_fade_out']
-  return dur, alph, db[sign..'_alpha_off']
-end
-
-local function queueFade (self, duration, from, to)
-  self:SetAlpha(to)
-end
-
-function D.UpdateBeacon(beacon)
-  local db = D.db
-  local isActive = (beacon.raised or beacon.selected or beacon.newMessage)
-  if isActive then
-    --print(beacon:GetName(), 'active, fade in')
-    queueFade(beacon, getFadeInArgs('dock_button', beacon))
-  end
-
-  if beacon.showName or isActive then
-    --print(beacon:GetName(), 'show name, fade in name')
-    queueFade(beacon.caption, getFadeInArgs('dock_button', beacon.caption))
-  end
-
-  if not isActive then
-    queueFade(beacon, getFadeOutArgs('dock_button', beacon))
-  end
-
-  if (not beacon.showName) and (not isActive) then
-    --print(beacon:GetName(), 'no name no active, fade out')
-    queueFade(beacon.caption,getFadeOutArgs('dock_button', beacon.caption))
-  end
-end
 
 local function FrameFade(frame)
   if not D.fader then
     D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn')
   end
-end
-
---- Dock interaction framescript
-function D.DockHighlight(beacon)
-  db = D.db
-  local self = D.dock
-  local mouseOverDock = false
-  if self:IsMouseOver() then
-    mouseOverDock = true
-  end
-
-  if beacon then
-    --print(beacon:GetName(), ' highlighter got beacon')
-    mouseOverDock = true
-    if not beacon.raised then
-      --print(beacon:GetName(), '  beacon not raised')
-      beacon.raised = true
-      D.UpdateBeacon(beacon)
-
-      -- IsMouseOver can still return false during its frame's OnEnter
-      beacon.inc = 0
-      beacon:SetScript('OnUpdate', function(self)
-        if not self:IsMouseOver() then
-          self.inc = self.inc + 1
-          --print(self:GetName(),self.inc)
-          if self.inc > 10 then
-          --print(self:GetName(), 'lost mouseover, terminating OnUpdate')
-          self.raised = nil
-          D.UpdateBeacon(self)
-          self:SetScript('OnUpdate', nil)
-            end
-        end
-      end)
-    end
-  elseif beacon.raised and beacon.index ~= db.current_channel then
-    beacon.raised = nil
-    D.UpdateBeacon(beacon)
-    --beacon:SetScript('OnUpdate', nil)
-  end
-
-  if mouseOverDock then
-    -- Raise it up
-    if not self.raised then
-
-      self.raised = true
-      queueFade(self, getFadeInArgs('dock', self))
-    end
-  elseif  self.raised then
-    -- Drop it down
-    self.raised = nil
-    queueFade(self, getFadeOutArgs('dock', self))
-    for k, v in pairs(self.buttons) do
-      v.raised = nil
-      D.UpdateBeacon(v)
-    end
-  end
-
 end
\ No newline at end of file