Advertisement
Guest User

Untitled

a guest
Sep 27th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.68 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. local accountID = C_BattleNet.GetFriendAccountInfo(i)
  301. if (toonName and client == BNET_CLIENT_WOW and CanCooperateWithGameAccount(accountID)) then
  302. if strfind(strupper(toonName), text, 1, 1) == 1 then
  303. newname = toonName
  304. break
  305. end
  306. end
  307. end
  308. end
  309.  
  310. -- The Blizzard autocomplete is borked for guild. So we implement our own for guild autocomplete
  311. if not newname and db.AutoCompleteGuild and IsInGuild() then
  312. local numMembers, numOnline = GetNumGuildMembers(true)
  313. for i = 1, numMembers do
  314. local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile, canSoR = GetGuildRosterInfo(i)
  315. if strfind(strupper(name), text, 1, 1) == 1 then
  316. newname = name
  317. break
  318. end
  319. end
  320. end
  321.  
  322. -- Call the original Blizzard function to autocomplete and for its popup
  323. self.hooks[SendMailNameEditBox].OnChar(editbox, ...)
  324.  
  325. -- Set our match if we found one (overriding Blizzard's match if there's one)
  326. if newname then
  327. editbox:SetText(newname)
  328. editbox:HighlightText(textlen, -1)
  329. editbox:SetCursorPosition(textlen)
  330. end
  331. end
  332.  
  333. function Postal_BlackBook.SetSendMailName(dropdownbutton, arg1, arg2, checked)
  334. SendMailNameEditBox:SetText(arg1)
  335. if SendMailNameEditBox:HasFocus() then SendMailSubjectEditBox:SetFocus() end
  336. CloseDropDownMenus()
  337. end
  338.  
  339. function Postal_BlackBook.AddContact(dropdownbutton, arg1, arg2, checked)
  340. local name = strtrim(SendMailNameEditBox:GetText())
  341. if name == "" then return end
  342. local db = Postal.db.profile.BlackBook.contacts
  343. for k = 1, #db do
  344. if name == db[k] then return end
  345. end
  346. tinsert(db, name)
  347. table.sort(db)
  348. end
  349.  
  350. function Postal_BlackBook.RemoveContact(dropdownbutton, arg1, arg2, checked)
  351. local name = strtrim(SendMailNameEditBox:GetText())
  352. if name == "" then return end
  353. local db = Postal.db.profile.BlackBook.contacts
  354. for k = 1, #db do
  355. if name == db[k] then tremove(db, k) return end
  356. end
  357. end
  358.  
  359. function Postal_BlackBook:SortAndCountNumFriends()
  360. wipe(sorttable)
  361. local numFriends = GetNumFriends()
  362. for i = 1, numFriends do
  363. sorttable[i] = GetFriendInfo(i)
  364. end
  365.  
  366. -- Battle.net friends
  367. if BNGetNumFriends then -- For pre 3.3.5 backwards compat
  368. local numBNetTotal, numBNetOnline = BNGetNumFriends()
  369. for i= 1, numBNetOnline do
  370. local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(i)
  371. local accountID = C_BattleNet.GetFriendAccountInfo(i)
  372. if (toonName and client == BNET_CLIENT_WOW and CanCooperateWithGameAccount(accountID)) then
  373. -- Check if already on friends list
  374. local alreadyOnList = false
  375. for j = 1, numFriends do
  376. if sorttable[j] == toonName then
  377. alreadyOnList = true
  378. break
  379. end
  380. end
  381. if not alreadyOnList then
  382. numFriends = numFriends + 1
  383. sorttable[numFriends] = toonName
  384. end
  385. end
  386. end
  387. end
  388.  
  389. -- Sort the list
  390. if numFriends > 0 and not ignoresortlocale[GetLocale()] then table.sort(sorttable) end
  391.  
  392. -- Store upvalue
  393. numFriendsOnList = numFriends
  394. return numFriends
  395. end
  396.  
  397. function Postal_BlackBook.BlackBookMenu(self, level)
  398. if not level then return end
  399. local info = self.info
  400. wipe(info)
  401. if level == 1 then
  402. info.isTitle = 1
  403. info.text = L["Contacts"]
  404. info.notCheckable = 1
  405. UIDropDownMenu_AddButton(info, level)
  406.  
  407. info.disabled = nil
  408. info.isTitle = nil
  409.  
  410. local db = Postal.db.profile.BlackBook.contacts
  411. for i = 1, #db do
  412. info.text = db[i]
  413. info.func = Postal_BlackBook.SetSendMailName
  414. info.arg1 = db[i]
  415. UIDropDownMenu_AddButton(info, level)
  416. end
  417.  
  418. info.arg1 = nil
  419. if #db > 0 then
  420. info.disabled = 1
  421. info.text = nil
  422. info.func = nil
  423. UIDropDownMenu_AddButton(info, level)
  424. info.disabled = nil
  425. end
  426.  
  427. info.text = L["Add Contact"]
  428. info.func = Postal_BlackBook.AddContact
  429. UIDropDownMenu_AddButton(info, level)
  430.  
  431. info.text = L["Remove Contact"]
  432. info.func = Postal_BlackBook.RemoveContact
  433. UIDropDownMenu_AddButton(info, level)
  434.  
  435. info.disabled = 1
  436. info.text = nil
  437. info.func = nil
  438. UIDropDownMenu_AddButton(info, level)
  439.  
  440. info.hasArrow = 1
  441. info.keepShownOnClick = 1
  442. info.func = self.UncheckHack
  443.  
  444. info.disabled = #Postal.db.profile.BlackBook.recent == 0
  445. info.text = L["Recently Mailed"]
  446. info.value = "recent"
  447. UIDropDownMenu_AddButton(info, level)
  448.  
  449. info.disabled = not enableAltsMenu
  450. info.text = L["Alts"]
  451. info.value = "alt"
  452. UIDropDownMenu_AddButton(info, level)
  453.  
  454. info.disabled = not enableAllAltsMenu
  455. info.text = L["All Alts"]
  456. info.value = "allalt"
  457. UIDropDownMenu_AddButton(info, level)
  458.  
  459. info.disabled = Postal_BlackBook:SortAndCountNumFriends() == 0
  460. info.text = L["Friends"]
  461. info.value = "friend"
  462. UIDropDownMenu_AddButton(info, level)
  463.  
  464. info.disabled = not IsInGuild()
  465. info.text = L["Guild"]
  466. info.value = "guild"
  467. UIDropDownMenu_AddButton(info, level)
  468.  
  469. wipe(info)
  470. info.disabled = 1
  471. info.notCheckable = 1
  472. UIDropDownMenu_AddButton(info, level)
  473. info.disabled = nil
  474.  
  475. info.text = CLOSE
  476. info.func = self.HideMenu
  477. UIDropDownMenu_AddButton(info, level)
  478.  
  479. elseif level == 2 then
  480. info.notCheckable = 1
  481. if UIDROPDOWNMENU_MENU_VALUE == "recent" then
  482. local realm = GetRealmName()
  483. local faction = UnitFactionGroup("player")
  484. local player = UnitName("player")
  485. local db = Postal.db.profile.BlackBook.recent
  486. if #db == 0 then return end
  487. for i = 1, #db do
  488. local p, r, f = strsplit("|", db[i])
  489. if r == realm and f == faction and p ~= player then
  490. info.text = p
  491. info.func = Postal_BlackBook.SetSendMailName
  492. info.arg1 = p
  493. UIDropDownMenu_AddButton(info, level)
  494. end
  495. end
  496.  
  497. info.disabled = 1
  498. info.text = nil
  499. info.func = nil
  500. info.arg1 = nil
  501. UIDropDownMenu_AddButton(info, level)
  502. info.disabled = nil
  503.  
  504. info.text = L["Clear list"]
  505. info.func = Postal_BlackBook.ClearRecent
  506. info.arg1 = nil
  507. UIDropDownMenu_AddButton(info, level)
  508.  
  509. elseif UIDROPDOWNMENU_MENU_VALUE == "alt" then
  510. if not enableAltsMenu then return end
  511. local db = Postal.db.global.BlackBook.alts
  512. local realm = GetRealmName()
  513. local faction = UnitFactionGroup("player")
  514. local player = UnitName("player")
  515. info.notCheckable = 1
  516. for i = 1, #db do
  517. local p, r, f, l, c = strsplit("|", db[i])
  518. if r == realm and p ~= player then
  519. if l and c then
  520. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  521. 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])
  522. else
  523. info.text = p
  524. end
  525. info.func = Postal_BlackBook.SetSendMailName
  526. info.arg1 = p
  527. UIDropDownMenu_AddButton(info, level)
  528. end
  529. end
  530.  
  531. info.disabled = 1
  532. info.text = nil
  533. info.func = nil
  534. info.arg1 = nil
  535. UIDropDownMenu_AddButton(info, level)
  536. info.disabled = nil
  537.  
  538. info.text = L["Delete"]
  539. info.hasArrow = 1
  540. info.keepShownOnClick = 1
  541. info.func = self.UncheckHack
  542. info.value = "deletealt"
  543. UIDropDownMenu_AddButton(info, level)
  544.  
  545. elseif UIDROPDOWNMENU_MENU_VALUE == "allalt" then
  546. if not enableAllAltsMenu then return end
  547. local db = Postal.db.global.BlackBook.alts
  548. local realm = GetRealmName()
  549. local faction = UnitFactionGroup("player")
  550. local player = UnitName("player")
  551. local plre = player.."-"..realm
  552. info.notCheckable = 1
  553. for i = 1, #db do
  554. local p, r, f, l, c = strsplit("|", db[i])
  555. local pr = p.."-"..r
  556. if (pr ~= plre ) then
  557. if l and c then
  558. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  559. 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])
  560. else
  561. info.text = ("%s-%s"):format(p, r)
  562. end
  563. info.func = Postal_BlackBook.SetSendMailName
  564. info.arg1 = ("%s-%s"):format(p, r)
  565. UIDropDownMenu_AddButton(info, level)
  566. end
  567. end
  568.  
  569. info.disabled = 1
  570. info.text = nil
  571. info.func = nil
  572. info.arg1 = nil
  573. UIDropDownMenu_AddButton(info, level)
  574. info.disabled = nil
  575.  
  576. info.text = L["Delete"]
  577. info.hasArrow = 1
  578. info.keepShownOnClick = 1
  579. info.func = self.UncheckHack
  580. info.value = "deleteallalt"
  581. UIDropDownMenu_AddButton(info, level)
  582.  
  583. if DropDownList2 then -- ensure long lists stay on screen
  584. DropDownList2:SetClampedToScreen(true)
  585. end
  586.  
  587. elseif UIDROPDOWNMENU_MENU_VALUE == "friend" then
  588. -- Friends list
  589. local numFriends = Postal_BlackBook:SortAndCountNumFriends()
  590.  
  591. -- 25 or less, don't need multi level menus
  592. if numFriends > 0 and numFriends <= 25 then
  593. for i = 1, numFriends do
  594. local name = sorttable[i]
  595. info.text = name
  596. info.func = Postal_BlackBook.SetSendMailName
  597. info.arg1 = name
  598. UIDropDownMenu_AddButton(info, level)
  599. end
  600. elseif numFriends > 25 then
  601. -- More than 25 people, split the list into multiple sublists of 25
  602. info.hasArrow = 1
  603. info.keepShownOnClick = 1
  604. info.func = self.UncheckHack
  605. for i = 1, math.ceil(numFriends/25) do
  606. info.text = L["Part %d"]:format(i)
  607. info.value = "fpart"..i
  608. UIDropDownMenu_AddButton(info, level)
  609. end
  610. end
  611.  
  612. elseif UIDROPDOWNMENU_MENU_VALUE == "guild" then
  613. if not IsInGuild() then return end
  614. local numFriends = GetNumGuildMembers(true)
  615. for i = 1, numFriends do
  616. local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile, canSoR = GetGuildRosterInfo(i)
  617. local c = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[classFileName] or RAID_CLASS_COLORS[classFileName]
  618. 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)
  619. end
  620. for i = #sorttable, numFriends+1, -1 do
  621. sorttable[i] = nil
  622. end
  623. if not ignoresortlocale[GetLocale()] then table.sort(sorttable) end
  624. if numFriends > 0 and numFriends <= 25 then
  625. for i = 1, numFriends do
  626. info.text = sorttable[i]
  627. info.func = Postal_BlackBook.SetSendMailName
  628. info.arg1 = strmatch(sorttable[i], "(.*) |cffffd200")
  629. UIDropDownMenu_AddButton(info, level)
  630. end
  631. elseif numFriends > 25 then
  632. -- More than 25 people, split the list into multiple sublists of 25
  633. info.hasArrow = 1
  634. info.keepShownOnClick = 1
  635. info.func = self.UncheckHack
  636. for i = 1, math.ceil(numFriends/25) do
  637. info.text = L["Part %d"]:format(i)
  638. info.value = "gpart"..i
  639. UIDropDownMenu_AddButton(info, level)
  640. end
  641. end
  642. end
  643.  
  644. elseif level >= 3 then
  645. info.notCheckable = 1
  646. if UIDROPDOWNMENU_MENU_VALUE == "deletealt" or UIDROPDOWNMENU_MENU_VALUE == "deleteallalt" then
  647. local all = ( UIDROPDOWNMENU_MENU_VALUE == "deleteallalt" )
  648. local db = Postal.db.global.BlackBook.alts
  649. local realm = GetRealmName()
  650. local faction = UnitFactionGroup("player")
  651. local player = UnitName("player")
  652. for i = 1, #db do
  653. local p, r, f, l, c = strsplit("|", db[i])
  654. if p ~= player and ( r == realm or all ) then
  655. p = all and p.."-"..r or p
  656. if l and c then
  657. local clr = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[c] or RAID_CLASS_COLORS[c]
  658. 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])
  659. else
  660. info.text = p
  661. end
  662. info.func = Postal_BlackBook.DeleteAlt
  663. info.arg1 = db[i]
  664. UIDropDownMenu_AddButton(info, level)
  665. end
  666. end
  667.  
  668. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "fpart") then
  669. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "fpart(%d+)")) * 25 - 24
  670. local endIndex = math.min(startIndex+24, numFriendsOnList)
  671. for i = startIndex, endIndex do
  672. local name = sorttable[i]
  673. info.text = name
  674. info.func = Postal_BlackBook.SetSendMailName
  675. info.arg1 = name
  676. UIDropDownMenu_AddButton(info, level)
  677. end
  678.  
  679. elseif strfind(UIDROPDOWNMENU_MENU_VALUE, "gpart") then
  680. local startIndex = tonumber(strmatch(UIDROPDOWNMENU_MENU_VALUE, "gpart(%d+)")) * 25 - 24
  681. local endIndex = math.min(startIndex+24, (GetNumGuildMembers(true)))
  682. for i = startIndex, endIndex do
  683. local name = sorttable[i]
  684. info.text = sorttable[i]
  685. info.func = Postal_BlackBook.SetSendMailName
  686. info.arg1 = strmatch(sorttable[i], "(.*) |cffffd200")
  687. UIDropDownMenu_AddButton(info, level)
  688. end
  689. end
  690.  
  691. end
  692. end
  693.  
  694. function Postal_BlackBook.SaveFriendGuildOption(dropdownbutton, arg1, arg2, checked)
  695. Postal.SaveOption(dropdownbutton, arg1, arg2, checked)
  696. local db = Postal.db.profile.BlackBook
  697. local exclude = bit.bor(db.AutoCompleteFriends and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_FRIEND,
  698. db.AutoCompleteGuild and AUTOCOMPLETE_FLAG_NONE or AUTOCOMPLETE_FLAG_IN_GUILD)
  699. Postal_BlackBook_Autocomplete_Flags.include = bit.bxor(
  700. db.ExcludeRandoms and (bit.bor(AUTOCOMPLETE_FLAG_FRIEND, AUTOCOMPLETE_FLAG_IN_GUILD)) or AUTOCOMPLETE_FLAG_ALL, exclude)
  701. end
  702.  
  703. function Postal_BlackBook.SetAutoComplete(dropdownbutton, arg1, arg2, checked)
  704. local self = Postal_BlackBook
  705. Postal.db.profile.BlackBook.UseAutoComplete = not checked
  706. if checked then
  707. if self:IsHooked(SendMailNameEditBox, "OnChar") then
  708. self:Unhook(SendMailNameEditBox, "OnChar")
  709. end
  710. else
  711. if not self:IsHooked(SendMailNameEditBox, "OnChar") then
  712. self:RawHookScript(SendMailNameEditBox, "OnChar")
  713. end
  714. end
  715. end
  716.  
  717. function Postal_BlackBook.ModuleMenu(self, level)
  718. if not level then return end
  719. local info = self.info
  720. wipe(info)
  721. info.isNotRadio = 1
  722. if level == 1 + self.levelAdjust then
  723. info.keepShownOnClick = 1
  724. info.text = L["Autofill last person mailed"]
  725. info.func = Postal.SaveOption
  726. info.arg1 = "BlackBook"
  727. info.arg2 = "AutoFill"
  728. info.checked = Postal.db.profile.BlackBook.AutoFill
  729. UIDropDownMenu_AddButton(info, level)
  730.  
  731. info.hasArrow = 1
  732. info.keepShownOnClick = 1
  733. info.func = self.UncheckHack
  734. info.checked = nil
  735. info.arg1 = nil
  736. info.arg2 = nil
  737. info.text = L["Name auto-completion options"]
  738. info.value = "AutoComplete"
  739. UIDropDownMenu_AddButton(info, level)
  740. local listFrame = _G["DropDownList"..level]
  741. self.UncheckHack(_G[listFrame:GetName().."Button"..listFrame.numButtons])
  742.  
  743. elseif level == 2 + self.levelAdjust then
  744. local db = Postal.db.profile.BlackBook
  745. info.arg1 = "BlackBook"
  746.  
  747. if UIDROPDOWNMENU_MENU_VALUE == "AutoComplete" then
  748. info.text = L["Use Postal's auto-complete"]
  749. info.arg2 = "UseAutoComplete"
  750. info.checked = db.UseAutoComplete
  751. info.func = Postal_BlackBook.SetAutoComplete
  752. UIDropDownMenu_AddButton(info, level)
  753.  
  754. info.func = Postal.SaveOption
  755. info.disabled = not db.UseAutoComplete
  756. info.keepShownOnClick = 1
  757.  
  758. info.text = L["Alts"]
  759. info.arg2 = "AutoCompleteAlts"
  760. info.checked = db.AutoCompleteAlts
  761. UIDropDownMenu_AddButton(info, level)
  762.  
  763. info.text = L["All Alts"]
  764. info.arg2 = "AutoCompleteAllAlts"
  765. info.checked = db.AutoCompleteAllAlts
  766. UIDropDownMenu_AddButton(info, level)
  767.  
  768. info.text = L["Recently Mailed"]
  769. info.arg2 = "AutoCompleteRecent"
  770. info.checked = db.AutoCompleteRecent
  771. UIDropDownMenu_AddButton(info, level)
  772.  
  773. info.text = L["Contacts"]
  774. info.arg2 = "AutoCompleteContacts"
  775. info.checked = db.AutoCompleteContacts
  776. UIDropDownMenu_AddButton(info, level)
  777.  
  778. info.disabled = nil
  779.  
  780. info.text = L["Friends"]
  781. info.arg2 = "AutoCompleteFriends"
  782. info.checked = db.AutoCompleteFriends
  783. info.func = Postal_BlackBook.SaveFriendGuildOption
  784. UIDropDownMenu_AddButton(info, level)
  785.  
  786. info.text = L["Guild"]
  787. info.arg2 = "AutoCompleteGuild"
  788. info.checked = db.AutoCompleteGuild
  789. UIDropDownMenu_AddButton(info, level)
  790.  
  791. info.text = L["Exclude randoms you interacted with"]
  792. info.arg2 = "ExcludeRandoms"
  793. info.checked = db.ExcludeRandoms
  794. UIDropDownMenu_AddButton(info, level)
  795.  
  796. info.text = L["Disable Blizzard's auto-completion popup menu"]
  797. info.arg2 = "DisableBlizzardAutoComplete"
  798. info.checked = db.DisableBlizzardAutoComplete
  799. info.func = Postal.SaveOption
  800. UIDropDownMenu_AddButton(info, level)
  801. end
  802. end
  803. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement