Quantcast
Quest about remove 'sell price' part from tooltip - WoWInterface
Thread Tools Display Modes
11-01-20, 09:34 PM   #1
devilArt
A Wyrmkin Dreamwalker
 
devilArt's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 51
Quest about remove 'sell price' part from tooltip

I use following codes to remove 'sell price' line from tooltip
Now 'sell price' line is gone
but still there is a gap in the tooltip

lua Code:
  1. function TOOLTIP:RemoveMoneyLine()
  2.   if not self.shownMoneyFrames then return end
  3.   GameTooltip_ClearMoney(self)
  4. end
  5. GameTooltip:HookScript('OnTooltipSetItem', TOOLTIP.RemoveMoneyLine)


So I checked blizz source code

lua Code:
  1. function SetTooltipMoney(frame, money, type, prefixText, suffixText)
  2.     GameTooltip_AddBlankLinesToTooltip(frame, 1);
  3.     ... more code ...
  4. end

Blizz insert a blank line into 'sell price' part, and GameTooltip_ClearMoney(self) cant remove it
then I stuck here, any solutions?
  Reply With Quote
11-02-20, 03:34 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,794
Did you try calling GameTooltip:Show() afterward?
__________________
"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
11-02-20, 08:44 PM   #3
devilArt
A Wyrmkin Dreamwalker
 
devilArt's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 51
Originally Posted by Seerah View Post
Did you try calling GameTooltip:Show() afterward?
thanks for help Seerah, but GameTooltip:Show() dosent work
  Reply With Quote
11-03-20, 02:55 AM   #4
LudiusMaximus
A Cobalt Mageweaver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 248
You could

store all tooltip lines,
completely clear the tooltip,
reprint all tooltip lines except the money frame line.

Just after you clear, you have to temporarily override GameTooltip.GetItem such that other addons reading the tooltip afterwards can still get the original item name and link:


Code:
-- This will restore the original GetItem after the tooltip is closed.
local originalGetItem = GameTooltip.GetItem
GameTooltip:HookScript("OnHide", function(self)
  GameTooltip.GetItem = originalGetItem
end)


-- Function to reprint stored tooltip lines.
local function AddLineOrDoubleLine(tooltip, leftText, rightText, leftTextR, leftTextG, leftTextB, rightTextR, rightTextG, rightTextB, intendedWordWrap)
  if rightText then
    tooltip:AddDoubleLine(leftText, rightText, leftTextR, leftTextG, leftTextB, rightTextR, rightTextG, rightTextB)
  else
    tooltip:AddLine(leftText, leftTextR, leftTextG, leftTextB, intendedWordWrap)
  end
end

Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)

  if not self.shownMoneyFrames then return end

  -- Store for GetItem to be overridden after ClearLines.
  local name, link = self:GetItem()

  -- Just to be on the safe side...
  if not name or not link then return end


  -- The money frame is anchored to a blank line of the tootlip.
  -- Find out which line it is.
  local moneyFrameLineNumber = nil

  -- Check all shown money frames of the tooltip.
  -- (There is normally only one, except other addons have added more.)
  for i = 1, self.shownMoneyFrames, 1 do

    local moneyFrameName = self:GetName().."MoneyFrame"..i

    -- If the money frame's PrefixText is "SELL_PRICE:", we assume it is the one we are looking for.
    if _G[moneyFrameName.."PrefixText"]:GetText() == string.format("%s:", SELL_PRICE) then
      local _, moneyFrameAnchor = _G[moneyFrameName]:GetPoint(1)

      -- Get line number.
      moneyFrameLineNumber = tonumber(string.match(moneyFrameAnchor:GetName(), self:GetName().."TextLeft(%d+)"))

      break
    end

  end

  if not moneyFrameLineNumber then return end


  -- Store all text and text colours of the original tooltip lines.
  -- Unfortunately I do not know how to store the "indented word wrap".
  -- Therefore, we have to put wrap=true for all lines in the new tooltip
  -- except the title line which is never wrapped.
  local leftText = {}
  local leftTextR = {}
  local leftTextG = {}
  local leftTextB = {}

  local rightText = {}
  local rightTextR = {}
  local rightTextG = {}
  local rightTextB = {}

  -- Store the number of lines for after ClearLines().
  local numLines = self:NumLines()

  -- Store all lines of the original tooltip.
  for i = 1, numLines, 1 do
    leftText[i] = _G[self:GetName().."TextLeft"..i]:GetText()
    leftTextR[i], leftTextG[i], leftTextB[i] = _G[self:GetName().."TextLeft"..i]:GetTextColor()

    rightText[i] = _G[self:GetName().."TextRight"..i]:GetText()
    rightTextR[i], rightTextG[i], rightTextB[i] = _G[self:GetName().."TextRight"..i]:GetTextColor()
  end


  self:ClearLines()
  -- Got to override GameTooltip.GetItem(), such that other addons can still use it
  -- to learn which item is displayed. Will be restored after GameTooltip:OnHide() (see above).
  self.GetItem = function(self) return name, link end


  -- Never word wrap the title line!
  AddLineOrDoubleLine(self, leftText[1], rightText[1], leftTextR[1], leftTextG[1], leftTextB[1], rightTextR[1], rightTextG[1], rightTextB[1], false)

  -- Refill the tooltip with the stored lines except the money frame.
  for i = 2, moneyFrameLineNumber-1, 1 do
    AddLineOrDoubleLine(self, leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i], true)
  end

  for i = moneyFrameLineNumber+1, numLines, 1 do
    AddLineOrDoubleLine(self, leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i], true)
  end

end
)
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
11-03-20, 10:37 AM   #5
devilArt
A Wyrmkin Dreamwalker
 
devilArt's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 51
Originally Posted by LudiusMaximus View Post
You could

store all tooltip lines,
completely clear the tooltip,
reprint all tooltip lines except the money frame line.

Just after you clear, you have to temporarily override GameTooltip.GetItem such that other addons reading the tooltip afterwards can still get the original item name and link:


Code:
-- This will restore the original GetItem after the tooltip is closed.
local originalGetItem = GameTooltip.GetItem
GameTooltip:HookScript("OnHide", function(self)
  GameTooltip.GetItem = originalGetItem
end)


-- Function to reprint stored tooltip lines.
local function AddLineOrDoubleLine(tooltip, leftText, rightText, leftTextR, leftTextG, leftTextB, rightTextR, rightTextG, rightTextB, intendedWordWrap)
  if rightText then
    tooltip:AddDoubleLine(leftText, rightText, leftTextR, leftTextG, leftTextB, rightTextR, rightTextG, rightTextB)
  else
    tooltip:AddLine(leftText, leftTextR, leftTextG, leftTextB, intendedWordWrap)
  end
end
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)

  if not self.shownMoneyFrames then return end

  -- Store for GetItem to be overridden after ClearLines.
  local name, link = self:GetItem()

  -- Just to be on the safe side...
  if not name or not link then return end


  -- The money frame is anchored to a blank line of the tootlip.
  -- Find out which line it is.
  local moneyFrameLineNumber = nil

  -- Check all shown money frames of the tooltip.
  -- (There is normally only one, except other addons have added more.)
  for i = 1, self.shownMoneyFrames, 1 do

    local moneyFrameName = self:GetName().."MoneyFrame"..i

    -- If the money frame's PrefixText is "SELL_PRICE:", we assume it is the one we are looking for.
    if _G[moneyFrameName.."PrefixText"]:GetText() == string.format("%s:", SELL_PRICE) then
      local _, moneyFrameAnchor = _G[moneyFrameName]:GetPoint(1)

      -- Get line number.
      moneyFrameLineNumber = tonumber(string.match(moneyFrameAnchor:GetName(), self:GetName().."TextLeft(%d+)"))

      break
    end

  end

  if not moneyFrameLineNumber then return end


  -- Store all text and text colours of the original tooltip lines.
  -- Unfortunately I do not know how to store the "indented word wrap".
  -- Therefore, we have to put wrap=true for all lines in the new tooltip
  -- except the title line which is never wrapped.
  local leftText = {}
  local leftTextR = {}
  local leftTextG = {}
  local leftTextB = {}

  local rightText = {}
  local rightTextR = {}
  local rightTextG = {}
  local rightTextB = {}

  -- Store the number of lines for after ClearLines().
  local numLines = self:NumLines()

  -- Store all lines of the original tooltip.
  for i = 1, numLines, 1 do
    leftText[i] = _G[self:GetName().."TextLeft"..i]:GetText()
    leftTextR[i], leftTextG[i], leftTextB[i] = _G[self:GetName().."TextLeft"..i]:GetTextColor()

    rightText[i] = _G[self:GetName().."TextRight"..i]:GetText()
    rightTextR[i], rightTextG[i], rightTextB[i] = _G[self:GetName().."TextRight"..i]:GetTextColor()
  end


  self:ClearLines()
  -- Got to override GameTooltip.GetItem(), such that other addons can still use it
  -- to learn which item is displayed. Will be restored after GameTooltip:OnHide() (see above).
  self.GetItem = function(self) return name, link end


  -- Never word wrap the title line!
  AddLineOrDoubleLine(self, leftText[1], rightText[1], leftTextR[1], leftTextG[1], leftTextB[1], rightTextR[1], rightTextG[1], rightTextB[1], false)

  -- Refill the tooltip with the stored lines except the money frame.
  for i = 2, moneyFrameLineNumber-1, 1 do
    AddLineOrDoubleLine(self, leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i], true)
  end

  for i = moneyFrameLineNumber+1, numLines, 1 do
    AddLineOrDoubleLine(self, leftText[i], rightText[i], leftTextR[i], leftTextG[i], leftTextB[i], rightTextR[i], rightTextG[i], rightTextB[i], true)
  end

end
)
Thanks LudiusMaximus, your method is great 👍
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Quest about remove 'sell price' part from tooltip

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