View Single Post
07-26-13, 01:18 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you don't need the quest name immediately (eg. you can wait for OnTooltipSetQuest to happen) then that will work, though I'd suggest cleaning it up some. In no particular order:
  • Making a table in your slash command handler like that is pretty horrifying.
  • There's no need to set and un-set the script, since your code is the only code that's going to be setting hyperlinks to that tooltip. If you're worried about it, check the self.message value instead.
  • "self" isn't a very good thing to call the second arg passed to your slash handler, since that arg refers to the editbox the user typed the command in, and not to any "self" as used anywhere else in your addon.
  • You can cut the number of calls to string.format in half.
  • You should :Hide() your tooltip after getting the text.

Code:
local frame = CreateFrame("GameTooltip", "MyPrivateStuff_QuestInfoTooltipFrame", UIParent, "GameTooltipTemplate")

frame:SetScript("OnTooltipSetQuest", function(self)
	if not self.message then return end
	local title = MyPrivateStuff_QuestInfoTooltipFrameTextLeft1:GetText()
	self:Hide()
	DEFAULT_CHAT_FRAME:AddMessage(format(self.message, self.linkID, title))
	self.message, self.linkID = nil, nil
end

SLASH_MYPRIVATESTUFF1 = "/my"
SlashCmdList["MYPRIVATESTUFF"] = function(msg, editBox)
	local linkType, linkID = strsplit(" ", msg)
	if linkType == "quest" then
		if IsQuestFlaggedCompleted(linkID) then
			frame.message = "Quest |cffffff00|Hquest:%d|h[%%s]|h|r flagged as completed."
		else
			frame.message = "Quest |cffffff00|Hquest:%d|h[%%s]|h|r is not completed or not available to character."
		end
		frame.linkID = linkID
		DEFAULT_CHAT_FRAME:AddMessage("Retrieving quest information...")
		frame:SetOwner(UIParent, "ANCHOR_NONE")
		frame:SetHyperlink("quest:" .. linkID)
	else
		frame.message, frame.linkID = nil, nil
	end
end
Edit: You posted a revision while I was posting mine, but most of the above is (probably) still applicable. Also, either your new code should be throwing errors left and right because you're using argv in a scope where it's not defined, or that isn't your real code.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 07-26-13 at 01:21 AM.
  Reply With Quote