Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. -- ------------------------------------------------------------------------------ --
  2. -- TradeSkillMaster_Vendoring --
  3. -- http://www.curse.com/addons/wow/tradeskillmaster_vendoring --
  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 MerchantTab = TSM:NewModule("MerchantTab", "AceEvent-3.0", "AceHook-3.0")
  11. local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Vendoring") -- loads the localization table
  12.  
  13. local private = {frame=nil}
  14.  
  15. function MerchantTab:OnEnable()
  16. MerchantTab:RegisterEvent("MERCHANT_SHOW", function() TSMAPI.Delay:AfterTime(0, private.OnMerchantShow) end)
  17. MerchantTab:RegisterEvent("MERCHANT_UPDATE",private.OnMerchantUpdate)
  18. MerchantTab:RegisterEvent("PLAYER_MONEY", private.UpdateMoneyAndRepair)
  19. MerchantTab:RegisterEvent("GUILDBANK_UPDATE_MONEY", private.UpdateMoneyAndRepair)
  20. MerchantTab:RegisterEvent("GUILDBANK_UPDATE_WITHDRAWMONEY",private.UpdateMoneyAndRepair)
  21. MerchantTab:RegisterEvent("CURRENCY_DISPLAY_UPDATE", private.UpdateMoney)
  22. MerchantTab:RegisterEvent("UPDATE_INVENTORY_DURABILITY", private.UpdateRepair)
  23. MerchantTab:RegisterEvent("MODIFIER_STATE_CHANGED", private.ModifierChanged)
  24.  
  25. TSMAPI.Inventory:RegisterCallback(private.OnBagUpdate)
  26.  
  27. MerchantTab:RawHook("MerchantFrame_UpdateBuybackInfo", function(...) if MerchantFrame.selectedTab == 2 then return MerchantTab.hooks.MerchantFrame_UpdateBuybackInfo(...) end end, true)
  28. MerchantTab:RawHook("MerchantFrame_UpdateMerchantInfo", function(...) if MerchantFrame.selectedTab == 1 then return MerchantTab.hooks.MerchantFrame_UpdateMerchantInfo(...) end end, true)
  29. MerchantTab:RawHook("MerchantFrame_Update", function(...) if MerchantFrame.selectedTab == 1 or MerchantFrame.selectedTab == 2 then return MerchantTab.hooks.MerchantFrame_Update(...) else private:OnMerchantUpdate() end end,true)
  30. end
  31.  
  32. function MerchantTab:ToggleHelpPlate(frame, info, btn, isUser)
  33. if not HelpPlate_IsShowing(info) then
  34. HelpPlate:SetParent(frame)
  35. HelpPlate:SetFrameStrata("DIALOG")
  36. HelpPlate_Show(info, frame, btn, isUser)
  37. else
  38. HelpPlate:SetParent(UIParent)
  39. HelpPlate:SetFrameStrata("DIALOG")
  40. HelpPlate_Hide(isUser)
  41. end
  42. end
  43.  
  44. function private:ModifierChanged()
  45. if private.frame and private.frame:IsVisible() then
  46. if IsControlKeyDown() then
  47. TSM.QuickSell:BeginInspect()
  48. TSM.Buy:BeginInspect()
  49. TSM.Buyback:BeginInspect()
  50. else
  51. TSM.Buyback:EndInspect()
  52. TSM.QuickSell:EndInspect()
  53. TSM.Buy:EndInspect()
  54. end
  55. end
  56. end
  57.  
  58. function private:OnBagUpdate()
  59. if private.frame and private.frame:IsVisible() then
  60. TSM.Buyback:OnBagUpdate()
  61. TSM.QuickSell:OnBagUpdate()
  62. end
  63. end
  64.  
  65. function private:UpdateMoneyAndRepair()
  66. private:UpdateMoney()
  67. private:UpdateRepair()
  68. end
  69.  
  70. function private:UpdateMoney()
  71.  
  72. if not private.frame then
  73. return
  74. end
  75.  
  76. if not private.frame:IsVisible() then
  77. return
  78. end
  79.  
  80. private.frame.moneyText:SetText(TSMAPI:MoneyToString(GetMoney(), "OPT_ICON"))
  81.  
  82. local currencies = { GetMerchantCurrencies() };
  83.  
  84. local currencyText = ""
  85.  
  86. if #currencies > 0 then
  87. for index = 1, #currencies do
  88.  
  89. local name, count, icon = GetCurrencyInfo(currencies[index]);
  90. currencyText = format("%s %d |T%s:0|t",currencyText,count, icon)
  91. end
  92. end
  93.  
  94. private.frame.currencyText:SetText(currencyText)
  95.  
  96. -- Hide default UI
  97. if MerchantPageText then MerchantPageText:Hide() end
  98. if MerchantFrameLootFilter then MerchantFrameLootFilter:Hide() end
  99. if MerchantMoneyFrame then MerchantMoneyFrame:Hide() end
  100. if MerchantMoneyInset then MerchantMoneyInset:Hide() end
  101. if MerchantExtraCurrencyInset then MerchantExtraCurrencyInset:Hide() end
  102. if MerchantExtraCurrencyBg then MerchantExtraCurrencyBg:Hide() end
  103. if MerchantMoneyBg then MerchantMoneyBg:Hide() end
  104.  
  105. for i = 1, 6 do
  106. local tokenButton = _G["MerchantToken"..i]
  107. if (tokenButton) then
  108. tokenButton:Hide()
  109. else
  110. break
  111. end
  112. end
  113.  
  114. end
  115.  
  116. function private:UpdateRepair()
  117. if not private.frame then
  118. return
  119. end
  120.  
  121. if not private.frame:IsVisible() then
  122. return
  123. end
  124.  
  125. -- Hide default UI
  126. if MerchantRepairItemButton then MerchantRepairItemButton:Hide() end
  127. if MerchantGuildBankRepairButton then MerchantGuildBankRepairButton:Hide() end
  128. if MerchantRepairAllButton then MerchantRepairAllButton:Hide() end
  129.  
  130. if CanMerchantRepair() then
  131. private.frame.repairBtn:Show()
  132. else
  133. private.frame.repairBtn:Hide()
  134. end
  135.  
  136. local repairAllCost, canRepair = GetRepairAllCost()
  137.  
  138. if (canRepair and (repairAllCost > 0)) then
  139. private.frame.repairBtn:Enable()
  140. else
  141. private.frame.repairBtn:Disable()
  142. end
  143. end
  144.  
  145. function private:OnMerchantShow()
  146. private.frame = private.frame or private:CreateMerchantTab()
  147. local currentTab = PanelTemplates_GetSelectedTab(MerchantFrame)
  148.  
  149. TSM.QuickSell:SellTrash()
  150.  
  151. if TSM.db.global.defaultMerchantTab then
  152. for i=1, MerchantFrame.numTabs do
  153. if _G["MerchantFrameTab"..i].isTSMTab then
  154. currentTab = i
  155. break
  156. end
  157. end
  158.  
  159. TSM.Buy:OnMerchantShow()
  160. TSM.Buyback:OnMerchantShow()
  161. TSM.QuickSell:OnMerchantShow()
  162. private:UpdateMoneyAndRepair()
  163. end
  164.  
  165. MerchantFrameTab2:Click()
  166. _G["MerchantFrameTab"..currentTab]:Click()
  167. end
  168.  
  169. function private:OnMerchantUpdate()
  170. TSM.Buy:OnMerchantUpdate()
  171. TSM.Buyback:OnMerchantUpdate()
  172. TSM.QuickSell:OnMerchantUpdate()
  173. end
  174.  
  175. function private:CreateMerchantTab()
  176.  
  177. local BFC = TSMAPI.GUI:GetBuildFrameConstants()
  178.  
  179. local frameInfo = {
  180. type = "Frame",
  181. parent = MerchantFrame,
  182. hidden = true,
  183. mouse = true,
  184. points = {{"TOPLEFT"}, {"BOTTOMRIGHT", 40, 0}},
  185. children = {
  186. {
  187. type = "TSMLogo",
  188. size = {80, 80},
  189. points = {{"CENTER", BFC.PARENT, "TOPLEFT", 25, -25}},
  190. },
  191. {
  192. type = "Text",
  193. text = "TSM_Vendoring - " .. TSM._version,
  194. textHeight = 18,
  195. justify = {"CENTER", "MIDDLE"},
  196. points = {{"TOPLEFT", 40, -5}, {"BOTTOMRIGHT", BFC.PARENT, "TOPRIGHT", -5, -25}},
  197. },
  198. {
  199. type = "Button",
  200. key = "closeBtn",
  201. text = "X",
  202. textHeight = 19,
  203. size = {20, 20},
  204. points = {{"TOPRIGHT", -5, -5}},
  205. scripts = {"OnClick"},
  206. },
  207. {
  208. type = "VLine",
  209. size = {2, 30},
  210. points = {{"TOPRIGHT", -30, -1}},
  211. },
  212. {
  213. type = "HLine",
  214. offset = -28,
  215. },
  216. {
  217. type = "Button",
  218. key = "buyBtn",
  219. text = L["Buy"],
  220. textHeight = 15,
  221. size = {55, 20},
  222. points = {{"TOPLEFT", 70, -40}},
  223. scripts = {"OnClick"},
  224. },
  225. {
  226. type = "Button",
  227. key = "buybackBtn",
  228. text = L["Buyback"],
  229. textHeight = 15,
  230. size = {65, 20},
  231. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}},
  232. scripts = {"OnClick"},
  233. },
  234. {
  235. type = "Button",
  236. key = "groupsBtn",
  237. text = L["TSM Groups"],
  238. textHeight = 15,
  239. size = {90, 20},
  240. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}},
  241. scripts = {"OnClick"},
  242. },
  243. {
  244. type = "Button",
  245. key = "quickSellBtn",
  246. text = L["Quick Sell"],
  247. textHeight = 15,
  248. size = {75, 20},
  249. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5, 0}},
  250. scripts = {"OnClick"},
  251. },
  252. {
  253. type = "HLine",
  254. offset = -70,
  255. },
  256. {
  257. type = "Frame",
  258. key = "content",
  259. points = {{"TOPLEFT", 0, -70}, {"BOTTOMRIGHT"}},
  260. children = {
  261. TSM.Buy:CreateTab(),
  262. TSM.Buyback:CreateTab(),
  263. TSM.Groups:CreateTab(),
  264. TSM.QuickSell:CreateTab(),
  265. },
  266. },
  267. {
  268. type = "Text",
  269. key = "moneyText",
  270. points = {{"BOTTOMLEFT", BFC.PARENT, 5, 5 }}
  271. },
  272. {
  273. type = "Text",
  274. key = "currencyText",
  275. points = {{"TOPLEFT", BFC.PREV, "TOPRIGHT", 5,0 }}
  276. },
  277. {
  278. type = "Button",
  279. key = "repairBtn",
  280. text = L["Repair"],
  281. textHeight = 15,
  282. size = {50,20},
  283. points = {{"BOTTOMRIGHT", BFC.PARENT, -5, 5}},
  284. scripts = {"OnClick", "OnEnter", "OnLeave"}
  285. },
  286. },
  287. handlers = {
  288. closeBtn = {
  289. OnClick = CloseMerchant
  290. },
  291. buyBtn = {
  292. OnClick = private.OnTabButtonClick,
  293. },
  294. buybackBtn = {
  295. OnClick = private.OnTabButtonClick,
  296. },
  297. groupsBtn = {
  298. OnClick = private.OnTabButtonClick,
  299. },
  300. quickSellBtn = {
  301. OnClick = private.OnTabButtonClick,
  302. },
  303. repairBtn = {
  304. OnClick = function()
  305. if IsShiftKeyDown() then
  306. RepairAllItems(1)
  307. else
  308. RepairAllItems()
  309. end
  310. end,
  311. OnEnter = function(self)
  312. GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  313.  
  314. local repairAllCost, canRepair = GetRepairAllCost();
  315. if ( canRepair and (repairAllCost > 0) ) then
  316. GameTooltip:SetText(REPAIR_ALL_ITEMS);
  317. SetTooltipMoney(GameTooltip, repairAllCost);
  318.  
  319. if CanGuildBankRepair() then
  320. local amount = GetGuildBankWithdrawMoney();
  321. local guildBankMoney = GetGuildBankMoney();
  322. if ( amount == -1 ) then
  323. -- Guild leader shows full guild bank amount
  324. amount = guildBankMoney;
  325. else
  326. amount = min(amount, guildBankMoney);
  327. end
  328. GameTooltip:AddLine(GUILDBANK_REPAIR, nil, nil, nil, 1)
  329. SetTooltipMoney(GameTooltip, amount, "GUILD_REPAIR");
  330.  
  331. GameTooltip:AddLine(" ",nil,nil,nil,false)
  332. GameTooltip:AddLine(L["Hold shift to repair with guild bank"],1,1,1,1)
  333. end
  334.  
  335. GameTooltip:Show()
  336. end
  337. end,
  338. OnLeave = function()
  339. GameTooltip:Hide()
  340. end
  341. }
  342. }
  343. }
  344.  
  345. local frame = TSMAPI.GUI:BuildFrame(frameInfo)
  346. TSMAPI.Design:SetFrameBackdropColor(frame)
  347.  
  348. for i=1, MerchantFrame.numTabs do
  349. if not _G["MerchantFrameTab"..i].isTSMTab then
  350. _G["MerchantFrameTab"..i]:HookScript("OnClick", private.OnOtherTabClick)
  351. end
  352. end
  353.  
  354. local n = MerchantFrame.numTabs + 1
  355. local tab = CreateFrame("Button", "MerchantFrameTab"..n, MerchantFrame, "FriendsFrameTabTemplate")
  356. tab:Hide()
  357. tab:SetID(n)
  358. tab:SetText(TSMAPI.Design:GetInlineColor("link2").."TSM_Vendoring|r")
  359. tab:SetNormalFontObject(GameFontHighlightSmall)
  360. tab.isTSMTab = true
  361. tab:SetPoint("LEFT", _G["MerchantFrameTab"..n-1], "RIGHT", -16, 0)
  362. tab:Show()
  363. tab:SetScript("OnClick", private.OnTabClick)
  364. PanelTemplates_SetNumTabs(MerchantFrame, n)
  365. PanelTemplates_EnableTab(MerchantFrame, n)
  366. frame.tab = tab
  367.  
  368. TSMAPI.Design:SetIconRegionColor(frame.moneyText)
  369.  
  370. return frame
  371. end
  372.  
  373. function private.OnTabClick(self)
  374. PanelTemplates_SetTab(MerchantFrame, self:GetID())
  375.  
  376. MerchantFrameInset:Hide()
  377. --MerchantFramePortraitFrame:Hide()
  378. MerchantFrameBg:Hide()
  379. if MerchantFrameText then MerchantFrameText:Hide() end
  380. --MerchantFrameTitleBg:Hide()
  381. MerchantFrameTitleText:Hide()
  382. MerchantFrameCloseButton:Hide()
  383.  
  384. for i = 1, 12 do
  385. local merchantItem = _G["MerchantItem"..i]
  386. if merchantItem then merchantItem:Hide() end
  387. end
  388.  
  389. if MerchantBuyBackItem then MerchantBuyBackItem:Hide() end
  390.  
  391. MerchantNameText:Hide()
  392. --MerchantFrameLeftBorder:Hide()
  393. --MerchantFrameTopBorder:Hide()
  394. --MerchantFrameRightBorder:Hide()
  395. --MerchantFrameBottomBorder:Hide()
  396. --MerchantFrameTopTileStreaks:Hide()
  397. --MerchantFrameTopRightCorner:Hide()
  398. --MerchantFrameBotLeftCorner:Hide()
  399. --MerchantFrameBotRightCorner:Hide()
  400. --MerchantNextPageButton:Hide()
  401. MerchantPrevPageButton:Hide()
  402. MerchantRepairText:Hide()
  403. MerchantFrameBottomLeftBorder:Hide()
  404. MerchantFrameBottomRightBorder:Hide()
  405. --MerchantFrameBotLeftCorner:Hide()
  406. --MerchantFrameBotRightCorner:Hide()
  407. --MerchantFrameBtnCornerLeft:Hide()
  408. --MerchantFrameBtnCornerRight:Hide()
  409. --MerchantFrameButtonBottomBorder:Hide()
  410.  
  411. BuybackBG:Hide()
  412.  
  413. private.frame:Show()
  414.  
  415. if TSM.db.global.defaultPage == 1 then
  416. private.frame.buyBtn:Click()
  417. elseif TSM.db.global.defaultPage == 2 then
  418. private.frame.buybackBtn:Click()
  419. elseif TSM.db.global.defaultPage == 3 then
  420. private.frame.groupsBtn:Click()
  421. elseif TSM.db.global.defaultPage == 4 then
  422. private.frame.quickSellBtn:Click()
  423. end
  424.  
  425. -- Detect SellJunk
  426. if IsAddOnLoaded("SellJunk") then LibStub("AceAddon-3.0"):GetAddon("SellJunk").sellButton:Hide() end
  427.  
  428. -- Detect Scrap
  429. if ScrapVisualizer then
  430. ScrapVisualizer:Hide()
  431. end
  432.  
  433. private:UpdateMoney()
  434. private:UpdateRepair()
  435. end
  436.  
  437. function private.OnOtherTabClick(a,b,c)
  438.  
  439. if not private.frame then return end
  440. private.frame:Hide()
  441.  
  442. -- Let other addons fend for themselves.
  443. if MerchantFrame.selectedTab > 2 then
  444. return
  445. end
  446.  
  447. MerchantNameText:Show()
  448. -- MerchantFrameLeftBorder:Show()
  449. --MerchantFrameTopBorder:Show()
  450. --MerchantFrameRightBorder:Show()
  451. --MerchantFrameBottomBorder:Show()
  452. --MerchantFrameTopTileStreaks:Show()
  453. --MerchantFrameTopRightCorner:Show()
  454. --MerchantFrameBotLeftCorner:Show()
  455. --MerchantFrameBotRightCorner:Show()
  456. --MerchantFrameBottomLeftBorder:Show()
  457. --MerchantFrameBottomRightBorder:Show()
  458.  
  459. MerchantFrameLootFilter:Show()
  460. MerchantMoneyFrame:Show()
  461. MerchantMoneyInset:Show()
  462. MerchantMoneyBg:Show()
  463. MerchantExtraCurrencyInset:Show()
  464. MerchantExtraCurrencyBg:Show()
  465. MerchantPageText:Show()
  466.  
  467. MerchantFrameInset:Show()
  468. MerchantFramePortrait:Show()
  469. --MerchantFramePortraitFrame:Show()
  470. MerchantFrameBg:Show()
  471. if MerchantFrameText then MerchantFrameText:Show() end
  472. --MerchantFrameTitleBg:Show()
  473. MerchantFrameTitleText:Show()
  474. MerchantFrameCloseButton:Show()
  475. MerchantNextPageButton:Show()
  476. MerchantPrevPageButton:Show()
  477. MerchantRepairText:Show()
  478. BuybackBG:Show()
  479.  
  480. if MerchantToken1 then MerchantToken1:Show() end
  481.  
  482. for i = 1, 12 do
  483. local merchantItem = _G["MerchantItem"..i]
  484. if merchantItem then merchantItem:Show() end
  485. end
  486.  
  487. if MerchantBuyBackItem then MerchantBuyBackItem:Show() end
  488.  
  489. -- Detect SellJunk
  490. if IsAddOnLoaded("SellJunk") then LibStub("AceAddon-3.0"):GetAddon("SellJunk").sellButton:Show() end
  491.  
  492. MerchantFrame_Update()
  493. end
  494.  
  495. function private.OnTabButtonClick(self)
  496. private.frame.content.quickSellTab:Hide()
  497. private.frame.content.groupsTab:Hide()
  498. private.frame.content.buybackTab:Hide()
  499. private.frame.content.buyTab:Hide()
  500.  
  501. private.frame.quickSellBtn:UnlockHighlight()
  502. private.frame.groupsBtn:UnlockHighlight()
  503. private.frame.buybackBtn:UnlockHighlight()
  504. private.frame.buyBtn:UnlockHighlight()
  505. self:LockHighlight()
  506.  
  507. if self == private.frame.quickSellBtn then
  508. private.frame.content.quickSellTab:Show()
  509. elseif self == private.frame.groupsBtn then
  510. private.frame.content.groupsTab:Show()
  511. elseif self == private.frame.buyBtn then
  512. private.frame.content.buyTab:Show()
  513. elseif self == private.frame.buybackBtn then
  514. private.frame.content.buybackTab:Show()
  515. end
  516. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement