Thread Tools Display Modes
06-16-16, 04:44 AM   #1
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Help Clearing Text OnHide

I am having trouble figuring out how to clear or update text once it has been displayed. The below script creates the text onshow. The timer starts and if I have an empty item slot and equip it then it will update. However, should I remove the item the text remains. Swapping items creates new text but it is overlayed onto the old text.

Any help would be appreciated.

Cheers!

EDIT: This is for Legion/PTR. This also works (except for the above issues) on WoD live if you remove:
PaperDollFrame_UpdateInventoryFixupComplete(self);
PaperDollFrame_HideInventoryFixupComplete(self);

Code:
-- ---------------------------
-- -- DCS Durability Frames --
-- ---------------------------
local DuraShowTimer
local kids = { PaperDollItemsFrame:GetChildren() };
--	print(kids);
local function duraOnShow()
-- -------------------
-- - Item Durability -
-- -------------------
print("tick")
print("tock")
    for k, child in ipairs(kids) do
        child:GetName();
        -- print(child);
        local duraFS = child:CreateFontString("FontString","OVERLAY","GameTooltipText")
            duraFS:SetPoint("BOTTOM",child,"BOTTOM",0,0);
            duraFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE");	
        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
end

local function duraOnHide()
    if DuraShowTimer then DuraShowTimer:Cancel() end
end

local function delayHideDura(self)
    DuraShowTimer = C_Timer.NewTicker(0.10, duraOnShow, nil)
end

-- --------------------	
-- - Total Durability -
-- --------------------
for slot, slotName in gmatch("1HEAD3SHOULDER5CHEST6WAIST7LEGS8FEET9WRIST10HANDS16MAINHAND17SECONDARYHAND18RANGED","(%d+)([^%d]+)") do
local durCur, durMax = GetInventoryItemDurability(slot)
-- print(durMax)
-- print(slot)
-- print(frameName)
    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

-- ------------------------------------------------
-- -- 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)
    DCS_ExpandCheck.tooltipText = 'Show Character Stats.' --Creates a tooltip on mouseover.

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

DCS_ExpandCheck:SetScript("OnEvent", function(self, event, arg1)
    if event == "PLAYER_LOGIN" then
        checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
        --	print(checked)
    end
end)

DCS_ExpandCheck:SetScript("OnClick", function(self,event,arg1) 
    checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
    if checked == true then
        --	print(checked)
        CharacterFrame_Collapse();
        DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Up") 
        private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = false
    else
        --	print(checked)
        CharacterFrame_Expand();
        DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Down") 
        private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = true
    end
end)

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
        delayHideDura()
    end)

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

Last edited by Dejablue : 06-16-16 at 04:50 AM.
  Reply With Quote
06-16-16, 05:29 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You will want to make sure that font strings are only being created once ever, instead of everytime the frame is shown.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
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
06-17-16, 04:58 AM   #4
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
Take a look at Tekkub's tekability:
http://www.wowinterface.com/downloads/info9235
  Reply With Quote
06-17-16, 06:23 AM   #5
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I would definitely use the manually created table instead. That's more reliable.

You're just missing a reference to your font strings. When you make the global reference the variable will just be overwritten and refer to whatever you assigned to it last, as you've noticed. What you should do is make a reference on the frames themselves.

Do this when creating the frames:
Code:
for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
	local duraFS = v:CreateFontString("FontString","OVERLAY","GameTooltipText")
	duraFS:SetPoint("BOTTOM",v,"BOTTOM",0,0);
	duraFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE");
	duraFS:SetFormattedText("lollolol");
	v.durability = duraFS
end
You may now access the font string through the durability field of each frame.

Code:
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
			v.durability:SetFormattedText("");
		elseif ( durCur ~= durMax ) then
			v.durability:SetFormattedText("%.0f%%", durCur*(100/durMax));
		end
	end
end
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-17-16, 09:22 PM   #6
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Originally Posted by Lombra View Post
I would definitely use the manually created table instead. That's more reliable.

You're just missing a reference to your font strings. When you make the global reference the variable will just be overwritten and refer to whatever you assigned to it last, as you've noticed. What you should do is make a reference on the frames themselves.

Do this when creating the frames:
Code:
for k, v in ipairs(DCSITEM_SLOT_FRAMES) do
	local duraFS = v:CreateFontString("FontString","OVERLAY","GameTooltipText")
	duraFS:SetPoint("BOTTOM",v,"BOTTOM",0,0);
	duraFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE");
	duraFS:SetFormattedText("lollolol");
	v.durability = duraFS
end
You may now access the font string through the durability field of each frame.

Code:
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
			v.durability:SetFormattedText("");
		elseif ( durCur ~= durMax ) then
			v.durability:SetFormattedText("%.0f%%", durCur*(100/durMax));
		end
	end
end
Yea I figured that out late last night but was just too tired to think of a solution, like how do I reference the frame itself with each iteration.

Thank you so much. I am very new to programming in general let alone lua.

Thanks for deciphering my spaghetti too and taking out the time. I will work on this over the weekend and post results or questions. Not that I expect you or anyone to continue to respond, but for other authors so that if they have this issue they can see what was done here. Archived posts has been a huge help to me.

Thanks again.

Cheers!
  Reply With Quote
06-17-16, 09:24 PM   #7
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Originally Posted by sezz View Post
Take a look at Tekkub's tekability:
http://www.wowinterface.com/downloads/info9235
Sweet! Great for my edification. I am going to try to work out what I have with Lombra's suggestion. I may need some of the concepts later tho as I intend to add item level as well. Thanks for the reference.

Cheers!
  Reply With Quote
06-20-16, 03:00 AM   #8
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Works perfect. Thanks again everyone. Here is the tentative script:

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

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

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

local function duraOnShow()
	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
			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
	end

    -- --------------------	
    -- - Total Durability -
    -- --------------------
    for slot, slotName in gmatch("1HEAD3SHOULDER5CHEST6WAIST7LEGS8FEET9WRIST10HANDS16MAINHAND17SECONDARYHAND18RANGED","([%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

-- ---------------------
-- -- Timers OnUpdate --
-- ---------------------
local function duraOnHide()
    if DuraShowTimer then DuraShowTimer:Cancel() end
end

local function delayShowDura(self)
    DuraShowTimer = C_Timer.NewTicker(0.10, duraOnShow, nil)
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)
	DCS_ExpandCheck.tooltipText = 'Show Character Stats.' --Creates a tooltip on mouseover.

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

DCS_ExpandCheck:SetScript("OnEvent", function(self, event, arg1)
	if event == "PLAYER_LOGIN" then
		checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
		--	print(checked)
	end
end)

DCS_ExpandCheck:SetScript("OnClick", function(self,event,arg1) 
	checked = private.db.dejacharacterstatsExpandChecked.ExpandSetChecked
	if checked == true then
	--	print(checked)
		CharacterFrame_Collapse();
		DCS_ExpandButtontexture:SetTexture("Interface\\GLUES\\COMMON\\Glue-RightArrow-Button-Up") 
		private.db.dejacharacterstatsExpandChecked.ExpandSetChecked = false
	else
	--	print(checked)
		CharacterFrame_Expand();
		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
    delayShowDura()
end)

PaperDollFrame:SetScript("OnHide", function(self, event, arg1)
	CharacterStatsPane.initialOffsetY = 0;
	CharacterFrame_Collapse();
	PaperDollSidebarTabs:Hide();
	PaperDollFrame_HideInventoryFixupComplete(self);
    duraOnHide()
end)
  Reply With Quote
06-20-16, 04:27 AM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Since you guys are talking about durability, I take it there is no event that fires when an item gains or loses it?
  Reply With Quote
06-20-16, 10:56 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
No specific event but it's part of taking damage so a health event would probably be the closest.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-20-16, 11:18 AM   #11
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
http://wowprogramming.com/docs/event...ORY_DURABILITY
  Reply With Quote
06-20-16, 12:51 PM   #12
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I thought so. That would make the OnUpdate script moot, and the code a whole lot simpler.
  Reply With Quote
06-20-16, 03:50 PM   #13
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Well, holy shit! Even better! Thanks myrroddin

Ill look into it, but I do not know that I can get rid of OnUpdate becasue when you swap out items on your paper doll the item level of an item doesn't change.

There is an event tho, UNIT_INVENTORY_CHANGED that probably can fix that.

Thanks for the prompt everyone!

Last edited by Dejablue : 06-20-16 at 04:05 PM.
  Reply With Quote
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
06-20-16, 10:19 PM   #15
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Heh. Don't thank me, I did nothing other than point out my own failing memory. It was Sirann who found your event.
  Reply With Quote
06-20-16, 10:22 PM   #16
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by myrroddin View Post
Heh. Don't thank me, I did nothing other than point out my own failing memory.
At least in that you know you are not alone .
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-20-16, 10:28 PM   #17
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Originally Posted by myrroddin View Post
Heh. Don't thank me, I did nothing other than point out my own failing memory. It was Sirann who found your event.
True Thanks Sirann!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Help Clearing Text OnHide

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off