WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Quest about remove 'sell price' part from tooltip (https://www.wowinterface.com/forums/showthread.php?t=58359)

devilArt 11-01-20 09:34 PM

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?

Seerah 11-02-20 03:34 PM

Did you try calling GameTooltip:Show() afterward?

devilArt 11-02-20 08:44 PM

Quote:

Originally Posted by Seerah (Post 337484)
Did you try calling GameTooltip:Show() afterward?

thanks for help Seerah, but GameTooltip:Show() dosent work :(

LudiusMaximus 11-03-20 02:55 AM

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
)


devilArt 11-03-20 10:37 AM

Quote:

Originally Posted by LudiusMaximus (Post 337489)
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 👍


All times are GMT -6. The time now is 06:11 AM.

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