| adam@0 | 1 local _, AskMrRobot = ... | 
| yellowfive@11 | 2 local L = AskMrRobot.L; | 
| adam@0 | 3 | 
| adam@0 | 4 -- initialize the ShoppingListTab class | 
| adam@0 | 5 AskMrRobot.ShoppingListTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame) | 
| adam@0 | 6 | 
| adam@0 | 7 StaticPopupDialogs["SHOPPING_TAB_PLEASE_OPEN"] = { | 
| yellowfive@11 | 8 	text = L.AMR_SHOPPINGLISTTAB_OPEN_MAIL, | 
| yellowfive@11 | 9 	button1 = L.AMR_SHOPPINGLISTTAB_BUTTON_OK, | 
| adam@0 | 10 	timeout = 0, | 
| adam@0 | 11 	whileDead = true, | 
| adam@0 | 12 	hideOnEscape = true, | 
| adam@0 | 13 	preferredIndex = 3,  -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/ | 
| adam@0 | 14 } | 
| adam@0 | 15 | 
| adam@0 | 16 function AskMrRobot.ShoppingListTab:new(parent) | 
| adam@0 | 17 | 
| adam@0 | 18 	local tab = AskMrRobot.Frame:new(nil, parent) | 
| adam@0 | 19 	setmetatable(tab, { __index = AskMrRobot.ShoppingListTab }) | 
| adam@0 | 20 	tab:SetPoint("TOPLEFT") | 
| adam@0 | 21 	tab:SetPoint("BOTTOMRIGHT") | 
| adam@0 | 22 	tab:Hide() | 
| adam@0 | 23 	tab:RegisterEvent("AUCTION_HOUSE_CLOSED") | 
| adam@0 | 24 	tab:RegisterEvent("AUCTION_HOUSE_SHOW") | 
| adam@0 | 25 	tab:RegisterEvent("MAIL_SHOW") | 
| adam@0 | 26 	tab:RegisterEvent("MAIL_CLOSED") | 
| adam@0 | 27 | 
| adam@0 | 28 	tab.isAuctionHouseVisible = false | 
| adam@0 | 29 | 
| adam@0 | 30 	tab:SetScript("OnEvent", function(...) | 
| adam@0 | 31 		tab:OnEvent(...) | 
| adam@0 | 32 	end) | 
| adam@0 | 33 | 
| adam@0 | 34 	tab.shoppingListHeader = AskMrRobot.FontString:new(tab, nil, "ARTWORK", "GameFontNormalLarge") | 
| adam@0 | 35 	tab.shoppingListHeader:SetPoint("TOPLEFT", 0, -5) | 
| yellowfive@11 | 36 	tab.shoppingListHeader:SetText(L.AMR_SHOPPINGLISTTAB_TITLE) | 
| adam@0 | 37 | 
| adam@0 | 38 	tab.shoppingPanel = AskMrRobot.Frame:new(nil, tab) | 
| adam@0 | 39 	tab.shoppingPanel:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 0, -10) | 
| adam@0 | 40 	tab.shoppingPanel:SetPoint("BOTTOMRIGHT", tab, "BOTTOMRIGHT", -20, 17) | 
| adam@0 | 41 | 
| adam@0 | 42 | 
| adam@0 | 43 	tab.sendButton = CreateFrame("Button", "AmrSendButton", tab.shoppingPanel, "UIPanelButtonTemplate") | 
| yellowfive@11 | 44 	tab.sendButton:SetText(L.AMR_SHOPPINGLISTTAB_BUTTON_SEND) | 
| adam@0 | 45 	tab.sendButton:SetPoint("BOTTOMLEFT", 0, 0) | 
| adam@0 | 46 	tab.sendButton:SetHeight(25) | 
| adam@0 | 47 	tab.sendButton:SetNormalFontObject("GameFontNormalLarge") | 
| adam@0 | 48 	tab.sendButton:SetHighlightFontObject("GameFontHighlightLarge") | 
| adam@0 | 49 	tab.sendButton:SetWidth(150) | 
| adam@0 | 50 	tab.sendButton:SetScript("OnClick", function() | 
| adam@0 | 51 		tab:Send() | 
| adam@0 | 52 	end) | 
| adam@0 | 53 | 
| adam@0 | 54 	tab.enchantMaterialsCheckbox = CreateFrame("CheckButton", "AmrEnchantMaterialsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); | 
| adam@17 | 55 	tab.enchantMaterialsCheckbox:SetChecked(AmrDb.SendSettings.SendEnchantMaterials) | 
| adam@17 | 56 	tab.enchantMaterialsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.SendEnchantMaterials = tab.enchantMaterialsCheckbox:GetChecked() end) | 
| adam@0 | 57 	tab.enchantMaterialsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 25) | 
| adam@0 | 58 	local text3 = getglobal(tab.enchantMaterialsCheckbox:GetName() .. 'Text') | 
| adam@0 | 59 	text3:SetFontObject("GameFontHighlightLarge") | 
| yellowfive@11 | 60 	text3:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANT_MATERIALS) | 
| adam@0 | 61 	text3:SetWidth(150) | 
| adam@0 | 62 	text3:SetPoint("TOPLEFT", tab.enchantMaterialsCheckbox, "TOPRIGHT", 2, -4) | 
| adam@0 | 63 | 
| adam@0 | 64 | 
| adam@0 | 65 	tab.enchantsCheckbox = CreateFrame("CheckButton", "AmrEnchantsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); | 
| adam@17 | 66 	tab.enchantsCheckbox:SetChecked(AmrDb.SendSettings.SendEnchants) | 
| adam@17 | 67 	tab.enchantsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.SendEnchants = tab.enchantsCheckbox:GetChecked() end) | 
| adam@0 | 68 	tab.enchantsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 50) | 
| adam@0 | 69 	local text2 = getglobal(tab.enchantsCheckbox:GetName() .. 'Text') | 
| adam@0 | 70 	text2:SetFontObject("GameFontHighlightLarge") | 
| yellowfive@11 | 71 	text2:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANTS) | 
| adam@0 | 72 	text2:SetWidth(150) | 
| adam@0 | 73 	text2:SetPoint("TOPLEFT", tab.enchantsCheckbox, "TOPRIGHT", 2, -4) | 
| adam@0 | 74 | 
| adam@0 | 75 | 
| adam@0 | 76 | 
| adam@0 | 77 	tab.gemsCheckbox = CreateFrame("CheckButton", "AmrGemsCheckbox", tab.shoppingPanel, "ChatConfigCheckButtonTemplate"); | 
| adam@0 | 78 	tab.gemsCheckbox:SetPoint("TOPLEFT", tab.sendButton, "TOPLEFT", 0, 75) | 
| adam@17 | 79 	tab.gemsCheckbox:SetChecked(AmrDb.SendSettings.SendGems) | 
| adam@17 | 80 	tab.gemsCheckbox:SetScript("OnClick", function () AmrDb.SendSettings.SendGems = tab.gemsCheckbox:GetChecked() end) | 
| adam@0 | 81 	local text = getglobal(tab.gemsCheckbox:GetName() .. 'Text') | 
| adam@0 | 82 	text:SetFontObject("GameFontHighlightLarge") | 
| yellowfive@11 | 83 	text:SetText(L.AMR_SHOPPINGLISTTAB_GEMS) | 
| adam@0 | 84 	text:SetWidth(150) | 
| adam@0 | 85 	text:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPRIGHT", 2, -4) | 
| adam@0 | 86 | 
| adam@0 | 87 | 
| adam@0 | 88 	tab.sendMessage4 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge") | 
| yellowfive@11 | 89 	tab.sendMessage4:SetText(L.AMR_SHOPPINGLISTTAB_INCLUDE) | 
| adam@0 | 90 	tab.sendMessage4:SetPoint("TOPLEFT", tab.gemsCheckbox, "TOPLEFT", 0, 20) | 
| adam@0 | 91 | 
| adam@0 | 92 | 
| adam@0 | 93 	tab.sendMessage3 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontHighlightLarge") | 
| yellowfive@11 | 94 	tab.sendMessage3:SetText(L.AMR_SHOPPINGLISTTAB_SEND_LIST_TO) | 
| adam@0 | 95 	tab.sendMessage3:SetPoint("TOPLEFT", tab.sendMessage4, "TOPLEFT", 0, 25) | 
| adam@0 | 96 | 
| adam@0 | 97 | 
| adam@0 | 98 	tab.sendMessage2 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormal") | 
| adam@0 | 99 	tab.sendMessage2:SetTextColor(.5,.5,.5) | 
| yellowfive@11 | 100 	tab.sendMessage2:SetText(L.AMR_SHOPPINGLISTTAB_WHISPER_CHANNEL) | 
| adam@0 | 101 	tab.sendMessage2:SetPoint("TOPLEFT", tab.sendMessage3, "TOPLEFT", 0, 25) | 
| adam@0 | 102 | 
| adam@0 | 103 | 
| adam@0 | 104 	tab.sendMessage1 = AskMrRobot.FontString:new(tab.shoppingPanel, nil, "ARTWORK", "GameFontNormalLarge") | 
| adam@0 | 105 	tab.sendMessage1:SetTextColor(0,1,0) | 
| yellowfive@11 | 106 	tab.sendMessage1:SetText(L.AMR_SHOPPINGLISTTAB_SEND_JEWELCRAFT_ENCHANTER) | 
| adam@0 | 107 	tab.sendMessage1:SetPoint("TOPLEFT", tab.sendMessage2, "TOPLEFT", 0, 25) | 
| adam@0 | 108 | 
| adam@0 | 109 | 
| adam@0 | 110 	tab.scrollFrame = CreateFrame("ScrollFrame", "AmrScrollFrame", tab.shoppingPanel, "UIPanelScrollFrameTemplate") | 
| adam@0 | 111 	tab.scrollFrame:SetPoint("TOPLEFT", 0, 0) | 
| adam@0 | 112 	tab.scrollFrame:SetPoint("RIGHT", -20, 0) | 
| adam@0 | 113 	tab.scrollFrame:SetPoint("BOTTOM", tab.sendMessage1, "TOP", 0, 10) | 
| adam@0 | 114 | 
| adam@0 | 115 	tab.scrollParent = AskMrRobot.Frame:new(nil, tab.shoppingPanel) | 
| adam@0 | 116 	tab.scrollParent:SetPoint("TOPLEFT", 0, 0) | 
| adam@0 | 117 	tab.scrollParent:SetWidth(tab:GetWidth() - 20) | 
| adam@0 | 118 	tab.scrollParent:SetHeight(500) | 
| adam@0 | 119 	tab.scrollFrame:SetScrollChild(tab.scrollParent) | 
| adam@0 | 120 | 
| adam@0 | 121 	-- magic to get the scrollbar to work with the scrollwheel... | 
| adam@0 | 122 	tab.scrollFrame:SetScript("OnMouseWheel", function(arg1, arg2) | 
| adam@0 | 123 	 	ScrollFrameTemplate_OnMouseWheel(arg1, arg2, arg1.ScrollBar) | 
| adam@0 | 124 	end) | 
| adam@0 | 125 | 
| adam@0 | 126 	tab.gemsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 127 	tab.gemsHeader:SetText(L.AMR_SHOPPINGLISTTAB_GEMS) | 
| adam@0 | 128 	tab.gemsHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 0, 0) | 
| adam@0 | 129 | 
| adam@0 | 130 	tab.gemsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 131 	tab.gemsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_TOTAL) | 
| adam@0 | 132 	tab.gemsQuantityHeader:SetPoint("TOPLEFT", tab.scrollParent, "TOPLEFT", 370, 0) | 
| adam@0 | 133 | 
| adam@0 | 134 	tab.enchantsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 135 	tab.enchantsHeader:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANTS) | 
| adam@0 | 136 | 
| adam@0 | 137 	tab.enchantsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 138 	tab.enchantsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_TOTAL) | 
| adam@0 | 139 	tab.enchantsQuantityHeader:SetPoint("TOPLEFT", tab.enchantsHeader, "TOPLEFT", 370, 0) | 
| adam@0 | 140 | 
| adam@0 | 141 	tab.enchantMaterialsHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 142 	tab.enchantMaterialsHeader:SetText(L.AMR_SHOPPINGLISTTAB_ENCHANT_MATERIALS) | 
| adam@0 | 143 | 
| adam@0 | 144 	tab.enchantMaterialsQuantityHeader = AskMrRobot.FontString:new(tab.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| yellowfive@11 | 145 	tab.enchantMaterialsQuantityHeader:SetText(L.AMR_SHOPPINGLISTTAB_TOTAL) | 
| adam@0 | 146 	tab.enchantMaterialsQuantityHeader:SetPoint("TOPLEFT", tab.enchantMaterialsHeader, "TOPLEFT", 370, 0) | 
| adam@0 | 147 | 
| adam@0 | 148 	tab.stamp = AskMrRobot.RobotStamp:new(nil, tab) | 
| adam@0 | 149 	tab.stamp:Hide() | 
| yellowfive@11 | 150 	tab.stamp.bigText:SetText(L.AMR_SHOPPINGLISTTAB_DONE) | 
| yellowfive@11 | 151 	tab.stamp.smallText:SetText(L.AMR_SHOPPINGLISTTAB_A_ROBOTS_WISHLIST) | 
| adam@0 | 152 	tab.stamp:SetPoint("TOPLEFT", tab.shoppingListHeader, "BOTTOMLEFT", 2, -15) | 
| adam@0 | 153 	tab.stamp:SetPoint("RIGHT", tab, "RIGHT", -30, 0) | 
| adam@0 | 154 	tab.stamp:SetHeight(92) | 
| adam@0 | 155 | 
| adam@0 | 156 	tab.gemIcons = {} | 
| adam@0 | 157 	tab.gemLinks = {} | 
| adam@0 | 158 	tab.gemQuantity = {} | 
| adam@0 | 159 	tab.enchantIcons = {} | 
| adam@0 | 160 	tab.enchantLinks = {} | 
| adam@0 | 161 	tab.enchantQuantity = {} | 
| adam@0 | 162 	tab.enchantMaterialIcons = {} | 
| adam@0 | 163 	tab.enchantMaterialLinks = {} | 
| adam@0 | 164 	tab.enchantMaterialQuantity = {} | 
| adam@0 | 165 | 
| adam@0 | 166 	-- Create the dropdown, and configure its appearance | 
| adam@0 | 167 	tab.dropDown = CreateFrame("FRAME", "AmrSendType", tab.shoppingPanel, "UIDropDownMenuTemplate") | 
| adam@0 | 168 	tab.dropDown:SetPoint("TOPLEFT", tab.sendMessage3, "TOPRIGHT", 0, 5) | 
| adam@0 | 169 	UIDropDownMenu_SetWidth(tab.dropDown, 140) | 
| adam@17 | 170 	UIDropDownMenu_SetText(tab.dropDown, AmrDb.SendSettings.SendToType) | 
| adam@0 | 171 | 
| adam@0 | 172 	local text = getglobal(tab.dropDown:GetName() .. 'Text') | 
| adam@0 | 173 	text:SetFontObject("GameFontHighlightLarge") | 
| adam@0 | 174 | 
| adam@0 | 175 	local AddButton = function(list, optionText) | 
| adam@0 | 176 		local info = UIDropDownMenu_CreateInfo() | 
| adam@0 | 177 		info.justifyH = "RIGHT" | 
| adam@0 | 178 		info.text = optionText | 
| adam@17 | 179 		info.checked = AmrDb.SendSettings.SendToType == optionText | 
| adam@0 | 180 		info.arg1 = optionText | 
| adam@0 | 181 		info.func = list.SetValue | 
| adam@0 | 182 		info.owner = list | 
| adam@0 | 183 		info.fontObject = "GameFontHighlightLarge" | 
| adam@0 | 184 		info.minWidth = 140 | 
| adam@0 | 185 		return info | 
| adam@0 | 186 	end | 
| adam@0 | 187 | 
| adam@0 | 188 	-- Create and bind the initialization function to the dropdown menu | 
| adam@0 | 189 	UIDropDownMenu_Initialize(tab.dropDown, function(self, level, menuList) | 
| yellowfive@11 | 190 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_FRIEND)) | 
| yellowfive@11 | 191 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_PARTY)) | 
| yellowfive@11 | 192 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_RAID)) | 
| yellowfive@11 | 193 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_GUILD)) | 
| yellowfive@11 | 194 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_CHANNEL)) | 
| yellowfive@11 | 195 	 UIDropDownMenu_AddButton(AddButton(self, L.AMR_SHOPPINGLISTTAB_DROPDOWN_MAIL)) | 
| adam@0 | 196 	end) | 
| adam@0 | 197 | 
| adam@0 | 198 	function tab.dropDown:SetValue(newValue) | 
| adam@17 | 199 		AmrDb.SendSettings.SendToType = newValue | 
| adam@0 | 200 		-- Update the text; if we merely wanted it to display newValue, we would not need to do this | 
| adam@17 | 201 		UIDropDownMenu_SetText(tab.dropDown, AmrDb.SendSettings.SendToType) | 
| adam@0 | 202 		-- Because this is called from a sub-menu, only that menu level is closed by default. | 
| adam@0 | 203 		-- Close the entire menu with this next call | 
| adam@0 | 204 		CloseDropDownMenus() | 
| adam@0 | 205 	end | 
| adam@0 | 206 | 
| adam@0 | 207 	tab.sendTo = CreateFrame("EditBox", "AmrSendTo", tab.shoppingPanel, "InputBoxTemplate" ) | 
| adam@0 | 208 	tab.sendTo:SetPoint("TOPLEFT", tab.dropDown, "TOPRIGHT", 0, 0) | 
| adam@0 | 209 	tab.sendTo:SetPoint("RIGHT", 0, 0) | 
| adam@0 | 210 	tab.sendTo:SetHeight(30) | 
| adam@17 | 211 	tab.sendTo:SetText(AmrDb.SendSettings.SendTo or "") | 
| adam@0 | 212 	tab.sendTo:SetFontObject("GameFontHighlightLarge") | 
| adam@0 | 213 	tab.sendTo:SetAutoFocus(false) | 
| adam@0 | 214 	tab.sendTo:SetScript("OnChar", function() | 
| adam@17 | 215 		AmrDb.SendSettings.SendTo = tab.sendTo:GetText() | 
| adam@0 | 216 	end) | 
| adam@0 | 217 | 
| adam@0 | 218 	tab.messageQueue = {} | 
| adam@0 | 219 	return tab | 
| adam@0 | 220 end | 
| adam@0 | 221 | 
| adam@0 | 222 -- display a gem icon in a row | 
| adam@0 | 223 -- gemInfo is {id, enchantId, color, count } | 
| adam@0 | 224 function AskMrRobot.ShoppingListTab:SetGemIcon(row, gemInfo) | 
| adam@0 | 225 	-- get gem icon for the row | 
| adam@0 | 226 	local gemIcon = self.gemIcons[row] | 
| adam@0 | 227 | 
| adam@0 | 228 	-- if we don't have one | 
| adam@0 | 229 	if gemIcon == nil then | 
| adam@0 | 230 		-- make one | 
| adam@0 | 231 		gemIcon = AskMrRobot.GemIcon:new(nil, self.scrollParent) | 
| adam@0 | 232 		self.gemIcons[row] = gemIcon | 
| adam@0 | 233 		gemIcon:SetScript("OnMouseDown", function() | 
| adam@0 | 234 			self:SearchForGem(row) | 
| adam@0 | 235 		end) | 
| adam@0 | 236 | 
| adam@0 | 237 		-- position it | 
| adam@0 | 238 		local previous = self.gemsHeader | 
| adam@0 | 239 		if row > 1 then | 
| adam@0 | 240 			previous = self.gemIcons[row - 1] | 
| adam@0 | 241 		end | 
| adam@0 | 242 		gemIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7) | 
| adam@0 | 243 | 
| adam@0 | 244 		-- size it | 
| adam@0 | 245 		gemIcon:SetWidth(24) | 
| adam@0 | 246 		gemIcon:SetHeight(24) | 
| adam@0 | 247 | 
| adam@0 | 248 		-- give it a nice border | 
| adam@0 | 249 		gemIcon:SetRoundBorder() | 
| adam@0 | 250 	end | 
| adam@0 | 251 | 
| adam@0 | 252 	gemIcon:Show() | 
| adam@0 | 253 | 
| adam@0 | 254 	-- make a link for the optimized gem | 
| adam@0 | 255 	gemLink = select(2, GetItemInfo(gemInfo.id)) | 
| adam@0 | 256 | 
| adam@0 | 257 	-- set the link (tooltip + icon) | 
| adam@0 | 258 	gemIcon:SetItemLink(gemLink) | 
| adam@17 | 259 	--gemIcon:SetGemColor(gemInfo.color) | 
| adam@17 | 260 	gemIcon:SetGemColor('Prismatic') | 
| adam@0 | 261 | 
| adam@0 | 262 	-- if we didn't get one, its because WoW is slow | 
| adam@0 | 263 	if not gemLink and gemInfo.id then | 
| adam@0 | 264 		-- when WoW finally returns the link, set the icon / tooltip | 
| adam@0 | 265 		AskMrRobot.RegisterItemInfoCallback(gemInfo.id, function(name, link) | 
| adam@0 | 266 			gemIcon:SetItemLink(link) | 
| adam@0 | 267 		end) | 
| adam@0 | 268 	end | 
| adam@0 | 269 | 
| adam@0 | 270 end | 
| adam@0 | 271 | 
| adam@0 | 272 | 
| adam@0 | 273 -- display a gem icon in a row | 
| adam@0 | 274 -- gemInfo is {id, enchantId, color, count } | 
| adam@0 | 275 function AskMrRobot.ShoppingListTab:SetGemText(row, gemInfo) | 
| adam@0 | 276 	-- get gem icon for the row | 
| adam@0 | 277 	local gemText = self.gemLinks[row] | 
| adam@0 | 278 | 
| adam@0 | 279 	-- if we don't have one | 
| adam@0 | 280 	if gemText == nil then | 
| adam@0 | 281 		-- make one | 
| adam@0 | 282 		gemText = AskMrRobot.ItemLinkText:new(nil, self.scrollParent) | 
| adam@0 | 283 		self.gemLinks[row] = gemText | 
| adam@0 | 284 		gemText:SetScript("OnMouseDown", function() | 
| adam@0 | 285 			self:SearchForGem(row) | 
| adam@0 | 286 		end) | 
| adam@0 | 287 | 
| adam@0 | 288 		-- position it | 
| adam@0 | 289 		local previous = self.gemsHeader | 
| adam@0 | 290 		if row > 1 then | 
| adam@0 | 291 			previous = self.gemIcons[row - 1] | 
| adam@0 | 292 		end | 
| adam@0 | 293 		gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8) | 
| adam@0 | 294 		gemText:SetPoint("RIGHT", self, "RIGHT", -70, 0) | 
| adam@0 | 295 		gemText:SetHeight(18) | 
| adam@0 | 296 		gemText:SetFontSize(15) | 
| adam@0 | 297 	end | 
| adam@0 | 298 | 
| adam@0 | 299 	gemText:Show() | 
| adam@0 | 300 | 
| adam@0 | 301 	gemText:SetItemId(gemInfo.id) | 
| adam@0 | 302 end | 
| adam@0 | 303 | 
| adam@0 | 304 -- display a gem icon in a row | 
| adam@0 | 305 -- gemInfo is {id, enchantId, color, count } | 
| adam@0 | 306 function AskMrRobot.ShoppingListTab:SetGemQuantity(row, qty, total) | 
| adam@0 | 307 	if qty > total then qty = total end | 
| adam@0 | 308 | 
| adam@0 | 309 	-- get gem icon for the row | 
| adam@0 | 310 	local gemText = self.gemQuantity[row] | 
| adam@0 | 311 | 
| adam@0 | 312 	-- if we don't have one | 
| adam@0 | 313 	if gemText == nil then | 
| adam@0 | 314 		-- make one | 
| adam@0 | 315 		gemText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| adam@0 | 316 		self.gemQuantity[row] = gemText | 
| adam@0 | 317 | 
| adam@0 | 318 		-- position it | 
| adam@0 | 319 		local previous = self.gemsHeader | 
| adam@0 | 320 		if row > 1 then | 
| adam@0 | 321 			previous = self.gemIcons[row - 1] | 
| adam@0 | 322 		end | 
| adam@0 | 323 		gemText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) | 
| adam@0 | 324 		gemText:SetHeight(18) | 
| adam@0 | 325 		gemText:SetFontSize(15) | 
| adam@0 | 326 	end | 
| adam@0 | 327 | 
| adam@0 | 328 	gemText:SetText('' .. qty .. '/' .. total) | 
| adam@0 | 329 	if qty == total then | 
| adam@0 | 330 		gemText:SetTextColor(0,1,0) | 
| adam@0 | 331 	else | 
| adam@0 | 332 		gemText:SetTextColor(1,0,0) | 
| adam@0 | 333 	end | 
| adam@0 | 334 	gemText:Show() | 
| adam@0 | 335 end | 
| adam@0 | 336 | 
| adam@0 | 337 | 
| adam@0 | 338 -- display an enchant icon in a row | 
| adam@0 | 339 function AskMrRobot.ShoppingListTab:SetEnchantIcon(row, enchantId) | 
| adam@0 | 340 | 
| adam@0 | 341 	-- get enchant icon for the row | 
| adam@0 | 342 	local enchantIcon = self.enchantIcons[row] | 
| adam@0 | 343 | 
| adam@0 | 344 	-- if we don't have one | 
| adam@0 | 345 	if enchantIcon == nil then | 
| adam@0 | 346 		-- make one | 
| adam@0 | 347 		enchantIcon = AskMrRobot.EnchantLinkIconAndText:new(nil, self.scrollParent) | 
| adam@0 | 348 		self.enchantIcons[row] = enchantIcon | 
| adam@0 | 349 		enchantIcon:SetScript("OnMouseDown", function() | 
| adam@0 | 350 			self:SearchForEnchant(row) | 
| adam@0 | 351 		end) | 
| adam@0 | 352 | 
| adam@0 | 353 		-- position it | 
| adam@0 | 354 		if row == 1 then | 
| adam@0 | 355 			enchantIcon:SetPoint("TOPLEFT", self.enchantsHeader, "BOTTOMLEFT", 0, -12) | 
| adam@0 | 356 			enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0) | 
| adam@0 | 357 		else | 
| adam@0 | 358 			enchantIcon:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -7) | 
| adam@0 | 359 			enchantIcon:SetPoint("RIGHT", self.scrollParent, "RIGHT", -30, 0) | 
| adam@0 | 360 		end | 
| adam@0 | 361 | 
| adam@0 | 362 		-- size it | 
| adam@0 | 363 		enchantIcon:SetWidth(24) | 
| adam@0 | 364 		enchantIcon:SetHeight(24) | 
| adam@0 | 365 		enchantIcon:SetFontSize(15) | 
| adam@0 | 366 | 
| adam@0 | 367 		-- give it a nice border | 
| adam@0 | 368 		enchantIcon:SetRoundBorder() | 
| adam@0 | 369 | 
| adam@0 | 370 		enchantIcon:UseSpellName() | 
| adam@0 | 371 	end | 
| adam@0 | 372 | 
| adam@0 | 373 	enchantIcon:SetEnchantId(enchantId) | 
| adam@0 | 374 | 
| adam@0 | 375 	enchantIcon:Show() | 
| adam@0 | 376 end | 
| adam@0 | 377 | 
| adam@0 | 378 -- display a gem icon in a row | 
| adam@0 | 379 -- gemInfo is {id, enchantId, color, count } | 
| adam@0 | 380 function AskMrRobot.ShoppingListTab:SetEnchantQuantity(row, qty, total) | 
| adam@0 | 381 	if qty > total then qty = total end | 
| adam@0 | 382 | 
| adam@0 | 383 	-- get gem icon for the row | 
| adam@0 | 384 	local enchantText = self.enchantQuantity[row] | 
| adam@0 | 385 | 
| adam@0 | 386 	-- if we don't have one | 
| adam@0 | 387 	if enchantText == nil then | 
| adam@0 | 388 		-- make one | 
| adam@0 | 389 		enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| adam@0 | 390 		self.enchantQuantity[row] = enchantText | 
| adam@0 | 391 | 
| adam@0 | 392 		-- position it | 
| adam@0 | 393 		local previous = self.enchantsHeader | 
| adam@0 | 394 		if row > 1 then | 
| adam@0 | 395 			previous = self.enchantIcons[row - 1] | 
| adam@0 | 396 		end | 
| adam@0 | 397 		enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) | 
| adam@0 | 398 		enchantText:SetHeight(18) | 
| adam@0 | 399 		enchantText:SetFontSize(15) | 
| adam@0 | 400 	end | 
| adam@0 | 401 | 
| adam@0 | 402 	enchantText:SetText('' .. qty .. '/' .. total) | 
| adam@0 | 403 	if qty == total then | 
| adam@0 | 404 		enchantText:SetTextColor(0,1,0) | 
| adam@0 | 405 	else | 
| adam@0 | 406 		enchantText:SetTextColor(1,0,0) | 
| adam@0 | 407 	end | 
| adam@0 | 408 	enchantText:Show() | 
| adam@0 | 409 end | 
| adam@0 | 410 | 
| adam@0 | 411 function AskMrRobot.ShoppingListTab:SearchForItem(itemName) | 
| adam@0 | 412 	if self.isAuctionHouseVisible then | 
| adam@0 | 413 		QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0, 0) | 
| adam@0 | 414 	end | 
| adam@0 | 415 end | 
| adam@0 | 416 | 
| adam@0 | 417 function AskMrRobot.ShoppingListTab:SearchForGem(row) | 
| adam@0 | 418 	self:SearchForItem(self.gemLinks[row].itemName) | 
| adam@0 | 419 end | 
| adam@0 | 420 | 
| adam@0 | 421 function AskMrRobot.ShoppingListTab:SearchForEnchant(row) | 
| adam@0 | 422 	self:SearchForItem(self.enchantIcons[row].itemName) | 
| adam@0 | 423 end | 
| adam@0 | 424 | 
| adam@0 | 425 function AskMrRobot.ShoppingListTab:SearchForEnchantMaterial(row) | 
| adam@0 | 426 	self:SearchForItem(self.enchantMaterialLinks[row].itemName) | 
| adam@0 | 427 end | 
| adam@0 | 428 | 
| adam@0 | 429 | 
| adam@0 | 430 -- display an enchant material icon in a row | 
| adam@0 | 431 function AskMrRobot.ShoppingListTab:SetEnchantMaterialIcon(row, itemId) | 
| adam@0 | 432 	-- get enchant material icon for the row | 
| adam@0 | 433 	local materialIcon = self.enchantMaterialIcons[row] | 
| adam@0 | 434 | 
| adam@0 | 435 	-- if we don't have one | 
| adam@0 | 436 	if materialIcon == nil then | 
| adam@0 | 437 		-- make one | 
| adam@0 | 438 		materialIcon = AskMrRobot.ItemIcon:new(nil, self.scrollParent) | 
| adam@0 | 439 		self.enchantMaterialIcons[row] = materialIcon | 
| adam@0 | 440 		materialIcon:SetScript("OnMouseDown", function() | 
| adam@0 | 441 			self:SearchForEnchantMaterial(row) | 
| adam@0 | 442 		end) | 
| adam@0 | 443 | 
| adam@0 | 444 		-- position it | 
| adam@0 | 445 		local previous = self.enchantMaterialsHeader | 
| adam@0 | 446 		if row > 1 then | 
| adam@0 | 447 			previous = self.enchantMaterialIcons[row - 1] | 
| adam@0 | 448 		end | 
| adam@0 | 449 		materialIcon:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 0, -7) | 
| adam@0 | 450 | 
| adam@0 | 451 		-- size it | 
| adam@0 | 452 		materialIcon:SetWidth(24) | 
| adam@0 | 453 		materialIcon:SetHeight(24) | 
| adam@0 | 454 | 
| adam@0 | 455 		-- give it a nice border | 
| adam@0 | 456 		materialIcon:SetRoundBorder() | 
| adam@0 | 457 	end | 
| adam@0 | 458 | 
| adam@0 | 459 	materialIcon:Show() | 
| adam@0 | 460 | 
| adam@0 | 461 	-- make a link for the optimized gem | 
| adam@0 | 462 	local itemLink = select(2, GetItemInfo(itemId)) | 
| adam@0 | 463 | 
| adam@0 | 464 	materialIcon:SetItemLink(itemLink) | 
| adam@0 | 465 | 
| adam@0 | 466 	-- if we didn't get one, its because WoW is slow | 
| adam@0 | 467 	if not itemLink and itemId then | 
| adam@0 | 468 		-- when WoW finally returns the link, set the icon / tooltip | 
| adam@0 | 469 		AskMrRobot.RegisterItemInfoCallback(itemId, function(name, link) | 
| adam@0 | 470 			materialIcon:SetItemLink(link) | 
| adam@0 | 471 		end) | 
| adam@0 | 472 	end | 
| adam@0 | 473 end | 
| adam@0 | 474 | 
| adam@0 | 475 | 
| adam@0 | 476 -- display an enchant material link in a row | 
| adam@0 | 477 function AskMrRobot.ShoppingListTab:SetEnchantMaterialLink(row, itemId) | 
| adam@0 | 478 	-- get gem icon for the row | 
| adam@0 | 479 	local materialLink = self.enchantMaterialLinks[row] | 
| adam@0 | 480 | 
| adam@0 | 481 	-- if we don't have one | 
| adam@0 | 482 	if materialLink == nil then | 
| adam@0 | 483 		-- make one | 
| adam@0 | 484 		materialLink = AskMrRobot.ItemLinkText:new(nil, self.scrollParent) | 
| adam@0 | 485 		self.enchantMaterialLinks[row] = materialLink | 
| adam@0 | 486 		materialLink:SetScript("OnMouseDown", function() | 
| adam@0 | 487 			self:SearchForEnchantMaterial(row) | 
| adam@0 | 488 		end) | 
| adam@0 | 489 | 
| adam@0 | 490 		-- position it | 
| adam@0 | 491 		local previous = self.enchantMaterialsHeader | 
| adam@0 | 492 		if row > 1 then | 
| adam@0 | 493 			previous = self.enchantMaterialIcons[row - 1] | 
| adam@0 | 494 		end | 
| adam@0 | 495 		materialLink:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 30, -8) | 
| adam@0 | 496 		materialLink:SetPoint("RIGHT", self, "RIGHT", -30, 0) | 
| adam@0 | 497 		materialLink:SetHeight(18) | 
| adam@0 | 498 		materialLink:SetFontSize(15) | 
| adam@0 | 499 	end | 
| adam@0 | 500 | 
| adam@0 | 501 	materialLink:Show() | 
| adam@0 | 502 | 
| adam@0 | 503 	materialLink:SetItemId(itemId) | 
| adam@0 | 504 	materialLink.itemId = itemId | 
| adam@0 | 505 end | 
| adam@0 | 506 | 
| adam@0 | 507 -- display a gem icon in a row | 
| adam@0 | 508 -- gemInfo is {id, enchantId, color, count } | 
| adam@0 | 509 function AskMrRobot.ShoppingListTab:SetEnchantMaterialQuantity(row, qty, total) | 
| adam@0 | 510 	if qty > total then qty = total end | 
| adam@0 | 511 | 
| adam@0 | 512 	-- get gem icon for the row | 
| adam@0 | 513 	local enchantText = self.enchantMaterialQuantity[row] | 
| adam@0 | 514 | 
| adam@0 | 515 	-- if we don't have one | 
| adam@0 | 516 	if enchantText == nil then | 
| adam@0 | 517 		-- make one | 
| adam@0 | 518 		enchantText = AskMrRobot.FontString:new(self.scrollParent, nil, "ARTWORK", "GameFontNormalLarge") | 
| adam@0 | 519 		self.enchantMaterialQuantity[row] = enchantText | 
| adam@0 | 520 | 
| adam@0 | 521 		-- position it | 
| adam@0 | 522 		local previous = self.enchantMaterialsHeader | 
| adam@0 | 523 		if row > 1 then | 
| adam@0 | 524 			previous = self.enchantMaterialIcons[row - 1] | 
| adam@0 | 525 		end | 
| adam@0 | 526 		enchantText:SetPoint("TOPLEFT", previous, "BOTTOMLEFT", 370, -8) | 
| adam@0 | 527 		enchantText:SetHeight(18) | 
| adam@0 | 528 		enchantText:SetFontSize(15) | 
| adam@0 | 529 	end | 
| adam@0 | 530 | 
| adam@0 | 531 	enchantText:SetText('' .. qty .. '/' .. total) | 
| adam@0 | 532 	if qty == total then | 
| adam@0 | 533 		enchantText:SetTextColor(0,1,0) | 
| adam@0 | 534 	else | 
| adam@0 | 535 		enchantText:SetTextColor(1,0,0) | 
| adam@0 | 536 	end | 
| adam@0 | 537 	enchantText:Show() | 
| adam@0 | 538 end | 
| adam@0 | 539 | 
| adam@0 | 540 function AskMrRobot.ShoppingListTab:HasStuffToBuy() | 
| adam@0 | 541 | 
| adam@0 | 542 	local gemList, enchantList, enchantMaterials = self:CalculateItems() | 
| adam@0 | 543 | 
| adam@0 | 544 	local count = 0 | 
| adam@0 | 545 	for gemId, gemInfo in AskMrRobot.spairs(gemList) do | 
| adam@0 | 546 		count = count + gemInfo.total - gemInfo.count | 
| adam@0 | 547 	end | 
| adam@0 | 548 	for slot, enchant in AskMrRobot.spairs(enchantList) do | 
| adam@0 | 549 		count = count + enchant.total - enchant.count | 
| adam@0 | 550 	end | 
| adam@0 | 551 | 
| adam@0 | 552 	return count > 0 | 
| adam@0 | 553 end | 
| adam@0 | 554 | 
| adam@0 | 555 function AskMrRobot.ShoppingListTab:CalculateItems() | 
| adam@17 | 556 	-- build a map of missing gem-enchant-ids -> {id, enchantid, count, total} | 
| adam@0 | 557 	local gemList = {} | 
| adam@17 | 558 | 
| adam@17 | 559 	-- for each piece of gear that needs at least 1 gem changed | 
| adam@17 | 560 	for _, badGems in pairs(AskMrRobot.ComparisonResult.gems) do | 
| adam@17 | 561 		-- for each specified gem | 
| adam@17 | 562 		for g = 1, #badGems.optimized do | 
| adam@17 | 563 			local goodGemEnchantId = badGems.optimized[g] | 
| adam@17 | 564 			-- if AMR says to optimized this gem AND it does *NOT* match matches the current gem | 
| adam@17 | 565 			if goodGemEnchantId ~= 0 and not AskMrRobot.AreGemsCompatible(goodGemEnchantId, badGems.current[g]) then | 
| adam@17 | 566 				-- see if this gem is in our list of gems to optimize | 
| adam@17 | 567 				local gem = gemList[goodGemEnchantId] | 
| adam@17 | 568 				if gem == nil then | 
| adam@17 | 569 					-- if not, add it | 
| adam@17 | 570 					gemList[goodGemEnchantId] = {id = AskMrRobot.ExtraGemData[goodGemEnchantId].id, enchantId = goodGemEnchantId, count = 0, total = 1, compatibleGemIds = AskMrRobot.ExtraGemData[goodGemEnchantId].identicalItemGroup} | 
| adam@17 | 571 				else | 
| adam@17 | 572 					-- if so, increase the total requested for this | 
| adam@17 | 573 					gem.total = gem.total + 1 | 
| adam@0 | 574 				end | 
| adam@0 | 575 			end | 
| adam@0 | 576 		end | 
| adam@0 | 577 	end | 
| adam@0 | 578 | 
| adam@0 | 579 	local enchantList = {} | 
| adam@17 | 580 	for slot, enchantData in AskMrRobot.sortSlots(AskMrRobot.ComparisonResult.enchants) do | 
| adam@17 | 581 		local extraData = AskMrRobot.ExtraEnchantData[enchantData.optimized] | 
| adam@17 | 582 		local id = extraData and extraData.itemId or enchantData.optimized | 
| adam@0 | 583 		local qty = enchantList[id] | 
| adam@0 | 584 		if qty then | 
| adam@0 | 585 			qty.total = qty.total + 1 | 
| adam@0 | 586 		else | 
| adam@0 | 587 			qty = { count = 0, total = 1, optimized = enchantData.optimized } | 
| adam@0 | 588 			enchantList[id] = qty | 
| adam@0 | 589 		end | 
| adam@0 | 590 	end | 
| adam@0 | 591 | 
| adam@0 | 592 	local enchantMaterials = {} | 
| adam@17 | 593 	for slot, enchantData in pairs(AskMrRobot.ComparisonResult.enchants) do | 
| adam@17 | 594 		local extraData = AskMrRobot.ExtraEnchantData[enchantData.optimized] | 
| adam@17 | 595 		if extraData and extraData.materials then | 
| adam@17 | 596 			local itemId | 
| adam@17 | 597 			local count | 
| adam@17 | 598 			for itemId, count in pairs(extraData.materials) do | 
| adam@17 | 599 				if enchantMaterials[itemId] then | 
| adam@17 | 600 					enchantMaterials[itemId].total = enchantMaterials[itemId].total + count | 
| adam@17 | 601 				else | 
| adam@17 | 602 					enchantMaterials[itemId] = { count = 0, total = count } | 
| adam@17 | 603 				end | 
| adam@17 | 604 			end | 
| adam@17 | 605 		end | 
| adam@17 | 606 | 
| adam@0 | 607 	end | 
| adam@0 | 608 | 
| adam@17 | 609 	local bagItemsWithCounts = {} | 
| adam@17 | 610 	-- copy the bank items into a new table so we don't alter them | 
| adam@17 | 611 	if (AmrDb.BankItemsAndCounts) then | 
| adam@17 | 612 		for id, count in pairs(AmrDb.BankItemsAndCounts) do | 
| adam@17 | 613 			bagItemsWithCounts[id] = count | 
| adam@0 | 614 		end | 
| adam@0 | 615 	end | 
| adam@0 | 616 | 
| adam@17 | 617 	-- add the items from the players bags | 
| adam@17 | 618 	AskMrRobot.ScanBags(bagItemsWithCounts) | 
| adam@0 | 619 | 
| adam@17 | 620 	--substract any inventory we already have in bags/bank | 
| adam@17 | 621 	for itemId, count in pairs(bagItemsWithCounts) do | 
| adam@17 | 622 		for _, gem in pairs(gemList) do | 
| adam@17 | 623 			if gem.compatibleGemIds[itemId] and gem.count < gem.total then | 
| adam@17 | 624 				local needed = gem.total - gem.count | 
| adam@17 | 625 				if count > needed then | 
| adam@17 | 626 					gem.count = gem.total | 
| adam@17 | 627 					-- only consume the number needed (subtract in case this is compatible with a different gem) | 
| adam@17 | 628 					count = count - needed | 
| adam@17 | 629 				else | 
| adam@17 | 630 					gem.count = gem.count + count | 
| adam@17 | 631 					count = 0 | 
| adam@0 | 632 				end | 
| adam@0 | 633 			end | 
| adam@17 | 634 		end | 
| adam@17 | 635 		local material = enchantMaterials[itemId] | 
| adam@17 | 636 		if material then | 
| adam@17 | 637 			material.count = material.count + count | 
| adam@17 | 638 		end | 
| adam@17 | 639 		local enchant = enchantList[itemId] | 
| adam@17 | 640 		if enchant then | 
| adam@17 | 641 			enchant.count = enchant.count + count | 
| adam@0 | 642 		end | 
| adam@0 | 643 	end | 
| adam@0 | 644 | 
| adam@0 | 645 	return gemList, enchantList, enchantMaterials | 
| adam@0 | 646 end | 
| adam@0 | 647 | 
| adam@0 | 648 function AskMrRobot.ShoppingListTab:Update() | 
| adam@0 | 649 | 
| adam@0 | 650 	local gemList, enchantList, enchantMaterials = self:CalculateItems() | 
| adam@0 | 651 | 
| adam@0 | 652 	-- update the UI | 
| adam@0 | 653 	local lastControl = nil | 
| adam@0 | 654 	local row = 1 | 
| adam@0 | 655 	for gemId, gemInfo in AskMrRobot.spairs(gemList) do | 
| adam@0 | 656 		self:SetGemIcon(row, gemInfo) | 
| adam@0 | 657 		self:SetGemText(row, gemInfo) | 
| adam@0 | 658 		self:SetGemQuantity(row, gemInfo.count, gemInfo.total) | 
| adam@0 | 659 		lastControl = self.gemIcons[row] | 
| adam@0 | 660 		row = row + 1 | 
| adam@0 | 661 	end | 
| adam@0 | 662 | 
| adam@0 | 663 	-- hide any extra gem icons | 
| adam@0 | 664 	for i = row, #self.gemIcons do | 
| adam@0 | 665 		self.gemIcons[i]:Hide() | 
| adam@0 | 666 		self.gemLinks[i]:Hide() | 
| adam@0 | 667 		self.gemQuantity[i]:Hide() | 
| adam@0 | 668 	end | 
| adam@0 | 669 | 
| adam@0 | 670 	-- hide / show the gems header, and position the enchant headers | 
| adam@0 | 671 	if row > 1 then | 
| adam@0 | 672 		self.gemsHeader:Show() | 
| adam@0 | 673 		self.gemsQuantityHeader:Show() | 
| adam@0 | 674 		self.enchantsHeader:SetPoint("TOPLEFT", self.gemIcons[row - 1], "BOTTOMLEFT", 0, -15) | 
| adam@0 | 675 	else | 
| adam@0 | 676 		self.gemsHeader:Hide() | 
| adam@0 | 677 		self.gemsQuantityHeader:Hide() | 
| adam@0 | 678 		self.enchantsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0) | 
| adam@0 | 679 	end | 
| adam@0 | 680 | 
| adam@0 | 681 	row = 1 | 
| adam@0 | 682 	for slot, enchant in AskMrRobot.spairs(enchantList) do | 
| adam@0 | 683 		self:SetEnchantIcon(row, enchant.optimized) | 
| adam@0 | 684 		self:SetEnchantQuantity(row, enchant.count, enchant.total) | 
| adam@0 | 685 		lastControl = self.enchantIcons[row] | 
| adam@0 | 686 		row = row + 1 | 
| adam@0 | 687 	end | 
| adam@0 | 688 | 
| adam@0 | 689 	-- hide any extra enchant icons | 
| adam@0 | 690 	for i = row, #self.enchantIcons do | 
| adam@0 | 691 		self.enchantIcons[i]:Hide() | 
| adam@0 | 692 		self.enchantQuantity[i]:Hide() | 
| adam@0 | 693 	end | 
| adam@0 | 694 | 
| adam@0 | 695 	-- hide / show the enchants header, and position the enchant materials headers | 
| adam@0 | 696 	if row > 1 then | 
| adam@0 | 697 		self.enchantsHeader:Show() | 
| adam@0 | 698 		self.enchantsQuantityHeader:Show() | 
| adam@0 | 699 		self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.enchantIcons[row - 1], "BOTTOMLEFT", 0, -15) | 
| adam@0 | 700 	else | 
| adam@0 | 701 		self.enchantsHeader:Hide() | 
| adam@0 | 702 		self.enchantsQuantityHeader:Hide() | 
| adam@0 | 703 		self.enchantMaterialsHeader:SetPoint("TOPLEFT", self.scrollParent, "TOPLEFT", 0, 0) | 
| adam@0 | 704 	end | 
| adam@0 | 705 | 
| adam@0 | 706 	row = 1 | 
| adam@0 | 707 	for itemId, count in AskMrRobot.spairs(enchantMaterials) do | 
| adam@0 | 708 		self:SetEnchantMaterialIcon(row, itemId) | 
| adam@0 | 709 		self:SetEnchantMaterialLink(row, itemId) | 
| adam@0 | 710 		self:SetEnchantMaterialQuantity(row, count.count, count.total) | 
| adam@0 | 711 		lastControl = self.enchantMaterialIcons[row] | 
| adam@0 | 712 		row = row + 1 | 
| adam@0 | 713 	end | 
| adam@0 | 714 | 
| adam@0 | 715 	for i = row, #self.enchantMaterialIcons do | 
| adam@0 | 716 		self.enchantMaterialIcons[i]:Hide() | 
| adam@0 | 717 		self.enchantMaterialLinks[i]:Hide() | 
| adam@0 | 718 		self.enchantMaterialQuantity[i]:Hide() | 
| adam@0 | 719 	end | 
| adam@0 | 720 | 
| adam@0 | 721 	if row == 1 then | 
| adam@0 | 722 		self.enchantMaterialsHeader:Hide() | 
| adam@0 | 723 		self.enchantMaterialsQuantityHeader:Hide() | 
| adam@0 | 724 	else | 
| adam@0 | 725 		self.enchantMaterialsHeader:Show() | 
| adam@0 | 726 		self.enchantMaterialsQuantityHeader:Show() | 
| adam@0 | 727 	end | 
| adam@0 | 728 | 
| adam@0 | 729 	-- fix up the scrollbar length | 
| adam@0 | 730 	if lastControl then | 
| adam@0 | 731 		local height = self.scrollParent:GetTop() - lastControl:GetBottom() | 
| adam@0 | 732 		self.scrollParent:SetHeight(height) | 
| adam@0 | 733 		if height < self.scrollFrame:GetHeight() then | 
| adam@0 | 734 			self.scrollFrame.ScrollBar:Hide() | 
| adam@0 | 735 		else | 
| adam@0 | 736 			self.scrollFrame:Show() | 
| adam@0 | 737 			self.scrollFrame.ScrollBar:Show() | 
| adam@0 | 738 		end | 
| adam@0 | 739 		self.stamp:Hide() | 
| adam@0 | 740 		self.shoppingPanel:Show() | 
| adam@0 | 741 	else | 
| adam@0 | 742 		self.scrollFrame.ScrollBar:Hide() | 
| adam@0 | 743 		self.shoppingPanel:Hide() | 
| adam@0 | 744 		self.stamp:Show() | 
| adam@0 | 745 	end | 
| adam@0 | 746 end | 
| adam@0 | 747 | 
| adam@0 | 748 | 
| adam@0 | 749 function AskMrRobot.ShoppingListTab:OnEvent(frame, event, ...) | 
| adam@0 | 750 	local handler = self["On_" .. event] | 
| adam@0 | 751 	if handler then | 
| adam@0 | 752 		handler(self, ...) | 
| adam@0 | 753 	end | 
| adam@0 | 754 end | 
| adam@0 | 755 | 
| adam@0 | 756 function AskMrRobot.ShoppingListTab:On_MAIL_SHOW() | 
| adam@0 | 757 	self.mailOpen = true | 
| adam@0 | 758 end | 
| adam@0 | 759 | 
| adam@0 | 760 function AskMrRobot.ShoppingListTab:On_MAIL_CLOSED() | 
| adam@0 | 761 	self.mailOpen = nil | 
| adam@0 | 762 end | 
| adam@0 | 763 | 
| adam@0 | 764 function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_SHOW() | 
| adam@0 | 765 	self.isAuctionHouseVisible = true | 
| adam@0 | 766 end | 
| adam@0 | 767 | 
| adam@0 | 768 function AskMrRobot.ShoppingListTab:On_AUCTION_HOUSE_CLOSED() | 
| adam@0 | 769 	self.isAuctionHouseVisible = false | 
| adam@0 | 770 end | 
| adam@0 | 771 | 
| adam@0 | 772 function AskMrRobot.ShoppingListTab:sendMail() | 
| adam@0 | 773 | 
| adam@0 | 774 	-- need mail window to be open for this to work | 
| adam@0 | 775 	if not self.mailOpen then | 
| adam@0 | 776 		StaticPopup_Show("SHOPPING_TAB_PLEASE_OPEN") | 
| adam@0 | 777 		return | 
| adam@0 | 778 	end | 
| adam@0 | 779 | 
| yellowfive@11 | 780 	local message = L.AMR_SHOPPINGLISTTAB_MAIL_ROBOT_MESSAGE | 
| adam@0 | 781 | 
| adam@0 | 782 	local gemList, enchantList, enchantMaterials = self:CalculateItems() | 
| adam@0 | 783 | 
| adam@17 | 784 	if AmrDb.SendSettings.SendGems then | 
| adam@0 | 785 		for k,v in pairs(gemList) do | 
| adam@0 | 786 			--exclude jewelcrafter gems | 
| adam@17 | 787 			--if not AskMrRobot.JewelcrafterGems[k] then | 
| adam@0 | 788 				local needed = v.total - v.count | 
| adam@0 | 789 				if needed > 0 then | 
| adam@17 | 790 					local itemName = GetItemInfo(v.id) | 
| adam@0 | 791 					if itemName then | 
| adam@0 | 792 						message = message .. "\n" .. needed .. "x " .. itemName | 
| adam@0 | 793 					end | 
| adam@0 | 794 				end | 
| adam@17 | 795 			--end | 
| adam@0 | 796 		end | 
| adam@0 | 797 	end | 
| adam@0 | 798 | 
| adam@17 | 799 	if AmrDb.SendSettings.SendEnchants then | 
| adam@0 | 800 		for k,v in pairs(enchantList) do | 
| adam@0 | 801 			local needed = v.total - v.count | 
| adam@0 | 802 			if needed > 0 then | 
| adam@0 | 803 				local itemName = GetItemInfo(k) | 
| adam@0 | 804 				if itemName then | 
| adam@0 | 805 					message = message .. "\n" .. needed .. "x " .. itemName | 
| adam@0 | 806 				end | 
| adam@0 | 807 			end | 
| adam@0 | 808 		end | 
| adam@0 | 809 	end | 
| adam@0 | 810 | 
| adam@17 | 811 	if AmrDb.SendSettings.SendEnchantMaterials then | 
| adam@0 | 812 		for k,v in pairs(enchantMaterials) do | 
| adam@0 | 813 			local needed = v.total - v.count | 
| adam@0 | 814 			if needed > 0 then | 
| adam@0 | 815 				local itemName = GetItemInfo(k) | 
| adam@0 | 816 				if itemName then | 
| adam@0 | 817 					message = message .. "\n" .. needed .. "x " .. itemName | 
| adam@0 | 818 				end | 
| adam@0 | 819 			end | 
| adam@0 | 820 		end | 
| adam@0 | 821 	end | 
| adam@0 | 822 | 
| adam@0 | 823 	MailFrameTab_OnClick(nil, 2) | 
| adam@17 | 824 	if AmrDb.SendSettings.SendGems then | 
| adam@17 | 825 		if AmrDb.SendSettings.SendEnchants then | 
| yellowfive@11 | 826 			SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_GE) | 
| adam@0 | 827 		else | 
| yellowfive@11 | 828 			SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_G) | 
| adam@0 | 829 		end | 
| adam@0 | 830 	else | 
| yellowfive@11 | 831 		SendMailSubjectEditBox:SetText(L.AMR_SHOPPINGLISTTAB_MAIL_SUBJECT_E) | 
| adam@0 | 832 	end | 
| adam@17 | 833 	SendMailNameEditBox:SetText(AmrDb.SendSettings.SendTo) | 
| adam@0 | 834 	SendMailBodyEditBox:SetText(message) | 
| adam@0 | 835 end | 
| adam@0 | 836 | 
| adam@0 | 837 function AskMrRobot.ShoppingListTab:Send() | 
| adam@0 | 838 	local chatType = nil | 
| adam@17 | 839 	if AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_PARTY then | 
| adam@0 | 840 		chatType = "PARTY" | 
| adam@17 | 841 	elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_GUILD then | 
| adam@0 | 842 		chatType = "GUILD" | 
| adam@17 | 843 	elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_RAID then | 
| adam@0 | 844 		chatType = "RAID" | 
| adam@17 | 845 	elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_CHANNEL then | 
| adam@0 | 846 		chatType = "CHANNEL" | 
| adam@17 | 847 	elseif AmrDb.SendSettings.SendToType == L.AMR_SHOPPINGLISTTAB_DROPDOWN_MAIL then | 
| adam@0 | 848 		self:sendMail() | 
| adam@0 | 849 		return | 
| adam@0 | 850 	else | 
| adam@0 | 851 		chatType = "WHISPER" | 
| adam@0 | 852 	end | 
| adam@0 | 853 | 
| yellowfive@11 | 854 	local message = L.AMR_SHOPPINGLISTTAB_CHAT_ROBOT_MESSAGE | 
| adam@0 | 855 	local count = 0 | 
| adam@0 | 856 | 
| adam@0 | 857 | 
| adam@0 | 858 	local gemList, enchantList, enchantMaterials = self:CalculateItems() | 
| adam@0 | 859 | 
| adam@0 | 860 	local items = {} | 
| adam@17 | 861 	if AmrDb.SendSettings.SendGems then | 
| adam@0 | 862 		for k,v in pairs(gemList) do | 
| adam@17 | 863 			--if not AskMrRobot.JewelcrafterGems[k] then | 
| adam@0 | 864 				local needed = v.total - v.count | 
| adam@0 | 865 				if needed > 0 then | 
| adam@17 | 866 					tinsert(items, {id = v.id, needed = needed}) | 
| adam@0 | 867 				end | 
| adam@17 | 868 			--end | 
| adam@0 | 869 		end | 
| adam@0 | 870 	end | 
| adam@0 | 871 | 
| adam@17 | 872 	if AmrDb.SendSettings.SendEnchants then | 
| adam@0 | 873 		for k,v in pairs(enchantList) do | 
| adam@0 | 874 			local needed = v.total - v.count | 
| adam@0 | 875 			if needed > 0 then | 
| adam@0 | 876 				tinsert(items, {id = k, needed = needed}) | 
| adam@0 | 877 			end | 
| adam@0 | 878 		end | 
| adam@0 | 879 	end | 
| adam@0 | 880 | 
| adam@17 | 881 	if AmrDb.SendSettings.SendEnchantMaterials then | 
| adam@0 | 882 		for k,v in pairs(enchantMaterials) do | 
| adam@0 | 883 			local needed = v.total - v.count | 
| adam@0 | 884 			if needed > 0 then | 
| adam@0 | 885 				tinsert(items, {id = k, needed = needed}) | 
| adam@0 | 886 			end | 
| adam@0 | 887 		end | 
| adam@0 | 888 	end | 
| adam@0 | 889 | 
| adam@0 | 890 	for i, entry in ipairs(items) do | 
| adam@0 | 891 		local _, link = GetItemInfo(entry.id) | 
| adam@0 | 892 		if link then | 
| adam@0 | 893 			message = message .. " " .. entry.needed .. "x " .. link | 
| adam@0 | 894 			count = count + 1 | 
| adam@0 | 895 			if count == 2 then | 
| adam@17 | 896 				tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrDb.SendSettings.SendTo}) | 
| adam@0 | 897 				count = 0 | 
| yellowfive@11 | 898 				message = L.AMR_SHOPPINGLISTTAB_CHAT_ROBOT_MESSAGE | 
| adam@0 | 899 			end | 
| adam@0 | 900 		end | 
| adam@0 | 901 	end | 
| adam@0 | 902 | 
| adam@0 | 903 	if count > 0 then | 
| adam@17 | 904 		tinsert(self.messageQueue, {message = message, chatType = chatType, chatChannel = AmrDb.SendSettings.SendTo}) | 
| adam@0 | 905 	end | 
| adam@0 | 906 | 
| adam@0 | 907 	self:SendNextMessage() | 
| adam@0 | 908 end | 
| adam@0 | 909 | 
| adam@0 | 910 function AskMrRobot.ShoppingListTab:SendNextMessage() | 
| adam@0 | 911 	while #self.messageQueue > 0 do | 
| adam@0 | 912 		local entry = self.messageQueue[1] | 
| adam@0 | 913 		table.remove(self.messageQueue, 1) | 
| adam@0 | 914 		SendChatMessage(entry.message, entry.chatType, nil, entry.chatChannel) | 
| adam@0 | 915 	end | 
| adam@0 | 916 end |