Quantcast
gsub'ing |t and stuff - WoWInterface
Thread Tools Display Modes
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
11-25-10, 04:29 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Without knowing what you're trying to extract, and not wanting to reverse-engineer it from the gsub() mess, the only thing I can offer is a simplification of your if-nesting mess:

Code:
local lastricon = 1

function addon:AddRaidIcon(self)
	if not addon.settings.showRaidIcon then
		return
	end
	local name, unit = self:GetUnit()

	if not unit then
		return
	end
	local text = GameTooltipTextLeft1:GetText()

	if not text then
		return
	end
	local ricon = GetRaidTargetIndex(unit)

	if not ricon then
		return
	end

	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

	if not 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)
			GameTooltipTextLeft1:SetText(("%s"):format(text))
			lastricon = 1
			GameTooltip:Show()
		end
	end
end
The only other change I made was getting rid of "or ricon == nil", since "not ricon" already achieves this. I'm also unsure of the overall logic, since you check for something, show the GameTooltip, then check for something else and show GameTooltip again.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
11-25-10, 04:42 AM   #3
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
if your gsub above removes a texture... like

|TTexturePaththerjunk:morejunk|t

is what your trying to remove, just do a

text = text:gsub("\124T.*\124t", "")

that removes the |T and |t and everything in between
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-25-10, 07:18 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Xubera View Post
if your gsub above removes a texture... like

|TTexturePaththerjunk:morejunk|t

is what your trying to remove, just do a

text = text:gsub("\124T.*\124t", "")

that removes the |T and |t and everything in between
BINGO

Thats exactly what its doing, removing the icon texture and all the garble in between. Thanks.

Torhal - I love how you refer to it all as a mess
The reason you do the gametooltip:show more then once is to make it update the gametooltip's size according to if the icon is shown or not, and since you can keep the cursor over a target and add/remove raid icons you need the size to update without cursoring off of the target. Best way i found to do that was to just make it show tooltip again. Another way although i could not get it to work is to get it the gametooltip onupdate script again but i tried get script and just running bliz's function and it did not work like one would think.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 11-25-10 at 08:14 AM.
  Reply With Quote
11-25-10, 01:47 PM   #5
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
Originally Posted by Xubera View Post
if your gsub above removes a texture... like

|TTexturePaththerjunk:morejunk|t

is what your trying to remove, just do a

text = text:gsub("\124T.*\124t", "")

that removes the |T and |t and everything in between
Careful there. You should use

text = text:gsub("\124T.-\124t", "")

instead to capture the smallest possible amount of text between |T and |t. This is because .* captures the longest possible amount of text and if the text contains 2 texture links, you will get rid of all the text between the 2 textures.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
11-25-10, 02:10 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Xinhuan View Post
Careful there. You should use

text = text:gsub("\124T.-\124t", "")

instead to capture the smallest possible amount of text between |T and |t. This is because .* captures the longest possible amount of text and if the text contains 2 texture links, you will get rid of all the text between the 2 textures.
So what your saying is if i had two icons at either end of the text line it would get rid of everything? For the moment this is not the case but i was going to add char portraits to the tooltips which then maybe will have two textures in one text line...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
11-25-10, 05:09 PM   #7
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
Yes, that's exactly what I am saying.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
11-26-10, 04:53 AM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Grimsin View Post
<snip>

Torhal - I love how you refer to it all as a mess
<snip>
Sorry - I'd just woken up and my extended vocabulary hadn't yet kicked in.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
11-26-10, 11:48 AM   #9
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
i thought .+ meant it was the longest possible string

edit::

oh .+ is 1 or more
.* is 0 or more, but the longest
.- is 0 or more, but the shortest.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

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

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