View Single Post
06-20-16, 04:46 PM   #14
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
So doing a /etrace it shows that UPDATE_INVENTORY_DURABILITY fires when you add or remove, change, items on the paper doll. So it appears that registering UNIT_INVENTORY_CHANGED is not needed.

Here is the new script, very nice, no OnUpdate, OnShow, OnHide or timers to worry about.

Total durability still seems to be wonky, gotta figure out the math or do something else.

Woot, thanks all

Code:
-- ---------------------------
-- -- DCS Durability Frames --
-- ---------------------------

local DCSITEM_SLOT_FRAMES = {CharacterHeadSlot,CharacterNeckSlot,CharacterShoulderSlot,
	CharacterBackSlot,CharacterChestSlot,CharacterWristSlot,CharacterHandsSlot,
	CharacterWaistSlot,CharacterLegsSlot,CharacterFeetSlot,CharacterFinger0Slot,
	CharacterFinger1Slot,CharacterTrinket0Slot,CharacterTrinket1Slot,
	CharacterMainHandSlot,CharacterSecondaryHandSlot,
};

local DCS_RegistrationFrame = CreateFrame("Frame")
    DCS_RegistrationFrame:RegisterEvent("PLAYER_LOGIN")
    DCS_RegistrationFrame:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
--  DCS_RegistrationFrame:RegisterEvent("UNIT_INVENTORY_CHANGED") -- UPDATE_INVENTORY_DURABILITY fires when item change.


for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
    v.durability = duraFS
    v.durability = v:CreateFontString("FontString","OVERLAY","GameTooltipText")
    v.durability:SetPoint("BOTTOM",v,"BOTTOM",0,0);
    v.durability:SetFont("Fonts\\FRIZQT__.TTF", 12, "THINOUTLINE");
    v.durability:SetFormattedText("");

    --v.itemlevel = ilvlFS
    --v.itemlevel = v:CreateFontString("FontString","OVERLAY","GameTooltipText")
    --v.itemlevel:SetPoint("TOP",v,"TOP",0,0);
    --v.itemlevel:SetFont("Fonts\\FRIZQT__.TTF", 12, "THINOUTLINE");
    --v.itemlevel:SetFormattedText("lol");
end

DCS_RegistrationFrame:SetScript("OnEvent", function(self, event, ...)
	for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
	    -- print(v)
	    -- ---------------------
	    -- -- Item Durability --
	    -- ---------------------
		local slotId = v:GetID();
		local durCur, durMax = GetInventoryItemDurability(slotId)
		if durCur == nil or durMax == nil then
			v.durability:SetFormattedText("");
		elseif ( durCur == durMax ) then
			v.durability:SetFormattedText("");
		elseif ( durCur ~= durMax ) then
			local durFinite = durCur*(100/durMax)
			--	print(durFinite)
	        v.durability:SetFormattedText("%.0f%%", durCur*(100/durMax));
			if durFinite >= 75 then
				v.durability:SetTextColor(0.75, 0.75, 0.75);
			elseif durFinite >= 50 then
				v.durability:SetTextColor(0, 1, 0);
			elseif durFinite >= 25 then
				v.durability:SetTextColor(1, 1, 0);
			elseif durFinite >= 0 then
				v.durability:SetTextColor(1, 0, 0);
			end
		end

		----------------
		-- Item Level --
		----------------
	        -- local DCSitemLink = GetInventoryItemLink("player", slotId)
		-- print(DCSitemLink)

		---------------------------
		-- Get Item Repair Costs --
		---------------------------
		-- local scanTool = CreateFrame("GameTooltip")
		--	scanTool:ClearLines()
		-- cal repairCost = select(3, scanTool:SetInventoryItem("player", slotId))
		-- print(repairCost)
	end

    -- ----------------------
    -- -- Total Durability --
    -- ----------------------
    for slot, slotName in gmatch("1HEAD3SHOULDER5CHEST6WAIST7LEGS8FEET9WRIST10HANDS16MAINHAND17SECONDARYHAND18RANGED","(%d+)([^%d]+)") do
    	-- print(slot)
    	local durCur, durMax = GetInventoryItemDurability(slot)
    	-- print(durCur, durMax)
    	-- print(durMax)
    	-- print(slot)
    	if ( durCur ~= durMax ) then
    		local duraFS = CharacterShirtSlot:CreateFontString("FontString","OVERLAY","GameTooltipText")
    			duraFS:ClearAllPoints()
    			duraFS:SetPoint("CENTER",CharacterShirtSlot,"CENTER",0,0)
    			duraFS:SetFont("Fonts\\FRIZQT__.TTF", 16, "THINOUTLINE")
    		
    		local durFinite = durCur*(100/durMax)
    		--	print(durFinite)
    		duraFS:SetFormattedText("%.0f%%", durCur*(100/durMax))
    		if durFinite == 100 then 
    			duraFS:Hide();
    		elseif durFinite >= 75 then
    			duraFS:SetTextColor(0.75, 0.75, 0.75);
    		elseif durFinite >= 50 then
    			duraFS:SetTextColor(0, 1, 0);
    		elseif durFinite >= 25 then
    			duraFS:SetTextColor(1, 1, 0);
    		elseif durFinite >= 0 then
    			duraFS:SetTextColor(1, 0, 0);
    		end
    	end	
    end
end)

-- ------------------------------------------------
-- -- DCS Character Frame Expand/Collapse Button --
-- ------------------------------------------------
local _, private = ...
	private.defaults.dejacharacterstatsExpandChecked = {
		ExpandSetChecked = true,
}
local DCS_ExpandCheck = CreateFrame("Button", "DCS_ExpandCheck", CharacterFrameInset, "InterfaceOptionsCheckButtonTemplate")
	DCS_ExpandCheck:RegisterEvent("PLAYER_LOGIN")
	DCS_ExpandCheck:ClearAllPoints()
	DCS_ExpandCheck:SetPoint("BOTTOMRIGHT", 0, 0)
	DCS_ExpandCheck:SetScale(1.25)


local DCS_ExpandButtonTextureFrame = CreateFrame("Frame", "DCS_ExpandButtonTextureFrame", DCS_ExpandCheck)
	DCS_ExpandButtonTextureFrame:ClearAllPoints()
	DCS_ExpandButtonTextureFrame:SetFrameStrata("HIGH")
	DCS_ExpandButtonTextureFrame:SetAllPoints(DCS_ExpandCheck) 


local DCS_ExpandButtontexture = DCS_ExpandButtonTextureFrame:CreateTexture() 
	DCS_ExpandButtontexture:SetAllPoints(DCS_ExpandButtonTextureFrame) 

DCS_ExpandCheck:SetScript("OnEvent", function(self, event, arg1)
	if event == "PLAYER_LOGIN" then
		checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
		--	print(checked)
		if checked == true then
		--	print(checked)
			CharacterFrame_Collapse();
			DCS_ExpandCheck.tooltipText = 'Show Character Stats.' --Creates a tooltip on mouseover.
			DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Up") 
			private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = false
		else
		--	print(checked)
			CharacterFrame_Expand();
			DCS_ExpandCheck.tooltipText = 'Hide Character Stats.' --Creates a tooltip on mouseover.
			DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Down") 
			private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = true
		end
	end
end)

DCS_ExpandCheck:SetScript("OnClick", function(self,event,arg1) 
	checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
	if checked == true then
	--	print(checked)
		CharacterFrame_Collapse();
		DCS_ExpandCheck.tooltipText = 'Show Character Stats.' --Creates a tooltip on mouseover.
		DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Up") 
		private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = false
	else
	--	print(checked)
		CharacterFrame_Expand();
		DCS_ExpandCheck.tooltipText = 'Hide Character Stats.' --Creates a tooltip on mouseover.
		DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Down") 
		private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = true
	end
end)
	
-- -----------------------------
-- -- PaperDoll OnShow/OnHide --
-- -----------------------------
PaperDollFrame:SetScript("OnShow", function(self, event, arg1)
	CharacterStatsPane.initialOffsetY = 0;
	CharacterFrameTitleText:SetText(UnitPVPName("player"));
	PaperDollFrame_SetLevel();
	PaperDollFrame_UpdateStats();

	SetPaperDollBackground(CharacterModelFrame, "player");
	PaperDollBgDesaturate(true);
	PaperDollSidebarTabs:Show();
	PaperDollFrame_UpdateInventoryFixupComplete(self);

	checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
	if checked == true then
	--	print(checked)
		CharacterFrame_Expand();
		DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Down") 
	else
	--	print(checked)
		CharacterFrame_Collapse();
		DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Up") 
	end
end)

PaperDollFrame:SetScript("OnHide", function(self, event, arg1)
	CharacterStatsPane.initialOffsetY = 0;
	CharacterFrame_Collapse();
	PaperDollSidebarTabs:Hide();
	PaperDollFrame_HideInventoryFixupComplete(self);
end)

Last edited by Dejablue : 06-22-16 at 01:43 AM.
  Reply With Quote