WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   TradeSkillFrame-add info below next rank text (https://www.wowinterface.com/forums/showthread.php?t=55711)

coomacheek 09-02-17 03:15 PM

TradeSkillFrame-add info below next rank text
 
Reaching out to the community for some help/guidance on how to add additional text just below the "Next Rank:" text within the TradeSkillUI frame. I've been dusting off an old addon I wrote from several years ago and the new changes have me stumped.

See here for an example of what I'm trying to accomplish:


I have this bit of code below, which works fine. The Recipe_Select() function currently does what it's suppose to and returns the output to the chat window. Rather than outputting to the chat window, I'm trying to figure out how to go about adding a new text field directly below the "Next Rank:" text like in my screenshot.

Code:

hooksecurefunc(TradeSkillFrame.RecipeList, "OnRecipeButtonClicked", function(self, ...)
        Recipe_Select()
end)

Believe I'll need to append the text to the TradeSkillFrame.DetailsFrame, but that's where I get stuck. I have other functions that add text within the TradeSkillFrame.RecipeList frame, but the same doesn't work for the DetailsFrame.

BujuArena 09-03-17 06:58 AM

This code adds the selected recipe ID to that spot. This was tricky to figure out, but through some investigation of the Blizzard UI code, I managed it.

Code:

ExtraTradeSkillRecipeTextFrame = CreateFrame("Frame", nil, UIParent)
ExtraTradeSkillRecipeTextFrame:RegisterEvent("ADDON_LOADED")

local hooked = false
ExtraTradeSkillRecipeTextFrame:SetScript("OnEvent", function(self, event, arg1, ...)
    if arg1 == "Blizzard_TradeSkillUI" then
        if hooked == false then
            hooksecurefunc(TradeSkillFrame.DetailsFrame, "RefreshDisplay", function(self, ...)
                if self.selectedRecipeID == nil then return end

                local extraText="recipe ID: "..tostring(self.selectedRecipeID)

                local sourceText=self.Contents.SourceText:GetText()
                if sourceText==nil then
                    local numReagents = C_TradeSkillUI.GetRecipeNumReagents(self.selectedRecipeID)
                    if numReagents > 0 then
                        self.Contents.SourceText:SetPoint("TOP", self.Contents.Reagents[numReagents], "BOTTOM", 0, -15)
                    else
                        self.Contents.SourceText:SetPoint("TOP", self.Contents.ReagentLabel, "TOP");
                    end
                    sourceText=extraText
                    self:AddContentWidget(self.Contents.SourceText)
                    self.Contents.SourceText:Show()
                else
                    sourceText=sourceText.."\n\n"..extraText
                end
                self.Contents.SourceText:SetText(sourceText)
                self:RefreshButtons()
            end)
            hooked = true
            self:UnregisterEvent("ADDON_LOADED")
        end
    end
end)


coomacheek 09-03-17 02:30 PM

Thanks, but I wasn't able to get your code to work. For me arg1 was never equal to "Blizzard_TradeSkillUI" (arg1 kept showing up as other addon names). Once I corrected for that I was able to get the code to run, but the text wasn't always formatted at the bottom within the frame. I believe that was driven by the recipe (some have more text than others).

Here's the code I ended up using:

Code:

local details = TradeSkillFrame.DetailsFrame
local contents = details.Contents
local myStuff = details.Contents:CreateFontString(nil,"ARTWORK","GameFontNormal")
myStuff:SetSize(290,0)
myStuff:SetJustifyH("LEFT")


-- function that runs after a RefreshDisplay
local function update(recipeID)
   
  if not recipeID then
    return -- if no recipeID yet, leave; a refresh will happen with one
  end

  local lastWidget
 
  -- if NextRankText+SoureText is in details, attach myStuff to it
  if contents.SourceText:IsVisible() then
    lastWidget = contents.SourceText
  else -- otherwise attach to last item (likely a reagent) that anchors to TOPLEFT

        for _,widget in ipairs(details.activeContentWidgets) do
          if widget:IsVisible() and widget:GetPoint()=="TOPLEFT" then
                lastWidget = widget
          end
        end
  end
 
  local recipeLink = C_TradeSkillUI.GetRecipeItemLink(recipeID);
 
  myStuff:SetPoint("TOPLEFT",lastWidget,"BOTTOMLEFT",0,0)
  myStuff:SetText("My text would go here"))
end

hooksecurefunc(details,"RefreshDisplay",function(self)
        local recipeID = TradeSkillFrame.RecipeList:GetSelectedRecipeID()
        update(recipeID)
end)


BujuArena 09-03-17 02:59 PM

What? You weren't able to get the code to work? That makes no sense. As a standalone addon, which is how I was programming it, it works perfectly.

coomacheek 09-03-17 04:02 PM

So I tried running it as a stand-alone addon and made sure it was the only addon I had enabled.

For me, arg1 = the addon name. This IF statement is never true for me: "if arg1 == "Blizzard_TradeSkillUI" then" If I take out that check, then it works like a champ. No drawing errors with the text.

So the text drawing issues must have been on my end when I tried incorporating it into my code. I'll have to take another look.

BujuArena 09-03-17 04:10 PM

I published my code as an addon: https://wow.curseforge.com/projects/...recipeidshower

I see no reason why it shouldn't work for you. It works perfectly for me, as shown in the screenshot.

Seerah 09-03-17 06:39 PM

Blizzard_TradeSkillUI is load on demand.

BujuArena 09-03-17 06:41 PM

Yup, hence why I wait for it to exist using the ADDON_LOADED event. If I try to implement the hook before it's loaded, I get a missing reference error.

myrroddin 09-03-17 09:51 PM

In your .toc file you need two lines because Blizzard_TradeSkillUI is load on demand:
Code:

## LoadOnDemand: 1
## LoadsWith: Blizzard_TradeSkillUI


BujuArena 09-03-17 09:52 PM

That sounds like an alternative (and superior) way to do it, but my original method did work. I'll update my addon to use that method though. Thanks!

Edit: Looks like "LoadsWith" is incorrect; using "LoadWith" instead.

Edit 2: Yup, that worked. Thanks! Project updated.

coomacheek 09-05-17 05:53 PM

I downloaded it and it works perfect now. I can only assume my TOC file was jacked before. This updated version is much cleaner than what I had before. I've already updated my addon with the new version. Many thanks.


All times are GMT -6. The time now is 06:24 PM.

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