Guest User

BlackBook.lua

a guest
Dec 8th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.16 KB | Gaming | 0 0
  1. local Postal = LibStub("AceAddon-3.0"):GetAddon("Postal")
  2. local Postal_BlackBook = Postal:NewModule("BlackBook", "AceEvent-3.0", "AceHook-3.0")
  3. local L = LibStub("AceLocale-3.0"):GetLocale("Postal")
  4. Postal_BlackBook.description = L["Adds a contact list next to the To: field."]
  5. Postal_BlackBook.description2 = L[ [[|cFFFFCC00*|r This module will list your contacts, friends, guild mates, alts and track the last 10 people you mailed.
  6. |cFFFFCC00*|r It will also autocomplete all names in your BlackBook.]] ]
  7.  
  8. -- luacheck: globals AUTOCOMPLETE_FLAG_ALL AUTOCOMPLETE_FLAG_BNET AUTOCOMPLETE_FLAG_NONE AUTOCOMPLETE_FLAG_FRIEND AUTOCOMPLETE_FLAG_IN_GUILD
  9.  
  10. local Postal_BlackBookButton
  11. local numFriendsOnList = 0
  12. local sorttable = {}
  13. local ignoresortlocale = {
  14. ["koKR"] = true,
  15. ["zhCN"] = true,
  16. ["zhTW"] = true,
  17. }
  18. local enableAltsMenu = true
  19. local enableAllAltsMenu = true
  20. local Postal_BlackBook_Autocomplete_Flags = {
  21. include = AUTOCOMPLETE_FLAG_ALL,
  22. exclude = AUTOCOMPLETE_FLAG_BNET,
  23. }
  24.  
  25. -- WoW 10.0 Release Show/Hide Frame Handlers
  26. function Postal_BlackBook:PLAYER_INTERACTION_MANAGER_FRAME_SHOW(eventName, ...)
  27. local paneType = ...
  28. if paneType == Enum.PlayerInteractionType.MailInfo then Postal_BlackBook:MAIL_SHOW() end
  29. end
  30.  
  31. function Postal_BlackBook:PLAYER_INTERACTION_MANAGER_FRAME_HIDE(eventName, ...)
  32. local paneType = ...
  33. if paneType == Enum.PlayerInteractionType.MailInfo then Postal_BlackBook:MAIL_CLOSED() end
  34. end
  35.  
  36. function Postal_BlackBook:OnEnable()
  37. if not Postal_BlackBookButton then
  38. -- Create the Menu Button
  39. Postal_BlackBookButton = CreateFrame("Button", "Postal_BlackBookButton", SendMailFrame)
  40. Postal_BlackBookButton:SetWidth(25)
  41. Postal_BlackBookButton:SetHeight(25)
  42. Postal_BlackBookButton:SetPoint("LEFT", SendMailNameEditBox, "RIGHT", -2, 2)
  43. Postal_BlackBookButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
  44. Postal_BlackBookButton:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Round")
  45. Postal_BlackBookButton:SetDisabledTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled")
  46. Postal_BlackBookButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
  47. Postal_BlackBookButton:SetScript("OnClick", function(self, button, down)
  48. if Postal_DropDownMenu.initialize ~= Postal_BlackBook.BlackBookMenu then
  49. CloseDropDownMenus()
  50. Postal_DropDownMenu.initialize = Postal_BlackBook.BlackBookMenu
  51. end
  52. ToggleDropDownMenu(1, nil, Postal_DropDownMenu, self:GetName(), 0, 0)
  53. end)
  54. Postal_BlackBookButton:SetScript("OnHide", Postal_DropDownMenu.HideMenu)
  55. end
  56.  
  57. local db = Postal.db.profile.BlackBook
  58.  
  59. SendMailNameEditBox:SetHistoryLines(15)
  60. self:RawHook("SendMailFrame_Reset", true)
  61. self:RawHook("MailFrameTab_OnClick", true)
  62. if db.UseAutoComplete then
  63. self:RawHookScript(SendMailNameEditBox, "OnChar")
  64. end
  65. self:HookScript(SendMailNameEditBox, "OnEditFocusGained")
  66. self:SecureHook("AutoComplete_Update")
  67. if Postal.WOWBCClassic then
  68. self:RegisterEvent("MAIL_SHOW")
  69. else
  70. Postal_BlackBook:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
  71. end
  72. self:RegisterEvent("PLAYER_ENTERING_WORLD", "AddAlt")
  73.  
  74. local exclude = bit.bor(db.AutoCompleteFriends and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_FRIEND,
  75. db.AutoCompleteGuild and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_IN_GUILD)
  76. Postal_BlackBook_Autocomplete_Flags.include = bit.bxor(
  77. db.ExcludeRandoms and (bit.bor(AUTOCOMPLETE_FLAG_FRIEND, AUTOCOMPLETE_FLAG_IN_GUILD)) or AUTOCOMPLETE_FLAG_ALL, exclude)
  78.  
  79. -- apply new flag filter to the editbox
  80. AutoCompleteEditBox_SetAutoCompleteSource(SendMailNameEditBox, GetAutoCompleteResults, Postal_BlackBook_Autocomplete_Flags.include, Postal_BlackBook_Autocomplete_Flags.exclude)
  81.  
  82. -- Delete Real ID database. Patch 4.0.1 onwards no longer allows addons to obtain Real ID information.
  83. Postal.db.global.BlackBook.realID = nil
  84. db.AutoCompleteRealIDFriends = nil
  85.  
  86. -- Delete old recent data without faction and realm data
  87. for i = #Postal.db.profile.BlackBook.recent, 1, -1 do
  88. local p, r, f = strsplit("|", Postal.db.profile.BlackBook.recent[i])
  89. if (not r) or (not f) then
  90. tremove(Postal.db.profile.BlackBook.recent, i)
  91. end
  92. end
  93.  
  94. -- For enabling after a disable
  95. Postal_BlackBookButton:Show()
  96. end
  97.  
  98. function Postal_BlackBook:OnDisable()
  99. -- Disabling modules unregisters all events/hook automatically
  100. SendMailNameEditBox:SetHistoryLines(1)
  101. Postal_BlackBookButton:Hide()
  102. SendMailNameEditBox.autoCompleteParams = AUTOCOMPLETE_LIST.MAIL
  103. end
  104.  
  105. function Postal_BlackBook:MAIL_SHOW()
  106. if Postal.WOWBCClassic then
  107. self:RegisterEvent("MAIL_CLOSED", "Reset")
  108. else
  109. Postal_BlackBook:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE", "Reset")
  110. end
  111. self:RegisterEvent("PLAYER_LEAVING_WORLD", "Reset")
  112. if self.AddAlt then self:AddAlt() end
  113. end
  114.  
  115. function Postal_BlackBook:MAIL_CLOSED()
  116. end
  117.  
  118. function Postal_BlackBook:Reset(event)
  119. if Postal.WOWBCClassic then
  120. self:UnregisterEvent("MAIL_CLOSED")
  121. else
  122. self:UnregisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
  123. end
  124. self:UnregisterEvent("PLAYER_LEAVING_WORLD")
  125. end
  126.  
  127. -- We do this once on MAIL_SHOW because UnitFactionGroup() is only valid after
  128. -- PLAYER_ENTERING_WORLD and because Postal might be LoD due to AddOnLoader
  129. -- and PLAYER_ENTERING_WORLD won't fire in that scenerio.
  130. function Postal_BlackBook:AddAlt()
  131. local realm = GetRealmName()
  132. local faction = UnitFactionGroup("player")
  133. local player = UnitName("player")
  134. local level = UnitLevel("player")
  135. local _, class = UnitClass("player")
  136. if not realm or not faction or not player or not level or not class then return end
  137. local namestring = ("%s|%s|%s|%s|%s"):format(player, realm, faction, level, class)
  138. local db = Postal.db.global.BlackBook.alts
  139. enableAltsMenu = false
  140. enableAllAltsMenu = false
  141. for i = #db, 1, -1 do
  142. local p, r, f, l, c = strsplit("|", db[i])
  143. if p == player and r == realm and f == faction then
  144. tremove(db, i)
  145. end
  146. if p ~= player and r == realm and f == faction then
  147. enableAltsMenu = true
  148. end
  149. if p ~= player or r ~= realm or f ~= faction then
  150. enableAllAltsMenu = true
  151. end
  152. end
  153. tinsert(db, namestring)
  154. table.sort(db)
  155. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  156. self.AddAlt = nil -- Kill ourselves so we only run it once
  157. end
  158.  
  159. function Postal_BlackBook.DeleteAlt(dropdownbutton, arg1, arg2, checked)
  160. local realm = GetRealmName()
  161. local faction = UnitFactionGroup("player")
  162. local player = UnitName("player")
  163. local db = Postal.db.global.BlackBook.alts
  164. enableAltsMenu = false
  165. enableAllAltsMenu = false
  166. for i = #db, 1, -1 do
  167. if arg1 == db[i] then
  168. tremove(db, i)
  169. else
  170. local p, r, f = strsplit("|", db[i])
  171. if r == realm and f == faction and p ~= player then
  172. enableAltsMenu = true
  173. end
  174. if r ~= realm or f ~= faction or p ~= player then
  175. enableAllAltsMenu = true
  176. end
  177. end
  178. end
  179. CloseDropDownMenus()
  180. end
  181.  
  182. -- Only called on a mail that is sent successfully
  183. function Postal_BlackBook:SendMailFrame_Reset()
  184. local name = strtrim(SendMailNameEditBox:GetText())
  185. if name == "" then return self.hooks["SendMailFrame_Reset"]() end
  186. SendMailNameEditBox:AddHistoryLine(name)
  187.  
  188. local realm = GetRealmName()
  189. local faction = UnitFactionGroup("player")
  190. if not realm or not faction then return self.hooks["SendMailFrame_Reset"]() end
  191.  
  192. local namestring = ("%s|%s|%s"):format(name, realm, faction)
  193. local db = Postal.db.profile.BlackBook.recent
  194. for k = 1, #db do
  195. if namestring == db[k] then tremove(db, k) break end
  196. end
  197. tinsert(db, 1, namestring)
  198. for k = #db, 21, -1 do
  199. tremove(db, k)
  200. end
  201. local a, b, c = self.hooks["SendMailFrame_Reset"]()
  202. if Postal.db.profile.BlackBook.AutoFill then
  203. SendMailNameEditBox:SetText(name)
  204. SendMailNameEditBox:HighlightText()
  205. end
  206. return a, b, c
  207. end
  208.  
  209. function Postal_BlackBook.ClearRecent(dropdownbutton, arg1, arg2, checked)
  210. wipe(Postal.db.profile.BlackBook.recent)
  211. CloseDropDownMenus()
  212. end
  213.  
  214. function Postal_BlackBook:MailFrameTab_OnClick(button, tab)
  215. self.hooks["MailFrameTab_OnClick"](button, tab)
  216. if Postal.db.profile.BlackBook.AutoFill and tab == 2 then
  217. local realm = GetRealmName()
  218. local faction = UnitFactionGroup("player")
  219. local player = UnitName("player")
  220.  
  221. -- Find the first eligible recently mailed
  222. for i = 1, #Postal.db.profile.BlackBook.recent do
  223. local p, r, f = strsplit("|", Postal.db.profile.BlackBook.recent[i])
  224. if r == realm and f == faction and p ~= player then
  225. if p and SendMailNameEditBox:GetText() == "" then
  226. SendMailNameEditBox:SetText(p)
  227. SendMailNameEditBox:HighlightText()
  228. break
  229. end
  230. end
  231. end
  232. end
  233. end
  234.  
  235. function Postal_BlackBook:OnEditFocusGained(editbox, ...)
  236. -- Most other addons aren't hooking properly and do not pass in editbox at all.
  237. SendMailNameEditBox:HighlightText()
  238. end
  239.  
  240. function Postal_BlackBook:AutoComplete_Update(parent, text, cursorPosition)
  241. if parent == SendMailNameEditBox and Postal.db.profile.BlackBook.DisableBlizzardAutoComplete then
  242. AutoComplete_HideIfAttachedTo(parent)
  243. end
  244. end
  245.  
  246. -- OnChar fires before OnTextChanged
  247. -- OnChar does not fire for Backspace, Delete keys that shorten the text
  248. -- Hook player name autocomplete to look in our dbs first
  249. function Postal_BlackBook:OnChar(editbox, ...)
  250. if editbox:GetUTF8CursorPosition() ~= strlenutf8(editbox:GetText()) then return end
  251.  
  252. local db = Postal.db.profile.BlackBook
  253. local text = strupper(editbox:GetText())
  254. local textlen = strlen(text)
  255. local realm = GetRealmName()
  256. local faction = UnitFactionGroup("player")
  257. local player = UnitName("player")
  258. local newname
  259.  
  260. -- Check all alt list
  261. if db.AutoCompleteAllAlts then
  262. local nosptext = text:gsub("%s*","") -- ignore spaces in matching fully-qualified names
  263. local db = Postal.db.global.BlackBook.alts
  264. for i = 1, #db do
  265. local p, r, f = strsplit("|", db[i])
  266. if p ~= player and r ~= realm then
  267. if strfind(strupper(p.."-"..r):gsub("%s*",""), nosptext, 1, 1) == 1 then
  268. newname = p.."-"..r
  269. break
  270. end
  271. end
  272. end
  273. end
  274.  
  275. -- Check alt list
  276. if db.AutoCompleteAlts then
  277. local db = Postal.db.global.BlackBook.alts
  278. for i = 1, #db do
  279. local p, r, f = strsplit("|", db[i])
  280. if r == realm and f == faction and p ~= player then
  281. if strfind(strupper(p), text, 1, 1) == 1 then
  282. newname = p
  283. break
  284. end
  285. end
  286. end
  287. end
  288.  
  289.  
  290. -- Check recent list
  291. if not newname and db.AutoCompleteRecent then
  292. local db2 = db.recent
  293. for j = 1, #db2 do
  294. local p, r, f = strsplit("|", db2[j])
  295. if r == realm and f == faction and p ~= player then
  296. if strfind(strupper(p), text, 1, 1) == 1 then
  297. newname = p
  298. break
  299. end
  300. end
  301. end
  302. end
  303.  
  304. -- Check contacts list
  305. if not newname and db.AutoCompleteContacts then
  306. local db2 = db.contacts
  307. for j = 1, #db2 do
  308. local name = db2[j]
  309. if strfind(strupper(name), text, 1, 1) == 1 then
  310. newname = name
  311. break
  312. end
  313. end
  314. end
  315.  
  316. -- Check RealID friends that are online :: rewrite due to API changes - Jonny
  317. if not newname and db.AutoCompleteFriends then
  318. local numBNetTotal, numBNetOnline = BNGetNumFriends()
  319. for i = 1, numBNetOnline do
  320. if Postal.WOWRetail then
  321. local accountInfo = C_BattleNet.GetFriendAccountInfo(i)
  322. if (accountInfo.gameAccountInfo.characterName and accountInfo.gameAccountInfo.clientProgram == BNET_CLIENT_WOW and CanCooperateWithGameAccount(accountInfo) and accountInfo.gameAccountInfo.wowProjectID == 1 ) then
  323. if strfind(strupper(accountInfo.gameAccountInfo.characterName), text, 1, 1) == 1 then
  324. newname = accountInfo.gameAccountInfo.characterName
  325. break
  326. end
  327. end
  328. end
  329. if Postal.WOWClassic or Postal.WOWBCClassic or Postal.WOWWotLKClassic or Postal.WOWCataClassic or Postal.WOWMists then
  330. local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(i)
  331. if (toonName and client == BNET_CLIENT_WOW and CanCooperateWithGameAccount(toonID)) then
  332. if strfind(strupper(toonName), text, 1, 1) == 1 then
  333. newname = toonName
  334. break
  335. end
  336. end
  337. end
  338. end
  339. end
  340.  
  341. -- The Blizzard autocomplete is borked for guild. So we implement our own for guild autocomplete
  342. if not newname and db.AutoCompleteGuild and IsInGuild() then
  343. local numMembers, numOnline = GetNumGuildMembers(true)
  344. for i = 1, numMembers do
  345. local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile, canSoR = GetGuildRosterInfo(i)
  346. if strfind(strupper(name), text, 1, 1) == 1 then
  347. newname = name
  348. break
  349. end
  350. end
  351. end
  352.  
  353. -- Call the original Blizzard function to autocomplete and for its popup
  354. self.hooks[SendMailNameEditBox].OnChar(editbox, ...)
  355.  
  356. -- Set our match if we found one (overriding Blizzard's match if there's one)
  357. if newname then
  358. editbox:SetText(newname)
  359. editbox:HighlightText(textlen, -1)
  360. editbox:SetCursorPosition(textlen)
  361. end
  362. end
  363.  
  364. function Postal_BlackBook.SetSendMailName(dropdownbutton, arg1, arg2, checked)
  365. SendMailNameEditBox:SetText(arg1)
  366. if SendMailNameEditBox:HasFocus() then SendMailSubjectEditBox:SetFocus() end
  367. CloseDropDownMenus()
  368. end
  369.  
  370. function Postal_BlackBook.AddContact(dropdownbutton, arg1, arg2, checked)
  371. local name = strtrim(SendMailNameEditBox:GetText())
  372. if name == "" then return end
  373. local db = Postal.db.profile.BlackBook.contacts
  374. for k = 1, #db do
  375. if name == db[k] then return end
  376. end
  377. tinsert(db, name)
  378. table.sort(db)
  379. end
  380.  
  381. function Postal_BlackBook.RemoveContact(dropdownbutton, arg1, arg2, checked)
  382. local name = strtrim(SendMailNameEditBox:GetText())
  383. if name == "" then return end
  384. local db = Postal.db.profile.BlackBook.contacts
  385. for k = 1, #db do
  386. if name == db[k] then tremove(db, k) return end
  387. end
  388. end
  389.  
  390. function Postal_BlackBook:SortAndCountNumFriends()
  391. wipe(sorttable)
  392. local numFriends = C_FriendList.GetNumFriends()
  393. for i = 1, numFriends do
  394. sorttable[i] = C_FriendList.GetFriendInfoByIndex(i).name
  395. end
  396.  
  397. -- Sort the list
  398. if numFriends > 0 and not ignoresortlocale[GetLocale()] then table.sort(sorttable) end
  399.  
  400. -- Store upvalue
  401. numFriendsOnList = numFriends
  402. return numFriends
  403. end
  404.  
  405. function Postal_BlackBook.BlackBookMenu(self, level)
  406. if not level then return end
  407. local altstable = {}
  408. local info = self.info
  409. local numAltsOnList = 0
  410. wipe(info)
  411. wipe(altstable)
  412. if enableAltsMenu then
  413. local db = Postal.db.global.BlackBook.alts
  414. local realm = GetRealmName()
  415. local faction = UnitFactionGroup("player")
  416. local player = UnitName("player")
  417. for k in pairs(db) do
  418. local p, r, f, l, c = strsplit("|", db[k])
  419. if r == realm and f == faction and p ~= player then
  420. numAltsOnList = numAltsOnList + 1
  421. table.insert(altstable,db[k])
  422. end
  423. end
  424. end
  425.  
  426. if level == 1 then
  427. info.isTitle = 1
  428. info.text = L["Contacts"]
  429. info.notCheckable = 1
  430. UIDropDownMenu_AddButton(info, level)
  431.  
  432. info.disabled = nil
  433. info.isTitle = nil
  434.  
  435. local db = Postal.db.profile.BlackBook.contacts
  436. for i = 1, #db do
  437. info.text = db[i]
  438. info.func = Postal_BlackBook.SetSendMailName
  439. info.arg1 = db[i]
  440. UIDropDownMenu_AddButton(info, level)
  441. end
  442.  
  443. info.arg1 = nil
  444. if #db > 0 then
  445. info.disabled = 1
  446. info.text = nil
  447. info.func = nil
  448. UIDropDownMenu_AddButton(info, level)
  449. info.disabled = nil
  450. end
  451.  
  452. info.text = L["Add Contact"]
  453. info.func = Postal_BlackBook.AddContact
  454. UIDropDownMenu_AddButton(info, level)
  455.  
  456. info.text = L["Remove Contact"]
  457. info.func = Postal_BlackBook.RemoveContact
  458. UIDropDownMenu_AddButton(info, level)
  459.  
  460. info.disabled = 1
  461. info.text = nil
  462. info.func = nil
  463. UIDropDownMenu_AddButton(info, level)
  464.  
  465. info.hasArrow = 1
  466. info.keepShownOnClick = 1
  467. info.func = self.UncheckHack
  468.  
  469. info.disabled = #Postal.db.profile.BlackBook.recent == 0
  470. info.text = L["Recently Mailed"]
  471. info.value = "recent"
  472. UIDropDownMenu_AddButton(info, level)
  473.  
  474. info.disabled = not enableAltsMenu
  475. info.text = L["Alts"]
  476. info.value = "alt"
  477. UIDropDownMenu_AddButton(info, level)
  478.  
  479. info.disabled = not enableAllAltsMenu
  480. info.text = L["All Alts"]
  481. info.value = "allalt"
  482. UIDropDownMenu_AddButton(info, level)
  483.  
  484. info.disabled = Postal_BlackBook:SortAndCountNumFriends() == 0
  485. info.text = L["Friends"]
  486. info.value = "friend"
  487. UIDropDownMenu_AddButton(info, level)
  488.  
  489. info.disabled = not IsInGuild()
  490. info.text = L["Guild"]
  491. info.value = "guild"
  492. UIDropDownMenu_AddButton(info, level)
  493.  
  494. wipe(info)
  495. info.disabled = 1
  496. info.notCheckable = 1
  497. UIDropDownMenu_AddButton(info, level)
  498. info.disabled = nil
  499.  
  500. info.text = CLOSE
  501. info.func = self.HideMenu
  502. UIDropDownMenu_AddButton(info, level)
  503.  
  504. elseif level == 2 then
  505. info.notCheckable = 1
  506. if UIDROPDOWNMENU_MENU_VALUE == "recent" then
  507. local realm = GetRealmName()
  508. local faction = UnitFactionGroup("player")
  509. local player = UnitName("player")
  510. local db = Postal.db.profile.BlackBook.recent
  511. if #db == 0 then return end
  512. for i = 1, #db do
  513. local p, r, f = strsplit("|", db[i])
  514. if r == realm and f == faction and p ~= player then
  515. info.text = p
  516. info.func = Postal_BlackBook.SetSendMailName
  517. info.arg1 = p
  518. UIDropDownMenu_AddButton(info, level)
  519. end
  520. end
  521.  
  522. info.disabled = 1
  523. info.text = nil
  524. info.func = nil
  525. info.arg1 = nil
  526. UIDropDownMenu_AddButton(info, level)
  527. info.disabled = nil
  528.  
  529. info.text = L["Clear list"]
  530. info.func = Postal_BlackBook.ClearRecent
  531. info.arg1 = nil
  532. UIDropDownMenu_AddButton(info, level)
  533.  
  534. elseif UIDROPDOWNMENU_MENU_VALUE == "alt" then
  535. if not enableAltsMenu then return end
  536. local db = altstable
  537. info.notCheckable = 1
  538. -- 8 or less, don't need multi level menus
  539. if numAltsOnList > 0 and numAltsOnList <= 8 then
  540. for i = 1, numAltsOnList do
  541. local p, r, f, l, c = strsplit("|", db[i])
  542. if l and c then
  543. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  544. info.text = format("%s |cff%.2x%.2x%.2x(%d %s)|r", p, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  545. else
  546. info.text = p
  547. end
  548. info.func = Postal_BlackBook.SetSendMailName
  549. info.arg1 = p
  550. UIDropDownMenu_AddButton(info, level)
  551. end
  552.  
  553. info.disabled = 1
  554. info.text = nil
  555. info.func = nil
  556. info.arg1 = nil
  557. UIDropDownMenu_AddButton(info, level)
  558. info.disabled = nil
  559.  
  560. info.text = L["Delete"]
  561. info.hasArrow = 1
  562. info.keepShownOnClick = 1
  563. info.func = self.UncheckHack
  564. info.value = "deletealt"
  565. UIDropDownMenu_AddButton(info, level)
  566. -- More than 8 people, split the list into multiple sublists of 8
  567. elseif numAltsOnList > 8 then
  568. info.hasArrow = 1
  569. info.keepShownOnClick = 1
  570. info.func = self.UncheckHack
  571. for i = 1, math.ceil(numAltsOnList/8) do
  572. info.text = L["Part %d"]:format(i)
  573. info.value = "sapart"..i
  574. UIDropDownMenu_AddButton(info, level)
  575. end
  576. end
  577. -- ensure long lists stay on screen
  578. if DropDownList2 then DropDownList2:SetClampedToScreen(true) end
  579. if DropDownList3 then DropDownList3:SetClampedToScreen(true) end
  580. if DropDownList4 then DropDownList4:SetClampedToScreen(true) end
  581.  
  582. elseif UIDROPDOWNMENU_MENU_VALUE == "allalt" then
  583. if not enableAllAltsMenu then return end
  584. local db = Postal.db.global.BlackBook.alts
  585. local realm = GetRealmName()
  586. local faction = UnitFactionGroup("player")
  587. local player = UnitName("player")
  588. local plre = player.."-"..realm
  589. info.notCheckable = 1
  590. -- 8 or less, don't need multi level menus
  591. if #db > 0 and #db <= 8 then
  592. for i = 1, #db do
  593. local p, r, f, l, c = strsplit("|", db[i])
  594. local pr = p.."-"..r
  595. if (pr ~= plre ) then
  596. if l and c then
  597. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  598. info.text = format("%s-%s-%s |cff%.2x%.2x%.2x(%d %s)|r", p, r, f, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  599. else
  600. info.text = ("%s-%s-%s"):format(p, r, f)
  601. end
  602. info.func = Postal_BlackBook.SetSendMailName
  603. info.arg1 = ("%s-%s"):format(p, r)
  604. UIDropDownMenu_AddButton(info, level)
  605. end
  606. end
  607. info.disabled = 1
  608. info.text = nil
  609. info.func = nil
  610. info.arg1 = nil
  611. UIDropDownMenu_AddButton(info, level)
  612. info.disabled = nil
  613.  
  614. info.text = L["Delete"]
  615. info.hasArrow = 1
  616. info.keepShownOnClick = 1
  617. info.func = self.UncheckHack
  618. info.value = "deleteallalt"
  619. UIDropDownMenu_AddButton(info, level)
  620. -- More than 8 people, split the list into multiple sublists of 8
  621. elseif #db > 8 then
  622. info.hasArrow = 1
  623. info.keepShownOnClick = 1
  624. info.func = self.UncheckHack
  625. for i = 1, math.ceil(#db/8) do
  626. info.text = L["Part %d"]:format(i)
  627. info.value = "aapart"..i
  628. UIDropDownMenu_AddButton(info, level)
  629. end
  630. end
  631. -- ensure long lists stay on screen
  632. if DropDownList2 then DropDownList2:SetClampedToScreen(true) end
  633. if DropDownList3 then DropDownList3:SetClampedToScreen(true) end
  634. if DropDownList4 then DropDownList4:SetClampedToScreen(true) end
  635.  
  636. elseif UIDROPDOWNMENU_MENU_VALUE == "friend" then
  637. -- Friends list
  638. local numFriends = Postal_BlackBook:SortAndCountNumFriends()
  639.  
  640. -- 8 or less, don't need multi level menus
  641. if numFriends > 0 and numFriends <= 8 then
  642. for i = 1, numFriends do
  643. local name = sorttable[i]
  644. info.text = name
  645. info.func = Postal_BlackBook.SetSendMailName
  646. info.arg1 = name
  647. UIDropDownMenu_AddButton(info, level)
  648. end
  649. elseif numFriends > 8 then
  650. -- More than 8 people, split the list into multiple sublists of 8
  651. info.hasArrow = 1
  652. info.keepShownOnClick = 1
  653. info.func = self.UncheckHack
  654. for i = 1, math.ceil(numFriends/8) do
  655. info.text = L["Part %d"]:format(i)
  656. info.value = "fpart"..i
  657. UIDropDownMenu_AddButton(info, level)
  658. end
  659. end
  660.  
  661. elseif UIDROPDOWNMENU_MENU_VALUE == "guild" then
  662. if not IsInGuild() then return end
  663. local numFriends = GetNumGuildMembers(true)
  664. for i = 1, numFriends do
  665. local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile, canSoR = GetGuildRosterInfo(i)
  666. local c = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[classFileName] or RAID_CLASS_COLORS[classFileName]
  667. sorttable[i] = format("%s |cffffd200(%s)|r |cff%.2x%.2x%.2x(%d %s)|r", name, rank, c.r*255, c.g*255, c.b*255, level, class)
  668. end
  669. for i = #sorttable, numFriends+1, -1 do
  670. sorttable[i] = nil
  671. end
  672. if not ignoresortlocale[GetLocale()] then table.sort(sorttable) end
  673. -- 8 or less, don't need multi level menus
  674. if numFriends > 0 and numFriends <= 8 then
  675. for i = 1, numFriends do
  676. info.text = sorttable[i]
  677. info.func = Postal_BlackBook.SetSendMailName
  678. info.arg1 = strmatch(sorttable[i], "(.*) |cffffd200")
  679. UIDropDownMenu_AddButton(info, level)
  680. end
  681. -- More than 8 people, split the list into multiple sublists of 8
  682. elseif numFriends > 8 then
  683. info.hasArrow = 1
  684. info.keepShownOnClick = 1
  685. info.func = self.UncheckHack
  686. for i = 1, math.ceil(numFriends/8) do
  687. info.text = L["Part %d"]:format(i)
  688. info.value = "gpart"..i
  689. UIDropDownMenu_AddButton(info, level)
  690. end
  691. end
  692. end
  693.  
  694. elseif level >= 3 then
  695. info.notCheckable = 1
  696. if UIDROPDOWNMENU_MENU_VALUE == "deletealt" or UIDROPDOWNMENU_MENU_VALUE == "deleteallalt" then
  697. local all = ( UIDROPDOWNMENU_MENU_VALUE == "deleteallalt" )
  698. local db = Postal.db.global.BlackBook.alts
  699. local realm = GetRealmName()
  700. local faction = UnitFactionGroup("player")
  701. local player = UnitName("player")
  702. if all then db = Postal.db.global.BlackBook.alts else db = altstable end
  703. for i = 1, #db do
  704. local p, r, f, l, c = strsplit("|", db[i])
  705. if (p ~= player or r ~= realm or f ~= faction) or all then
  706. if all then
  707. p = all and p.."-"..r.."-"..f or p
  708. else
  709. p = all and p.."-"..r or p
  710. end
  711. if l and c then
  712. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  713. info.text = format("%s |cff%.2x%.2x%.2x(%d %s)|r", p, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  714. else
  715. info.text = p
  716. end
  717. info.func = Postal_BlackBook.DeleteAlt
  718. info.arg1 = db[i]
  719. UIDropDownMenu_AddButton(info, level)
  720. end
  721. end
  722.  
  723. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "delsapart") then
  724. local db = altstable
  725. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "delsapart(%d+)")) * 8 - 7
  726. local endIndex = math.min(startIndex+7, numAltsOnList)
  727. for i = startIndex, endIndex do
  728. local name = sorttable[i]
  729. local p, r, f, l, c = strsplit("|", db[i])
  730. p = all and p.."-"..r or p
  731. if l and c then
  732. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  733. info.text = format("%s |cff%.2x%.2x%.2x(%d %s)|r", p, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  734. else
  735. info.text = p
  736. end
  737. info.func = Postal_BlackBook.DeleteAlt
  738. info.arg1 = db[i]
  739. UIDropDownMenu_AddButton(info, level)
  740. end
  741.  
  742. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "delaapart") then
  743. local all = strfind(UIDROPDOWNMENU_MENU_VALUE, "delaapart")
  744. local db = Postal.db.global.BlackBook.alts
  745. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "delaapart(%d+)")) * 8 - 7
  746. local endIndex = math.min(startIndex+7, #db)
  747. local realm = GetRealmName()
  748. local faction = UnitFactionGroup("player")
  749. local player = UnitName("player")
  750. for i = startIndex, endIndex do
  751. local p, r, f, l, c = strsplit("|", db[i])
  752. if (p ~= player or r ~= realm or f ~= faction) or all then
  753. p = all and p.."-"..r.."-"..f or p
  754. if l and c then
  755. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  756. info.text = format("%s |cff%.2x%.2x%.2x(%d %s)|r", p, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  757. else
  758. info.text = p
  759. end
  760. info.func = Postal_BlackBook.DeleteAlt
  761. info.arg1 = db[i]
  762. UIDropDownMenu_AddButton(info, level)
  763. end
  764. end
  765.  
  766. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "sapart") then
  767. local db = altstable
  768. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "sapart(%d+)")) * 8 - 7
  769. local endIndex = math.min(startIndex+8, numAltsOnList)
  770. for i = startIndex, endIndex do
  771. local name = sorttable[i]
  772. local p, r, f, l, c = strsplit("|", db[i])
  773. local pr = p.."-"..r
  774. if (pr ~= plre ) then
  775. if l and c then
  776. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  777. info.text = format("%s |cff%.2x%.2x%.2x(%d %s)|r", p, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  778. else
  779. info.text = p
  780. end
  781. info.func = Postal_BlackBook.SetSendMailName
  782. info.arg1 = p
  783. UIDropDownMenu_AddButton(info, level)
  784. end
  785. end
  786. info.disabled = 1
  787. info.text = nil
  788. info.func = nil
  789. info.arg1 = nil
  790. UIDropDownMenu_AddButton(info, level)
  791. info.disabled = nil
  792.  
  793. info.text = L["Delete"]
  794. info.hasArrow = 1
  795. info.keepShownOnClick = 1
  796. info.func = self.UncheckHack
  797. info.value = "delsapart"..tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "sapart(%d+)"))
  798. UIDropDownMenu_AddButton(info, level)
  799.  
  800. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "aapart") then
  801. local db = Postal.db.global.BlackBook.alts
  802. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "aapart(%d+)")) * 8 - 7
  803. local endIndex = math.min(startIndex+7, #db)
  804. for i = startIndex, endIndex do
  805. local name = sorttable[i]
  806. local p, r, f, l, c = strsplit("|", db[i])
  807. local pr = p.."-"..r
  808. if (pr ~= plre ) then
  809. if l and c then
  810. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  811. info.text = format("%s-%s-%s |cff%.2x%.2x%.2x(%d %s)|r", p, r, f, clr.r*255, clr.g*255, clr.b*255, l, LOCALIZED_CLASS_NAMES_MALE[c])
  812. else
  813. info.text = ("%s-%s-%s"):format(p, r, f)
  814. end
  815. info.func = Postal_BlackBook.SetSendMailName
  816. info.arg1 = ("%s-%s"):format(p, r)
  817. UIDropDownMenu_AddButton(info, level)
  818. end
  819. end
  820. info.disabled = 1
  821. info.text = nil
  822. info.func = nil
  823. info.arg1 = nil
  824. UIDropDownMenu_AddButton(info, level)
  825. info.disabled = nil
  826.  
  827. info.text = L["Delete"]
  828. info.hasArrow = 1
  829. info.keepShownOnClick = 1
  830. info.func = self.UncheckHack
  831. info.value = "delaapart"..tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "aapart(%d+)"))
  832. UIDropDownMenu_AddButton(info, level)
  833.  
  834. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "fpart") then
  835. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "fpart(%d+)")) * 8 - 7
  836. local endIndex = math.min(startIndex+7, numFriendsOnList)
  837. for i = startIndex, endIndex do
  838. local name = sorttable[i]
  839. info.text = name
  840. info.func = Postal_BlackBook.SetSendMailName
  841. info.arg1 = name
  842. UIDropDownMenu_AddButton(info, level)
  843. end
  844.  
  845. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "gpart") then
  846. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "gpart(%d+)")) * 8 - 7
  847. local endIndex = math.min(startIndex+7, (GetNumGuildMembers(true)))
  848. for i = startIndex, endIndex do
  849. local name = sorttable[i]
  850. info.text = sorttable[i]
  851. info.func = Postal_BlackBook.SetSendMailName
  852. info.arg1 = strmatch(sorttable[i], "(.*) |cffffd200")
  853. UIDropDownMenu_AddButton(info, level)
  854. end
  855. end
  856.  
  857. end
  858. end
  859.  
  860. function Postal_BlackBook.SaveFriendGuildOption(dropdownbutton, arg1, arg2, checked)
  861. Postal.SaveOption(dropdownbutton, arg1, arg2, checked)
  862. local db = Postal.db.profile.BlackBook
  863. local exclude = bit.bor(db.AutoCompleteFriends and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_FRIEND,
  864. db.AutoCompleteGuild and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_IN_GUILD)
  865. Postal_BlackBook_Autocomplete_Flags.include = bit.bxor(
  866. db.ExcludeRandoms and (bit.bor(AUTOCOMPLETE_FLAG_FRIEND, AUTOCOMPLETE_FLAG_IN_GUILD)) or AUTOCOMPLETE_FLAG_ALL, exclude)
  867. end
  868.  
  869. function Postal_BlackBook.SetAutoComplete(dropdownbutton, arg1, arg2, checked)
  870. local self = Postal_BlackBook
  871. Postal.db.profile.BlackBook.UseAutoComplete = not checked
  872. if checked then
  873. if self:IsHooked(SendMailNameEditBox, "OnChar") then
  874. self:Unhook(SendMailNameEditBox, "OnChar")
  875. end
  876. else
  877. if not self:IsHooked(SendMailNameEditBox, "OnChar") then
  878. self:RawHookScript(SendMailNameEditBox, "OnChar")
  879. end
  880. end
  881. end
  882.  
  883. function Postal_BlackBook.ModuleMenu(self, level)
  884. if not level then return end
  885. local info = self.info
  886. wipe(info)
  887. info.isNotRadio = 1
  888. if level == 1 + self.levelAdjust then
  889. info.keepShownOnClick = 1
  890. info.text = L["Autofill last person mailed"]
  891. info.func = Postal.SaveOption
  892. info.arg1 = "BlackBook"
  893. info.arg2 = "AutoFill"
  894. info.checked = Postal.db.profile.BlackBook.AutoFill
  895. UIDropDownMenu_AddButton(info, level)
  896.  
  897. info.hasArrow = 1
  898. info.keepShownOnClick = 1
  899. info.func = self.UncheckHack
  900. info.checked = nil
  901. info.arg1 = nil
  902. info.arg2 = nil
  903. info.text = L["Name auto-completion options"]
  904. info.value = "AutoComplete"
  905. UIDropDownMenu_AddButton(info, level)
  906. local listFrame = _G["DropDownList"..level]
  907. self.UncheckHack(_G[listFrame:GetName().."Button"..listFrame.numButtons])
  908.  
  909. elseif level == 2 + self.levelAdjust then
  910. local db = Postal.db.profile.BlackBook
  911. info.arg1 = "BlackBook"
  912.  
  913. if UIDROPDOWNMENU_MENU_VALUE == "AutoComplete" then
  914. info.text = L["Use Postal's auto-complete"]
  915. info.arg2 = "UseAutoComplete"
  916. info.checked = db.UseAutoComplete
  917. info.func = Postal_BlackBook.SetAutoComplete
  918. UIDropDownMenu_AddButton(info, level)
  919.  
  920. info.func = Postal.SaveOption
  921. info.disabled = not db.UseAutoComplete
  922. info.keepShownOnClick = 1
  923.  
  924. info.text = L["Alts"]
  925. info.arg2 = "AutoCompleteAlts"
  926. info.checked = db.AutoCompleteAlts
  927. UIDropDownMenu_AddButton(info, level)
  928.  
  929. info.text = L["All Alts"]
  930. info.arg2 = "AutoCompleteAllAlts"
  931. info.checked = db.AutoCompleteAllAlts
  932. UIDropDownMenu_AddButton(info, level)
  933.  
  934. info.text = L["Recently Mailed"]
  935. info.arg2 = "AutoCompleteRecent"
  936. info.checked = db.AutoCompleteRecent
  937. UIDropDownMenu_AddButton(info, level)
  938.  
  939. info.text = L["Contacts"]
  940. info.arg2 = "AutoCompleteContacts"
  941. info.checked = db.AutoCompleteContacts
  942. UIDropDownMenu_AddButton(info, level)
  943.  
  944. info.disabled = nil
  945.  
  946. info.text = L["Friends"]
  947. info.arg2 = "AutoCompleteFriends"
  948. info.checked = db.AutoCompleteFriends
  949. info.func = Postal_BlackBook.SaveFriendGuildOption
  950. UIDropDownMenu_AddButton(info, level)
  951.  
  952. info.text = L["Guild"]
  953. info.arg2 = "AutoCompleteGuild"
  954. info.checked = db.AutoCompleteGuild
  955. UIDropDownMenu_AddButton(info, level)
  956.  
  957. info.text = L["Exclude randoms you interacted with"]
  958. info.arg2 = "ExcludeRandoms"
  959. info.checked = db.ExcludeRandoms
  960. UIDropDownMenu_AddButton(info, level)
  961.  
  962. info.text = L["Disable Blizzard's auto-completion popup menu"]
  963. info.arg2 = "DisableBlizzardAutoComplete"
  964. info.checked = db.DisableBlizzardAutoComplete
  965. info.func = Postal.SaveOption
  966. UIDropDownMenu_AddButton(info, level)
  967. end
  968. end
  969. end
  970.  
Advertisement
Add Comment
Please, Sign In to add comment