ChatFrame.lua

ChatFrame.lua (9.0.2.37176; unchanged since 9.0.2.36665)
  1. local forceinsecure = forceinsecure;
  2. MESSAGE_SCROLLBUTTON_INITIAL_DELAY = 0;
  3. MESSAGE_SCROLLBUTTON_SCROLL_DELAY = 0.05;
  4. CHAT_BUTTON_FLASH_TIME = 0.5;
  5. CHAT_TELL_ALERT_TIME = 300;
  6. NUM_CHAT_WINDOWS = 10;
  7. DEFAULT_CHAT_FRAME = ChatFrame1;
  8. CHAT_FOCUS_OVERRIDE = nil;
  9. NUM_REMEMBERED_TELLS = 10;
  10. MAX_WOW_CHAT_CHANNELS = 20;
  11. MAX_COUNTDOWN_SECONDS = 3600; -- One Hour
  12. CHAT_TIMESTAMP_FORMAT = nil; -- gets set from Interface Options
  13. CHAT_SHOW_IME = false;
  14. MAX_CHARACTER_NAME_BYTES = 305;
  15. --DEBUG FIXME FOR TESTING
  16. CHAT_OPTIONS = {
  17. ONE_EDIT_AT_A_TIME = "old"
  18. };
  19. -- Table for event indexed chatFilters.
  20. -- Format ["CHAT_MSG_SYSTEM"] = { function1, function2, function3 }
  21. -- filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 = function1 (self, event, ...) if filter then return true end return false, ... end
  22. local chatFilters = {};
  23. -- These hash tables are to improve performance of common lookups
  24. -- if you change what these tables point to (ie slash command, emote, chat)
  25. -- then you need to invalidate the entry in the hash table
  26. local hash_SecureCmdList = {}
  27. --Note: These need to remain global for AddOns
  28. hash_SlashCmdList = {} --[localizedCommand] -> function
  29. hash_EmoteTokenList = {}
  30. hash_ChatTypeInfoList = {} --[localizedCommand] -> identifier (Stores all slash commands)
  31. ChatTypeInfo = { };
  32. ChatTypeInfo["SYSTEM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  33. ChatTypeInfo["SAY"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  34. ChatTypeInfo["PARTY"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  35. ChatTypeInfo["RAID"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  36. ChatTypeInfo["GUILD"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  37. ChatTypeInfo["OFFICER"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  38. ChatTypeInfo["YELL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  39. ChatTypeInfo["WHISPER"] = { sticky = 1, flashTab = true, flashTabOnGeneral = true };
  40. ChatTypeInfo["SMART_WHISPER"] = ChatTypeInfo["WHISPER"];
  41. ChatTypeInfo["WHISPER_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  42. ChatTypeInfo["REPLY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  43. ChatTypeInfo["EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  44. ChatTypeInfo["TEXT_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  45. ChatTypeInfo["MONSTER_SAY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  46. ChatTypeInfo["MONSTER_PARTY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  47. ChatTypeInfo["MONSTER_YELL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  48. ChatTypeInfo["MONSTER_WHISPER"] = { sticky = 0, flashTab = true, flashTabOnGeneral = true };
  49. ChatTypeInfo["MONSTER_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  50. ChatTypeInfo["CHANNEL"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  51. ChatTypeInfo["CHANNEL_JOIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  52. ChatTypeInfo["CHANNEL_LEAVE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  53. ChatTypeInfo["CHANNEL_LIST"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  54. ChatTypeInfo["CHANNEL_NOTICE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  55. ChatTypeInfo["CHANNEL_NOTICE_USER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  56. ChatTypeInfo["TARGETICONS"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  57. ChatTypeInfo["AFK"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  58. ChatTypeInfo["DND"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  59. ChatTypeInfo["IGNORED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  60. ChatTypeInfo["SKILL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  61. ChatTypeInfo["LOOT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  62. ChatTypeInfo["CURRENCY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  63. ChatTypeInfo["MONEY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  64. ChatTypeInfo["OPENING"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  65. ChatTypeInfo["TRADESKILLS"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  66. ChatTypeInfo["PET_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  67. ChatTypeInfo["COMBAT_MISC_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  68. ChatTypeInfo["COMBAT_XP_GAIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  69. ChatTypeInfo["COMBAT_HONOR_GAIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  70. ChatTypeInfo["COMBAT_FACTION_CHANGE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  71. ChatTypeInfo["BG_SYSTEM_NEUTRAL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  72. ChatTypeInfo["BG_SYSTEM_ALLIANCE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  73. ChatTypeInfo["BG_SYSTEM_HORDE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  74. ChatTypeInfo["RAID_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  75. ChatTypeInfo["RAID_WARNING"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  76. ChatTypeInfo["RAID_BOSS_WHISPER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  77. ChatTypeInfo["RAID_BOSS_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  78. ChatTypeInfo["QUEST_BOSS_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  79. ChatTypeInfo["FILTERED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  80. ChatTypeInfo["INSTANCE_CHAT"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  81. ChatTypeInfo["INSTANCE_CHAT_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  82. ChatTypeInfo["RESTRICTED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  83. ChatTypeInfo["CHANNEL1"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  84. ChatTypeInfo["CHANNEL2"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  85. ChatTypeInfo["CHANNEL3"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  86. ChatTypeInfo["CHANNEL4"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  87. ChatTypeInfo["CHANNEL5"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  88. ChatTypeInfo["CHANNEL6"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  89. ChatTypeInfo["CHANNEL7"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  90. ChatTypeInfo["CHANNEL8"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  91. ChatTypeInfo["CHANNEL9"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  92. ChatTypeInfo["CHANNEL10"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  93. ChatTypeInfo["CHANNEL11"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  94. ChatTypeInfo["CHANNEL12"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  95. ChatTypeInfo["CHANNEL13"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  96. ChatTypeInfo["CHANNEL14"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  97. ChatTypeInfo["CHANNEL15"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  98. ChatTypeInfo["CHANNEL16"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  99. ChatTypeInfo["CHANNEL17"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  100. ChatTypeInfo["CHANNEL18"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  101. ChatTypeInfo["CHANNEL19"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  102. ChatTypeInfo["CHANNEL20"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  103. ChatTypeInfo["ACHIEVEMENT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  104. ChatTypeInfo["GUILD_ACHIEVEMENT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  105. ChatTypeInfo["PARTY_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  106. ChatTypeInfo["BN_WHISPER"] = { sticky = 1, flashTab = true, flashTabOnGeneral = true };
  107. ChatTypeInfo["BN_WHISPER_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  108. ChatTypeInfo["BN_ALERT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  109. ChatTypeInfo["BN_BROADCAST"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  110. ChatTypeInfo["BN_BROADCAST_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  111. ChatTypeInfo["BN_INLINE_TOAST_ALERT"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  112. ChatTypeInfo["BN_INLINE_TOAST_BROADCAST"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  113. ChatTypeInfo["BN_INLINE_TOAST_BROADCAST_INFORM"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  114. ChatTypeInfo["BN_WHISPER_PLAYER_OFFLINE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  115. ChatTypeInfo["PET_BATTLE_COMBAT_LOG"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  116. ChatTypeInfo["PET_BATTLE_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  117. ChatTypeInfo["GUILD_ITEM_LOOTED"] = ChatTypeInfo["GUILD_ACHIEVEMENT"];
  118. ChatTypeInfo["COMMUNITIES_CHANNEL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  119. --NEW_CHAT_TYPE -Add the info here.
  120. ChatTypeGroup = {};
  121. ChatTypeGroup["SYSTEM"] = {
  122. "CHAT_MSG_SYSTEM",
  123. "TIME_PLAYED_MSG",
  124. "PLAYER_LEVEL_CHANGED",
  125. "UNIT_LEVEL",
  126. "CHARACTER_POINTS_CHANGED",
  127. "CHAT_MSG_BN_WHISPER_PLAYER_OFFLINE",
  128. "QUEST_TURNED_IN",
  129. };
  130. ChatTypeGroup["SAY"] = {
  131. "CHAT_MSG_SAY",
  132. };
  133. ChatTypeGroup["EMOTE"] = {
  134. "CHAT_MSG_EMOTE",
  135. "CHAT_MSG_TEXT_EMOTE",
  136. };
  137. ChatTypeGroup["YELL"] = {
  138. "CHAT_MSG_YELL",
  139. };
  140. ChatTypeGroup["WHISPER"] = {
  141. "CHAT_MSG_WHISPER",
  142. "CHAT_MSG_WHISPER_INFORM",
  143. "CHAT_MSG_AFK",
  144. "CHAT_MSG_DND",
  145. };
  146. ChatTypeGroup["PARTY"] = {
  147. "CHAT_MSG_PARTY",
  148. "CHAT_MSG_MONSTER_PARTY",
  149. };
  150. ChatTypeGroup["PARTY_LEADER"] = {
  151. "CHAT_MSG_PARTY_LEADER",
  152. };
  153. ChatTypeGroup["RAID"] = {
  154. "CHAT_MSG_RAID",
  155. };
  156. ChatTypeGroup["RAID_LEADER"] = {
  157. "CHAT_MSG_RAID_LEADER",
  158. };
  159. ChatTypeGroup["RAID_WARNING"] = {
  160. "CHAT_MSG_RAID_WARNING",
  161. };
  162. ChatTypeGroup["INSTANCE_CHAT"] = {
  163. "CHAT_MSG_INSTANCE_CHAT",
  164. };
  165. ChatTypeGroup["INSTANCE_CHAT_LEADER"] = {
  166. "CHAT_MSG_INSTANCE_CHAT_LEADER",
  167. };
  168. ChatTypeGroup["GUILD"] = {
  169. "CHAT_MSG_GUILD",
  170. "GUILD_MOTD",
  171. };
  172. ChatTypeGroup["OFFICER"] = {
  173. "CHAT_MSG_OFFICER",
  174. };
  175. ChatTypeGroup["MONSTER_SAY"] = {
  176. "CHAT_MSG_MONSTER_SAY",
  177. };
  178. ChatTypeGroup["MONSTER_YELL"] = {
  179. "CHAT_MSG_MONSTER_YELL",
  180. };
  181. ChatTypeGroup["MONSTER_EMOTE"] = {
  182. "CHAT_MSG_MONSTER_EMOTE",
  183. };
  184. ChatTypeGroup["MONSTER_WHISPER"] = {
  185. "CHAT_MSG_MONSTER_WHISPER",
  186. };
  187. ChatTypeGroup["MONSTER_BOSS_EMOTE"] = {
  188. "CHAT_MSG_RAID_BOSS_EMOTE",
  189. };
  190. ChatTypeGroup["MONSTER_BOSS_WHISPER"] = {
  191. "CHAT_MSG_RAID_BOSS_WHISPER",
  192. };
  193. ChatTypeGroup["ERRORS"] = {
  194. "CHAT_MSG_RESTRICTED",
  195. "CHAT_MSG_FILTERED",
  196. };
  197. ChatTypeGroup["AFK"] = {
  198. "CHAT_MSG_AFK",
  199. };
  200. ChatTypeGroup["DND"] = {
  201. "CHAT_MSG_DND",
  202. };
  203. ChatTypeGroup["IGNORED"] = {
  204. "CHAT_MSG_IGNORED",
  205. };
  206. ChatTypeGroup["BG_HORDE"] = {
  207. "CHAT_MSG_BG_SYSTEM_HORDE",
  208. };
  209. ChatTypeGroup["BG_ALLIANCE"] = {
  210. "CHAT_MSG_BG_SYSTEM_ALLIANCE",
  211. };
  212. ChatTypeGroup["BG_NEUTRAL"] = {
  213. "CHAT_MSG_BG_SYSTEM_NEUTRAL",
  214. };
  215. ChatTypeGroup["COMBAT_XP_GAIN"] = {
  216. "CHAT_MSG_COMBAT_XP_GAIN";
  217. }
  218. ChatTypeGroup["COMBAT_HONOR_GAIN"] = {
  219. "CHAT_MSG_COMBAT_HONOR_GAIN";
  220. }
  221. ChatTypeGroup["COMBAT_FACTION_CHANGE"] = {
  222. "CHAT_MSG_COMBAT_FACTION_CHANGE";
  223. };
  224. ChatTypeGroup["SKILL"] = {
  225. "CHAT_MSG_SKILL",
  226. };
  227. ChatTypeGroup["LOOT"] = {
  228. "CHAT_MSG_LOOT",
  229. };
  230. ChatTypeGroup["CURRENCY"] = {
  231. "CHAT_MSG_CURRENCY",
  232. };
  233. ChatTypeGroup["MONEY"] = {
  234. "CHAT_MSG_MONEY",
  235. };
  236. ChatTypeGroup["OPENING"] = {
  237. "CHAT_MSG_OPENING";
  238. };
  239. ChatTypeGroup["TRADESKILLS"] = {
  240. "CHAT_MSG_TRADESKILLS";
  241. };
  242. ChatTypeGroup["PET_INFO"] = {
  243. "CHAT_MSG_PET_INFO";
  244. };
  245. ChatTypeGroup["COMBAT_MISC_INFO"] = {
  246. "CHAT_MSG_COMBAT_MISC_INFO";
  247. };
  248. ChatTypeGroup["ACHIEVEMENT"] = {
  249. "CHAT_MSG_ACHIEVEMENT";
  250. };
  251. ChatTypeGroup["GUILD_ACHIEVEMENT"] = {
  252. "CHAT_MSG_GUILD_ACHIEVEMENT",
  253. "CHAT_MSG_GUILD_ITEM_LOOTED",
  254. };
  255. ChatTypeGroup["CHANNEL"] = {
  256. "CHAT_MSG_CHANNEL_JOIN",
  257. "CHAT_MSG_CHANNEL_LEAVE",
  258. "CHAT_MSG_CHANNEL_NOTICE",
  259. "CHAT_MSG_CHANNEL_NOTICE_USER",
  260. "CHAT_MSG_CHANNEL_LIST",
  261. };
  262. ChatTypeGroup["COMMUNITIES_CHANNEL"] = {
  263. "CHAT_MSG_COMMUNITIES_CHANNEL",
  264. }
  265. ChatTypeGroup["TARGETICONS"] = {
  266. "CHAT_MSG_TARGETICONS"
  267. };
  268. ChatTypeGroup["BN_WHISPER"] = {
  269. "CHAT_MSG_BN_WHISPER",
  270. "CHAT_MSG_BN_WHISPER_INFORM",
  271. };
  272. ChatTypeGroup["BN_INLINE_TOAST_ALERT"] = {
  273. "CHAT_MSG_BN_INLINE_TOAST_ALERT",
  274. "CHAT_MSG_BN_INLINE_TOAST_BROADCAST",
  275. "CHAT_MSG_BN_INLINE_TOAST_BROADCAST_INFORM",
  276. };
  277. ChatTypeGroup["PET_BATTLE_COMBAT_LOG"] = {
  278. "CHAT_MSG_PET_BATTLE_COMBAT_LOG",
  279. };
  280. ChatTypeGroup["PET_BATTLE_INFO"] = {
  281. "CHAT_MSG_PET_BATTLE_INFO",
  282. };
  283. --NEW_CHAT_TYPE - Add the chat type above.
  284. ChatTypeGroupInverted = {};
  285. for group, values in pairs(ChatTypeGroup) do
  286. for _, value in pairs(values) do
  287. ChatTypeGroupInverted[value] = group;
  288. end
  289. end
  290. CHAT_CATEGORY_LIST = {
  291. PARTY = { "PARTY_LEADER", "PARTY_GUIDE", "MONSTER_PARTY" },
  292. RAID = { "RAID_LEADER", "RAID_WARNING" },
  293. GUILD = { "GUILD_ACHIEVEMENT", "GUILD_ITEM_LOOTED" },
  294. WHISPER = { "WHISPER_INFORM", "AFK", "DND" },
  295. CHANNEL = { "CHANNEL_JOIN", "CHANNEL_LEAVE", "CHANNEL_NOTICE", "CHANNEL_USER", "CHANNEL_NOTICE_USER" },
  296. INSTANCE_CHAT = { "INSTANCE_CHAT_LEADER" },
  297. BN_WHISPER = { "BN_WHISPER_INFORM" },
  298. };
  299. CHAT_INVERTED_CATEGORY_LIST = {};
  300. for category, sublist in pairs(CHAT_CATEGORY_LIST) do
  301. for _, item in pairs(sublist) do
  302. CHAT_INVERTED_CATEGORY_LIST[item] = category;
  303. end
  304. end
  305. function Chat_GetChatFrame(chatFrameIndex)
  306. return _G["ChatFrame"..chatFrameIndex];
  307. end
  308. function Chat_GetChatCategory(chatType)
  309. return CHAT_INVERTED_CATEGORY_LIST[chatType] or chatType;
  310. end
  311. function Chat_GetChannelColor(chatInfo)
  312. return chatInfo.r, chatInfo.g, chatInfo.b;
  313. end
  314. function Chat_GetCommunitiesChannelName(clubId, streamId)
  315. return ("Community:%s:%s"):format(tostring(clubId), tostring(streamId));
  316. end
  317. local function Chat_GetCommunitiesChannel(clubId, streamId)
  318. local communitiesChannelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  319. for i = 1, MAX_WOW_CHAT_CHANNELS do
  320. local channelID, channelName = GetChannelName(i);
  321. if channelName and channelName == communitiesChannelName then
  322. return "CHANNEL"..i;
  323. end
  324. end
  325. return nil;
  326. end
  327. function Chat_GetCommunitiesChannelColor(clubId, streamId)
  328. local channel = Chat_GetCommunitiesChannel(clubId, streamId);
  329. if channel then
  330. local chatInfo = ChatTypeInfo[channel];
  331. if chatInfo then
  332. return Chat_GetChannelColor(chatInfo);
  333. end
  334. end
  335. local clubInfo = C_Club.GetClubInfo(clubId);
  336. if clubInfo then
  337. if clubInfo.clubType == Enum.ClubType.Guild then
  338. local streamInfo = C_Club.GetStreamInfo(clubId, streamId);
  339. local chatInfoType = (streamInfo and streamInfo.streamType == Enum.ClubStreamType.Officer) and "OFFICER" or "GUILD";
  340. return Chat_GetChannelColor(ChatTypeInfo[chatInfoType]);
  341. elseif clubInfo.clubType == Enum.ClubType.BattleNet then
  342. return BATTLENET_FONT_COLOR:GetRGB();
  343. end
  344. end
  345. return DEFAULT_CHAT_CHANNEL_COLOR:GetRGB();
  346. end
  347. -- list of text emotes that we want to show on the Emote submenu (these have anims)
  348. EmoteList = {
  349. "WAVE",
  350. "BOW",
  351. "DANCE",
  352. "APPLAUD",
  353. "BEG",
  354. "CHICKEN",
  355. "CRY",
  356. "EAT",
  357. "FLEX",
  358. "KISS",
  359. "LAUGH",
  360. "POINT",
  361. "ROAR",
  362. "RUDE",
  363. "SALUTE",
  364. "SHY",
  365. "TALK",
  366. "STAND",
  367. "SIT",
  368. "SLEEP",
  369. "KNEEL",
  370. };
  371. -- list of text emotes that we want to show on the Speech submenu (these have sounds)
  372. TextEmoteSpeechList = {
  373. "HELPME",
  374. "INCOMING",
  375. "CHARGE",
  376. "FLEE",
  377. "ATTACKMYTARGET",
  378. "OOM",
  379. "FOLLOW",
  380. "WAIT",
  381. "HEALME",
  382. "CHEER",
  383. "OPENFIRE",
  384. "RASP",
  385. "HELLO",
  386. "BYE",
  387. "NOD",
  388. "NO",
  389. "THANK",
  390. "WELCOME",
  391. "CONGRATULATE",
  392. "FLIRT",
  393. "JOKE",
  394. "TRAIN",
  395. };
  396. -- These are text emote tokens - add new ones at the bottom of the list!
  397. EMOTE1_TOKEN = "AGREE";
  398. EMOTE2_TOKEN = "AMAZE";
  399. EMOTE3_TOKEN = "ANGRY";
  400. EMOTE4_TOKEN = "APOLOGIZE";
  401. EMOTE5_TOKEN = "APPLAUD";
  402. EMOTE6_TOKEN = "BASHFUL";
  403. EMOTE7_TOKEN = "BECKON";
  404. EMOTE8_TOKEN = "BEG";
  405. EMOTE9_TOKEN = "BITE";
  406. EMOTE10_TOKEN = "BLEED";
  407. EMOTE11_TOKEN = "BLINK";
  408. EMOTE12_TOKEN = "BLUSH";
  409. EMOTE13_TOKEN = "BONK";
  410. EMOTE14_TOKEN = "BORED";
  411. EMOTE15_TOKEN = "BOUNCE";
  412. EMOTE16_TOKEN = "BRB";
  413. EMOTE17_TOKEN = "BOW";
  414. EMOTE18_TOKEN = "BURP";
  415. EMOTE19_TOKEN = "BYE";
  416. EMOTE20_TOKEN = "CACKLE";
  417. EMOTE21_TOKEN = "CHEER";
  418. EMOTE22_TOKEN = "CHICKEN";
  419. EMOTE23_TOKEN = "CHUCKLE";
  420. EMOTE24_TOKEN = "CLAP";
  421. EMOTE25_TOKEN = "CONFUSED";
  422. EMOTE26_TOKEN = "CONGRATULATE";
  423. EMOTE27_TOKEN = "UNUSED";
  424. EMOTE28_TOKEN = "COUGH";
  425. EMOTE29_TOKEN = "COWER";
  426. EMOTE30_TOKEN = "CRACK";
  427. EMOTE31_TOKEN = "CRINGE";
  428. EMOTE32_TOKEN = "CRY";
  429. EMOTE33_TOKEN = "CURIOUS";
  430. EMOTE34_TOKEN = "CURTSEY";
  431. EMOTE35_TOKEN = "DANCE";
  432. EMOTE36_TOKEN = "DRINK";
  433. EMOTE37_TOKEN = "DROOL";
  434. EMOTE38_TOKEN = "EAT";
  435. EMOTE39_TOKEN = "EYE";
  436. EMOTE40_TOKEN = "FART";
  437. EMOTE41_TOKEN = "FIDGET";
  438. EMOTE42_TOKEN = "FLEX";
  439. EMOTE43_TOKEN = "FROWN";
  440. EMOTE44_TOKEN = "GASP";
  441. EMOTE45_TOKEN = "GAZE";
  442. EMOTE46_TOKEN = "GIGGLE";
  443. EMOTE47_TOKEN = "GLARE";
  444. EMOTE48_TOKEN = "GLOAT";
  445. EMOTE49_TOKEN = "GREET";
  446. EMOTE50_TOKEN = "GRIN";
  447. EMOTE51_TOKEN = "GROAN";
  448. EMOTE52_TOKEN = "GROVEL";
  449. EMOTE53_TOKEN = "GUFFAW";
  450. EMOTE54_TOKEN = "HAIL";
  451. EMOTE55_TOKEN = "HAPPY";
  452. EMOTE56_TOKEN = "HELLO";
  453. EMOTE57_TOKEN = "HUG";
  454. EMOTE58_TOKEN = "HUNGRY";
  455. EMOTE59_TOKEN = "KISS";
  456. EMOTE60_TOKEN = "KNEEL";
  457. EMOTE61_TOKEN = "LAUGH";
  458. EMOTE62_TOKEN = "LAYDOWN";
  459. EMOTE63_TOKEN = "MASSAGE";
  460. EMOTE64_TOKEN = "MOAN";
  461. EMOTE65_TOKEN = "MOON";
  462. EMOTE66_TOKEN = "MOURN";
  463. EMOTE67_TOKEN = "NO";
  464. EMOTE68_TOKEN = "NOD";
  465. EMOTE69_TOKEN = "NOSEPICK";
  466. EMOTE70_TOKEN = "PANIC";
  467. EMOTE71_TOKEN = "PEER";
  468. EMOTE72_TOKEN = "PLEAD";
  469. EMOTE73_TOKEN = "POINT";
  470. EMOTE74_TOKEN = "POKE";
  471. EMOTE75_TOKEN = "PRAY";
  472. EMOTE76_TOKEN = "ROAR";
  473. EMOTE77_TOKEN = "ROFL";
  474. EMOTE78_TOKEN = "RUDE";
  475. EMOTE79_TOKEN = "SALUTE";
  476. EMOTE80_TOKEN = "SCRATCH";
  477. EMOTE81_TOKEN = "SEXY";
  478. EMOTE82_TOKEN = "SHAKE";
  479. EMOTE83_TOKEN = "SHOUT";
  480. EMOTE84_TOKEN = "SHRUG";
  481. EMOTE85_TOKEN = "SHY";
  482. EMOTE86_TOKEN = "SIGH";
  483. EMOTE87_TOKEN = "SIT";
  484. EMOTE88_TOKEN = "SLEEP";
  485. EMOTE89_TOKEN = "SNARL";
  486. EMOTE90_TOKEN = "SPIT";
  487. EMOTE91_TOKEN = "STARE";
  488. EMOTE92_TOKEN = "SURPRISED";
  489. EMOTE93_TOKEN = "SURRENDER";
  490. EMOTE94_TOKEN = "TALK";
  491. EMOTE95_TOKEN = "TALKEX";
  492. EMOTE96_TOKEN = "TALKQ";
  493. EMOTE97_TOKEN = "TAP";
  494. EMOTE98_TOKEN = "THANK";
  495. EMOTE99_TOKEN = "THREATEN";
  496. EMOTE100_TOKEN = "TIRED";
  497. EMOTE101_TOKEN = "VICTORY";
  498. EMOTE102_TOKEN = "WAVE";
  499. EMOTE103_TOKEN = "WELCOME";
  500. EMOTE104_TOKEN = "WHINE";
  501. EMOTE105_TOKEN = "WHISTLE";
  502. EMOTE106_TOKEN = "WORK";
  503. EMOTE107_TOKEN = "YAWN";
  504. EMOTE108_TOKEN = "BOGGLE";
  505. EMOTE109_TOKEN = "CALM";
  506. EMOTE110_TOKEN = "COLD";
  507. EMOTE111_TOKEN = "COMFORT";
  508. EMOTE112_TOKEN = "CUDDLE";
  509. EMOTE113_TOKEN = "DUCK";
  510. EMOTE114_TOKEN = "INSULT";
  511. EMOTE115_TOKEN = "INTRODUCE";
  512. EMOTE116_TOKEN = "JK";
  513. EMOTE117_TOKEN = "LICK";
  514. EMOTE118_TOKEN = "LISTEN";
  515. EMOTE119_TOKEN = "LOST";
  516. EMOTE120_TOKEN = "MOCK";
  517. EMOTE121_TOKEN = "PONDER";
  518. EMOTE122_TOKEN = "POUNCE";
  519. EMOTE123_TOKEN = "PRAISE";
  520. EMOTE124_TOKEN = "PURR";
  521. EMOTE125_TOKEN = "PUZZLE";
  522. EMOTE126_TOKEN = "RAISE";
  523. EMOTE127_TOKEN = "READY";
  524. EMOTE128_TOKEN = "SHIMMY";
  525. EMOTE129_TOKEN = "SHIVER";
  526. EMOTE130_TOKEN = "SHOO";
  527. EMOTE131_TOKEN = "SLAP";
  528. EMOTE132_TOKEN = "SMIRK";
  529. EMOTE133_TOKEN = "SNIFF";
  530. EMOTE134_TOKEN = "SNUB";
  531. EMOTE135_TOKEN = "SOOTHE";
  532. EMOTE136_TOKEN = "STINK";
  533. EMOTE137_TOKEN = "TAUNT";
  534. EMOTE138_TOKEN = "TEASE";
  535. EMOTE139_TOKEN = "THIRSTY";
  536. EMOTE140_TOKEN = "VETO";
  537. EMOTE141_TOKEN = "SNICKER";
  538. EMOTE142_TOKEN = "TICKLE";
  539. EMOTE143_TOKEN = "STAND";
  540. EMOTE144_TOKEN = "VIOLIN";
  541. EMOTE145_TOKEN = "SMILE";
  542. EMOTE146_TOKEN = "RASP";
  543. EMOTE147_TOKEN = "GROWL";
  544. EMOTE148_TOKEN = "BARK";
  545. EMOTE149_TOKEN = "PITY";
  546. EMOTE150_TOKEN = "SCARED";
  547. EMOTE151_TOKEN = "FLOP";
  548. EMOTE152_TOKEN = "LOVE";
  549. EMOTE153_TOKEN = "MOO";
  550. EMOTE154_TOKEN = "COMMEND";
  551. EMOTE155_TOKEN = "TRAIN";
  552. EMOTE156_TOKEN = "HELPME";
  553. EMOTE157_TOKEN = "INCOMING";
  554. EMOTE158_TOKEN = "OPENFIRE";
  555. EMOTE159_TOKEN = "CHARGE";
  556. EMOTE160_TOKEN = "FLEE";
  557. EMOTE161_TOKEN = "ATTACKMYTARGET";
  558. EMOTE162_TOKEN = "OOM";
  559. EMOTE163_TOKEN = "FOLLOW";
  560. EMOTE164_TOKEN = "WAIT";
  561. EMOTE165_TOKEN = "FLIRT";
  562. EMOTE166_TOKEN = "HEALME";
  563. EMOTE167_TOKEN = "JOKE";
  564. EMOTE168_TOKEN = "WINK";
  565. EMOTE169_TOKEN = "PAT";
  566. EMOTE170_TOKEN = "GOLFCLAP";
  567. EMOTE171_TOKEN = "MOUNTSPECIAL";
  568. EMOTE304_TOKEN = "INCOMING";
  569. EMOTE306_TOKEN = "FLEE";
  570. EMOTE368_TOKEN = "BLAME"
  571. EMOTE369_TOKEN = "BLANK"
  572. EMOTE370_TOKEN = "BRANDISH"
  573. EMOTE371_TOKEN = "BREATH"
  574. EMOTE372_TOKEN = "DISAGREE"
  575. EMOTE373_TOKEN = "DOUBT"
  576. EMOTE374_TOKEN = "EMBARRASS"
  577. EMOTE375_TOKEN = "ENCOURAGE"
  578. EMOTE376_TOKEN = "ENEMY"
  579. EMOTE377_TOKEN = "EYEBROW"
  580. EMOTE380_TOKEN = "HIGHFIVE"
  581. EMOTE381_TOKEN = "ABSENT"
  582. EMOTE382_TOKEN = "ARM"
  583. EMOTE383_TOKEN = "AWE"
  584. EMOTE384_TOKEN = "BACKPACK"
  585. EMOTE385_TOKEN = "BADFEELING"
  586. EMOTE386_TOKEN = "CHALLENGE"
  587. EMOTE387_TOKEN = "CHUG"
  588. EMOTE389_TOKEN = "DING"
  589. EMOTE390_TOKEN = "FACEPALM"
  590. EMOTE391_TOKEN = "FAINT"
  591. EMOTE392_TOKEN = "GO"
  592. EMOTE393_TOKEN = "GOING"
  593. EMOTE394_TOKEN = "GLOWER"
  594. EMOTE395_TOKEN = "HEADACHE"
  595. EMOTE396_TOKEN = "HICCUP"
  596. EMOTE398_TOKEN = "HISS"
  597. EMOTE399_TOKEN = "HOLDHAND"
  598. EMOTE401_TOKEN = "HURRY"
  599. EMOTE402_TOKEN = "IDEA"
  600. EMOTE403_TOKEN = "JEALOUS"
  601. EMOTE404_TOKEN = "LUCK"
  602. EMOTE405_TOKEN = "MAP"
  603. EMOTE406_TOKEN = "MERCY"
  604. EMOTE407_TOKEN = "MUTTER"
  605. EMOTE408_TOKEN = "NERVOUS"
  606. EMOTE409_TOKEN = "OFFER"
  607. EMOTE410_TOKEN = "PET"
  608. EMOTE411_TOKEN = "PINCH"
  609. EMOTE413_TOKEN = "PROUD"
  610. EMOTE414_TOKEN = "PROMISE"
  611. EMOTE415_TOKEN = "PULSE"
  612. EMOTE416_TOKEN = "PUNCH"
  613. EMOTE417_TOKEN = "POUT"
  614. EMOTE418_TOKEN = "REGRET"
  615. EMOTE420_TOKEN = "REVENGE"
  616. EMOTE421_TOKEN = "ROLLEYES"
  617. EMOTE422_TOKEN = "RUFFLE"
  618. EMOTE423_TOKEN = "SAD"
  619. EMOTE424_TOKEN = "SCOFF"
  620. EMOTE425_TOKEN = "SCOLD"
  621. EMOTE426_TOKEN = "SCOWL"
  622. EMOTE427_TOKEN = "SEARCH"
  623. EMOTE428_TOKEN = "SHAKEFIST"
  624. EMOTE429_TOKEN = "SHIFTY"
  625. EMOTE430_TOKEN = "SHUDDER"
  626. EMOTE431_TOKEN = "SIGNAL"
  627. EMOTE432_TOKEN = "SILENCE"
  628. EMOTE433_TOKEN = "SING"
  629. EMOTE434_TOKEN = "SMACK"
  630. EMOTE435_TOKEN = "SNEAK"
  631. EMOTE436_TOKEN = "SNEEZE"
  632. EMOTE437_TOKEN = "SNORT"
  633. EMOTE438_TOKEN = "SQUEAL"
  634. EMOTE440_TOKEN = "SUSPICIOUS"
  635. EMOTE441_TOKEN = "THINK"
  636. EMOTE442_TOKEN = "TRUCE"
  637. EMOTE443_TOKEN = "TWIDDLE"
  638. EMOTE444_TOKEN = "WARN"
  639. EMOTE445_TOKEN = "SNAP"
  640. EMOTE446_TOKEN = "CHARM"
  641. EMOTE447_TOKEN = "COVEREARS"
  642. EMOTE448_TOKEN = "CROSSARMS"
  643. EMOTE449_TOKEN = "LOOK"
  644. EMOTE450_TOKEN = "OBJECT"
  645. EMOTE451_TOKEN = "SWEAT"
  646. EMOTE452_TOKEN = "YW"
  647. EMOTE453_TOKEN = "READ"
  648. EMOTE454_TOKEN = "FORTHEALLIANCE"
  649. EMOTE455_TOKEN = "FORTHEHORDE"
  650. EMOTE517_TOKEN = "WHOA"
  651. EMOTE518_TOKEN = "OOPS"
  652. EMOTE521_TOKEN = "MEOW"
  653. EMOTE522_TOKEN = "BOOP"
  654. -- NOTE: The indices used to iterate the tokens may not be contiguous, keep that in mind when updating this value.
  655. local MAXEMOTEINDEX = 522;
  656. ICON_LIST = {
  657. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:",
  658. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_2:",
  659. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_3:",
  660. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_4:",
  661. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_5:",
  662. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_6:",
  663. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_7:",
  664. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:",
  665. }
  666. --Links tags from Global Strings to indicies for entries in ICON_LIST. This way addons can easily replace icons
  667. ICON_TAG_LIST =
  668. {
  669. [strlower(ICON_TAG_RAID_TARGET_STAR1)] = 1,
  670. [strlower(ICON_TAG_RAID_TARGET_STAR2)] = 1,
  671. [strlower(ICON_TAG_RAID_TARGET_STAR3)] = 1,
  672. [strlower(ICON_TAG_RAID_TARGET_CIRCLE1)] = 2,
  673. [strlower(ICON_TAG_RAID_TARGET_CIRCLE2)] = 2,
  674. [strlower(ICON_TAG_RAID_TARGET_CIRCLE3)] = 2,
  675. [strlower(ICON_TAG_RAID_TARGET_DIAMOND1)] = 3,
  676. [strlower(ICON_TAG_RAID_TARGET_DIAMOND2)] = 3,
  677. [strlower(ICON_TAG_RAID_TARGET_DIAMOND3)] = 3,
  678. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE1)] = 4,
  679. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE2)] = 4,
  680. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE3)] = 4,
  681. [strlower(ICON_TAG_RAID_TARGET_MOON1)] = 5,
  682. [strlower(ICON_TAG_RAID_TARGET_MOON2)] = 5,
  683. [strlower(ICON_TAG_RAID_TARGET_MOON3)] = 5,
  684. [strlower(ICON_TAG_RAID_TARGET_SQUARE1)] = 6,
  685. [strlower(ICON_TAG_RAID_TARGET_SQUARE2)] = 6,
  686. [strlower(ICON_TAG_RAID_TARGET_SQUARE3)] = 6,
  687. [strlower(ICON_TAG_RAID_TARGET_CROSS1)] = 7,
  688. [strlower(ICON_TAG_RAID_TARGET_CROSS2)] = 7,
  689. [strlower(ICON_TAG_RAID_TARGET_CROSS3)] = 7,
  690. [strlower(ICON_TAG_RAID_TARGET_SKULL1)] = 8,
  691. [strlower(ICON_TAG_RAID_TARGET_SKULL2)] = 8,
  692. [strlower(ICON_TAG_RAID_TARGET_SKULL3)] = 8,
  693. [strlower(RAID_TARGET_1)] = 1,
  694. [strlower(RAID_TARGET_2)] = 2,
  695. [strlower(RAID_TARGET_3)] = 3,
  696. [strlower(RAID_TARGET_4)] = 4,
  697. [strlower(RAID_TARGET_5)] = 5,
  698. [strlower(RAID_TARGET_6)] = 6,
  699. [strlower(RAID_TARGET_7)] = 7,
  700. [strlower(RAID_TARGET_8)] = 8,
  701. }
  702. GROUP_TAG_LIST =
  703. {
  704. [strlower(GROUP1_CHAT_TAG1)] = 1,
  705. [strlower(GROUP1_CHAT_TAG2)] = 1,
  706. [strlower(GROUP2_CHAT_TAG1)] = 2,
  707. [strlower(GROUP2_CHAT_TAG2)] = 2,
  708. [strlower(GROUP3_CHAT_TAG1)] = 3,
  709. [strlower(GROUP3_CHAT_TAG2)] = 3,
  710. [strlower(GROUP4_CHAT_TAG1)] = 4,
  711. [strlower(GROUP4_CHAT_TAG2)] = 4,
  712. [strlower(GROUP5_CHAT_TAG1)] = 5,
  713. [strlower(GROUP5_CHAT_TAG2)] = 5,
  714. [strlower(GROUP6_CHAT_TAG1)] = 6,
  715. [strlower(GROUP6_CHAT_TAG2)] = 6,
  716. [strlower(GROUP7_CHAT_TAG1)] = 7,
  717. [strlower(GROUP7_CHAT_TAG2)] = 7,
  718. [strlower(GROUP8_CHAT_TAG1)] = 8,
  719. [strlower(GROUP8_CHAT_TAG2)] = 8,
  720. --Language independent:
  721. ["g1"] = 1;
  722. ["g2"] = 2;
  723. ["g3"] = 3;
  724. ["g4"] = 4;
  725. ["g5"] = 5;
  726. ["g6"] = 6;
  727. ["g7"] = 7;
  728. ["g8"] = 8;
  729. };
  730. GROUP_LANGUAGE_INDEPENDENT_STRINGS =
  731. {
  732. "g1",
  733. "g2",
  734. "g3",
  735. "g4",
  736. "g5",
  737. "g6",
  738. "g7",
  739. "g8",
  740. };
  741. local MAX_COMMUNITY_NAME_LENGTH = 12;
  742. local MAX_COMMUNITY_NAME_LENGTH_NO_CHANNEL = 24;
  743. function ChatFrame_TruncateToMaxLength(text, maxLength)
  744. local length = strlenutf8(text);
  745. if ( length > maxLength ) then
  746. return text:sub(1, maxLength - 2).."...";
  747. end
  748. return text;
  749. end
  750. function ChatFrame_ResolvePrefixedChannelName(communityChannel)
  751. local prefix, communityChannel = communityChannel:match("(%d+. )(.*)");
  752. return prefix..ChatFrame_ResolveChannelName(communityChannel);
  753. end
  754. function ChatFrame_GetCommunityAndStreamFromChannel(communityChannel)
  755. local clubId, streamId = communityChannel:match("(%d+)%:(%d+)");
  756. return tonumber(clubId), tonumber(streamId);
  757. end
  758. function ChatFrame_ResolveChannelName(communityChannel)
  759. local clubId, streamId = ChatFrame_GetCommunityAndStreamFromChannel(communityChannel);
  760. if not clubId or not streamId then
  761. return communityChannel;
  762. end
  763. return ChatFrame_GetCommunityAndStreamName(clubId, streamId);
  764. end
  765. function ChatFrame_GetCommunityAndStreamName(clubId, streamId)
  766. local streamInfo = C_Club.GetStreamInfo(clubId, streamId);
  767. if streamInfo and (streamInfo.streamType == Enum.ClubStreamType.Guild or streamInfo.streamType == Enum.ClubStreamType.Officer) then
  768. return streamInfo.name;
  769. end
  770. local streamName = streamInfo and ChatFrame_TruncateToMaxLength(streamInfo.name, MAX_COMMUNITY_NAME_LENGTH) or "";
  771. local clubInfo = C_Club.GetClubInfo(clubId);
  772. if streamInfo and streamInfo.streamType == Enum.ClubStreamType.General then
  773. local communityName = clubInfo and ChatFrame_TruncateToMaxLength(clubInfo.shortName or clubInfo.name, MAX_COMMUNITY_NAME_LENGTH_NO_CHANNEL) or "";
  774. return communityName;
  775. else
  776. local communityName = clubInfo and ChatFrame_TruncateToMaxLength(clubInfo.shortName or clubInfo.name, MAX_COMMUNITY_NAME_LENGTH) or "";
  777. return communityName.." - "..streamName;
  778. end
  779. end
  780. --
  781. -- CastSequence support
  782. --
  783. local CastSequenceManager;
  784. local CastSequenceTable = {};
  785. local CastSequenceFreeList = {};
  786. local function CreateCanonicalActions(entry, ...)
  787. entry.spells = {};
  788. entry.spellNames = {};
  789. entry.spellID = {};
  790. entry.items = {};
  791. local count = 0;
  792. for i=1, select("#", ...) do
  793. local action = strlower(strtrim((select(i, ...))));
  794. if ( action and action ~="" ) then
  795. count = count + 1;
  796. if ( GetItemInfo(action) or select(3, SecureCmdItemParse(action)) ) then
  797. local spellName, spellID = GetItemSpell(action);
  798. entry.items[count] = action;
  799. entry.spells[count] = strlower(spellName or "");
  800. entry.spellNames[count] = entry.spells[count];
  801. entry.spellID[count] = spellID;
  802. else
  803. entry.spells[count] = action;
  804. entry.spellNames[count] = gsub(action, "!*(.*)", "%1");
  805. entry.spellID[count] = select(7, GetSpellInfo(action));
  806. end
  807. end
  808. end
  809. end
  810. local function SetCastSequenceIndex(entry, index)
  811. entry.index = index;
  812. entry.pending = nil;
  813. end
  814. local function ResetCastSequence(sequence, entry)
  815. SetCastSequenceIndex(entry, 1);
  816. CastSequenceFreeList[sequence] = entry;
  817. CastSequenceTable[sequence] = nil;
  818. end
  819. local function SetNextCastSequence(sequence, entry)
  820. if ( entry.index == #entry.spells ) then
  821. ResetCastSequence(sequence, entry);
  822. else
  823. SetCastSequenceIndex(entry, entry.index + 1);
  824. end
  825. end
  826. local function CastSequenceManager_OnEvent(self, event, ...)
  827. -- Reset all sequences when the player dies
  828. if ( event == "PLAYER_DEAD" ) then
  829. for sequence, entry in pairs(CastSequenceTable) do
  830. ResetCastSequence(sequence, entry);
  831. end
  832. return;
  833. end
  834. -- Increment sequences for spells which succeed.
  835. if ( event == "UNIT_SPELLCAST_SENT" or
  836. event == "UNIT_SPELLCAST_SUCCEEDED" or
  837. event == "UNIT_SPELLCAST_INTERRUPTED" or
  838. event == "UNIT_SPELLCAST_FAILED" or
  839. event == "UNIT_SPELLCAST_FAILED_QUIET" ) then
  840. local unit, castID, spellID;
  841. if event == "UNIT_SPELLCAST_SENT" then
  842. local target;
  843. unit, target, castID, spellID = ...;
  844. else
  845. unit, castID, spellID = ...;
  846. end
  847. if ( unit == "player" or unit == "pet" ) then
  848. local overrideSpellID = FindSpellOverrideByID(spellID);
  849. local baseSpellID = FindBaseSpellByID(spellID);
  850. for sequence, entry in pairs(CastSequenceTable) do
  851. local entrySpellID = entry.spellID[entry.index];
  852. if ( entrySpellID == overrideSpellID or entrySpellID == baseSpellID ) then
  853. if ( event == "UNIT_SPELLCAST_SENT" ) then
  854. entry.pending = castID;
  855. elseif ( entry.pending == castID ) then
  856. entry.pending = nil;
  857. if ( event == "UNIT_SPELLCAST_SUCCEEDED" ) then
  858. SetNextCastSequence(sequence, entry);
  859. end
  860. end
  861. end
  862. end
  863. end
  864. return;
  865. end
  866. -- Handle reset events
  867. local reset = "";
  868. if ( event == "PLAYER_TARGET_CHANGED" ) then
  869. reset = "target";
  870. elseif ( event == "PLAYER_REGEN_ENABLED" ) then
  871. reset = "combat";
  872. end
  873. for sequence, entry in pairs(CastSequenceTable) do
  874. if ( strfind(entry.reset, reset, 1, true) ) then
  875. ResetCastSequence(sequence, entry);
  876. end
  877. end
  878. end
  879. local function CastSequenceManager_OnUpdate(self, elapsed)
  880. elapsed = self.elapsed + elapsed;
  881. if ( elapsed < 1 ) then
  882. self.elapsed = elapsed;
  883. return;
  884. end
  885. for sequence, entry in pairs(CastSequenceTable) do
  886. if ( entry.timeout ) then
  887. if ( elapsed >= entry.timeout ) then
  888. ResetCastSequence(sequence, entry);
  889. else
  890. entry.timeout = entry.timeout - elapsed;
  891. end
  892. end
  893. end
  894. self.elapsed = 0;
  895. end
  896. local function ExecuteCastSequence(sequence, target)
  897. if ( not CastSequenceManager ) then
  898. CastSequenceManager = CreateFrame("Frame");
  899. CastSequenceManager.elapsed = 0;
  900. CastSequenceManager:RegisterEvent("PLAYER_DEAD");
  901. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_SENT");
  902. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  903. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");
  904. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_FAILED");
  905. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET");
  906. CastSequenceManager:RegisterEvent("PLAYER_TARGET_CHANGED");
  907. CastSequenceManager:RegisterEvent("PLAYER_REGEN_ENABLED");
  908. CastSequenceManager:SetScript("OnEvent", CastSequenceManager_OnEvent);
  909. CastSequenceManager:SetScript("OnUpdate", CastSequenceManager_OnUpdate);
  910. end
  911. local entry = CastSequenceTable[sequence];
  912. if ( not entry ) then
  913. entry = CastSequenceFreeList[sequence];
  914. if ( not entry ) then
  915. local reset, spells = strmatch(sequence, "^reset=([^%s]+)%s*(.*)");
  916. if ( not reset ) then
  917. spells = sequence;
  918. end
  919. entry = {};
  920. CreateCanonicalActions(entry, strsplit(",", spells));
  921. entry.reset = strlower(reset or "");
  922. end
  923. CastSequenceTable[sequence] = entry;
  924. entry.index = 1;
  925. end
  926. -- Don't do anything if this entry is still pending
  927. if ( entry.pending ) then
  928. return;
  929. end
  930. -- See if modified click restarts the sequence
  931. if ( (IsShiftKeyDown() and strfind(entry.reset, "shift", 1, true)) or
  932. (IsControlKeyDown() and strfind(entry.reset, "ctrl", 1, true)) or
  933. (IsAltKeyDown() and strfind(entry.reset, "alt", 1, true)) ) then
  934. SetCastSequenceIndex(entry, 1);
  935. end
  936. -- Reset the timeout each time the sequence is used
  937. local timeout = strmatch(entry.reset, "(%d+)");
  938. if ( timeout ) then
  939. entry.timeout = CastSequenceManager.elapsed + tonumber(timeout);
  940. end
  941. -- Execute the sequence!
  942. local item, spell = entry.items[entry.index], entry.spells[entry.index];
  943. if ( item ) then
  944. local name, bag, slot = SecureCmdItemParse(item);
  945. if ( slot ) then
  946. local spellID;
  947. if ( name ) then
  948. local spellName;
  949. spellName, spellID = GetItemSpell(name);
  950. spell = strlower(spellName or "");
  951. else
  952. spell = "";
  953. end
  954. entry.spellNames[entry.index] = spell;
  955. entry.spellID[entry.index] = spellID;
  956. end
  957. if ( IsEquippableItem(name) and not IsEquippedItem(name) ) then
  958. EquipItemByName(name);
  959. else
  960. SecureCmdUseItem(name, bag, slot, target);
  961. end
  962. else
  963. CastSpellByName(spell, target);
  964. end
  965. end
  966. function QueryCastSequence(sequence)
  967. local index = 1;
  968. local item, spell;
  969. local entry = CastSequenceTable[sequence];
  970. if ( entry ) then
  971. if ( (IsShiftKeyDown() and strfind(entry.reset, "shift", 1, true)) or
  972. (IsControlKeyDown() and strfind(entry.reset, "ctrl", 1, true)) or
  973. (IsAltKeyDown() and strfind(entry.reset, "alt", 1, true)) ) then
  974. index = 1;
  975. else
  976. index = entry.index;
  977. end
  978. item, spell = entry.items[index], entry.spells[index];
  979. else
  980. entry = CastSequenceFreeList[sequence];
  981. if ( entry ) then
  982. item, spell = entry.items[index], entry.spells[index];
  983. else
  984. local reset, spells = strmatch(sequence, "^reset=([^%s]+)%s*(.*)");
  985. if ( not reset ) then
  986. spells = sequence;
  987. end
  988. local action = strlower(strtrim((strsplit(",", spells))));
  989. if ( select(3, SecureCmdItemParse(action)) or GetItemInfo(action) ) then
  990. item, spell = action, strlower(GetItemSpell(action) or "");
  991. else
  992. item, spell = nil, action;
  993. end
  994. end
  995. end
  996. if ( item ) then
  997. local name, bag, slot = SecureCmdItemParse(item);
  998. if ( slot ) then
  999. if ( name ) then
  1000. spell = strlower(GetItemSpell(name) or "");
  1001. else
  1002. spell = "";
  1003. end
  1004. end
  1005. end
  1006. return index, item, spell;
  1007. end
  1008. local CastRandomManager;
  1009. local CastRandomTable = {};
  1010. local function CastRandomManager_OnEvent(self, event, ...)
  1011. local unit, castID, spellID = ...;
  1012. if ( unit == "player" ) then
  1013. local name = strlower(GetSpellInfo(spellID));
  1014. local rank = strlower(GetSpellSubtext(spellID) or "");
  1015. local nameplus = name.."()";
  1016. local fullname = name.."("..rank..")";
  1017. for sequence, entry in pairs(CastRandomTable) do
  1018. if ( entry.pending and entry.value ) then
  1019. local entryName = strlower(entry.value);
  1020. if ( entryName == name or entryName == nameplus or entryName == fullname ) then
  1021. entry.pending = nil;
  1022. if ( event == "UNIT_SPELLCAST_SUCCEEDED" ) then
  1023. entry.value = nil;
  1024. end
  1025. end
  1026. end
  1027. end
  1028. end
  1029. end
  1030. local function ExecuteCastRandom(actions)
  1031. if ( not CastRandomManager ) then
  1032. CastRandomManager = CreateFrame("Frame");
  1033. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  1034. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");
  1035. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_FAILED");
  1036. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET");
  1037. CastRandomManager:SetScript("OnEvent", CastRandomManager_OnEvent);
  1038. end
  1039. local entry = CastRandomTable[actions];
  1040. if ( not entry ) then
  1041. entry = {};
  1042. CreateCanonicalActions(entry, strsplit(",", actions));
  1043. CastRandomTable[actions] = entry;
  1044. end
  1045. if ( not entry.value ) then
  1046. entry.value = entry.spellNames[random(#entry.spellNames)];
  1047. end
  1048. entry.pending = true;
  1049. return entry.value;
  1050. end
  1051. -- Slash commands that are protected from tampering
  1052. local SecureCmdList = { };
  1053. function IsSecureCmd(command)
  1054. command = strupper(command);
  1055. -- first check the hash table
  1056. if ( hash_SecureCmdList[command] ) then
  1057. return true;
  1058. end
  1059. for index, value in pairs(SecureCmdList) do
  1060. local i = 1;
  1061. local cmdString = _G["SLASH_"..index..i];
  1062. while ( cmdString ) do
  1063. cmdString = strupper(cmdString);
  1064. if ( cmdString == command ) then
  1065. return true;
  1066. end
  1067. i = i + 1;
  1068. cmdString = _G["SLASH_"..index..i];
  1069. end
  1070. end
  1071. end
  1072. function SecureCmdItemParse(item)
  1073. if ( not item ) then
  1074. return nil, nil, nil;
  1075. end
  1076. local bag, slot = strmatch(item, "^(%d+)%s+(%d+)$");
  1077. if ( not bag ) then
  1078. slot = strmatch(item, "^(%d+)$");
  1079. end
  1080. if ( bag ) then
  1081. item = GetContainerItemLink(bag, slot);
  1082. elseif ( slot ) then
  1083. item = GetInventoryItemLink("player", slot);
  1084. end
  1085. return item, bag, slot;
  1086. end
  1087. function SecureCmdUseItem(name, bag, slot, target)
  1088. if ( bag ) then
  1089. UseContainerItem(bag, slot, target);
  1090. elseif ( slot ) then
  1091. UseInventoryItem(slot, target);
  1092. else
  1093. UseItemByName(name, target);
  1094. end
  1095. end
  1096. --These functions are terrible, but they support legacy slash commands.
  1097. function ValueToBoolean(valueToCheck, defaultValue, defaultReturn)
  1098. if ( type(valueToCheck) == "nil" ) then
  1099. return false;
  1100. elseif ( type(valueToCheck) == "boolean" ) then
  1101. return valueToCheck;
  1102. elseif ( type(valueToCheck) == "number" ) then
  1103. return valueToCheck ~= 0;
  1104. elseif ( type(valueToCheck) == "string" ) then
  1105. return StringToBoolean(valueToCheck, defaultReturn);
  1106. else
  1107. return defaultReturn;
  1108. end
  1109. end
  1110. function StringToBoolean(stringToCheck, defaultReturn)
  1111. stringToCheck = string.lower(stringToCheck);
  1112. local firstChar = string.sub(stringToCheck, 1, 1);
  1113. if ( firstChar == "0" or firstChar == "n" or firstChar == "f" or stringToCheck == "off" or stringToCheck == "disabled" ) then
  1114. return false;
  1115. elseif ( firstChar == "1" or firstChar == "2" or firstChar == "3" or firstChar == "4" or firstChar == "5" or
  1116. firstChar == "6" or firstChar == "7" or firstChar == "8" or firstChar == "9" or firstChar == "y" or
  1117. firstChar == "t" or stringToCheck == "on" or stringToCheck == "enabled" ) then
  1118. return true;
  1119. end
  1120. return defaultReturn;
  1121. end
  1122. SecureCmdList["STARTATTACK"] = function(msg)
  1123. local action, target = SecureCmdOptionParse(msg);
  1124. if ( action ) then
  1125. if ( not target or target == "target" ) then
  1126. target = action;
  1127. end
  1128. StartAttack(target);
  1129. end
  1130. end
  1131. SecureCmdList["STOPATTACK"] = function(msg)
  1132. if ( SecureCmdOptionParse(msg) ) then
  1133. StopAttack();
  1134. end
  1135. end
  1136. -- We want to prefer spells for /cast and items for /use but we can use either
  1137. SecureCmdList["CAST"] = function(msg)
  1138. local action, target = SecureCmdOptionParse(msg);
  1139. if ( action ) then
  1140. local spellExists = DoesSpellExist(action)
  1141. local name, bag, slot = SecureCmdItemParse(action);
  1142. if ( spellExists ) then
  1143. CastSpellByName(action, target);
  1144. elseif ( slot or GetItemInfo(name) ) then
  1145. SecureCmdUseItem(name, bag, slot, target);
  1146. end
  1147. end
  1148. end
  1149. SecureCmdList["USE"] = function(msg)
  1150. local action, target = SecureCmdOptionParse(msg);
  1151. if ( action ) then
  1152. local name, bag, slot = SecureCmdItemParse(action);
  1153. if ( slot or GetItemInfo(name) ) then
  1154. SecureCmdUseItem(name, bag, slot, target);
  1155. else
  1156. CastSpellByName(action, target);
  1157. end
  1158. end
  1159. end
  1160. SecureCmdList["CASTRANDOM"] = function(msg)
  1161. local actions, target = SecureCmdOptionParse(msg);
  1162. if ( actions ) then
  1163. local action = ExecuteCastRandom(actions);
  1164. local name, bag, slot = SecureCmdItemParse(action);
  1165. if ( slot or GetItemInfo(name) ) then
  1166. SecureCmdUseItem(name, bag, slot, target);
  1167. else
  1168. CastSpellByName(action, target);
  1169. end
  1170. end
  1171. end
  1172. SecureCmdList["USERANDOM"] = SecureCmdList["CASTRANDOM"];
  1173. SecureCmdList["CASTSEQUENCE"] = function(msg)
  1174. local sequence, target = SecureCmdOptionParse(msg);
  1175. if ( sequence and sequence ~= "" ) then
  1176. ExecuteCastSequence(sequence, target);
  1177. end
  1178. end
  1179. SecureCmdList["STOPCASTING"] = function(msg)
  1180. if ( SecureCmdOptionParse(msg) ) then
  1181. SpellStopCasting();
  1182. end
  1183. end
  1184. SecureCmdList["STOPSPELLTARGET"] = function(msg)
  1185. if ( SecureCmdOptionParse(msg) ) then
  1186. SpellStopTargeting();
  1187. end
  1188. end
  1189. SecureCmdList["CANCELAURA"] = function(msg)
  1190. local spell = SecureCmdOptionParse(msg);
  1191. if ( spell ) then
  1192. CancelSpellByName(spell);
  1193. end
  1194. end
  1195. SecureCmdList["CANCELFORM"] = function(msg)
  1196. if ( SecureCmdOptionParse(msg) ) then
  1197. CancelShapeshiftForm();
  1198. end
  1199. end
  1200. SecureCmdList["EQUIP"] = function(msg)
  1201. local item = SecureCmdOptionParse(msg);
  1202. if ( item ) then
  1203. EquipItemByName((SecureCmdItemParse(item)));
  1204. end
  1205. end
  1206. SecureCmdList["EQUIP_TO_SLOT"] = function(msg)
  1207. local action = SecureCmdOptionParse(msg);
  1208. if ( action ) then
  1209. local slot, item = strmatch(action, "^(%d+)%s+(.*)");
  1210. if ( item ) then
  1211. if ( PaperDoll_IsEquippedSlot(slot) ) then
  1212. EquipItemByName(SecureCmdItemParse(item), slot);
  1213. else
  1214. -- user specified a bad slot number (slot that you can't equip an item to)
  1215. ChatFrame_DisplayUsageError(format(ERROR_SLASH_EQUIP_TO_SLOT, EQUIPPED_FIRST, EQUIPPED_LAST));
  1216. end
  1217. elseif ( slot ) then
  1218. -- user specified a slot but not an item
  1219. ChatFrame_DisplayUsageError(format(ERROR_SLASH_EQUIP_TO_SLOT, EQUIPPED_FIRST, EQUIPPED_LAST));
  1220. end
  1221. end
  1222. end
  1223. SecureCmdList["CHANGEACTIONBAR"] = function(msg)
  1224. local page = SecureCmdOptionParse(msg);
  1225. if ( page and page ~= "" ) then
  1226. page = tonumber(page);
  1227. if (page and page >= 1 and page <= NUM_ACTIONBAR_PAGES) then
  1228. ChangeActionBarPage(page);
  1229. else
  1230. ChatFrame_DisplayUsageError(format(ERROR_SLASH_CHANGEACTIONBAR, 1, NUM_ACTIONBAR_PAGES));
  1231. end
  1232. end
  1233. end
  1234. SecureCmdList["SWAPACTIONBAR"] = function(msg)
  1235. local action = SecureCmdOptionParse(msg);
  1236. if ( action ) then
  1237. local a, b = strmatch(action, "(%d+)%s+(%d+)");
  1238. if ( a and b ) then
  1239. a = tonumber(a);
  1240. b = tonumber(b);
  1241. if ( ( a and a >= 1 and a <= NUM_ACTIONBAR_PAGES ) and ( b and b >= 1 and b <= NUM_ACTIONBAR_PAGES ) ) then
  1242. if ( GetActionBarPage() == a ) then
  1243. ChangeActionBarPage(b);
  1244. else
  1245. ChangeActionBarPage(a);
  1246. end
  1247. else
  1248. ChatFrame_DisplayUsageError(format(ERROR_SLASH_SWAPACTIONBAR, 1, NUM_ACTIONBAR_PAGES));
  1249. end
  1250. end
  1251. end
  1252. end
  1253. SecureCmdList["TARGET"] = function(msg)
  1254. local action, target = SecureCmdOptionParse(msg);
  1255. if ( action ) then
  1256. if ( not target or target == "target" ) then
  1257. target = action;
  1258. end
  1259. TargetUnit(target);
  1260. end
  1261. end
  1262. SecureCmdList["TARGET_EXACT"] = function(msg)
  1263. local action, target = SecureCmdOptionParse(msg);
  1264. if ( action ) then
  1265. if ( not target or target == "target" ) then
  1266. target = action;
  1267. end
  1268. TargetUnit(target, true);
  1269. end
  1270. end
  1271. SecureCmdList["TARGET_NEAREST_ENEMY"] = function(msg)
  1272. local action = SecureCmdOptionParse(msg);
  1273. if ( action ) then
  1274. TargetNearestEnemy(ValueToBoolean(action, false));
  1275. end
  1276. end
  1277. SecureCmdList["TARGET_NEAREST_ENEMY_PLAYER"] = function(msg)
  1278. local action = SecureCmdOptionParse(msg);
  1279. if ( action ) then
  1280. TargetNearestEnemyPlayer(ValueToBoolean(action, false));
  1281. end
  1282. end
  1283. SecureCmdList["TARGET_NEAREST_FRIEND"] = function(msg)
  1284. local action = SecureCmdOptionParse(msg);
  1285. if ( action ) then
  1286. TargetNearestFriend(ValueToBoolean(action, false));
  1287. end
  1288. end
  1289. SecureCmdList["TARGET_NEAREST_FRIEND_PLAYER"] = function(msg)
  1290. local action = SecureCmdOptionParse(msg);
  1291. if ( action ) then
  1292. TargetNearestFriendPlayer(ValueToBoolean(action, false));
  1293. end
  1294. end
  1295. SecureCmdList["TARGET_NEAREST_PARTY"] = function(msg)
  1296. local action = SecureCmdOptionParse(msg);
  1297. if ( action ) then
  1298. TargetNearestPartyMember(ValueToBoolean(action, false));
  1299. end
  1300. end
  1301. SecureCmdList["TARGET_NEAREST_RAID"] = function(msg)
  1302. local action = SecureCmdOptionParse(msg);
  1303. if ( action ) then
  1304. TargetNearestRaidMember(ValueToBoolean(action, false));
  1305. end
  1306. end
  1307. SecureCmdList["CLEARTARGET"] = function(msg)
  1308. if ( SecureCmdOptionParse(msg) ) then
  1309. ClearTarget();
  1310. end
  1311. end
  1312. SecureCmdList["TARGET_LAST_TARGET"] = function(msg)
  1313. if ( SecureCmdOptionParse(msg) ) then
  1314. TargetLastTarget();
  1315. end
  1316. end
  1317. SecureCmdList["TARGET_LAST_ENEMY"] = function(msg)
  1318. local action = SecureCmdOptionParse(msg);
  1319. if ( action ) then
  1320. TargetLastEnemy(action);
  1321. end
  1322. end
  1323. SecureCmdList["TARGET_LAST_FRIEND"] = function(msg)
  1324. local action = SecureCmdOptionParse(msg);
  1325. if ( action ) then
  1326. TargetLastFriend(action);
  1327. end
  1328. end
  1329. SecureCmdList["ASSIST"] = function(msg)
  1330. if ( msg == "" ) then
  1331. AssistUnit();
  1332. else
  1333. local action, target = SecureCmdOptionParse(msg);
  1334. if ( action ) then
  1335. if ( not target ) then
  1336. target = action;
  1337. end
  1338. AssistUnit(target);
  1339. end
  1340. end
  1341. end
  1342. SecureCmdList["FOCUS"] = function(msg)
  1343. if ( msg == "" ) then
  1344. FocusUnit();
  1345. else
  1346. local action, target = SecureCmdOptionParse(msg);
  1347. if ( action ) then
  1348. if ( not target or target == "focus" ) then
  1349. target = action;
  1350. end
  1351. FocusUnit(target);
  1352. end
  1353. end
  1354. end
  1355. SecureCmdList["CLEARFOCUS"] = function(msg)
  1356. if ( SecureCmdOptionParse(msg) ) then
  1357. ClearFocus();
  1358. end
  1359. end
  1360. SecureCmdList["MAINTANKON"] = function(msg)
  1361. local action, target = SecureCmdOptionParse(msg);
  1362. if ( action ) then
  1363. if ( not target ) then
  1364. target = action;
  1365. end
  1366. if ( target == "" ) then
  1367. target = "target";
  1368. end
  1369. SetPartyAssignment("MAINTANK", target);
  1370. end
  1371. end
  1372. SecureCmdList["MAINTANKOFF"] = function(msg)
  1373. local action, target = SecureCmdOptionParse(msg);
  1374. if ( action ) then
  1375. if ( not target ) then
  1376. target = action;
  1377. end
  1378. if ( target == "" ) then
  1379. target = "target";
  1380. end
  1381. ClearPartyAssignment("MAINTANK", target);
  1382. end
  1383. end
  1384. SecureCmdList["MAINASSISTON"] = function(msg)
  1385. local action, target = SecureCmdOptionParse(msg);
  1386. if ( action ) then
  1387. if ( not target ) then
  1388. target = action;
  1389. end
  1390. if ( target == "" ) then
  1391. target = "target";
  1392. end
  1393. SetPartyAssignment("MAINASSIST", target);
  1394. end
  1395. end
  1396. SecureCmdList["MAINASSISTOFF"] = function(msg)
  1397. local action, target = SecureCmdOptionParse(msg);
  1398. if ( action ) then
  1399. if ( not target ) then
  1400. target = action;
  1401. end
  1402. if ( target == "" ) then
  1403. target = "target";
  1404. end
  1405. ClearPartyAssignment("MAINASSIST", target);
  1406. end
  1407. end
  1408. SecureCmdList["DUEL"] = function(msg)
  1409. StartDuel(msg)
  1410. end
  1411. SecureCmdList["DUEL_CANCEL"] = function(msg)
  1412. ForfeitDuel()
  1413. end
  1414. SecureCmdList["PET_ATTACK"] = function(msg)
  1415. local action, target = SecureCmdOptionParse(msg);
  1416. if ( action ) then
  1417. if ( not target or target == "pettarget" ) then
  1418. target = action;
  1419. end
  1420. PetAttack(target);
  1421. end
  1422. end
  1423. SecureCmdList["PET_FOLLOW"] = function(msg)
  1424. if ( SecureCmdOptionParse(msg) ) then
  1425. PetFollow();
  1426. end
  1427. end
  1428. SecureCmdList["PET_MOVE_TO"] = function(msg)
  1429. local action, target = SecureCmdOptionParse(msg);
  1430. if ( action ) then
  1431. PetMoveTo(target);
  1432. end
  1433. end
  1434. SecureCmdList["PET_STAY"] = function(msg)
  1435. if ( SecureCmdOptionParse(msg) ) then
  1436. PetWait();
  1437. end
  1438. end
  1439. SecureCmdList["PET_PASSIVE"] = function(msg)
  1440. if ( SecureCmdOptionParse(msg) ) then
  1441. PetPassiveMode();
  1442. end
  1443. end
  1444. SecureCmdList["PET_DEFENSIVE"] = function(msg)
  1445. if ( SecureCmdOptionParse(msg) ) then
  1446. PetDefensiveMode();
  1447. end
  1448. end
  1449. SecureCmdList["PET_DEFENSIVEASSIST"] = function(msg)
  1450. if ( SecureCmdOptionParse(msg) ) then
  1451. PetDefensiveAssistMode();
  1452. end
  1453. end
  1454. SecureCmdList["PET_AGGRESSIVE"] = function(msg)
  1455. if ( SecureCmdOptionParse(msg) ) then
  1456. PetAggressiveMode();
  1457. end
  1458. end
  1459. SecureCmdList["PET_ASSIST"] = function(msg)
  1460. if ( SecureCmdOptionParse(msg) ) then
  1461. PetAssistMode();
  1462. end
  1463. end
  1464. SecureCmdList["PET_AUTOCASTON"] = function(msg)
  1465. local spell = SecureCmdOptionParse(msg);
  1466. if ( spell ) then
  1467. EnableSpellAutocast(spell);
  1468. end
  1469. end
  1470. SecureCmdList["PET_AUTOCASTOFF"] = function(msg)
  1471. local spell = SecureCmdOptionParse(msg);
  1472. if ( spell ) then
  1473. DisableSpellAutocast(spell);
  1474. end
  1475. end
  1476. SecureCmdList["PET_AUTOCASTTOGGLE"] = function(msg)
  1477. local spell = SecureCmdOptionParse(msg);
  1478. if ( spell ) then
  1479. ToggleSpellAutocast(spell);
  1480. end
  1481. end
  1482. SecureCmdList["STOPMACRO"] = function(msg)
  1483. if ( SecureCmdOptionParse(msg) ) then
  1484. StopMacro();
  1485. end
  1486. end
  1487. SecureCmdList["CANCELQUEUEDSPELL"] = function(msg)
  1488. if ( SecureCmdOptionParse(msg) ) then
  1489. SpellCancelQueuedSpell();
  1490. end
  1491. end
  1492. SecureCmdList["CLICK"] = function(msg)
  1493. local action = SecureCmdOptionParse(msg);
  1494. if ( action and action ~= "" ) then
  1495. local name, mouseButton, down = strmatch(action, "([^%s]+)%s+([^%s]+)%s*(.*)");
  1496. if ( not name ) then
  1497. name = action;
  1498. end
  1499. local button = GetClickFrame(name);
  1500. if ( button and button:IsObjectType("Button") and not button:IsForbidden() ) then
  1501. button:Click(mouseButton, down);
  1502. end
  1503. end
  1504. end
  1505. SecureCmdList["EQUIP_SET"] = function(msg)
  1506. local set = SecureCmdOptionParse(msg);
  1507. if ( set and set ~= "" ) then
  1508. C_EquipmentSet.UseEquipmentSet(C_EquipmentSet.GetEquipmentSetID(set));
  1509. end
  1510. end
  1511. SecureCmdList["WORLD_MARKER"] = function(msg)
  1512. local marker = SecureCmdOptionParse(msg);
  1513. if ( tonumber(marker) ) then
  1514. PlaceRaidMarker(tonumber(marker));
  1515. end
  1516. end
  1517. SecureCmdList["CLEAR_WORLD_MARKER"] = function(msg)
  1518. local marker = SecureCmdOptionParse(msg);
  1519. if ( tonumber(marker) ) then
  1520. ClearRaidMarker(tonumber(marker));
  1521. elseif ( type(marker) == "string" and strtrim(strlower(marker)) == strlower(ALL) ) then
  1522. ClearRaidMarker(nil); --Clear all world markers.
  1523. end
  1524. end
  1525. SecureCmdList["SUMMON_BATTLE_PET"] = function(msg)
  1526. local pet = SecureCmdOptionParse(msg);
  1527. if ( type(pet) == "string" ) then
  1528. local _, petID = C_PetJournal.FindPetIDByName(string.trim(pet));
  1529. if ( petID ) then
  1530. C_PetJournal.SummonPetByGUID(petID);
  1531. else
  1532. C_PetJournal.SummonPetByGUID(pet);
  1533. end
  1534. end
  1535. end
  1536. SecureCmdList["RANDOMPET"] = function(msg)
  1537. if ( SecureCmdOptionParse(msg) ) then
  1538. C_PetJournal.SummonRandomPet(false);
  1539. end
  1540. end
  1541. SecureCmdList["RANDOMFAVORITEPET"] = function(msg)
  1542. if ( SecureCmdOptionParse(msg) ) then
  1543. C_PetJournal.SummonRandomPet(true);
  1544. end
  1545. end
  1546. SecureCmdList["DISMISSBATTLEPET"] = function(msg)
  1547. if ( SecureCmdOptionParse(msg) ) then
  1548. local petID = C_PetJournal.GetSummonedPetGUID();
  1549. if ( petID ) then
  1550. C_PetJournal.SummonPetByGUID(petID);
  1551. end
  1552. end
  1553. end
  1554. SecureCmdList["PET_DISMISS"] = function(msg)
  1555. if ( PetCanBeAbandoned() ) then
  1556. CastSpellByID(HUNTER_DISMISS_PET);
  1557. else
  1558. PetDismiss();
  1559. end
  1560. end
  1561. SecureCmdList["USE_TOY"] = function(msg)
  1562. local toyName = SecureCmdOptionParse(msg);
  1563. if ( toyName and toyName ~= "" ) then
  1564. UseToyByName(toyName)
  1565. end
  1566. end
  1567. SecureCmdList["LOGOUT"] = function(msg)
  1568. Logout();
  1569. end
  1570. SecureCmdList["QUIT"] = function(msg)
  1571. if (Kiosk.IsEnabled()) then
  1572. return;
  1573. end
  1574. Quit();
  1575. end
  1576. SecureCmdList["GUILD_UNINVITE"] = function(msg)
  1577. if(msg == "") then
  1578. msg = UnitName("target");
  1579. end
  1580. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1581. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1582. return;
  1583. end
  1584. GuildUninvite(msg);
  1585. end
  1586. SecureCmdList["GUILD_PROMOTE"] = function(msg)
  1587. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1588. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1589. return;
  1590. end
  1591. GuildPromote(msg);
  1592. end
  1593. SecureCmdList["GUILD_DEMOTE"] = function(msg)
  1594. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1595. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1596. return;
  1597. end
  1598. GuildDemote(msg);
  1599. end
  1600. SecureCmdList["GUILD_LEADER"] = function(msg)
  1601. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1602. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1603. return;
  1604. end
  1605. GuildSetLeader(msg);
  1606. end
  1607. SecureCmdList["GUILD_LEAVE"] = function(msg)
  1608. GuildLeave();
  1609. end
  1610. SecureCmdList["GUILD_DISBAND"] = function(msg)
  1611. if ( IsGuildLeader() ) then
  1612. StaticPopup_Show("CONFIRM_GUILD_DISBAND");
  1613. end
  1614. end
  1615. function AddSecureCmd(cmd, cmdString)
  1616. if not issecure() then
  1617. error("Cannot call AddSecureCmd from insecure code");
  1618. end
  1619. hash_SecureCmdList[strupper(cmdString)] = cmd;
  1620. end
  1621. function AddSecureCmdAliases(cmd, ...)
  1622. for i = 1, select("#", ...) do
  1623. local cmdString = select(i, ...);
  1624. AddSecureCmd(cmd, cmdString);
  1625. end
  1626. end
  1627. -- Pre-populate the secure command hash table
  1628. for index, value in pairs(SecureCmdList) do
  1629. local i = 1;
  1630. local cmdString = "";
  1631. while cmdString do
  1632. cmdString = _G["SLASH_"..index..i];
  1633. if cmdString then
  1634. AddSecureCmd(value, cmdString);
  1635. i = i + 1;
  1636. end
  1637. end
  1638. end
  1639. -- Slash commands
  1640. SlashCmdList = { };
  1641. SlashCmdList["CONSOLE"] = function(msg)
  1642. forceinsecure();
  1643. ConsoleExec(msg);
  1644. end
  1645. SlashCmdList["CHATLOG"] = function(msg)
  1646. local info = ChatTypeInfo["SYSTEM"];
  1647. if ( LoggingChat() ) then
  1648. LoggingChat(false);
  1649. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGDISABLED, info.r, info.g, info.b, info.id);
  1650. else
  1651. LoggingChat(true);
  1652. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGENABLED, info.r, info.g, info.b, info.id);
  1653. end
  1654. end
  1655. SlashCmdList["COMBATLOG"] = function(msg)
  1656. local info = ChatTypeInfo["SYSTEM"];
  1657. if ( LoggingCombat() ) then
  1658. LoggingCombat(false);
  1659. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGDISABLED, info.r, info.g, info.b, info.id);
  1660. else
  1661. LoggingCombat(true);
  1662. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGENABLED, info.r, info.g, info.b, info.id);
  1663. end
  1664. end
  1665. SlashCmdList["INVITE"] = function(msg)
  1666. if(msg == "") then
  1667. msg = GetUnitName("target", true)
  1668. end
  1669. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1670. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1671. return;
  1672. end
  1673. if(msg == nil) then
  1674. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1675. return;
  1676. end
  1677. C_PartyInfo.InviteUnit(msg);
  1678. end
  1679. SlashCmdList["REQUEST_INVITE"] = function(msg)
  1680. if(msg == "") then
  1681. msg = GetUnitName("target", true)
  1682. end
  1683. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1684. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1685. return;
  1686. end
  1687. if(msg == nil) then
  1688. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1689. return;
  1690. end
  1691. C_PartyInfo.RequestInviteFromUnit(msg);
  1692. end
  1693. SlashCmdList["UNINVITE"] = function(msg)
  1694. if(msg == "") then
  1695. msg = GetUnitName("target", true);
  1696. end
  1697. if(msg == nil) then
  1698. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1699. return;
  1700. end
  1701. UninviteUnit(msg);
  1702. end
  1703. SlashCmdList["PROMOTE"] = function(msg)
  1704. PromoteToLeader(msg);
  1705. end
  1706. SlashCmdList["REPLY"] = function(msg, editBox)
  1707. local lastTell = ChatEdit_GetLastTellTarget();
  1708. if ( lastTell ) then
  1709. msg = SubstituteChatMessageBeforeSend(msg);
  1710. SendChatMessage(msg, "WHISPER", editBox.languageID, lastTell);
  1711. else
  1712. -- error message
  1713. end
  1714. end
  1715. SlashCmdList["HELP"] = function(msg)
  1716. ChatFrame_DisplayHelpText(DEFAULT_CHAT_FRAME);
  1717. end
  1718. SlashCmdList["MACROHELP"] = function(msg)
  1719. ChatFrame_DisplayMacroHelpText(DEFAULT_CHAT_FRAME);
  1720. end
  1721. SlashCmdList["TIME"] = function(msg)
  1722. ChatFrame_DisplayGameTime(DEFAULT_CHAT_FRAME);
  1723. end
  1724. SlashCmdList["PLAYED"] = function(msg)
  1725. RequestTimePlayed();
  1726. end
  1727. SlashCmdList["FOLLOW"] = function(msg)
  1728. FollowUnit(msg);
  1729. end
  1730. SlashCmdList["TRADE"] = function(msg)
  1731. InitiateTrade("target");
  1732. end
  1733. SlashCmdList["INSPECT"] = function(msg)
  1734. InspectUnit("target");
  1735. end
  1736. SlashCmdList["JOIN"] = function(msg)
  1737. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1738. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1739. if(name == "") then
  1740. local joinhelp = CHAT_JOIN_HELP;
  1741. local info = ChatTypeInfo["SYSTEM"];
  1742. DEFAULT_CHAT_FRAME:AddMessage(joinhelp, info.r, info.g, info.b, info.id);
  1743. else
  1744. local zoneChannel, channelName = JoinPermanentChannel(name, password, DEFAULT_CHAT_FRAME:GetID(), 1);
  1745. if ( channelName ) then
  1746. name = channelName;
  1747. end
  1748. if ( not zoneChannel ) then
  1749. local info = ChatTypeInfo["CHANNEL"];
  1750. DEFAULT_CHAT_FRAME:AddMessage(CHAT_INVALID_NAME_NOTICE, info.r, info.g, info.b, info.id);
  1751. return;
  1752. end
  1753. local i = 1;
  1754. while ( DEFAULT_CHAT_FRAME.channelList[i] ) do
  1755. i = i + 1;
  1756. end
  1757. DEFAULT_CHAT_FRAME.channelList[i] = name;
  1758. DEFAULT_CHAT_FRAME.zoneChannelList[i] = zoneChannel;
  1759. end
  1760. end
  1761. SlashCmdList["LEAVE"] = function(msg)
  1762. local name = strmatch(msg, "%s*([^%s]+)");
  1763. if ( name ) then
  1764. LeaveChannelByName(name);
  1765. end
  1766. end
  1767. SlashCmdList["LIST_CHANNEL"] = function(msg)
  1768. local name = strmatch(msg, "%s*([^%s]+)");
  1769. if ( name ) then
  1770. ListChannelByName(name);
  1771. else
  1772. ListChannels();
  1773. end
  1774. end
  1775. SlashCmdList["CHAT_HELP"] =
  1776. function(msg)
  1777. ChatFrame_DisplayChatHelp(DEFAULT_CHAT_FRAME)
  1778. end
  1779. SlashCmdList["CHAT_PASSWORD"] =
  1780. function(msg)
  1781. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1782. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1783. SetChannelPassword(name, password);
  1784. end
  1785. SlashCmdList["CHAT_OWNER"] =
  1786. function(msg)
  1787. local channel = gsub(msg, "%s*([^%s]+).*", "%1");
  1788. local newOwner = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1789. if ( not channel or not newOwner ) then
  1790. return;
  1791. end
  1792. local newOwnerLen = strlen(newOwner);
  1793. if ( newOwnerLen > MAX_CHARACTER_NAME_BYTES ) then
  1794. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1795. return;
  1796. end
  1797. if ( channel ~= "" ) then
  1798. if ( newOwnerLen > 0 ) then
  1799. SetChannelOwner(channel, newOwner);
  1800. else
  1801. DisplayChannelOwner(channel);
  1802. end
  1803. end
  1804. end
  1805. SlashCmdList["CHAT_MODERATOR"] =
  1806. function(msg)
  1807. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1808. if ( not channel or not player ) then
  1809. return;
  1810. end
  1811. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1812. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1813. return;
  1814. end
  1815. ChannelModerator(channel, player);
  1816. end
  1817. SlashCmdList["CHAT_UNMODERATOR"] =
  1818. function(msg)
  1819. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1820. if ( not channel or not player ) then
  1821. return;
  1822. end
  1823. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1824. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1825. return;
  1826. end
  1827. if ( channel and player ) then
  1828. ChannelUnmoderator(channel, player);
  1829. end
  1830. end
  1831. SlashCmdList["CHAT_CINVITE"] =
  1832. function(msg)
  1833. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1834. if ( not channel or not player ) then
  1835. return;
  1836. end
  1837. if ( channel and player ) then
  1838. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1839. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1840. return;
  1841. end
  1842. ChannelInvite(channel, player);
  1843. end
  1844. end
  1845. SlashCmdList["CHAT_KICK"] =
  1846. function(msg)
  1847. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1848. if ( not channel or not player ) then
  1849. return;
  1850. end
  1851. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1852. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1853. return;
  1854. end
  1855. if ( channel and player ) then
  1856. ChannelKick(channel, player);
  1857. end
  1858. end
  1859. SlashCmdList["CHAT_BAN"] =
  1860. function(msg)
  1861. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1862. if ( not channel or not player ) then
  1863. return;
  1864. end
  1865. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1866. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1867. return;
  1868. end
  1869. if ( channel and player ) then
  1870. ChannelBan(channel, player);
  1871. end
  1872. end
  1873. SlashCmdList["CHAT_UNBAN"] =
  1874. function(msg)
  1875. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1876. if ( not channel or not player ) then
  1877. return;
  1878. end
  1879. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1880. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1881. return;
  1882. end
  1883. if ( channel and player ) then
  1884. ChannelUnban(channel, player);
  1885. end
  1886. end
  1887. SlashCmdList["CHAT_ANNOUNCE"] =
  1888. function(msg)
  1889. local channel = strmatch(msg, "%s*([^%s]+)");
  1890. if ( channel ) then
  1891. ChannelToggleAnnouncements(channel);
  1892. end
  1893. end
  1894. SlashCmdList["GUILD_INVITE"] = function(msg)
  1895. if(msg == "") then
  1896. msg = GetUnitName("target", true);
  1897. end
  1898. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1899. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1900. return;
  1901. end
  1902. GuildInvite(msg);
  1903. end
  1904. SlashCmdList["GUILD_MOTD"] = function(msg)
  1905. GuildSetMOTD(msg)
  1906. end
  1907. SlashCmdList["GUILD_INFO"] = function(msg)
  1908. GuildInfo();
  1909. end
  1910. SlashCmdList["GUILD_ROSTER"] = function(msg)
  1911. if ( IsInGuild() ) then
  1912. GuildFrame_LoadUI();
  1913. if ( GuildFrame ) then
  1914. GuildFrameTab2:Click();
  1915. ShowUIPanel(GuildFrame);
  1916. end
  1917. end
  1918. end
  1919. --SlashCmdList["GUILD_HELP"] = function(msg)
  1920. -- ChatFrame_DisplayGuildHelp(DEFAULT_CHAT_FRAME);
  1921. --end
  1922. SlashCmdList["CHAT_AFK"] = function(msg)
  1923. SendChatMessage(msg, "AFK");
  1924. end
  1925. SlashCmdList["CHAT_DND"] = function(msg)
  1926. SendChatMessage(msg, "DND");
  1927. end
  1928. SlashCmdList["WHO"] = function(msg)
  1929. if (Kiosk.IsEnabled()) then
  1930. return;
  1931. end
  1932. if ( msg == "" ) then
  1933. msg = WhoFrame_GetDefaultWhoCommand();
  1934. ShowWhoPanel();
  1935. end
  1936. WhoFrameEditBox:SetText(msg);
  1937. C_FriendList.SendWho(msg);
  1938. end
  1939. SlashCmdList["CHANNEL"] = function(msg, editBox)
  1940. msg = SubstituteChatMessageBeforeSend(msg);
  1941. SendChatMessage(msg, "CHANNEL", editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  1942. end
  1943. SlashCmdList["FRIENDS"] = function(msg)
  1944. if msg == "" and UnitIsPlayer("target") then
  1945. msg = GetUnitName("target", true)
  1946. end
  1947. if not msg or msg == "" then
  1948. ToggleFriendsPanel();
  1949. else
  1950. local player, note = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1951. if player then
  1952. C_FriendList.AddOrRemoveFriend(player, note);
  1953. end
  1954. end
  1955. end
  1956. SlashCmdList["REMOVEFRIEND"] = function(msg)
  1957. C_FriendList.RemoveFriend(msg);
  1958. end
  1959. SlashCmdList["IGNORE"] = function(msg)
  1960. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1961. local bNetIDAccount = BNet_GetBNetIDAccount(msg);
  1962. if ( bNetIDAccount ) then
  1963. if ( BNIsFriend(bNetIDAccount) ) then
  1964. SendSystemMessage(ERR_CANNOT_IGNORE_BN_FRIEND);
  1965. else
  1966. BNSetBlocked(bNetIDAccount, not BNIsBlocked(bNetIDAccount));
  1967. end
  1968. else
  1969. C_FriendList.AddOrDelIgnore(msg);
  1970. end
  1971. else
  1972. ToggleIgnorePanel();
  1973. end
  1974. end
  1975. SlashCmdList["UNIGNORE"] = function(msg)
  1976. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1977. C_FriendList.DelIgnore(msg);
  1978. else
  1979. ToggleIgnorePanel();
  1980. end
  1981. end
  1982. SlashCmdList["SCRIPT"] = function(msg)
  1983. if ( not ScriptsDisallowedForBeta() ) then
  1984. if ( not AreDangerousScriptsAllowed() ) then
  1985. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  1986. return;
  1987. end
  1988. RunScript(msg);
  1989. end
  1990. end
  1991. SlashCmdList["RANDOM"] = function(msg)
  1992. local num1 = gsub(msg, "(%s*)(%d+)(.*)", "%2", 1);
  1993. local rest = gsub(msg, "(%s*)(%d+)(.*)", "%3", 1);
  1994. local num2 = "";
  1995. local numSubs;
  1996. if ( rest ~= "" ) then
  1997. num2, numSubs = gsub(msg, "(%s*)(%d+)([-%s]+)(%d+)(.*)", "%4", 1);
  1998. if ( numSubs == 0 ) then
  1999. num2 = "";
  2000. end
  2001. end
  2002. if ( num1 == "" and num2 == "" ) then
  2003. RandomRoll("1", "100");
  2004. elseif ( num2 == "" ) then
  2005. RandomRoll("1", num1);
  2006. else
  2007. RandomRoll(num1, num2);
  2008. end
  2009. end
  2010. SlashCmdList["MACRO"] = function(msg)
  2011. ShowMacroFrame();
  2012. end
  2013. SlashCmdList["PVP"] = function(msg)
  2014. TogglePVP();
  2015. end
  2016. SlashCmdList["RAID_INFO"] = function(msg)
  2017. RaidFrame.slashCommand = 1;
  2018. if ( ( GetNumSavedInstances() + GetNumSavedWorldBosses() > 0 ) and not RaidInfoFrame:IsVisible() ) then
  2019. ToggleRaidFrame();
  2020. RaidInfoFrame:Show();
  2021. elseif ( not RaidFrame:IsVisible() ) then
  2022. ToggleRaidFrame();
  2023. end
  2024. end
  2025. SlashCmdList["READYCHECK"] = function(msg)
  2026. if ( UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") ) then
  2027. DoReadyCheck();
  2028. end
  2029. end
  2030. --[[All of this information is obtainable through the armory now.
  2031. SlashCmdList["SAVEGUILDROSTER"] = function(msg)
  2032. SaveGuildRoster();
  2033. end]]
  2034. SlashCmdList["DUNGEONS"] = function(msg)
  2035. ToggleLFDParentFrame();
  2036. end
  2037. SlashCmdList["BENCHMARK"] = function(msg)
  2038. SetTaxiBenchmarkMode(ValueToBoolean(msg), true);
  2039. end
  2040. SlashCmdList["DISMOUNT"] = function(msg)
  2041. if ( SecureCmdOptionParse(msg) ) then
  2042. Dismount();
  2043. end
  2044. end
  2045. SlashCmdList["LEAVEVEHICLE"] = function(msg)
  2046. if ( SecureCmdOptionParse(msg) ) then
  2047. VehicleExit();
  2048. end
  2049. end
  2050. SlashCmdList["RESETCHAT"] = function(msg)
  2051. FCF_ResetAllWindows();
  2052. end
  2053. SlashCmdList["ENABLE_ADDONS"] = function(msg)
  2054. EnableAllAddOns(msg);
  2055. ReloadUI();
  2056. end
  2057. SlashCmdList["DISABLE_ADDONS"] = function(msg)
  2058. DisableAllAddOns(msg);
  2059. ReloadUI();
  2060. end
  2061. SlashCmdList["STOPWATCH"] = function(msg)
  2062. if ( not IsAddOnLoaded("Blizzard_TimeManager") ) then
  2063. UIParentLoadAddOn("Blizzard_TimeManager");
  2064. end
  2065. if ( StopwatchFrame ) then
  2066. local text = strmatch(msg, "%s*([^%s]+)%s*");
  2067. if ( text ) then
  2068. text = strlower(text);
  2069. -- in any of the following cases, the stopwatch will be shown
  2070. StopwatchFrame:Show();
  2071. -- try to match a command
  2072. local function MatchCommand(param, text)
  2073. local i, compare;
  2074. i = 1;
  2075. repeat
  2076. compare = _G[param..i];
  2077. if ( compare and compare == text ) then
  2078. return true;
  2079. end
  2080. i = i + 1;
  2081. until ( not compare );
  2082. return false;
  2083. end
  2084. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PLAY", text) ) then
  2085. Stopwatch_Play();
  2086. return;
  2087. end
  2088. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PAUSE", text) ) then
  2089. Stopwatch_Pause();
  2090. return;
  2091. end
  2092. if ( MatchCommand("SLASH_STOPWATCH_PARAM_STOP", text) ) then
  2093. Stopwatch_Clear();
  2094. return;
  2095. end
  2096. -- try to match a countdown
  2097. -- kinda ghetto, but hey, it's simple and it works =)
  2098. local hour, minute, second = strmatch(msg, "(%d+):(%d+):(%d+)");
  2099. if ( not hour ) then
  2100. minute, second = strmatch(msg, "(%d+):(%d+)");
  2101. if ( not minute ) then
  2102. second = strmatch(msg, "(%d+)");
  2103. end
  2104. end
  2105. Stopwatch_StartCountdown(tonumber(hour), tonumber(minute), tonumber(second));
  2106. else
  2107. Stopwatch_Toggle();
  2108. end
  2109. end
  2110. end
  2111. SlashCmdList["CALENDAR"] = function(msg)
  2112. if ( not IsAddOnLoaded("Blizzard_Calendar") ) then
  2113. UIParentLoadAddOn("Blizzard_Calendar");
  2114. end
  2115. if ( Calendar_Toggle ) then
  2116. Calendar_Toggle();
  2117. end
  2118. end
  2119. SlashCmdList["ACHIEVEMENTUI"] = function(msg)
  2120. ToggleAchievementFrame();
  2121. end
  2122. SlashCmdList["SET_TITLE"] = function(msg)
  2123. local name = SecureCmdOptionParse(msg);
  2124. if ( name and name ~= "") then
  2125. if(not SetTitleByName(name)) then
  2126. UIErrorsFrame:AddMessage(TITLE_DOESNT_EXIST, 1.0, 0.1, 0.1, 1.0);
  2127. end
  2128. else
  2129. SetCurrentTitle(-1)
  2130. end
  2131. end
  2132. SlashCmdList["USE_TALENT_SPEC"] = function(msg)
  2133. local group = SecureCmdOptionParse(msg);
  2134. if ( group ) then
  2135. local groupNumber = tonumber(group);
  2136. if ( groupNumber ) then
  2137. --SetActiveSpecGroup(groupNumber);
  2138. end
  2139. end
  2140. end
  2141. -- easier method to turn on/off errors for macros
  2142. SlashCmdList["UI_ERRORS_OFF"] = function(msg)
  2143. UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE");
  2144. SetCVar("Sound_EnableSFX", "0");
  2145. end
  2146. SlashCmdList["UI_ERRORS_ON"] = function(msg)
  2147. UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE");
  2148. SetCVar("Sound_EnableSFX", "1");
  2149. end
  2150. SlashCmdList["FRAMESTACK"] = function(msg)
  2151. UIParentLoadAddOn("Blizzard_DebugTools");
  2152. local showHiddenArg, showRegionsArg, showAnchorsArg;
  2153. local pattern = "^%s*(%S+)(.*)$";
  2154. showHiddenArg, msg = string.match(msg or "", pattern);
  2155. showRegionsArg, msg = string.match(msg or "", pattern);
  2156. showAnchorsArg, msg = string.match(msg or "", pattern);
  2157. -- If no parameters are passed the defaults specified by these cvars are used instead.
  2158. local showHiddenDefault = FrameStackTooltip_IsShowHiddenEnabled();
  2159. local showRegionsDefault = FrameStackTooltip_IsShowRegionsEnabled();
  2160. local showAnchorsDefault = FrameStackTooltip_IsShowAnchorsEnabled();
  2161. local showHidden = StringToBoolean(showHiddenArg or "", showHiddenDefault);
  2162. local showRegions = StringToBoolean(showRegionsArg or "", showRegionsDefault);
  2163. local showAnchors = StringToBoolean(showAnchorsArg or "", showAnchorsDefault);
  2164. FrameStackTooltip_Toggle(showHidden, showRegions, showAnchors);
  2165. end
  2166. SlashCmdList["EVENTTRACE"] = function(msg)
  2167. UIParentLoadAddOn("Blizzard_DebugTools");
  2168. EventTraceFrame_HandleSlashCmd(msg);
  2169. end
  2170. if IsGMClient() then
  2171. SLASH_TEXELVIS1 = "/texelvis";
  2172. SLASH_TEXELVIS2 = "/tvis";
  2173. SlashCmdList["TEXELVIS"] = function(msg)
  2174. UIParentLoadAddOn("Blizzard_DebugTools");
  2175. TexelSnappingVisualizer:Show();
  2176. end
  2177. end
  2178. SlashCmdList["TABLEINSPECT"] = function(msg)
  2179. if ( Kiosk.IsEnabled() or ScriptsDisallowedForBeta() ) then
  2180. return;
  2181. end
  2182. if ( not AreDangerousScriptsAllowed() ) then
  2183. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  2184. return;
  2185. end
  2186. forceinsecure();
  2187. UIParentLoadAddOn("Blizzard_DebugTools");
  2188. local focusedTable = nil;
  2189. if msg ~= "" and msg ~= " " then
  2190. local focusedFunction = loadstring(("return %s"):format(msg));
  2191. focusedTable = focusedFunction and focusedFunction();
  2192. end
  2193. if focusedTable and type(focusedTable) == "table" then
  2194. DisplayTableInspectorWindow(focusedTable);
  2195. else
  2196. local highlightFrame = FrameStackTooltip:SetFrameStack();
  2197. if highlightFrame then
  2198. DisplayTableInspectorWindow(highlightFrame);
  2199. else
  2200. DisplayTableInspectorWindow(UIParent);
  2201. end
  2202. end
  2203. end
  2204. SlashCmdList["DUMP"] = function(msg)
  2205. if (not Kiosk.IsEnabled() and not ScriptsDisallowedForBeta()) then
  2206. if ( not AreDangerousScriptsAllowed() ) then
  2207. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  2208. return;
  2209. end
  2210. UIParentLoadAddOn("Blizzard_DebugTools");
  2211. DevTools_DumpCommand(msg);
  2212. end
  2213. end
  2214. SlashCmdList["RELOAD"] = function(msg)
  2215. ReloadUI();
  2216. end
  2217. SlashCmdList["WARGAME"] = function(msg)
  2218. -- Parameters are (playername, area, isTournamentMode). Since the player name can be multiple words,
  2219. -- we pass in theses parameters as a whitespace delimited string and let the C side tokenize it
  2220. StartWarGameByName(msg);
  2221. end
  2222. SlashCmdList["SPECTATOR_WARGAME"] = function(msg)
  2223. local target1, target2, size, area, isTournamentMode = strmatch(msg, "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s*([^%s]*)%s*([^%s]*)")
  2224. if (not target1 or not target2 or not size) then
  2225. return;
  2226. end
  2227. local bnetIDGameAccount1 = BNet_GetBNetIDAccountFromCharacterName(target1) or BNet_GetBNetIDAccount(target1);
  2228. if not bnetIDGameAccount1 then
  2229. ConsolePrint("Failed to find StartSpectatorWarGame target1:", target1);
  2230. end
  2231. local bnetIDGameAccount2 = BNet_GetBNetIDAccountFromCharacterName(target2) or BNet_GetBNetIDAccount(target2);
  2232. if not bnetIDGameAccount2 then
  2233. ConsolePrint("Failed to find StartSpectatorWarGame target2:", target2);
  2234. end
  2235. if (area == "" or area == "nil" or area == "0") then area = nil end
  2236. StartSpectatorWarGame(bnetIDGameAccount1 or target1, bnetIDGameAccount2 or target2, size, area, ValueToBoolean(isTournamentMode));
  2237. end
  2238. SlashCmdList["GUILDFINDER"] = function(msg)
  2239. if ( GameLimitedMode_IsActive() ) then
  2240. UIErrorsFrame:AddMessage(ERR_RESTRICTED_ACCOUNT_TRIAL, 1.0, 0.1, 0.1, 1.0);
  2241. else
  2242. ToggleGuildFinder();
  2243. end
  2244. end
  2245. SlashCmdList["TARGET_MARKER"] = function(msg)
  2246. local marker, target = SecureCmdOptionParse(msg);
  2247. if ( not target ) then
  2248. target = "target";
  2249. end
  2250. if ( tonumber(marker) ) then
  2251. SetRaidTarget(target, tonumber(marker)); --Using /tm 0 will clear the target marker.
  2252. end
  2253. end
  2254. SlashCmdList["OPEN_LOOT_HISTORY"] = function(msg)
  2255. ToggleLootHistoryFrame();
  2256. end
  2257. SlashCmdList["RAIDFINDER"] = function(msg)
  2258. PVEFrame_ToggleFrame("GroupFinderFrame", RaidFinderFrame);
  2259. end
  2260. SlashCmdList["SHARE"] = function(msg)
  2261. -- Allow if any social platforms are enabled (currently only Twitter)
  2262. if (C_Social.IsSocialEnabled()) then
  2263. SocialFrame_LoadUI();
  2264. Social_ToggleShow(msg);
  2265. end
  2266. end
  2267. SlashCmdList["API"] = function(msg)
  2268. APIDocumentation_LoadUI();
  2269. APIDocumentation:HandleSlashCommand(msg);
  2270. end
  2271. SlashCmdList["COMMENTATOR_OVERRIDE"] = function(msg)
  2272. if not IsAddOnLoaded("Blizzard_Commentator") then
  2273. return;
  2274. end
  2275. local originalName, overrideName = msg:match("^(%S-)%s+(.+)");
  2276. if not originalName or not overrideName then
  2277. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2278. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2279. return;
  2280. end
  2281. originalName = originalName:sub(1, 1):upper() .. originalName:sub(2, -1);
  2282. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(originalName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2283. C_Commentator.AddPlayerOverrideName(originalName, overrideName);
  2284. -- Also add character name without the realm if we got CharacterName-Realm.
  2285. -- Prepend possible realm separators with % so they are matched literally
  2286. local realmSeparateMatchList = string.gsub(REALM_SEPARATORS, ".", "%%%1");
  2287. local characterName = string.match(originalName, "(..-)["..realmSeparateMatchList.."].");
  2288. if characterName and characterName ~= originalName then
  2289. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(characterName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2290. C_Commentator.AddPlayerOverrideName(characterName, overrideName);
  2291. end
  2292. end
  2293. SlashCmdList["COMMENTATOR_NAMETEAM"] = function(msg)
  2294. if not IsAddOnLoaded("Blizzard_Commentator") then
  2295. return;
  2296. end
  2297. local teamIndex, teamName = msg:match("^(%d+) (.+)");
  2298. teamIndex = tonumber(teamIndex);
  2299. if not teamIndex or not teamName then
  2300. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2301. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2302. return;
  2303. end
  2304. if not C_Commentator.IsSpectating() then
  2305. DEFAULT_CHAT_FRAME:AddMessage(CONTEXT_ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2306. return;
  2307. else
  2308. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_NAMETEAM_SUCCESS):format(teamIndex, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2309. end
  2310. C_Commentator.AssignPlayersToTeamInCurrentInstance(teamIndex, teamName);
  2311. end
  2312. SlashCmdList["COMMENTATOR_ASSIGNPLAYER"] = function(msg)
  2313. if not IsAddOnLoaded("Blizzard_Commentator") then
  2314. return;
  2315. end
  2316. local playerName, teamName = msg:match("^(%S-)%s+(.+)");
  2317. if not playerName or not teamName then
  2318. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2319. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2320. return;
  2321. end
  2322. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_ASSIGNPLAYER_SUCCESS):format(playerName, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2323. C_Commentator.AssignPlayerToTeam(playerName, teamName);
  2324. end
  2325. SlashCmdList["RESET_COMMENTATOR_SETTINGS"] = function(msg)
  2326. if not IsAddOnLoaded("Blizzard_Commentator") then
  2327. return;
  2328. end
  2329. C_Commentator.ResetSettings();
  2330. end
  2331. SlashCmdList["VOICECHAT"] = function(msg)
  2332. if msg == "" then
  2333. local info = ChatTypeInfo["SYSTEM"];
  2334. DEFAULT_CHAT_FRAME:AddMessage(VOICE_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2335. return;
  2336. end
  2337. local name = msg;
  2338. local lowerName = string.lower(name);
  2339. if lowerName == string.lower(VOICE_LEAVE_COMMAND) then
  2340. local channelID = C_VoiceChat.GetActiveChannelID();
  2341. if channelID then
  2342. C_VoiceChat.DeactivateChannel(channelID);
  2343. end
  2344. return;
  2345. end
  2346. local channelType;
  2347. local communityID;
  2348. local streamID;
  2349. if lowerName == string.lower(PARTY) then
  2350. channelType = Enum.ChatChannelType.Private_Party;
  2351. elseif lowerName == string.lower(INSTANCE) then
  2352. channelType = Enum.ChatChannelType.Public_Party;
  2353. elseif lowerName == string.lower(GUILD) then
  2354. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Guild);
  2355. elseif lowerName == string.lower(OFFICER) then
  2356. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Officer);
  2357. else
  2358. local communityName, streamName = string.split(":", name);
  2359. communityID, streamID = CommunitiesUtil.FindCommunityAndStreamByName(communityName, streamName);
  2360. end
  2361. if channelType then
  2362. if channelType ~= C_VoiceChat.GetActiveChannelType() then
  2363. local activate = true;
  2364. ChannelFrame:TryJoinVoiceChannelByType(channelType, activate);
  2365. end
  2366. elseif communityID and streamID then
  2367. local activeChannelID = C_VoiceChat.GetActiveChannelID();
  2368. local communityStreamChannel = C_VoiceChat.GetChannelForCommunityStream(communityID, streamID);
  2369. local communityStreamChannelID = communityStreamChannel and communityStreamChannel.channelID;
  2370. if not activeChannelID or activeChannelID ~= communityStreamChannelID then
  2371. ChannelFrame:TryJoinCommunityStreamChannel(communityID, streamID);
  2372. end
  2373. end
  2374. end
  2375. SlashCmdList["COMMUNITY"] = function(msg)
  2376. if msg == "" then
  2377. local info = ChatTypeInfo["SYSTEM"];
  2378. DEFAULT_CHAT_FRAME:AddMessage(COMMUNITY_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2379. return;
  2380. end
  2381. local command, clubType = string.split(" ", string.lower(msg));
  2382. local loadCommunity = function()
  2383. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  2384. Communities_LoadUI();
  2385. ToggleCommunitiesFrame();
  2386. end
  2387. end
  2388. if command == string.lower(COMMUNITY_COMMAND_JOIN) then
  2389. loadCommunity();
  2390. AddCommunitiesFlow_Toggle()
  2391. elseif command == string.lower(COMMUNITY_COMMAND_CREATE) then
  2392. if clubType == string.lower(COMMUNITY_COMMAND_CHARACTER) then
  2393. loadCommunity();
  2394. CommunitiesCreateCommunityDialog();
  2395. elseif clubType == string.lower(COMMUNITY_COMMAND_BATTLENET) then
  2396. loadCommunity();
  2397. CommunitiesCreateBattleNetDialog();
  2398. end
  2399. end
  2400. end
  2401. function RegisterNewSlashCommand(callback, command, commandAlias)
  2402. local name = string.upper(command);
  2403. _G["SLASH_"..name.."1"] = "/"..command;
  2404. _G["SLASH_"..name.."2"] = "/"..commandAlias;
  2405. SlashCmdList[name] = callback;
  2406. end
  2407. SlashCmdList["COUNTDOWN"] = function(msg)
  2408. local num1 = gsub(msg, "(%s*)(%d+)", "%2");
  2409. if(num1 ~= "" and tonumber(num1) <= MAX_COUNTDOWN_SECONDS) then
  2410. C_PartyInfo.DoCountdown(num1);
  2411. end
  2412. end
  2413. function ChatFrame_SetupListProxyTable(list)
  2414. if ( getmetatable(list) ) then
  2415. return;
  2416. end
  2417. setmetatable(list, { __index = {} });
  2418. end
  2419. function ChatFrame_ImportListToHash(list, hash)
  2420. for k, v in pairs(list) do
  2421. local i = 1;
  2422. local tag = _G["SLASH_"..k..i];
  2423. while(tag) do
  2424. tag = strupper(tag);
  2425. if ( hash ) then
  2426. hash[tag] = v;
  2427. end
  2428. hash_ChatTypeInfoList[tag] = k; --Also need to import it here for all types.
  2429. i = i + 1;
  2430. tag = _G["SLASH_"..k..i];
  2431. end
  2432. --Add the item we removed to the proxy table.
  2433. local proxyTable = getmetatable(list).__index;
  2434. proxyTable[k] = v;
  2435. end
  2436. table.wipe(list);
  2437. end
  2438. function ChatFrame_ImportEmoteTokensToHash()
  2439. -- Hook up per-faction emotes before we build the emote list hash.
  2440. local factionGroup = UnitFactionGroup("player");
  2441. if ( factionGroup == "Alliance" ) then
  2442. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEALLIANCE";
  2443. elseif ( factionGroup == "Horde" ) then
  2444. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEHORDE";
  2445. end
  2446. local i = 1;
  2447. local j = 1;
  2448. local cmdString = _G["EMOTE"..i.."_CMD"..j];
  2449. while ( i <= MAXEMOTEINDEX ) do
  2450. local token = _G["EMOTE"..i.."_TOKEN"];
  2451. -- if the code in here changes - change the corresponding code above
  2452. if ( token and cmdString) then
  2453. hash_EmoteTokenList[strupper(cmdString)] = token; -- add to hash
  2454. end
  2455. j = j + 1;
  2456. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2457. if ( not cmdString ) then
  2458. i = i + 1;
  2459. j = 1;
  2460. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2461. end
  2462. end
  2463. end
  2464. function ChatFrame_ImportAllListsToHash()
  2465. ChatFrame_ImportListToHash(SecureCmdList, hash_SecureCmdList);
  2466. ChatFrame_ImportListToHash(SlashCmdList, hash_SlashCmdList);
  2467. ChatFrame_ImportListToHash(ChatTypeInfo);
  2468. end
  2469. ChatFrame_SetupListProxyTable(SecureCmdList);
  2470. ChatFrame_SetupListProxyTable(SlashCmdList);
  2471. ChatFrame_SetupListProxyTable(ChatTypeInfo);
  2472. for index, value in pairs(ChatTypeInfo) do
  2473. value.r = 1.0;
  2474. value.g = 1.0;
  2475. value.b = 1.0;
  2476. value.id = GetChatTypeIndex(index);
  2477. end
  2478. ChatFrame_ImportAllListsToHash();
  2479. ChatFrame_ImportEmoteTokensToHash();
  2480. -- ChatFrame functions
  2481. function ChatFrame_OnLoad(self)
  2482. self:SetTimeVisible(120.0);
  2483. self:SetMaxLines(128);
  2484. self:SetFontObject(ChatFontNormal);
  2485. self:SetIndentedWordWrap(true);
  2486. self:SetJustifyH("LEFT");
  2487. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  2488. self:RegisterEvent("UPDATE_CHAT_COLOR");
  2489. self:RegisterEvent("UPDATE_CHAT_WINDOWS");
  2490. self:RegisterEvent("CHAT_MSG_CHANNEL");
  2491. self:RegisterEvent("CHAT_MSG_COMMUNITIES_CHANNEL");
  2492. self:RegisterEvent("CLUB_REMOVED");
  2493. self:RegisterEvent("UPDATE_INSTANCE_INFO");
  2494. self:RegisterEvent("UPDATE_CHAT_COLOR_NAME_BY_CLASS");
  2495. self:RegisterEvent("VARIABLES_LOADED");
  2496. self:RegisterEvent("CHAT_SERVER_DISCONNECTED");
  2497. self:RegisterEvent("CHAT_SERVER_RECONNECTED");
  2498. self:RegisterEvent("BN_CONNECTED");
  2499. self:RegisterEvent("BN_DISCONNECTED");
  2500. self:RegisterEvent("PLAYER_REPORT_SUBMITTED");
  2501. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  2502. self:RegisterEvent("CHARACTER_UPGRADE_SPELL_TIER_SET");
  2503. self:RegisterEvent("ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED");
  2504. self:RegisterEvent("NEWCOMER_GRADUATION");
  2505. self:RegisterEvent("CHAT_REGIONAL_STATUS_CHANGED");
  2506. self:RegisterEvent("CHAT_REGIONAL_SEND_FAILED");
  2507. self.channelList = {};
  2508. self.zoneChannelList = {};
  2509. self.messageTypeList = {};
  2510. self.defaultLanguage = GetDefaultLanguage(); --If PLAYER_ENTERING_WORLD hasn't been called yet, this is nil, but it'll be fixed whent he event is fired.
  2511. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2512. end
  2513. function ChatFrame_RegisterForMessages(self, ...)
  2514. local messageGroup;
  2515. local index = 1;
  2516. for i=1, select("#", ...) do
  2517. messageGroup = ChatTypeGroup[select(i, ...)];
  2518. if ( messageGroup ) then
  2519. self.messageTypeList[index] = select(i, ...);
  2520. for index, value in pairs(messageGroup) do
  2521. self:RegisterEvent(value);
  2522. end
  2523. index = index + 1;
  2524. end
  2525. end
  2526. end
  2527. function ChatFrame_RegisterForChannels(self, ...)
  2528. local index = 1;
  2529. for i=1, select("#", ...), 2 do
  2530. self.channelList[index], self.zoneChannelList[index] = select(i, ...);
  2531. index = index + 1;
  2532. end
  2533. end
  2534. function ChatFrame_AddMessageGroup(chatFrame, group)
  2535. local info = ChatTypeGroup[group];
  2536. if ( info ) then
  2537. tinsert(chatFrame.messageTypeList, group);
  2538. for index, value in pairs(info) do
  2539. chatFrame:RegisterEvent(value);
  2540. end
  2541. AddChatWindowMessages(chatFrame:GetID(), group);
  2542. end
  2543. end
  2544. function ChatFrame_ContainsMessageGroup(chatFrame, group)
  2545. for i, messageType in pairs(chatFrame.messageTypeList) do
  2546. if group == messageType then
  2547. return true;
  2548. end
  2549. end
  2550. return false;
  2551. end
  2552. function ChatFrame_AddSingleMessageType(chatFrame, messageType)
  2553. local group = ChatTypeGroupInverted[messageType];
  2554. local info = ChatTypeGroup[group];
  2555. if ( info ) then
  2556. if (not tContains(chatFrame.messageTypeList, group)) then
  2557. tinsert(chatFrame.messageTypeList, group);
  2558. end
  2559. for index, value in pairs(info) do
  2560. if (value == messageType) then
  2561. chatFrame:RegisterEvent(value);
  2562. end
  2563. end
  2564. end
  2565. end
  2566. function ChatFrame_RemoveMessageGroup(chatFrame, group)
  2567. local info = ChatTypeGroup[group];
  2568. if ( info ) then
  2569. for index, value in pairs(chatFrame.messageTypeList) do
  2570. if ( strupper(value) == strupper(group) ) then
  2571. chatFrame.messageTypeList[index] = nil;
  2572. end
  2573. end
  2574. for index, value in pairs(info) do
  2575. chatFrame:UnregisterEvent(value);
  2576. end
  2577. RemoveChatWindowMessages(chatFrame:GetID(), group);
  2578. end
  2579. end
  2580. function ChatFrame_RemoveAllMessageGroups(chatFrame)
  2581. for index, value in pairs(chatFrame.messageTypeList) do
  2582. for eventIndex, eventValue in pairs(ChatTypeGroup[value]) do
  2583. chatFrame:UnregisterEvent(eventValue);
  2584. end
  2585. RemoveChatWindowMessages(chatFrame:GetID(), value);
  2586. end
  2587. chatFrame.messageTypeList = {};
  2588. end
  2589. function ChatFrame_ContainsChannel(chatFrame, channel)
  2590. for i, channelName in pairs(chatFrame.channelList) do
  2591. if channel == channelName then
  2592. return true;
  2593. end
  2594. end
  2595. return false;
  2596. end
  2597. function ChatFrame_AddNewCommunitiesChannel(chatFrameIndex, clubId, streamId, setEditBoxToChannel)
  2598. local clubInfo = C_Club.GetClubInfo(clubId);
  2599. if clubInfo then
  2600. C_Club.AddClubStreamChatChannel(clubId, streamId);
  2601. local channelColor = DEFAULT_CHAT_CHANNEL_COLOR;
  2602. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2603. if clubInfo.clubType == Enum.ClubType.BattleNet then
  2604. channelColor = BATTLENET_FONT_COLOR;
  2605. local channel = Chat_GetCommunitiesChannel(clubId, streamId);
  2606. ChangeChatColor(channel, channelColor:GetRGB());
  2607. end
  2608. local chatFrame = _G["ChatFrame"..chatFrameIndex];
  2609. ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel);
  2610. end
  2611. end
  2612. function ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel)
  2613. local channelIndex = ChatFrame_AddChannel(chatFrame, channelName);
  2614. chatFrame:AddMessage(COMMUNITIES_CHANNEL_ADDED_TO_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), channelColor:GetRGB());
  2615. if setEditBoxToChannel then
  2616. chatFrame.editBox:SetAttribute("channelTarget", channelIndex);
  2617. chatFrame.editBox:SetAttribute("chatType", "CHANNEL");
  2618. chatFrame.editBox:SetAttribute("stickyType", "CHANNEL");
  2619. ChatEdit_UpdateHeader(chatFrame.editBox);
  2620. end
  2621. end
  2622. function ChatFrame_CanAddChannel()
  2623. return C_ChatInfo.GetNumActiveChannels() < MAX_WOW_CHAT_CHANNELS;
  2624. end
  2625. function ChatFrame_AddChannel(chatFrame, channel)
  2626. local channelIndex = nil;
  2627. local zoneChannel = AddChatWindowChannel(chatFrame:GetID(), channel);
  2628. if ( zoneChannel ) then
  2629. local i = 1;
  2630. while ( chatFrame.channelList[i] ) do
  2631. i = i + 1;
  2632. end
  2633. chatFrame.channelList[i] = channel;
  2634. chatFrame.zoneChannelList[i] = zoneChannel;
  2635. local localId = GetChannelName(channel);
  2636. channelIndex = localId;
  2637. end
  2638. return channelIndex;
  2639. end
  2640. local function ChatFrame_CheckAddChannel(chatFrame, eventType, channelID)
  2641. -- This is called in the event that a user receives chat events for a channel that isn't enabled for any chat frames.
  2642. -- Minor hack, because chat channel filtering is backed by the client, but driven entirely from Lua.
  2643. -- This solves the issue of Guides abdicating their status, and then re-applying in the same game session, unless ChatFrame_AddChannel
  2644. -- is called, the channel filter will be off even though it's still enabled in the client, since abdication removes the chat channel and its config.
  2645. -- Only add to default (since multiple chat frames receive the event and we don't want to add to others)
  2646. if chatFrame ~= DEFAULT_CHAT_FRAME then
  2647. return false;
  2648. end
  2649. -- Only add if the user is joining a channel
  2650. if eventType ~= "YOU_CHANGED" then
  2651. return false;
  2652. end
  2653. -- Only add regional channels
  2654. if not C_ChatInfo.IsChannelRegionalForChannelID(channelID) then
  2655. return false;
  2656. end
  2657. return ChatFrame_AddChannel(chatFrame, C_ChatInfo.GetChannelShortcutForChannelID(channelID)) ~= nil;
  2658. end
  2659. function ChatFrame_GetCommunitiesChannelLocalID(clubId, streamId)
  2660. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2661. local localID = GetChannelName(channelName);
  2662. return localID;
  2663. end
  2664. function ChatFrame_RemoveCommunitiesChannel(chatFrame, clubId, streamId, omitMessage)
  2665. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2666. local channelIndex = ChatFrame_RemoveChannel(chatFrame, channelName);
  2667. if not omitMessage then
  2668. local r, g, b = Chat_GetCommunitiesChannelColor(clubId, streamId);
  2669. chatFrame:AddMessage(COMMUNITIES_CHANNEL_REMOVED_FROM_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), r, g, b);
  2670. end
  2671. end
  2672. function ChatFrame_RemoveChannel(chatFrame, channel)
  2673. for index, value in pairs(chatFrame.channelList) do
  2674. if ( strupper(channel) == strupper(value) ) then
  2675. chatFrame.channelList[index] = nil;
  2676. chatFrame.zoneChannelList[index] = nil;
  2677. end
  2678. end
  2679. local localId = GetChannelName(channel);
  2680. RemoveChatWindowChannel(chatFrame:GetID(), channel);
  2681. return localId;
  2682. end
  2683. function ChatFrame_RemoveAllChannels(chatFrame)
  2684. for index, value in pairs(chatFrame.channelList) do
  2685. RemoveChatWindowChannel(chatFrame:GetID(), value);
  2686. end
  2687. chatFrame.channelList = {};
  2688. chatFrame.zoneChannelList = {};
  2689. end
  2690. function ChatFrame_AddPrivateMessageTarget(chatFrame, chatTarget)
  2691. ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget);
  2692. if ( chatFrame.privateMessageList ) then
  2693. chatFrame.privateMessageList[strlower(chatTarget)] = true;
  2694. else
  2695. chatFrame.privateMessageList = { [strlower(chatTarget)] = true };
  2696. end
  2697. end
  2698. function ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget)
  2699. if ( chatFrame.privateMessageList ) then
  2700. chatFrame.privateMessageList[strlower(chatTarget)] = nil;
  2701. end
  2702. end
  2703. function ChatFrame_ExcludePrivateMessageTarget(chatFrame, chatTarget)
  2704. ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget);
  2705. if ( chatFrame.excludePrivateMessageList ) then
  2706. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = true;
  2707. else
  2708. chatFrame.excludePrivateMessageList = { [strlower(chatTarget)] = true };
  2709. end
  2710. end
  2711. function ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget)
  2712. if ( chatFrame.excludePrivateMessageList ) then
  2713. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = nil;
  2714. end
  2715. end
  2716. function ChatFrame_ReceiveAllPrivateMessages(chatFrame)
  2717. chatFrame.privateMessageList = nil;
  2718. chatFrame.excludePrivateMessageList = nil;
  2719. end
  2720. -- Set up a private editbox to handle macro execution
  2721. do
  2722. local function GetDefaultChatEditBox(field)
  2723. return DEFAULT_CHAT_FRAME.editBox;
  2724. end
  2725. local editbox = CreateFrame("Editbox", "MacroEditBox");
  2726. editbox:RegisterEvent("EXECUTE_CHAT_LINE");
  2727. editbox:SetScript("OnEvent",
  2728. function(self,event,line)
  2729. if ( event == "EXECUTE_CHAT_LINE" ) then
  2730. local defaulteditbox = securecall(GetDefaultChatEditBox);
  2731. self:SetAttribute("chatType", defaulteditbox:GetAttribute("chatType"));
  2732. self:SetAttribute("tellTarget", defaulteditbox:GetAttribute("tellTarget"));
  2733. self:SetAttribute("channelTarget", ChatEdit_GetChannelTarget(defaulteditbox));
  2734. self:SetText(line);
  2735. ChatEdit_SendText(self);
  2736. end
  2737. end
  2738. );
  2739. editbox:Hide();
  2740. end
  2741. function ChatFrame_OnEvent(self, event, ...)
  2742. if ( ChatFrame_ConfigEventHandler(self, event, ...) ) then
  2743. return;
  2744. end
  2745. if ( ChatFrame_SystemEventHandler(self, event, ...) ) then
  2746. return
  2747. end
  2748. if ( ChatFrame_MessageEventHandler(self, event, ...) ) then
  2749. return
  2750. end
  2751. end
  2752. function ChatFrame_UpdateColorByID(self, chatTypeID, r, g, b)
  2753. local function TransformColorByID(text, messageR, messageG, messageB, messageChatTypeID, messageAccessID, lineID)
  2754. if messageChatTypeID == chatTypeID then
  2755. return true, r, g, b;
  2756. end
  2757. return false;
  2758. end
  2759. self:AdjustMessageColors(TransformColorByID);
  2760. end
  2761. -- NOTE: The leave channel event happens before the channel info is removed from the client, so excludeChannels that you're leaving if you don't
  2762. -- want to count them.
  2763. local function GetFirstChannelIDOfChannelMatchingRuleset(ruleset, excludeChannel)
  2764. for i = 1, GetNumDisplayChannels() do
  2765. local localID, _, active = select(4, GetChannelDisplayInfo(i));
  2766. if active and localID and localID > 0 and localID ~= excludeChannel then
  2767. if C_ChatInfo.GetChannelRuleset(localID) == ruleset then
  2768. return localID;
  2769. end
  2770. end
  2771. end
  2772. return nil;
  2773. end
  2774. function GetSlashCommandForChannelOpenChat(localID)
  2775. return "/" .. localID;
  2776. end
  2777. local function HasNewcomerChannelEnabled(chatFrame)
  2778. for i, channelID in ipairs(chatFrame.zoneChannelList) do
  2779. if C_ChatInfo.GetChannelRulesetForChannelID(channelID) == Enum.ChatChannelRuleset.Mentor then
  2780. return true;
  2781. end
  2782. end
  2783. return false;
  2784. end
  2785. function ChatFrame_GetDefaultChatTarget(chatFrame)
  2786. if IsActivePlayerNewcomer() then
  2787. if HasNewcomerChannelEnabled(chatFrame) then
  2788. local localID = GetFirstChannelIDOfChannelMatchingRuleset(Enum.ChatChannelRuleset.Mentor);
  2789. if localID then
  2790. return "CHANNEL", localID;
  2791. end
  2792. end
  2793. end
  2794. if #chatFrame.messageTypeList == 1 and #chatFrame.channelList == 0 then
  2795. return chatFrame.messageTypeList[1], nil;
  2796. elseif #chatFrame.messageTypeList == 0 and #chatFrame.channelList == 1 then
  2797. local channelName = chatFrame.channelList[1];
  2798. local localID = GetChannelName(channelName);
  2799. if localID ~= 0 then
  2800. return "CHANNEL", localID;
  2801. else
  2802. return "CHANNEL", channelName;
  2803. end
  2804. end
  2805. return nil;
  2806. end
  2807. function ChatFrame_UpdateDefaultChatTarget(self)
  2808. local defaultChatType, defaultChannelTarget = ChatFrame_GetDefaultChatTarget(self);
  2809. if defaultChatType then
  2810. local editBox = self.editBox;
  2811. editBox:SetAttribute("chatType", defaultChatType);
  2812. editBox:SetAttribute("stickyType", defaultChatType);
  2813. editBox:SetAttribute("channelTarget", defaultChannelTarget);
  2814. ChatEdit_UpdateHeader(editBox);
  2815. end
  2816. end
  2817. function ChatFrame_ConfigEventHandler(self, event, ...)
  2818. if ( event == "PLAYER_ENTERING_WORLD" ) then
  2819. self.defaultLanguage = GetDefaultLanguage();
  2820. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2821. if self == DEFAULT_CHAT_FRAME then
  2822. ChatEdit_UpdateNewcomerEditBoxHint(self.editBox);
  2823. local isInitialLogin, isUIReload = ...;
  2824. if isInitialLogin then
  2825. C_Timer.After(3, ChatFrame_CheckShowNewcomerGraduation);
  2826. end
  2827. end
  2828. self.chatLevelUP = {};
  2829. LevelUpDisplay_InitPlayerStates(self.chatLevelUP);
  2830. return true;
  2831. elseif ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  2832. self.defaultLanguage = GetDefaultLanguage();
  2833. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2834. return true;
  2835. elseif ( event == "ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED" ) then
  2836. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2837. return true;
  2838. elseif ( event == "NEWCOMER_GRADUATION" ) then
  2839. local isFromEvent = true;
  2840. ChatFrame_CheckShowNewcomerGraduation(isFromEvent);
  2841. return true;
  2842. elseif ( event == "UPDATE_CHAT_WINDOWS" ) then
  2843. local name, fontSize, r, g, b, a, shown, locked = FCF_GetChatWindowInfo(self:GetID());
  2844. if ( fontSize > 0 ) then
  2845. local fontFile, unused, fontFlags = self:GetFont();
  2846. self:SetFont(fontFile, fontSize, fontFlags);
  2847. end
  2848. if ( shown and not self.minimized ) then
  2849. self:Show();
  2850. end
  2851. -- Do more stuff!!!
  2852. ChatFrame_RegisterForMessages(self, GetChatWindowMessages(self:GetID()));
  2853. ChatFrame_RegisterForChannels(self, GetChatWindowChannels(self:GetID()));
  2854. ChatFrame_UpdateDefaultChatTarget(self);
  2855. -- GMOTD may have arrived before this frame registered for the event
  2856. if ( not self.checkedGMOTD and self:IsEventRegistered("GUILD_MOTD") ) then
  2857. self.checkedGMOTD = true;
  2858. ChatFrame_DisplayGMOTD(self, GetGuildRosterMOTD());
  2859. end
  2860. return true;
  2861. end
  2862. local arg1, arg2, arg3, arg4 = ...;
  2863. if ( event == "UPDATE_CHAT_COLOR" ) then
  2864. local info = ChatTypeInfo[strupper(arg1)];
  2865. if ( info ) then
  2866. info.r = arg2;
  2867. info.g = arg3;
  2868. info.b = arg4;
  2869. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2870. if ( strupper(arg1) == "WHISPER" ) then
  2871. info = ChatTypeInfo["REPLY"];
  2872. if ( info ) then
  2873. info.r = arg2;
  2874. info.g = arg3;
  2875. info.b = arg4;
  2876. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2877. end
  2878. end
  2879. end
  2880. return true;
  2881. elseif ( event == "UPDATE_CHAT_COLOR_NAME_BY_CLASS" ) then
  2882. local info = ChatTypeInfo[strupper(arg1)];
  2883. if ( info ) then
  2884. info.colorNameByClass = arg2;
  2885. if ( strupper(arg1) == "WHISPER" ) then
  2886. info = ChatTypeInfo["REPLY"];
  2887. if ( info ) then
  2888. info.colorNameByClass = arg2;
  2889. end
  2890. end
  2891. end
  2892. return true;
  2893. elseif ( event == "VARIABLES_LOADED" ) then
  2894. if ( GetCVarBool("chatMouseScroll") ) then
  2895. self:SetScript("OnMouseWheel", FloatingChatFrame_OnMouseScroll);
  2896. self:EnableMouseWheel(true);
  2897. end
  2898. self:UnregisterEvent("VARIABLES_LOADED");
  2899. return true;
  2900. end
  2901. end
  2902. local function GetRegionalChatAvailableString()
  2903. return DoesActivePlayerHaveMentorStatus() and NPEV2_CHAT_AVAILABLE or NPEV2_REGIONAL_CHAT_AVAILABLE;
  2904. end
  2905. local function GetRegionalChatUnavailableString()
  2906. return DoesActivePlayerHaveMentorStatus() and NPEV2_CHAT_UNAVAILABLE or NPEV2_REGIONAL_CHAT_UNAVAILABLE;
  2907. end
  2908. function ChatFrame_SystemEventHandler(self, event, ...)
  2909. if ( event == "TIME_PLAYED_MSG" ) then
  2910. local arg1, arg2 = ...;
  2911. ChatFrame_DisplayTimePlayed(self, arg1, arg2);
  2912. return true;
  2913. elseif ( event == "PLAYER_LEVEL_CHANGED" ) then
  2914. local oldLevel, newLevel, real = ...;
  2915. if real and oldLevel ~= 0 and newLevel ~= 0 then
  2916. if newLevel > oldLevel then
  2917. LevelUpDisplay_ChatPrint(self, newLevel, LEVEL_UP_TYPE_CHARACTER)
  2918. elseif newLevel < oldLevel then
  2919. LevelUpDisplay_InitPlayerStates(self.chatLevelUP);
  2920. end
  2921. end
  2922. return true;
  2923. elseif ( event == "QUEST_TURNED_IN" ) then
  2924. local questID, xp, money = ...;
  2925. if questID == WORLD_QUESTS_AVAILABLE_QUEST_ID then
  2926. LevelUpDisplay_ChatPrint(self, nil, TOAST_WORLD_QUESTS_UNLOCKED)
  2927. end
  2928. return true;
  2929. elseif ( event == "CHARACTER_UPGRADE_SPELL_TIER_SET" ) then
  2930. local tierIndex = ...;
  2931. if (tierIndex > 0) then
  2932. LevelUpDisplay_ChatPrint(self, tierIndex, LEVEL_UP_TYPE_SPELL_BUCKET);
  2933. end
  2934. return true;
  2935. elseif ( event == "CHARACTER_POINTS_CHANGED" ) then
  2936. local arg1 = ...;
  2937. local info = ChatTypeInfo["SYSTEM"];
  2938. return true;
  2939. elseif ( event == "GUILD_MOTD" ) then
  2940. ChatFrame_DisplayGMOTD(self, ...);
  2941. return true;
  2942. elseif ( event == "UPDATE_INSTANCE_INFO" ) then
  2943. if ( RaidFrame.hasRaidInfo ) then
  2944. local info = ChatTypeInfo["SYSTEM"];
  2945. if ( RaidFrame.slashCommand and GetNumSavedInstances() + GetNumSavedWorldBosses() == 0 and self == DEFAULT_CHAT_FRAME) then
  2946. self:AddMessage(NO_RAID_INSTANCES_SAVED, info.r, info.g, info.b, info.id);
  2947. RaidFrame.slashCommand = nil;
  2948. end
  2949. end
  2950. return true;
  2951. elseif ( event == "CHAT_SERVER_DISCONNECTED" ) then
  2952. local info = ChatTypeInfo["SYSTEM"];
  2953. local isInitialMessage = ...;
  2954. self:AddMessage(CHAT_SERVER_DISCONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2955. return true;
  2956. elseif ( event == "CHAT_SERVER_RECONNECTED" ) then
  2957. local info = ChatTypeInfo["SYSTEM"];
  2958. self:AddMessage(CHAT_SERVER_RECONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2959. return true;
  2960. elseif ( event == "BN_CONNECTED" ) then
  2961. local suppressNotification = ...;
  2962. local info = ChatTypeInfo["SYSTEM"];
  2963. if not suppressNotification then
  2964. self:AddMessage(BN_CHAT_CONNECTED, info.r, info.g, info.b, info.id);
  2965. end
  2966. elseif ( event == "BN_DISCONNECTED" ) then
  2967. local _, suppressNotification = ...;
  2968. local info = ChatTypeInfo["SYSTEM"];
  2969. if not suppressNotification then
  2970. self:AddMessage(BN_CHAT_DISCONNECTED, info.r, info.g, info.b, info.id);
  2971. end
  2972. elseif event == "CHAT_REGIONAL_STATUS_CHANGED" then
  2973. local isServiceAvailable = ...;
  2974. local info = ChatTypeInfo["SYSTEM"];
  2975. if isServiceAvailable then
  2976. self:AddMessage(GetRegionalChatAvailableString(), info.r, info.g, info.b, info.id);
  2977. else
  2978. self:AddMessage(GetRegionalChatUnavailableString(), info.r, info.g, info.b, info.id);
  2979. end
  2980. return true;
  2981. elseif event == "CHAT_REGIONAL_SEND_FAILED" then
  2982. local info = ChatTypeInfo["SYSTEM"];
  2983. self:AddMessage(GetRegionalChatUnavailableString(), info.r, info.g, info.b, info.id);
  2984. return true;
  2985. elseif ( event == "PLAYER_REPORT_SUBMITTED" ) then
  2986. local guid = ...;
  2987. FCF_RemoveAllMessagesFromChanSender(self, guid);
  2988. return true;
  2989. elseif ( event == "CLUB_REMOVED" ) then
  2990. local clubId = ...;
  2991. local streamIDs = C_ChatInfo.GetClubStreamIDs(clubId);
  2992. for k, streamID in pairs(streamIDs) do
  2993. local channelName = Chat_GetCommunitiesChannelName(clubId, streamID);
  2994. for i = 1, FCF_GetNumActiveChatFrames() do
  2995. local chatWindow = _G["ChatFrame"..i];
  2996. if ChatFrame_ContainsChannel(chatWindow, channelName) then
  2997. local omitMessage = true;
  2998. ChatFrame_RemoveCommunitiesChannel(chatWindow, clubId, streamID, omitMessage);
  2999. end
  3000. end
  3001. end
  3002. end
  3003. end
  3004. function GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  3005. local chatType = strsub(event, 10);
  3006. if ( strsub(chatType, 1, 7) == "WHISPER" ) then
  3007. chatType = "WHISPER";
  3008. end
  3009. if ( strsub(chatType, 1, 7) == "CHANNEL" ) then
  3010. chatType = "CHANNEL"..arg8;
  3011. end
  3012. local info = ChatTypeInfo[chatType];
  3013. --ambiguate guild chat names
  3014. if (chatType == "GUILD") then
  3015. arg2 = Ambiguate(arg2, "guild")
  3016. else
  3017. arg2 = Ambiguate(arg2, "none")
  3018. end
  3019. if ( arg12 and info and Chat_ShouldColorChatByClass(info) ) then
  3020. local localizedClass, englishClass, localizedRace, englishRace, sex = GetPlayerInfoByGUID(arg12)
  3021. if ( englishClass ) then
  3022. local classColorTable = RAID_CLASS_COLORS[englishClass];
  3023. if ( not classColorTable ) then
  3024. return arg2;
  3025. end
  3026. return string.format("\124cff%.2x%.2x%.2x", classColorTable.r*255, classColorTable.g*255, classColorTable.b*255)..arg2.."\124r"
  3027. end
  3028. end
  3029. return arg2;
  3030. end
  3031. function RemoveExtraSpaces(str)
  3032. return string.gsub(str, " +", " "); --Replace all instances of 5+ spaces with only 4 spaces.
  3033. end
  3034. function RemoveNewlines(str)
  3035. return string.gsub(str, "\n", "");
  3036. end
  3037. function ChatFrame_DisplayGMOTD(frame, gmotd)
  3038. if ( gmotd and (gmotd ~= "") ) then
  3039. local info = ChatTypeInfo["GUILD"];
  3040. local string = format(GUILD_MOTD_TEMPLATE, gmotd);
  3041. frame:AddMessage(string, info.r, info.g, info.b, info.id);
  3042. end
  3043. end
  3044. function ChatFrame_GetMobileEmbeddedTexture(r, g, b)
  3045. r, g, b = floor(r * 255), floor(g * 255), floor(b * 255);
  3046. return format("|TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat:14:14:0:0:16:16:0:16:0:16:%d:%d:%d|t", r, g, b);
  3047. end
  3048. function ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)
  3049. if chatGroup == "RAID" then
  3050. return true;
  3051. end
  3052. if chatGroup == "INSTANCE_CHAT" then
  3053. return IsInRaid(LE_PARTY_CATEGORY_INSTANCE);
  3054. end
  3055. return false;
  3056. end
  3057. function DoesActivePlayerHaveMentorStatus()
  3058. return C_PlayerMentorship.GetMentorshipStatus(PlayerLocation:CreateFromUnit("player")) ~= Enum.PlayerMentorshipStatus.None;
  3059. end
  3060. function IsActivePlayerMentor()
  3061. return C_PlayerMentorship.GetMentorshipStatus(PlayerLocation:CreateFromUnit("player")) == Enum.PlayerMentorshipStatus.Mentor;
  3062. end
  3063. function IsActivePlayerNewcomer()
  3064. return C_PlayerMentorship.GetMentorshipStatus(PlayerLocation:CreateFromUnit("player")) == Enum.PlayerMentorshipStatus.Newcomer;
  3065. end
  3066. local function GetPFlag(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17)
  3067. -- Renaming for clarity:
  3068. local specialFlag = arg6;
  3069. local zoneChannelID = arg7;
  3070. local localChannelID = arg8;
  3071. if specialFlag ~= "" then
  3072. if specialFlag == "GM" or specialFlag == "DEV" then
  3073. -- Add Blizzard Icon if this was sent by a GM/DEV
  3074. return "|TInterface\\ChatFrame\\UI-ChatIcon-Blizz:12:20:0:0:32:16:4:28:0:16|t ";
  3075. elseif specialFlag == "GUIDE" then
  3076. if C_PlayerMentorship.IsActivePlayerConsideredNewcomer() then
  3077. return NPEV2_CHAT_USER_TAG_GUIDE .. " "; -- possibly unable to save global string with trailing whitespace...
  3078. end
  3079. elseif specialFlag == "NEWCOMER" then
  3080. if IsActivePlayerMentor() then
  3081. return NPEV2_CHAT_USER_TAG_NEWCOMER;
  3082. end
  3083. else
  3084. return _G["CHAT_FLAG_"..specialFlag];
  3085. end
  3086. end
  3087. return "";
  3088. end
  3089. function ChatFrame_ShowNewcomerGraduation(s)
  3090. local localID = C_ChatInfo.GetGeneralChannelLocalID();
  3091. local slashCmd;
  3092. if localID then
  3093. slashCmd = GetSlashCommandForChannelOpenChat(localID);
  3094. else
  3095. slashCmd = ("%s %s"):format(SLASH_JOIN1, C_ChatInfo.GetChannelShortcutForChannelID(C_ChatInfo.GetGeneralChannelID()));
  3096. end
  3097. ChatFrame_DisplaySystemMessageInPrimary(s:format(slashCmd));
  3098. end
  3099. function ChatFrame_CheckShowNewcomerGraduation(isFromGraduationEvent)
  3100. local hasShownGraduation = GetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_NEWCOMER_GRADUATION);
  3101. if not hasShownGraduation and isFromGraduationEvent then
  3102. ChatFrame_ShowNewcomerGraduation(NPEV2_CHAT_NEWCOMER_GRADUATION);
  3103. SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_NEWCOMER_GRADUATION, true);
  3104. elseif hasShownGraduation and not isFromGraduationEvent and not GetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_NEWCOMER_GRADUATION_REMINDER) then
  3105. ChatFrame_ShowNewcomerGraduation(NPEV2_CHAT_NEWCOMER_GRADUATION_REMINDER);
  3106. SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_NEWCOMER_GRADUATION_REMINDER, true);
  3107. end
  3108. end
  3109. function ChatFrame_MessageEventHandler(self, event, ...)
  3110. if ( strsub(event, 1, 8) == "CHAT_MSG" ) then
  3111. local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17 = ...;
  3112. if (arg16) then
  3113. -- hiding sender in letterbox: do NOT even show in chat window (only shows in cinematic frame)
  3114. return true;
  3115. end
  3116. local type = strsub(event, 10);
  3117. local info = ChatTypeInfo[type];
  3118. --If it was a GM whisper, dispatch it to the GMChat addon.
  3119. if arg6 == "GM" and type == "WHISPER" then
  3120. return;
  3121. end
  3122. local filter = false;
  3123. if ( chatFilters[event] ) then
  3124. local newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14;
  3125. for _, filterFunc in next, chatFilters[event] do
  3126. filter, newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14 = filterFunc(self, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  3127. if ( filter ) then
  3128. return true;
  3129. elseif ( newarg1 ) then
  3130. arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14 = newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14;
  3131. end
  3132. end
  3133. end
  3134. local coloredName = GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  3135. local channelLength = strlen(arg4);
  3136. local infoType = type;
  3137. if ( (type == "COMMUNITIES_CHANNEL") or ((strsub(type, 1, 7) == "CHANNEL") and (type ~= "CHANNEL_LIST") and ((arg1 ~= "INVITE") or (type ~= "CHANNEL_NOTICE_USER"))) ) then
  3138. if ( arg1 == "WRONG_PASSWORD" ) then
  3139. local staticPopup = _G[StaticPopup_Visible("CHAT_CHANNEL_PASSWORD") or ""];
  3140. if ( staticPopup and strupper(staticPopup.data) == strupper(arg9) ) then
  3141. -- Don't display invalid password messages if we're going to prompt for a password (bug 102312)
  3142. return;
  3143. end
  3144. end
  3145. local found = false;
  3146. for index, value in pairs(self.channelList) do
  3147. if ( channelLength > strlen(value) ) then
  3148. -- arg9 is the channel name without the number in front...
  3149. if ( ((arg7 > 0) and (self.zoneChannelList[index] == arg7)) or (strupper(value) == strupper(arg9)) ) then
  3150. found = true;
  3151. infoType = "CHANNEL"..arg8;
  3152. info = ChatTypeInfo[infoType];
  3153. if ( (type == "CHANNEL_NOTICE") and (arg1 == "YOU_LEFT") ) then
  3154. self.channelList[index] = nil;
  3155. self.zoneChannelList[index] = nil;
  3156. end
  3157. break;
  3158. end
  3159. end
  3160. end
  3161. if not found or not info then
  3162. local eventType, channelID = arg1, arg7;
  3163. if not ChatFrame_CheckAddChannel(self, eventType, channelID) then
  3164. return true;
  3165. end
  3166. end
  3167. end
  3168. local chatGroup = Chat_GetChatCategory(type);
  3169. local chatTarget;
  3170. if ( chatGroup == "CHANNEL" ) then
  3171. chatTarget = tostring(arg8);
  3172. elseif ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  3173. if(not(strsub(arg2, 1, 2) == "|K")) then
  3174. chatTarget = strupper(arg2);
  3175. else
  3176. chatTarget = arg2;
  3177. end
  3178. end
  3179. if ( FCFManager_ShouldSuppressMessage(self, chatGroup, chatTarget) ) then
  3180. return true;
  3181. end
  3182. if ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  3183. if ( self.privateMessageList and not self.privateMessageList[strlower(arg2)] ) then
  3184. return true;
  3185. elseif ( self.excludePrivateMessageList and self.excludePrivateMessageList[strlower(arg2)]
  3186. and ( (chatGroup == "WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") or (chatGroup == "BN_WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") ) ) then
  3187. return true;
  3188. end
  3189. end
  3190. if (self.privateMessageList) then
  3191. -- Dedicated BN whisper windows need online/offline messages for only that player
  3192. if ( (chatGroup == "BN_INLINE_TOAST_ALERT" or chatGroup == "BN_WHISPER_PLAYER_OFFLINE") and not self.privateMessageList[strlower(arg2)] ) then
  3193. return true;
  3194. end
  3195. -- HACK to put certain system messages into dedicated whisper windows
  3196. if ( chatGroup == "SYSTEM") then
  3197. local matchFound = false;
  3198. local message = strlower(arg1);
  3199. for playerName, _ in pairs(self.privateMessageList) do
  3200. local playerNotFoundMsg = strlower(format(ERR_CHAT_PLAYER_NOT_FOUND_S, playerName));
  3201. local charOnlineMsg = strlower(format(ERR_FRIEND_ONLINE_SS, playerName, playerName));
  3202. local charOfflineMsg = strlower(format(ERR_FRIEND_OFFLINE_S, playerName));
  3203. if ( message == playerNotFoundMsg or message == charOnlineMsg or message == charOfflineMsg) then
  3204. matchFound = true;
  3205. break;
  3206. end
  3207. end
  3208. if (not matchFound) then
  3209. return true;
  3210. end
  3211. end
  3212. end
  3213. if ( type == "SYSTEM" or type == "SKILL" or type == "CURRENCY" or type == "MONEY" or
  3214. type == "OPENING" or type == "TRADESKILLS" or type == "PET_INFO" or type == "TARGETICONS" or type == "BN_WHISPER_PLAYER_OFFLINE") then
  3215. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3216. elseif (type == "LOOT") then
  3217. -- Append [Share] hyperlink if this is a valid social item and you are the looter.
  3218. if (C_Social.IsSocialEnabled() and UnitGUID("player") == arg12) then
  3219. -- Because it is being placed inside another hyperlink (the shareitem link created below), we have to strip off the hyperlink markup
  3220. -- The item link markup will be added back in when the shareitem link is clicked (in ItemRef.lua) and then passed to the social panel
  3221. local itemID, strippedItemLink = GetItemInfoFromHyperlink(arg1);
  3222. if (itemID and C_Social.GetLastItem() == itemID) then
  3223. arg1 = arg1 .. " " .. Social_GetShareItemLink(strippedItemLink, true);
  3224. end
  3225. end
  3226. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3227. elseif ( strsub(type,1,7) == "COMBAT_" ) then
  3228. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3229. elseif ( strsub(type,1,6) == "SPELL_" ) then
  3230. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3231. elseif ( strsub(type,1,10) == "BG_SYSTEM_" ) then
  3232. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3233. elseif ( strsub(type,1,11) == "ACHIEVEMENT" ) then
  3234. -- Append [Share] hyperlink
  3235. if (arg12 == UnitGUID("player") and C_Social.IsSocialEnabled()) then
  3236. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3237. if (achieveID) then
  3238. arg1 = arg1 .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3239. end
  3240. end
  3241. self:AddMessage(arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName))), info.r, info.g, info.b, info.id);
  3242. elseif ( strsub(type,1,18) == "GUILD_ACHIEVEMENT" ) then
  3243. local message = arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName)));
  3244. if (C_Social.IsSocialEnabled()) then
  3245. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3246. if (achieveID) then
  3247. local isGuildAchievement = select(12, GetAchievementInfo(achieveID));
  3248. if (isGuildAchievement) then
  3249. message = message .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3250. end
  3251. end
  3252. end
  3253. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3254. elseif ( type == "IGNORED" ) then
  3255. self:AddMessage(format(CHAT_IGNORED, arg2), info.r, info.g, info.b, info.id);
  3256. elseif ( type == "FILTERED" ) then
  3257. self:AddMessage(format(CHAT_FILTERED, arg2), info.r, info.g, info.b, info.id);
  3258. elseif ( type == "RESTRICTED" ) then
  3259. self:AddMessage(CHAT_RESTRICTED_TRIAL, info.r, info.g, info.b, info.id);
  3260. elseif ( type == "CHANNEL_LIST") then
  3261. if(channelLength > 0) then
  3262. self:AddMessage(format(_G["CHAT_"..type.."_GET"]..arg1, tonumber(arg8), arg4), info.r, info.g, info.b, info.id);
  3263. else
  3264. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3265. end
  3266. elseif (type == "CHANNEL_NOTICE_USER") then
  3267. local globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3268. if ( not globalstring ) then
  3269. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3270. end
  3271. if not globalstring then
  3272. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE_BN"));
  3273. return;
  3274. end
  3275. if(arg5 ~= "") then
  3276. -- TWO users in this notice (E.G. x kicked y)
  3277. self:AddMessage(format(globalstring, arg8, arg4, arg2, arg5), info.r, info.g, info.b, info.id);
  3278. elseif ( arg1 == "INVITE" ) then
  3279. local playerLink = GetPlayerLink(arg2, ("[%s]"):format(arg2), arg11);
  3280. local accessID = ChatHistory_GetAccessID(chatGroup, chatTarget);
  3281. local typeID = ChatHistory_GetAccessID(infoType, chatTarget, arg12);
  3282. self:AddMessage(format(globalstring, arg4, playerLink), info.r, info.g, info.b, info.id, accessID, typeID);
  3283. else
  3284. self:AddMessage(format(globalstring, arg8, arg4, arg2), info.r, info.g, info.b, info.id);
  3285. end
  3286. if ( arg1 == "INVITE" and GetCVarBool("blockChannelInvites") ) then
  3287. self:AddMessage(CHAT_MSG_BLOCK_CHAT_CHANNEL_INVITE, info.r, info.g, info.b, info.id);
  3288. end
  3289. elseif (type == "CHANNEL_NOTICE") then
  3290. local accessID = ChatHistory_GetAccessID(Chat_GetChatCategory(type), arg8);
  3291. local typeID = ChatHistory_GetAccessID(infoType, arg8, arg12);
  3292. if arg1 == "YOU_CHANGED" and C_ChatInfo.GetChannelRuleset(arg8) == Enum.ChatChannelRuleset.Mentor then
  3293. ChatFrame_UpdateDefaultChatTarget(self);
  3294. ChatEdit_UpdateNewcomerEditBoxHint(self.editBox);
  3295. else
  3296. if arg1 == "YOU_LEFT" then
  3297. ChatEdit_UpdateNewcomerEditBoxHint(self.editBox, arg8);
  3298. end
  3299. local globalstring;
  3300. if ( arg1 == "TRIAL_RESTRICTED" ) then
  3301. globalstring = CHAT_TRIAL_RESTRICTED_NOTICE_TRIAL;
  3302. else
  3303. globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3304. if ( not globalstring ) then
  3305. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3306. if not globalstring then
  3307. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE"));
  3308. return;
  3309. end
  3310. end
  3311. end
  3312. self:AddMessage(format(globalstring, arg8, ChatFrame_ResolvePrefixedChannelName(arg4)), info.r, info.g, info.b, info.id, accessID, typeID);
  3313. end
  3314. elseif ( type == "BN_INLINE_TOAST_ALERT" ) then
  3315. local globalstring = _G["BN_INLINE_TOAST_"..arg1];
  3316. if not globalstring then
  3317. GMError(("Missing global string for %q"):format("BN_INLINE_TOAST_"..arg1));
  3318. return;
  3319. end
  3320. local message;
  3321. if ( arg1 == "FRIEND_REQUEST" ) then
  3322. message = globalstring;
  3323. elseif ( arg1 == "FRIEND_PENDING" ) then
  3324. message = format(BN_INLINE_TOAST_FRIEND_PENDING, BNGetNumFriendInvites());
  3325. elseif ( arg1 == "FRIEND_REMOVED" or arg1 == "BATTLETAG_FRIEND_REMOVED" ) then
  3326. message = format(globalstring, arg2);
  3327. elseif ( arg1 == "FRIEND_ONLINE" or arg1 == "FRIEND_OFFLINE") then
  3328. local accountInfo = C_BattleNet.GetAccountInfoByID(arg13);
  3329. if accountInfo and accountInfo.gameAccountInfo.clientProgram ~= "" then
  3330. local characterName = BNet_GetValidatedCharacterNameWithClientEmbeddedTexture(accountInfo.gameAccountInfo.characterName, accountInfo.battleTag, accountInfo.gameAccountInfo.clientProgram, 14);
  3331. local linkDisplayText = ("[%s] (%s)"):format(arg2, characterName);
  3332. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3333. message = format(globalstring, playerLink);
  3334. else
  3335. local linkDisplayText = ("[%s]"):format(arg2);
  3336. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3337. message = format(globalstring, playerLink);
  3338. end
  3339. else
  3340. local linkDisplayText = ("[%s]"):format(arg2);
  3341. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3342. message = format(globalstring, playerLink);
  3343. end
  3344. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3345. elseif ( type == "BN_INLINE_TOAST_BROADCAST" ) then
  3346. if ( arg1 ~= "" ) then
  3347. arg1 = RemoveNewlines(RemoveExtraSpaces(arg1));
  3348. local linkDisplayText = ("[%s]"):format(arg2);
  3349. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3350. self:AddMessage(format(BN_INLINE_TOAST_BROADCAST, playerLink, arg1), info.r, info.g, info.b, info.id);
  3351. end
  3352. elseif ( type == "BN_INLINE_TOAST_BROADCAST_INFORM" ) then
  3353. if ( arg1 ~= "" ) then
  3354. arg1 = RemoveExtraSpaces(arg1);
  3355. self:AddMessage(BN_INLINE_TOAST_BROADCAST_INFORM, info.r, info.g, info.b, info.id);
  3356. end
  3357. else
  3358. local body;
  3359. local _, fontHeight = FCF_GetChatWindowInfo(self:GetID());
  3360. if ( fontHeight == 0 ) then
  3361. --fontHeight will be 0 if it's still at the default (14)
  3362. fontHeight = 14;
  3363. end
  3364. -- Add AFK/DND flags
  3365. local pflag = GetPFlag(...);
  3366. if ( type == "WHISPER_INFORM" and GMChatFrame_IsGM and GMChatFrame_IsGM(arg2) ) then
  3367. return;
  3368. end
  3369. local showLink = 1;
  3370. if ( strsub(type, 1, 7) == "MONSTER" or strsub(type, 1, 9) == "RAID_BOSS") then
  3371. showLink = nil;
  3372. else
  3373. arg1 = gsub(arg1, "%%", "%%%%");
  3374. end
  3375. -- Search for icon links and replace them with texture links.
  3376. arg1 = C_ChatInfo.ReplaceIconAndGroupExpressions(arg1, arg17, not ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)); -- If arg17 is true, don't convert to raid icons
  3377. --Remove groups of many spaces
  3378. arg1 = RemoveExtraSpaces(arg1);
  3379. local playerLink;
  3380. local playerLinkDisplayText = coloredName;
  3381. local relevantDefaultLanguage = self.defaultLanguage;
  3382. if ( (type == "SAY") or (type == "YELL") ) then
  3383. relevantDefaultLanguage = self.alternativeDefaultLanguage;
  3384. end
  3385. local usingDifferentLanguage = (arg3 ~= "") and (arg3 ~= relevantDefaultLanguage);
  3386. local usingEmote = (type == "EMOTE") or (type == "TEXT_EMOTE");
  3387. if ( usingDifferentLanguage or not usingEmote ) then
  3388. playerLinkDisplayText = ("[%s]"):format(coloredName);
  3389. end
  3390. local isCommunityType = type == "COMMUNITIES_CHANNEL";
  3391. local playerName, lineID, bnetIDAccount = arg2, arg11, arg13;
  3392. if ( isCommunityType ) then
  3393. local isBattleNetCommunity = bnetIDAccount ~= nil and bnetIDAccount ~= 0;
  3394. local messageInfo, clubId, streamId, clubType = C_Club.GetInfoFromLastCommunityChatLine();
  3395. if (messageInfo ~= nil) then
  3396. if ( isBattleNetCommunity ) then
  3397. playerLink = GetBNPlayerCommunityLink(playerName, playerLinkDisplayText, bnetIDAccount, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3398. else
  3399. playerLink = GetPlayerCommunityLink(playerName, playerLinkDisplayText, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3400. end
  3401. else
  3402. playerLink = playerLinkDisplayText;
  3403. end
  3404. else
  3405. if ( type == "BN_WHISPER" or type == "BN_WHISPER_INFORM" ) then
  3406. playerLink = GetBNPlayerLink(playerName, playerLinkDisplayText, bnetIDAccount, lineID, chatGroup, chatTarget);
  3407. else
  3408. playerLink = GetPlayerLink(playerName, playerLinkDisplayText, lineID, chatGroup, chatTarget);
  3409. end
  3410. end
  3411. local message = arg1;
  3412. if ( arg14 ) then --isMobile
  3413. message = ChatFrame_GetMobileEmbeddedTexture(info.r, info.g, info.b)..message;
  3414. end
  3415. if ( usingDifferentLanguage ) then
  3416. local languageHeader = "["..arg3.."] ";
  3417. if ( showLink and (arg2 ~= "") ) then
  3418. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..playerLink);
  3419. else
  3420. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..arg2);
  3421. end
  3422. else
  3423. if ( not showLink or arg2 == "" ) then
  3424. if ( type == "TEXT_EMOTE" ) then
  3425. body = message;
  3426. else
  3427. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..arg2, arg2);
  3428. end
  3429. else
  3430. if ( type == "EMOTE" ) then
  3431. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3432. elseif ( type == "TEXT_EMOTE") then
  3433. body = string.gsub(message, arg2, pflag..playerLink, 1);
  3434. elseif (type == "GUILD_ITEM_LOOTED") then
  3435. body = string.gsub(message, "$s", GetPlayerLink(arg2, playerLinkDisplayText));
  3436. else
  3437. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3438. end
  3439. end
  3440. end
  3441. -- Add Channel
  3442. if (channelLength > 0) then
  3443. body = "|Hchannel:channel:"..arg8.."|h["..ChatFrame_ResolvePrefixedChannelName(arg4).."]|h "..body;
  3444. end
  3445. --Add Timestamps
  3446. if ( CHAT_TIMESTAMP_FORMAT ) then
  3447. body = BetterDate(CHAT_TIMESTAMP_FORMAT, time())..body;
  3448. end
  3449. local accessID = ChatHistory_GetAccessID(chatGroup, chatTarget);
  3450. local typeID = ChatHistory_GetAccessID(infoType, chatTarget, arg12 or arg13);
  3451. self:AddMessage(body, info.r, info.g, info.b, info.id, accessID, typeID);
  3452. end
  3453. if ( type == "WHISPER" or type == "BN_WHISPER" ) then
  3454. --BN_WHISPER FIXME
  3455. ChatEdit_SetLastTellTarget(arg2, type);
  3456. if ( not self.tellTimer or (GetTime() > self.tellTimer) ) then
  3457. PlaySound(SOUNDKIT.TELL_MESSAGE);
  3458. end
  3459. self.tellTimer = GetTime() + CHAT_TELL_ALERT_TIME;
  3460. --FCF_FlashTab(self);
  3461. FlashClientIcon();
  3462. end
  3463. if ( not self:IsShown() ) then
  3464. if ( (self == DEFAULT_CHAT_FRAME and info.flashTabOnGeneral) or (self ~= DEFAULT_CHAT_FRAME and info.flashTab) ) then
  3465. if ( not CHAT_OPTIONS.HIDE_FRAME_ALERTS or type == "WHISPER" or type == "BN_WHISPER" ) then --BN_WHISPER FIXME
  3466. if (not FCFManager_ShouldSuppressMessageFlash(self, chatGroup, chatTarget) ) then
  3467. FCF_StartAlertFlash(self);
  3468. end
  3469. end
  3470. end
  3471. end
  3472. return true;
  3473. end
  3474. end
  3475. function ChatFrame_AddMessageEventFilter (event, filter)
  3476. assert(event and filter);
  3477. if ( chatFilters[event] ) then
  3478. -- Only allow a filter to be added once
  3479. for index, filterFunc in next, chatFilters[event] do
  3480. if ( filterFunc == filter ) then
  3481. return;
  3482. end
  3483. end
  3484. else
  3485. chatFilters[event] = {};
  3486. end
  3487. tinsert(chatFilters[event], filter);
  3488. end
  3489. function ChatFrame_RemoveMessageEventFilter (event, filter)
  3490. assert(event and filter);
  3491. if ( chatFilters[event] ) then
  3492. for index, filterFunc in next, chatFilters[event] do
  3493. if ( filterFunc == filter ) then
  3494. tremove(chatFilters[event], index);
  3495. end
  3496. end
  3497. if ( #chatFilters[event] == 0 ) then
  3498. chatFilters[event] = nil;
  3499. end
  3500. end
  3501. end
  3502. function ChatFrame_GetMessageEventFilters (event)
  3503. assert(event);
  3504. return chatFilters[event];
  3505. end
  3506. function ChatFrame_OnUpdate(self, elapsedSec)
  3507. local flash = self.ScrollToBottomButton.Flash;
  3508. if flash then
  3509. local shouldFlash = not self:AtBottom();
  3510. if shouldFlash ~= UIFrameIsFlashing(flash) then
  3511. if shouldFlash then
  3512. UIFrameFlash(flash, .1, .1, -1, false, CHAT_BUTTON_FLASH_TIME, CHAT_BUTTON_FLASH_TIME);
  3513. FCF_FadeInScrollbar(self);
  3514. else
  3515. UIFrameFlashStop(flash);
  3516. end
  3517. end
  3518. end
  3519. end
  3520. function ChatFrame_OnHyperlinkShow(self, link, text, button)
  3521. SetItemRef(link, text, button, self);
  3522. end
  3523. function ChatFrame_OnMouseWheel(value)
  3524. if ( value > 0 ) then
  3525. SELECTED_DOCK_FRAME:ScrollUp();
  3526. elseif ( value < 0 ) then
  3527. SELECTED_DOCK_FRAME:ScrollDown();
  3528. end
  3529. end
  3530. function ChatFrame_SetChatFocusOverride(editBoxOverride)
  3531. CHAT_FOCUS_OVERRIDE = editBoxOverride;
  3532. end
  3533. function ChatFrame_GetChatFocusOverride()
  3534. return CHAT_FOCUS_OVERRIDE;
  3535. end
  3536. function ChatFrame_ClearChatFocusOverride()
  3537. CHAT_FOCUS_OVERRIDE = nil;
  3538. end
  3539. function ChatFrame_OpenChat(text, chatFrame, desiredCursorPosition)
  3540. if chatFrame == nil and CHAT_FOCUS_OVERRIDE ~= nil then
  3541. if CHAT_FOCUS_OVERRIDE.supportsSlashCommands or not text or strsub(text, 0, 1) ~= "/" then
  3542. CHAT_FOCUS_OVERRIDE:SetFocus();
  3543. if text then
  3544. CHAT_FOCUS_OVERRIDE:SetText(text);
  3545. end
  3546. return;
  3547. end
  3548. end
  3549. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3550. ChatEdit_ActivateChat(editBox);
  3551. editBox.desiredCursorPosition = desiredCursorPosition;
  3552. if text then
  3553. editBox.text = text;
  3554. editBox.setText = 1;
  3555. end
  3556. if ( editBox:GetAttribute("chatType") == editBox:GetAttribute("stickyType") ) then
  3557. if ( (editBox:GetAttribute("stickyType") == "PARTY") and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) or
  3558. (editBox:GetAttribute("stickyType") == "RAID") and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) or
  3559. (editBox:GetAttribute("stickyType") == "INSTANCE_CHAT") and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE))) then
  3560. editBox:SetAttribute("chatType", "SAY");
  3561. end
  3562. end
  3563. ChatEdit_UpdateHeader(editBox);
  3564. return editBox;
  3565. end
  3566. function ChatFrame_ScrollToBottom()
  3567. SELECTED_DOCK_FRAME:ScrollToBottom();
  3568. end
  3569. function ChatFrame_ScrollUp()
  3570. SELECTED_DOCK_FRAME:ScrollUp();
  3571. end
  3572. function ChatFrame_ScrollDown()
  3573. SELECTED_DOCK_FRAME:ScrollDown();
  3574. end
  3575. --used for chatframe and combat log
  3576. function MessageFrameScrollButton_OnLoad(self)
  3577. self.clickDelay = MESSAGE_SCROLLBUTTON_INITIAL_DELAY;
  3578. self:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonUp", "RightButtonDown");
  3579. end
  3580. --Controls scrolling for chatframe and combat log
  3581. function MessageFrameScrollButton_OnUpdate(self, elapsed)
  3582. if (self:GetButtonState() == "PUSHED") then
  3583. self.clickDelay = self.clickDelay - elapsed;
  3584. if ( self.clickDelay < 0 ) then
  3585. local name = self:GetName();
  3586. if ( name == self:GetParent():GetName().."DownButton" ) then
  3587. self:GetParent():GetParent():ScrollDown();
  3588. elseif ( name == self:GetParent():GetName().."UpButton" ) then
  3589. self:GetParent():GetParent():ScrollUp();
  3590. end
  3591. self.clickDelay = MESSAGE_SCROLLBUTTON_SCROLL_DELAY;
  3592. end
  3593. end
  3594. end
  3595. function ChatFrame_ToggleMenu()
  3596. ChatMenu:SetShown(not ChatMenu:IsShown());
  3597. end
  3598. function ChatFrameMenu_UpdateAnchorPoint()
  3599. --Update the menu anchor point
  3600. if ( FCF_GetButtonSide(DEFAULT_CHAT_FRAME) == "right" ) then
  3601. ChatMenu:ClearAllPoints();
  3602. ChatMenu:SetPoint("BOTTOMRIGHT", ChatFrameMenuButton, "TOPLEFT");
  3603. else
  3604. ChatMenu:ClearAllPoints();
  3605. ChatMenu:SetPoint("BOTTOMLEFT", ChatFrameMenuButton, "TOPRIGHT");
  3606. end
  3607. end
  3608. function ChatFrame_SendTell(name, chatFrame)
  3609. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3610. --DEBUG FIXME - for now, we're not going to remove spaces from names. We need to make sure X-server still works.
  3611. -- Remove spaces from the server name for slash command parsing
  3612. --name = gsub(name, " ", "");
  3613. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3614. ChatFrame_OpenChat(SLASH_WHISPER1.." "..name.." ", chatFrame);
  3615. else
  3616. editBox:SetText(SLASH_WHISPER1.." "..name.." ");
  3617. end
  3618. ChatEdit_ParseText(editBox, 0);
  3619. end
  3620. function ChatFrame_SendBNetTell(tokenizedName)
  3621. local editBox = ChatEdit_ChooseBoxForSend();
  3622. editBox:SetAttribute("tellTarget", tokenizedName);
  3623. editBox:SetAttribute("chatType", "BN_WHISPER");
  3624. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3625. ChatFrame_OpenChat("");
  3626. else
  3627. ChatEdit_UpdateHeader(editBox);
  3628. end
  3629. end
  3630. function ChatFrame_ReplyTell(chatFrame)
  3631. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3632. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  3633. if ( lastTell ) then
  3634. --BN_WHISPER FIXME
  3635. editBox:SetAttribute("chatType", lastTellType);
  3636. editBox:SetAttribute("tellTarget", lastTell);
  3637. ChatEdit_UpdateHeader(editBox);
  3638. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3639. ChatFrame_OpenChat("", chatFrame);
  3640. end
  3641. else
  3642. -- Error message
  3643. end
  3644. end
  3645. function ChatFrame_ReplyTell2(chatFrame)
  3646. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3647. local lastTold, lastToldType = ChatEdit_GetLastToldTarget();
  3648. if ( lastTold ) then
  3649. --BN_WHISPER FIXME
  3650. editBox:SetAttribute("chatType", lastToldType);
  3651. editBox:SetAttribute("tellTarget", lastTold);
  3652. ChatEdit_UpdateHeader(editBox);
  3653. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3654. ChatFrame_OpenChat("", chatFrame);
  3655. end
  3656. else
  3657. -- Error message
  3658. end
  3659. end
  3660. function ChatFrame_DisplayHelpTextSimple(frame)
  3661. if ( not frame ) then
  3662. return;
  3663. end
  3664. local info = ChatTypeInfo["SYSTEM"];
  3665. frame:AddMessage(HELP_TEXT_SIMPLE, info.r, info.g, info.b, info.id);
  3666. end
  3667. function ChatFrame_DisplayHelpText(frame)
  3668. if ( not frame ) then
  3669. return;
  3670. end
  3671. local info = ChatTypeInfo["SYSTEM"];
  3672. local i = 1;
  3673. local text = _G["HELP_TEXT_LINE"..i];
  3674. while text do
  3675. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3676. i = i + 1;
  3677. text = _G["HELP_TEXT_LINE"..i];
  3678. end
  3679. end
  3680. function ChatFrame_DisplayMacroHelpText(frame)
  3681. if ( not frame ) then
  3682. return;
  3683. end
  3684. local info = ChatTypeInfo["SYSTEM"];
  3685. local i = 1;
  3686. local text = _G["MACRO_HELP_TEXT_LINE"..i];
  3687. while text do
  3688. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3689. i = i + 1;
  3690. text = _G["MACRO_HELP_TEXT_LINE"..i];
  3691. end
  3692. end
  3693. function ChatFrame_DisplayChatHelp(frame)
  3694. if ( not frame ) then
  3695. return;
  3696. end
  3697. local info = ChatTypeInfo["SYSTEM"];
  3698. local i = 1;
  3699. local text = _G["CHAT_HELP_TEXT_LINE"..i];
  3700. while text do
  3701. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3702. i = i + 1;
  3703. -- hack fix for removing a line without causing localization problems
  3704. if ( i == 15 ) then
  3705. i = i + 1;
  3706. end
  3707. text = _G["CHAT_HELP_TEXT_LINE"..i];
  3708. end
  3709. end
  3710. function ChatFrame_DisplayGuildHelp(frame)
  3711. if ( not frame ) then
  3712. return;
  3713. end
  3714. local info = ChatTypeInfo["SYSTEM"];
  3715. local i = 1;
  3716. local text = _G["GUILD_HELP_TEXT_LINE"..i];
  3717. while text do
  3718. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3719. i = i + 1;
  3720. text = _G["GUILD_HELP_TEXT_LINE"..i];
  3721. end
  3722. end
  3723. function ChatFrame_DisplayGameTime(frame)
  3724. if ( not frame ) then
  3725. return;
  3726. end
  3727. local info = ChatTypeInfo["SYSTEM"];
  3728. frame:AddMessage(GameTime_GetGameTime(true), info.r, info.g, info.b, info.id);
  3729. end
  3730. function ChatFrame_TimeBreakDown(time)
  3731. local days = floor(time / (60 * 60 * 24));
  3732. local hours = floor((time - (days * (60 * 60 * 24))) / (60 * 60));
  3733. local minutes = floor((time - (days * (60 * 60 * 24)) - (hours * (60 * 60))) / 60);
  3734. local seconds = mod(time, 60);
  3735. return days, hours, minutes, seconds;
  3736. end
  3737. function ChatFrame_DisplayTimePlayed(self, totalTime, levelTime)
  3738. local info = ChatTypeInfo["SYSTEM"];
  3739. local d;
  3740. local h;
  3741. local m;
  3742. local s;
  3743. d, h, m, s = ChatFrame_TimeBreakDown(totalTime);
  3744. local string = format(TIME_PLAYED_TOTAL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3745. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3746. d, h, m, s = ChatFrame_TimeBreakDown(levelTime);
  3747. local string = format(TIME_PLAYED_LEVEL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3748. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3749. end
  3750. function ChatFrame_ChatPageUp()
  3751. SELECTED_CHAT_FRAME:PageUp();
  3752. end
  3753. function ChatFrame_ChatPageDown()
  3754. SELECTED_CHAT_FRAME:PageDown();
  3755. end
  3756. function ChatFrame_DisplayUsageError(messageTag)
  3757. ChatFrame_DisplaySystemMessageInPrimary(messageTag);
  3758. end
  3759. function ChatFrame_DisplaySystemMessageInPrimary(messageTag)
  3760. local info = ChatTypeInfo["SYSTEM"];
  3761. DEFAULT_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3762. end
  3763. function ChatFrame_DisplaySystemMessageInCurrent(messageTag)
  3764. local info = ChatTypeInfo["SYSTEM"];
  3765. SELECTED_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3766. end
  3767. -- ChatEdit functions
  3768. local ChatEdit_LastTell = {};
  3769. local ChatEdit_LastTellType = {};
  3770. for i = 1, NUM_REMEMBERED_TELLS, 1 do
  3771. ChatEdit_LastTell[i] = "";
  3772. ChatEdit_LastTellType[i] = "";
  3773. end
  3774. local ChatEdit_LastTold;
  3775. local ChatEdit_LastToldType;
  3776. function ChatEdit_OnLoad(self)
  3777. self:SetFrameLevel(self.chatFrame:GetFrameLevel()+1);
  3778. self:SetAttribute("chatType", "SAY");
  3779. self:SetAttribute("stickyType", "SAY");
  3780. self.chatLanguage = GetDefaultLanguage();
  3781. self:RegisterEvent("UPDATE_CHAT_COLOR");
  3782. self.addSpaceToAutoComplete = true;
  3783. self.addHighlightedText = true;
  3784. if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "many" ) then
  3785. self:Show();
  3786. end
  3787. local function ChatEditAutoComplete(editBox, fullText, nameInfo, ambiguatedName)
  3788. if hash_ChatTypeInfoList[string.upper(editBox.command)] == "SMART_WHISPER" then
  3789. if nameInfo.bnetID ~= nil and nameInfo.bnetID ~= 0 then
  3790. editBox:SetAttribute("tellTarget", nameInfo.name);
  3791. editBox:SetAttribute("chatType", "BN_WHISPER");
  3792. else
  3793. editBox:SetAttribute("tellTarget", ambiguatedName);
  3794. editBox:SetAttribute("chatType", "WHISPER");
  3795. end
  3796. editBox:SetText("");
  3797. ChatEdit_UpdateHeader(editBox);
  3798. return true;
  3799. end
  3800. return false;
  3801. end
  3802. AutoCompleteEditBox_SetCustomAutoCompleteFunction(self, ChatEditAutoComplete);
  3803. self:SetParent(UIParent);
  3804. end
  3805. function ChatEdit_OnEvent(self, event, ...)
  3806. if ( event == "UPDATE_CHAT_COLOR" ) then
  3807. local chatType = ...;
  3808. if ( self:IsShown() ) then
  3809. ChatEdit_UpdateHeader(self);
  3810. end
  3811. end
  3812. end
  3813. function ChatEdit_OnUpdate(self, elapsedSec)
  3814. if ( self.setText == 1) then
  3815. self:SetText(self.text);
  3816. self.setText = 0;
  3817. ChatEdit_ParseText(self, 0, true);
  3818. if self.desiredCursorPosition then
  3819. self:SetCursorPosition(self.desiredCursorPosition);
  3820. self.desiredCursorPosition = nil;
  3821. end
  3822. end
  3823. end
  3824. function ChatEdit_OnShow(self)
  3825. ChatEdit_ResetChatType(self);
  3826. end
  3827. function ChatEdit_ResetChatType(self)
  3828. if ( self:GetAttribute("chatType") == "PARTY" and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) ) then
  3829. self:SetAttribute("chatType", "SAY");
  3830. end
  3831. if ( self:GetAttribute("chatType") == "RAID" and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) ) then
  3832. self:SetAttribute("chatType", "SAY");
  3833. end
  3834. if ( (self:GetAttribute("chatType") == "GUILD" or self:GetAttribute("chatType") == "OFFICER") and not IsInGuild() ) then
  3835. self:SetAttribute("chatType", "SAY");
  3836. end
  3837. if ( self:GetAttribute("chatType") == "INSTANCE_CHAT" and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3838. self:SetAttribute("chatType", "SAY");
  3839. end
  3840. self.lastTabComplete = nil;
  3841. self.tabCompleteText = nil;
  3842. self.tabCompleteTableIndex = 1;
  3843. ChatEdit_UpdateHeader(self);
  3844. ChatEdit_OnInputLanguageChanged(self);
  3845. --[[if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "old") then
  3846. self:SetFocus();
  3847. end]]
  3848. end
  3849. function ChatEdit_OnHide(self)
  3850. if ( ACTIVE_CHAT_EDIT_BOX == self ) then
  3851. ChatEdit_DeactivateChat(self);
  3852. end
  3853. if ( LAST_ACTIVE_CHAT_EDIT_BOX == self and self:IsShown() ) then --Our parent was hidden. Let's find a new default frame.
  3854. --We'll go with the active dock frame since people think of that as the primary chat.
  3855. ChatEdit_SetLastActiveWindow(FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox);
  3856. end
  3857. end
  3858. function ChatEdit_OnEditFocusGained(self)
  3859. ChatEdit_ActivateChat(self);
  3860. end
  3861. function ChatEdit_OnEditFocusLost(self)
  3862. AutoCompleteEditBox_OnEditFocusLost(self);
  3863. if self:GetText() == "" then
  3864. ChatEdit_DeactivateChat(self);
  3865. end
  3866. end
  3867. function ChatEdit_ActivateChat(editBox)
  3868. ChatFrame_ClearChatFocusOverride();
  3869. if ( ACTIVE_CHAT_EDIT_BOX and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3870. ChatEdit_DeactivateChat(ACTIVE_CHAT_EDIT_BOX);
  3871. end
  3872. ACTIVE_CHAT_EDIT_BOX = editBox;
  3873. ChatEdit_SetLastActiveWindow(editBox);
  3874. --Stop any sort of fading
  3875. UIFrameFadeRemoveFrame(editBox);
  3876. editBox:Show();
  3877. editBox:SetFocus();
  3878. editBox:SetFrameStrata("DIALOG");
  3879. editBox:Raise();
  3880. editBox.header:Show();
  3881. ChatEdit_UpdateNewcomerEditBoxHint(editBox);
  3882. editBox.focusLeft:Show();
  3883. editBox.focusRight:Show();
  3884. editBox.focusMid:Show();
  3885. editBox:SetAlpha(1.0);
  3886. ChatEdit_UpdateHeader(editBox);
  3887. if ( CHAT_SHOW_IME ) then
  3888. _G[editBox:GetName().."Language"]:Show();
  3889. end
  3890. end
  3891. local function ChatEdit_SetDeactivated(editBox)
  3892. editBox:SetFrameStrata("LOW");
  3893. if ( GetCVar("chatStyle") == "classic" and not editBox.isGM ) then
  3894. editBox:Hide();
  3895. else
  3896. editBox:SetText("");
  3897. editBox.header:Hide();
  3898. if ( not editBox.isGM ) then
  3899. editBox:SetAlpha(0.35);
  3900. end
  3901. ChatEdit_UpdateNewcomerEditBoxHint(editBox);
  3902. editBox:ClearFocus();
  3903. editBox.focusLeft:Hide();
  3904. editBox.focusRight:Hide();
  3905. editBox.focusMid:Hide();
  3906. ChatEdit_ResetChatTypeToSticky(editBox);
  3907. ChatEdit_ResetChatType(editBox);
  3908. end
  3909. _G[editBox:GetName().."Language"]:Hide();
  3910. end
  3911. function ChatEdit_DeactivateChat(editBox)
  3912. if ( ACTIVE_CHAT_EDIT_BOX == editBox ) then
  3913. ACTIVE_CHAT_EDIT_BOX = nil;
  3914. end
  3915. ChatEdit_SetDeactivated(editBox);
  3916. end
  3917. function ChatEdit_ChooseBoxForSend(preferredChatFrame)
  3918. if ( GetCVar("chatStyle") == "classic" ) then
  3919. return DEFAULT_CHAT_FRAME.editBox;
  3920. elseif ( preferredChatFrame and preferredChatFrame:IsShown() ) then
  3921. return preferredChatFrame.editBox;
  3922. elseif ( ChatEdit_GetLastActiveWindow() and ChatEdit_GetLastActiveWindow():GetParent():IsShown() ) then
  3923. return ChatEdit_GetLastActiveWindow();
  3924. else
  3925. return FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox;
  3926. end
  3927. end
  3928. function ChatEdit_SetLastActiveWindow(editBox)
  3929. local previousValue = LAST_ACTIVE_CHAT_EDIT_BOX;
  3930. if ( LAST_ACTIVE_CHAT_EDIT_BOX and not LAST_ACTIVE_CHAT_EDIT_BOX.isGM and LAST_ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3931. if ( GetCVar("chatStyle") == "im" ) then
  3932. LAST_ACTIVE_CHAT_EDIT_BOX:Hide();
  3933. end
  3934. end
  3935. LAST_ACTIVE_CHAT_EDIT_BOX = editBox;
  3936. if ( editBox and GetCVar("chatStyle") == "im" and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3937. editBox:Show();
  3938. ChatEdit_SetDeactivated(editBox);
  3939. end
  3940. if ( previousValue ) then
  3941. FCFClickAnywhereButton_UpdateState(previousValue.chatFrame.clickAnywhereButton);
  3942. end
  3943. if ( editBox ) then
  3944. FCFClickAnywhereButton_UpdateState(editBox.chatFrame.clickAnywhereButton);
  3945. end
  3946. end
  3947. function ChatEdit_GetActiveWindow()
  3948. return ACTIVE_CHAT_EDIT_BOX;
  3949. end
  3950. function ChatEdit_GetLastActiveWindow()
  3951. return LAST_ACTIVE_CHAT_EDIT_BOX;
  3952. end
  3953. function ChatEdit_FocusActiveWindow()
  3954. local active = ChatEdit_GetActiveWindow()
  3955. if ( active ) then
  3956. ChatEdit_ActivateChat(active);
  3957. end
  3958. end
  3959. function ChatEdit_LinkItem(itemID, itemLink)
  3960. if ( not itemLink ) then
  3961. itemLink = select(2, GetItemInfo(itemID));
  3962. end
  3963. if ( itemLink ) then
  3964. if ( ChatEdit_GetActiveWindow() ) then
  3965. ChatEdit_InsertLink(itemLink);
  3966. else
  3967. ChatFrame_OpenChat(itemLink);
  3968. end
  3969. end
  3970. end
  3971. function ChatEdit_InsertLink(text)
  3972. if ( not text ) then
  3973. return false;
  3974. end
  3975. if ( MacroFrameText and MacroFrameText:HasFocus() ) then
  3976. local item;
  3977. if ( strfind(text, "item:", 1, true) ) then
  3978. item = GetItemInfo(text);
  3979. end
  3980. local cursorPosition = MacroFrameText:GetCursorPosition();
  3981. if (cursorPosition == 0 or strsub(MacroFrameText:GetText(), cursorPosition, cursorPosition) == "\n" ) then
  3982. if ( item ) then
  3983. if ( GetItemSpell(text) ) then
  3984. MacroFrameText:Insert(SLASH_USE1.." "..item.."\n");
  3985. else
  3986. MacroFrameText:Insert(SLASH_EQUIP1.." "..item.."\n");
  3987. end
  3988. else
  3989. MacroFrameText:Insert(SLASH_CAST1.." "..text.."\n");
  3990. end
  3991. else
  3992. MacroFrameText:Insert(item or text);
  3993. end
  3994. return true;
  3995. end
  3996. if ( TradeSkillFrame and TradeSkillFrame.SearchBox:HasFocus() ) then
  3997. local item;
  3998. if ( strfind(text, "item:", 1, true) ) then
  3999. item = GetItemInfo(text);
  4000. end
  4001. if ( item ) then
  4002. TradeSkillFrame.SearchBox:SetText(item);
  4003. return true;
  4004. end
  4005. end
  4006. if ( CommunitiesFrame and CommunitiesFrame.ChatEditBox:HasFocus() ) then
  4007. CommunitiesFrame.ChatEditBox:Insert(text);
  4008. return true;
  4009. end
  4010. local activeWindow = ChatEdit_GetActiveWindow();
  4011. if ( activeWindow ) then
  4012. activeWindow:Insert(text);
  4013. activeWindow:SetFocus();
  4014. return true;
  4015. end
  4016. if ( AuctionHouseFrame and AuctionHouseFrame:IsVisible() ) then
  4017. local item;
  4018. if ( strfind(text, "battlepet:") ) then
  4019. local petName = strmatch(text, "%[(.+)%]");
  4020. item = petName;
  4021. elseif ( strfind(text, "item:", 1, true) ) then
  4022. item = GetItemInfo(text);
  4023. end
  4024. if ( item ) then
  4025. if ( AuctionHouseFrame:SetSearchText(item) ) then
  4026. return true;
  4027. end
  4028. end
  4029. end
  4030. return false;
  4031. end
  4032. function ChatEdit_TryInsertChatLink(link)
  4033. if ( IsModifiedClick("CHATLINK") and link ) then
  4034. return ChatEdit_InsertLink(link);
  4035. end
  4036. end
  4037. function ChatEdit_TryInsertQuestLinkForQuestID(questID)
  4038. return ChatEdit_TryInsertChatLink(GetQuestLink(questID));
  4039. end
  4040. function ChatEdit_GetChannelTarget(editBox)
  4041. local channelTarget = editBox:GetAttribute("channelTarget"); -- may be a name or an index
  4042. if channelTarget == nil then
  4043. return 0;
  4044. end
  4045. local localID = GetChannelName(channelTarget);
  4046. return localID;
  4047. end
  4048. function ChatEdit_GetLastTellTarget()
  4049. for i=1, #ChatEdit_LastTell do
  4050. local value = ChatEdit_LastTell[i];
  4051. if ( value ~= "" ) then
  4052. return value, ChatEdit_LastTellType[i];
  4053. end
  4054. end
  4055. return nil;
  4056. end
  4057. function ChatEdit_SetLastTellTarget(target, chatType)
  4058. local found = #ChatEdit_LastTell;
  4059. for i=1, #ChatEdit_LastTell do
  4060. local tellTarget, tellChatType = ChatEdit_LastTell[i], ChatEdit_LastTellType[i];
  4061. if ( strupper(target) == strupper(tellTarget) and strupper(chatType) == strupper(tellChatType) ) then
  4062. found = i;
  4063. break;
  4064. end
  4065. end
  4066. for i = found, 2, -1 do
  4067. ChatEdit_LastTell[i] = ChatEdit_LastTell[i-1];
  4068. ChatEdit_LastTellType[i] = ChatEdit_LastTellType[i-1];
  4069. end
  4070. ChatEdit_LastTell[1] = target;
  4071. ChatEdit_LastTellType[1] = chatType;
  4072. end
  4073. function ChatEdit_GetNextTellTarget(target, chatType)
  4074. if ( not target or target == "" ) then
  4075. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  4076. end
  4077. for i = 1, #ChatEdit_LastTell - 1, 1 do
  4078. if ( ChatEdit_LastTell[i] == "" ) then
  4079. break;
  4080. elseif ( strupper(target) == strupper(ChatEdit_LastTell[i]) and
  4081. strupper(chatType) == strupper(ChatEdit_LastTellType[i]) ) then
  4082. if ( ChatEdit_LastTell[i+1] ~= "" ) then
  4083. return ChatEdit_LastTell[i+1], ChatEdit_LastTellType[i+1];
  4084. else
  4085. break;
  4086. end
  4087. end
  4088. end
  4089. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  4090. end
  4091. function ChatEdit_GetLastToldTarget()
  4092. return ChatEdit_LastTold, ChatEdit_LastToldType;
  4093. end
  4094. function ChatEdit_SetLastToldTarget(name, chatType)
  4095. ChatEdit_LastTold = name;
  4096. ChatEdit_LastToldType = chatType;
  4097. end
  4098. function ChatEdit_UpdateHeader(editBox)
  4099. local type = editBox:GetAttribute("chatType");
  4100. if ( not type ) then
  4101. return;
  4102. end
  4103. local info = ChatTypeInfo[type];
  4104. local header = _G[editBox:GetName().."Header"];
  4105. local headerSuffix = _G[editBox:GetName().."HeaderSuffix"];
  4106. if ( not header ) then
  4107. return;
  4108. end
  4109. header:SetWidth(0);
  4110. --BN_WHISPER FIXME
  4111. if ( type == "SMART_WHISPER" ) then
  4112. --If we have a bnetIDAccount or this name, it's a BN whisper.
  4113. if ( BNet_GetBNetIDAccount(editBox:GetAttribute("tellTarget")) ) then
  4114. editBox:SetAttribute("chatType", "BN_WHISPER");
  4115. else
  4116. editBox:SetAttribute("chatType", "WHISPER");
  4117. end
  4118. ChatEdit_UpdateHeader(editBox);
  4119. return;
  4120. elseif ( type == "WHISPER" ) then
  4121. header:SetFormattedText(CHAT_WHISPER_SEND, editBox:GetAttribute("tellTarget"));
  4122. elseif ( type == "BN_WHISPER" ) then
  4123. local name = editBox:GetAttribute("tellTarget");
  4124. header:SetFormattedText(CHAT_BN_WHISPER_SEND, name);
  4125. elseif ( type == "EMOTE" ) then
  4126. header:SetFormattedText(CHAT_EMOTE_SEND, UnitName("player"));
  4127. elseif ( type == "CHANNEL" ) then
  4128. local localID, channelName, instanceID, isCommunitiesChannel = GetChannelName(ChatEdit_GetChannelTarget(editBox));
  4129. if ( channelName ) then
  4130. if ( isCommunitiesChannel ) then
  4131. channelName = ChatFrame_ResolveChannelName(channelName);
  4132. elseif ( instanceID > 0 ) then
  4133. channelName = channelName.." "..instanceID;
  4134. end
  4135. info = ChatTypeInfo["CHANNEL"..localID];
  4136. editBox:SetAttribute("channelTarget", localID);
  4137. header:SetFormattedText(CHAT_CHANNEL_SEND, localID, channelName);
  4138. end
  4139. elseif ( (type == "PARTY") and
  4140. (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  4141. --Smartly switch to instance chat
  4142. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  4143. ChatEdit_UpdateHeader(editBox);
  4144. return;
  4145. elseif ( (type == "RAID") and
  4146. (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) ) then
  4147. --Smartly switch to instance chat
  4148. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  4149. ChatEdit_UpdateHeader(editBox);
  4150. return;
  4151. elseif ( (type == "INSTANCE_CHAT") and
  4152. (IsInGroup(LE_PARTY_CATEGORY_HOME) and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) )then
  4153. if ( IsInRaid(LE_PARTY_CATEGORY_HOME) ) then
  4154. editBox:SetAttribute("chatType", "RAID");
  4155. else
  4156. editBox:SetAttribute("chatType", "PARTY");
  4157. end
  4158. ChatEdit_UpdateHeader(editBox);
  4159. return;
  4160. else
  4161. header:SetText(_G["CHAT_"..type.."_SEND"]);
  4162. end
  4163. local headerWidth = (header:GetRight() or 0) - (header:GetLeft() or 0);
  4164. local editBoxWidth = (editBox:GetRight() or 0) - (editBox:GetLeft() or 0);
  4165. if ( headerWidth > editBoxWidth / 2 ) then
  4166. header:SetWidth(editBoxWidth / 2);
  4167. headerSuffix:Show();
  4168. else
  4169. headerSuffix:Hide();
  4170. end
  4171. header:SetTextColor(info.r, info.g, info.b);
  4172. headerSuffix:SetTextColor(info.r, info.g, info.b);
  4173. editBox:SetTextInsets(15 + header:GetWidth() + (headerSuffix:IsShown() and headerSuffix:GetWidth() or 0), 13, 0, 0);
  4174. editBox:SetTextColor(info.r, info.g, info.b);
  4175. editBox.focusLeft:SetVertexColor(info.r, info.g, info.b);
  4176. editBox.focusRight:SetVertexColor(info.r, info.g, info.b);
  4177. editBox.focusMid:SetVertexColor(info.r, info.g, info.b);
  4178. end
  4179. function ChatEdit_DoesCurrentChannelTargetMatch(editBox, localID)
  4180. local type = editBox:GetAttribute("chatType");
  4181. if type == "CHANNEL" then
  4182. return ChatEdit_GetChannelTarget(editBox) == localID;
  4183. end
  4184. return false;
  4185. end
  4186. function ChatEdit_UpdateNewcomerEditBoxHint(editBox, excludeChannel)
  4187. local shouldBeShown = not editBox.isGM and not editBox.header:IsShown() and IsActivePlayerNewcomer();
  4188. if shouldBeShown then
  4189. local localID = GetFirstChannelIDOfChannelMatchingRuleset(Enum.ChatChannelRuleset.Mentor, excludeChannel);
  4190. editBox.NewcomerHint:SetShown(localID);
  4191. if localID then
  4192. editBox:SetAlpha(1.0);
  4193. if ChatEdit_DoesCurrentChannelTargetMatch(editBox, localID) then
  4194. editBox.NewcomerHint:SetText(NPEV2_CHAT_HELP_HINT_HERE);
  4195. else
  4196. editBox.NewcomerHint:SetFormattedText(NPEV2_CHAT_HELP_HINT_DIFFERENT, GetSlashCommandForChannelOpenChat(localID));
  4197. end
  4198. end
  4199. else
  4200. editBox.NewcomerHint:Hide();
  4201. end
  4202. end
  4203. function ChatEdit_CheckUpdateNewcomerEditBoxHint()
  4204. local editBox = ChatEdit_GetActiveWindow() or ChatEdit_GetLastActiveWindow();
  4205. if editBox then
  4206. -- No need for an exlcude channel, this should not be called when leaving a channel.
  4207. ChatEdit_UpdateNewcomerEditBoxHint(editBox);
  4208. end
  4209. end
  4210. function ChatEdit_AddHistory(editBox)
  4211. local text = "";
  4212. local type = editBox:GetAttribute("chatType");
  4213. local header = _G["SLASH_"..type.."1"];
  4214. if ( header ) then
  4215. text = header;
  4216. end
  4217. if ( type == "WHISPER" ) then
  4218. text = text.." "..editBox:GetAttribute("tellTarget");
  4219. elseif ( type == "CHANNEL" ) then
  4220. text = "/"..ChatEdit_GetChannelTarget(editBox);
  4221. end
  4222. local editBoxText = editBox:GetText();
  4223. if ( editBoxText ~= "" ) then
  4224. text = text.." "..editBox:GetText();
  4225. end
  4226. if ( text ~= "" ) then
  4227. editBox:AddHistoryLine(text);
  4228. end
  4229. end
  4230. function ChatEdit_SendText(editBox, addHistory)
  4231. ChatEdit_ParseText(editBox, 1);
  4232. local type = editBox:GetAttribute("chatType");
  4233. local text = editBox:GetText();
  4234. if ( strfind(text, "%s*[^%s]+") ) then
  4235. text = SubstituteChatMessageBeforeSend(text);
  4236. --BN_WHISPER FIXME
  4237. if ( type == "WHISPER") then
  4238. local target = editBox:GetAttribute("tellTarget");
  4239. ChatEdit_SetLastToldTarget(target, type);
  4240. SendChatMessage(text, type, editBox.languageID, target);
  4241. elseif ( type == "BN_WHISPER" ) then
  4242. local target = editBox:GetAttribute("tellTarget");
  4243. local bnetIDAccount = BNet_GetBNetIDAccount(target);
  4244. if ( bnetIDAccount ) then
  4245. ChatEdit_SetLastToldTarget(target, type);
  4246. BNSendWhisper(bnetIDAccount, text);
  4247. else
  4248. local info = ChatTypeInfo["SYSTEM"]
  4249. editBox.chatFrame:AddMessage(format(BN_UNABLE_TO_RESOLVE_NAME, target), info.r, info.g, info.b);
  4250. end
  4251. elseif ( type == "CHANNEL") then
  4252. SendChatMessage(text, type, editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  4253. else
  4254. SendChatMessage(text, type, editBox.languageID);
  4255. end
  4256. if ( addHistory ) then
  4257. ChatEdit_AddHistory(editBox);
  4258. end
  4259. end
  4260. end
  4261. function ChatEdit_OnEnterPressed(self)
  4262. if(AutoCompleteEditBox_OnEnterPressed(self)) then
  4263. return;
  4264. end
  4265. ChatEdit_SendText(self, 1);
  4266. local type = self:GetAttribute("chatType");
  4267. local chatFrame = self:GetParent();
  4268. if ( chatFrame.isTemporary and chatFrame.chatType ~= "PET_BATTLE_COMBAT_LOG" ) then --Temporary window sticky types never change.
  4269. self:SetAttribute("stickyType", chatFrame.chatType);
  4270. --BN_WHISPER FIXME
  4271. if ( chatFrame.chatType == "WHISPER" or chatFrame.chatType == "BN_WHISPER" ) then
  4272. self:SetAttribute("tellTarget", chatFrame.chatTarget);
  4273. end
  4274. elseif ( ChatTypeInfo[type].sticky == 1 ) then
  4275. self:SetAttribute("stickyType", type);
  4276. end
  4277. ChatEdit_ClearChat(self);
  4278. end
  4279. function ChatEdit_ClearChat(editBox)
  4280. ChatEdit_ResetChatTypeToSticky(editBox);
  4281. if ( not editBox.isGM and (GetCVar("chatStyle") ~= "im" or editBox == MacroEditBox) ) then
  4282. editBox:SetText("");
  4283. editBox:Hide();
  4284. else
  4285. ChatEdit_DeactivateChat(editBox);
  4286. end
  4287. end
  4288. function ChatEdit_OnEscapePressed(editBox)
  4289. if ( not AutoCompleteEditBox_OnEscapePressed(editBox) ) then
  4290. ChatEdit_ClearChat(editBox);
  4291. end
  4292. end
  4293. function ChatEdit_ResetChatTypeToSticky(editBox)
  4294. editBox:SetAttribute("chatType", editBox:GetAttribute("stickyType"));
  4295. end
  4296. function ChatEdit_OnSpacePressed(self)
  4297. ChatEdit_ParseText(self, 0);
  4298. end
  4299. function ChatEdit_CustomTabPressed(self)
  4300. end
  4301. local tabCompleteTables = { hash_ChatTypeInfoList, hash_EmoteTokenList };
  4302. function ChatEdit_SecureTabPressed(self)
  4303. local chatType = self:GetAttribute("chatType");
  4304. if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
  4305. local newTarget, newTargetType = ChatEdit_GetNextTellTarget(self:GetAttribute("tellTarget"), chatType);
  4306. if ( newTarget and newTarget ~= "" ) then
  4307. self:SetAttribute("chatType", newTargetType);
  4308. self:SetAttribute("tellTarget", newTarget);
  4309. ChatEdit_UpdateHeader(self);
  4310. end
  4311. return;
  4312. end
  4313. local text = self.tabCompleteText;
  4314. if ( not text ) then
  4315. text = self:GetText();
  4316. self.tabCompleteText = text;
  4317. end
  4318. if ( strsub(text, 1, 1) ~= "/" ) then
  4319. return;
  4320. end
  4321. ChatFrame_ImportAllListsToHash();
  4322. local lastTabComplete = self.lastTabComplete;
  4323. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4324. local command = strmatch(text, "^(/[^%s]+)") or "";
  4325. local cmdString = lastTabComplete;
  4326. repeat --The outer loop lets us go through multiple hash tables of commands.
  4327. repeat --Loop through this table to find matching items.
  4328. cmdString = next(tabCompleteTables[self.tabCompleteTableIndex], cmdString);
  4329. until ( not cmdString or strfind(cmdString, strupper(command), 1, 1) ); --Either we finished going through this table or we found a match.
  4330. if ( not cmdString ) then --Nothing else in the current table, move to the next one.
  4331. self.tabCompleteTableIndex = self.tabCompleteTableIndex + 1;
  4332. end
  4333. until ( cmdString or self.tabCompleteTableIndex > #tabCompleteTables );
  4334. self.lastTabComplete = cmdString;
  4335. if ( cmdString ) then
  4336. self.ignoreTextChange = 1;
  4337. self:SetText(strlower(cmdString));
  4338. else
  4339. self.tabCompleteTableIndex = 1;
  4340. self:SetText(self.tabCompleteText);
  4341. end
  4342. end
  4343. function ChatEdit_OnTabPressed(self)
  4344. if ( not AutoCompleteEditBox_OnTabPressed(self) ) then
  4345. if ( securecall("ChatEdit_CustomTabPressed", self) ) then
  4346. return;
  4347. end
  4348. ChatEdit_SecureTabPressed(self);
  4349. end
  4350. end
  4351. function ChatEdit_OnTextChanged(self, userInput)
  4352. ChatEdit_ParseText(self, 0);
  4353. if ( not self.ignoreTextChange ) then
  4354. self.lastTabComplete = nil;
  4355. self.tabCompleteText = nil;
  4356. self.tabCompleteTableIndex = 1;
  4357. end
  4358. self.ignoreTextChange = nil;
  4359. local regex = "^((/[^%s]+)%s+(.+))"
  4360. local full, command, target = strmatch(self:GetText(), regex);
  4361. if ( not target or (strsub(target, 1, 1) == "|") or self.disallowAutoComplete) then
  4362. AutoComplete_HideIfAttachedTo(self);
  4363. return;
  4364. end
  4365. if ( userInput ) then
  4366. self.autoCompleteXOffset = 35;
  4367. AutoComplete_Update(self, target, self:GetUTF8CursorPosition() - strlenutf8(command) - 1);
  4368. end
  4369. end
  4370. local symbols = {"%%", "%*", "%+", "%-", "%?", "%(", "%)", "%[", "%]", "%$", "%^"} --% has to be escaped first or everything is ruined
  4371. local replacements = {"%%%%", "%%%*", "%%%+", "%%%-", "%%%?", "%%%(", "%%%)", "%%%[", "%%%]", "%%%$", "%%%^"}
  4372. function escapePatternSymbols(text)
  4373. for i=1, #symbols do
  4374. text = text:gsub(symbols[i], replacements[i])
  4375. end
  4376. return text
  4377. end
  4378. function ChatEdit_OnChar(self)
  4379. local regex = "^((/[^%s]+)(%s+)(.+))$"
  4380. local text, command, whitespace, target = strmatch(self:GetText(), regex);
  4381. if (command) then
  4382. self.command = command
  4383. else
  4384. self.command = nil;
  4385. end
  4386. if (command and target and self.autoCompleteSource and self.autoCompleteParams) then --if they typed a command with a autocompletable target
  4387. local utf8Position = self:GetUTF8CursorPosition();
  4388. local allowFullMatch = false;
  4389. local nameToShow = self.autoCompleteSource(target, 1, utf8Position, allowFullMatch, unpack(self.autoCompleteParams))[1];
  4390. if (nameToShow and nameToShow.name) then
  4391. local name = Ambiguate(nameToShow.name, "all");
  4392. --We're going to be setting the text programatically which will clear the userInput flag on the editBox.
  4393. --So we want to manually update the dropdown before we change the text.
  4394. AutoComplete_Update(self, target, utf8Position - strlenutf8(command) - strlen(whitespace));
  4395. if strsub(name, 1, 1) ~= "|" then
  4396. target = escapePatternSymbols(target);
  4397. local newTarget = name;
  4398. self:SetText(string.format("%s%s%s", command, whitespace, newTarget));
  4399. self:HighlightText(strlen(text), strlen(command) + strlen(whitespace) + strlen(newTarget));
  4400. end
  4401. end
  4402. end
  4403. end
  4404. function ChatEdit_OnTextSet(self)
  4405. ChatEdit_ParseText(self, 0);
  4406. end
  4407. function ChatEdit_LanguageShow()
  4408. CHAT_SHOW_IME = true;
  4409. end
  4410. function ChatEdit_OnInputLanguageChanged(self)
  4411. local button = _G[self:GetName().."Language"];
  4412. local variable = _G["INPUT_"..self:GetInputLanguage()];
  4413. button:SetText(variable);
  4414. end
  4415. local function processChatType(editBox, msg, index, send)
  4416. local autoCompleteInfo = AUTOCOMPLETE_LIST[index];
  4417. if ( autoCompleteInfo ) then
  4418. AutoCompleteEditBox_SetAutoCompleteSource(editBox, GetAutoCompleteResults, autoCompleteInfo.include, autoCompleteInfo.exclude);
  4419. else
  4420. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4421. end
  4422. -- this is a special function for "ChatEdit_HandleChatType"
  4423. if ( ChatTypeInfo[index] ) then
  4424. if ( index == "WHISPER" or index == "SMART_WHISPER" ) then
  4425. local targetFound, target, chatType, parsedMsg = ChatEdit_ExtractTellTarget(editBox, msg, index);
  4426. if ( targetFound ) then
  4427. editBox:SetAttribute("tellTarget", target);
  4428. editBox:SetAttribute("chatType", chatType);
  4429. editBox:SetText(parsedMsg);
  4430. ChatEdit_UpdateHeader(editBox);
  4431. elseif ( send == 1 ) then
  4432. ChatEdit_ClearChat(editBox);
  4433. end
  4434. elseif ( index == "REPLY" ) then
  4435. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  4436. if ( lastTell ) then
  4437. --BN_WHISPER FIXME
  4438. editBox:SetAttribute("chatType", lastTellType);
  4439. editBox:SetAttribute("tellTarget", lastTell);
  4440. editBox:SetText(msg);
  4441. ChatEdit_UpdateHeader(editBox);
  4442. else
  4443. if ( send == 1 ) then
  4444. ChatEdit_ClearChat(editBox);
  4445. end
  4446. end
  4447. elseif (index == "CHANNEL") then
  4448. ChatEdit_ExtractChannel(editBox, msg);
  4449. else
  4450. editBox:SetAttribute("chatType", index);
  4451. editBox:SetText(msg);
  4452. ChatEdit_UpdateHeader(editBox);
  4453. end
  4454. return true;
  4455. end
  4456. return false;
  4457. end
  4458. function ChatEdit_HandleChatType(editBox, msg, command, send)
  4459. local channel = strmatch(command, "/([0-9]+)$");
  4460. if( channel ) then
  4461. local chanNum = tonumber(channel);
  4462. if ( chanNum > 0 and chanNum <= MAX_WOW_CHAT_CHANNELS ) then
  4463. local channelNum, channelName = GetChannelName(channel);
  4464. if ( channelNum > 0 ) then
  4465. editBox:SetAttribute("channelTarget", channelNum);
  4466. editBox:SetAttribute("chatType", "CHANNEL");
  4467. editBox:SetText(msg);
  4468. ChatEdit_UpdateHeader(editBox);
  4469. return true;
  4470. end
  4471. end
  4472. else
  4473. -- first check the hash table
  4474. ChatFrame_ImportAllListsToHash();
  4475. if ( hash_ChatTypeInfoList[command] ) then
  4476. return processChatType(editBox, msg, hash_ChatTypeInfoList[command], send);
  4477. end
  4478. end
  4479. --This isn't one we found in our list, so we're not going to autocomplete.
  4480. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4481. return false;
  4482. end
  4483. function ChatEdit_ParseText(editBox, send, parseIfNoSpaces)
  4484. local text = editBox:GetText();
  4485. if ( text == "" ) then
  4486. return;
  4487. end
  4488. if ( strsub(text, 1, 1) ~= "/" ) then
  4489. return;
  4490. end
  4491. --Do not bother parsing if there is no space in the message and we aren't sending.
  4492. if ( send ~= 1 and not parseIfNoSpaces and not strfind(text, "%s") ) then
  4493. return;
  4494. end
  4495. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4496. local command = strmatch(text, "^(/[^%s]+)") or "";
  4497. local msg = "";
  4498. if ( command ~= text ) then
  4499. msg = strsub(text, strlen(command) + 2);
  4500. msg = strmatch(msg, "^%s*(.*)$") or msg;
  4501. end
  4502. command = strupper(command);
  4503. -- Check and see if we've got secure commands to run before we look for chat types or slash commands.
  4504. -- This hash table is prepopulated, unlike the other ones, since nobody can add secure commands. (See line 1205 or thereabouts)
  4505. -- We don't want this code to run unless send is 1, but we need ChatEdit_HandleChatType to run when send is 1 as well, which is why we
  4506. -- didn't just move ChatEdit_HandleChatType inside the send == 0 conditional, which could have also solved the problem with insecure
  4507. -- code having the ability to affect secure commands.
  4508. if ( send == 1 and hash_SecureCmdList[command] ) then
  4509. hash_SecureCmdList[command](strtrim(msg));
  4510. editBox:AddHistoryLine(text);
  4511. ChatEdit_ClearChat(editBox);
  4512. return;
  4513. end
  4514. ChatFrame_ImportAllListsToHash();
  4515. -- Handle chat types. No need for a securecall here, since we should be done with anything secure.
  4516. if ( ChatEdit_HandleChatType(editBox, msg, command, send) ) then
  4517. return;
  4518. end
  4519. if ( send == 0 ) then
  4520. return;
  4521. end
  4522. -- Check the hash tables for slash commands and emotes to see if we've run this before.
  4523. if ( hash_SlashCmdList[command] ) then
  4524. -- if the code in here changes - change the corresponding code below
  4525. hash_SlashCmdList[command](strtrim(msg), editBox);
  4526. editBox:AddHistoryLine(text);
  4527. ChatEdit_ClearChat(editBox);
  4528. return;
  4529. elseif ( hash_EmoteTokenList[command] ) then
  4530. -- if the code in here changes - change the corresponding code below
  4531. local restricted = DoEmote(hash_EmoteTokenList[command], msg);
  4532. -- If the emote is restricted, we want to treat it as if the player entered an unrecognized chat command.
  4533. if ( not restricted ) then
  4534. editBox:AddHistoryLine(text);
  4535. ChatEdit_ClearChat(editBox);
  4536. return;
  4537. end
  4538. end
  4539. -- Unrecognized chat command, show simple help text
  4540. if ( editBox.chatFrame ) then
  4541. ChatFrame_DisplayHelpTextSimple(editBox.chatFrame);
  4542. end
  4543. -- Reset the chat type and clear the edit box's contents
  4544. ChatEdit_ClearChat(editBox);
  4545. return;
  4546. end
  4547. function SubstituteChatMessageBeforeSend(msg)
  4548. for tag in string.gmatch(msg, "%b{}") do
  4549. local term = strlower(string.gsub(tag, "[{}]", ""));
  4550. if ( GROUP_TAG_LIST[term] ) then
  4551. local groupIndex = GROUP_TAG_LIST[term];
  4552. msg = string.gsub(msg, tag, "{"..GROUP_LANGUAGE_INDEPENDENT_STRINGS[groupIndex].."}");
  4553. end
  4554. end
  4555. return msg;
  4556. end
  4557. function ChatEdit_ExtractTellTarget(editBox, msg, chatType)
  4558. local tellTargetExtractionAutoComplete;
  4559. if ( chatType == "WHISPER" ) then
  4560. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.WHISPER_EXTRACT;
  4561. else
  4562. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.SMART_WHISPER_EXTRACT;
  4563. end
  4564. -- Grab the string after the slash command
  4565. local target = strmatch(msg, "%s*(.*)");
  4566. --If we haven't even finished one word, we aren't done.
  4567. if ( not target or not strfind(target, "%s") ) then
  4568. return false;
  4569. end
  4570. if ( strsub(target, 1, 1) == "|" ) then
  4571. return false;
  4572. end
  4573. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4574. --Even if there's a space, we still want to let the person keep typing -- they may be trying to type whatever is in AutoComplete.
  4575. return false;
  4576. end
  4577. --Keep pulling off everything after the last space until we either have something on the AutoComplete list or only a single word is left.
  4578. while ( strfind(target, "%s") ) do
  4579. --Pull off everything after the last space.
  4580. target = strmatch(target, "(.+)%s+[^%s]*");
  4581. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4582. break;
  4583. end
  4584. end
  4585. msg = strsub(msg, strlen(target) + 2);
  4586. if ( chatType ~= "WHISPER" and BNet_GetBNetIDAccount(target) ) then --"WHISPER" forces character whisper
  4587. chatType = "BN_WHISPER";
  4588. else
  4589. chatType = "WHISPER";
  4590. end
  4591. return true, target, chatType, msg;
  4592. end
  4593. function ChatEdit_ExtractChannel(editBox, msg)
  4594. local target = strmatch(msg, "%s*([^%s]+)");
  4595. if ( not target ) then
  4596. return;
  4597. end
  4598. local channelNum, channelName = GetChannelName(target);
  4599. if ( channelNum <= 0 ) then
  4600. return;
  4601. end
  4602. msg = strsub(msg, strlen(target) + 2);
  4603. editBox:SetAttribute("channelTarget", channelNum);
  4604. editBox:SetAttribute("chatType", "CHANNEL");
  4605. editBox:SetText(msg);
  4606. ChatEdit_UpdateHeader(editBox);
  4607. end
  4608. -- Chat menu functions
  4609. function ChatMenu_SetChatType(chatFrame, type)
  4610. local editBox = ChatFrame_OpenChat("");
  4611. editBox:SetAttribute("chatType", type);
  4612. ChatEdit_UpdateHeader(editBox);
  4613. end
  4614. function ChatMenu_Say(self)
  4615. ChatMenu_SetChatType(self:GetParent().chatFrame, "SAY");
  4616. end
  4617. function ChatMenu_Party(self)
  4618. ChatMenu_SetChatType(self:GetParent().chatFrame, "PARTY");
  4619. end
  4620. function ChatMenu_Raid(self)
  4621. ChatMenu_SetChatType(self:GetParent().chatFrame, "RAID");
  4622. end
  4623. function ChatMenu_InstanceChat(self)
  4624. ChatMenu_SetChatType(self:GetParent().chatFrame, "INSTANCE_CHAT");
  4625. end
  4626. function ChatMenu_Guild(self)
  4627. ChatMenu_SetChatType(self:GetParent().chatFrame, "GUILD");
  4628. end
  4629. function ChatMenu_Yell(self)
  4630. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4631. end
  4632. function ChatMenu_Whisper(self)
  4633. local editBox = ChatFrame_OpenChat(SLASH_SMART_WHISPER1.." ");
  4634. editBox:SetText(SLASH_SMART_WHISPER1.." "..editBox:GetText());
  4635. end
  4636. function ChatMenu_Emote(self)
  4637. ChatMenu_SetChatType(self:GetParent().chatFrame, "EMOTE");
  4638. end
  4639. function ChatMenu_Reply(self)
  4640. ChatFrame_ReplyTell();
  4641. end
  4642. function ChatMenu_VoiceMacro(self)
  4643. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4644. end
  4645. function ChatMenu_OnLoad(self)
  4646. self.chatFrame = DEFAULT_CHAT_FRAME;
  4647. UIMenu_Initialize(self);
  4648. UIMenu_AddButton(self, SAY_MESSAGE, SLASH_SAY1, ChatMenu_Say);
  4649. UIMenu_AddButton(self, PARTY_MESSAGE, SLASH_PARTY1, ChatMenu_Party);
  4650. UIMenu_AddButton(self, RAID_MESSAGE, SLASH_RAID1, ChatMenu_Raid);
  4651. UIMenu_AddButton(self, INSTANCE_CHAT_MESSAGE, SLASH_INSTANCE_CHAT1, ChatMenu_InstanceChat);
  4652. UIMenu_AddButton(self, GUILD_MESSAGE, SLASH_GUILD1, ChatMenu_Guild);
  4653. UIMenu_AddButton(self, YELL_MESSAGE, SLASH_YELL1, ChatMenu_Yell);
  4654. UIMenu_AddButton(self, WHISPER_MESSAGE, SLASH_SMART_WHISPER1, ChatMenu_Whisper);
  4655. UIMenu_AddButton(self, EMOTE_MESSAGE, SLASH_EMOTE1, ChatMenu_Emote, "EmoteMenu");
  4656. UIMenu_AddButton(self, REPLY_MESSAGE, SLASH_REPLY1, ChatMenu_Reply);
  4657. UIMenu_AddButton(self, LANGUAGE, nil, nil, "LanguageMenu");
  4658. UIMenu_AddButton(self, VOICEMACRO_LABEL, nil, nil, "VoiceMacroMenu");
  4659. UIMenu_AddButton(self, MACRO, SLASH_MACRO1, ShowMacroFrame);
  4660. UIMenu_AutoSize(self);
  4661. end
  4662. function ChatMenu_OnShow(self)
  4663. UIMenu_OnShow(self);
  4664. EmoteMenu:Hide();
  4665. LanguageMenu:Hide();
  4666. VoiceMacroMenu:Hide();
  4667. end
  4668. function EmoteMenu_Click(self)
  4669. DoEmote(EmoteList[self:GetID()]);
  4670. ChatMenu:Hide();
  4671. end
  4672. function TextEmoteSort(token1, token2)
  4673. local i = 1;
  4674. local string1, string2;
  4675. local token = _G["EMOTE"..i.."_TOKEN"];
  4676. while ( i <= MAXEMOTEINDEX ) do
  4677. if ( token == token1 ) then
  4678. string1 = _G["EMOTE"..i.."_CMD1"];
  4679. if ( string2 ) then
  4680. break;
  4681. end
  4682. end
  4683. if ( token == token2 ) then
  4684. string2 = _G["EMOTE"..i.."_CMD1"];
  4685. if ( string1 ) then
  4686. break;
  4687. end
  4688. end
  4689. i = i + 1;
  4690. token = _G["EMOTE"..i.."_TOKEN"];
  4691. end
  4692. return string1 < string2;
  4693. end
  4694. function OnMenuLoad(self,list,func)
  4695. sort(list, TextEmoteSort);
  4696. UIMenu_Initialize(self);
  4697. self.parentMenu = "ChatMenu";
  4698. for index, value in pairs(list) do
  4699. local i = 1;
  4700. local token = _G["EMOTE"..i.."_TOKEN"];
  4701. while ( i < MAXEMOTEINDEX ) do
  4702. if ( token == value ) then
  4703. break;
  4704. end
  4705. i = i + 1;
  4706. token = _G["EMOTE"..i.."_TOKEN"];
  4707. end
  4708. local label = _G["EMOTE"..i.."_CMD1"];
  4709. if ( not label ) then
  4710. label = value;
  4711. end
  4712. UIMenu_AddButton(self, label, nil, func);
  4713. end
  4714. UIMenu_AutoSize(self);
  4715. end
  4716. function EmoteMenu_OnLoad(self)
  4717. OnMenuLoad(self, EmoteList, EmoteMenu_Click);
  4718. end
  4719. function LanguageMenu_OnLoad(self)
  4720. UIMenu_Initialize(self);
  4721. self.parentMenu = "ChatMenu";
  4722. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  4723. self:RegisterEvent("LANGUAGE_LIST_CHANGED");
  4724. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  4725. end
  4726. function VoiceMacroMenu_Click(self)
  4727. local emote = TextEmoteSpeechList[self:GetID()];
  4728. if (emote == EMOTE454_TOKEN or emote == EMOTE455_TOKEN) then
  4729. local faction = UnitFactionGroup("player", true);
  4730. if (faction == "Alliance") then
  4731. emote = EMOTE454_TOKEN;
  4732. elseif (faction == "Horde") then
  4733. emote = EMOTE455_TOKEN;
  4734. end
  4735. end
  4736. DoEmote(emote);
  4737. ChatMenu:Hide();
  4738. end
  4739. function VoiceMacroMenu_OnLoad(self)
  4740. OnMenuLoad(self, TextEmoteSpeechList, VoiceMacroMenu_Click);
  4741. end
  4742. function LanguageMenu_OnEvent(self, event, ...)
  4743. if ( event == "PLAYER_ENTERING_WORLD" ) then
  4744. self:Hide();
  4745. UIMenu_Initialize(self);
  4746. LanguageMenu_LoadLanguages(self);
  4747. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4748. return;
  4749. end
  4750. if ( event == "LANGUAGE_LIST_CHANGED" ) then
  4751. self:Hide();
  4752. UIMenu_Initialize(self);
  4753. LanguageMenu_LoadLanguages(self);
  4754. return;
  4755. end
  4756. if ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  4757. self:Hide();
  4758. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4759. return;
  4760. end
  4761. end
  4762. function LanguageMenu_LoadLanguages(self)
  4763. local numLanguages = GetNumLanguages();
  4764. local i;
  4765. local editBoxLanguageID = self:GetParent().chatFrame.editBox.languageID;
  4766. local languageKnown = false;
  4767. for i = 1, numLanguages, 1 do
  4768. local language, languageID = GetLanguageByIndex(i);
  4769. UIMenu_AddButton(self, language, nil, LanguageMenu_Click);
  4770. if ( languageID == editBoxLanguageID ) then
  4771. languageKnown = true;
  4772. end
  4773. end
  4774. if ( languageKnown ~= true ) then
  4775. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(1);
  4776. end
  4777. UIMenu_AutoSize(self);
  4778. end
  4779. function LanguageMenu_Click(self)
  4780. self:GetParent():GetParent().chatFrame.editBox.language, self:GetParent():GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(self:GetID());
  4781. ChatMenu:Hide();
  4782. end
  4783. function ChatFrame_ActivateCombatMessages(chatFrame)
  4784. ChatFrame_AddMessageGroup(chatFrame, "OPENING");
  4785. ChatFrame_AddMessageGroup(chatFrame, "TRADESKILLS");
  4786. ChatFrame_AddMessageGroup(chatFrame, "PET_INFO");
  4787. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_MISC_INFO");
  4788. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_XP_GAIN");
  4789. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_HONOR_GAIN");
  4790. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_FACTION_CHANGE");
  4791. end
  4792. function ChatChannelDropDown_Show(chatFrame, chatType, chatTarget, chatName)
  4793. HideDropDownMenu(1);
  4794. ChatChannelDropDown.initialize = ChatChannelDropDown_Initialize;
  4795. ChatChannelDropDown.displayMode = "MENU";
  4796. ChatChannelDropDown.chatType = chatType;
  4797. ChatChannelDropDown.chatTarget = chatTarget;
  4798. ChatChannelDropDown.chatName = chatName;
  4799. ChatChannelDropDown.chatFrame = chatFrame;
  4800. ToggleDropDownMenu(1, nil, ChatChannelDropDown, "cursor");
  4801. end
  4802. function ChatChannelDropDown_Initialize()
  4803. local frame = ChatChannelDropDown;
  4804. local info = UIDropDownMenu_CreateInfo();
  4805. info.text = ChatFrame_ResolveChannelName(frame.chatName);
  4806. info.notCheckable = true;
  4807. info.isTitle = true;
  4808. UIDropDownMenu_AddButton(info, 1);
  4809. local clubId, streamId = ChatFrame_GetCommunityAndStreamFromChannel(frame.chatName);
  4810. if clubId and streamId and C_Club.IsEnabled() then
  4811. info = UIDropDownMenu_CreateInfo();
  4812. info.text = CHAT_CHANNEL_DROP_DOWN_OPEN_COMMUNITIES_FRAME;
  4813. info.notCheckable = true;
  4814. info.func = function ()
  4815. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  4816. ToggleCommunitiesFrame();
  4817. end
  4818. CommunitiesFrame:SelectStream(clubId, streamId);
  4819. CommunitiesFrame:SelectClub(clubId);
  4820. end;
  4821. UIDropDownMenu_AddButton(info);
  4822. end
  4823. info = UIDropDownMenu_CreateInfo();
  4824. info.text = MOVE_TO_NEW_WINDOW;
  4825. info.notCheckable = 1;
  4826. info.func = ChatChannelDropDown_PopOutChat;
  4827. info.arg1 = frame.chatType;
  4828. info.arg2 = frame.chatTarget;
  4829. if ( FCF_GetNumActiveChatFrames() == NUM_CHAT_WINDOWS ) then
  4830. info.disabled = 1;
  4831. end
  4832. UIDropDownMenu_AddButton(info);
  4833. end
  4834. function ChatChannelDropDown_PopOutChat(self, chatType, chatTarget)
  4835. local sourceChatFrame = ChatChannelDropDown.chatFrame;
  4836. local windowName;
  4837. if ( chatType == "CHANNEL" ) then
  4838. windowName = Chat_GetChannelShortcutName(chatTarget);
  4839. else
  4840. windowName = _G[chatType];
  4841. end
  4842. local frame = FCF_OpenNewWindow(windowName);
  4843. FCF_CopyChatSettings(frame, sourceChatFrame);
  4844. ChatFrame_RemoveAllMessageGroups(frame);
  4845. ChatFrame_RemoveAllChannels(frame);
  4846. ChatFrame_ReceiveAllPrivateMessages(frame);
  4847. ChatFrame_AddMessageGroup(frame, chatType);
  4848. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4849. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4850. ChatFrame_AddMessageGroup(frame, chat);
  4851. end
  4852. end
  4853. frame.editBox:SetAttribute("chatType", chatType);
  4854. frame.editBox:SetAttribute("stickyType", chatType);
  4855. if ( chatType == "CHANNEL" ) then
  4856. frame.editBox:SetAttribute("channelTarget", chatTarget);
  4857. ChatFrame_AddChannel(frame, Chat_GetChannelShortcutName(chatTarget));
  4858. end
  4859. if ( chatType == "PET_BATTLE_COMBAT_LOG" or chatType == "PET_BATTLE_INFO" ) then
  4860. frame.editBox:SetAttribute("chatType", "SAY");
  4861. frame.editBox:SetAttribute("stickyType", "SAY");
  4862. end
  4863. --Remove the things popped out from the source chat frame.
  4864. if ( chatType == "CHANNEL" ) then
  4865. ChatFrame_RemoveChannel(sourceChatFrame, Chat_GetChannelShortcutName(chatTarget));
  4866. else
  4867. ChatFrame_RemoveMessageGroup(sourceChatFrame, chatType);
  4868. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4869. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4870. ChatFrame_RemoveMessageGroup(sourceChatFrame, chat);
  4871. end
  4872. end
  4873. end
  4874. --Copy over messages
  4875. local accessID = ChatHistory_GetAccessID(chatType, chatTarget);
  4876. for i = 1, sourceChatFrame:GetNumMessages() do
  4877. local text, r, g, b, chatTypeID, messageAccessID, lineID = sourceChatFrame:GetMessageInfo(i);
  4878. if messageAccessID == accessID then
  4879. frame:AddMessage(text, r, g, b, chatTypeID, messageAccessID, lineID);
  4880. end
  4881. end
  4882. --Remove the messages from the old frame.
  4883. sourceChatFrame:RemoveMessagesByPredicate(function(text, r, g, b, chatTypeID, messageAccessID, lineID) return messageAccessID == accessID; end);
  4884. end
  4885. function Chat_GetChannelShortcutName(index)
  4886. if not tonumber(index) and type(index) == "string" then
  4887. index = GetChannelName(index);
  4888. end
  4889. return C_ChatInfo.GetChannelShortcut(index);
  4890. end
  4891. function ChatChannelDropDown_PopInChat(self, chatType, chatTarget)
  4892. --PopOutChat_PopInChat(chatType, chatTarget);
  4893. end
  4894. function Chat_ShouldColorChatByClass(chatTypeInfo)
  4895. local override = ChatClassColorOverrideShown();
  4896. local colorByClass = chatTypeInfo and chatTypeInfo.colorNameByClass;
  4897. return override or (override == nil and colorByClass);
  4898. end
  4899. function Chat_GetColoredChatName(chatType, chatTarget)
  4900. if ( chatType == "CHANNEL" ) then
  4901. local info = ChatTypeInfo["CHANNEL"..chatTarget];
  4902. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4903. local chanNum, channelName = GetChannelName(chatTarget);
  4904. return format("%s|Hchannel:channel:%d|h[%d. %s]|h|r", colorString, chanNum, chanNum, gsub(channelName, "%s%-%s.*", "")); --The gsub removes zone-specific markings (e.g. "General - Ironforge" to "General")
  4905. elseif ( chatType == "WHISPER" ) then
  4906. local info = ChatTypeInfo["WHISPER"];
  4907. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4908. return format("%s[%s] |Hplayer:%3$s|h[%3$s]|h|r", colorString, _G[chatType], chatTarget);
  4909. else
  4910. local info = ChatTypeInfo[chatType];
  4911. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4912. return format("%s|Hchannel:%s|h[%s]|h|r", colorString, chatType, _G[chatType]);
  4913. end
  4914. end
  4915. --------------------------------------------------------------------------------
  4916. -- Social share link functions
  4917. --------------------------------------------------------------------------------
  4918. SHARE_ICON_COLOR = "ffffd200";
  4919. SHARE_ICON_TEXT = "|TInterface\\ChatFrame\\UI-ChatIcon-Share:18:18|t";
  4920. function Social_GetShareItemLink(strippedItemLink, earned)
  4921. local earnedNum = 0;
  4922. if (earned) then
  4923. earnedNum = 1;
  4924. end
  4925. return format("|c%s|Hshareitem:%s:%d|h%s|h|r", SHARE_ICON_COLOR, strippedItemLink, earnedNum, SHARE_ICON_TEXT);
  4926. end
  4927. function Social_GetShareAchievementLink(achievementID, earned)
  4928. local earnedNum = 0;
  4929. if (earned) then
  4930. earnedNum = 1;
  4931. end
  4932. return format("|c%s|Hshareachieve:%d:%d|h%s|h|r", SHARE_ICON_COLOR, achievementID, earnedNum, SHARE_ICON_TEXT);
  4933. end
  4934. function Social_GetShareScreenshotLink()
  4935. local index = C_Social.GetLastScreenshotIndex();
  4936. return format("|c%s|Hsharess:%d|h%s|h|r", SHARE_ICON_COLOR, index, SHARE_ICON_TEXT);
  4937. end