Quantcast

Stolen idea from BuG and code from Blaze :D

Darthpred [04-22-15 - 12:36]
Stolen idea from BuG and code from Blaze :D
Filename
ElvUI_SLE/modules/sledatatexts/durability.lua
ElvUI_SLE/modules/sledatatexts/load_datatexts.xml
diff --git a/ElvUI_SLE/modules/sledatatexts/durability.lua b/ElvUI_SLE/modules/sledatatexts/durability.lua
new file mode 100644
index 0000000..4c89484
--- /dev/null
+++ b/ElvUI_SLE/modules/sledatatexts/durability.lua
@@ -0,0 +1,73 @@
+local E, L, V, P, G = unpack(ElvUI); --Inport: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
+local DT = E:GetModule('DataTexts')
+
+local join = string.join
+
+local displayString = ""
+local tooltipString = "%d%%"
+local totalDurability = 0
+local current, max, lastPanel
+local invDurability = {}
+local slots = {
+	["SecondaryHandSlot"] = L["Offhand"],
+	["MainHandSlot"] = L["Main Hand"],
+	["FeetSlot"] = L["Feet"],
+	["LegsSlot"] = L["Legs"],
+	["HandsSlot"] = L["Hands"],
+	["WristSlot"] = L["Wrist"],
+	["WaistSlot"] = L["Waist"],
+	["ChestSlot"] = L["Chest"],
+	["ShoulderSlot"] = L["Shoulder"],
+	["HeadSlot"] = L["Head"],
+}
+
+local function OnEvent(self, event, ...)
+    lastPanel = self
+    totalDurability = 100
+    for index, value in pairs(slots) do
+        local slot = GetInventorySlotInfo(index)
+        current, max = GetInventoryItemDurability(slot)
+        if current then
+            invDurability[value] = (current/max)*100
+            if ((current/max) * 100) < totalDurability then
+                totalDurability = (current/max) * 100
+            end
+        end
+    end
+    if totalDurability <= 89 then
+        E:Flash(self, 0.53, true)
+    else
+        E:StopFlash(self)
+    end
+    local r,g,b = E:ColorGradient(totalDurability/100, .9,.2,.2, .9,.9,.2, .2,.9,.2)
+    local hex = E:RGBToHex(r,g,b)
+    self.text:SetFormattedText("%s: %s%d%%|r", DURABILITY, hex, totalDurability)
+end
+
+local function Click()
+	ToggleCharacter("PaperDollFrame")
+end
+
+local function OnEnter(self)
+	DT:SetupTooltip(self)
+
+	for slot, durability in pairs(invDurability) do
+		DT.tooltip:AddDoubleLine(slot, format(tooltipString, durability), 1, 1, 1, E:ColorGradient(durability * 0.01, 1, 0, 0, 1, 1, 0, 0, 1, 0))
+	end
+
+	DT.tooltip:Show()
+end
+
+--[[
+	DT:RegisterDatatext(name, events, eventFunc, updateFunc, clickFunc, onEnterFunc, onLeaveFunc)
+
+	name - name of the datatext (required)
+	events - must be a table with string values of event names to register
+	eventFunc - function that gets fired when an event gets triggered
+	updateFunc - onUpdate script target function
+	click - function to fire when clicking the datatext
+	onEnterFunc - function to fire OnEnter
+	onLeaveFunc - function to fire OnLeave, if not provided one will be set for you that hides the tooltip.
+]]
+DT:RegisterDatatext('Durability', {'PLAYER_ENTERING_WORLD', "UPDATE_INVENTORY_DURABILITY", "MERCHANT_SHOW"}, OnEvent, nil, Click, OnEnter)
+
diff --git a/ElvUI_SLE/modules/sledatatexts/load_datatexts.xml b/ElvUI_SLE/modules/sledatatexts/load_datatexts.xml
index da5babc..ad43dd1 100644
--- a/ElvUI_SLE/modules/sledatatexts/load_datatexts.xml
+++ b/ElvUI_SLE/modules/sledatatexts/load_datatexts.xml
@@ -17,4 +17,5 @@
 	<Script file='micromenu.lua'/>
 	<Script file='currency.lua'/>
 	<Script file='range.lua'/>
+	<Script file='durability.lua'/>
 </Ui>
\ No newline at end of file