adam@0: local _, AskMrRobot = ... yellowfive@11: local L = AskMrRobot.L; 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"] = { yellowfive@11: text = L.AMR_SHOPPINGLISTTAB_OPEN_MAIL, yellowfive@11: button1 = L.AMR_SHOPPINGLISTTAB_BUTTON_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) yellowfive@11: tab.shoppingListHeader:SetText(L.AMR_SHOPPINGLISTTAB_TITLE) 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") yellowfive@11: tab.sendButton:SetText(L.AMR_SHOPPINGLISTTAB_BUTTON_SEND) 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@17: tab.enchantMaterialsCheckbox:SetChecked(AmrDb.SendSettings.SendEnchantMaterials) adam@17: tab.enchantMaterialsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.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") yellowfive@11: text3:SetText(L.AMR_SHOPPINGLISTTAB_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@17: tab.enchantsCheckbox:SetChecked(AmrDb.SendSettings.SendEnchants) adam@17: tab.enchantsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.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") yellowfive@11: text2:SetText(L.AMR_SHOPPINGLISTTAB_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@17: tab.gemsCheckbox:SetChecked(AmrDb.SendSettings.SendGems) adam@17: tab.gemsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.SendGems = tab.gemsCheckbox:GetChecked() end) adam@0: local text = getglobal(tab.gemsCheckbox:GetName() .. 'Text') adam@0: text:SetFontObject("GameFontHighlightLarge") yellowfive@11: text:SetText(L.AMR_SHOPPINGLISTTAB_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") yellowfive@11: tab.sendMessage4:SetText(L.AMR_SHOPPINGLISTTAB_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") yellowfive@11: tab.sendMessage3:SetText(L.AMR_SHOPPINGLISTTAB_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) yellowfive@11: tab.sendMessage2:SetText(L.AMR_SHOPPINGLISTTAB_WHISPER_CHANNEL) 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) yellowfive@11: tab.sendMessage1:SetText(L.AMR_SHOPPINGLISTTAB_SEND_JEWELCRAFT_ENCHANTER) 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") yellowfive@11: tab.gemsHeader:SetText(L.AMR_SHOPPINGLISTTAB_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") yellowfive@11: tab.gemsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_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") yellowfive@11: tab.enchantsHeader:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANTS) adam@0: adam@0: tab.enchantsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") yellowfive@11: tab.enchantsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_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") yellowfive@11: tab.enchantMaterialsHeader:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANT_MATERIALS) adam@0: adam@0: tab.enchantMaterialsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") yellowfive@11: tab.enchantMaterialsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_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() yellowfive@11: tab.stamp.bigText:SetText(L.AMR_SHOPPINGLISTTAB_DONE) yellowfive@11: tab.stamp.smallText:SetText(L.AMR_SHOPPINGLISTTAB_A_ROBOTS_WISHLIST) 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@17: UIDropDownMenu_SetText(tab.dropDown, AmrDb.SendSettings.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@17: info.checked = AmrDb.SendSettings.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) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_FRIEND)) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_PARTY)) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_RAID)) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_GUILD)) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_CHANNEL)) yellowfive@11: UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_MAIL)) adam@0: end) adam@0: adam@0: function tab.dropDown:SetValue(newValue) adam@17: AmrDb.SendSettings.SendToType = newValue adam@0: -- Update the text; if we merely wanted it to display newValue, we would not need to do this adam@17: UIDropDownMenu_SetText(tab.dropDown, AmrDb.SendSettings.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@17: tab.sendTo:SetText(AmrDb.SendSettings.SendTo or "") adam@0: tab.sendTo:SetFontObject("GameFontHighlightLarge") adam@0: tab.sendTo:SetAutoFocus(false) adam@0: tab.sendTo:SetScript("OnChar", function() adam@17: AmrDb.SendSettings.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@17: --gemIcon:SetGemColor(gemInfo.color) adam@17: gemIcon:SetGemColor('Prismatic') 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@17: -- build a map of missing gem-enchant-ids -> {id, enchantid, count, total} adam@0: local gemList = {} adam@17: adam@17: -- for each piece of gear that needs at least 1 gem changed adam@17: for _, badGems in pairs(AskMrRobot.ComparisonResult.gems) do adam@17: -- for each specified gem adam@17: for g = 1, #badGems.optimized do adam@17: local goodGemEnchantId = badGems.optimized[g] adam@17: -- if AMR says to optimized this gem AND it does *NOT* match matches the current gem adam@17: if goodGemEnchantId ~= 0 and not AskMrRobot.AreGemsCompatible(goodGemEnchantId, badGems.current[g]) then adam@17: -- see if this gem is in our list of gems to optimize adam@17: local gem = gemList[goodGemEnchantId] adam@17: if gem == nil then adam@17: -- if not, add it adam@17: gemList[goodGemEnchantId] = {id = AskMrRobot.ExtraGemData[goodGemEnchantId].id, enchantId = goodGemEnchantId, count = 0, total = 1, compatibleGemIds = AskMrRobot.ExtraGemData[goodGemEnchantId].identicalItemGroup} adam@17: else adam@17: -- if so, increase the total requested for this adam@17: gem.total = gem.total + 1 adam@0: end adam@0: end adam@0: end adam@0: end adam@0: adam@0: local enchantList = {} adam@17: for slot, enchantData in AskMrRobot.sortSlots(AskMrRobot.ComparisonResult.enchants) do adam@17: local extraData = AskMrRobot.ExtraEnchantData[enchantData.optimized] adam@17: local id = extraData and extraData.itemId 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@17: for slot, enchantData in pairs(AskMrRobot.ComparisonResult.enchants) do adam@17: local extraData = AskMrRobot.ExtraEnchantData[enchantData.optimized] adam@17: if extraData and extraData.materials then adam@17: local itemId adam@17: local count adam@17: for itemId, count in pairs(extraData.materials) do adam@17: if enchantMaterials[itemId] then adam@17: enchantMaterials[itemId].total = enchantMaterials[itemId].total + count adam@17: else adam@17: enchantMaterials[itemId] = { count = 0, total = count } adam@17: end adam@17: end adam@17: end adam@17: adam@0: end adam@0: adam@17: local bagItemsWithCounts = {} adam@17: -- copy the bank items into a new table so we don't alter them adam@17: if (AmrDb.BankItemsAndCounts) then adam@17: for id, count in pairs(AmrDb.BankItemsAndCounts) do adam@17: bagItemsWithCounts[id] = count adam@0: end adam@0: end adam@0: adam@17: -- add the items from the players bags adam@17: AskMrRobot.ScanBags(bagItemsWithCounts) adam@0: adam@21: -- note: void storage can't hold stackable items, so don't worry about them adam@21: adam@17: --substract any inventory we already have in bags/bank adam@17: for itemId, count in pairs(bagItemsWithCounts) do adam@17: for _, gem in pairs(gemList) do adam@17: if gem.compatibleGemIds[itemId] and gem.count < gem.total then adam@17: local needed = gem.total - gem.count adam@17: if count > needed then adam@17: gem.count = gem.total adam@17: -- only consume the number needed (subtract in case this is compatible with a different gem) adam@17: count = count - needed adam@17: else adam@17: gem.count = gem.count + count adam@17: count = 0 adam@0: end adam@0: end adam@17: end adam@17: local material = enchantMaterials[itemId] adam@17: if material then adam@17: material.count = material.count + count adam@17: end adam@17: local enchant = enchantList[itemId] adam@17: if enchant then adam@17: enchant.count = enchant.count + count 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: yellowfive@11: local message = L.AMR_SHOPPINGLISTTAB_MAIL_ROBOT_MESSAGE adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@17: if AmrDb.SendSettings.SendGems then adam@0: for k,v in pairs(gemList) do adam@0: --exclude jewelcrafter gems adam@17: --if not AskMrRobot.JewelcrafterGems[k] then adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@17: local itemName = GetItemInfo(v.id) adam@0: if itemName then adam@0: message = message .. "\n" .. needed .. "x " .. itemName adam@0: end adam@0: end adam@17: --end adam@0: end adam@0: end adam@0: adam@17: if AmrDb.SendSettings.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@17: if AmrDb.SendSettings.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@17: if AmrDb.SendSettings.SendGems then adam@17: if AmrDb.SendSettings.SendEnchants then yellowfive@11: SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_GE) adam@0: else yellowfive@11: SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_G) adam@0: end adam@0: else yellowfive@11: SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_E) adam@0: end adam@17: SendMailNameEditBox:SetText(AmrDb.SendSettings.SendTo) adam@0: SendMailBodyEditBox:SetText(message) adam@0: end adam@0: adam@0: function AskMrRobot.ShoppingListTab:Send() adam@0: local chatType = nil adam@17: if AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_PARTY then adam@0: chatType = "PARTY" adam@17: elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_GUILD then adam@0: chatType = "GUILD" adam@17: elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_RAID then adam@0: chatType = "RAID" adam@17: elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_CHANNEL then adam@0: chatType = "CHANNEL" adam@17: elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_MAIL then adam@0: self:sendMail() adam@0: return adam@0: else adam@0: chatType = "WHISPER" adam@0: end adam@0: yellowfive@11: local message = L.AMR_SHOPPINGLISTTAB_CHAT_ROBOT_MESSAGE adam@0: local count = 0 adam@0: adam@0: adam@0: local gemList, enchantList, enchantMaterials = self:CalculateItems() adam@0: adam@0: local items = {} adam@17: if AmrDb.SendSettings.SendGems then adam@0: for k,v in pairs(gemList) do adam@17: --if not AskMrRobot.JewelcrafterGems[k] then adam@0: local needed = v.total - v.count adam@0: if needed > 0 then adam@17: tinsert(items, {id = v.id, needed = needed}) adam@0: end adam@17: --end adam@0: end adam@0: end adam@0: adam@17: if AmrDb.SendSettings.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@17: if AmrDb.SendSettings.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@17: tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrDb.SendSettings.SendTo}) adam@0: count = 0 yellowfive@11: message = L.AMR_SHOPPINGLISTTAB_CHAT_ROBOT_MESSAGE adam@0: end adam@0: end adam@0: end adam@0: adam@0: if count > 0 then adam@17: tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrDb.SendSettings.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