Quantcast TradeSkillFrame-add info below next rank text - WoWInterface
Thread Tools Display Modes
09-02-17, 03:15 PM   #1
coomacheek
A Murloc Raider
Join Date: Sep 2017
Posts: 4
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.
  Reply With Quote
09-03-17, 06:58 AM   #2
BujuArena
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 13
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)

Last edited by BujuArena : 09-03-17 at 07:09 AM. Reason: bug fix
  Reply With Quote
09-03-17, 02:30 PM   #3
coomacheek
A Murloc Raider
Join Date: Sep 2017
Posts: 4
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)
  Reply With Quote
09-03-17, 02:59 PM   #4
BujuArena
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 13
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.
  Reply With Quote
09-03-17, 04:02 PM   #5
coomacheek
A Murloc Raider
Join Date: Sep 2017
Posts: 4
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.
  Reply With Quote
09-03-17, 04:10 PM   #6
BujuArena
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 13
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.
  Reply With Quote
09-03-17, 06:39 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,385
Blizzard_TradeSkillUI is load on demand.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-03-17, 06:41 PM   #8
BujuArena
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 13
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.
  Reply With Quote
09-03-17, 09:51 PM   #9
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 806
In your .toc file you need two lines because Blizzard_TradeSkillUI is load on demand:
Code:
## LoadOnDemand: 1
## LoadsWith: Blizzard_TradeSkillUI
  Reply With Quote
09-03-17, 09:52 PM   #10
BujuArena
A Deviate Faerie Dragon
Join Date: Mar 2008
Posts: 13
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.

Last edited by BujuArena : 09-03-17 at 10:16 PM.
  Reply With Quote
09-05-17, 05:53 PM   #11
coomacheek
A Murloc Raider
Join Date: Sep 2017
Posts: 4
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.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » TradeSkillFrame-add info below next rank text

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