Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-25-10, 02:19 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
gsub'ing |t and stuff

Okay so i added raid icons to the tooltip text. Now i may have gone about this all wrong but it works, and fairly well. I had to do a lot of extra gsubs because when you gsub just lastricon it leaves a big blank space... if you gsub |t it then prints the file path to the text. Is there a way to shorten up the gsubing that i did? why do some characters not gsub without another? like why in order to gsub a \ you have to do \\ hmm? this is what my code looks like curious what input everyone has.

It adds raid icons to the tooltip and updates when you add remove them, its hooked to the OnUpdate of the GameToolTip. This is especially nice because i use mouseover raid target icon setting macros.

Code:
local lastricon = 1
function addon:AddRaidIcon(self)
	if addon.settings.showRaidIcon then
		local name, unit = self:GetUnit()
		if unit then
			local text = GameTooltipTextLeft1:GetText()
			if text then
				local ricon = GetRaidTargetIndex(unit)
				if ricon then
					if lastricon ~= 1 then
						text = gsub(text, "|T", "")
						text = gsub(text, lastricon.."::", "")
						text = gsub(text, addon.settings.tooltipIconSize / 10, "")
						text = gsub(text, "Interface", "")
						text = gsub(text, "TargetingFrame", "")
						text = gsub(text, "\\", "")
						text = gsub(text, "UI", "")
						text = gsub(text, "RaidTargetingIcon", "")
						text = gsub(text, "-", "")
						text = gsub(text, "_", "")
						text = gsub(text, " ", "", 1)
					end
					lastricon = ricon
					if not text:find(ricon) then
						GameTooltipTextLeft1:SetText(("|t%s:%s|t %s"):format(ICON_LIST[ricon], addon.settings.tooltipIconSize / 10, text))
					GameTooltip:Show()
					end
				end
				if not ricon or ricon == nil then
					if lastricon ~= 1 then 
						text = gsub(text, "|T", "")
						text = gsub(text, lastricon.."::", "")
						text = gsub(text, addon.settings.tooltipIconSize / 10, "")
						text = gsub(text, "Interface", "")
						text = gsub(text, "TargetingFrame", "")
						text = gsub(text, "\\", "")
						text = gsub(text, "UI", "")
						text = gsub(text, "RaidTargetingIcon", "")
						text = gsub(text, "-", "")
						text = gsub(text, "_", "")
						text = gsub(text, " ", "", 1)
						GameTooltipTextLeft1:SetText(("%s"):format(text))
						lastricon = 1
						GameTooltip:Show()
					end
				end
			end
		end
	end
end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » gsub'ing |t and stuff


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