WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Help Clearing Text OnHide (https://www.wowinterface.com/forums/showthread.php?t=53721)

Dejablue 06-16-16 04:44 AM

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)


Lombra 06-16-16 05:29 AM

You will want to make sure that font strings are only being created once ever, instead of everytime the frame is shown.

Dejablue 06-16-16 08:35 PM

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!

sezz 06-17-16 04:58 AM

Take a look at Tekkub's tekability:
http://www.wowinterface.com/downloads/info9235

Lombra 06-17-16 06:23 AM

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


Dejablue 06-17-16 09:22 PM

Quote:

Originally Posted by Lombra (Post 315774)
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!

Dejablue 06-17-16 09:24 PM

Quote:

Originally Posted by sezz (Post 315770)
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!

Dejablue 06-20-16 03:00 AM

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)


myrroddin 06-20-16 04:27 AM

Since you guys are talking about durability, I take it there is no event that fires when an item gains or loses it?

Fizzlemizz 06-20-16 10:56 AM

No specific event but it's part of taking damage so a health event would probably be the closest.

sirann 06-20-16 11:18 AM

http://wowprogramming.com/docs/event...ORY_DURABILITY

myrroddin 06-20-16 12:51 PM

Quote:

Originally Posted by sirann (Post 315833)

I thought so. That would make the OnUpdate script moot, and the code a whole lot simpler.

Dejablue 06-20-16 03:50 PM

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! ;)

Dejablue 06-20-16 04:46 PM

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)


myrroddin 06-20-16 10:19 PM

Heh. Don't thank me, I did nothing other than point out my own failing memory. It was Sirann who found your event.

Fizzlemizz 06-20-16 10:22 PM

Quote:

Originally Posted by myrroddin (Post 315848)
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 :o.

Dejablue 06-20-16 10:28 PM

Quote:

Originally Posted by myrroddin (Post 315848)
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!


All times are GMT -6. The time now is 07:03 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI