Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 111.34 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------------
  2. -- Client Lua Script for Bb_chat
  3. -- Copyright (c) NCsoft. All rights reserved
  4. -----------------------------------------------------------------------------------------------
  5.  
  6. local core = Apollo.GetPackage("Gemini:Addon-1.1").tPackage
  7. local Log = Apollo.GetPackage("Log-1.0").tPackage
  8. require "Window"
  9. require "Unit"
  10. require "Spell"
  11. require "GameLib"
  12. require "ChatSystemLib"
  13. require "ChatChannelLib"
  14. require "CombatFloater"
  15. require "GroupLib"
  16. require "FriendshipLib"
  17. require "DatacubeLib"
  18.  
  19.  
  20. local Bb_chat = {}
  21. local kcrInvalidColor = ApolloColor.new("InvalidChat")
  22. local kcrValidColor = ApolloColor.new("white")
  23. local knCountSpaces = 2
  24. local kstrColorChatRegular = "ff7fffb9"
  25. local kstrColorChatShout = "ffd9eef7"
  26. local kstrColorChatRoleplay = "ff58e3b0"
  27. local kstrColorNonSelectedEntry = "UI_BtnTextHoloNormal"
  28. local kstrBubbleFont = "CRB_InterfaceMedium_BB"
  29. local kstrDialogFont = "CRB_InterfaceMedium_BB"
  30. local kstrDialogFontRP = "CRB_InterfaceMedium_BB"
  31.  
  32. local kstrGMIcon = "Icon_Windows_UI_GMIcon"
  33. local knChannelListHeight = 275
  34.  
  35. local knWindowStayOnScreenOffset = 50
  36.  
  37. local knFadeTimerfrequency = 10 --blakbird changed from 1
  38. local knTimeToFade = 5 --blakbird changed from 300
  39. local knTimeToFadeAfterAction = 5 --blakbird changed from 30
  40.  
  41. local knSaveVersion = 8
  42. local knMaxRecentEntries = 10
  43. local karEvalColors =
  44. {
  45. [Item.CodeEnumItemQuality.Inferior] = "ItemQuality_Inferior",
  46. [Item.CodeEnumItemQuality.Average] = "ItemQuality_Average",
  47. [Item.CodeEnumItemQuality.Good] = "ItemQuality_Good",
  48. [Item.CodeEnumItemQuality.Excellent] = "ItemQuality_Excellent",
  49. [Item.CodeEnumItemQuality.Superb] = "ItemQuality_Superb",
  50. [Item.CodeEnumItemQuality.Legendary] = "ItemQuality_Legendary",
  51. [Item.CodeEnumItemQuality.Artifact] = "ItemQuality_Artifact",
  52. }
  53.  
  54. local karChannelTypeToColor = -- TODO Merge into one table like this
  55. {
  56. [ChatSystemLib.ChatChannel_Command] = { Channel = "ChannelCommand", },
  57. [ChatSystemLib.ChatChannel_System] = { Channel = "ChannelSystem", },
  58. [ChatSystemLib.ChatChannel_Debug] = { Channel = "ChannelDebug", },
  59. [ChatSystemLib.ChatChannel_Say] = { Channel = "ChannelSay", },
  60. [ChatSystemLib.ChatChannel_Yell] = { Channel = "ChannelShout", },
  61. [ChatSystemLib.ChatChannel_Whisper] = { Channel = "ChannelWhisper", },
  62. [ChatSystemLib.ChatChannel_Party] = { Channel = "ChannelParty", },
  63. [ChatSystemLib.ChatChannel_Emote] = { Channel = "ChannelEmote", },
  64. [ChatSystemLib.ChatChannel_AnimatedEmote] = { Channel = "ChannelEmote", },
  65. [ChatSystemLib.ChatChannel_Zone] = { Channel = "ChannelZone", },
  66. [ChatSystemLib.ChatChannel_ZoneGerman] = { Channel = "ChannelZone", },
  67. [ChatSystemLib.ChatChannel_ZoneFrench] = { Channel = "ChannelZone", },
  68. [ChatSystemLib.ChatChannel_ZonePvP] = { Channel = "ChannelPvP", },
  69. [ChatSystemLib.ChatChannel_Trade] = { Channel = "ChannelTrade", },
  70. [ChatSystemLib.ChatChannel_Guild] = { Channel = "ChannelGuild", },
  71. [ChatSystemLib.ChatChannel_GuildOfficer] = { Channel = "ChannelGuildOfficer", },
  72. [ChatSystemLib.ChatChannel_Society] = { Channel = "ChannelCircle2", },
  73. [ChatSystemLib.ChatChannel_Custom] = { Channel = "ChannelCustom", },
  74. [ChatSystemLib.ChatChannel_NPCSay] = { Channel = "ChannelNPC", },
  75. [ChatSystemLib.ChatChannel_NPCYell] = { Channel = "ChannelNPC", },
  76. [ChatSystemLib.ChatChannel_NPCWhisper] = { Channel = "ChannelNPC", },
  77. [ChatSystemLib.ChatChannel_Datachron] = { Channel = "ChannelNPC", },
  78. [ChatSystemLib.ChatChannel_Combat] = { Channel = "ChannelGeneral", },
  79. [ChatSystemLib.ChatChannel_Realm] = { Channel = "ChannelSupport", },
  80. [ChatSystemLib.ChatChannel_Loot] = { Channel = "ChannelLoot", },
  81. [ChatSystemLib.ChatChannel_PlayerPath] = { Channel = "ChannelGeneral", },
  82. [ChatSystemLib.ChatChannel_Instance] = { Channel = "ChannelInstance", },
  83. [ChatSystemLib.ChatChannel_WarParty] = { Channel = "ChannelWarParty", },
  84. [ChatSystemLib.ChatChannel_WarPartyOfficer] = { Channel = "ChannelWarPartyOfficer", },
  85. [ChatSystemLib.ChatChannel_Nexus] = { Channel = "ChannelNexus", },
  86. [ChatSystemLib.ChatChannel_AccountWhisper] = { Channel = "ChannelAccountWisper", },
  87. }
  88.  
  89. local ktChatResultOutputStrings =
  90. {
  91. [ChatSystemLib.ChatChannelResult_DoesntExist] = Apollo.GetString("CRB_Channel_does_not_exist"),
  92. [ChatSystemLib.ChatChannelResult_BadPassword] = Apollo.GetString("CRB_Channel_password_incorrect"),
  93. [ChatSystemLib.ChatChannelResult_NoPermissions] = Apollo.GetString("CRB_Channel_no_permissions"),
  94. [ChatSystemLib.ChatChannelResult_NoSpeaking] = Apollo.GetString("CRB_Channel_no_speaking"),
  95. [ChatSystemLib.ChatChannelResult_Muted] = Apollo.GetString("CRB_Channel_muted"),
  96. [ChatSystemLib.ChatChannelResult_Throttled] = Apollo.GetString("CRB_Channel_throttled"),
  97. [ChatSystemLib.ChatChannelResult_NotInGroup] = Apollo.GetString("CRB_Not_in_group"),
  98. [ChatSystemLib.ChatChannelResult_NotInGuild] = Apollo.GetString("CRB_Channel_not_in_guild"),
  99. [ChatSystemLib.ChatChannelResult_NotInSociety] = Apollo.GetString("CRB_Channel_not_in_society"),
  100. [ChatSystemLib.ChatChannelResult_NotGuildOfficer] = Apollo.GetString("CRB_Channel_not_guild_officer"),
  101. [ChatSystemLib.ChatChannelResult_AlreadyMember] = Apollo.GetString("ChatLog_AlreadyInChannel"),
  102. [ChatSystemLib.ChatChannelResult_BadName] = Apollo.GetString("ChatLog_InvalidChannel"),
  103. [ChatSystemLib.ChatChannelResult_NotMember] = Apollo.GetString("ChatLog_TargetNotInChannel"),
  104. [ChatSystemLib.ChatChannelResult_NotInWarParty] = Apollo.GetString("ChatLog_NotInWarparty"),
  105. [ChatSystemLib.ChatChannelResult_NotWarPartyOfficer] = Apollo.GetString("ChatLog_NotWarpartyOfficer"),
  106. [ChatSystemLib.ChatChannelResult_InvalidMessageText] = Apollo.GetString("ChatLog_InvalidMessage"),
  107. [ChatSystemLib.ChatChannelResult_InvalidPasswordText] = Apollo.GetString("ChatLog_UseDifferentPassword"),
  108. [ChatSystemLib.ChatChannelResult_TruncatedText] = Apollo.GetString("ChatLog_MessageTruncated"),
  109. [ChatSystemLib.ChatChannelResult_InvalidCharacterName] = Apollo.GetString("ChatLog_InvalidCharacterName"),
  110. [ChatSystemLib.ChatChannelResult_GMMuted] = Apollo.GetString("ChatLog_MutedByGm"),
  111. [ChatSystemLib.ChatChannelResult_MissingEntitlement] = Apollo.GetString("ChatLog_MissingEntitlement"),
  112. }
  113.  
  114. local ktChatActionOutputStrings =
  115. {
  116. [ChatSystemLib.ChatChannelAction_PassOwner] = Apollo.GetString("ChatLog_PassedOwnership"),
  117. [ChatSystemLib.ChatChannelAction_AddModerator] = Apollo.GetString("ChatLog_MadeModerator"),
  118. [ChatSystemLib.ChatChannelAction_RemoveModerator] = Apollo.GetString("ChatLog_MadeMember"),
  119. [ChatSystemLib.ChatChannelAction_Muted] = Apollo.GetString("ChatLog_PlayerMuted"),
  120. [ChatSystemLib.ChatChannelAction_Unmuted] = Apollo.GetString("ChatLog_PlayerUnmuted"),
  121. [ChatSystemLib.ChatChannelAction_Kicked] = Apollo.GetString("ChatLog_PlayerKicked"),
  122. [ChatSystemLib.ChatChannelAction_AddPassword] = Apollo.GetString("ChatLog_PasswordAdded"),
  123. [ChatSystemLib.ChatChannelAction_RemovePassword] = Apollo.GetString("ChatLog_PasswordRemoved")
  124. }
  125.  
  126. local ktChatJoinOutputStrings =
  127. {
  128. [ChatSystemLib.ChatChannelResult_BadPassword] = Apollo.GetString("CRB_Channel_password_incorrect"),
  129. [ChatSystemLib.ChatChannelResult_AlreadyMember] = Apollo.GetString("ChatLog_AlreadyMember"),
  130. [ChatSystemLib.ChatChannelResult_BadName] = Apollo.GetString("ChatLog_BadName"),
  131. [ChatSystemLib.ChatChannelResult_InvalidPasswordText] = Apollo.GetString("ChatLog_InvalidPasswordText"),
  132. [ChatSystemLib.ChatChannelResult_NoPermissions] = Apollo.GetString("CRB_Channel_no_permissions"),
  133. [ChatSystemLib.ChatChannelResult_TooManyCustomChannels] = Apollo.GetString("ChatLog_TooManyCustom")
  134. }
  135.  
  136. local ktDatacubeTypeStrings =
  137. {
  138. [DatacubeLib.DatacubeType_Datacube] = Apollo.GetString("ChatLog_Datacube"),
  139. [DatacubeLib.DatacubeType_Chronicle] = Apollo.GetString("ChatLog_Chronicle"),
  140. [DatacubeLib.DatacubeType_Journal] = Apollo.GetString("ChatLog_Journal")
  141. }
  142.  
  143. local ktDefaultHolds = {}
  144. ktDefaultHolds[ChatSystemLib.ChatChannel_Whisper] = true
  145.  
  146. function Bb_chat:new(o)
  147. o = o or {}
  148. setmetatable(o, self)
  149. self.__index = self
  150. return o
  151. end
  152.  
  153. function Bb_chat:Init()
  154. Apollo.RegisterAddon(self, true, Apollo.GetString("ChatLog_ChatLogBtn"))
  155. end
  156.  
  157. function Bb_chat:OnSave(eType)
  158. if eType ~= GameLib.CodeEnumAddonSaveLevel.Character then
  159. return nil
  160. end
  161. local wndChatOptionsContent = self.wndChatOptions:FindChild("ChatOptionsContent")
  162.  
  163. local nFoundFontSize = 2
  164. if self.wndChatOptions then
  165. if wndChatOptionsContent:FindChild("FontSizeSmall"):IsChecked() then
  166. nFoundFontSize = 1
  167. elseif wndChatOptionsContent:FindChild("FontSizeMedium"):IsChecked() then
  168. nFoundFontSize = 2
  169. elseif wndChatOptionsContent:FindChild("FontSizeLarge"):IsChecked() then
  170. nFoundFontSize = 3
  171. elseif wndChatOptionsContent:FindChild("FontSizeHuge"):IsChecked() then
  172. nFoundFontSize = 4
  173. end
  174. end
  175.  
  176.  
  177. local tSave =
  178. {
  179. tWindow = {},
  180. bEnableBGFade = self.bEnableBGFade,
  181. bEnableNCFade = self.bEnableNCFade,
  182. nBGOpacity = self.nBGOpacity,
  183. nFontSize = nFoundFontSize,
  184. bShowChannel = self.bShowChannel,
  185. bShowTimestamp = self.bShowTimestamp,
  186. bProfanityFilter = self.bProfanityFilter,
  187. eRoleplayOption = self.eRoleplayOption,
  188. bEnableChatLineFade = self.bEnableChatLineFade
  189. }
  190.  
  191. local arWindowGroupMap = {}
  192. local nCount = 0
  193. for key, wndChat in pairs(self.tChatWindows) do
  194. nCount = nCount + 1
  195. tSave.tWindow[nCount] = {}
  196. tSave.tWindow[nCount].tChatData = wndChat:GetData()
  197. tSave.tWindow[nCount].tStrings = wndChat:FindChild("Input"):GetHistoryStrings()
  198. tSave.tWindow[nCount].strTitle = wndChat:GetText()
  199.  
  200. local nMatchingTabGroup = 0
  201. for idx, wndGroup in pairs(arWindowGroupMap) do
  202. if wndGroup:IsAttachedToTab(wndChat) then
  203. nMatchingTabGroup = idx
  204. break
  205. end
  206. end
  207.  
  208. if nMatchingTabGroup == 0 then
  209. nMatchingTabGroup = #arWindowGroupMap + 1
  210. arWindowGroupMap[nMatchingTabGroup] = wndChat
  211. end
  212.  
  213. tSave.tWindow[nCount].nTabGroup = nMatchingTabGroup
  214. tSave.tWindow[nCount].tWindowLocation = wndChat:GetLocation():ToTable()
  215. end
  216.  
  217. tSave.nVersion = knSaveVersion
  218. return tSave
  219. end
  220.  
  221. function Bb_chat:OnRestore(eType, tSavedData)
  222. if not tSavedData or tSavedData.nVersion ~= knSaveVersion then
  223. return
  224. end
  225.  
  226. if tSavedData.bEnableNCFade ~= nil then
  227. self.bEnableNCFade = tSavedData.bEnableNCFade
  228. end
  229. if tSavedData.bEnableBGFade ~= nil then
  230. self.bEnableBGFade = tSavedData.bEnableBGFade
  231. end
  232. if tSavedData.nBGOpacity ~= nil then
  233. self.nBGOpacity = tSavedData.nBGOpacity
  234. end
  235. if tSavedData.bShowChannel ~= nil then
  236. self.bShowChannel = tSavedData.bShowChannel
  237. end
  238. if tSavedData.bShowTimestamp ~= nil then
  239. self.bShowTimestamp = tSavedData.bShowTimestamp
  240. end
  241. if tSavedData.bProfanityFilter ~= nil then
  242. self.bProfanityFilter = tSavedData.bProfanityFilter
  243. end
  244. if tSavedData.eRoleplayOption then
  245. self.eRoleplayOption = tSavedData.eRoleplayOption
  246. end
  247. if tSavedData.bEnableChatLineFade then
  248. self.bEnableChatLineFade = tSavedData.bEnableChatLineFade
  249. end
  250.  
  251. self.nFontSize = tSavedData.nFontSize
  252. if tSavedData.tWindow and #tSavedData.tWindow > 0 then
  253. self.tWindow = tSavedData.tWindow
  254. end
  255. end
  256.  
  257. function Bb_chat:OnConfigure() -- From ESC -> Options
  258. if self.wndChatOptions and self.wndChatOptions:IsValid() then
  259. self.wndChatOptions:Invoke()
  260. end
  261. end
  262.  
  263. function Bb_chat:OnClose(wndHandle, wndControl)
  264. self.wndChatOptions:Close()
  265. end
  266.  
  267. function Bb_chat:OnLoad()
  268. self.xmlDoc = XmlDoc.CreateFromFile("Bb_chat.xml")
  269. self.xmlDoc:RegisterCallback("OnDocumentReady", self)
  270. self.tRecent = {}
  271. end
  272.  
  273. function Bb_chat:OnDocumentReady()
  274. if self.xmlDoc == nil then
  275. return
  276. end
  277.  
  278. Apollo.RegisterEventHandler("WindowManagementUpdate", "OnWindowManagementUpdate", self)
  279.  
  280. Apollo.RegisterEventHandler("ChatMessage", "OnChatMessage", self)
  281. Apollo.RegisterEventHandler("ChatFlag", "OnChatFlag", self)
  282. Apollo.RegisterEventHandler("ChatZone", "OnChatZone", self)
  283. Apollo.RegisterEventHandler("ChatResult", "OnChatResult", self)
  284. Apollo.RegisterEventHandler("ChatTellFailed", "OnChatTellFailed", self)
  285. Apollo.RegisterEventHandler("ChatAccountTellFailed", "OnChatAccountTellFailed", self)
  286. Apollo.RegisterEventHandler("AccountSupportTicketResult", "OnAccountSupportTicketResult", self)
  287. Apollo.RegisterEventHandler("ChatJoin", "OnChatJoin", self)
  288. Apollo.RegisterEventHandler("ChatLeave", "OnChatLeave", self)
  289. Apollo.RegisterEventHandler("ChatList", "OnChatList", self)
  290. Apollo.RegisterEventHandler("ChatAction", "OnChatAction", self)
  291. Apollo.RegisterEventHandler("ChatJoinResult", "OnChatJoinResult", self)
  292. Apollo.RegisterEventHandler("CombatLogModifying", "OnCombatLogModifying", self) -- duplicated in combat log too
  293. Apollo.RegisterEventHandler("CombatLogDatacube", "OnCombatLogDatacube", self)
  294. Apollo.RegisterEventHandler("ItemSentToCrate", "OnItemSentToCrate", self)
  295. Apollo.RegisterEventHandler("HarvestItemsSentToOwner", "OnHarvestItemsSentToOwner", self)
  296. Apollo.RegisterEventHandler("LuaChatLogMessage", "OnLuaChatLogMessage", self)
  297. Apollo.RegisterEventHandler("PlayedTime", "OnPlayedtime", self)
  298. Apollo.RegisterEventHandler("ChatReply", "OnChatReply", self)
  299. Apollo.RegisterEventHandler("ChannelUpdate_Loot", "OnChannelUpdate_Loot", self)
  300. Apollo.RegisterEventHandler("ChannelUpdate_Crafting", "OnChannelUpdate_Crafting", self)
  301. Apollo.RegisterEventHandler("ChannelUpdate_Progress", "OnChannelUpdate_Progress", self)
  302. Apollo.RegisterEventHandler("GenericEvent_LinkItemToChat", "OnGenericEvent_LinkItemToChat", self)
  303.  
  304. Apollo.RegisterEventHandler("TradeSkillSigilResult", "OnTradeSkillSigilResult", self)
  305. Apollo.RegisterEventHandler("GenericEvent_LootChannelMessage", "OnGenericEvent_LootChannelMessage", self)
  306. Apollo.RegisterEventHandler("GenericEvent_SystemChannelMessage", "OnGenericEvent_SystemChannelMessage", self)
  307. Apollo.RegisterEventHandler("Event_EngageWhisper", "OnEvent_EngageWhisper", self)
  308. Apollo.RegisterEventHandler("GenericEvent_QuestLink", "OnGenericEvent_QuestLink", self)
  309. Apollo.RegisterEventHandler("GenericEvent_ArchiveArticleLink", "OnGenericEvent_ArchiveArticleLink", self)
  310. Apollo.RegisterEventHandler("GenericEvent_ChatLogWhisper", "OnGenericEvent_ChatLogWhisper", self)
  311. Apollo.RegisterEventHandler("Event_EngageAccountWhisper", "OnEvent_EngageAccountWhisper", self)
  312. Apollo.RegisterEventHandler("SuggestedMenuResult", "OnSuggestedMenuResult", self)
  313.  
  314. Apollo.RegisterEventHandler("NextFrame", "OnChatLineTimer", self)
  315.  
  316. self.timerFade = ApolloTimer.Create(knFadeTimerfrequency, true, "OnChatLineFadeTimer", self)
  317.  
  318. self.nCurrentTimeMS = GameLib.GetGameTime()
  319. self.nChatIndex = 0
  320.  
  321. self.arChatColor =
  322. {
  323. [ChatSystemLib.ChatChannel_Command] = ApolloColor.new("ChatCommand"),
  324. [ChatSystemLib.ChatChannel_System] = ApolloColor.new("ChatSystem"),
  325. [ChatSystemLib.ChatChannel_Debug] = ApolloColor.new("ChatDebug"),
  326. [ChatSystemLib.ChatChannel_Say] = ApolloColor.new("ChatSay"),
  327. [ChatSystemLib.ChatChannel_Yell] = ApolloColor.new("ChatShout"),
  328. [ChatSystemLib.ChatChannel_Whisper] = ApolloColor.new("ChatWhisper"),
  329. [ChatSystemLib.ChatChannel_Party] = ApolloColor.new("ChatParty"),
  330. [ChatSystemLib.ChatChannel_AnimatedEmote] = ApolloColor.new("ChatEmote"),
  331. [ChatSystemLib.ChatChannel_Zone] = ApolloColor.new("ChatZone"),
  332. [ChatSystemLib.ChatChannel_ZoneGerman] = ApolloColor.new("ChatZone"),
  333. [ChatSystemLib.ChatChannel_ZoneFrench] = ApolloColor.new("ChatZone"),
  334. [ChatSystemLib.ChatChannel_ZonePvP] = ApolloColor.new("ChatPvP"),
  335. [ChatSystemLib.ChatChannel_Trade] = ApolloColor.new("ChatTrade"),
  336. [ChatSystemLib.ChatChannel_Guild] = ApolloColor.new("ChatGuild"),
  337. [ChatSystemLib.ChatChannel_GuildOfficer] = ApolloColor.new("ChatGuildOfficer"),
  338. [ChatSystemLib.ChatChannel_Society] = ApolloColor.new("ChatCircle2"),
  339. [ChatSystemLib.ChatChannel_Custom] = ApolloColor.new("ChatCustom"),
  340. [ChatSystemLib.ChatChannel_NPCSay] = ApolloColor.new("ChatNPC"),
  341. [ChatSystemLib.ChatChannel_NPCYell] = ApolloColor.new("ChatNPC"),
  342. [ChatSystemLib.ChatChannel_NPCWhisper] = ApolloColor.new("ChatNPC"),
  343. [ChatSystemLib.ChatChannel_Datachron] = ApolloColor.new("ChatNPC"),
  344. [ChatSystemLib.ChatChannel_Combat] = ApolloColor.new("ChatGeneral"),
  345. [ChatSystemLib.ChatChannel_Realm] = ApolloColor.new("ChatSupport"),
  346. [ChatSystemLib.ChatChannel_Loot] = ApolloColor.new("ChatLoot"),
  347. [ChatSystemLib.ChatChannel_Emote] = ApolloColor.new("ChatEmote"),
  348. [ChatSystemLib.ChatChannel_PlayerPath] = ApolloColor.new("ChatGeneral"),
  349. [ChatSystemLib.ChatChannel_Instance] = ApolloColor.new("ChatInstance"),
  350. [ChatSystemLib.ChatChannel_WarParty] = ApolloColor.new("ChatWarParty"),
  351. [ChatSystemLib.ChatChannel_WarPartyOfficer] = ApolloColor.new("ChatWarPartyOfficer"),
  352. [ChatSystemLib.ChatChannel_Nexus] = ApolloColor.new("ChatNexus"),
  353. [ChatSystemLib.ChatChannel_AccountWhisper] = ApolloColor.new("ChatAccountWisper"),
  354. }
  355.  
  356. self.tAllViewedChannels = {}
  357. self.tChatWindows = {}
  358. self.tLinks = {}
  359. self.nNextLinkIndex = 1
  360. self.nMaxChatLines = 256
  361. self.twndItemLinkTooltips = {}
  362.  
  363. self.tEmotes = {}
  364. local tEmotes = ChatSystemLib.GetEmotes()
  365. for idx, strEmote in pairs(tEmotes) do
  366. self.tEmotes[strEmote] = strEmote
  367. end
  368.  
  369. ---------------OPTIONS---------------
  370. self.wndChatOptions = Apollo.LoadForm(self.xmlDoc, "ChatOptionsForm", "FixedHudStratumLow", self)
  371.  
  372. local wndOptionsContainer = self.wndChatOptions:FindChild("TwoOptionsContainer")
  373.  
  374. wndOptionsContainer:FindChild("SaveToLogOn"):SetCheck(Apollo.GetConsoleVariable("chat.saveLog"))
  375. wndOptionsContainer:FindChild("SaveToLogOff"):SetCheck(not Apollo.GetConsoleVariable("chat.saveLog"))
  376. self.wndChatOptions:FindChild("ChatOptionsContent:RoleplayViewToggle_3"):SetCheck(true)
  377.  
  378. if GameLib.GetGameMode() == GameLib.CodeEnumGameMode.China then
  379. local wndOptionsContainer = self.wndChatOptions:FindChild("TwoOptionsContainer")
  380. wndOptionsContainer:FindChild("Profanity"):Show(false)
  381.  
  382. wndOptionsContainer:ArrangeChildrenVert(Window.CodeEnumArrangeOrigin.LeftOrTop)
  383.  
  384. local nHeight = wndOptionsContainer:FindChild("Profanity"):GetHeight()
  385. local nLeft, nTop, nRight, nBottom = self.wndChatOptions:GetAnchorOffsets()
  386. self.wndChatOptions:SetAnchorOffsets(nLeft, nTop, nRight, nBottom - nHeight)
  387. end
  388.  
  389. -- Profanity Filter Option
  390. if self.bProfanityFilter == nil then
  391. self.bProfanityFilter = true
  392. end
  393.  
  394. wndOptionsContainer:FindChild("ProfanityOn"):SetData(true)
  395. wndOptionsContainer:FindChild("ProfanityOff"):SetData(false)
  396. wndOptionsContainer:FindChild("ProfanityOn"):SetCheck(self.bProfanityFilter) -- Default
  397. wndOptionsContainer:FindChild("ProfanityOff"):SetCheck(not self.bProfanityFilter)
  398.  
  399. for idx, channelCurrent in ipairs(ChatSystemLib.GetChannels()) do
  400. local eChannelType = channelCurrent:GetType()
  401. if eChannelType == ChatSystemLib.ChatChannel_Whisper then
  402. self.channelWhisper = channelCurrent
  403. elseif eChannelType == ChatSystemLib.ChatChannel_AccountWhisper then
  404. self.channelAccountWhisper = channelCurrent
  405. elseif eChannelType == ChatSystemLib.ChatChannel_Say then
  406. self.channelSay = channelCurrent
  407. elseif eChannelType == ChatSystemLib.ChatChannel_Loot then
  408. self.channelLoot = channelCurrent
  409. end
  410.  
  411. channelCurrent:SetProfanity(self.bProfanityFilter)
  412. end
  413.  
  414. -- Font Options
  415. self.strFontOption = "CRB_InterfaceMedium_BB"
  416. self.strAlienFontOption = "CRB_AlienMedium"
  417. self.strRPFontOption = "CRB_InterfaceMedium_BB"
  418.  
  419. local wndChatOptionsContent = self.wndChatOptions:FindChild("ChatOptionsContent")
  420. wndChatOptionsContent:FindChild("FontSizeSmall"):SetData({ strNormal = "CRB_InterfaceSmall", strAlien = "CRB_AlienSmall", strRP = "CRB_InterfaceSmall_I" })
  421. wndChatOptionsContent:FindChild("FontSizeMedium"):SetData({ strNormal = "CRB_InterfaceMedium_BB", strAlien = "CRB_AlienMedium", strRP = "CRB_InterfaceMedium_BB" })
  422. wndChatOptionsContent:FindChild("FontSizeLarge"):SetData({ strNormal = "CRB_InterfaceLarge_BB", strAlien = "CRB_AlienLarge", strRP = "CRB_InterfaceLarge_I" })
  423. wndChatOptionsContent:FindChild("FontSizeHuge"):SetData({ strNormal = "CRB_Interface16", strAlien = "CRB_AlienHuge", strRP = "CRB_Interface16_I" })
  424. wndChatOptionsContent:FindChild("FontSizeMedium"):SetCheck(true) -- Default
  425.  
  426. -- Channel Options
  427. local wndOptionsContainer = self.wndChatOptions:FindChild("TwoOptionsContainer")
  428. if self.bShowChannel == nil then
  429. self.bShowChannel = true
  430. end
  431. wndOptionsContainer:FindChild("ChannelShow"):SetData(true)
  432. wndOptionsContainer:FindChild("ChannelShowOff"):SetData(false)
  433. wndOptionsContainer:FindChild("ChannelShow"):SetCheck(self.bShowChannel) -- Default
  434. wndOptionsContainer:FindChild("ChannelShowOff"):SetCheck(not self.bShowChannel)
  435.  
  436. -- Timestamp
  437. if self.bShowTimestamp == nil then
  438. self.bShowTimestamp = true
  439. end
  440. wndOptionsContainer:FindChild("TimestampShow"):SetData(true)
  441. wndOptionsContainer:FindChild("TimestampShowOff"):SetData(false)
  442. wndOptionsContainer:FindChild("TimestampShow"):SetCheck(self.bShowTimestamp) -- Default
  443. wndOptionsContainer:FindChild("TimestampShowOff"):SetData(not self.bShowTimestamp)
  444.  
  445. -- Background
  446. if self.bEnableBGFade == nil then
  447. self.bEnableBGFade = true
  448. end
  449. wndOptionsContainer:FindChild("EnableFadeBtn"):SetData(true)
  450. wndOptionsContainer:FindChild("DisableFadeBtn"):SetData(false)
  451. wndOptionsContainer:FindChild("EnableFadeBtn"):SetCheck(self.bEnableBGFade) -- Default
  452. wndOptionsContainer:FindChild("DisableFadeBtn"):SetCheck(not self.bEnableBGFade)
  453.  
  454. --Chat line format
  455. if self.bEnableChatLineFade == nil then
  456. self.bEnableChatLineFade = true
  457. end
  458. wndOptionsContainer:FindChild("EnableLineFadeBtn"):SetData(true)
  459. wndOptionsContainer:FindChild("DisableLineFadeBtn"):SetData(false)
  460. wndOptionsContainer:FindChild("EnableLineFadeBtn"):SetCheck(self.bEnableBGFade) -- Default
  461. wndOptionsContainer:FindChild("DisableLineFadeBtn"):SetCheck(not self.bEnableBGFade)
  462.  
  463. -- Player Chat Bubbles
  464. self.bEnablePlayerBubbles = Apollo.GetConsoleVariable("unit.playerTextBubbleEnabled") or false
  465. wndOptionsContainer:FindChild("EnablePlayerChatBubblesBtn"):SetData(true)
  466. wndOptionsContainer:FindChild("DisablePlayerChatBubblesBtn"):SetData(false)
  467. wndOptionsContainer:FindChild("EnablePlayerChatBubblesBtn"):SetCheck(self.bEnablePlayerBubbles) -- Default
  468. wndOptionsContainer:FindChild("DisablePlayerChatBubblesBtn"):SetCheck(not self.bEnablePlayerBubbles)
  469.  
  470. -- NPC Chat Bubbles
  471. self.bEnableNPCBubbles = Apollo.GetConsoleVariable("unit.npcTextBubbleEnabled") or false
  472. wndOptionsContainer:FindChild("EnableNPCChatBubblesBtn"):SetData(true)
  473. wndOptionsContainer:FindChild("DisableNPCChatBubblesBtn"):SetData(false)
  474. wndOptionsContainer:FindChild("EnableNPCChatBubblesBtn"):SetCheck(self.bEnableNPCBubbles) -- Default
  475. wndOptionsContainer:FindChild("DisableNPCChatBubblesBtn"):SetCheck(not self.bEnableNPCBubbles)
  476.  
  477.  
  478. if not self.nBGOpacity then
  479. self.nBGOpacity = self.wndChatOptions:FindChild("BGOpacitySlider"):GetValue()
  480. else
  481. self.wndChatOptions:FindChild("BGOpacitySlider"):SetValue(self.nBGOpacity)
  482. end
  483.  
  484. -- Default Channels
  485. self.tCombatChannels = {}
  486. self.tDefaultChannels = {}
  487.  
  488. for idx, channelCurrent in ipairs(ChatSystemLib.GetChannels() or {}) do
  489. local eType = channelCurrent:GetType()
  490. if eType ~= ChatSystemLib.ChatChannel_Combat then
  491. self.tDefaultChannels[channelCurrent:GetUniqueId()] = true
  492. end
  493.  
  494. if eType == ChatSystemLib.ChatChannel_System or eType == ChatSystemLib.ChatChannel_Combat then
  495. self.tCombatChannels[channelCurrent:GetUniqueId()] = true
  496. end
  497. end
  498.  
  499. if not self.tWindow then
  500. local wndChat = self:NewChatWindow(Apollo.GetString("CRB_Chat"), self.tDefaultChannels, false)
  501. local wndCombat = self:NewChatWindow(Apollo.GetString("ChatType_Combat"), self.tCombatChannels, true)
  502. wndChat:AttachTab(wndCombat, false)
  503. end
  504.  
  505. self.tChatQueue = Queue:new()
  506.  
  507. if not self.eRoleplayOption then
  508. self.eRoleplayOption = 3 -- by default, no RP shown
  509. end
  510. wndChatOptionsContent:SetRadioSel("RoleplayViewToggle", self.eRoleplayOption)
  511. self.tLastWhisperer = nil -- last person to whisper to you
  512.  
  513. -------------------------------------OnRestoreSection-------------------------------------
  514. if self.nFontSize ~= nil then
  515. local strFontControlName = "FontSizeMedium"
  516.  
  517. local wndChatOptionsContent = self.wndChatOptions:FindChild("ChatOptionsContent")
  518.  
  519. wndChatOptionsContent:FindChild("FontSizeSmall"):SetCheck(self.nFontSize == 1)
  520. wndChatOptionsContent:FindChild("FontSizeMedium"):SetCheck(self.nFontSize == 2)
  521. wndChatOptionsContent:FindChild("FontSizeLarge"):SetCheck(self.nFontSize == 3)
  522. wndChatOptionsContent:FindChild("FontSizeHuge"):SetCheck(self.nFontSize == 4)
  523.  
  524. if self.nFontSize == 1 then
  525. strFontControlName = "FontSizeSmall"
  526. elseif self.nFontSize == 2 then
  527. strFontControlName = "FontSizeMedium"
  528. elseif self.nFontSize == 3 then
  529. strFontControlName = "FontSizeLarge"
  530. elseif self.nFontSize == 4 then
  531. strFontControlName = "FontSizeHuge"
  532. end
  533.  
  534. local wndFontControl = self.wndChatOptions:FindChild("ChatOptionsContent:" .. strFontControlName)
  535. self:OnFontSizeOption(wndFontControl, wndFontControl)
  536. end
  537.  
  538. local arWindowGroupMap = {}
  539. for key, tWindowInfo in ipairs(self.tWindow or {}) do
  540. if self.tChatWindows[key] == nil then
  541. local bCombatLog = false
  542.  
  543. if tWindowInfo.tChatData.bCombatLog ~= nil then
  544. bCombatLog = tWindowInfo.tChatData.bCombatLog
  545. end
  546.  
  547. self:NewChatWindow(tWindowInfo.strTitle, tWindowInfo.tChatData.tViewedChannels or self.tDefaultChannels, tWindowInfo.tChatData.bCombatLog)
  548. end
  549.  
  550. local wndChat = self.tChatWindows[key]
  551. if tWindowInfo.tStrings ~= nil then
  552. for idx, strHistory in pairs(tWindowInfo.tStrings) do
  553. wndChat:FindChild("Input"):AddHistoryString(strHistory)
  554. end
  555. end
  556.  
  557. if tWindowInfo.strTitle ~= nil then
  558. if tWindowInfo.strTitle == "Chat" then
  559. tWindowInfo.strTitle = Apollo.GetString("CRB_Chat")
  560. elseif tWindowInfo.strTitle == "Combat" then
  561. tWindowInfo.strTitle = Apollo.GetString("ChatType_Combat")
  562. else
  563. wndChat:SetText(tWindowInfo.strTitle)
  564. end
  565. end
  566.  
  567. if tWindowInfo.tWindowLocation then
  568. wndChat:Detach()
  569. end
  570.  
  571. if self.bEnableNCFade ~= nil and self.bEnableBGFade ~= nil then
  572. wndChat:SetStyle("AutoFadeNC", self.bEnableNCFade)
  573. if self.bEnableNCFade then wndChat:SetNCOpacity(1) end
  574.  
  575. wndChat:SetStyle("AutoFadeBG", self.bEnableBGFade)
  576. if self.bEnableBGFade then wndChat:SetBGOpacity(1) end
  577. end
  578.  
  579. if self.nBGOpacity ~= nil then
  580. wndChat:FindChild("BGArt"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  581. wndChat:FindChild("BGArt_SidePanel"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  582. wndChat:FindChild("BGArt_ResizeHandle"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  583. end
  584.  
  585. local nMatchingTabGroup = 0
  586. for idx, wndGroup in pairs(arWindowGroupMap) do
  587. if idx == tWindowInfo.nTabGroup then
  588. nMatchingTabGroup = idx
  589. break
  590. end
  591. end
  592.  
  593. if nMatchingTabGroup == 0 then
  594. nMatchingTabGroup = tWindowInfo.nTabGroup
  595. arWindowGroupMap[tWindowInfo.nTabGroup] = wndChat
  596. else
  597. arWindowGroupMap[tWindowInfo.nTabGroup]:AttachTab(wndChat)
  598. end
  599. end
  600.  
  601. if self.wndChatOptions then
  602. local wndOptionsContainer = self.wndChatOptions:FindChild("TwoOptionsContainer")
  603. wndOptionsContainer:FindChild("EnableLineFadeBtn"):SetCheck(self.bEnableNPCBubbles)
  604. wndOptionsContainer:FindChild("DisableLineFadeBtn"):SetCheck(not self.bEnableNPCBubbles)
  605. wndOptionsContainer:FindChild("EnableFadeBtn"):SetCheck(self.bEnableBGFade)
  606. wndOptionsContainer:FindChild("DisableFadeBtn"):SetCheck(not self.bEnableBGFade)
  607. self.wndChatOptions:FindChild("BGOpacitySlider"):SetValue(self.nBGOpacity)
  608. wndOptionsContainer:FindChild("ChannelShow"):SetCheck(self.bShowChannel)
  609. wndOptionsContainer:FindChild("ChannelShowOff"):SetCheck(not self.bShowChannel)
  610. wndOptionsContainer:FindChild("TimestampShow"):SetCheck(self.bShowTimestamp)
  611. wndOptionsContainer:FindChild("TimestampShowOff"):SetCheck(not self.bShowTimestamp)
  612. wndOptionsContainer:FindChild("ProfanityOn"):SetCheck(self.bProfanityFilter)
  613. wndOptionsContainer:FindChild("ProfanityOff"):SetCheck(not self.bProfanityFilter)
  614. Apollo.SetConsoleVariable("chat.filter", self.bProfanityFilter)
  615.  
  616. for idx, channelCurrent in ipairs(ChatSystemLib.GetChannels() or {}) do
  617. channelCurrent:SetProfanity(self.bProfanityFilter)
  618. end
  619. end
  620.  
  621. Apollo.RegisterEventHandler("WindowManagementReady", "OnWindowManagementReady", self)
  622. self:OnWindowManagementReady()
  623. end
  624.  
  625. function Bb_chat:OnWindowManagementUpdate(tSettings)
  626. --OnWindowManagementUpdate will fire WHENEVER the window moves and when reset button is pressed.
  627. --The time we care about is when the window is NOT moving, which is when the reset button is pressed.
  628. if not tSettings or tSettings.bHasMoved then
  629. return
  630. end
  631.  
  632. for key, wndChat in pairs(self.tChatWindows) do
  633. --the "name" of the chat/combat tabs are the text on the window, tSettings.strName is the tab to reset.
  634. if wndChat:GetText() == tSettings.strName and #self.tChatWindows > 1 then
  635. --make sure not to attach window to itself, and make sure that index is atleast 1
  636. local nIndexToAttach = (key % #self.tChatWindows) + 1
  637. self.tChatWindows[nIndexToAttach]:AttachTab(wndChat, false)
  638. break
  639. end
  640. end
  641. end
  642.  
  643. function Bb_chat:OnWindowManagementReady()
  644. for key, wndChat in pairs(self.tChatWindows) do
  645. Event_FireGenericEvent("WindowManagementRegister", {wnd = wndChat, strName = wndChat:GetText(), bIsTabWindow = true})
  646. Event_FireGenericEvent("WindowManagementAdd", {wnd = wndChat, strName = wndChat:GetText(), bIsTabWindow = true})
  647. end
  648.  
  649. if self.wndChatOptions and self.wndChatOptions:FindChild("BGHeaderText") then
  650. Event_FireGenericEvent("WindowManagementRegister", {wnd = self.wndChatOptions, strName = self.wndChatOptions:FindChild("BGHeaderText"):GetText(), nSaveVersion=6})
  651. Event_FireGenericEvent("WindowManagementAdd", {wnd = self.wndChatOptions, strName = self.wndChatOptions:FindChild("BGHeaderText"):GetText(), nSaveVersion=6})
  652. end
  653. end
  654.  
  655. function Bb_chat:NewChatWindow(strTitle, tViewedChannels, bCombatLog, channelCurrent)
  656. local wndChatWindow = Apollo.LoadForm(self.xmlDoc, "ChatWindow", "FixedHudStratumLow", self)
  657. Event_FireGenericEvent("WindowManagementRegisterd", {wnd = wndChatWindow, strName = strTitle, bIsTabWindow = true})
  658. Event_FireGenericEvent("WindowManagementAdd", {wnd = wndChatWindow, strName = strTitle, bIsTabWindow = true})
  659.  
  660. wndChatWindow:SetSizingMinimum(240, 240)
  661. wndChatWindow:SetStyle("AutoFadeNC", self.bEnableBGFade)
  662. wndChatWindow:SetStyle("AutoFadeBG", self.bEnableBGFade)
  663. wndChatWindow:FindChild("BGArt"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  664. wndChatWindow:FindChild("BGArt_SidePanel"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  665. wndChatWindow:FindChild("BGArt_ResizeHandle"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  666. wndChatWindow:SetText(strTitle)
  667. wndChatWindow:Show(true)
  668. wndChatWindow:FindChild("InputTypeBtn"):AttachWindow(wndChatWindow:FindChild("InputWindow"))
  669. wndChatWindow:FindChild("EmoteBtn"):AttachWindow(wndChatWindow:FindChild("EmoteMenu"))
  670. wndChatWindow:FindChild("Options"):AttachWindow(wndChatWindow:FindChild("OptionsSubForm"))
  671. wndChatWindow:FindChild("OptionsSubForm"):SetData(wndChatWindow)
  672. --Store the initial input window size
  673. self.nInputMenuLeft, self.nInputMenuTop, self.nInputMenuRight, self.nInputMenuBottom = wndChatWindow:FindChild("InputWindow"):GetAnchorOffsets()
  674.  
  675. local tChatData = {}
  676. tChatData.wndForm = wndChatWindow
  677. tChatData.tViewedChannels = {}
  678.  
  679. tChatData.tMessageQueue = Queue:new()
  680. tChatData.tChildren = Queue:new()
  681.  
  682. local wndChatChild = wndChatWindow:FindChild("Chat")
  683. for idx = 1, self.nMaxChatLines do
  684. local wndChatLine = Apollo.LoadForm(self.xmlDoc, "ChatLine", wndChatChild, self)
  685. wndChatLine:SetData({ ["nLine"]=idx, ["nAddedTime"]=knTimeToFade, ["bFading"]=false })
  686. wndChatLine:Show(false)
  687. tChatData.tChildren:Push(wndChatLine)
  688. end
  689. tChatData.nNextIndex = self.nMaxChatLines + 1
  690.  
  691. local tChannels = bCombatLog and self.tCombatChannels or tViewedChannels
  692. tChatData.wndForm:FindChild("BGArt_ChatBackerIcon"):Show(bCombatLog)
  693.  
  694. for key, value in pairs(tChannels) do
  695. tChatData.tViewedChannels[key] = value
  696. end
  697.  
  698. tChatData.bCombatLog = bCombatLog
  699. wndChatWindow:SetData(tChatData)
  700.  
  701. if not bCombatLog then
  702. for key, value in pairs(tViewedChannels) do
  703. if value then
  704. self:HelperAddChannelToAll(key)
  705. end
  706. end
  707. end
  708.  
  709. tChatData.channelCurrent = channelCurrent or self:HelperFindAViewedChannel()
  710.  
  711. local wndInput = wndChatWindow:FindChild("Input")
  712. if tChatData.channelCurrent then
  713. tChatData.crText = self.arChatColor[tChatData.channelCurrent:GetType()]
  714. wndInput:SetPrompt(tChatData.channelCurrent:GetCommand())
  715. wndInput:SetPromptColor(tChatData.crText)
  716. else
  717. wndInput:SetPrompt("X")
  718. wndInput:SetPromptColor(kcrInvalidColor)
  719. end
  720.  
  721. tChatData.wndOptions = tChatData.wndForm:FindChild("OptionsSubForm")
  722. tChatData.wndOptions:Show(false)
  723.  
  724. if #self.tChatWindows >= 1 then
  725. wndChatWindow:FindChild("CloseBtn"):Show(true)
  726. else
  727. wndChatWindow:FindChild("CloseBtn"):Show(false)
  728. end
  729.  
  730. table.insert(self.tChatWindows, wndChatWindow)
  731.  
  732. local nWindowCount = #self.tChatWindows
  733. if not self.tChatWindows[1]:FindChild("CloseBtn"):IsShown() and nWindowCount > 1 then
  734. self.tChatWindows[1]:FindChild("CloseBtn"):Show(true)
  735. end
  736.  
  737. return wndChatWindow
  738. end
  739.  
  740. function Bb_chat:OnLuaChatLogMessage(strArgMessage, tArgFlags)
  741. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Debug, strArgMessage, "")
  742. end
  743.  
  744. -----------------------------------------------------------------------------------------------
  745. -- ChannelUpdates
  746. -----------------------------------------------------------------------------------------------
  747. function Bb_chat:OnChannelUpdate_Loot(eType, tEventArgs)
  748. local strResult = nil
  749.  
  750. if eType == GameLib.ChannelUpdateLootType.Currency and tEventArgs.monNew then
  751.  
  752. if tEventArgs.monNew:GetAccountCurrencyType() == AccountItemLib.CodeEnumAccountCurrency.Omnibits and tOmniBitInfo then
  753. local tOmniBitInfo = GameLib.GetOmnibitsBonusInfo()
  754. if tOmniBitInfo then
  755. strResult = String_GetWeaselString(Apollo.GetString("ChatLog_OmniBits_Gained"), tEventArgs.nOmnibitsGained, tEventArgs.nBonusAmount, tOmniBitInfo.nWeeklyBonusEarned, tOmniBitInfo.nWeeklyBonusTotal)
  756. else
  757. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_LootReceived"), tEventArgs.monNew:GetMoneyString())
  758. end
  759. else
  760. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_LootReceived"), tEventArgs.monNew:GetMoneyString())
  761. end
  762.  
  763. elseif eType == GameLib.ChannelUpdateLootType.Item and tEventArgs.itemNew then
  764.  
  765. local strItem = tEventArgs.itemNew:GetChatLinkString()
  766. if tEventArgs.nCount > 1 then
  767. strItem = String_GetWeaselString(Apollo.GetString("CombatLog_MultiItem"), tEventArgs.nCount, strItem)
  768. end
  769. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_LootReceived"), strItem)
  770.  
  771. elseif eType == GameLib.ChannelUpdateLootType.ItemDestroy and tEventArgs.itemDestroyed then
  772.  
  773. strResult = String_GetWeaselString(Apollo.GetString("ChatLog_DestroyItem"), tEventArgs.itemDestroyed:GetChatLinkString())
  774.  
  775. end
  776.  
  777. if strResult ~= nil then
  778. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Loot, strResult, "")
  779. end
  780. end
  781.  
  782. function Bb_chat:OnChannelUpdate_Crafting(eType, tEventArgs)
  783. local strResult = nil
  784.  
  785. if eType == GameLib.ChannelUpdateCraftingType.Item and tEventArgs.itemNew then
  786. strResult = String_GetWeaselString(Apollo.GetString("ChatLog_CraftItem"), tEventArgs.itemNew:GetChatLinkString())
  787. end
  788.  
  789. if strResult ~= nil then
  790. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Loot, strResult, "")
  791. end
  792. end
  793.  
  794. function Bb_chat:OnChannelUpdate_Progress(eType, tEventArgs)
  795. local strResult = nil
  796.  
  797. if eType == GameLib.ChannelUpdateProgressType.RewardPoints and tEventArgs.rtCurr then
  798. if tEventArgs.rtCurr:GetType() == RewardTrackLib.CodeEnumRewardTrackType.Challenge then
  799. strResult = String_GetWeaselString(Apollo.GetString("ChatLog_Progress_Challenge"), tEventArgs.rtCurr:GetName(), tEventArgs.nGain)
  800. end
  801. elseif eType == GameLib.ChannelUpdateProgressType.Experience then
  802. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_XPGain"), tEventArgs.nGain)
  803. elseif eType == GameLib.ChannelUpdateProgressType.RestExperience then
  804. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_RestXPGain"), tEventArgs.nGain)
  805. elseif eType == GameLib.ChannelUpdateProgressType.ElderPoints then
  806. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_ElderPointsGained"), tEventArgs.nGain)
  807. elseif eType == GameLib.ChannelUpdateProgressType.RestElderPoints then
  808. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_RestEPGain"), tEventArgs.nGain)
  809. elseif eType == GameLib.ChannelUpdateProgressType.SignatureExperience then
  810. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_SignatureXPGain"), tEventArgs.nGain)
  811. elseif eType == GameLib.ChannelUpdateProgressType.SignatureElderPoints then
  812. strResult = String_GetWeaselString(Apollo.GetString("CombatLog_SignatureEPGain"), tEventArgs.nGain)
  813. end
  814.  
  815. if strResult ~= nil then
  816. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Loot, strResult, "")
  817. end
  818. end
  819.  
  820. -----------------------------------------------------------------------------------------------
  821. -- Duplicated in Combat Log
  822. -----------------------------------------------------------------------------------------------
  823.  
  824. function Bb_chat:OnCombatLogDatacube(tEventArgs)
  825. local strResult = ktDatacubeTypeStrings[tEventArgs.eDatacubeType]
  826. if tEventArgs.eDatacubeType == DatacubeLib.DatacubeType_Journal and tEventArgs.bHasPieces then
  827. strResult = Apollo.GetString("ChatLog_MultiJournal")
  828. end
  829. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Loot, strResult, "")
  830. end
  831.  
  832. function Bb_chat:OnCombatLogModifying(tEventArgs)
  833. if tEventArgs.itemHost == nil or tEventArgs.itemAdded == nil or tEventArgs.itemRemoved == nil then
  834. return
  835. end
  836.  
  837. local strResult = String_GetWeaselString(Apollo.GetString("ChatLog_ModItem"), tEventArgs.itemHost:GetChatLinkString(), tEventArgs.itemAdded:GetChatLinkString(), tEventArgs.itemRemoved:GetChatLinkString())
  838. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Loot, strResult, "")
  839. end
  840.  
  841. -----------------------------------------------------------------------------------------------
  842.  
  843. function Bb_chat:OnChatMessage(channelCurrent, tMessage)
  844. -- tMessage has bAutoResponse, bGM, bSelf, strSender, strRealmName, nPresenceState, arMessageSegments, unitSource, bShowChatBubble, bCrossFaction, nReportId
  845.  
  846. -- arMessageSegments is an array of tables. Each table representsa part of the message + the formatting for that segment.
  847. -- This allows us to signal font (alien text for example) changes mid stream.
  848. -- local example = arMessageSegments[1]
  849. -- example.strText is the text
  850. -- example.bAlien == true if alien font set
  851. -- example.bRolePlay == true if this is rolePlay Text. RolePlay text should only show up for people in roleplay mode, and non roleplay text should only show up for people outside it.
  852.  
  853. -- to use: {#}toggles alien on {*}toggles rp on. Alien is still on {!}resets all format codes.
  854.  
  855.  
  856. -- There will be a lot of chat messages, particularly for combat log. If you make your own chat log module, you will want to batch
  857. -- up several at a time and only process lines you expect to see.
  858.  
  859. local tQueuedMessage = {}
  860. tQueuedMessage.tMessage = tMessage
  861. tQueuedMessage.eChannelType = channelCurrent:GetType()
  862. tQueuedMessage.strChannelName = channelCurrent:GetName()
  863. tQueuedMessage.strChannelCommand = channelCurrent:GetCommand()
  864. tQueuedMessage.idChannel = channelCurrent:GetUniqueId()
  865.  
  866. -- handle unit bubble if needed.
  867. if tQueuedMessage.tMessage.unitSource and tQueuedMessage.tMessage.bShowChatBubble then
  868. self:HelperGenerateChatMessage(tQueuedMessage)
  869. if tQueuedMessage.xmlBubble then
  870. tMessage.unitSource:AddTextBubble(tQueuedMessage.xmlBubble)
  871. end
  872. end
  873.  
  874. self:HelperQueueMessage(tQueuedMessage)
  875. end
  876.  
  877. function Bb_chat:HelperQueueMessage(tQueuedMessage)
  878. -- queue message on windows.
  879. for key, wndChat in pairs(self.tChatWindows) do
  880. if wndChat:GetData().tViewedChannels[tQueuedMessage.idChannel] then -- check flags for filtering
  881. self.bQueuedMessages = true
  882. wndChat:GetData().tMessageQueue:Push(tQueuedMessage)
  883. end
  884. end
  885. end
  886.  
  887. function Bb_chat:HelperCheckForEmptyString(strText)
  888. local strFirstChar
  889. local bHasText = false
  890.  
  891. strFirstChar = string.find(strText, "%S")
  892.  
  893. bHasText = strFirstChar ~= nil and string.len(strFirstChar) > 0
  894. return bHasText
  895. end
  896.  
  897. function Bb_chat:OnChatFlag( channelUpdated )
  898. -- example
  899. -- local bIsOwner = channelUpdated:IsOwner()
  900. -- local bIsModerator = channelUpdated:IsModerator()
  901. -- local bIsMuted = channelUpdated:IsMuted()
  902. end
  903.  
  904. function Bb_chat:OnChatZone( description )
  905. -- TODO
  906. --local zoneName = description
  907. end
  908.  
  909.  
  910. function Bb_chat:OnChatResult(channelSender, eResult)
  911. local strMessage = Apollo.GetString("CombatFloaterType_Error")
  912. local strChanName = ""
  913.  
  914. if channelSender == nil or channelSender:GetName() == "" then
  915. strChanName = Apollo.GetString("Unknown_Unit")
  916. else
  917. strChanName = channelSender:GetName()
  918. end
  919.  
  920. if ktChatResultOutputStrings[eResult] then
  921. if eResult == ChatSystemLib.ChatChannelResult_NotInGroup and GroupLib.InGroup() and GroupLib.InInstance() then
  922. strMessage = Apollo.GetString("ChatLog_UseInstanceChannel")
  923. else
  924. strMessage = String_GetWeaselString(ktChatResultOutputStrings[eResult], strMessage, strChanName)
  925. end
  926. else
  927. strMessage = String_GetWeaselString(Apollo.GetString("ChatLog_UndefinedMessage"), strMessage, eResult, strChanName)
  928. end
  929.  
  930. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  931. end
  932.  
  933. function Bb_chat:OnChatTellFailed( channel, strCharacterTo )
  934. strMessage = String_GetWeaselString(Apollo.GetString("CRB_Whisper_Error"), Apollo.GetString("CombatFloaterType_Error"), strCharacterTo, Apollo.GetString("CRB_Whisper_Error_Reason"))
  935. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  936. self:RemoveFromRecent(strCharacterTo)
  937. end
  938.  
  939. function Bb_chat:OnChatAccountTellFailed( channel, strCharacterTo )
  940. strMessage = String_GetWeaselString(Apollo.GetString("CRB_Whisper_Error"), Apollo.GetString("CombatFloaterType_Error"), strCharacterTo, Apollo.GetString("CRB_Account_Whisper_Error_Reason"))
  941. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  942. self:RemoveFromRecent(strCharacterTo)
  943. end
  944.  
  945. function Bb_chat:OnAccountSupportTicketResult( channelSource, bSuccess )
  946. if( bSuccess ) then
  947. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_System, Apollo.GetString("PlayerTicket_TicketSent"), "")
  948. else
  949. ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_System, Apollo.GetString("PlayerTicket_TicketFailed"), "")
  950. end
  951. end
  952.  
  953. function Bb_chat:OnChatJoin( channelJoined )
  954. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, String_GetWeaselString(Apollo.GetString("ChatLog_JoinChannel"), channelJoined:GetName()), "" );
  955.  
  956. -- ChatJoin event is called both on startup and on join.
  957.  
  958. for idx, wndChatWindow in pairs(self.tChatWindows) do
  959. wndChatWindow:FindChild("InputWindow"):Close()
  960.  
  961. -- explicit check for nil, it means we have have no saved setting for this channel displaying in this window.
  962.  
  963. local tChatData = wndChatWindow:GetData()
  964. if not tChatData.bCombatLog and tChatData.tViewedChannels[channelJoined:GetUniqueId()] == nil then
  965. self:HelperAddChannelToAll(channelJoined:GetUniqueId())
  966. tChatData.tViewedChannels[channelJoined:GetUniqueId()] = true
  967. end
  968. end
  969. end
  970.  
  971. function Bb_chat:OnChatLeave( channelLeft, bKicked, bBanned )
  972. if( bBanned ) then
  973. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, String_GetWeaselString(Apollo.GetString("ChatLog_BannedFromChannel"), channelLeft:GetName()), "" );
  974. elseif( bKicked ) then
  975. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, String_GetWeaselString(Apollo.GetString("ChatLog_KickedFromChannel"), channelLeft:GetName()), "" );
  976. else
  977. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, String_GetWeaselString(Apollo.GetString("ChatLog_LeftChannel"), channelLeft:GetName()), "" );
  978. end
  979.  
  980. for idx, wndChatWindow in pairs(self.tChatWindows) do
  981. local tChatData = wndChatWindow:GetData()
  982.  
  983. if tChatData.channelCurrent == channelLeft then
  984. tChatData.channelCurrent = self.channelSay
  985. tChatData.crText = self.arChatColor[ ChatSystemLib.ChatChannel_Say ]
  986.  
  987. local wndInput = wndChatWindow:FindChild("Input")
  988. wndInput:SetPrompt(tChatData.channelCurrent:GetCommand())
  989. wndInput:SetPromptColor(tChatData.crText)
  990. end
  991. end
  992. end
  993.  
  994. function Bb_chat:OnChatList( channelSource )
  995. local tMembers = channelSource:GetMembers()
  996. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, Apollo.GetString("ChatLog_MemberList"), "" );
  997. for idx = 1,#tMembers do
  998. local strDesc = ""
  999. if tMembers[idx].bIsChannelOwner then
  1000. strDesc = String_GetWeaselString(Apollo.GetString("ChatLog_ChannelOwner"), strDesc)
  1001. end
  1002. if tMembers[idx].bIsModerator then
  1003. strDesc = String_GetWeaselString(Apollo.GetString("ChatLog_ChannelModerator"), strDesc)
  1004. end
  1005. if tMembers[idx].bIsMuted then
  1006. strDesc = String_GetWeaselString(Apollo.GetString("ChatLog_Muted"), strDesc)
  1007. end
  1008.  
  1009. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, tMembers[idx].strMemberName .. strDesc, "" )
  1010. end
  1011. end
  1012.  
  1013. function Bb_chat:OnChatAction( channelSource, eAction, strActor, strActedOn )
  1014. local strMessage = ""
  1015. local strChanName = ""
  1016.  
  1017. if channelSource == nil or channelSource:GetName() == "" then
  1018. strChanName = Apollo.GetString("Unknown_Unit")
  1019. else
  1020. strChanName = channelSource:GetName()
  1021. end
  1022.  
  1023. if ktChatActionOutputStrings[eAction] then
  1024. strMessage = String_GetWeaselString(ktChatActionOutputStrings[eAction], strChanName, strActor, strActedOn)
  1025. else
  1026. strMessage = String_GetWeaselString(Apollo.GetString("ChatLog_UndefinedMessage"), Apollo.GetString("CombatFloaterType_Error"), eAction, strChanName)
  1027. end
  1028.  
  1029. if strMessage then
  1030. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  1031. end
  1032. end
  1033.  
  1034. function Bb_chat:OnChatJoinResult( strChanName, eResult )
  1035. local strMessage = Apollo.GetString("CombatFloaterType_Error")
  1036.  
  1037. if strChanName == nil or strChanName == "" then
  1038. strChanName = Apollo.GetString("Unknown_Unit")
  1039. end
  1040.  
  1041. if ktChatJoinOutputStrings[eResult] then
  1042. strMessage = String_GetWeaselString(ktChatJoinOutputStrings[eResult], strMessage, strChanName)
  1043. else
  1044. strMessage = String_GetWeaselString(Apollo.GetString("ChatLog_UndefinedMessage"), strMessage, eResult, strChanName)
  1045. end
  1046.  
  1047. if strMessage then
  1048. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  1049. end
  1050. end
  1051.  
  1052. function Bb_chat:OnChatLineTimer()
  1053. nCurrentTimeMS = GameLib.GetGameTime()
  1054. local nDeltaTimeMS = nCurrentTimeMS - self.nCurrentTimeMS
  1055. self.nCurrentTimeMS = nCurrentTimeMS
  1056. if nDeltaTimeMS < 0 then
  1057. nDeltaTimeMS = 33
  1058. end
  1059.  
  1060. if self.bQueuedMessages then
  1061. self.bQueuedMessages = false
  1062.  
  1063. for key, wndChat in pairs(self.tChatWindows) do
  1064. if not wndChat:GetData().tMessageQueue:Empty() then
  1065. self:ShowQueuedMessages(wndChat, nDeltaTimeMS)
  1066. self.bQueuedMessages = self.bQueuedMessages or not wndChat:GetData().tMessageQueue:Empty()
  1067. end
  1068. end
  1069. end
  1070. end
  1071.  
  1072. function Bb_chat:ShowQueuedMessages(wndForm, nDeltaTimeMS)
  1073. local tChatData = wndForm:GetData()
  1074. local wndChatList = wndForm:FindChild("Chat")
  1075.  
  1076. local nLineCount = tChatData.tChildren:GetSize()
  1077. -- we only show tChatData.tChildren:GetSize() chat lines at once.
  1078. while tChatData.tMessageQueue:GetSize() > nLineCount do
  1079. tChatData.tMessageQueue:Pop()
  1080. end
  1081.  
  1082. local nMessages = nLineCount * nDeltaTimeMS
  1083. if nMessages < 1 then
  1084. nMessages = 1
  1085. end
  1086.  
  1087. -- grab queued message and put it into oldest chat line window. Move window to bottom. Only do 20 at a time.
  1088. local bPrettyItUp = false
  1089. for iCount = 1, nMessages do
  1090. if tChatData.tMessageQueue:GetSize() == 0 then
  1091. break;
  1092. end
  1093. bPrettyItUp = true
  1094. local tQueuedMessage = tChatData.tMessageQueue:Pop()
  1095. self:HelperGenerateChatMessage(tQueuedMessage)
  1096.  
  1097. if tQueuedMessage.eChannelType == ChatSystemLib.ChatChannel_AccountWhisper then
  1098. self.channelReply = self.channelAccountWhisper
  1099. elseif tQueuedMessage.eChannelType == ChatSystemLib.ChatChannel_Whisper then
  1100. self.channelReply = self.channelWhisper
  1101. end
  1102.  
  1103. local wndChatLine = tChatData.tChildren:Pop()
  1104. wndChatLine:SetData({ ["nLine"]=tChatData.nNextIndex, ["nAddedTime"]=knTimeToFade, ["bFading"]=false })
  1105. wndChatLine:SetOpacity(1, 0)
  1106. wndChatLine:Show(true)
  1107. if tQueuedMessage.strMessage then
  1108. wndChatLine:SetText( tQueuedMessage.strMessage )
  1109. elseif tQueuedMessage.xml then
  1110. wndChatLine:SetDoc( tQueuedMessage.xml )
  1111. end
  1112. wndChatLine:SetHeightToContentHeight()
  1113.  
  1114. tChatData.nNextIndex = tChatData.nNextIndex + 1
  1115. tChatData.tChildren:Push(wndChatLine)
  1116.  
  1117. wndChatList:SendChildToBottom(wndChatLine, true)
  1118. end
  1119.  
  1120. if bPrettyItUp then
  1121. self:PrettyItUp(wndForm)
  1122. end
  1123. end
  1124.  
  1125. function Bb_chat:PrettyItUp(wndForm)
  1126. local wndChatList = wndForm:FindChild("Chat")
  1127. local bAtBottom = false
  1128. local nPos = wndChatList:GetVScrollPos()
  1129.  
  1130. if nPos == wndChatList:GetVScrollRange() then
  1131. bAtBottom = true
  1132. end
  1133.  
  1134. -- arrange children
  1135. wndChatList:ArrangeChildrenVert(Window.CodeEnumArrangeOrigin.LeftOrTop)
  1136.  
  1137. if bAtBottom then
  1138. wndChatList:SetVScrollPos(wndChatList:GetVScrollRange())
  1139. end
  1140. end
  1141.  
  1142. function Bb_chat:OnChatLineFadeTimer()
  1143. for idx, wndChat in pairs(self.tChatWindows) do
  1144. self:RunChatWindowFade(wndChat)
  1145. end
  1146. end
  1147.  
  1148. function Bb_chat:RunChatWindowFade(wndChat)
  1149. local tChatData = wndChat:GetData()
  1150. local wndChatList = wndChat:FindChild("Chat")
  1151. local wndInput = wndChat:FindChild("Input")
  1152. local strInput = wndInput:GetText()
  1153. local bForceOpaque = (wndChatList:GetVScrollPos() ~= wndChatList:GetVScrollRange())
  1154. or (strInput ~= nil and strInput ~= "")
  1155. or wndChat:ContainsMouse()
  1156. or not self.bEnableChatLineFade
  1157.  
  1158. for idx, wndChatLine in pairs(tChatData.tChildren:GetItems()) do
  1159. if wndChatLine:IsShown() then
  1160. local tChatLineData = wndChatLine:GetData()
  1161.  
  1162. if bForceOpaque then
  1163. wndChatLine:SetOpacity(1, 0)
  1164. else
  1165. local nTimeLeft = tChatLineData.nAddedTime - knFadeTimerfrequency
  1166. tChatLineData.nAddedTime = nTimeLeft
  1167. if nTimeLeft <= 0 then
  1168. wndChatLine:SetOpacity(0, 1) --blakbird changed from (0.2, 1) to completely fade out chat lines
  1169. end
  1170. end
  1171.  
  1172. wndChatLine:SetData(tChatLineData)
  1173. end
  1174. end
  1175. end
  1176.  
  1177. function Bb_chat:OnMouseEnter(wndHandler, wndControl, x, y)
  1178. if wndHandler ~= wndControl then
  1179. return
  1180. end
  1181. self:RunChatWindowFade(wndControl)
  1182. end
  1183.  
  1184. function Bb_chat:ChatActionTaken(wndChat)
  1185. local tChatData = wndChat:GetData()
  1186.  
  1187. for idx, wndChatLine in pairs(tChatData.tChildren:GetItems()) do
  1188. if wndChatLine:IsShown() then
  1189. local tChatLineData = wndChatLine:GetData()
  1190. tChatLineData.nAddedTime = math.max(knTimeToFadeAfterAction, tChatLineData.nAddedTime)
  1191. wndChatLine:SetData(tChatLineData)
  1192. end
  1193. end
  1194. end
  1195.  
  1196. function Bb_chat:OnNodeClick(wndHandler, wndControl, strNode, tAttributes, eMouseButton)
  1197. -- can only report players who are not yourself, which matches who we want this menu for.
  1198. if strNode == "Source" and eMouseButton == GameLib.CodeEnumInputMouse.Right and tAttributes.strCharacterName and tAttributes.strCrossFaction then
  1199. local bCross = tAttributes.strCrossFaction == "true"--sending boolean
  1200. local nReportId = nil
  1201. if tAttributes ~= nil and tAttributes.nReportId ~= nil then
  1202. nReportId = tAttributes.nReportId
  1203. end
  1204. local tOptionalData = {nReportId = tAttributes.nReportId, bCrossFaction = bCross}
  1205. Event_FireGenericEvent("GenericEvent_NewContextMenuPlayer", wndHandler, tAttributes.strCharacterName, nil, tOptionalData)
  1206. return true
  1207. end
  1208.  
  1209. if strNode == "Link" then
  1210.  
  1211. -- note, tAttributes.nLinkIndex is a string value, instead of the int we passed in because it was saved
  1212. -- out as xml text then read back in.
  1213. local nIndex = tonumber(tAttributes.strIndex)
  1214.  
  1215. if self.tLinks[nIndex] and
  1216. ( self.tLinks[nIndex].uItem or self.tLinks[nIndex].uQuest or self.tLinks[nIndex].uArchiveArticle or self.tLinks[nIndex].tNavPoint ) then
  1217.  
  1218. if Apollo.IsShiftKeyDown() then
  1219.  
  1220. local wndEdit = self:HelperGetCurrentEditbox()
  1221.  
  1222. -- pump link to the chat line
  1223. if wndEdit then
  1224. self:HelperAppendLink( wndEdit, self.tLinks[nIndex] )
  1225. end
  1226. else
  1227. if self.tLinks[nIndex].uItem then
  1228.  
  1229. local bWindowExists = false
  1230. for idx, wndCur in pairs(self.twndItemLinkTooltips or {}) do
  1231. if wndCur:GetData() == self.tLinks[nIndex].uItem then
  1232. bWindowExists = true
  1233. break
  1234. end
  1235. end
  1236.  
  1237. if bWindowExists == false then
  1238. local wndChatItemToolTip = Apollo.LoadForm("Bb_chat.xml", "TooltipWindow", nil, self)
  1239. wndChatItemToolTip:SetData(self.tLinks[nIndex].uItem)
  1240.  
  1241. table.insert(self.twndItemLinkTooltips, wndChatItemToolTip)
  1242.  
  1243. local itemEquipped = self.tLinks[nIndex].uItem:GetEquippedItemForItemType()
  1244.  
  1245. local wndLink = Tooltip.GetItemTooltipForm(self, wndControl, self.tLinks[nIndex].uItem, {bPermanent = true, wndParent = wndChatItemToolTip, bSelling = false, bNotEquipped = true})
  1246.  
  1247. local nLeftWnd, nTopWnd, nRightWnd, nBottomWnd = wndChatItemToolTip:GetAnchorOffsets()
  1248. local nLeft, nTop, nRight, nBottom = wndLink:GetAnchorOffsets()
  1249.  
  1250. wndChatItemToolTip:SetAnchorOffsets(nLeftWnd, nTopWnd, nLeftWnd + nRight + 15, nBottom + 75)
  1251.  
  1252. if itemEquipped then
  1253. wndChatItemToolTip:SetTooltipDoc(nil)
  1254. Tooltip.GetItemTooltipForm(self, wndChatItemToolTip, itemEquipped, {bPrimary = true, bSelling = false, bNotEquipped = false})
  1255. end
  1256. end
  1257.  
  1258. elseif self.tLinks[nIndex].uQuest then
  1259. Event_FireGenericEvent("ShowQuestLog", wndHandler:GetData()) -- Codex (todo: deprecate this)
  1260. Event_FireGenericEvent("GenericEvent_ShowQuestLog", self.tLinks[nIndex].uQuest)
  1261. elseif self.tLinks[nIndex].uArchiveArticle then
  1262. Event_FireGenericEvent("HudAlert_ToggleLoreWindow")
  1263. Event_FireGenericEvent("GenericEvent_ShowGalacticArchive", self.tLinks[nIndex].uArchiveArticle)
  1264. elseif self.tLinks[nIndex].tNavPoint then
  1265. GameLib.SetNavPoint(self.tLinks[nIndex].tNavPoint.tPosition, self.tLinks[nIndex].tNavPoint.nMapZoneId)
  1266. GameLib.ShowNavPointHintArrow()
  1267. end
  1268. end
  1269. end
  1270. end
  1271.  
  1272. return false
  1273. end
  1274.  
  1275. function Bb_chat:OnCloseItemTooltipWindow(wndHandler, wndControl)
  1276. local wndParent = wndControl:GetParent()
  1277. local itemData = wndParent:GetData()
  1278.  
  1279. for idx, wndCur in pairs(self.twndItemLinkTooltips) do
  1280. if wndCur:GetData() == itemData then
  1281. table.remove(self.twndItemLinkTooltips, idx)
  1282. end
  1283. end
  1284.  
  1285. wndParent:Destroy()
  1286. end
  1287.  
  1288. function Bb_chat:OnEvent_EngageAccountWhisper(strDisplayName, strCharacterName, strRealmName)
  1289. local wndEdit = self:HelperGetCurrentEditbox()
  1290. self.tAccountWhisperContex =
  1291. {
  1292. ["strDisplayName"] = strDisplayName,
  1293. ["strCharacterName"] = strCharacterName,
  1294. ["strRealmName"] = strRealmName,
  1295. }
  1296. local strOutput = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), Apollo.GetString("ChatType_AccountTell"), strDisplayName)
  1297. wndEdit:SetText(strOutput)
  1298. wndEdit:SetFocus()
  1299. wndEdit:SetSel(strOutput:len(), -1)
  1300. self:OnInputChanged(nil, wndEdit, strOutput)
  1301. end
  1302.  
  1303. function Bb_chat:OnEvent_EngageWhisper(strPlayerName)
  1304. local wndEdit = self:HelperGetCurrentEditbox()
  1305.  
  1306. local strOutput = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), Apollo.GetString("ChatType_Tell"), strPlayerName)
  1307. wndEdit:SetText(strOutput)
  1308. wndEdit:SetFocus()
  1309. wndEdit:SetSel(strOutput:len(), -1)
  1310. self:OnInputChanged(nil, wndEdit, strOutput)
  1311. end
  1312.  
  1313. function Bb_chat:OnChatReply()
  1314.  
  1315. local wndParent = nil
  1316. for idx, wndCurr in pairs(self.tChatWindows) do
  1317. if wndCurr and wndCurr:IsValid() then
  1318. wndParent = wndCurr
  1319. break
  1320. end
  1321. end
  1322.  
  1323. if not wndParent then
  1324. return
  1325. end
  1326.  
  1327. if not self.tRecent or not self.tRecent[1] then
  1328. return
  1329. end
  1330.  
  1331. --get the name of the first person on the recent, which will be either a character or account name
  1332. local strTarget = self.tRecent[1].strCharacterName
  1333. local strOutput = ""
  1334. if self.channelReply then
  1335. strOutput = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), self.channelReply:GetAbbreviation(), strTarget)
  1336. end
  1337.  
  1338. local wndEdit = wndParent:FindChild("Input")
  1339. wndEdit:SetText(strOutput)
  1340. wndEdit:SetFocus()
  1341. wndEdit:SetSel(strOutput:len(), -1)
  1342. self:OnInputChanged(nil, wndEdit, strOutput)
  1343. end
  1344.  
  1345. function Bb_chat:OnGenericEvent_ChatLogWhisper(strTarget)
  1346. local wndParent = nil
  1347. for idx, wndCurr in pairs(self.tChatWindows) do
  1348. if wndCurr and wndCurr:IsValid() and wndCurr:GetData() and not wndCurr:GetData().bCombatLog then
  1349. wndParent = wndCurr
  1350. break
  1351. end
  1352. end
  1353.  
  1354. if not wndParent then
  1355. return
  1356. end
  1357.  
  1358. if not strTarget and self.tLastWhisperer and self.tLastWhisperer.strCharacterName then
  1359. strTarget = self.tLastWhisperer.strCharacterName
  1360. end
  1361.  
  1362. local wndEdit = wndParent:FindChild("Input")
  1363. local strOutput = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), Apollo.StringToLower(Apollo.GetString("ChatType_Tell")), strTarget)
  1364. wndEdit:SetText(strOutput)
  1365. wndEdit:SetFocus()
  1366. wndEdit:SetSel(strOutput:len(), -1)
  1367. self:OnInputChanged(nil, wndEdit, strOutput)
  1368. end
  1369.  
  1370. function Bb_chat:OnEmoteCheck(wndHandler, wndControl)
  1371. local wndEmotes = wndControl:GetParent():FindChild("EmoteMenu")
  1372. local wndContainer = wndEmotes:FindChild("EmoteMenuContent")
  1373. local tEmotes = ChatSystemLib.GetEmotes()
  1374.  
  1375. if wndHandler:IsChecked() then
  1376. local nScrollPosition = wndContainer:GetVScrollPos() or 0
  1377. wndContainer:DestroyChildren()
  1378.  
  1379. for idx, strEmote in pairs(tEmotes) do
  1380. if strEmote ~= "" and strEmote ~= nil then
  1381. local wnd = Apollo.LoadForm(self.xmlDoc, "EmoteMenuEntry", wndContainer, self)
  1382. wnd:SetText(String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strEmote))
  1383. wnd:SetData(strEmote)
  1384. end
  1385. end
  1386.  
  1387. wndContainer:ArrangeChildrenVert(Window.CodeEnumArrangeOrigin.LeftOrTop, function(a,b) return a:GetData() < b:GetData() end)
  1388. wndContainer:SetVScrollPos(nScrollPosition)
  1389. end
  1390. wndEmotes:GetParent():FindChild("CloseBtn"):Enable(not wndHandler:IsChecked())
  1391. end
  1392.  
  1393. function Bb_chat:OnEmoteMenuClosed(wndHandler, wndControl)
  1394. local wndParent = wndHandler:GetParent()
  1395. wndParent:FindChild("CloseBtn"):Enable(true)
  1396. wndHandler:Close()
  1397. end
  1398.  
  1399. function Bb_chat:OnEmoteMenuClose(wndHandler, wndControl)
  1400. local wndGrandparent = wndControl:GetParent():GetParent()
  1401. wndGrandparent:FindChild("EmoteBtn"):SetCheck(false)
  1402. wndGrandparent:FindChild("CloseBtn"):Enable(true)
  1403. wndControl:GetParent():Close()
  1404. end
  1405.  
  1406. function Bb_chat:OnEmoteMenuEntry(wndHandler, wndControl)
  1407. local strEmote = wndControl:GetData()
  1408. local wndParent = wndControl:GetParent():GetParent()
  1409. local wndEdit = wndParent:GetParent():FindChild("Input")
  1410. local wndToggle = wndParent:GetParent():FindChild("EmoteBtn")
  1411. local strEntry = String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strEmote)
  1412. wndEdit:SetText(strEntry)
  1413. wndEdit:SetFocus()
  1414. wndEdit:SetSel(strEntry:len(), -1)
  1415. wndParent:Show(false)
  1416. wndToggle:SetCheck(false)
  1417.  
  1418. self:OnInputChanged(nil, wndEdit, strEntry)
  1419. end
  1420.  
  1421. function Bb_chat:HelperLoadSetRules(luaSubclass)
  1422. if not luaSubclass then
  1423. return
  1424. end
  1425.  
  1426. local tRules = {}
  1427. if self.channelWhisper and self.channelAccountWhisper then
  1428. tRules[Apollo.StringToLower(self.channelAccountWhisper:GetCommand())] = {}
  1429. tRules[Apollo.StringToLower(self.channelWhisper:GetCommand())] = {}
  1430. end
  1431.  
  1432. local eNot = luaSubclass:GetEnumNot()
  1433. local eOr = luaSubclass:GetEnumOr()
  1434. local eAnd = luaSubclass:GetEnumAnd()
  1435.  
  1436. local eFriends = luaSubclass:GetEnumFriends()
  1437. local eAccountFriends = luaSubclass:GetEnumAccountFriends()
  1438. local eNeighbors = luaSubclass:GetEnumNeighbors()
  1439. local eGroups = luaSubclass:GetEnumGroups()
  1440. local eRecent = luaSubclass:GetEnumRecent()
  1441.  
  1442. if not eNot or not eOr or not eAnd or not eFriends or not eAccountFriends or not eNeighbors or not eGroups or not eRecent then
  1443. return
  1444. end
  1445.  
  1446. tRules[Apollo.StringToLower(Apollo.GetString("Command_Neighbor_Invite"))] = {eOperator = eNot, arRelationFilters = {eNeighbors}}
  1447. tRules[Apollo.StringToLower(Apollo.GetString("Command_Neighbor_Remove"))] = {arRelationFilters = {eNeighbors}}
  1448. tRules[Apollo.StringToLower(Apollo.GetString("Command_Group_Invite"))] = {eOperator = eNot, arRelationFilters = {eGroups}}
  1449. tRules[Apollo.StringToLower(Apollo.GetString("Command_Group_Join"))] = {eOperator = eNot, arRelationFilters = {eGroups}}
  1450. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Friend"))] = {eOperator = eNot, arRelationFilters = {eFriends}}
  1451. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Unfriend"))] = {arRelationFilters = {eFriends}}
  1452. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_FriendAccount"))] = {eOperator = eNot, arRelationFilters = {eAccountFriends}}
  1453. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_UnfriendAccount"))] = {arRelationFilters = {eAccountFriends}}
  1454. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Ignore"))] = {eOperator = eAnd, arRelationFilters = {eRecent, {eOperator = eNot, arRelationFilters = {eAccountFriends}}}}
  1455. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Rival"))] = {}--May want to come back and keep track of this also
  1456. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Unrival"))] = {}--May want to come back and keep track of this also
  1457. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Accept"))] = {eOperator = eNot, arRelationFilters = {eFriends}}
  1458. tRules[Apollo.StringToLower(Apollo.GetString("Command_Friendship_Decline"))] = {eOperator = eNot, arRelationFilters = {eFriends}}
  1459.  
  1460. return tRules
  1461. end
  1462.  
  1463. function Bb_chat:OnSuggestedMenuResult(tInfo, nTextBoxId)
  1464. local wndEdit = self:HelperGetCurrentEditbox()
  1465. if not wndEdit or nTextBoxId ~= wndEdit:GetId() or not tInfo then
  1466. return
  1467. end
  1468.  
  1469. --this section will auto correct the channel if it was a communication command, otherwise use original.
  1470. local tInput = ChatSystemLib.SplitInput(wndEdit:GetText())
  1471. local strCommand = ""
  1472. local strExtraSpace = " "
  1473. local eChannelType = ChatSystemLib.ChatChannel_Whisper
  1474. if tInput and tInput.channelCommand and tInput.channelCommand ~= self.channelAccountWhisper and tInput.channelCommand ~= self.channelWhisper then
  1475. strCommand = tInput.strCommand
  1476. eChannelType = tInput.channelCommand:GetType()
  1477. bExtraSpace = false
  1478. strExtraSpace = ""
  1479. elseif tInfo.bAccountFriends then
  1480. strCommand = self.channelAccountWhisper:GetAbbreviation()
  1481. eChannelType = ChatSystemLib.ChatChannel_AccountWhisper
  1482. else
  1483. strCommand = self.channelWhisper:GetAbbreviation()
  1484. eChannelType = ChatSystemLib.ChatChannel_Whisper
  1485. end
  1486.  
  1487. local strOutput = "/"..strCommand.." "..tInfo.strCharacterName..strExtraSpace
  1488. wndEdit:SetText(strOutput)
  1489. wndEdit:SetTextColor(self.arChatColor[eChannelType] or ApolloColor.new("white"))
  1490. wndEdit:SetFocus()
  1491. wndEdit:SetSel(strOutput:len(), -1)
  1492. end
  1493.  
  1494. function Bb_chat:OnCloseChatWindow(wndHandler, wndControl)
  1495. local wndForm = wndControl:GetParent()
  1496. local tChatData = wndForm:GetData()
  1497.  
  1498. if tChatData ~= nil then -- remove this window's channels from the total list
  1499. for idx, value in pairs(tChatData.tViewedChannels) do
  1500. if tChatData.tViewedChannels[idx] then
  1501. self:HelperRemoveChannelFromAll(idx)
  1502. end
  1503. end
  1504. end
  1505.  
  1506. for idx = 1,#self.tChatWindows do
  1507. if self.tChatWindows[idx] == wndForm then
  1508. table.remove(self.tChatWindows, idx)
  1509. end
  1510. if #self.tChatWindows == 1 then
  1511. self.tChatWindows[1]:FindChild("CloseBtn"):Show(false)
  1512. end
  1513. end
  1514.  
  1515. wndForm:Detach()
  1516. wndForm:Destroy()
  1517. end
  1518.  
  1519. function Bb_chat:OnChatInputReturn(wndHandler, wndControl, strText)
  1520. if wndControl:GetName() == "Input" then
  1521. local wndForm = wndControl:GetParent()
  1522. strText = self:HelperReplaceLinks(strText, wndControl:GetAllLinks())
  1523.  
  1524. local wndInput = wndForm:FindChild("Input")
  1525.  
  1526. local luaSubclass = wndControl:GetWindowSubclass()
  1527. if luaSubclass and luaSubclass:IsSuggestedMenuShown() then
  1528. luaSubclass:OnEditBoxReturn(wndHandler, wndControl)
  1529. return
  1530. end
  1531. wndControl:SetText("")
  1532. if self.eRoleplayOption == 2 then
  1533. wndControl:SetText(Apollo.GetString("ChatLog_RPMarker"))
  1534. end
  1535.  
  1536. local tChatData = wndForm:GetData()
  1537. local bViewedChannel = true
  1538. local tInput = ChatSystemLib.SplitInput(strText)
  1539. if strText ~= "" and strText ~= Apollo.GetString("ChatLog_RPMarker") and strText ~= Apollo.GetString("ChatLog_Marker") then
  1540. local channelCurrent = tInput.channelCommand or tChatData.channelCurrent
  1541. if channelCurrent:GetType() == ChatSystemLib.ChatChannel_Command then
  1542. if tInput.bValidCommand then -- good command
  1543. ChatSystemLib.Command( strText )
  1544. else -- bad command
  1545. local strFailString = String_GetWeaselString(Apollo.GetString("ChatLog_UnknownCommand"), Apollo.GetString("CombatFloaterType_Error"), {strLiteral = tInput.strCommand})
  1546. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strFailString, "" )
  1547. wndInput:SetText(String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), {strLiteral = tInput.strCommand}, {strLiteral = tInput.strMessage}))
  1548. wndInput:SetFocus()
  1549. local strSubmitted = wndForm:FindChild("Input"):GetText()
  1550. wndInput:SetSel(strSubmitted:len(), -1)
  1551. return
  1552. end
  1553. else
  1554. tChatData.channelCurrent = channelCurrent
  1555. bViewedChannel = self:VerifyChannelVisibility(channelCurrent, tInput, wndForm)
  1556. end
  1557. end
  1558.  
  1559. --updating the string for the prompt to tell you the whisper target.
  1560. local strPromptText = tChatData.channelCurrent:GetCommand()
  1561. local eChannelType = tChatData.channelCurrent:GetType()
  1562. if self.strLastTarget and (eChannelType == ChatSystemLib.ChatChannel_Whisper or eChannelType == ChatSystemLib.ChatChannel_AccountWhisper) then
  1563. strPromptText = strPromptText.. " " .. self.strLastTarget
  1564. end
  1565.  
  1566. local crText = self.arChatColor[tChatData.channelCurrent:GetType()] or ApolloColor.new("white")
  1567. wndForm:GetData().crText = crText
  1568. wndInput:SetPrompt(strPromptText)--here add name if whisper
  1569. wndInput:SetPromptColor(crText)
  1570. wndInput:SetTextColor(crText)
  1571.  
  1572. if bViewedChannel ~= true then
  1573. wndInput:SetTextColor(kcrInvalidColor)
  1574. wndInput:SetPrompt("X " .. tInput.strCommand)
  1575. end
  1576.  
  1577. self:ChatActionTaken(wndControl:GetParent())
  1578. end
  1579. end
  1580.  
  1581.  
  1582. function Bb_chat:VerifyChannelVisibility(channelChecking, tInput, wndChat)
  1583. local tChatData = wndChat:GetData()
  1584.  
  1585. local bNewChannel = self.channelLastChannel ~= channelChecking
  1586. self.channelLastChannel = channelChecking
  1587. if self.tAllViewedChannels[channelChecking:GetUniqueId()] ~= nil then -- see if this channelChecking is viewed
  1588. local strMessage = tInput.strMessage
  1589. if channelChecking:GetType() == ChatSystemLib.ChatChannel_AccountWhisper then
  1590. if self.tAccountWhisperContex then
  1591. local strCharacterAndRealm = self.tAccountWhisperContex.strCharacterName .. "@" .. self.tAccountWhisperContex.strRealmName
  1592. strMessage = string.gsub(strMessage, self.tAccountWhisperContex.strDisplayName, strCharacterAndRealm, 1)
  1593. end
  1594. end
  1595.  
  1596. -- if there is a str command, they are changing the channel, or whisper target
  1597. --the target can be the same as the last target
  1598. if tInput.strCommand ~= "" or bNewChannel then
  1599. self.strLastTarget = ""
  1600. end
  1601.  
  1602. local strSend = ""
  1603. if self.strLastTarget and self.strLastTarget ~= "" then --use last whispered as the target
  1604. strSend = self.strLastTarget.." "..strMessage
  1605. else --updating last whispered for next messages
  1606. strSend = strMessage
  1607.  
  1608. local strPattern = "" --using regex pattern
  1609. if channelChecking:GetType() == ChatSystemLib.ChatChannel_Whisper then
  1610. --find a space, any number of alphabet characters, and then another space
  1611. strPattern = "%s%a*%s-"
  1612. elseif channelChecking:GetType() == ChatSystemLib.ChatChannel_AccountWhisper then
  1613. --since account names only are one word, find a space
  1614. strPattern = "%s"
  1615. end
  1616. local nPlaceHolder, nSubstringStop = string.find(strSend, strPattern)
  1617.  
  1618. --Occurs when not typing a message, just ending with sender name.
  1619. if not nSubstringStop then
  1620. nSubstringStop = string.len(strSend)
  1621. end
  1622.  
  1623. if strPattern ~= "" then
  1624. self.strLastTarget = string.sub(strSend, 0, nSubstringStop)--gets the name of the target
  1625. end
  1626. end
  1627.  
  1628. channelChecking:Send(strSend)
  1629. return true
  1630. else
  1631. local wndInput = wndChat:FindChild("Input")
  1632.  
  1633. strMessage = String_GetWeaselString(Apollo.GetString("CRB_Message_not_sent_you_are_not_viewing"), channelChecking:GetName())
  1634. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Command, strMessage, "" )
  1635. wndInput:SetText(String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), tInput.strCommand, tInput.strMessage))
  1636. wndInput:SetFocus()
  1637. local strSubmitted = wndInput:GetText()
  1638. wndInput:SetSel(strSubmitted:len(), -1)
  1639. return false
  1640. end
  1641. end
  1642.  
  1643. function Bb_chat:InsertIntoRecent(strInsertName, bAccountFriends)
  1644. --check and see if name was already in tRecent
  1645. local nRemoveIndex = -1
  1646. for idx, tInfo in pairs(self.tRecent) do
  1647. if tInfo.strCharacterName == strInsertName then
  1648. nRemoveIndex = idx
  1649. break
  1650. end
  1651. end
  1652. if nRemoveIndex ~= -1 then --already had this person
  1653. table.remove(self.tRecent, nRemoveIndex)
  1654. end
  1655.  
  1656. if #self.tRecent > knMaxRecentEntries then
  1657. table.remove(self.tRecent, knMaxRecentEntries)--remove the last
  1658. end
  1659. table.insert(self.tRecent, 1, {strCharacterName = strInsertName, bAccountFriends = bAccountFriends})
  1660.  
  1661. Event_FireGenericEvent("UpdateRecent", self.tRecent)
  1662. end
  1663.  
  1664. function Bb_chat:RemoveFromRecent(strCharacterName)
  1665. if self.tRecent[strCharacterName] then
  1666. self.tRecent[strCharacterName] = nil
  1667. end
  1668. Event_FireGenericEvent("UpdateRecent", self.tRecent)
  1669. end
  1670.  
  1671. function Bb_chat:OnWindowGainedFocus(wndHandler, wndControl)
  1672. if wndHandler ~= wndControl then
  1673. return
  1674. end
  1675. wndHandler:SetSel(wndHandler:GetText():len(), -1)
  1676. end
  1677.  
  1678. function Bb_chat:OnInputChanged(wndHandler, wndControl, strText)
  1679. local wndForm = wndControl:GetParent()
  1680.  
  1681. if wndControl:GetName() ~= "Input" then
  1682. return
  1683. end
  1684.  
  1685. for idx, wndChat in pairs(self.tChatWindows) do
  1686. wndChat:FindChild("Input"):SetData(false)
  1687. end
  1688. wndControl:SetData(true)
  1689.  
  1690. local wndForm = wndControl:GetParent()
  1691. local wndInput = wndForm:FindChild("Input")
  1692.  
  1693. if Apollo.StringToLower(strText) == Apollo.GetString("ChatLog_Reply") and self.tLastWhisperer and self.tLastWhisperer.strCharacterName ~= "" then
  1694. local strName = self.tLastWhisperer.strCharacterName
  1695. local channel = self.channelWhisper
  1696. if self.tLastWhisperer.eChannelType == ChatSystemLib.ChatChannel_AccountWhisper then
  1697. channel = self.channelAccountWhisper
  1698.  
  1699. self.tAccountWhisperContex =
  1700. {
  1701. ["strDisplayName"] = self.tLastWhisperer.strDisplayName,
  1702. ["strCharacterName"] = self.tLastWhisperer.strCharacterName,
  1703. ["strRealmName"] = self.tLastWhisperer.strRealmName,
  1704. }
  1705. strName = self.tLastWhisperer.strDisplayName
  1706. end
  1707.  
  1708. local strWhisper = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), channel:GetAbbreviation(), strName)
  1709. wndInput:SetPrompt(channel:GetCommand())
  1710. wndInput:SetPromptColor(self.arChatColor[self.tLastWhisperer.eChannelType])
  1711. wndInput:SetTextColor(self.arChatColor[self.tLastWhisperer.eChannelType])
  1712. wndInput:SetText(strWhisper)
  1713. wndInput:SetFocus()
  1714. wndInput:SetSel(strWhisper:len(), -1)
  1715. return
  1716. end
  1717.  
  1718. local tChatData = wndForm:GetData()
  1719. local tInput = ChatSystemLib.SplitInput(strText)
  1720. local channelInput = tInput.channelCommand or tChatData.channelCurrent
  1721. local crText = self.arChatColor[channelInput:GetType()] or ApolloColor.new("white")
  1722. wndInput:SetStyleEx("PromptColor", crText)
  1723. wndInput:SetTextColor(crText)
  1724.  
  1725. if channelInput:GetType() == ChatSystemLib.ChatChannel_Command then -- command or emote
  1726. if tInput.bValidCommand then
  1727. if not self.tEmotes[tInput.strCommand] then
  1728. wndInput:SetPrompt(String_GetWeaselString(Apollo.GetString("CRB_CurlyBrackets"), "", tInput.strCommand))
  1729. wndInput:SetPromptColor(kcrValidColor)
  1730. wndInput:SetTextColor(kcrValidColor)
  1731. end
  1732. else
  1733. --if there was a last channel, use that. otherwise default to say.
  1734. wndInput:SetPrompt(self.channelLastChannel and self.channelLastChannel:GetCommand() or self.channelSay:GetCommand())
  1735. end
  1736. else -- chatting in a channel; check for visibility
  1737. if self.tAllViewedChannels[ channelInput:GetType() ] ~= nil then -- channel is viewed
  1738. wndInput:SetPrompt(channelInput:GetCommand())
  1739. else -- channel is hidden
  1740. wndInput:SetPrompt(String_GetWeaselString(Apollo.GetString("ChatLog_Invalid"), channelInput:GetCommand()))
  1741. wndInput:SetPromptColor(kcrInvalidColor)
  1742. end
  1743. end
  1744.  
  1745. local luaSubclass = wndInput:GetWindowSubclass()
  1746. if luaSubclass and tInput then
  1747. if not self.tSuggestedFilterRules then
  1748. self.tSuggestedFilterRules = self:HelperLoadSetRules(luaSubclass)
  1749. end
  1750.  
  1751. if tInput.bValidCommand then
  1752. strCommandName = tInput.channelCommand and tInput.channelCommand:GetCommand() ~= "" and tInput.channelCommand:GetCommand() or tInput.strCommand
  1753. end
  1754.  
  1755. if strCommandName ~= "" then
  1756. local strLowerCaseCommand = Apollo.StringToLower(strCommandName)
  1757. if self.tSuggestedFilterRules and self.tSuggestedFilterRules[strLowerCaseCommand] then
  1758. local strPlaceHolder, nCountSpaces = string.gsub(strText, " ", " ")
  1759. if tInput.bValidCommand and nCountSpaces <= knCountSpaces then
  1760. local tSuggestFilterInfo = self.tSuggestedFilterRules[strLowerCaseCommand]
  1761. self.tLastFilteredInfo = tSuggestFilterInfo
  1762. luaSubclass:SetFilters(tSuggestFilterInfo)
  1763. luaSubclass:OnEditBoxChanged(wndHandler, wndControl, tInput.strMessage)
  1764. elseif tInput.bValidCommand and nCountSpaces > knCountSpaces or not tInput.bValidCommand and luaSubclass:IsSuggestedMenuShown() then
  1765. luaSubclass:HideSuggestedMenu()
  1766. end
  1767. end
  1768. end
  1769. end
  1770. end
  1771.  
  1772. function Bb_chat:FindAnInputWindow()
  1773. for idx, wnd in pairs(self.tChatWindows) do
  1774. wnd:FindChild("Input"):SetData(false)
  1775. end
  1776. end
  1777.  
  1778. function Bb_chat:OnAddWindow(wndHandler, wndControl)
  1779. local wndForm = wndControl:GetParent() -- TODO refactor
  1780. local wndAdd = wndForm:FindChild("AddTabSubForm")
  1781. local bShown = wndAdd:IsShown()
  1782.  
  1783.  
  1784. for key, wndChat in pairs(self.tChatWindows) do
  1785. if wndChat:FindChild("AddTabSubForm"):IsShown() then
  1786. wndChat:FindChild("AddTabSubForm"):Show(false)
  1787. end
  1788. end
  1789.  
  1790. if not bShown then
  1791. wndAdd:Invoke()
  1792. else
  1793. wndAdd:Close()
  1794. end
  1795. end
  1796.  
  1797. function Bb_chat:OnAddTabSubFormClose(wndHandler, wndControl)
  1798. local wndForm = wndControl:GetParent() -- TODO refactor
  1799. wndForm:FindChild("AddTabSubForm"):Close()
  1800. end
  1801.  
  1802. function Bb_chat:OnAddNewTabChat(wndHandler, wndControl) -- this is when a tab; each is its own window
  1803. wndControl:GetParent():Close()
  1804. self.nChatIndex = self.nChatIndex + 1
  1805.  
  1806. local wndForm = wndControl:GetParent():GetParent() -- TODO refactor
  1807. local tData = wndForm:GetData()
  1808. local strName = String_GetWeaselString(Apollo.GetString("ChatLog_SecondChannel"), Apollo.GetString("CRB_Chat"), self.nChatIndex)
  1809.  
  1810. local tChannelsToView = tData.bCombatLog and self.tCombatChannels or tData.tViewedChannels
  1811.  
  1812. -- needs to take it from the main form of toggled from a combat window (idx == 1)
  1813. if wndForm:FindChild("BGArt_ChatBackerIcon"):IsShown() then
  1814. for idx, wndChat in pairs(self.tChatWindows) do
  1815. local tChatData = wndChat:GetData()
  1816. if not wndChat:FindChild("BGArt_ChatBackerIcon"):IsShown() then
  1817. tChannelsToView = tChatData.tViewedChannels
  1818. break
  1819. end
  1820. end
  1821. end
  1822.  
  1823. local wndNewForm = self:NewChatWindow(strName, tChannelsToView, false, tData.channelCurrent)
  1824.  
  1825. wndForm:AttachTab(wndNewForm, true)
  1826. wndNewForm:FindChild("Options"):SetCheck(true)
  1827.  
  1828. self:OnSettings(wndNewForm:FindChild("Options"), wndNewForm:FindChild("Options"))
  1829. end
  1830.  
  1831. function Bb_chat:OnAddNewTabCombat(wndHandler, wndControl) -- this is when a tab; each is its own window
  1832. wndControl:GetParent():Close()
  1833. self.nChatIndex = self.nChatIndex + 1
  1834.  
  1835. local wndForm = wndControl:GetParent():GetParent()
  1836. local tData = wndForm:GetData()
  1837. local strName = String_GetWeaselString(Apollo.GetString("ChatLog_SecondChannel"), Apollo.GetString("ChatType_Combat"), self.nChatIndex)
  1838. local wndNewForm = self:NewChatWindow(strName, tData.tViewedChannels, true, tData.channelCurrent)
  1839.  
  1840. wndForm:AttachTab(wndNewForm, true)
  1841. wndNewForm:FindChild("Options"):SetCheck(true)
  1842.  
  1843. self:OnSettingsCombat(wndNewForm:FindChild("Options"), wndNewForm:FindChild("Options"))
  1844. end
  1845.  
  1846. function Bb_chat:OnSaveLog(wndHandler, wndControl)
  1847. wndControl:Enable(false)
  1848. end
  1849.  
  1850. function Bb_chat:GetDisplayNameForChannel(strChannel)
  1851. return strChannel
  1852. end
  1853.  
  1854. function Bb_chat:AddChannelTypeToList(tData, wndList, channel)
  1855. local wndChannelItem = Apollo.LoadForm(self.xmlDoc, "ChatType", wndList, self)
  1856. wndChannelItem:FindChild("TypeName"):SetText(channel:GetName())
  1857. wndChannelItem:SetData(channel:GetUniqueId())
  1858. wndChannelItem:FindChild("ViewCheck"):SetCheck(tData.tViewedChannels[channel:GetUniqueId()] or false)
  1859. end
  1860.  
  1861. function Bb_chat:OnViewCheck(wndHandler, wndControl)
  1862. local wndChannel = wndControl:GetParent()
  1863. local wndOptions = wndChannel:GetParent():GetParent():GetParent()
  1864. local eChannelId = wndChannel:GetData()
  1865. local tData = wndOptions:GetData()
  1866.  
  1867. if tData == nil then
  1868. return
  1869. end
  1870.  
  1871. if tData.tViewedChannels[eChannelId] then
  1872. tData.tViewedChannels[eChannelId] = false
  1873. self:HelperRemoveChannelFromAll(eChannelId)
  1874. else
  1875. tData.tViewedChannels[eChannelId] = true
  1876. self:HelperAddChannelToAll(eChannelId)
  1877. end
  1878. end
  1879.  
  1880. function Bb_chat:OnChatTitleChanged(wndHandler, wndControl, strNewTitle)
  1881. local tData = wndControl:GetParent():GetParent():GetParent():GetParent():GetData()
  1882. tData.wndForm:SetText(strNewTitle)
  1883. end
  1884.  
  1885. function Bb_chat:OnOptionsSubFormClosed( wndHandler, wndControl )
  1886. if wndHandler ~= wndControl then return end
  1887.  
  1888. local wndForm = wndControl:GetData()
  1889. wndForm:FindChild("Input"):Show(true)
  1890. end
  1891.  
  1892. function Bb_chat:OnSettings(wndHandler, wndControl)
  1893. local wndForm = wndControl:GetParent()
  1894. local tData = wndForm:GetData()
  1895.  
  1896. if wndForm:FindChild("BGArt_ChatBackerIcon"):IsShown() then
  1897. self:OnSettingsCombat(wndForm:FindChild("Options"), wndForm:FindChild("Options"))
  1898. return
  1899. end
  1900.  
  1901. if not wndControl:IsChecked() then
  1902. tData.wndOptions:Show(false)
  1903. wndForm:FindChild("Input"):Show(true)
  1904. else
  1905. if wndForm:FindChild("EmoteMenu"):IsVisible() then
  1906. wndForm:FindChild("EmoteMenu"):Show(false)
  1907. wndForm:FindChild("EmoteBtn"):SetCheck(false)
  1908. end
  1909.  
  1910. if wndForm:FindChild("InputWindow"):IsVisible() then
  1911. wndForm:FindChild("InputWindow"):Show(false)
  1912. wndForm:FindChild("InputTypeBtn"):SetCheck(false)
  1913. end
  1914.  
  1915. self:DrawSettings(wndForm)
  1916. end
  1917. end
  1918.  
  1919. function Bb_chat:OnSettingsCombat(wndHandler, wndControl)
  1920. local wndForm = wndControl:GetParent()
  1921. local tData = wndForm:GetData()
  1922.  
  1923. if not wndControl:IsChecked() then
  1924. tData.wndOptions:Show(false)
  1925. wndForm:FindChild("Input"):Show(true)
  1926. else
  1927. if wndForm:FindChild("EmoteMenu"):IsVisible() then
  1928. wndForm:FindChild("EmoteMenu"):Show(false)
  1929. wndForm:FindChild("EmoteBtn"):SetCheck(false)
  1930. end
  1931.  
  1932. if wndForm:FindChild("InputWindow"):IsVisible() then
  1933. wndForm:FindChild("InputWindow"):Show(false)
  1934. wndForm:FindChild("InputTypeBtn"):SetCheck(false)
  1935. end
  1936.  
  1937. self:DrawSettingsCombat(wndForm)
  1938. end
  1939. end
  1940.  
  1941. function Bb_chat:DrawSettings(wndForm)
  1942. local tData = wndForm:GetData()
  1943.  
  1944. tData.wndOptions:Show(true)
  1945.  
  1946. local wndList = tData.wndOptions:FindChild("ChatTypesList")
  1947. wndList:DestroyChildren()
  1948. wndList:RecalculateContentExtents()
  1949.  
  1950. local wndNameEntry = Apollo.LoadForm(self.xmlDoc, "ChatNameEntry", wndList, self)
  1951. wndNameEntry:FindChild("Name"):SetText(wndForm:GetText())
  1952.  
  1953. --wndNameEntry:FindChild("Name"):SetSel(0, -1)
  1954. --wndNameEntry:FindChild("Name"):SetFocus()
  1955.  
  1956. local tChannels = ChatSystemLib.GetChannels()
  1957.  
  1958. local wndCat = Apollo.LoadForm(self.xmlDoc, "ChatCategory", wndList, self)
  1959. for idx, channelCurrent in ipairs(tChannels) do
  1960. self:AddChannelTypeToList(tData, wndList, channelCurrent)
  1961. end
  1962.  
  1963. local tCustomChannels = {}
  1964. for idx, channelViewed in pairs(tChannels) do -- gives us our viewed channels
  1965. if channelViewed:GetType() == ChatSystemLib.ChatChannel_Custom then
  1966. table.insert(tCustomChannels, channelViewed)
  1967. end
  1968. end
  1969.  
  1970. local wndCustomHeader = Apollo.LoadForm(self.xmlDoc, "CustomChatCategory", wndList, self)
  1971. --wndCustomHeader:FindChild("FramingAccent"):Show(#tCustomChannels > 0)
  1972.  
  1973. local wndAddJoinChannel = wndCustomHeader:FindChild("AddJoinForm")
  1974. wndCustomHeader:FindChild("AddJoinCustomChannel"):AttachWindow(wndAddJoinChannel)
  1975. wndAddJoinChannel:FindChild("AddJoinConfirmBtn"):Enable(false)
  1976. wndAddJoinChannel:Show(false)
  1977.  
  1978. if #tCustomChannels > 0 then
  1979. for idxCustom, channelCustom in pairs(tCustomChannels) do
  1980. local wndCustomChannel = Apollo.LoadForm(self.xmlDoc, "ChatTypeCustom", wndList, self)
  1981. wndCustomChannel:FindChild("LeaveCustomChannelBtn"):SetData(channelCustom)
  1982. wndCustomChannel:FindChild("TypeName"):SetText(String_GetWeaselString(Apollo.GetString("ChatLog_ChannelCommand"), channelCustom:GetCommand(), channelCustom:GetName()))
  1983. end
  1984. end
  1985.  
  1986. wndList:ArrangeChildrenVert()
  1987. tData.wndOptions:SetOpacity(0.9)
  1988. wndForm:FindChild("Input"):Show(false)
  1989. end
  1990.  
  1991. function Bb_chat:DrawSettingsCombat(wndForm)
  1992. local tData = wndForm:GetData()
  1993.  
  1994. tData.wndOptions:Show(true)
  1995.  
  1996. local wndList = tData.wndOptions:FindChild("ChatTypesList")
  1997. wndList:DestroyChildren()
  1998. wndList:RecalculateContentExtents()
  1999.  
  2000. local wndNameEntry = Apollo.LoadForm(self.xmlDoc, "ChatNameEntry", wndList, self)
  2001. wndNameEntry:FindChild("Name"):SetText(wndForm:GetText())
  2002.  
  2003. --wndNameEntry:FindChild("Name"):SetSel(0, -1)
  2004. --wndNameEntry:FindChild("Name"):SetFocus()
  2005.  
  2006. local wndCat = Apollo.LoadForm(self.xmlDoc, "ChatCategory", wndList, self)
  2007. for idx, channelCurrent in ipairs(ChatSystemLib.GetChannels()) do
  2008. if self.tCombatChannels[channelCurrent:GetType()] then
  2009. self:AddChannelTypeToList(tData, wndList, channelCurrent)
  2010. end
  2011. end
  2012.  
  2013. wndList:ArrangeChildrenVert()
  2014. tData.wndOptions:SetOpacity(0.9)
  2015. wndForm:FindChild("Input"):Show(false)
  2016. end
  2017.  
  2018. function Bb_chat:OnBeginChat(wndHandler, wndControl)
  2019. wndControl:GetParent():FindChild("Input"):SetFocus()
  2020. end
  2021.  
  2022. function Bb_chat:OnItemSentToCrate(itemSentToCrate, nCount)
  2023. if itemSentToCrate == nil or nCount == 0 then
  2024. return
  2025. end
  2026. local tFlags = {ChatFlags_Loot=true}
  2027. local strMessage = String_GetWeaselString(Apollo.GetString("ChatLog_ToHousingCrate"), {["count"] = nCount, ["name"] = itemSentToCrate:GetName()})
  2028. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Loot, strMessage, "" )
  2029. end
  2030.  
  2031. function Bb_chat:OnHarvestItemsSentToOwner(arSentToOwner)
  2032. for _, tSent in ipairs(arSentToOwner) do
  2033. if tSent.item then
  2034. local strMessage = String_GetWeaselString(Apollo.GetString("Housing_HarvestingLoot"), {["count"] = tSent.nCount, ["name"] = tSent.item:GetName()})
  2035. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Loot, strMessage, "" )
  2036. end
  2037. end
  2038. end
  2039.  
  2040. function Bb_chat:OnGenericEvent_LootChannelMessage(strMessage)
  2041. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_Loot, strMessage, "" )
  2042. end
  2043.  
  2044. function Bb_chat:OnGenericEvent_SystemChannelMessage(strMessage)
  2045. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_System, strMessage, "" )
  2046. end
  2047.  
  2048. function Bb_chat:OnGenericEvent_LinkItemToChat(itemLinked)
  2049. if itemLinked == nil then
  2050. return
  2051. end
  2052.  
  2053. tLink = {}
  2054. tLink.uItem = itemLinked
  2055. tLink.strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), itemLinked:GetName())
  2056.  
  2057. local wndEdit = self:HelperGetCurrentEditbox()
  2058.  
  2059. -- pump link to the chat line
  2060. if wndEdit then
  2061. self:HelperAppendLink( wndEdit, tLink )
  2062. end
  2063. end
  2064.  
  2065. function Bb_chat:OnPlayedtime(strCreationDate, strPlayedTime, strPlayedLevelTime, strPlayedSessionTime, dateCreation, nSecondsPlayed, nSecondsLevel, nSecondsSession)
  2066. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_System, strCreationDate, "" )
  2067. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_System, strPlayedTime, "" )
  2068. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_System, strPlayedLevelTime, "" )
  2069. ChatSystemLib.PostOnChannel( ChatSystemLib.ChatChannel_System, strPlayedSessionTime, "" )
  2070. end
  2071.  
  2072. function Bb_chat:OnGenericEvent_QuestLink(queLinked)
  2073. if queLinked == nil or not Quest.is(queLinked) then
  2074. return
  2075. end
  2076.  
  2077. local tLink = {}
  2078. tLink.uQuest = queLinked
  2079. tLink.strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), queLinked:GetTitle())
  2080.  
  2081. local wndEdit = self:HelperGetCurrentEditbox()
  2082.  
  2083. -- pump link to the chat line
  2084. if wndEdit then
  2085. self:HelperAppendLink(wndEdit, tLink)
  2086. end
  2087. end
  2088.  
  2089. function Bb_chat:OnGenericEvent_ArchiveArticleLink(artLinked)
  2090. if artLinked == nil then
  2091. return
  2092. end
  2093.  
  2094. local tLink = {}
  2095. tLink.uArchiveArticle = artLinked
  2096. tLink.strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), artLinked:GetTitle())
  2097.  
  2098. local wndEdit = self:HelperGetCurrentEditbox()
  2099.  
  2100. -- pump link to the chat line
  2101. if wndEdit then
  2102. self:HelperAppendLink( wndEdit, tLink )
  2103. end
  2104. end
  2105.  
  2106. function Bb_chat:OnSaveBtn()
  2107. end
  2108.  
  2109. function Bb_chat:OnInputTypeCheck(wndHandler, wndControl)
  2110. local wndParent = wndControl:GetParent()
  2111. local wndMenu = wndParent:FindChild("InputWindow")
  2112.  
  2113. if wndHandler:IsChecked() then
  2114. wndMenu:Invoke()
  2115. else
  2116. wndMenu:Close()
  2117. end
  2118.  
  2119. if wndHandler:IsChecked() then
  2120. self:BuildInputTypeMenu(wndParent)
  2121. end
  2122. end
  2123.  
  2124. function Bb_chat:BuildInputTypeMenu(wndChat) -- setting this up externally so we can remove it from toggle at some point
  2125. --local wndChannel = wndControl:GetParent()
  2126. --local wndOptions = wndChat:GetParent():GetParent():GetParent()
  2127. --local channelType = wndChannel:GetData()
  2128. local tData = wndChat:GetData()
  2129.  
  2130. if tData == nil then
  2131. return
  2132. end
  2133.  
  2134. local wndInputMenu = wndChat:FindChild("InputWindow")
  2135. local wndContent = wndInputMenu:FindChild("InputMenuContent")
  2136. wndContent:DestroyChildren()
  2137.  
  2138. local tChannels = ChatSystemLib.GetChannels()
  2139. local nEntryHeight = 26 --height of the entry wnd
  2140. local nCount = 0 --number of joined channels
  2141.  
  2142. for idx, channelCurrent in pairs(tChannels) do -- gives us our viewed channels
  2143. if self.tAllViewedChannels[channelCurrent:GetUniqueId()] ~= nil then
  2144. if channelCurrent:GetCommand() ~= nil and channelCurrent:GetCommand() ~= "" then -- make sure it's a channelCurrent that can be spoken into
  2145. local strCommand = channelCurrent:GetAbbreviation()
  2146.  
  2147. if strCommand == "" or strCommand == nil then
  2148. strCommand = channelCurrent:GetCommand()
  2149. end
  2150.  
  2151. local wndEntry = Apollo.LoadForm(self.xmlDoc, "InputMenuEntry", wndContent, self)
  2152.  
  2153. local strType = ""
  2154. if channelCurrent:GetType() == ChatSystemLib.ChatChannel_Custom then
  2155. strType = Apollo.GetString("ChatLog_CustomLabel")
  2156. end
  2157.  
  2158. wndEntry:FindChild("NameText"):SetText(channelCurrent:GetName())
  2159. wndEntry:FindChild("CommandText"):SetText(String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strCommand))
  2160. wndEntry:SetData(channelCurrent) -- set the channelCurrent
  2161.  
  2162. local crText = self.arChatColor[channelCurrent:GetType()] or ApolloColor.new("white")
  2163. wndEntry:FindChild("CommandText"):SetTextColor(crText)
  2164. wndEntry:FindChild("NameText"):SetTextColor(crText)
  2165.  
  2166. nCount = nCount + 1
  2167. end
  2168. end
  2169. end
  2170.  
  2171. if nCount == 0 then
  2172. local wndEntry = Apollo.LoadForm(self.xmlDoc, "InputMenuEntry", wndContent, self)
  2173. wndEntry:Enable(false)
  2174. wndEntry:FindChild("NameText"):SetText(Apollo.GetString("CRB_No_Channels_Visible"))
  2175. nCount = 1
  2176. end
  2177.  
  2178. nEntryHeight = nEntryHeight * nCount
  2179. wndInputMenu:SetAnchorOffsets(self.nInputMenuLeft, math.max(-knChannelListHeight , self.nInputMenuTop - nEntryHeight), self.nInputMenuRight, self.nInputMenuBottom)
  2180.  
  2181. wndContent:ArrangeChildrenVert()
  2182. end
  2183.  
  2184. function Bb_chat:OnInputMenuEntry(wndHandler, wndControl)
  2185. local channelCurrent = wndControl:GetData()
  2186. local wndChat = wndControl:GetParent():GetParent():GetParent()
  2187. local tChatData = wndChat:GetData()
  2188. local wndInput = wndChat:FindChild("Input")
  2189. local strText = wndInput:GetText()
  2190. local strCommand = channelCurrent:GetAbbreviation()
  2191.  
  2192. if strCommand == "" or strCommand == nil then
  2193. strCommand = channelCurrent:GetCommand()
  2194. end
  2195.  
  2196. if strText == "" then
  2197. strText = String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strCommand.." ")
  2198. else
  2199. local tInput = ChatSystemLib.SplitInput(strText) -- get the existing message, ignore the old command
  2200. strText = String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strCommand).." "..tInput.strMessage
  2201. end
  2202.  
  2203. wndInput:SetText(strText)
  2204. local crText = self.arChatColor[channelCurrent:GetType()] or ApolloColor.new("white")
  2205. wndInput:SetTextColor(crText)
  2206. wndInput:SetPrompt(channelCurrent:GetCommand())
  2207. wndInput:SetPromptColor(crText)
  2208. wndInput:SetFocus()
  2209. wndInput:SetSel(strText:len(), -1)
  2210.  
  2211. tChatData.channelCurrent = channelCurrent
  2212.  
  2213. wndControl:GetParent():GetParent():Show(false)
  2214. wndChat:FindChild("InputTypeBtn"):SetCheck(false)
  2215. end
  2216.  
  2217. function Bb_chat:OnRoleplayBtn(wndHandler, wndControl)
  2218. if wndHandler ~= wndControl then
  2219. return false
  2220. end
  2221.  
  2222. local wndParent = wndControl:GetParent()
  2223. self.eRoleplayOption = wndParent:GetRadioSel("RoleplayViewToggle")
  2224. for idx, wndChat in pairs(self.tChatWindows) do
  2225. if self.eRoleplayOption == 2 then
  2226. wndChat:FindChild("Input"):SetText(Apollo.GetString("ChatLog_RPMarker"))
  2227. else
  2228. wndChat:FindChild("Input"):SetText("")
  2229. end
  2230. end
  2231. end
  2232.  
  2233. function Bb_chat:OnLeaveCustomChannelBtn(wndHandler, wndControl)
  2234. if wndControl:GetData() == nil then return end
  2235.  
  2236. local wndChannel = wndControl:GetData()
  2237. wndChannel:Leave()
  2238. local wndParent = wndControl:GetParent()
  2239. local wndChat = wndParent:GetParent():GetParent():GetParent() -- TODO REFACTOR
  2240. wndChat:FindChild("Options"):SetCheck(false)
  2241. wndChat:FindChild("OptionsSubForm"):Show(false)
  2242. wndChat:FindChild("Input"):Show(true)
  2243. end
  2244.  
  2245.  
  2246. -------- Custom Channel Functions ---------
  2247. function Bb_chat:OnAddJoinCustomChannel(wndHandler, wndControl)
  2248. if wndHandler ~= wndControl then
  2249. return false
  2250. end
  2251.  
  2252. local wndHeader = wndControl:GetParent()
  2253. if wndControl:IsChecked() then
  2254. wndHeader:FindChild("AddJoinForm"):Invoke()
  2255. else
  2256. wndHeader:FindChild("AddJoinForm"):Close()
  2257. end
  2258. end
  2259.  
  2260. function Bb_chat:OnAddJoinInputChanging(wndHandler, wndControl)
  2261. if wndHandler ~= wndControl then
  2262. return false
  2263. end
  2264.  
  2265. local strInput = wndControl:GetText()
  2266. local bNameValid = GameLib.IsTextValid(strInput, GameLib.CodeEnumUserText.ChatCustomChannelName, GameLib.CodeEnumUserTextFilterClass.Strict )
  2267.  
  2268. local wndForm = wndControl:GetParent()
  2269. wndForm:FindChild("AddJoinConfirmBtn"):Enable(self:HelperCheckForEmptyString(strInput) and bNameValid)
  2270. wndForm:FindChild("InvalidInputWarning"):Show(self:HelperCheckForEmptyString(strInput) and not bNameValid)
  2271. end
  2272.  
  2273. function Bb_chat:OnAddJoinCancelBtn(wndHandler, wndControl)
  2274. if wndHandler ~= wndControl then
  2275. return false
  2276. end
  2277. local wndForm = wndControl:GetParent()
  2278. wndForm:FindChild("AddJoinConfirmBtn"):Enable(false)
  2279. wndForm:FindChild("AddJoinInput"):SetText("")
  2280. wndForm:Show(false)
  2281. end
  2282.  
  2283. function Bb_chat:OnAddJoinFormClose(wndHandler, wndControl)
  2284. if wndHandler ~= wndControl then
  2285. return false
  2286. end
  2287. wndControl:FindChild("AddJoinConfirmBtn"):Enable(false)
  2288. wndControl:FindChild("AddJoinInput"):SetText("")
  2289. wndControl:Close()
  2290. end
  2291.  
  2292. function Bb_chat:OnAddJoinConfirmBtn(wndHandler, wndControl)
  2293. if wndHandler ~= wndControl then
  2294. return false
  2295. end
  2296. local wndForm = wndControl:GetParent()
  2297. local strName = wndForm:FindChild("AddJoinInput"):GetText()
  2298. ChatSystemLib.JoinChannel(strName)
  2299.  
  2300. local wndChat = wndForm:GetParent():GetParent():GetParent():GetParent() -- TODO REFACTOR
  2301. wndChat:FindChild("Options"):SetCheck(false)
  2302. wndChat:FindChild("OptionsSubForm"):Show(false)
  2303. wndChat:FindChild("Input"):Show(true)
  2304. end
  2305.  
  2306. function Bb_chat:OnFontSizeOption(wndHandler, wndControl)
  2307. local tFontOption = wndControl:GetData()
  2308. self.strFontOption = tFontOption.strNormal
  2309. self.strAlienFontOption = tFontOption.strAlien
  2310. self.strRPFontOption = tFontOption.strRP
  2311. end
  2312.  
  2313. function Bb_chat:OnTimestamp(wndHandler, wndControl)
  2314. self.bShowTimestamp = wndControl:GetData()
  2315. end
  2316.  
  2317. function Bb_chat:OnProfanityFilter(wndHandler, wndControl)
  2318. if wndHandler == wndControl then
  2319. self.bProfanityFilter = wndControl:GetData()
  2320. for idx, channelCurrent in ipairs(ChatSystemLib.GetChannels()) do
  2321. channelCurrent:SetProfanity(self.bProfanityFilter)
  2322. end
  2323. Apollo.SetConsoleVariable("chat.filter", self.bProfanityFilter)
  2324. end
  2325. end
  2326.  
  2327. function Bb_chat:OnChannelLabel(wndHandler, wndControl)
  2328. self.bShowChannel = wndControl:GetData()
  2329. end
  2330.  
  2331. function Bb_chat:OnBGFade(wndHandler, wndControl)
  2332. local wndParent = wndControl:GetParent()
  2333. self.bEnableBGFade = wndControl:GetData()
  2334. self.bEnableNCFade = wndControl:GetData()
  2335.  
  2336. for idx, wndChatWindow in pairs(self.tChatWindows) do
  2337. wndChatWindow:SetStyle("AutoFadeNC", self.bEnableNCFade)
  2338. if self.bEnableNCFade then
  2339. wndChatWindow:SetNCOpacity(1)
  2340. end
  2341.  
  2342. wndChatWindow:SetStyle("AutoFadeBG", self.bEnableBGFade)
  2343. if self.bEnableBGFade then
  2344. wndChatWindow:SetBGOpacity(1)
  2345. end
  2346. end
  2347. end
  2348.  
  2349. function Bb_chat:OnChatLineFade(wndHandler, wndControl, eMouseButton)
  2350. self.bEnableChatLineFade = wndControl:GetData()
  2351. end
  2352.  
  2353. function Bb_chat:OnBGDrawSlider(wndHandler, wndControl)
  2354. self.nBGOpacity = self.wndChatOptions:FindChild("BGOpacitySlider"):GetValue()
  2355.  
  2356. for idx, wndChatWindow in pairs(self.tChatWindows) do
  2357. wndChatWindow:FindChild("BGArt"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  2358. wndChatWindow:FindChild("BGArt_SidePanel"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  2359. wndChatWindow:FindChild("BGArt_ResizeHandle"):SetBGColor(CColor.new(1.0, 1.0, 1.0, self.nBGOpacity))
  2360. end
  2361. end
  2362.  
  2363. function Bb_chat:OnTogglePlayerChatBubbles(wndHandler, wndControl)
  2364. if wndHandler ~= wndControl then
  2365. return
  2366. end
  2367.  
  2368. self.bEnablePlayerBubbles = wndHandler:GetData()
  2369. Apollo.SetConsoleVariable("unit.playerTextBubbleEnabled", self.bEnablePlayerBubbles)
  2370. end
  2371.  
  2372.  
  2373. function Bb_chat:OnToggleNPCChatBubbles(wndHandler, wndControl)
  2374. if wndHandler ~= wndControl then
  2375. return
  2376. end
  2377.  
  2378. self.bEnableNPCBubbles = wndHandler:GetData()
  2379. Apollo.SetConsoleVariable("unit.npcTextBubbleEnabled", self.bEnableNPCBubbles)
  2380. end
  2381.  
  2382. function Bb_chat:OnSaveToLog(wndHandler, wndControl)
  2383. if wndHandler == wndControl then
  2384. local bValue = wndHandler:GetName() == "SaveToLogOn"
  2385. Apollo.SetConsoleVariable("chat.saveLog", bValue)
  2386. self.wndChatOptions:FindChild("SaveToLogOn"):SetCheck(bValue)
  2387. self.wndChatOptions:FindChild("SaveToLogOff"):SetCheck(not bValue)
  2388. end
  2389. end
  2390.  
  2391. -----------------------------------------------------------------------------------------------
  2392. -- Helpers
  2393. -----------------------------------------------------------------------------------------------
  2394.  
  2395. function Bb_chat:HelperGenerateChatMessage(tQueuedMessage)
  2396. if tQueuedMessage.xml then
  2397. return
  2398. end
  2399.  
  2400. local eChannelType = tQueuedMessage.eChannelType
  2401. local tMessage = tQueuedMessage.tMessage
  2402.  
  2403. -- Different handling for combat log
  2404. if eChannelType == ChatSystemLib.ChatChannel_Combat then
  2405. -- no formats in combat, roll it all up into one.
  2406. local strMessage = ""
  2407. for idx, tSegment in ipairs(tMessage.arMessageSegments) do
  2408. strMessage = strMessage .. tSegment.strText
  2409. end
  2410. tQueuedMessage.strMessage = strMessage
  2411. return
  2412. end
  2413.  
  2414. local xml = XmlDoc.new()
  2415.  
  2416. local crText = self.arChatColor[eChannelType] or ApolloColor.new("white")
  2417. local crChannel = ApolloColor.new(karChannelTypeToColor[eChannelType].Channel or "white")
  2418. local crPlayerName = ApolloColor.new("ChatPlayerName")
  2419.  
  2420. local strTime = ""
  2421. if self.bShowTimestamp then
  2422. strTime = self:HelperGetTimeStr()
  2423. end
  2424.  
  2425. local strWhisperName = tMessage.strSender
  2426. if tMessage.strRealmName:len() > 0 and eChannelType ~= ChatSystemLib.ChatChannel_AccountWhisper then
  2427. -- Name/Realm formatting needs to be very specific for cross realm chat to work
  2428. strWhisperName = strWhisperName .. "@" .. tMessage.strRealmName
  2429. end
  2430. local strDisplayName = strWhisperName
  2431.  
  2432. --strWhisperName must only be sender@realm, or friends equivelent name.
  2433.  
  2434. local strPresenceState = ""
  2435. if tMessage.bAutoResponse then
  2436. strPresenceState = '('..Apollo.GetString("AutoResponse_Prefix")..')'
  2437. end
  2438.  
  2439. if tMessage.nPresenceState == FriendshipLib.AccountPresenceState_Away then
  2440. strPresenceState = '<'..Apollo.GetString("Command_Friendship_AwayFromKeyboard")..'>'
  2441. elseif tMessage.nPresenceState == FriendshipLib.AccountPresenceState_Busy then
  2442. strPresenceState = '<'..Apollo.GetString("Command_Friendship_DoNotDisturb")..'>'
  2443. end
  2444.  
  2445. if eChannelType == ChatSystemLib.ChatChannel_Whisper then
  2446. if not tMessage.bSelf then
  2447. self.tLastWhisperer = { strCharacterName = strWhisperName, eChannelType = ChatSystemLib.ChatChannel_Whisper }--record the last incoming whisperer for quick response
  2448. end
  2449. Sound.Play(Sound.PlayUISocialWhisper)
  2450. self:InsertIntoRecent(strWhisperName, false)
  2451. elseif eChannelType == ChatSystemLib.ChatChannel_AccountWhisper then
  2452.  
  2453. local tPreviousWhisperer = self.tLastWhisperer
  2454.  
  2455. local tAccountFriends = FriendshipLib.GetAccountList()
  2456. for idx, tAccountFriend in pairs(tAccountFriends) do
  2457. if tAccountFriend.arCharacters ~= nil then
  2458. for idx, tCharacter in pairs(tAccountFriend.arCharacters) do
  2459. if tCharacter.strCharacterName == tMessage.strSender and (tMessage.strRealmName:len() == 0 or tCharacter.strRealm == tMessage.strRealmName) then
  2460. if not tMessage.bSelf or (tPreviousWhisperer and tPreviousWhisperer.strCharacterName == tMessage.strSender) then
  2461. self.tLastWhisperer =
  2462. {
  2463. strCharacterName = tMessage.strSender,
  2464. strRealmName = tCharacter.strRealm,
  2465. strDisplayName = tAccountFriend.strCharacterName,
  2466. eChannelType = ChatSystemLib.ChatChannel_AccountWhisper
  2467. }
  2468. end
  2469. strDisplayName = tAccountFriend.strCharacterName
  2470. end
  2471. end
  2472. end
  2473. end
  2474. Sound.Play(Sound.PlayUISocialWhisper)
  2475. self:InsertIntoRecent(strDisplayName, true)
  2476. end
  2477.  
  2478. -- We build strings backwards, right to left
  2479. if eChannelType == ChatSystemLib.ChatChannel_AnimatedEmote then -- emote animated channel gets special formatting
  2480. xml:AddLine(strTime, crChannel, self.strFontOption, "Left")
  2481.  
  2482. elseif eChannelType == ChatSystemLib.ChatChannel_Emote then -- emote channel gets special formatting
  2483. xml:AddLine(strTime, crChannel, self.strFontOption, "Left")
  2484. if strDisplayName:len() > 0 then
  2485. if tMessage.bGM then
  2486. xml:AppendImage(kstrGMIcon, 16, 16)
  2487. end
  2488. local strCross = tMessage.bCrossFaction and "true" or "false"--has to be a string or a number due to code restriction
  2489. xml:AppendText(strDisplayName, crPlayerName, self.strFontOption, {strCharacterName = strWhisperName, nReportId = tMessage.nReportId, strCrossFaction = strCross}, "Source")
  2490. end
  2491. xml:AppendText(" ")
  2492. else
  2493. local strChannel
  2494. if eChannelType == ChatSystemLib.ChatChannel_Society then
  2495. strChannel = (string.format("%s ", String_GetWeaselString(Apollo.GetString("ChatLog_GuildCommand"), tQueuedMessage.strChannelName, tQueuedMessage.strChannelCommand))) --String DB removed empty characters at the end of string, so have to hardcode it here.
  2496. else
  2497. strChannel = String_GetWeaselString(Apollo.GetString("CRB_Brackets_Space"), tQueuedMessage.strChannelName)
  2498. end
  2499.  
  2500. if self.bShowChannel ~= true then
  2501. strChannel = ""
  2502. end
  2503.  
  2504. xml:AddLine(strTime .. strChannel, crChannel, self.strFontOption, "Left")
  2505. if strDisplayName:len() > 0 then
  2506.  
  2507. local strWhisperNamePrefix = ""
  2508. if eChannelType == ChatSystemLib.ChatChannel_Whisper or eChannelType == ChatSystemLib.ChatChannel_AccountWhisper then
  2509. if tMessage.bSelf then
  2510. strWhisperNamePrefix = Apollo.GetString("ChatLog_To")
  2511. else
  2512. strWhisperNamePrefix = Apollo.GetString("ChatLog_From")
  2513. end
  2514. end
  2515.  
  2516. xml:AppendText( strWhisperNamePrefix, crText, self.strFontOption)
  2517.  
  2518. if tMessage.bGM then
  2519. xml:AppendImage(kstrGMIcon, 16, 16)
  2520. end
  2521.  
  2522. local strCross = tMessage.bCrossFaction and "true" or "false"--has to be a string or a number due to code restriction
  2523. xml:AppendText( strDisplayName, crPlayerName, self.strFontOption, {strCharacterName = strWhisperName, nReportId = tMessage.nReportId , strCrossFaction = strCross}, "Source")
  2524. end
  2525. xml:AppendText( strPresenceState .. Apollo.GetString("Chat_ColonBreak"), crChannel, self.strFontOption, "Left")
  2526. end
  2527.  
  2528. local xmlBubble = nil
  2529. if tMessage.bShowChatBubble then
  2530. xmlBubble = XmlDoc.new() -- This is the speech bubble form
  2531. xmlBubble:AddLine("", crChannel, self.strFontOption, "Center")
  2532. end
  2533.  
  2534. local bHasVisibleText = false
  2535. for idx, tSegment in ipairs( tMessage.arMessageSegments ) do
  2536. local strText = tSegment.strText
  2537. local bAlien = tSegment.bAlien or tMessage.bCrossFaction
  2538. local bShow = false
  2539.  
  2540. if self.eRoleplayOption == 3 then
  2541. bShow = not tSegment.bRolePlay
  2542. elseif self.eRoleplayOption == 2 then
  2543. bShow = tSegment.bRolePlay
  2544. else
  2545. bShow = true;
  2546. end
  2547.  
  2548. if bShow then
  2549. local crChatText = crText;
  2550. local crBubbleText = kstrColorChatRegular
  2551. local strChatFont = self.strFontOption
  2552. local strBubbleFont = kstrBubbleFont
  2553. local tLink = {}
  2554.  
  2555.  
  2556. if tSegment.uItem ~= nil then -- item link
  2557. -- replace me with correct colors
  2558. strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), tSegment.uItem:GetName())
  2559. crChatText = karEvalColors[tSegment.uItem:GetItemQuality()]
  2560. crBubbleText = ApolloColor.new("white")
  2561.  
  2562. tLink.strText = strText
  2563. tLink.uItem = tSegment.uItem
  2564.  
  2565. elseif tSegment.uQuest ~= nil then -- quest link
  2566. -- replace me with correct colors
  2567. strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), tSegment.uQuest:GetTitle())
  2568. crChatText = ApolloColor.new("green")
  2569. crBubbleText = ApolloColor.new("green")
  2570.  
  2571. tLink.strText = strText
  2572. tLink.uQuest = tSegment.uQuest
  2573.  
  2574. elseif tSegment.uArchiveArticle ~= nil then -- archive article
  2575. -- replace me with correct colors
  2576. strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), tSegment.uArchiveArticle:GetTitle())
  2577. crChatText = ApolloColor.new("ffb7a767")
  2578. crBubbleText = ApolloColor.new("ffb7a767")
  2579.  
  2580. tLink.strText = strText
  2581. tLink.uArchiveArticle = tSegment.uArchiveArticle
  2582.  
  2583. elseif tSegment.tNavPoint ~= nil then
  2584. -- replace me with correct colors
  2585. strText = String_GetWeaselString(Apollo.GetString("CRB_Brackets"), "NavPoint")
  2586. crChatText = ApolloColor.new("blue")
  2587. crBubbleText = ApolloColor.new("blue")
  2588.  
  2589. tLink.strText = strText
  2590. tLink.tNavPoint = tSegment.tNavPoint
  2591.  
  2592. else
  2593. if tSegment.bRolePlay then
  2594. crBubbleText = kstrColorChatRoleplay
  2595. strChatFont = self.strRPFontOption
  2596. strBubbleFont = kstrDialogFontRP
  2597. end
  2598.  
  2599. if bAlien or tSegment.bProfanity then -- Weak filter. Note only profanity is scrambled.
  2600. strChatFont = self.strAlienFontOption
  2601. strBubbleFont = self.strAlienFontOption
  2602. end
  2603. end
  2604.  
  2605. if next(tLink) == nil then
  2606. if eChannelType == ChatSystemLib.ChatChannel_AnimatedEmote then
  2607. local strCross = tMessage.bCrossFaction and "true" or "false"--has to be a string or a number due to code restriction
  2608. xml:AppendText(strText, crChatText, strChatFont, {strCharacterName = strWhisperName, nReportId = tMessage.nReportId, strCrossFaction = strCross}, "Source")
  2609. else
  2610. xml:AppendText(strText, crChatText, strChatFont)
  2611. end
  2612. else
  2613. local strLinkIndex = tostring( self:HelperSaveLink(tLink) )
  2614. -- append text can only save strings as attributes.
  2615. xml:AppendText(strText, crChatText, strChatFont, {strIndex=strLinkIndex} , "Link")
  2616. end
  2617.  
  2618. if xmlBubble then
  2619. xmlBubble:AppendText(strText, crBubbleText, strBubbleFont) -- Format for bubble; regular
  2620. end
  2621.  
  2622. bHasVisibleText = bHasVisibleText or self:HelperCheckForEmptyString(strText)
  2623. end
  2624. end
  2625.  
  2626. tQueuedMessage.bHasVisibleText = bHasVisibleText
  2627. tQueuedMessage.xml = xml
  2628. tQueuedMessage.xmlBubble = xmlBubble
  2629. end
  2630.  
  2631. function Bb_chat:HelperGetTimeStr()
  2632. --Toggle Visibility based on ui preference
  2633. local nVisibility = Apollo.GetConsoleVariable("hud.TimeDisplay")
  2634.  
  2635. local tTime = GameLib.GetLocalTime()
  2636. strTime = (string.format("%02d:%02d", tostring(tTime.nHour), tostring(tTime.nMinute)))
  2637.  
  2638. if nVisibility == 2 then --Local 12hr am/pm
  2639. local nHour = tTime.nHour > 12 and tTime.nHour - 12 or tTime.nHour == 0 and 12 or tTime.nHour
  2640.  
  2641. strTime = (string.format("%02d:%02d", tostring(nHour), tostring(tTime.nMinute)))
  2642. elseif nVisibility == 3 then --Server 24hr
  2643. tTime = GameLib.GetServerTime()
  2644.  
  2645. strTime = (string.format("%02d:%02d", tostring(tTime.nHour), tostring(tTime.nMinute)))
  2646. elseif nVisibility == 4 then --Server 12hr am/pm
  2647. tTime = GameLib.GetServerTime()
  2648. local nHour = tTime.nHour > 12 and tTime.nHour - 12 or tTime.nHour == 0 and 12 or tTime.nHour
  2649.  
  2650. strTime = (string.format("%02d:%02d", tostring(nHour), tostring(tTime.nMinute)))
  2651. end
  2652.  
  2653. strTime = strTime.." "
  2654. return strTime
  2655. end
  2656. function Bb_chat:HelperSaveLink(tLink)
  2657. self.tLinks[self.nNextLinkIndex] = tLink
  2658. self.nNextLinkIndex = self.nNextLinkIndex + 1
  2659. return self.nNextLinkIndex - 1
  2660. end
  2661.  
  2662. function Bb_chat:HelperAppendLink( wndEdit, tLink )
  2663. local tSelectedText = wndEdit:GetSel()
  2664.  
  2665. wndEdit:AddLink( tSelectedText.cpCaret, tLink.strText, tLink )
  2666. self:OnInputChanged(nil, wndEdit, wndEdit:GetText())
  2667. wndEdit:SetFocus()
  2668. end
  2669.  
  2670. function Bb_chat:HelperReplaceLinks(strText, arEditLinks)
  2671. local strReplacedText = ""
  2672.  
  2673. local nCurrentIdx = 1
  2674. local nLastIdx = strText:len()
  2675. while nCurrentIdx <= nLastIdx do
  2676. local nNextIdx = nCurrentIdx + 1
  2677.  
  2678. local bFound = false
  2679.  
  2680. for nEditIdx, tEditLink in pairs( arEditLinks ) do
  2681. if tEditLink.iMin <= nCurrentIdx and nCurrentIdx < tEditLink.iLim then
  2682.  
  2683. if tEditLink.data.uItem then
  2684. strReplacedText = strReplacedText .. tEditLink.data.uItem:GetChatLinkString()
  2685. elseif tEditLink.data.uQuest then
  2686. strReplacedText = strReplacedText .. tEditLink.data.uQuest:GetChatLinkString()
  2687. elseif tEditLink.data.uArchiveArticle then
  2688. strReplacedText = strReplacedText .. tEditLink.data.uArchiveArticle:GetChatLinkString()
  2689. end
  2690.  
  2691. if nNextIdx < tEditLink.iLim then
  2692. nNextIdx = tEditLink.iLim
  2693. end
  2694.  
  2695. bFound = true
  2696. break
  2697. end
  2698. end
  2699.  
  2700. if bFound == false then
  2701. strReplacedText = strReplacedText .. strText:sub(nCurrentIdx, nCurrentIdx)
  2702. end
  2703.  
  2704. nCurrentIdx = nNextIdx
  2705. end
  2706.  
  2707. return strReplacedText
  2708. end
  2709.  
  2710. function Bb_chat:HelperAddChannelToAll(channelAdded)
  2711. if self.tAllViewedChannels[channelAdded] ~= nil then
  2712. self.tAllViewedChannels[channelAdded] = self.tAllViewedChannels[channelAdded] + 1
  2713. else
  2714. self.tAllViewedChannels[channelAdded] = 1
  2715. end
  2716. end
  2717.  
  2718. function Bb_chat:HelperRemoveChannelFromAll(channelRemoved)
  2719. if self.tAllViewedChannels[channelRemoved] ~= nil then
  2720. self.tAllViewedChannels[channelRemoved] = self.tAllViewedChannels[channelRemoved] - 1
  2721.  
  2722. if self.tAllViewedChannels[channelRemoved] <= 0 then
  2723. self.tAllViewedChannels[channelRemoved] = nil
  2724. self:HelperRemoveChannelFromInputWindow(channelRemoved)
  2725. end
  2726. end
  2727. end
  2728.  
  2729. function Bb_chat:HelperRemoveChannelFromInputWindow(channelRemoved) -- used when we've totally removed a channel
  2730. for idx, wnd in pairs(self.tChatWindows) do
  2731. local tChatData = wnd:GetData()
  2732.  
  2733. if tChatData.channelCurrent:GetUniqueId() == channelRemoved then
  2734.  
  2735. local channelNew = self:HelperFindAViewedChannel()
  2736. local wndInput = wnd:FindChild("Input")
  2737.  
  2738. if channelNew ~= nil then
  2739. tChatData.channelCurrent = channelNew
  2740. wndInput:SetPrompt(tChatData.channelCurrent:GetCommand())
  2741. tChatData.crText = self.arChatColor[tChatData.channelCurrent:GetType()]
  2742. wndInput:SetPromptColor(tChatData.crText)
  2743.  
  2744. --TODO: Helper this since we do it other places
  2745. local strText = wndInput:GetText()
  2746. local strCommand = tChatData.channelCurrent:GetAbbreviation()
  2747.  
  2748. if strCommand == "" or strCommand == nil then
  2749. strCommand = tChatData.channelCurrent:GetCommand()
  2750. end
  2751.  
  2752. if strText == "" then
  2753. strText =String_GetWeaselString(Apollo.GetString("ChatLog_SlashPrefix"), strCommand.." ")
  2754. else
  2755. local tInput = ChatSystemLib.SplitInput(strText) -- get the existing message, ignore the old command
  2756. strText = String_GetWeaselString(Apollo.GetString("ChatLog_MessageToPlayer"), strCommand).." "..tInput.strMessage
  2757. end
  2758.  
  2759. wndInput:SetText(strText)
  2760. local crText = self.arChatColor[tChatData.channelCurrent:GetType()] or ApolloColor.new("white")
  2761. wndInput:SetTextColor(crText)
  2762. wndInput:SetFocus()
  2763. wndInput:SetSel(strText:len(), -1)
  2764.  
  2765. else
  2766. wndInput:SetPrompt("X")
  2767. wndInput:SetPromptColor(kcrInvalidColor)
  2768. end
  2769. end
  2770. end
  2771. end
  2772.  
  2773. function Bb_chat:HelperFindAViewedChannel()
  2774. local channelNew = nil
  2775. local nNewChannelIdx = nil
  2776. local tBaseChannels = ChatSystemLib.GetChannels()
  2777. local tChannelsWithInput = {}
  2778.  
  2779. for idx, channelCurrent in pairs(tBaseChannels) do
  2780. if channelCurrent:GetCommand() ~= nil and channelCurrent:GetCommand() ~= "" then
  2781. tChannelsWithInput[channelCurrent:GetType()] = true
  2782. end
  2783. end
  2784.  
  2785. for idx, channelCurrent in pairs(self.tAllViewedChannels) do
  2786. if self.tAllViewedChannels[idx] ~= nil and tChannelsWithInput[idx] ~= nil then
  2787. nNewChannelIdx = idx
  2788. break
  2789. end
  2790. end
  2791.  
  2792. if nNewChannelIdx == nil then
  2793. nNewChannelIdx = ChatSystemLib.ChatChannel_Say
  2794. end
  2795.  
  2796. for idx, channelCurrent in ipairs(tBaseChannels) do
  2797. if channelCurrent:GetType() == nNewChannelIdx then
  2798. channelNew = channelCurrent
  2799. break
  2800. end
  2801. end
  2802.  
  2803. return channelNew
  2804. end
  2805.  
  2806. function Bb_chat:HelperGetCurrentEditbox()
  2807. local wndEdit
  2808. -- find the last used chat window
  2809. for idx, wndCurrent in pairs(self.tChatWindows) do
  2810. local tData = wndCurrent:GetData()
  2811. if tData and not tData.bCombatLog and wndCurrent:FindChild("Input"):GetData() then
  2812. wndEdit = wndCurrent:FindChild("Input")
  2813. break
  2814. end
  2815. end
  2816.  
  2817. -- if none found, use the first on our list
  2818. if wndEdit == nil then
  2819. for idx, wndCurrent in pairs(self.tChatWindows) do
  2820. local tData = wndCurrent:GetData()
  2821. if tData and not tData.bCombatLog then
  2822. wndEdit = wndCurrent:FindChild("Input")
  2823. break
  2824. end
  2825. end
  2826. end
  2827.  
  2828. return wndEdit
  2829. end
  2830.  
  2831. -----------------------------------------------------------------------------------------------
  2832. -- Other Add-ons
  2833. -----------------------------------------------------------------------------------------------
  2834.  
  2835. function Bb_chat:OnTradeSkillSigilResult(eResult)
  2836. local tEnumTable = CraftingLib.CodeEnumTradeskillResult
  2837. local kstrTradeskillResultTable =
  2838. {
  2839. [tEnumTable.Success] = Apollo.GetString("EngravingStation_Success"),
  2840. [tEnumTable.InsufficentFund] = Apollo.GetString("EngravingStation_NeedMoreMoney"),
  2841. [tEnumTable.InvalidItem] = Apollo.GetString("EngravingStation_InvalidItem"),
  2842. [tEnumTable.InvalidSlot] = Apollo.GetString("EngravingStation_InvalidSlot"),
  2843. [tEnumTable.MissingEngravingStation] = Apollo.GetString("EngravingStation_StationTooFar"),
  2844. [tEnumTable.Unlocked] = Apollo.GetString("EngravingStation_UnlockSuccessfull"),
  2845. [tEnumTable.UnknownError] = Apollo.GetString("EngravingStation_Failure"),
  2846. [tEnumTable.RuneExists] = Apollo.GetString("EngravingStation_ExistingRune"),
  2847. [tEnumTable.MissingRune] = Apollo.GetString("EngravingStation_RuneMissing"),
  2848. [tEnumTable.DuplicateRune] = Apollo.GetString("EngravingStation_DuplicateRune"),
  2849. [tEnumTable.AttemptFailed] = Apollo.GetString("EngravingStation_Failure"),
  2850. [tEnumTable.RuneSlotLimit] = Apollo.GetString("EngravingStation_SlotLimitReached"),
  2851. }
  2852.  
  2853. Event_FireGenericEvent("GenericEvent_LootChannelMessage", kstrTradeskillResultTable[eResult])
  2854. end
  2855.  
  2856. local Bb_chatInstance = Bb_chat:new()
  2857. Bb_chatInstance:Init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement