PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/Tukui/modules/datatext/durability.lua

http://github.com/Asphyxia/Tukui
Lua | 62 lines | 52 code | 6 blank | 4 comment | 8 complexity | 3167db630e6a4b801b1c1d551d3e1423 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2--------------------------------------------------------------------
 3-- DURABILITY
 4--------------------------------------------------------------------
 5	
 6if C["datatext"].dur and C["datatext"].dur > 0 then
 7	local Stat = CreateFrame("Frame")
 8	Stat:EnableMouse(true)
 9	Stat:SetFrameStrata("HIGH")
10	Stat:SetFrameLevel(3)
11
12	local Text  = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
13	Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
14	T.PP(C["datatext"].dur, Text)
15
16	local Total = 0
17	local current, max
18
19	local function OnEvent(self)
20		for i = 1, 11 do
21			if GetInventoryItemLink("player", L.Slots[i][1]) ~= nil then
22				current, max = GetInventoryItemDurability(L.Slots[i][1])
23				if current then 
24					L.Slots[i][3] = current/max
25					Total = Total + 1
26				end
27			end
28		end
29		table.sort(L.Slots, function(a, b) return a[3] < b[3] end)
30		
31		if Total > 0 then
32			Text:SetText(DURABILITY..": "..T.datacolor..floor(L.Slots[1][3]*100).."% ")
33		else
34			Text:SetText(DURABILITY..": "..T.datacolor.."100% ")
35		end
36		-- Setup Durability Tooltip
37		self:SetAllPoints(Text)
38		Total = 0
39	end
40
41	Stat:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
42	Stat:RegisterEvent("MERCHANT_SHOW")
43	Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
44	Stat:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
45	Stat:SetScript("OnEvent", OnEvent)
46	Stat:SetScript("OnEnter", function(self)
47		if not InCombatLockdown() then
48			local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
49			GameTooltip:SetOwner(panel, anchor, xoff, yoff)
50			GameTooltip:ClearLines()
51			for i = 1, 11 do
52				if L.Slots[i][3] ~= 1000 then
53					green = L.Slots[i][3]*2
54					red = 1 - green
55					GameTooltip:AddDoubleLine(L.Slots[i][2], floor(L.Slots[i][3]*100).."%",1 ,1 , 1, red + 1, green, 0)
56				end
57			end
58			GameTooltip:Show()
59		end
60	end)
61	Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
62end