View Single Post
06-16-16, 08:35 PM   #3
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Ok, so just focusing on the OnShow portion; I get the children:

Code:
local kids = { PaperDollItemsFrame:GetChildren() };
Then I make a fontstring for each child frame:

Code:
for k, child in ipairs(kids) do
    print(child);
    local duraFS = child:CreateFontString("FontString","OVERLAY","GameTooltipText")
        duraFS:SetPoint("BOTTOM",child,"BOTTOM",0,0);
        duraFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE");
        duraFS:SetFormattedText("");
end
So far so good, that works.

However I am having trouble with getting it to iterate new text. I am trying to get slotId and then with that get durCur, durMax and refresh everything OnShow with the local function duraOnShow()


Code:
local function duraOnShow()

        local slotId = child:GetID();
        -- print(slotId);
        local durCur, durMax = GetInventoryItemDurability(slotId);
        if durCur == nil or durMax == nil then
            -- print(slotId);
            duraFS:Hide();
        else
            -- print(slotId);
            local durItemFinite = durCur*(100/durMax);
            -- print(durItemFinite);
            duraFS:SetFormattedText("%.0f%%", durCur*(100/durMax));
            if durItemFinite == 100 then 
                duraFS:Hide();
            elseif durItemFinite >= 75 then
                duraFS:SetTextColor(0.75, 0.75, 0.75);
            elseif durItemFinite >= 50 then
                duraFS:SetTextColor(0, 1, 0);
            elseif durItemFinite >= 25 then
                duraFS:SetTextColor(1, 1, 0);
            elseif durItemFinite >= 0 then
                duraFS:SetTextColor(1, 0, 0);
            end
        end
end
local function duraOnShow() does ok until it hits duraFS and errors with nil. If I change local duraFS

Code:
local duraFS = child:CreateFontString("FontString","OVERLAY","GameTooltipText")
into a global like this:

Code:
duraFS = child:CreateFontString("FontString","OVERLAY","GameTooltipText")
then it works but it dumps everything into the last frame.

To clarify, if I remove the last peice of gear, weapon, then it displays the feet. if I remove the feet it displays the legs, etc, etc. So it works, it is changing the text, it jsut is not allocating each to its own frame.

I tried making a table manually as well :

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

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

local function duraRefresh()
	for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
		local slotId = v:GetID();
		-- print(slotId)
		local durCur, durMax = GetInventoryItemDurability(slotId)
		if durCur == nil or durMax == nil then
			duraFS:SetFormattedText("");
		elseif ( durCur ~= durMax ) then
			local durFinite = durCur*(100/durMax)
				print(durFinite)
			if 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
			duraFS:SetFormattedText("%.0f%%", durCur*(100/durMax));
		end
	end
end
Just to see if I was missing any kind of information from the several transfers from parent to child to frame to slot to id to bla, bla, bla; to no avail in helping me figure this out.

If anyone has time to help me wrangle with this I would appreciate it.

Cheers!
  Reply With Quote