adam@0: local _, AskMrRobot = ... adam@0: adam@0: -- initialize the ShoppingListTab class adam@0: AskMrRobot.ShoppingListTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame) adam@0: adam@0: StaticPopupDialogs["SHOPPING_TAB_PLEASE_OPEN"] = { adam@0: text = "You need to open the mail window for this to work", adam@0: button1 = "Ok", adam@0: timeout = 0, adam@0: whileDead = true, adam@0: hideOnEscape = true, adam@0: preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/ adam@0: } adam@0: adam@0: function AskMrRobot.ShoppingListTab:new(parent) adam@0: adam@0: local tab = AskMrRobot.Frame:new(nil, parent) adam@0: setmetatable(tab, { __index = AskMrRobot.ShoppingListTab }) adam@0: tab:SetPoint("TOPLEFT") adam@0: tab:SetPoint("BOTTOMRIGHT") adam@0: tab:Hide() adam@0: tab:RegisterEvent("AUCTION_HOUSE_CLOSED") adam@0: tab:RegisterEvent("AUCTION_HOUSE_SHOW") adam@0: tab:RegisterEvent("MAIL_SHOW") adam@0: tab:RegisterEvent("MAIL_CLOSED") adam@0: adam@0: tab.isAuctionHouseVisible = false adam@0: adam@0: tab:SetScript("OnEvent", function(...) adam@0: tab:OnEvent(...) adam@0: end) adam@0: adam@0: tab.shoppingListHeader = AskMrRobot.FontString:new(tab, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.shoppingListHeader:SetPoint("TOPLEFT", 0, -5) adam@0: tab.shoppingListHeader:SetText("Shopping List") adam@0: adam@0: tab.shoppingPanel = AskMrRobot.Frame:new(nil, tab) adam@0: tab.shoppingPanel:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 0, -10) adam@0: tab.shoppingPanel:SetPoint("BOTTOMRIGHT", tab, "BOTTOMRIGHT", -20, 17) adam@0: adam@0: adam@0: tab.sendButton = CreateFrame("Button", "AmrSendButton", tab.shoppingPanel, "UIPanelButtonTemplate") adam@0: tab.sendButton:SetText("send it!") adam@0: tab.sendButton:SetPoint("BOTTOMLEFT", 0, 0) adam@0: tab.sendButton:SetHeight(25) adam@0: tab.sendButton:SetNormalFontObject("GameFontNormalLarge") adam@0: tab.sendButton:SetHighlightFontObject("GameFontHighlightLarge") adam@0: tab.sendButton:SetWidth(150) adam@0: tab.sendButton:SetScript("OnClick", function() adam@0: tab:Send() adam@0: end) adam@0: adam@0: tab.enchantMaterialsCheckbox = CreateFrame("CheckButton", "AmrEnchantMaterialsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); adam@0: tab.enchantMaterialsCheckbox:SetChecked(AmrSendSettings.SendEnchantMaterials) adam@0: tab.enchantMaterialsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendEnchantMaterials = tab.enchantMaterialsCheckbox:GetChecked() end) adam@0: tab.enchantMaterialsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 25) adam@0: local text3 = getglobal(tab.enchantMaterialsCheckbox:GetName() .. 'Text') adam@0: text3:SetFontObject("GameFontHighlightLarge") adam@0: text3:SetText("Enchant Materials") adam@0: text3:SetWidth(150) adam@0: text3:SetPoint("TOPLEFT", tab.enchantMaterialsCheckbox, "TOPRIGHT", 2, -4) adam@0: adam@0: adam@0: tab.enchantsCheckbox = CreateFrame("CheckButton", "AmrEnchantsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); adam@0: tab.enchantsCheckbox:SetChecked(AmrSendSettings.SendEnchants) adam@0: tab.enchantsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendEnchants = tab.enchantsCheckbox:GetChecked() end) adam@0: tab.enchantsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 50) adam@0: local text2 = getglobal(tab.enchantsCheckbox:GetName() .. 'Text') adam@0: text2:SetFontObject("GameFontHighlightLarge") adam@0: text2:SetText("Enchants") adam@0: text2:SetWidth(150) adam@0: text2:SetPoint("TOPLEFT", tab.enchantsCheckbox, "TOPRIGHT", 2, -4) adam@0: adam@0: adam@0: adam@0: tab.gemsCheckbox = CreateFrame("CheckButton", "AmrGemsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); adam@0: tab.gemsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 75) adam@0: tab.gemsCheckbox:SetChecked(AmrSendSettings.SendGems) adam@0: tab.gemsCheckbox:SetScript("OnClick", function () AmrSendSettings.SendGems = tab.gemsCheckbox:GetChecked() end) adam@0: local text = getglobal(tab.gemsCheckbox:GetName() .. 'Text') adam@0: text:SetFontObject("GameFontHighlightLarge") adam@0: text:SetText("Gems") adam@0: text:SetWidth(150) adam@0: text:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPRIGHT", 2, -4) adam@0: adam@0: adam@0: tab.sendMessage4 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge") adam@0: tab.sendMessage4:SetText("Include:") adam@0: tab.sendMessage4:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPLEFT", 0, 20) adam@0: adam@0: adam@0: tab.sendMessage3 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge") adam@0: tab.sendMessage3:SetText("Send list to") adam@0: tab.sendMessage3:SetPoint("TOPLEFT", tab.sendMessage4, "TOPLEFT", 0, 25) adam@0: adam@0: adam@0: tab.sendMessage2 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormal") adam@0: tab.sendMessage2:SetTextColor(.5,.5,.5) adam@0: tab.sendMessage2:SetText("Whisper to a friend or send to a channel, like /raid or /guild.") adam@0: tab.sendMessage2:SetPoint("TOPLEFT", tab.sendMessage3, "TOPLEFT", 0, 25) adam@0: adam@0: adam@0: tab.sendMessage1 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.sendMessage1:SetTextColor(0,1,0) adam@0: tab.sendMessage1:SetText("Send to a Jewelcraft or Enchanter friend :)") adam@0: tab.sendMessage1:SetPoint("TOPLEFT", tab.sendMessage2, "TOPLEFT", 0, 25) adam@0: adam@0: adam@0: tab.scrollFrame = CreateFrame("ScrollFrame", "AmrScrollFrame", tab.shoppingPanel, "UIPanelScrollFrameTemplate") adam@0: tab.scrollFrame:SetPoint("TOPLEFT", 0, 0) adam@0: tab.scrollFrame:SetPoint("RIGHT", -20, 0) adam@0: tab.scrollFrame:SetPoint("BOTTOM", tab.sendMessage1, "TOP", 0, 10) adam@0: adam@0: tab.scrollParent = AskMrRobot.Frame:new(nil, tab.shoppingPanel) adam@0: tab.scrollParent:SetPoint("TOPLEFT", 0, 0) adam@0: tab.scrollParent:SetWidth(tab:GetWidth() - 20) adam@0: tab.scrollParent:SetHeight(500) adam@0: tab.scrollFrame:SetScrollChild(tab.scrollParent) adam@0: adam@0: -- magic to get the scrollbar to work with the scrollwheel... adam@0: tab.scrollFrame:SetScript("OnMouseWheel", function(arg1, arg2) adam@0: ScrollFrameTemplate_OnMouseWheel(arg1, arg2, arg1.ScrollBar) adam@0: end) adam@0: adam@0: tab.gemsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.gemsHeader:SetText("Gems") adam@0: tab.gemsHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 0, 0) adam@0: adam@0: tab.gemsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.gemsQuantityHeader:SetText("Total") adam@0: tab.gemsQuantityHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 370, 0) adam@0: adam@0: tab.enchantsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.enchantsHeader:SetText("Enchants") adam@0: adam@0: tab.enchantsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.enchantsQuantityHeader:SetText("Total") adam@0: tab.enchantsQuantityHeader:SetPoint("TOPLEFT", tab.enchantsHeader, "TOPLEFT", 370, 0) adam@0: adam@0: tab.enchantMaterialsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.enchantMaterialsHeader:SetText("Enchant Materials") adam@0: adam@0: tab.enchantMaterialsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: tab.enchantMaterialsQuantityHeader:SetText("Total") adam@0: tab.enchantMaterialsQuantityHeader:SetPoint("TOPLEFT", tab.enchantMaterialsHeader, "TOPLEFT", 370, 0) adam@0: adam@0: tab.stamp = AskMrRobot.RobotStamp:new(nil, tab) adam@0: tab.stamp:Hide() adam@0: tab.stamp.bigText:SetText("YOUR SHOPPING IS ALL DONE!") adam@0: tab.stamp.smallText:SetText("Unless you want to buy me a birthday present! I like titanium bolts and robot dogs... Or was it titanium dogs and robot bolts...") adam@0: tab.stamp:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 2, -15) adam@0: tab.stamp:SetPoint("RIGHT", tab, "RIGHT", -30, 0) adam@0: tab.stamp:SetHeight(92) adam@0: adam@0: tab.gemIcons = {} adam@0: tab.gemLinks = {} adam@0: tab.gemQuantity = {} adam@0: tab.enchantIcons = {} adam@0: tab.enchantLinks = {} adam@0: tab.enchantQuantity = {} adam@0: tab.enchantMaterialIcons = {} adam@0: tab.enchantMaterialLinks = {} adam@0: tab.enchantMaterialQuantity = {} adam@0: adam@0: -- Create the dropdown, and configure its appearance adam@0: tab.dropDown = CreateFrame("FRAME", "AmrSendType", tab.shoppingPanel, "UIDropDownMenuTemplate") adam@0: tab.dropDown:SetPoint("TOPLEFT", tab.sendMessage3, "TOPRIGHT", 0, 5) adam@0: UIDropDownMenu_SetWidth(tab.dropDown, 140) adam@0: UIDropDownMenu_SetText(tab.dropDown, AmrSendSettings.SendToType) adam@0: adam@0: local text = getglobal(tab.dropDown:GetName() .. 'Text') adam@0: text:SetFontObject("GameFontHighlightLarge") adam@0: adam@0: local AddButton = function(list, optionText) adam@0: local info = UIDropDownMenu_CreateInfo() adam@0: info.justifyH = "RIGHT" adam@0: info.text = optionText adam@0: info.checked = AmrSendSettings.SendToType == optionText adam@0: info.arg1 = optionText adam@0: info.func = list.SetValue adam@0: info.owner = list adam@0: info.fontObject = "GameFontHighlightLarge" adam@0: info.minWidth = 140 adam@0: return info adam@0: end adam@0: adam@0: -- Create and bind the initialization function to the dropdown menu adam@0: UIDropDownMenu_Initialize(tab.dropDown, function(self, level, menuList) adam@0: UIDropDownMenu_AddButton(AddButton(self, "a friend")) adam@0: UIDropDownMenu_AddButton(AddButton(self, "party")) adam@0: UIDropDownMenu_AddButton(AddButton(self, "raid")) adam@0: UIDropDownMenu_AddButton(AddButton(self, "guild")) adam@0: UIDropDownMenu_AddButton(AddButton(self, "channel")) adam@0: UIDropDownMenu_AddButton(AddButton(self, "mail")) adam@0: end) adam@0: adam@0: function tab.dropDown:SetValue(newValue) adam@0: AmrSendSettings.SendToType = newValue adam@0: -- Update the text; if we merely wanted it to display newValue, we would not need to do this adam@0: UIDropDownMenu_SetText(tab.dropDown, AmrSendSettings.SendToType) adam@0: -- Because this is called from a sub-menu, only that menu level is closed by default. adam@0: -- Close the entire menu with this next call adam@0: CloseDropDownMenus() adam@0: end adam@0: adam@0: tab.sendTo = CreateFrame("EditBox", "AmrSendTo", tab.shoppingPanel, "InputBoxTemplate" ) adam@0: tab.sendTo:SetPoint("TOPLEFT", tab.dropDown, "TOPRIGHT", 0, 0) adam@0: tab.sendTo:SetPoint("RIGHT", 0, 0) adam@0: tab.sendTo:SetHeight(30) adam@0: tab.sendTo:SetText(AmrSendSettings.SendTo or "") adam@0: tab.sendTo:SetFontObject("GameFontHighlightLarge") adam@0: tab.sendTo:SetAutoFocus(false) adam@0: tab.sendTo:SetScript("OnChar", function() adam@0: AmrSendSettings.SendTo = tab.sendTo:GetText() adam@0: end) adam@0: adam@0: tab.messageQueue = {} adam@0: return tab adam@0: end adam@0: adam@0: -- display a gem icon in a row adam@0: -- gemInfo is {id, enchantId, color, count } adam@0: function AskMrRobot.ShoppingListTab:SetGemIcon(row, gemInfo) adam@0: -- get gem icon for the row adam@0: local gemIcon = self.gemIcons[row] adam@0: adam@0: -- if we don't have one adam@0: if gemIcon == nil then adam@0: -- make one adam@0: gemIcon = AskMrRobot.GemIcon:new(nil, self.scrollParent) adam@0: self.gemIcons[row] = gemIcon adam@0: gemIcon:SetScript("OnMouseDown", function() adam@0: self:SearchForGem(row) adam@0: end) adam@0: adam@0: -- position it adam@0: local previous = self.gemsHeader adam@0: if row > 1 then adam@0: previous = self.gemIcons[row - 1] adam@0: end adam@0: gemIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7) adam@0: adam@0: -- size it adam@0: gemIcon:SetWidth(24) adam@0: gemIcon:SetHeight(24) adam@0: adam@0: -- give it a nice border adam@0: gemIcon:SetRoundBorder() adam@0: end adam@0: adam@0: gemIcon:Show() adam@0: adam@0: -- make a link for the optimized gem adam@0: gemLink = select(2, GetItemInfo(gemInfo.id)) adam@0: adam@0: -- set the link (tooltip + icon) adam@0: gemIcon:SetItemLink(gemLink) adam@0: gemIcon:SetGemColor(gemInfo.color) adam@0: adam@0: -- if we didn't get one, its because WoW is slow adam@0: if not gemLink and gemInfo.id then adam@0: -- when WoW finally returns the link, set the icon / tooltip adam@0: AskMrRobot.RegisterItemInfoCallback(gemInfo.id, function(name, link) adam@0: gemIcon:SetItemLink(link) adam@0: end) adam@0: end adam@0: adam@0: end adam@0: adam@0: adam@0: -- display a gem icon in a row adam@0: -- gemInfo is {id, enchantId, color, count } adam@0: function AskMrRobot.ShoppingListTab:SetGemText(row, gemInfo) adam@0: -- get gem icon for the row adam@0: local gemText = self.gemLinks[row] adam@0: adam@0: -- if we don't have one adam@0: if gemText == nil then adam@0: -- make one adam@0: gemText = AskMrRobot.ItemLinkText:new(nil, self.scrollParent) adam@0: self.gemLinks[row] = gemText adam@0: gemText:SetScript("OnMouseDown", function() adam@0: self:SearchForGem(row) adam@0: end) adam@0: adam@0: -- position it adam@0: local previous = self.gemsHeader adam@0: if row > 1 then adam@0: previous = self.gemIcons[row - 1] adam@0: end adam@0: gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8) adam@0: gemText:SetPoint("RIGHT", self, "RIGHT", -70, 0) adam@0: gemText:SetHeight(18) adam@0: gemText:SetFontSize(15) adam@0: end adam@0: adam@0: gemText:Show() adam@0: adam@0: gemText:SetItemId(gemInfo.id) adam@0: end adam@0: adam@0: -- display a gem icon in a row adam@0: -- gemInfo is {id, enchantId, color, count } adam@0: function AskMrRobot.ShoppingListTab:SetGemQuantity(row, qty, total) adam@0: if qty > total then qty = total end adam@0: adam@0: -- get gem icon for the row adam@0: local gemText = self.gemQuantity[row] adam@0: adam@0: -- if we don't have one adam@0: if gemText == nil then adam@0: -- make one adam@0: gemText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: self.gemQuantity[row] = gemText adam@0: adam@0: -- position it adam@0: local previous = self.gemsHeader adam@0: if row > 1 then adam@0: previous = self.gemIcons[row - 1] adam@0: end adam@0: gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) adam@0: gemText:SetHeight(18) adam@0: gemText:SetFontSize(15) adam@0: end adam@0: adam@0: gemText:SetText('' .. qty .. '/' .. total) adam@0: if qty == total then adam@0: gemText:SetTextColor(0,1,0) adam@0: else adam@0: gemText:SetTextColor(1,0,0) adam@0: end adam@0: gemText:Show() adam@0: end adam@0: adam@0: adam@0: -- display an enchant icon in a row adam@0: function AskMrRobot.ShoppingListTab:SetEnchantIcon(row, enchantId) adam@0: adam@0: -- get enchant icon for the row adam@0: local enchantIcon = self.enchantIcons[row] adam@0: adam@0: -- if we don't have one adam@0: if enchantIcon == nil then adam@0: -- make one adam@0: enchantIcon = AskMrRobot.EnchantLinkIconAndText:new(nil, self.scrollParent) adam@0: self.enchantIcons[row] = enchantIcon adam@0: enchantIcon:SetScript("OnMouseDown", function() adam@0: self:SearchForEnchant(row) adam@0: end) adam@0: adam@0: -- position it adam@0: if row == 1 then adam@0: enchantIcon:SetPoint("TOPLEFT", self.enchantsHeader, "BOTTOMLEFT", 0, -12) adam@0: enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0) adam@0: else adam@0: enchantIcon:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -7) adam@0: enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0) adam@0: end adam@0: adam@0: -- size it adam@0: enchantIcon:SetWidth(24) adam@0: enchantIcon:SetHeight(24) adam@0: enchantIcon:SetFontSize(15) adam@0: adam@0: -- give it a nice border adam@0: enchantIcon:SetRoundBorder() adam@0: adam@0: enchantIcon:UseSpellName() adam@0: end adam@0: adam@0: enchantIcon:SetEnchantId(enchantId) adam@0: adam@0: enchantIcon:Show() adam@0: end adam@0: adam@0: -- display a gem icon in a row adam@0: -- gemInfo is {id, enchantId, color, count } adam@0: function AskMrRobot.ShoppingListTab:SetEnchantQuantity(row, qty, total) adam@0: if qty > total then qty = total end adam@0: adam@0: -- get gem icon for the row adam@0: local enchantText = self.enchantQuantity[row] adam@0: adam@0: -- if we don't have one adam@0: if enchantText == nil then adam@0: -- make one adam@0: enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: self.enchantQuantity[row] = enchantText adam@0: adam@0: -- position it adam@0: local previous = self.enchantsHeader adam@0: if row > 1 then adam@0: previous = self.enchantIcons[row - 1] adam@0: end adam@0: enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) adam@0: enchantText:SetHeight(18) adam@0: enchantText:SetFontSize(15) adam@0: end adam@0: adam@0: enchantText:SetText('' .. qty .. '/' .. total) adam@0: if qty == total then adam@0: enchantText:SetTextColor(0,1,0) adam@0: else adam@0: enchantText:SetTextColor(1,0,0) adam@0: end adam@0: enchantText:Show() adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:SearchForItem(itemName) adam@0: if self.isAuctionHouseVisible then adam@0: QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0, 0) adam@0: end adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:SearchForGem(row) adam@0: self:SearchForItem(self.gemLinks[row].itemName) adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:SearchForEnchant(row) adam@0: self:SearchForItem(self.enchantIcons[row].itemName) adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:SearchForEnchantMaterial(row) adam@0: self:SearchForItem(self.enchantMaterialLinks[row].itemName) adam@0: end adam@0: adam@0: adam@0: -- display an enchant material icon in a row adam@0: function AskMrRobot.ShoppingListTab:SetEnchantMaterialIcon(row, itemId) adam@0: -- get enchant material icon for the row adam@0: local materialIcon = self.enchantMaterialIcons[row] adam@0: adam@0: -- if we don't have one adam@0: if materialIcon == nil then adam@0: -- make one adam@0: materialIcon = AskMrRobot.ItemIcon:new(nil, self.scrollParent) adam@0: self.enchantMaterialIcons[row] = materialIcon adam@0: materialIcon:SetScript("OnMouseDown", function() adam@0: self:SearchForEnchantMaterial(row) adam@0: end) adam@0: adam@0: -- position it adam@0: local previous = self.enchantMaterialsHeader adam@0: if row > 1 then adam@0: previous = self.enchantMaterialIcons[row - 1] adam@0: end adam@0: materialIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7) adam@0: adam@0: -- size it adam@0: materialIcon:SetWidth(24) adam@0: materialIcon:SetHeight(24) adam@0: adam@0: -- give it a nice border adam@0: materialIcon:SetRoundBorder() adam@0: end adam@0: adam@0: materialIcon:Show() adam@0: adam@0: -- make a link for the optimized gem adam@0: local itemLink = select(2, GetItemInfo(itemId)) adam@0: adam@0: materialIcon:SetItemLink(itemLink) adam@0: adam@0: -- if we didn't get one, its because WoW is slow adam@0: if not itemLink and itemId then adam@0: -- when WoW finally returns the link, set the icon / tooltip adam@0: AskMrRobot.RegisterItemInfoCallback(itemId, function(name, link) adam@0: materialIcon:SetItemLink(link) adam@0: end) adam@0: end adam@0: end adam@0: adam@0: adam@0: -- display an enchant material link in a row adam@0: function AskMrRobot.ShoppingListTab:SetEnchantMaterialLink(row, itemId) adam@0: -- get gem icon for the row adam@0: local materialLink = self.enchantMaterialLinks[row] adam@0: adam@0: -- if we don't have one adam@0: if materialLink == nil then adam@0: -- make one adam@0: materialLink = AskMrRobot.ItemLinkText:new(nil, self.scrollParent) adam@0: self.enchantMaterialLinks[row] = materialLink adam@0: materialLink:SetScript("OnMouseDown", function() adam@0: self:SearchForEnchantMaterial(row) adam@0: end) adam@0: adam@0: -- position it adam@0: local previous = self.enchantMaterialsHeader adam@0: if row > 1 then adam@0: previous = self.enchantMaterialIcons[row - 1] adam@0: end adam@0: materialLink:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8) adam@0: materialLink:SetPoint("RIGHT", self, "RIGHT", -30, 0) adam@0: materialLink:SetHeight(18) adam@0: materialLink:SetFontSize(15) adam@0: end adam@0: adam@0: materialLink:Show() adam@0: adam@0: materialLink:SetItemId(itemId) adam@0: materialLink.itemId = itemId adam@0: end adam@0: adam@0: -- display a gem icon in a row adam@0: -- gemInfo is {id, enchantId, color, count } adam@0: function AskMrRobot.ShoppingListTab:SetEnchantMaterialQuantity(row, qty, total) adam@0: if qty > total then qty = total end adam@0: adam@0: -- get gem icon for the row adam@0: local enchantText = self.enchantMaterialQuantity[row] adam@0: adam@0: -- if we don't have one adam@0: if enchantText == nil then adam@0: -- make one adam@0: enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") adam@0: self.enchantMaterialQuantity[row] = enchantText adam@0: adam@0: -- position it adam@0: local previous = self.enchantMaterialsHeader adam@0: if row > 1 then adam@0: previous = self.enchantMaterialIcons[row - 1] adam@0: end adam@0: enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) adam@0: enchantText:SetHeight(18) adam@0: enchantText:SetFontSize(15) adam@0: end adam@0: adam@0: enchantText:SetText('' .. qty .. '/' .. total) adam@0: if qty == total then adam@0: enchantText:SetTextColor(0,1,0) adam@0: else adam@0: enchantText:SetTextColor(1,0,0) adam@0: end adam@0: enchantText:Show() adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:HasStuffToBuy() adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@0: local count = 0 adam@0: for gemId, gemInfo in AskMrRobot.spairs(gemList) do adam@0: count = count + gemInfo.total - gemInfo.count adam@0: end adam@0: for slot, enchant in AskMrRobot.spairs(enchantList) do adam@0: count = count + enchant.total - enchant.count adam@0: end adam@0: adam@0: return count > 0 adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:CalculateItems() adam@0: -- build a map of missing gem-ids -> {id, color, enchantid, count, total} adam@0: local gemList = {} adam@0: for slotNum, badGems in pairs(AskMrRobot.itemDiffs.gems) do adam@0: --badGems: {current: array of enchant ids, optimized: (array of {id, color, enchantId}) adam@0: for i = 1, #badGems.optimized do adam@0: if badGems.badGems[i] then adam@0: local goodGem = badGems.optimized[i] adam@0: if goodGem.id ~= 0 then adam@0: local gem = gemList[goodGem.id] adam@0: if gem == nil then adam@0: gemList[goodGem.id] = {id = goodGem.id, enchantId = goodGem.enchantId, color = goodGem.color, count = 0, total = 1} adam@0: else adam@0: gem.total = gem.total + 1 adam@0: end adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: local enchantList = {} adam@0: for slot, enchantData in AskMrRobot.sortSlots(AskMrRobot.itemDiffs.enchants) do adam@0: local id = AskMrRobot.getEnchantItemId(enchantData.optimized) or enchantData.optimized adam@0: local qty = enchantList[id] adam@0: if qty then adam@0: qty.total = qty.total + 1 adam@0: else adam@0: qty = { count = 0, total = 1, optimized = enchantData.optimized } adam@0: enchantList[id] = qty adam@0: end adam@0: end adam@0: adam@0: local enchantMaterials = {} adam@0: for slot, enchantData in pairs(AskMrRobot.itemDiffs.enchants) do adam@0: AskMrRobot.addEnchantMaterials(enchantMaterials, enchantData.optimized) adam@0: end adam@0: adam@0: --substract any inventory we already have in the bank adam@0: for i = 1, #AmrBankItemsAndCounts do adam@0: local itemId = AskMrRobot.getItemIdFromLink(AmrBankItemsAndCounts[i].link) adam@0: if itemId then adam@0: local gem = gemList[itemId] adam@0: if gem then adam@0: gem.count = gem.count + AmrBankItemsAndCounts[i].count adam@0: else adam@0: local alternateGemId = AskMrRobot.gemDuplicates[itemId] adam@0: if alternateGemId then adam@0: gem = gemList[alternateGemId] adam@0: if gem then adam@0: gem.count = gem.count + AmrBankItemsAndCounts[i].count adam@0: end adam@0: end adam@0: end adam@0: local material = enchantMaterials[itemId] adam@0: if material then adam@0: material.count = material.count + AmrBankItemsAndCounts[i].count adam@0: end adam@0: local enchant = enchantList[itemId] adam@0: if enchant then adam@0: enchant.count = enchant.count + AmrBankItemsAndCounts[i].count adam@0: end adam@0: end adam@0: end adam@0: adam@0: local _ , bagItemsWithCount = AskMrRobot.ScanBags() adam@0: adam@0: --substract any inventory we already have in bags adam@0: for i = 1, #bagItemsWithCount do adam@0: local itemId = AskMrRobot.getItemIdFromLink(bagItemsWithCount[i].link) adam@0: if itemId then adam@0: local gem = gemList[itemId] adam@0: if gem then adam@0: gem.count = gem.count + bagItemsWithCount[i].count adam@0: else adam@0: local alternateGemId = AskMrRobot.gemDuplicates[itemId] adam@0: if alternateGemId then adam@0: gem = gemList[alternateGemId] adam@0: if gem then adam@0: gem.count = gem.count + bagItemsWithCount[i].count adam@0: end adam@0: end adam@0: end adam@0: local material = enchantMaterials[itemId] adam@0: if material then adam@0: material.count = material.count + bagItemsWithCount[i].count adam@0: end adam@0: local enchant = enchantList[itemId] adam@0: if enchant then adam@0: enchant.count = enchant.count + bagItemsWithCount[i].count adam@0: end adam@0: end adam@0: end adam@0: adam@0: return gemList, enchantList, enchantMaterials adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:Update() adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@0: -- update the UI adam@0: local lastControl = nil adam@0: local row = 1 adam@0: for gemId, gemInfo in AskMrRobot.spairs(gemList) do adam@0: self:SetGemIcon(row, gemInfo) adam@0: self:SetGemText(row, gemInfo) adam@0: self:SetGemQuantity(row, gemInfo.count, gemInfo.total) adam@0: lastControl = self.gemIcons[row] adam@0: row = row + 1 adam@0: end adam@0: adam@0: -- hide any extra gem icons adam@0: for i = row, #self.gemIcons do adam@0: self.gemIcons[i]:Hide() adam@0: self.gemLinks[i]:Hide() adam@0: self.gemQuantity[i]:Hide() adam@0: end adam@0: adam@0: -- hide / show the gems header, and position the enchant headers adam@0: if row > 1 then adam@0: self.gemsHeader:Show() adam@0: self.gemsQuantityHeader:Show() adam@0: self.enchantsHeader:SetPoint("TOPLEFT", self.gemIcons[row - 1], "BOTTOMLEFT", 0, -15) adam@0: else adam@0: self.gemsHeader:Hide() adam@0: self.gemsQuantityHeader:Hide() adam@0: self.enchantsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0) adam@0: end adam@0: adam@0: row = 1 adam@0: for slot, enchant in AskMrRobot.spairs(enchantList) do adam@0: self:SetEnchantIcon(row, enchant.optimized) adam@0: self:SetEnchantQuantity(row, enchant.count, enchant.total) adam@0: lastControl = self.enchantIcons[row] adam@0: row = row + 1 adam@0: end adam@0: adam@0: -- hide any extra enchant icons adam@0: for i = row, #self.enchantIcons do adam@0: self.enchantIcons[i]:Hide() adam@0: self.enchantQuantity[i]:Hide() adam@0: end adam@0: adam@0: -- hide / show the enchants header, and position the enchant materials headers adam@0: if row > 1 then adam@0: self.enchantsHeader:Show() adam@0: self.enchantsQuantityHeader:Show() adam@0: self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -15) adam@0: else adam@0: self.enchantsHeader:Hide() adam@0: self.enchantsQuantityHeader:Hide() adam@0: self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0) adam@0: end adam@0: adam@0: row = 1 adam@0: for itemId, count in AskMrRobot.spairs(enchantMaterials) do adam@0: self:SetEnchantMaterialIcon(row, itemId) adam@0: self:SetEnchantMaterialLink(row, itemId) adam@0: self:SetEnchantMaterialQuantity(row, count.count, count.total) adam@0: lastControl = self.enchantMaterialIcons[row] adam@0: row = row + 1 adam@0: end adam@0: adam@0: for i = row, #self.enchantMaterialIcons do adam@0: self.enchantMaterialIcons[i]:Hide() adam@0: self.enchantMaterialLinks[i]:Hide() adam@0: self.enchantMaterialQuantity[i]:Hide() adam@0: end adam@0: adam@0: if row == 1 then adam@0: self.enchantMaterialsHeader:Hide() adam@0: self.enchantMaterialsQuantityHeader:Hide() adam@0: else adam@0: self.enchantMaterialsHeader:Show() adam@0: self.enchantMaterialsQuantityHeader:Show() adam@0: end adam@0: adam@0: -- fix up the scrollbar length adam@0: if lastControl then adam@0: local height = self.scrollParent:GetTop() - lastControl:GetBottom() adam@0: self.scrollParent:SetHeight(height) adam@0: if height < self.scrollFrame:GetHeight() then adam@0: self.scrollFrame.ScrollBar:Hide() adam@0: else adam@0: self.scrollFrame:Show() adam@0: self.scrollFrame.ScrollBar:Show() adam@0: end adam@0: self.stamp:Hide() adam@0: self.shoppingPanel:Show() adam@0: else adam@0: self.scrollFrame.ScrollBar:Hide() adam@0: self.shoppingPanel:Hide() adam@0: self.stamp:Show() adam@0: end adam@0: end adam@0: adam@0: adam@0: function AskMrRobot.ShoppingListTab:OnEvent(frame, event, ...) adam@0: local handler = self["On_" .. event] adam@0: if handler then adam@0: handler(self, ...) adam@0: end adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:On_MAIL_SHOW() adam@0: self.mailOpen = true adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:On_MAIL_CLOSED() adam@0: self.mailOpen = nil adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_SHOW() adam@0: self.isAuctionHouseVisible = true adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_CLOSED() adam@0: self.isAuctionHouseVisible = false adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:sendMail() adam@0: adam@0: -- need mail window to be open for this to work adam@0: if not self.mailOpen then adam@0: StaticPopup_Show("SHOPPING_TAB_PLEASE_OPEN") adam@0: return adam@0: end adam@0: adam@0: local message = "Mr. Robot says I need the following to optimize my gear:\n" adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@0: if AmrSendSettings.SendGems then adam@0: for k,v in pairs(gemList) do adam@0: --exclude jewelcrafter gems adam@0: if not AskMrRobot.JewelcrafterGems[k] then adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: local itemName = GetItemInfo(k) adam@0: if itemName then adam@0: message = message .. "\n" .. needed .. "x " .. itemName adam@0: end adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: if AmrSendSettings.SendEnchants then adam@0: for k,v in pairs(enchantList) do adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: local itemName = GetItemInfo(k) adam@0: if itemName then adam@0: message = message .. "\n" .. needed .. "x " .. itemName adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: if AmrSendSettings.SendEnchantMaterials then adam@0: for k,v in pairs(enchantMaterials) do adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: local itemName = GetItemInfo(k) adam@0: if itemName then adam@0: message = message .. "\n" .. needed .. "x " .. itemName adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: MailFrameTab_OnClick(nil, 2) adam@0: if AmrSendSettings.SendGems then adam@0: if AmrSendSettings.SendEnchants then adam@0: SendMailSubjectEditBox:SetText('Request for gems and enchants') adam@0: else adam@0: SendMailSubjectEditBox:SetText('Request for gems') adam@0: end adam@0: else adam@0: SendMailSubjectEditBox:SetText('Request for enchants') adam@0: end adam@0: SendMailNameEditBox:SetText(AmrSendSettings.SendTo) adam@0: SendMailBodyEditBox:SetText(message) adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:Send() adam@0: local chatType = nil adam@0: if AmrSendSettings.SendToType == "party" then adam@0: chatType = "PARTY" adam@0: elseif AmrSendSettings.SendToType == "guild" then adam@0: chatType = "GUILD" adam@0: elseif AmrSendSettings.SendToType == "raid" then adam@0: chatType = "RAID" adam@0: elseif AmrSendSettings.SendToType == "channel" then adam@0: chatType = "CHANNEL" adam@0: elseif AmrSendSettings.SendToType == "mail" then adam@0: self:sendMail() adam@0: return adam@0: else adam@0: chatType = "WHISPER" adam@0: end adam@0: adam@0: local message = "Mr. Robot says I need" adam@0: local count = 0 adam@0: adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@0: local items = {} adam@0: if AmrSendSettings.SendGems then adam@0: for k,v in pairs(gemList) do adam@0: if not AskMrRobot.JewelcrafterGems[k] then adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: tinsert(items, {id = k, needed = needed}) adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: if AmrSendSettings.SendEnchants then adam@0: for k,v in pairs(enchantList) do adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: tinsert(items, {id = k, needed = needed}) adam@0: end adam@0: end adam@0: end adam@0: adam@0: if AmrSendSettings.SendEnchantMaterials then adam@0: for k,v in pairs(enchantMaterials) do adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@0: tinsert(items, {id = k, needed = needed}) adam@0: end adam@0: end adam@0: end adam@0: adam@0: for i, entry in ipairs(items) do adam@0: local _, link = GetItemInfo(entry.id) adam@0: if link then adam@0: message = message .. " " .. entry.needed .. "x " .. link adam@0: count = count + 1 adam@0: if count == 2 then adam@0: tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrSendSettings.SendTo}) adam@0: count = 0 adam@0: message = "Mr. Robot says I need" adam@0: end adam@0: end adam@0: end adam@0: adam@0: if count > 0 then adam@0: tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrSendSettings.SendTo}) adam@0: end adam@0: adam@0: self:SendNextMessage() adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:SendNextMessage() adam@0: while #self.messageQueue > 0 do adam@0: local entry = self.messageQueue[1] adam@0: table.remove(self.messageQueue, 1) adam@0: SendChatMessage(entry.message, entry.chatType, nil, entry.chatChannel) adam@0: end adam@0: end