Guest User

Untitled

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