ItemRef.lua

ItemRef.lua (9.0.2.36037; unchanged since 9.0.1.35679)
  1. local function FormatLink(linkType, linkDisplayText, ...)
  2. local linkFormatTable = { ("|H%s"):format(linkType), ... };
  3. local returnLink = table.concat(linkFormatTable, ":");
  4. if linkDisplayText then
  5. return returnLink .. ("|h%s|h"):format(linkDisplayText);
  6. else
  7. return returnLink .. "|h";
  8. end
  9. end
  10. function SetItemRef(link, text, button, chatFrame)
  11. -- Going forward, use linkType and linkData instead of strsub and strsplit everywhere
  12. local linkType, linkData = ExtractLinkData(link);
  13. if ( strsub(link, 1, 6) == "player" ) then
  14. local namelink, isGMLink, isCommunityLink;
  15. if ( strsub(link, 7, 8) == "GM" ) then
  16. namelink = strsub(link, 10);
  17. isGMLink = true;
  18. elseif ( strsub(link, 7, 15) == "Community") then
  19. namelink = strsub(link, 17);
  20. isCommunityLink = true;
  21. else
  22. namelink = strsub(link, 8);
  23. end
  24. local name, lineID, chatType, chatTarget, communityClubID, communityStreamID, communityEpoch, communityPosition;
  25. if ( isCommunityLink ) then
  26. name, communityClubID, communityStreamID, communityEpoch, communityPosition = strsplit(":", namelink);
  27. else
  28. name, lineID, chatType, chatTarget = strsplit(":", namelink);
  29. end
  30. if ( name and (strlen(name) > 0) ) then
  31. if ( IsModifiedClick("CHATLINK") ) then
  32. local staticPopup;
  33. staticPopup = StaticPopup_Visible("ADD_IGNORE");
  34. if ( staticPopup ) then
  35. -- If add ignore dialog is up then enter the name into the editbox
  36. _G[staticPopup.."EditBox"]:SetText(name);
  37. return;
  38. end
  39. staticPopup = StaticPopup_Visible("ADD_FRIEND");
  40. if ( staticPopup ) then
  41. -- If add ignore dialog is up then enter the name into the editbox
  42. _G[staticPopup.."EditBox"]:SetText(name);
  43. return;
  44. end
  45. staticPopup = StaticPopup_Visible("ADD_GUILDMEMBER");
  46. if ( staticPopup ) then
  47. -- If add ignore dialog is up then enter the name into the editbox
  48. _G[staticPopup.."EditBox"]:SetText(name);
  49. return;
  50. end
  51. staticPopup = StaticPopup_Visible("CHANNEL_INVITE");
  52. if ( staticPopup ) then
  53. _G[staticPopup.."EditBox"]:SetText(name);
  54. return;
  55. end
  56. if ( ChatEdit_GetActiveWindow() ) then
  57. ChatEdit_InsertLink(name);
  58. else
  59. C_FriendList.SendWho(WHO_TAG_EXACT..name);
  60. end
  61. elseif ( button == "RightButton" and (not isGMLink) ) then
  62. FriendsFrame_ShowDropdown(name, 1, lineID, chatType, chatFrame, nil, nil, communityClubID, communityStreamID, communityEpoch, communityPosition);
  63. else
  64. ChatFrame_SendTell(name, chatFrame);
  65. end
  66. end
  67. return;
  68. elseif ( strsub(link, 1, 8) == "BNplayer" ) then
  69. local namelink, isCommunityLink;
  70. if ( strsub(link, 9, 17) == "Community" ) then
  71. namelink = strsub(link, 19);
  72. isCommunityLink = true;
  73. else
  74. namelink = strsub(link, 10);
  75. end
  76. local name, bnetIDAccount, lineID, chatType, chatTarget, communityClubID, communityStreamID, communityEpoch, communityPosition;
  77. if ( isCommunityLink ) then
  78. name, bnetIDAccount, communityClubID, communityStreamID, communityEpoch, communityPosition = strsplit(":", namelink);
  79. else
  80. name, bnetIDAccount, lineID, chatType, chatTarget = strsplit(":", namelink);
  81. end
  82. if ( name and (strlen(name) > 0) ) then
  83. if ( IsModifiedClick("CHATLINK") ) then
  84. -- Disable SHIFT-CLICK for battlenet friends, so we don't put an encoded bnetIDAccount in chat
  85. elseif ( button == "RightButton" ) then
  86. if ( isCommunityLink or not BNIsSelf(bnetIDAccount) ) then
  87. FriendsFrame_ShowBNDropdown(name, 1, nil, chatType, chatFrame, nil, bnetIDAccount, communityClubID, communityStreamID, communityEpoch, communityPosition);
  88. end
  89. else
  90. if ( BNIsFriend(bnetIDAccount)) then
  91. ChatFrame_SendBNetTell(name);
  92. else
  93. local displayName = BNGetDisplayName(bnetIDAccount);
  94. ChatFrame_SendBNetTell(displayName)
  95. end
  96. end
  97. end
  98. return;
  99. elseif ( strsub(link, 1, 7) == "channel" ) then
  100. if ( IsModifiedClick("CHATLINK") ) then
  101. local chanLink = strsub(link, 9);
  102. local chatType, chatTarget = strsplit(":", chanLink);
  103. ChannelFrame:Toggle();
  104. elseif ( button == "LeftButton" ) then
  105. local chanLink = strsub(link, 9);
  106. local chatType, chatTarget = strsplit(":", chanLink);
  107. if ( strupper(chatType) == "CHANNEL" ) then
  108. if ( GetChannelName(tonumber(chatTarget))~=0 ) then
  109. ChatFrame_OpenChat("/"..chatTarget, chatFrame);
  110. end
  111. elseif ( strupper(chatType) == "PET_BATTLE_COMBAT_LOG" or strupper(chatType) == "PET_BATTLE_INFO" ) then
  112. --Don't do anything
  113. else
  114. ChatFrame_OpenChat("/"..chatType, chatFrame);
  115. end
  116. elseif ( button == "RightButton" ) then
  117. local chanLink = strsub(link, 9);
  118. local chatType, chatTarget = strsplit(":", chanLink);
  119. if not ( (strupper(chatType) == "CHANNEL" and GetChannelName(tonumber(chatTarget)) == 0) ) then --Don't show the dropdown if this is a channel we are no longer in.
  120. ChatChannelDropDown_Show(chatFrame, strupper(chatType), chatTarget, Chat_GetColoredChatName(strupper(chatType), chatTarget));
  121. end
  122. end
  123. return;
  124. elseif ( strsub(link, 1, 6) == "GMChat" ) then
  125. GMChatStatusFrame_OnClick();
  126. return;
  127. elseif ( strsub(link, 1, 7) == "levelup" ) then
  128. local _, level, levelUpType, arg1 = strsplit(":", link);
  129. LevelUpDisplay_ShowSideDisplay(tonumber(level), _G[levelUpType], arg1);
  130. return;
  131. elseif ( strsub(link, 1, 6) == "pvpbgs" ) then
  132. TogglePVPUI();
  133. return;
  134. elseif ( strsub(link, 1, 12) == "battleground" ) then
  135. PVEFrame_ShowFrame("PVPUIFrame", HonorFrame);
  136. HonorFrame_SetType("specific");
  137. local _, bgID = strsplit(":", link);
  138. HonorFrameSpecificList_FindAndSelectBattleground(tonumber(bgID));
  139. return;
  140. elseif ( strsub(link, 1, 3) == "lfd" ) then
  141. ToggleLFDParentFrame();
  142. return;
  143. elseif ( strsub(link, 1, 8) == "specpane" ) then
  144. ToggleTalentFrame(SPECIALIZATION_TAB);
  145. return;
  146. elseif ( strsub(link, 1, 10) == "talentpane" ) then
  147. ToggleTalentFrame(TALENTS_TAB);
  148. return;
  149. elseif ( strsub(link, 1, 14) == "mountequipment" ) then
  150. ToggleCollectionsJournal(1);
  151. return;
  152. elseif ( strsub(link, 1, 11) == "honortalent" ) then
  153. ToggleTalentFrame(PVP_TALENTS_TAB);
  154. return;
  155. elseif ( strsub(link, 1, 10) == "worldquest" ) then
  156. OpenWorldMap();
  157. return;
  158. elseif ( strsub(link, 1, 7) == "journal" ) then
  159. if ( not HandleModifiedItemClick(GetFixedLink(text)) ) then
  160. if ( not EncounterJournal ) then
  161. EncounterJournal_LoadUI();
  162. end
  163. EncounterJournal_OpenJournalLink(strsplit(":", link));
  164. end
  165. return;
  166. elseif ( strsub(link, 1, 8) == "urlIndex" ) then
  167. local _, index = strsplit(":", link);
  168. LoadURLIndex(tonumber(index));
  169. return;
  170. elseif ( strsub(link, 1, 11) == "lootHistory" ) then
  171. local _, rollID = strsplit(":", link);
  172. LootHistoryFrame_ToggleWithRoll(LootHistoryFrame, tonumber(rollID), chatFrame);
  173. return;
  174. elseif ( strsub(link, 1, 13) == "battlePetAbil" ) then
  175. local _, abilityID, maxHealth, power, speed = strsplit(":", link);
  176. if ( IsModifiedClick() ) then
  177. local fixedLink = GetFixedLink(text);
  178. HandleModifiedItemClick(fixedLink);
  179. else
  180. FloatingPetBattleAbility_Show(tonumber(abilityID), tonumber(maxHealth), tonumber(power), tonumber(speed));
  181. end
  182. return;
  183. elseif ( strsub(link, 1, 9) == "battlepet" ) then
  184. local _, speciesID, level, breedQuality, maxHealth, power, speed, battlePetID = strsplit(":", link);
  185. if ( IsModifiedClick() ) then
  186. local fixedLink = GetFixedLink(text, tonumber(breedQuality));
  187. HandleModifiedItemClick(fixedLink);
  188. else
  189. FloatingBattlePet_Toggle(tonumber(speciesID), tonumber(level), tonumber(breedQuality), tonumber(maxHealth), tonumber(power), tonumber(speed), string.gsub(string.gsub(text, "^(.*)%[", ""), "%](.*)$", ""), battlePetID);
  190. end
  191. return;
  192. elseif ( strsub(link, 1, 19) == "garrfollowerability" ) then
  193. local _, garrFollowerAbilityID = strsplit(":", link);
  194. if ( IsModifiedClick() ) then
  195. local fixedLink = GetFixedLink(text);
  196. HandleModifiedItemClick(fixedLink);
  197. else
  198. FloatingGarrisonFollowerAbility_Toggle(tonumber(garrFollowerAbilityID));
  199. end
  200. return;
  201. elseif ( strsub(link, 1, 12) == "garrfollower" ) then
  202. local _, garrisonFollowerID, quality, level, itemLevel, ability1, ability2, ability3, ability4, trait1, trait2, trait3, trait4, spec1 = strsplit(":", link);
  203. if ( IsModifiedClick() ) then
  204. local fixedLink = GetFixedLink(text, tonumber(quality));
  205. HandleModifiedItemClick(fixedLink);
  206. else
  207. FloatingGarrisonFollower_Toggle(tonumber(garrisonFollowerID), tonumber(quality), tonumber(level), tonumber(itemLevel), tonumber(spec1), tonumber(ability1), tonumber(ability2), tonumber(ability3), tonumber(ability4), tonumber(trait1), tonumber(trait2), tonumber(trait3), tonumber(trait4));
  208. end
  209. return;
  210. elseif ( strsub(link, 1, 11) == "garrmission" ) then
  211. local _, garrMissionID = strsplit(":", link);
  212. local garrMissionID, garrMissionDBID = link:match("garrmission:(%d+):([0-9a-fA-F]+)")
  213. if (garrMissionID and garrMissionDBID and strlen(garrMissionDBID) == 16) then
  214. if ( IsModifiedClick() ) then
  215. local fixedLink = GetFixedLink(text);
  216. HandleModifiedItemClick(fixedLink);
  217. else
  218. FloatingGarrisonMission_Toggle(tonumber(garrMissionID), "0x"..(garrMissionDBID:upper()));
  219. end
  220. end
  221. return;
  222. elseif ( strsub(link, 1, 5) == "death" ) then
  223. local _, id = strsplit(":", link);
  224. OpenDeathRecapUI(id);
  225. return;
  226. elseif ( strsub(link, 1, 7) == "sharess" ) then
  227. local _, index = strsplit(":", link);
  228. SocialFrame_LoadUI();
  229. Social_ShowScreenshot(tonumber(index));
  230. return;
  231. elseif ( strsub(link, 1, 12) == "shareachieve" ) then
  232. local _, achievementID, earned = strsplit(":", link);
  233. SocialFrame_LoadUI();
  234. Social_ShowAchievement(tonumber(achievementID), StringToBoolean(earned));
  235. return;
  236. elseif ( strsub(link, 1, 9) == "shareitem" ) then
  237. local strippedItemLink, earned = link:match("^shareitem:(.-):(%d+)$");
  238. local itemLink = FormatLink("item", nil, strippedItemLink);
  239. SocialFrame_LoadUI();
  240. Social_ShowItem(itemLink, earned);
  241. return;
  242. elseif ( strsub(link, 1, 16) == "transmogillusion" ) then
  243. local fixedLink = GetFixedLink(text);
  244. if ( not HandleModifiedItemClick(fixedLink) ) then
  245. DressUpTransmogLink(link);
  246. end
  247. return;
  248. elseif ( strsub(link, 1, 18) == "transmogappearance" ) then
  249. if ( IsModifiedClick("CHATLINK") ) then
  250. local _, sourceID = strsplit(":", link);
  251. local itemLink = select(6, C_TransmogCollection.GetAppearanceSourceInfo(sourceID));
  252. HandleModifiedItemClick(itemLink);
  253. else
  254. if ( not CollectionsJournal ) then
  255. CollectionsJournal_LoadUI();
  256. end
  257. if ( CollectionsJournal ) then
  258. WardrobeCollectionFrame_OpenTransmogLink(link);
  259. end
  260. end
  261. return;
  262. elseif ( strsub(link, 1, 11) == "transmogset" ) then
  263. if ( not CollectionsJournal ) then
  264. CollectionsJournal_LoadUI();
  265. end
  266. if ( CollectionsJournal ) then
  267. WardrobeCollectionFrame_OpenTransmogLink(link);
  268. end
  269. return;
  270. elseif ( strsub(link, 1, 3) == "api" ) then
  271. APIDocumentation_LoadUI();
  272. local command = APIDocumentation.Commands.Default;
  273. if button == "RightButton" then
  274. command = APIDocumentation.Commands.CopyAPI;
  275. elseif IsModifiedClick("CHATLINK") then
  276. command = APIDocumentation.Commands.OpenDump;
  277. end
  278. APIDocumentation:HandleAPILink(link, command);
  279. return;
  280. elseif ( strsub(link, 1, 13) == "storecategory" ) then
  281. local _, category = strsplit(":", link);
  282. if category == "token" then
  283. StoreFrame_SetTokenCategory();
  284. ToggleStoreUI();
  285. elseif category == "games" then
  286. StoreFrame_OpenGamesCategory();
  287. elseif category == "services" then
  288. StoreFrame_SetServicesCategory();
  289. ToggleStoreUI();
  290. elseif category == "gametime" then
  291. StoreFrame_OpenGameTimeCategory();
  292. end
  293. elseif ( strsub(link, 1, 4) == "item" ) then
  294. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  295. local name, link = GetItemInfo(text);
  296. if ChatEdit_InsertLink(link) then
  297. return;
  298. end
  299. end
  300. elseif ( strsub(link, 1, 10) == "clubTicket" ) then
  301. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  302. if ChatEdit_InsertLink(text) then
  303. return;
  304. end
  305. end
  306. local _, ticketId = strsplit(":", link);
  307. if ( CommunitiesFrame_IsEnabled() ) then
  308. Communities_LoadUI();
  309. CommunitiesHyperlink.OnClickLink(ticketId);
  310. end
  311. return;
  312. elseif ( strsub(link, 1, 13) == "calendarEvent" ) then
  313. local _, monthOffset, monthDay, index = strsplit(":", link);
  314. local dayEvent = C_Calendar.GetDayEvent(monthOffset, monthDay, index);
  315. if dayEvent then
  316. Calendar_LoadUI();
  317. if not CalendarFrame:IsShown() then
  318. Calendar_Toggle();
  319. end
  320. C_Calendar.OpenEvent(monthOffset, monthDay, index);
  321. end
  322. return;
  323. elseif ( strsub(link, 1, 9) == "community" ) then
  324. if ( CommunitiesFrame_IsEnabled() ) then
  325. local _, clubId = strsplit(":", link);
  326. clubId = tonumber(clubId);
  327. Communities_LoadUI();
  328. CommunitiesHyperlink.OnClickReference(clubId);
  329. end
  330. return;
  331. elseif ( strsub(link, 1, 9) == "azessence" ) then
  332. if ChatEdit_InsertLink(link) then
  333. return;
  334. end
  335. elseif ( strsub(link, 1, 10) == "clubFinder" ) then
  336. if ( IsModifiedClick("CHATLINK") and button == "LeftButton" ) then
  337. if ChatEdit_InsertLink(text) then
  338. return;
  339. end
  340. end
  341. Communities_LoadUI();
  342. local _, clubFinderId = strsplit(":", link);
  343. CommunitiesFrame:ClubFinderHyperLinkClicked(clubFinderId);
  344. return;
  345. elseif ( strsub(link, 1, 8) == "worldmap" ) then
  346. local waypoint = C_Map.GetUserWaypointFromHyperlink(link);
  347. if waypoint then
  348. C_Map.SetUserWaypoint(waypoint);
  349. OpenWorldMap(waypoint.uiMapID);
  350. end
  351. return;
  352. end
  353. if ( IsModifiedClick() ) then
  354. local fixedLink = GetFixedLink(text);
  355. HandleModifiedItemClick(fixedLink);
  356. else
  357. local itemName, itemLink = ItemRefTooltip:GetItem();
  358. if itemLink == GetFixedLink(text) then
  359. HideUIPanel(ItemRefTooltip);
  360. else
  361. ShowUIPanel(ItemRefTooltip);
  362. if ( not ItemRefTooltip:IsShown() ) then
  363. ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
  364. end
  365. ItemRefTooltip:ItemRefSetHyperlink(link);
  366. end
  367. end
  368. end
  369. function GetFixedLink(text, quality)
  370. local startLink = strfind(text, "|H");
  371. if ( not strfind(text, "|c") ) then
  372. if ( quality ) then
  373. return (gsub(text, "(|H.+|h.+|h)", ITEM_QUALITY_COLORS[quality].hex.."%1|r", 1));
  374. elseif ( strsub(text, startLink + 2, startLink + 6) == "quest" ) then
  375. --We'll always color it yellow. We really need to fix this for Cata. (It will appear the correct color in the chat log)
  376. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  377. elseif ( strsub(text, startLink + 2, startLink + 12) == "achievement" ) then
  378. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  379. elseif ( strsub(text, startLink + 2, startLink + 7) == "talent" ) then
  380. return (gsub(text, "(|H.+|h.+|h)", "|cff4e96f7%1|r", 1));
  381. elseif ( strsub(text, startLink + 2, startLink + 6) == "trade" ) then
  382. return (gsub(text, "(|H.+|h.+|h)", "|cffffd000%1|r", 1));
  383. elseif ( strsub(text, startLink + 2, startLink + 8) == "enchant" ) then
  384. return (gsub(text, "(|H.+|h.+|h)", "|cffffd000%1|r", 1));
  385. elseif ( strsub(text, startLink + 2, startLink + 13) == "instancelock" ) then
  386. return (gsub(text, "(|H.+|h.+|h)", "|cffff8000%1|r", 1));
  387. elseif ( strsub(text, startLink + 2, startLink + 8) == "journal" ) then
  388. return (gsub(text, "(|H.+|h.+|h)", "|cff66bbff%1|r", 1));
  389. elseif ( strsub(text, startLink + 2, startLink + 14) == "battlePetAbil" ) then
  390. return (gsub(text, "(|H.+|h.+|h)", "|cff4e96f7%1|r", 1));
  391. elseif ( strsub(text, startLink + 2, startLink + 10) == "battlepet" ) then
  392. return (gsub(text, "(|H.+|h.+|h)", "|cffffd200%1|r", 1)); -- s_defaultColorString (yellow)
  393. elseif ( strsub(text, startLink + 2, startLink + 12) == "garrmission" ) then
  394. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  395. elseif ( strsub(text, startLink + 2, startLink + 17) == "transmogillusion" ) then
  396. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  397. elseif ( strsub(text, startLink + 2, startLink + 19) == "transmogappearance" ) then
  398. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  399. elseif ( strsub(text, startLink + 2, startLink + 12) == "transmogset" ) then
  400. return (gsub(text, "(|H.+|h.+|h)", "|cffff80ff%1|r", 1));
  401. elseif ( strsub(text, startLink + 2, startLink + 9) == "worldmap" ) then
  402. return (gsub(text, "(|H.+|h.+|h)", "|cffffff00%1|r", 1));
  403. end
  404. end
  405. --Nothing to change.
  406. return text;
  407. end
  408. function GetBattlePetAbilityHyperlink(abilityID, maxHealth, power, speed)
  409. local id, name = C_PetBattles.GetAbilityInfoByID(abilityID);
  410. if not name then
  411. GMError("Attempt to link ability when we don't have record.");
  412. return "";
  413. end
  414. return ("|cff4e96f7%s|r"):format(FormatLink("battlePetAbil", name, abilityID, maxHealth or 100, power or 0, speed or 0));
  415. end
  416. function GetPlayerLink(characterName, linkDisplayText, lineID, chatType, chatTarget)
  417. -- Use simplified link if possible
  418. if lineID or chatType or chatTarget then
  419. return FormatLink("player", linkDisplayText, characterName, lineID or 0, chatType or 0, chatTarget or "");
  420. else
  421. return FormatLink("player", linkDisplayText, characterName);
  422. end
  423. end
  424. function GetBNPlayerLink(name, linkDisplayText, bnetIDAccount, lineID, chatType, chatTarget)
  425. return FormatLink("BNplayer", linkDisplayText, name, bnetIDAccount, lineID or 0, chatType, chatTarget);
  426. end
  427. function GetGMLink(gmName, linkDisplayText, lineID)
  428. if lineID then
  429. return FormatLink("playerGM", linkDisplayText, gmName, lineID or 0);
  430. else
  431. return FormatLink("playerGM", linkDisplayText, gmName);
  432. end
  433. end
  434. local function SanitizeCommunityData(clubId, streamId, epoch, position)
  435. if type(clubId) == "number" then
  436. clubId = ("%.f"):format(clubId);
  437. end
  438. if type(streamId) == "number" then
  439. streamId = ("%.f"):format(streamId);
  440. end
  441. epoch = ("%.f"):format(epoch);
  442. position = ("%.f"):format(position);
  443. return clubId, streamId, epoch, position;
  444. end
  445. function GetBNPlayerCommunityLink(playerName, linkDisplayText, bnetIDAccount, clubId, streamId, epoch, position)
  446. clubId, streamId, epoch, position = SanitizeCommunityData(clubId, streamId, epoch, position);
  447. return FormatLink("BNplayerCommunity", linkDisplayText, playerName, bnetIDAccount, clubId, streamId, epoch, position);
  448. end
  449. function GetPlayerCommunityLink(playerName, linkDisplayText, clubId, streamId, epoch, position)
  450. clubId, streamId, epoch, position = SanitizeCommunityData(clubId, streamId, epoch, position);
  451. return FormatLink("playerCommunity", linkDisplayText, playerName, clubId, streamId, epoch, position);
  452. end
  453. function GetClubTicketLink(ticketId, clubName, clubType)
  454. local link = FormatLink("clubTicket", CLUB_INVITE_HYPERLINK_TEXT:format(clubName), ticketId);
  455. if clubType == Enum.ClubType.BattleNet then
  456. return BATTLENET_FONT_COLOR:WrapTextInColorCode(link);
  457. else
  458. return NORMAL_FONT_COLOR:WrapTextInColorCode(link);
  459. end
  460. end
  461. function GetClubFinderLink(clubFinderId, clubName)
  462. local clubType = C_ClubFinder.GetClubTypeFromFinderGUID(clubFinderId);
  463. local fontColor = NORMAL_FONT_COLOR;
  464. local linkGlobalString;
  465. if(clubType == Enum.ClubFinderRequestType.Guild) then
  466. linkGlobalString = CLUB_FINDER_LINK_GUILD;
  467. elseif(clubType == Enum.ClubFinderRequestType.Community) then
  468. linkGlobalString = CLUB_FINDER_LINK_COMMUNITY;
  469. fontColor = BATTLENET_FONT_COLOR;
  470. else
  471. linkGlobalString = ""
  472. end
  473. return fontColor:WrapTextInColorCode(FormatLink("clubFinder", linkGlobalString:format(clubName), clubFinderId));
  474. end
  475. function GetCalendarEventLink(monthOffset, monthDay, index)
  476. local dayEvent = C_Calendar.GetDayEvent(monthOffset, monthDay, index);
  477. if dayEvent then
  478. return FormatLink("calendarEvent", dayEvent.title, monthOffset, monthDay, index);
  479. end
  480. return nil;
  481. end
  482. function GetCommunityLink(clubId)
  483. local clubInfo = C_Club.GetClubInfo(clubId);
  484. if clubInfo then
  485. local link = FormatLink("community", COMMUNITY_REFERENCE_FORMAT:format(clubInfo.name), clubId);
  486. if clubInfo.clubType == Enum.ClubType.BattleNet then
  487. return BATTLENET_FONT_COLOR:WrapTextInColorCode(link);
  488. else
  489. return NORMAL_FONT_COLOR:WrapTextInColorCode(link);
  490. end
  491. end
  492. return nil;
  493. end
  494. LinkUtil = {};
  495. function LinkUtil.SplitLink(link) -- returns linkText and displayText
  496. return link:match("^|H(.+)|h(.*)|h$");
  497. end
  498. -- Extract the first link from the text given, ignoring leading and trailing characters.
  499. -- returns linkType, linkOptions, displayText
  500. function LinkUtil.ExtractLink(text)
  501. -- linkType: |H([^:]*): matches everything that's not a colon, up to the first colon.
  502. -- linkOptions: ([^|]*)|h matches everything that's not a |, up to the first |h.
  503. -- displayText: ([^|]*)|h matches everything that's not a |, up to the second |h.
  504. -- Ex: |cffffffff|Htype:a:b:c:d|htext|h|r becomes type, a:b:c:d, text
  505. return string.match(text, [[|H([^:]*):([^|]*)|h([^|]*)|h]]);
  506. end
  507. function LinkUtil.IsLinkType(link, matchLinkType)
  508. local linkType, linkOptions, displayText = LinkUtil.ExtractLink(link);
  509. return linkType == matchLinkType;
  510. end
  511. ItemRefTooltipMixin = {};
  512. function ItemRefTooltipMixin:OnLoad()
  513. GameTooltip_OnLoad(self);
  514. self:RegisterForDrag("LeftButton");
  515. self.shoppingTooltips = { ItemRefShoppingTooltip1, ItemRefShoppingTooltip2 };
  516. self.updateTooltipTime = 0;
  517. self.UpdateTooltip = function(self, elapsed)
  518. if ( IsModifiedClick("COMPAREITEMS") ) then
  519. self.updateTooltipTime = self.updateTooltipTime - elapsed;
  520. if ( self.updateTooltipTime > 0 ) then
  521. return;
  522. end
  523. self.updateTooltipTime = TOOLTIP_UPDATE_TIME;
  524. GameTooltip_ShowCompareItem(self);
  525. else
  526. for _, frame in pairs(self.shoppingTooltips) do
  527. frame:Hide();
  528. end
  529. self.needsReset = true;
  530. self.comparing = false;
  531. end
  532. end
  533. end
  534. function ItemRefTooltipMixin:OnTooltipSetItem()
  535. self.updateTooltipTime = 0;
  536. if ( IsModifiedClick("COMPAREITEMS") and self:IsMouseOver() ) then
  537. GameTooltip_ShowCompareItem(self);
  538. end
  539. end
  540. function ItemRefTooltipMixin:OnDragStart()
  541. self:StartMoving();
  542. end
  543. function ItemRefTooltipMixin:OnDragStop()
  544. self:StopMovingOrSizing();
  545. ValidateFramePosition(self);
  546. if ( IsModifiedClick("COMPAREITEMS") ) then --We do this to choose where the comparison is shown
  547. GameTooltip_ShowCompareItem(self);
  548. end
  549. end
  550. function ItemRefTooltipMixin:OnEnter()
  551. self.updateTooltipTime = 0;
  552. self:SetScript("OnUpdate", self.UpdateTooltip);
  553. end
  554. function ItemRefTooltipMixin:OnLeave()
  555. for _, frame in pairs(self.shoppingTooltips) do
  556. frame:Hide();
  557. end
  558. self:SetScript("OnUpdate", nil);
  559. end
  560. function ItemRefTooltipMixin:OnHide()
  561. GameTooltip_OnHide(self);
  562. --While it is true that OnUpdate won't fire while the frame is hidden, we don't want to have to check-and-unregister when we show it
  563. self:SetScript("OnUpdate", nil);
  564. end
  565. function ItemRefTooltipMixin:ItemRefSetHyperlink(link)
  566. self:SetPadding(0, 0);
  567. self:SetHyperlink(link);
  568. local title = _G[self:GetName().."TextLeft1"];
  569. if ( title and title:GetRight() - self.CloseButton:GetLeft() > 0 ) then
  570. local xPadding = 16;
  571. self:SetPadding(xPadding, 0);
  572. end
  573. end