changeset 1:cd7d06bcd98d

KeyBinds: set hotkey text for blizzard action buttons UnitFrame: prototype templates for the majority of units
author Nenue
date Tue, 21 Jun 2016 04:47:52 -0400
parents 69e828f4238a
children f7a0898d293c
files SkeletonKey/KeyBinds.lua SkeletonKey/KeyBinds.xml SkeletonKey/SkeletonKey.toc SkeletonStats/DamageMeter.lua SkeletonStats/DamageMeter.xml SkeletonUnit/UnitFrame.lua
diffstat 6 files changed, 264 insertions(+), 135 deletions(-) [+]
line wrap: on
line diff
--- a/SkeletonKey/KeyBinds.lua	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonKey/KeyBinds.lua	Tue Jun 21 04:47:52 2016 -0400
@@ -14,9 +14,10 @@
 --   .profile(name)                         set profile character
 --   .loadbinds(bindings)                   walk table with SetBinding()
 
+local KT = LibKT.register(KeyBinder)
 local kb = KeyBinder
-local KT = select(2,...)
-KT.register(KeyBinder)
+local db
+
 local MIN_BIND_SLOTS = 32
 local BINDS_PER_ROW = 8
 local KEY_BUTTON_SIZE = 40
@@ -25,8 +26,7 @@
 local TAB_SPACING = 2
 local BUTTON_SPACING = 4
 local BUTTON_PADDING = 12
-local HEADER_OFFSET
-local FOOTER_OFFSET
+local HEADER_OFFSET, FOOTER_OFFSET
 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544;
 local BINDING_TYPE_SPECIALIZATION = 3
 local BINDING_TYPE_CHARACTER = 2
@@ -81,19 +81,14 @@
 local BORDER_ASSIGNED = {0.5,0.5,0.5,1 }
 local BORDER_PENDING = {1,0.5,0,1 }
 
-
-
-local bindMode = 3 -- not to be confused with db.bindMode which is boolean
+local bindMode = 3
 local bindHeader = ''
 local specHeader, specTexture, characterHeader = 'SPEC_NAME', 'Interface\\ICONS\\INV_Misc_QuestionMark', 'PLAYER_NAME'
+local numButtons = BINDS_PER_ROW * 4
 local bindsCommitted = true
 
-local profile
-local character
-local specialization
-local global
+local profile, character, specialization, global
 local priority = {}
-local numButtons = BINDS_PER_ROW * 4
 local buttons = {}
 local reverts = {}
 local KeyButton = {}  -- collection of KeyButton template handlers
@@ -508,13 +503,13 @@
 
 --- Invokes the KeyBinder frame (from the /kb function or some other source)
 kb.ui = function()
-  if not KT.db.bindMode then
+  if not db.showUI then
     return
   end
 
   if not kb:IsVisible() then
     kb:Show()
-    KT.db.bindMode = true
+    db.showUI = true
   end
 
   if not kb.loaded then
@@ -583,30 +578,50 @@
 end
 
 local ACTION_BARS = {
-  'MultiBarBottomLeftButton',
-  'MultiBarBottomRighttButton',
-  'MultiBarLeftButton',
-  'MultiBarRightButton',
-  'ActionButton'
+  {'ActionButton', 0},
+  {'MultiBarLeftButton', 24},
+  {'MultiBarRightButton',  36},
+  {'MultiBarBottomRighttButton', 48},
+  {'MultiBarBottomLeftButton', 60},
 }
-kb.HotKeyText = function ()
-  for _, prefix in ipairs(ACTION_BARS) do
-    for i = 1,12 do
-      local button = _G[prefix .. i]
-      if button and button.action then
-        local type, id, subType, subID = GetActionInfo(button.action)
-        if type == 'spell' then
-          local name = GetSpellInfo(id)
-          local bind, bind2 = GetBindingKey('SPELL '..name)
-          if bind or bind2 then
-            --print('SPELL '..name, GetBindingKey('SPELL '..name))
-            button.HotKey:SetText(BindingString(bind))
-            button.HotKey:Show()
-          end
-        end
-      end
+kb.HotKeyText = function (slot)
+  local i, offset = 0, 0
+  local actionbar
+
+  -- figure out which bar the slot belongs to
+  for i, bar in ipairs(ACTION_BARS) do
+    actionbar, offset = unpack(ACTION_BARS[i])
+    if bar[2] > slot then
+      break
     end
   end
+  local button = _G[actionbar .. (slot - offset)]
+
+  if not button then
+    return
+  end
+
+  local type, id, subType, subID = GetActionInfo(slot)
+
+  if not type then
+    return
+  end
+
+  local bind, command
+  if type == 'spell' then
+    local name = GetSpellInfo(id)
+    command = 'SPELL '..name
+  elseif type == 'macro' then
+    command = 'MACRO ' .. id
+  else
+      return
+  end
+  bind = GetBindingKey(command)
+  print(slot, bind, '->', command)
+  if bind then
+    button.HotKey:SetText(BindingString(bind))
+    button.HotKey:Show()
+  end
 end
 
 kb.InitProfile = function(profile)
@@ -629,23 +644,22 @@
 
 --- Gives us the profile structure to work with while instating data
 kb.profile = function(name)
-  KT.db = KT.db or {}
-  global = kb.InitProfile(KT.db)
+  global = kb.InitProfile(db)
   profile = global
   local subtitle
   if name then
-    KT.db[name] = KT.db[name] or {}
-    KT.db[name] = kb.InitProfile(KT.db[name])
-    character = KT.db[name]
+    db[name] = db[name] or {}
+    db[name] = kb.InitProfile(db[name])
+    character = db[name]
     local spec = GetSpecialization()
     if spec then
-      KT.db[name][spec] = KT.db[name][spec] or {}
-      profile = kb.InitProfile(KT.db[name][spec])
+      db[name][spec] = db[name][spec] or {}
+      profile = kb.InitProfile(db[name][spec])
       bindMode = BINDING_TYPE_SPECIALIZATION
       subtitle = select(2,GetSpecializationInfo(spec))
-      specialization = KT.db[name][spec]
+      specialization = db[name][spec]
     else
-      profile = kb.InitProfile(KT.db[name])
+      profile = kb.InitProfile(db[name])
       bindMode = BINDING_TYPE_CHARACTER
       subtitle = name
       specialization = character
@@ -655,15 +669,15 @@
 
 
 
-  if not KT.db.bindsPage then
-    KT.db.bindsPage = bindMode
+  if not db.bindsPage then
+    db.bindsPage = bindMode
   end
-  bindMode = KT.db.bindsPage
+  bindMode = db.bindsPage
 
 
   if not BINDING_MODE[bindMode] then
     bindMode = 3
-    KT.db.bindsPage = 3
+    db.bindsPage = 3
     print('overriding', bindMode)
   end
 
@@ -682,7 +696,7 @@
 kb.SelectTab = function(self)
   bindMode = self:GetID()
   profile = priority[self:GetID()]
-  KT.db.bindsPage = self:GetID()
+  db.bindsPage = self:GetID()
   kb.ui()
 end
 kb.save = function()
@@ -711,6 +725,8 @@
 
 --- Get started
 kb.variables = function()
+  SkeletonKeyDB = SkeletonKeyDB or {}
+  db = SkeletonKeyDB
   kb.profile(GetUnitName('player', true))
   for i = 1, 3 do
     for attribute, data in pairs(priority[i].macros) do
@@ -729,48 +745,46 @@
 end
 
 kb.close = function()
-  KT.db.bindMode = false
+  db.showUI = false
   kb:Hide()
 end
 
 kb.PLAYER_REGEN_DISABLED = function()
-  if KT.db.bindMode then
-
+  if db.showUI then
     kb:Hide()
   end
 end
 
 kb.PLAYER_REGEN_ENABLED = function()
-  if KT.db.bindMode then
+  if db.showUI then
     kb.ui()
   end
 end
 --- Refresh buttons if macros are updated
 kb.UPDATE_BINDINGS = function()
-  if KT.db.bindMode then
+  for i = 1, 120 do
+    print(i)
+    kb.HotKeyText(i)
+  end
+  if db.showUI then
     kb.ui()
   end
-  kb.HotKeyText()
 end
 
-kb.ACTIONBAR_SLOT_CHANGED = function()
-  kb.HotKeyText()
+kb.ACTIONBAR_SLOT_CHANGED = function(self, event, slot)
+  kb.HotKeyText(slot)
 end
 
-
-
 kb.UPDATE_MACROS = kb.UPDATE_BINDINGS
-
-
 SLASH_KB1 = "/kb"
-SlashCmdList.KB = function()
-  if KT.db.bindMode then
-    KT.db.bindMode = false
+SlashCmdList.KB = function(self, input)
+  if db.showUI then
+    db.showUI = false
     print('|cFFFFFF00KeyBinds|r trace, |cFFFF0000OFF|r.')
     kb:Hide()
   else
-    KT.db.bindMode = true
+    db.showUI = true
     print('|cFFFFFF00KeyBinds|r trace, |cFF00FF00ON|r.')
     kb.ui()
   end
-end
\ No newline at end of file
+end
--- a/SkeletonKey/KeyBinds.xml	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonKey/KeyBinds.xml	Tue Jun 21 04:47:52 2016 -0400
@@ -51,7 +51,7 @@
     </HighlightTexture>
   </CheckButton>
 
-  <Frame name="KeyBinder" parent="UIParent" inherits="KTDebugTemplate" hidden="true" clampToScreen="true" movable="true" enableMouse="true">
+  <Frame name="KeyBinder" parent="UIParent" hidden="true" clampToScreen="true" movable="true" enableMouse="true">
     <Scripts>
       <OnLoad>
         self:RegisterForDrag('LeftButton')
--- a/SkeletonKey/SkeletonKey.toc	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonKey/SkeletonKey.toc	Tue Jun 21 04:47:52 2016 -0400
@@ -1,14 +1,14 @@
 ## Interface: 70000
-## Title: KTest
-## Notes: tools and things
+## Title: SkeletonKey
+## Notes: Key Bindings for dinosaurs
 ## Author: Krakyn
 ## Version: 1.0-@project-revision@
-## SavedVariables: KTestDB
+## SavedVariables: SkeletonKeyDB
 ## X-Category: Interface Enhancements
 ## DefaultState: Enabled
 ## LoadOnDemand: 0
+## OptionalDeps: libKT
 
 libKT-1.0\libKT-1.0.xml
-
 KeyBinds.xml
 KeyBinds.lua
\ No newline at end of file
--- a/SkeletonStats/DamageMeter.lua	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonStats/DamageMeter.lua	Tue Jun 21 04:47:52 2016 -0400
@@ -10,10 +10,9 @@
 --   .showbar (bar )     -- toggle row
 --   .hidebar ( bar )    --
 --   .ui ()              -- update chart
-local KT = select(2,...)
+local KT = LibKT.register(DamageMeter)
 local dm = DamageMeter
-KT.register(dm)
-
+local db
 local segments = {}
 local actors = {}
 local ordered = {}
@@ -33,11 +32,10 @@
 
 dm.init = function()
   dm:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
+  dm:RegisterEvent('PLAYER_REGEN_DISABLED')
   dm:RegisterEvent('ENCOUNTER_START')
   dm.bars = dm.bars or {}
   dm.headings = dm.headings or {}
-
-  sortType = SortByDamage
 end
 
 dm.ENCOUNTER_START = function()
@@ -45,13 +43,17 @@
 end
 
 dm.variables = function()
-  KT.db.segments = KT.db.segments or {}
-  KT.db.currentSegment = KT.db.currentSegment or 0
-  KT.db.actors = KT.db.actors or {}
-  actors = KT.db.actors
-  segments = KT.db.segments
-  viewPos = KT.db.currentSegment
+  SkeletonStatsDB = SkeletonStatsDB or {}
+  db = SkeletonStatsDB
+  db.segments = db.segments or {}
+  db.currentSegment = db.currentSegment or 0
+  db.actors = db.actors or {}
+  db.viewType = db.viewType or 'damageDone'
 
+    actors = db.actors
+    segments = db.segments
+    viewPos = db.currentSegment
+    viewType = prototypes[viewType] and viewType or 'damageDone'
 
   dm.handler(viewType)
 
@@ -62,7 +64,7 @@
     view = segments[viewPos]
     print('Using segment #', viewPos)
   end
-  KT.db.currentSegment = viewPos
+  db.currentSegment = viewPos
 
   dm.ui()
 end
@@ -73,12 +75,12 @@
 end
 
 dm.new = function()
-  segmentUID = (KT.db.segUID or 0) + 1
-  KT.db.segUID = segmentUID
+  segmentUID = (db.segUID or 0) + 1
+  db.segUID = segmentUID
   view = {}
   viewPos = #segments+1
   segments[viewPos] = view
-  KT.db.currentSegment = viewPos
+  db.currentSegment = viewPos
   print('Starting new segment #', viewPos)
   return viewPos
 end
@@ -122,6 +124,10 @@
   header = 'Damage Done',
 }
 
+dm.PLAYER_REGEN_DISABLED = function()
+  dm.new()
+end
+
 dm.COMBAT_LOG_EVENT_UNFILTERED = function(self, event, timeStemp, subEvent, u1, ...)
   local sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags = ...
 
--- a/SkeletonStats/DamageMeter.xml	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonStats/DamageMeter.xml	Tue Jun 21 04:47:52 2016 -0400
@@ -2,10 +2,10 @@
 ..\FrameXML\UI.xsd">
 
 
-  <Frame name="DamageMeter" parent="UIParent" movable="true" enableMouse="true" inherits="KTDebugTemplate">
+  <Frame name="DamageMeter" parent="UIParent" movable="true" enableMouse="true">
     <Size x="180" y="260" />
     <Anchors>
-      <Anchor point="LEFT" />
+      <Anchor point="TOPLEFT" relativePoint="LEFT" x="25" y="110" />
     </Anchors>
     <Scripts>
       <OnLoad>
--- a/SkeletonUnit/UnitFrame.lua	Mon Jun 20 06:35:11 2016 -0400
+++ b/SkeletonUnit/UnitFrame.lua	Tue Jun 21 04:47:52 2016 -0400
@@ -6,46 +6,145 @@
 -- Created: 6/16/2016 3:46 AM
 --------------------------------------------
 
-local KT = select(2,...)
+local KT = LibKT.register(SkeletonUnits)
 local PLAYER_NAMEPLATE
 local PLAYER_WIDTH = 220
 local BUFF_SIZE = 24
+local sk = SkeletonUnits
+local player = KTPlayerFrame
+local prototypes = {
+  player = {},
+  target = {},
+  pet = {},
+  focus = {}
+}
+local units = {}
+local buttons = {}
+local params = {
+  player = {width = 220, height = 30},
+  pet = {height = 25}
+}
+sk.handler = sk -- so sk.event can work
 
 
-KT.register(KTplayerFrame)
-KTplayerFrame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player")
-KTplayerFrame:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
-KTplayerFrame:RegisterUnitEvent("UNIT_AURA", 'player')
-KTplayerFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
-KTplayerFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
-KTplayerFrame.event = function(self)
-  --  print(C_NamePlate.GetNamePlateForUnit('player'))
+local UpdateUnitAnchor = function(self)
+  self.nameplate = C_NamePlate.GetNamePlateForUnit(self.unit)
+  if self.nameplate and self.nameplate.namePlateUnitToken then
+    self:ClearAllPoints()
+    self:SetPoint('TOP', self.nameplate, 'BOTTOM', 0, 0)
+    print('snapping', self.unit, 'to', self.nameplate.namePlateUnitToken)
+  else
+    self:ClearAllPoints()
+    self:SetPoint(unpack(self.anchorPoint))
+  end
 end
 
-local buttons = {}
 local SetupButton = function(self, unit, index)
-  if not buttons[index] then
-    buttons[index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton')
-    buttons[index]:SetSize(BUFF_SIZE, BUFF_SIZE)
-    buttons[index].cooldown:SetHideCountdownNumbers(true)
+  if not buttons[unit][index] then
+    buttons[unit][index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton')
+    buttons[unit][index]:SetSize(BUFF_SIZE, BUFF_SIZE)
+    buttons[unit][index].cooldown:SetHideCountdownNumbers(true)
 
   end
-  return buttons[index]
+  return buttons[unit][index]
 end
 
-KTplayerFrame.UNIT_AURA = function(self, event, unit)
+sk.init = function()
+  for unit, handler in pairs(prototypes) do
+    if not _G['KT'..unit..'Frame'] then
+      CreateFrame('Frame', 'KT'.. unit .. 'Frame', sk)
+    end
+    local frame = _G['KT'..unit..'Frame']
+    frame.unit = unit
+    frame.anchorPoint = {frame:GetPoint(1)}
+    frame.handler = handler
+    if handler.init then
+      handler.init(frame, unit)
+    end
+    buttons[unit] = {}
+    units[unit] = frame
+  end
+
+  sk:RegisterEvent('PLAYER_TARGET_CHANGED')
+  sk:RegisterUnitEvent("UNIT_AURA")
+end
+sk.variables = function()
+  for unit, frame in pairs(units) do
+    if frame.handler.variables then
+      frame.handler.variables(frame, unit)
+    end
+    local width = params.player.width
+    local height = params.player.height
+    if params[unit] then
+      if params[unit].width then
+      width = params[unit].width
+      end
+      if params[unit].height then
+        height = params[unit].height
+      end
+    end
+
+    frame:SetWidth(width)
+    frame:SetHeight(height)
+  end
+end
+
+sk.event = function(self, event, ...)
+  if self.handler[event] then
+    self.handler[event](self, event, ...)
+  end
+end
+
+sk.PLAYER_TARGET_CHANGED = function()
+  prototypes.player.refresh(units.target)
+end
+
+prototypes.player.init = function(self)
+  self:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", self.unit)
+  self:RegisterUnitEvent("UNIT_POWER_FREQUENT", self.unit)
+  self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
+  self:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
+  self:RegisterEvent("UNIT_TARGET")
+  self:SetScript('OnEvent', sk.event)
+end
+
+--- Runs once
+prototypes.player.variables = function(self)
+  self.handler.refresh(self)
+end
+
+--- Runs when event handler decides so
+prototypes.player.refresh = function(self)
+  if not UnitExists(self.unit) then
+    self:Hide()
+    return
+  end
+
+  local class, classFile = UnitClass(self.unit)
+  if classFile then
+    self.healthbar:SetColorTexture(RAID_CLASS_COLORS[classFile].r, RAID_CLASS_COLORS[classFile].g, RAID_CLASS_COLORS[classFile].b)
+  end
+
+  self.handler.UNIT_HEALTH_FREQUENT(self)
+  self.handler.UNIT_POWER_FREQUENT(self)
+end
+
+sk.UNIT_AURA = function(self, event, unit)
+  if not units[unit] then return end
+
   local buffOffset = 0
+  local buttons = buttons[unit]
   for i = 1, 16 do
-    --UnitAura()
-    local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, nil, 'HELPFUL')
+
+    local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, 'HARMFUL')
     if aura then
-      local button = SetupButton(self, unit, i)
+      local button = SetupButton(units[unit], unit, i)
 
       button.icon:SetTexture(texture)
       button.cooldown:SetCooldown(expires - duration, duration)
       button.cooldown:Show()
       button.count:SetText(count > 0 and count or nil)
-      button:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', buffOffset* BUFF_SIZE, 2)
+      button:SetPoint('BOTTOMLEFT', units[unit], 'TOPLEFT', buffOffset* BUFF_SIZE, 2)
       button:Show()
       buffOffset = buffOffset + 1
     else
@@ -56,35 +155,45 @@
   end
 end
 
-KTplayerFrame.NAME_PLATE_UNIT_ADDED = function(self, event, unit)
-  print('|cFF008800'..unit)
-  if UnitIsUnit('player', unit) then
-    PLAYER_NAMEPLATE = unit
-    self:ClearAllPoints()
-    self:SetPoint('TOP', C_NamePlate.GetNamePlateForUnit(unit), 'BOTTOM', 0, 0)
+prototypes.player.NAME_PLATE_UNIT_ADDED = function(self, event, nameplate)
+    UpdateUnitAnchor(self)
+end
+prototypes.player.NAME_PLATE_UNIT_REMOVED = function(self, event, nameplate)
+    UpdateUnitAnchor(self)
+end
+
+prototypes.player.UNIT_HEALTH_FREQUENT = function(self, ...)
+  if UnitHealthMax(self.unit) > 0 then
+    self.healthbar:SetWidth(PLAYER_WIDTH * UnitHealth(self.unit) / UnitHealthMax(self.unit))
+    self.healthtext:SetText(UnitHealth(self.unit))
+  else
+    self.healthbar:SetWidth(PLAYER_WIDTH)
+    self.healthtext:SetText(nil)
   end
+  return true
 end
-KTplayerFrame.NAME_PLATE_UNIT_REMOVED = function(self, event, unit)
-  if unit == PLAYER_NAMEPLATE then
-    PLAYER_NAMEPLATE = nil
-    self:ClearAllPoints()
-    self:SetPoint('LEFT', UIParent, 'LEFT', 25, 0)
+
+prototypes.player.UNIT_POWER_FREQUENT = function(self)
+  if UnitPowerMax(self.unit) > 0 then
+    self.powerbar:SetWidth(PLAYER_WIDTH * UnitPower(self.unit) / UnitPowerMax(self.unit))
+    self.powertext:SetText(UnitPower(self.unit))
+  else
+    self.powerbar:Hide()
+    self.powertext:SetText(nil)
+  end
+  return true
+end
+
+
+prototypes.player.UNIT_TARGET = function(self, ...)
+  if not UnitExists(self.unit) then
+    self:Hide()
+  else
+    self:Show()
+    self.handler.refresh(self)
+    UpdateUnitAnchor(self)
   end
 end
 
-KTplayerFrame.UNIT_HEALTH_FREQUENT = function(self, ...)
-  --print(UnitHealth('player') / UnitHealthMax('player'))
-  self.healthbar:SetWidth(PLAYER_WIDTH * UnitHealth('player') / UnitHealthMax('player'))
-  return true
-end
-
-KTplayerFrame.UNIT_POWER_FREQUENT = function(self)
-  self.powerbar:SetWidth(PLAYER_WIDTH * UnitPower('player') / UnitPowerMax('player'))
-  return true
-end
-
-KTplayerFrame:SetWidth(PLAYER_WIDTH)
-KTplayerFrame.variables = function()
-  KTplayerFrame:UNIT_HEALTH_FREQUENT()
-  KTplayerFrame:UNIT_POWER_FREQUENT()
-end
\ No newline at end of file
+prototypes.pet = prototypes.player
+prototypes.target = prototypes.player
\ No newline at end of file