Quantcast

Minor bug fixes, Armor Module

MilleXIV [08-16-16 - 21:55]
Minor bug fixes, Armor Module
Filename
locales/enUS.lua
modules/armor.lua
modules/clock.lua
modules/load_modules.xml
modules/micromenu.lua
modules/old/armor.lua
diff --git a/locales/enUS.lua b/locales/enUS.lua
index 746923b..3602156 100644
--- a/locales/enUS.lua
+++ b/locales/enUS.lua
@@ -48,6 +48,9 @@ L['No Tag'] = true;
 L['Level'] = true;

 L['Armor'] = true;
+L['Always Show Item Level'] = true;
+L['Minimum Durability to Become Active'] = true;
+L['Maximum Durability to Show Item Level'] = true;

 L['Clock'] = true;
 L['Time Format'] = true;
diff --git a/modules/armor.lua b/modules/armor.lua
index e211304..8e33bbd 100644
--- a/modules/armor.lua
+++ b/modules/armor.lua
@@ -1,72 +1,214 @@
-local addon, ns = ...
-local cfg = ns.cfg
-local unpack = unpack
---------------------------------------------------------------
-if not cfg.armor.show then return end
-
-local armorFrame = CreateFrame("BUTTON",nil, cfg.SXframe)
-armorFrame:SetPoint("LEFT",590,0)
-armorFrame:EnableMouse(true)
-armorFrame:RegisterForClicks("AnyUp")
-
-local armorIcon = armorFrame:CreateTexture(nil,"OVERLAY",nil,7)
-armorIcon:SetPoint("LEFT")
-armorIcon:SetTexture(cfg.mediaFolder.."datatexts\\repair")
-armorIcon:SetVertexColor(unpack(cfg.color.inactive))
-
-local armorText = armorFrame:CreateFontString(nil, "OVERLAY")
-armorText:SetFont(cfg.text.font, cfg.text.normalFontSize)
-armorText:SetPoint("RIGHT", armorFrame,2,0)
-armorText:SetTextColor(unpack(cfg.color.normal))
-
-armorFrame:SetScript("OnEnter", function()
-	if InCombatLockdown() then return end
-	armorIcon:SetVertexColor(unpack(cfg.color.hover))
-end)
-
-armorFrame:SetScript("OnLeave", function()
-	local durMin = 100
-		for i = 1, 18 do
-			local durCur, durMax = GetInventoryItemDurability(i)
-			if ( durCur ~= durMax ) then durMin = min(durMin, durCur*(100/durMax)) end
-		end
-	if durMin >= cfg.armor.minArmor then
-		armorIcon:SetVertexColor(unpack(cfg.color.inactive))
-	else
-		armorIcon:SetVertexColor(unpack(cfg.color.normal))
-	end
-end)
-
-armorFrame:SetScript("OnClick", function(self, button, down)
-	if InCombatLockdown() then return end
-	if button == "LeftButton" then
-
-	end
-end)
-
-local eventframe = CreateFrame("Frame")
-eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
-eventframe:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
-
-eventframe:SetScript("OnEvent", function(self,event, ...)
-	local durMin, durCol
-		durMin, durCol = 100, "ffffff"
-		for i = 1, 18 do
-			local durCur, durMax = GetInventoryItemDurability(i)
-			if ( durCur ~= durMax ) then durMin = min(durMin, durCur*(100/durMax)) end
-		end
-
-	if durMin >= cfg.armor.maxArmor then
-		local overallilvl, equippedilvl = GetAverageItemLevel()
-		armorText:SetText(floor(equippedilvl).." ilvl")
-	else
-		armorText:SetText(floor(durMin).."% - "..floor(select(2,GetAverageItemLevel())).." ilvl")
-	end
-
-	if durMin >= cfg.armor.minArmor then
-		armorIcon:SetVertexColor(unpack(cfg.color.inactive))
-	else
-		armorIcon:SetVertexColor(unpack(cfg.color.normal))
-	end
-	armorFrame:SetSize(armorText:GetStringWidth()+18, 16)
-end)
\ No newline at end of file
+local AddOnName, XIVBar = ...;
+local _G = _G;
+local xb = XIVBar;
+local L = XIVBar.L;
+
+local ArmorModule = xb:NewModule("ArmorModule", 'AceEvent-3.0')
+
+function ArmorModule:GetName()
+  return L['Armor'];
+end
+
+function ArmorModule:OnInitialize()
+  self.iconPath = xb.constants.mediaPath..'datatexts\\repair'
+  self.durabilityAverage = 0
+  self.durabilityList = {
+    [INVSLOT_HEAD] = { cur = 0, max = 0, text = HEADSLOT},
+    [INVSLOT_SHOULDER] =  { cur = 0, max = 0, text = SHOULDERSLOT},
+    [INVSLOT_CHEST] =  { cur = 0, max = 0, text = CHESTSLOT},
+    [INVSLOT_WAIST] =  { cur = 0, max = 0, text = WAISTSLOT},
+    [INVSLOT_LEGS] =  { cur = 0, max = 0, text = LEGSSLOT},
+    [INVSLOT_FEET] =  { cur = 0, max = 0, text = FEETSLOT},
+    [INVSLOT_WRIST] =  { cur = 0, max = 0, text = WRISTSLOT},
+    [INVSLOT_HAND] =  { cur = 0, max = 0, text = HANDSSLOT},
+    [INVSLOT_MAINHAND] =  { cur = 0, max = 0, text = MAINHANDSLOT},
+    [INVSLOT_OFFHAND] =  { cur = 0, max = 0, text = SECONDARYHANDSLOT}
+  }
+end
+
+function ArmorModule:OnEnable()
+  if self.armorFrame == nil then
+    self.armorFrame = CreateFrame("FRAME", nil, xb:GetFrame('bar'))
+    xb:RegisterFrame('armorFrame', self.armorFrame)
+  end
+  self:CreateFrames()
+  self:RegisterFrameEvents()
+  self:Refresh()
+end
+
+function ArmorModule:OnDisable()
+  self:UnregisterEvent('UPDATE_INVENTORY_DURABILITY')
+end
+
+function ArmorModule:CreateFrames()
+  self.armorButton = self.armorButton or CreateFrame('BUTTON', nil, self.armorFrame)
+  self.armorIcon = self.armorIcon or self.armorButton:CreateTexture(nil, 'OVERLAY')
+  self.armorText = self.armorText or self.armorButton:CreateFontString(nil, 'OVERLAY')
+end
+
+function ArmorModule:RegisterFrameEvents()
+  self.armorButton:EnableMouse(true)
+
+  self.armorButton:SetScript('OnEnter', function()
+    ArmorModule:SetArmorColor()
+    GameTooltip:SetOwner(ArmorModule.armorFrame, 'ANCHOR_'..xb.miniTextPosition)
+    GameTooltip:AddLine("[|cff6699FF"..L['Armor'].."|r]")
+    GameTooltip:AddLine(" ")
+    for i,v in pairs(ArmorModule.durabilityList) do
+      if v.max ~= nil and v.max > 0 then
+        local perc = floor((v.cur / v.max)  * 100)
+        GameTooltip:AddDoubleLine(v.text, string.format('%d/%d (%d%%)', v.cur, v.max, perc), 1, 1, 0, 1, 1, 1)
+      end
+    end
+    GameTooltip:Show()
+  end)
+
+  self.armorButton:SetScript('OnLeave', function()
+    self:SetArmorColor()
+    GameTooltip:Hide()
+  end)
+
+  self:RegisterMessage('XIVBar_FrameHide', function(_, name)
+    if name == 'microMenuFrame' then
+      self:Refresh()
+    end
+  end)
+
+  self:RegisterMessage('XIVBar_FrameShow', function(_, name)
+    if name == 'microMenuFrame' then
+      self:Refresh()
+    end
+  end)
+
+  self:RegisterEvent('UPDATE_INVENTORY_DURABILITY')
+end
+
+function ArmorModule:SetArmorColor()
+  local db = xb.db.profile
+  if self.armorButton:IsMouseOver() then
+    self.armorText:SetTextColor(unpack(xb:HoverColors()))
+  else
+    self.armorText:SetTextColor(db.color.inactive.r, db.color.inactive.g, db.color.inactive.b, db.color.inactive.a)
+    if self.durabilityAverage >= db.modules.armor.durabilityMin then
+      self.armorIcon:SetVertexColor(db.color.inactive.r, db.color.inactive.g, db.color.inactive.b, db.color.inactive.a)
+    else
+      self.armorIcon:SetVertexColor(db.color.normal.r, db.color.normal.g, db.color.normal.b, db.color.normal.a)
+    end
+  end
+end
+
+function ArmorModule:Refresh()
+  if self.armorFrame == nil then return; end
+  if not xb.db.profile.modules.armor.enabled then return; end
+
+  local iconSize = xb:GetHeight()
+  self.armorIcon:SetTexture(self.iconPath)
+  --self.armorIcon:SetSize(iconSize, iconSize)
+  self.armorIcon:SetPoint('LEFT')
+
+  self.armorText:SetFont(xb.LSM:Fetch(xb.LSM.MediaType.FONT, xb.db.profile.text.font), xb.db.profile.text.fontSize)
+  self:UpdateDurabilityText()
+  self.armorText:SetPoint('LEFT', self.armorIcon, 'RIGHT', 5, 0)
+
+  self.armorFrame:SetSize(5 + iconSize + self.armorText:GetStringWidth(), xb:GetHeight())
+
+  self.armorButton:SetAllPoints()
+
+  local relativeAnchorPoint = 'RIGHT'
+  local xOffset = 30
+  if not xb:GetFrame('microMenuFrame'):IsVisible() then
+    relativeAnchorPoint = 'LEFT'
+    xOffset = 0
+  end
+
+  self.armorFrame:ClearAllPoints()
+  self.armorFrame:SetPoint('LEFT', xb:GetFrame('microMenuFrame'), relativeAnchorPoint, xOffset, 0)
+  self:SetArmorColor()
+end
+
+function ArmorModule:UPDATE_INVENTORY_DURABILITY()
+  self:UpdateDurabilityText()
+  self:Refresh()
+end
+
+function ArmorModule:UpdateDurabilityText()
+  local total = 0
+  local maxTotal = 0
+  local db =  xb.db.profile.modules.armor
+  local text = ''
+
+  for i,v in pairs(self.durabilityList) do
+    local curDur, maxDur = GetInventoryItemDurability(i)
+    if curDur ~= nil and maxDur ~= nil then
+      total = total + curDur
+      maxTotal = maxTotal + maxDur
+      v.cur = curDur
+      v.max = maxDur
+    end
+  end
+  self.durabilityAverage = floor((total / maxTotal) * 100)
+
+  if self.durabilityAverage < db.durabilityMax then
+    text = self.durabilityAverage..'%'
+  end
+
+  if (self.durabilityAverage >= db.durabilityMax) or db.alwaysShowIlvl then
+    local _, equippedIlvl = GetAverageItemLevel()
+    text = text..floor(equippedIlvl)..' ilvl'
+  end
+
+  self.armorText:SetText(text)
+end
+
+function ArmorModule:GetDefaultOptions()
+  return 'armor', {
+      enabled = true,
+      durabilityMin = 20,
+      durabilityMax = 75,
+      alwaysShowIlvl = true
+    }
+end
+
+function ArmorModule:GetConfig()
+  return {
+    name = self:GetName(),
+    type = "group",
+    args = {
+      enable = {
+        name = ENABLE,
+        order = 0,
+        type = "toggle",
+        get = function() return xb.db.profile.modules.armor.enabled; end,
+        set = function(_, val) xb.db.profile.modules.armor.enabled = val; self:Refresh(); end
+      },
+      ilvlAlways = {
+        name = L['Always Show Item Level'],
+        order = 1,
+        type = "toggle",
+        get = function() return xb.db.profile.modules.armor.alwaysShowIlvl; end,
+        set = function(_, val) xb.db.profile.modules.armor.alwaysShowIlvl = val; self:Refresh(); end
+      },
+      duraMin = {
+        name = L['Minimum Durability to Become Active'],
+        type = 'range',
+        order = 2,
+        min = 0,
+        max = 100,
+        step = 5,
+        get = function() return xb.db.profile.modules.armor.durabilityMin; end,
+        set = function(info, val) xb.db.profile.modules.armor.durabilityMin = val; self:Refresh(); end
+      },
+      duraMax = {
+        name = L['Maximum Durability to Show Item Level'],
+        type = 'range',
+        order = 3,
+        min = 0,
+        max = 100,
+        step = 5,
+        get = function() return xb.db.profile.modules.armor.durabilityMax; end,
+        set = function(info, val) xb.db.profile.modules.armor.durabilityMax = val; self:Refresh(); end,
+        disabled = function() return xb.db.profile.modules.armor.alwaysShowIlvl; end
+      }
+    }
+  }
+end
diff --git a/modules/clock.lua b/modules/clock.lua
index 51d5efa..0835524 100644
--- a/modules/clock.lua
+++ b/modules/clock.lua
@@ -117,7 +117,7 @@ function ClockModule:RegisterFrameEvents()
     if InCombatLockdown() then return; end
     ClockModule:SetClockColor()
     GameTooltip:SetOwner(ClockModule.clockTextFrame, 'ANCHOR_'..xb.miniTextPosition)
-    GameTooltip:AddLine("[|cff6699FFClock|r]")
+    GameTooltip:AddLine("[|cff6699FF"..L['Clock'].."|r]")
     GameTooltip:AddLine(" ")
     local clockTime = nil
     local ttTimeText = ''
@@ -189,7 +189,7 @@ function ClockModule:GetConfig()
         set = function(_, val) xb.db.profile.modules.clock.enabled = val; end,
         width = "full"
       },
-      enable = {
+      useServerTime = {
         name = L['Use Server Time'],
         order = 1,
         type = "toggle",
diff --git a/modules/load_modules.xml b/modules/load_modules.xml
index e80a701..ea97f09 100644
--- a/modules/load_modules.xml
+++ b/modules/load_modules.xml
@@ -2,4 +2,5 @@
   <!--<Script file="test.lua" />-->
   <Script file="micromenu.lua" />
   <Script file="clock.lua" />
+  <Script file="armor.lua" />
 </Ui>
diff --git a/modules/micromenu.lua b/modules/micromenu.lua
index 498f4ba..c9a0ced 100644
--- a/modules/micromenu.lua
+++ b/modules/micromenu.lua
@@ -108,7 +108,7 @@ function MenuModule:Refresh()
     frame:SetFont(xb.LSM:Fetch(xb.LSM.MediaType.FONT, xb.db.profile.text.font), xb.db.profile.text.smallFontSize)
     frame:SetPoint('CENTER', self.frames[name], xb.miniTextPosition)
     self.bgTexture[name]:SetColorTexture(xb.db.profile.color.barColor.r, xb.db.profile.color.barColor.g, xb.db.profile.color.barColor.b, xb.db.profile.color.barColor.a)
-    self.bgTexture[name]:SetPoint('CENTER', frame)
+    self.bgTexture[name]:SetPoint('CENTER', frame, 'CENTER')
   end
 end

diff --git a/modules/old/armor.lua b/modules/old/armor.lua
new file mode 100644
index 0000000..e211304
--- /dev/null
+++ b/modules/old/armor.lua
@@ -0,0 +1,72 @@
+local addon, ns = ...
+local cfg = ns.cfg
+local unpack = unpack
+--------------------------------------------------------------
+if not cfg.armor.show then return end
+
+local armorFrame = CreateFrame("BUTTON",nil, cfg.SXframe)
+armorFrame:SetPoint("LEFT",590,0)
+armorFrame:EnableMouse(true)
+armorFrame:RegisterForClicks("AnyUp")
+
+local armorIcon = armorFrame:CreateTexture(nil,"OVERLAY",nil,7)
+armorIcon:SetPoint("LEFT")
+armorIcon:SetTexture(cfg.mediaFolder.."datatexts\\repair")
+armorIcon:SetVertexColor(unpack(cfg.color.inactive))
+
+local armorText = armorFrame:CreateFontString(nil, "OVERLAY")
+armorText:SetFont(cfg.text.font, cfg.text.normalFontSize)
+armorText:SetPoint("RIGHT", armorFrame,2,0)
+armorText:SetTextColor(unpack(cfg.color.normal))
+
+armorFrame:SetScript("OnEnter", function()
+	if InCombatLockdown() then return end
+	armorIcon:SetVertexColor(unpack(cfg.color.hover))
+end)
+
+armorFrame:SetScript("OnLeave", function()
+	local durMin = 100
+		for i = 1, 18 do
+			local durCur, durMax = GetInventoryItemDurability(i)
+			if ( durCur ~= durMax ) then durMin = min(durMin, durCur*(100/durMax)) end
+		end
+	if durMin >= cfg.armor.minArmor then
+		armorIcon:SetVertexColor(unpack(cfg.color.inactive))
+	else
+		armorIcon:SetVertexColor(unpack(cfg.color.normal))
+	end
+end)
+
+armorFrame:SetScript("OnClick", function(self, button, down)
+	if InCombatLockdown() then return end
+	if button == "LeftButton" then
+
+	end
+end)
+
+local eventframe = CreateFrame("Frame")
+eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
+eventframe:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
+
+eventframe:SetScript("OnEvent", function(self,event, ...)
+	local durMin, durCol
+		durMin, durCol = 100, "ffffff"
+		for i = 1, 18 do
+			local durCur, durMax = GetInventoryItemDurability(i)
+			if ( durCur ~= durMax ) then durMin = min(durMin, durCur*(100/durMax)) end
+		end
+
+	if durMin >= cfg.armor.maxArmor then
+		local overallilvl, equippedilvl = GetAverageItemLevel()
+		armorText:SetText(floor(equippedilvl).." ilvl")
+	else
+		armorText:SetText(floor(durMin).."% - "..floor(select(2,GetAverageItemLevel())).." ilvl")
+	end
+
+	if durMin >= cfg.armor.minArmor then
+		armorIcon:SetVertexColor(unpack(cfg.color.inactive))
+	else
+		armorIcon:SetVertexColor(unpack(cfg.color.normal))
+	end
+	armorFrame:SetSize(armorText:GetStringWidth()+18, 16)
+end)
\ No newline at end of file