Advertisement
SilverFox4226

MailTab.lua

Dec 16th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. -- ------------------------------------------------------------------------------ --
  2. -- TradeSkillMaster_Mailing --
  3. -- http://www.curse.com/addons/wow/tradeskillmaster_mailing --
  4. -- --
  5. -- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
  6. -- All Rights Reserved* - Detailed license information included with addon. --
  7. -- ------------------------------------------------------------------------------ --
  8.  
  9. local TSM = select(2, ...)
  10. local MailTab = TSM:NewModule("MailTab", "AceEvent-3.0", "AceHook-3.0")
  11. local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Mailing") -- loads the localization table
  12. local private = {frame=nil, tabs={}, didHook=nil}
  13.  
  14.  
  15. function MailTab:OnEnable()
  16. MailTab:RegisterEvent("MAIL_SHOW", function() TSMAPI.Delay:AfterTime(0, private.OnMailShow) end)
  17. end
  18.  
  19. function MailTab:ToggleHelpPlate(frame, info, btn, isUser)
  20. if not HelpPlate_IsShowing(info) then
  21. HelpPlate:SetParent(frame)
  22. HelpPlate:SetFrameStrata("DIALOG")
  23. HelpPlate_Show(info, frame, btn, isUser)
  24. else
  25. HelpPlate:SetParent(UIParent)
  26. HelpPlate:SetFrameStrata("DIALOG")
  27. HelpPlate_Hide(isUser)
  28. end
  29. end
  30.  
  31. function private:OnMailShow()
  32. private:CreateMailTab()
  33. if not private.didHook then
  34. private.didHook = true
  35. MailTab:Hook("MailFrameTab_OnClick", private.OnOtherTabClick, true)
  36. end
  37.  
  38. local currentTab = PanelTemplates_GetSelectedTab(MailFrame)
  39. if TSM.db.global.defaultMailTab then
  40. for i=1, MailFrame.numTabs do
  41. if _G["MailFrameTab"..i].isTSMTab then
  42. currentTab = i
  43. end
  44. end
  45. end
  46.  
  47. -- make sure the second tab gets loaded so we can send mail
  48. MailFrameTab2:Click()
  49. _G["MailFrameTab"..currentTab]:Click()
  50. end
  51.  
  52. function private:CreateMailTab()
  53. if private.frame then return end
  54.  
  55. local BFC = TSMAPI.GUI:GetBuildFrameConstants()
  56. local frameInfo = {
  57. type = "Frame",
  58. parent = MailFrame,
  59. hidden = true,
  60. mouse = true,
  61. points = {{"TOPLEFT"}, {"BOTTOMRIGHT", 0, 0}},
  62. children = {
  63. {
  64. type = "TSMLogo",
  65. size = {80, 80},
  66. points = {{"CENTER", BFC.PARENT, "TOPLEFT", 25, -25}},
  67. },
  68. {
  69. type = "Text",
  70. text = "TSM_Mailing - "..TSM._version,
  71. textHeight = 16,
  72. justify = {"CENTER", "MIDDLE"},
  73. points = {{"TOPLEFT", 40, -3}, {"BOTTOMRIGHT", BFC.PARENT, "TOPRIGHT", -5, -25}},
  74. },
  75. {
  76. type = "Button",
  77. key = "closeBtn",
  78. text = "X",
  79. textHeight = 19,
  80. size = {20, 20},
  81. points = {{"TOPRIGHT", -1, -2}},
  82. scripts = {"OnClick"},
  83. },
  84. {
  85. type = "VLine",
  86. size = {2, 30},
  87. points = {{"TOPRIGHT", -30, -1}},
  88. },
  89. {
  90. type = "HLine",
  91. offset = -28,
  92. },
  93. {
  94. type = "Button",
  95. key = "inboxBtn",
  96. text = INBOX,
  97. textHeight = 10,
  98. size = {55, 20},
  99. points = {{"TOPLEFT", 70, -40}},
  100. scripts = {"OnClick"},
  101. },
  102. {
  103. type = "Button",
  104. key = "groupsBtn",
  105. text = L["TSM Groups"],
  106. textHeight = 10,
  107. size = {65, 20},
  108. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}},
  109. scripts = {"OnClick"},
  110. },
  111. {
  112. type = "Button",
  113. key = "quickSendBtn",
  114. text = L["Quick Send"],
  115. textHeight = 10,
  116. size = {65, 20},
  117. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}},
  118. scripts = {"OnClick"},
  119. },
  120. {
  121. type = "Button",
  122. key = "otherBtn",
  123. text = OTHER,
  124. textHeight = 10,
  125. size = {10, 20},
  126. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}, {"TOPRIGHT", -5, -40}},
  127. scripts = {"OnClick"},
  128. },
  129. {
  130. type = "HLine",
  131. offset = -70,
  132. },
  133. {
  134. type = "Frame",
  135. key = "content",
  136. points = {{"TOPLEFT", 0, -70}, {"BOTTOMRIGHT"}},
  137. children = {
  138. TSM.Inbox:CreateTab(),
  139. TSM.Groups:CreateTab(),
  140. TSM.Other:CreateTab(),
  141. TSM.QuickSend:CreateTab(),
  142. },
  143. },
  144. },
  145. handlers = {
  146. closeBtn = {
  147. OnClick = CloseMail,
  148. },
  149. inboxBtn = {
  150. OnClick = private.OnButtonClick,
  151. },
  152. groupsBtn = {
  153. OnClick = private.OnButtonClick,
  154. },
  155. quickSendBtn = {
  156. OnClick = private.OnButtonClick,
  157. },
  158. otherBtn = {
  159. OnClick = private.OnButtonClick,
  160. },
  161. },
  162. }
  163.  
  164. local frame = TSMAPI.GUI:BuildFrame(frameInfo)
  165. TSMAPI.Design:SetFrameBackdropColor(frame)
  166.  
  167. local n = MailFrame.numTabs + 1
  168. local tab = CreateFrame("Button", "MailFrameTab"..n, MailFrame, "FriendsFrameTabTemplate")
  169. tab:Hide()
  170. tab:SetID(n)
  171. tab:SetText(TSMAPI.Design:GetInlineColor("link2").."TSM_Mailing|r")
  172. tab:SetNormalFontObject(GameFontHighlightSmall)
  173. tab.isTSMTab = true
  174. tab:SetPoint("LEFT", _G["MailFrameTab"..n-1], "RIGHT", -8, 0)
  175. tab:Show()
  176. tab:SetScript("OnClick", private.OnTabClick)
  177. PanelTemplates_SetNumTabs(MailFrame, n)
  178. PanelTemplates_EnableTab(MailFrame, n)
  179. frame.tab = tab
  180.  
  181. TSMAPI.Design:SetFrameColor(frame.content.groupsTab.groupTreeContainer)
  182. TSMAPI.Design:SetFrameColor(frame.content.otherTab.deBox)
  183. TSMAPI.Design:SetFrameColor(frame.content.otherTab.sendGoldBox)
  184.  
  185. private.frame = frame
  186. end
  187.  
  188. function private.OnTabClick(tabFrame)
  189. PanelTemplates_SetTab(MailFrame, tabFrame:GetID())
  190. ButtonFrameTemplate_HideButtonBar(MailFrame)
  191. InboxFrame:Hide()
  192. OpenMailFrame:Hide()
  193. SendMailFrame:Hide()
  194. SetSendMailShowing(false)
  195.  
  196. MailFrameInset:Hide()
  197. --MailFramePortraitFrame:Hide()
  198. -- MailFrameBg:Hide()
  199. if MailFrameText then MailFrameText:Hide() end
  200. --MailFrameTitleBg:Hide()
  201. --MailFrameTitleText:Hide()
  202. MailFrameCloseButton:Hide()
  203.  
  204.  
  205. -- MailFrameLeftBorder:Hide()
  206. --MailFrameTopBorder:Hide()
  207. -- MailFrameRightBorder:Hide()
  208. --MailFrameBottomBorder:Hide()
  209. -- MailFrameTopTileStreaks:Hide()
  210. --MailFrameTopRightCorner:Hide()
  211. -- MailFrameBotLeftCorner:Hide()
  212. --MailFrameBotRightCorner:Hide()
  213.  
  214. private.frame:Show()
  215. if TSM.db.global.defaultPage == 1 then
  216. private.frame.inboxBtn:Click()
  217. elseif TSM.db.global.defaultPage == 2 then
  218. private.frame.groupsBtn:Click()
  219. elseif TSM.db.global.defaultPage == 3 then
  220. private.frame.quickSendBtn:Click()
  221. elseif TSM.db.global.defaultPage == 4 then
  222. private.frame.otherBtn:Click()
  223. end
  224. end
  225.  
  226. function private.OnOtherTabClick()
  227. private.frame:Hide()
  228. ---MailFrameLeftBorder:Show()
  229. --MailFrameTopBorder:Show()
  230. --MailFrameRightBorder:Show()
  231. --MailFrameBottomBorder:Show()
  232. --MailFrameTopTileStreaks:Show()
  233. --MailFrameTopRightCorner:Show()
  234. --MailFrameBotLeftCorner:Show()
  235. --MailFrameBotRightCorner:Show()
  236.  
  237. MailFrameInset:Show()
  238. --MailFramePortraitFrame:Show()
  239. MailFrameBg:Show()
  240. if MailFrameText then MailFrameText:Show() end
  241. --MailFrameTitleBg:Show()
  242. --MailFrameTitleText:Show()
  243. -- MailFrameCloseButton:Show()
  244. end
  245.  
  246. function private.OnButtonClick(self)
  247. private.frame.content.inboxTab:Hide()
  248. private.frame.content.groupsTab:Hide()
  249. private.frame.content.otherTab:Hide()
  250. private.frame.content.quickSendTab:Hide()
  251.  
  252. private.frame.inboxBtn:UnlockHighlight()
  253. private.frame.groupsBtn:UnlockHighlight()
  254. private.frame.otherBtn:UnlockHighlight()
  255. private.frame.quickSendBtn:UnlockHighlight()
  256. self:LockHighlight()
  257.  
  258. if self == private.frame.inboxBtn then
  259. private.frame.content.inboxTab:Show()
  260. elseif self == private.frame.groupsBtn then
  261. private.frame.content.groupsTab:Show()
  262. elseif self == private.frame.otherBtn then
  263. private.frame.content.otherTab:Show()
  264. elseif self == private.frame.quickSendBtn then
  265. private.frame.content.quickSendTab:Show()
  266. end
  267. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement