yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true) yellowfive@57: local AceGUI = LibStub("AceGUI-3.0") yellowfive@57: yellowfive@57: local _lastExport = nil yellowfive@57: local _txt = nil yellowfive@57: yellowfive@57: local function createLabel(container, text, width) yellowfive@57: local lbl = AceGUI:Create("AmrUiLabel") yellowfive@57: lbl:SetWidth(width or 800) yellowfive@57: lbl:SetText(text) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@57: container:AddChild(lbl) yellowfive@57: return lbl yellowfive@57: end yellowfive@57: yellowfive@57: local function onSplashClose() yellowfive@57: Amr:HideCover() yellowfive@57: Amr.db.char.FirstUse = false yellowfive@57: end yellowfive@57: yellowfive@69: local function onTextChanged(widget) yellowfive@69: local val = _txt:GetText() yellowfive@69: if val == "overwolf-bib" then yellowfive@69: -- go to the gear tab, open import window, and show a cover yellowfive@69: Amr:ShowTab("Gear") yellowfive@69: Amr:ShowImportWindow(true) yellowfive@69: end yellowfive@69: end yellowfive@69: yellowfive@57: -- render a splash screen with first-time help yellowfive@57: local function renderSplash(container) yellowfive@57: local panel = Amr:RenderCoverChrome(container, 700, 450) yellowfive@57: yellowfive@57: local lbl = createLabel(panel, L.ExportSplashTitle, 650) yellowfive@57: lbl:SetJustifyH("CENTER") yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive)) yellowfive@57: lbl:SetPoint("TOP", panel.content, "TOP", 0, -10) yellowfive@57: yellowfive@57: local lbl2 = createLabel(panel, L.ExportSplashSubtitle, 650) yellowfive@57: lbl2:SetJustifyH("CENTER") yellowfive@57: lbl2:SetFont(Amr.CreateFont("Bold", 18, Amr.Colors.TextTan)) yellowfive@57: lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -20) yellowfive@57: yellowfive@57: lbl = createLabel(panel, L.ExportSplash1, 650) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@57: lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -70) yellowfive@57: yellowfive@57: lbl2 = createLabel(panel, L.ExportSplash2, 650) yellowfive@57: lbl2:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@57: lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -15) yellowfive@57: yellowfive@57: lbl = createLabel(panel, L.ExportSplash3, 650) yellowfive@57: lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@57: lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -15) yellowfive@81: yellowfive@81: lbl2 = createLabel(panel, L.ExportSplash4, 650) yellowfive@81: lbl2:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@81: lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -15) yellowfive@57: yellowfive@57: local btn = AceGUI:Create("AmrUiButton") yellowfive@57: btn:SetText(L.ExportSplashClose) yellowfive@57: btn:SetBackgroundColor(Amr.Colors.Green) yellowfive@57: btn:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White)) yellowfive@57: btn:SetWidth(120) yellowfive@57: btn:SetHeight(28) yellowfive@57: btn:SetPoint("BOTTOM", panel.content, "BOTTOM", 0, 20) yellowfive@57: btn:SetCallback("OnClick", onSplashClose) yellowfive@57: panel:AddChild(btn) yellowfive@57: end yellowfive@57: yellowfive@57: -- renders the main UI for the Export tab yellowfive@57: function Amr:RenderTabExport(container) yellowfive@57: yellowfive@57: local lbl = createLabel(container, L.ExportTitle) yellowfive@57: lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive)) yellowfive@57: lbl:SetPoint("TOPLEFT", container.content, "TOPLEFT", 0, -40) yellowfive@57: yellowfive@57: local lbl2 = createLabel(container, L.ExportHelp1) yellowfive@57: lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10) yellowfive@57: yellowfive@57: lbl = createLabel(container, L.ExportHelp2) yellowfive@57: lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -10) yellowfive@57: yellowfive@57: lbl2 = createLabel(container, L.ExportHelp3) yellowfive@57: lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10) yellowfive@57: yellowfive@57: _txt = AceGUI:Create("AmrUiTextarea") yellowfive@57: _txt:SetWidth(800) yellowfive@57: _txt:SetHeight(300) yellowfive@81: _txt:SetPoint("TOP", lbl2.frame, "BOTTOM", 0, -20) yellowfive@57: _txt:SetFont(Amr.CreateFont("Regular", 12, Amr.Colors.Text)) yellowfive@69: _txt:SetCallback("OnTextChanged", onTextChanged) yellowfive@57: container:AddChild(_txt) yellowfive@57: yellowfive@57: local data = self:ExportCharacter() yellowfive@57: local txt = Amr.Serializer:SerializePlayerData(data, true) yellowfive@57: _txt:SetText(txt) yellowfive@57: _txt:SetFocus(true) yellowfive@57: yellowfive@57: -- update shopping list data yellowfive@57: Amr:UpdateShoppingData(data) yellowfive@57: yellowfive@57: -- show help splash if first time a user is using this yellowfive@57: if Amr.db.char.FirstUse then yellowfive@57: Amr:ShowCover(renderSplash) yellowfive@57: AceGUI:ClearFocus() yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:ReleaseTabExport() yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:GetExportText() yellowfive@57: return _txt:GetText() yellowfive@57: end yellowfive@57: yellowfive@57: yellowfive@57: -- use some local variables to deal with the fact that a user can close the bank before a scan completes yellowfive@57: local _lastBankBagId = nil yellowfive@57: local _lastBankSlotId = nil yellowfive@57: yellowfive@57: local function scanBag(bagId, isBank, bagTable, bagItemsWithCount) yellowfive@57: local numSlots = GetContainerNumSlots(bagId) yellowfive@57: for slotId = 1, numSlots do yellowfive@57: local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId) yellowfive@57: if itemLink ~= nil then yellowfive@57: local itemData = Amr.Serializer.ParseItemLink(itemLink) yellowfive@57: if itemData ~= nil then yellowfive@85: yellowfive@57: -- only add equippable items to bag data yellowfive@85: --if IsEquippableItem(itemLink) or Amr.SetTokenIds[itemData.id] then yellowfive@57: if isBank then yellowfive@57: _lastBankBagId = bagId yellowfive@57: _lastBankSlotId = slotId yellowfive@57: end yellowfive@57: yellowfive@57: table.insert(bagTable, itemLink) yellowfive@85: --end yellowfive@57: yellowfive@57: -- all items and counts, used for e.g. shopping list and reagents, etc. yellowfive@57: if bagItemsWithCount then yellowfive@57: if bagItemsWithCount[itemData.id] then yellowfive@57: bagItemsWithCount[itemData.id] = bagItemsWithCount[itemData.id] + itemCount yellowfive@57: else yellowfive@57: bagItemsWithCount[itemData.id] = itemCount yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: -- get the player's current gear and save it, also returns the data from GetPlayerData for efficiency yellowfive@57: local function getEquipped() yellowfive@81: local data = Amr.Serializer:GetPlayerData() yellowfive@81: local spec = GetSpecialization() yellowfive@57: yellowfive@57: Amr.db.char.Equipped[spec] = data.Equipped[spec] yellowfive@57: yellowfive@57: return data yellowfive@57: end yellowfive@57: yellowfive@57: local function scanBags() yellowfive@57: yellowfive@57: local bagItems = {} yellowfive@57: local itemsAndCounts = {} yellowfive@57: yellowfive@57: scanBag(BACKPACK_CONTAINER, false, bagItems, itemsAndCounts) -- backpack yellowfive@57: for bagId = 1, NUM_BAG_SLOTS do yellowfive@57: scanBag(bagId, false, bagItems, itemsAndCounts) yellowfive@57: end yellowfive@57: yellowfive@57: Amr.db.char.BagItems = bagItems yellowfive@57: Amr.db.char.BagItemsAndCounts = itemsAndCounts yellowfive@57: end yellowfive@57: yellowfive@57: -- scan the player's bank and save the contents, must be at the bank yellowfive@57: local function scanBank() yellowfive@57: yellowfive@57: local bankItems = {} yellowfive@57: local itemsAndCounts = {} yellowfive@57: yellowfive@57: scanBag(BANK_CONTAINER, true, bankItems, itemsAndCounts) yellowfive@57: scanBag(REAGENTBANK_CONTAINER, true, bankItems, itemsAndCounts) yellowfive@57: for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do yellowfive@57: scanBag(bagId, true, bankItems, itemsAndCounts) yellowfive@57: end yellowfive@57: yellowfive@57: -- see if the scan completed before the window closed, otherwise we don't overwrite with partial data yellowfive@57: if _lastBankBagId ~= nil then yellowfive@57: local itemLink = GetContainerItemLink(_lastBankBagId, _lastBankSlotId) yellowfive@57: if itemLink ~= nil then --still open yellowfive@57: Amr.db.char.BankItems = bankItems yellowfive@57: Amr.db.char.BankItemsAndCounts = itemsAndCounts yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: -- scan the player's void storage and save the contents, must be at void storage yellowfive@57: local function scanVoid() yellowfive@57: yellowfive@57: if IsVoidStorageReady() then yellowfive@57: local voidItems = {} yellowfive@57: local VOID_STORAGE_MAX = 80 yellowfive@57: local VOID_STORAGE_PAGES = 2 yellowfive@57: yellowfive@57: for page = 1,VOID_STORAGE_PAGES do yellowfive@57: for i = 1,VOID_STORAGE_MAX do yellowfive@57: local itemId = GetVoidItemInfo(page, i) yellowfive@57: if itemId then yellowfive@57: local itemLink = GetVoidItemHyperlinkString(((page - 1) * VOID_STORAGE_MAX) + i); yellowfive@57: if itemLink then yellowfive@57: tinsert(voidItems, itemLink) yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: Amr.db.char.VoidItems = voidItems yellowfive@57: end yellowfive@57: yellowfive@57: end yellowfive@57: yellowfive@57: local function getRepStanding(factionId) yellowfive@57: local name, description, standingId, _ = GetFactionInfoByID(factionId) yellowfive@57: return standingId - 1; -- our rep enum correspond to what the armory returns, are 1 less than what the game returns yellowfive@57: end yellowfive@57: yellowfive@57: local function getReputations() yellowfive@57: local reps = {} yellowfive@57: yellowfive@57: local repList = {1375,1376,1270,1269,1341,1337,1387,1388,1435} yellowfive@57: for i, repId in pairs(repList) do yellowfive@57: local standing = getRepStanding(repId) yellowfive@57: if standing >= 0 then yellowfive@57: reps[repId] = standing yellowfive@57: end yellowfive@57: end yellowfive@57: yellowfive@57: return reps yellowfive@57: end yellowfive@57: yellowfive@81: local function scanTalents() yellowfive@81: local specPos = GetSpecialization() yellowfive@81: if not specPos or specPos < 1 or specPos > 4 then return end yellowfive@81: yellowfive@81: local talentInfo = {} yellowfive@81: local maxTiers = 7 yellowfive@81: for tier = 1, maxTiers do yellowfive@81: for col = 1, 3 do yellowfive@81: local id, name, _, _, _, spellId, _, t, c, selected = GetTalentInfoBySpecialization(specPos, tier, col) yellowfive@81: if selected then yellowfive@81: talentInfo[tier] = col yellowfive@81: end yellowfive@81: end yellowfive@81: end yellowfive@81: yellowfive@81: local str = "" yellowfive@81: for i = 1, maxTiers do yellowfive@81: if talentInfo[i] then yellowfive@81: str = str .. talentInfo[i] yellowfive@81: else yellowfive@81: str = str .. '0' yellowfive@81: end yellowfive@81: end yellowfive@81: yellowfive@81: Amr.db.char.Talents[specPos] = str yellowfive@81: end yellowfive@81: yellowfive@81: local function scanArtifact() yellowfive@81: -- TODO: when they put in a real API for this, switch to that instead of using UI methods directly yellowfive@81: local powers = C_ArtifactUI.GetPowers() yellowfive@81: if not powers then return end yellowfive@81: yellowfive@81: local powerRanks = {} yellowfive@81: for k,v in pairs(powers) do yellowfive@81: local spellId, cost, rank, maxRank, relicRank = C_ArtifactUI.GetPowerInfo(v) yellowfive@81: if rank - relicRank > 0 then yellowfive@81: powerRanks[v] = rank - relicRank yellowfive@81: end yellowfive@81: end yellowfive@81: yellowfive@81: local relicInfo = {} yellowfive@81: for i = 1,3 do yellowfive@81: local _, _, _, link = C_ArtifactUI.GetRelicInfo(i); yellowfive@81: table.insert(relicInfo, link or "") yellowfive@81: end yellowfive@81: yellowfive@81: -- make sure that the artifact UI didn't get closed while we were reading it, GetPowers seems to return nil unless it is open yellowfive@81: powers = C_ArtifactUI.GetPowers() yellowfive@81: if not powers then return end yellowfive@81: yellowfive@81: local spec = GetSpecialization() yellowfive@81: Amr.db.char.Artifacts[spec] = { yellowfive@81: Powers = powerRanks, yellowfive@81: Relics = relicInfo yellowfive@81: } yellowfive@81: end yellowfive@81: yellowfive@57: -- Returns a data object containing all information about the current player needed for an export: yellowfive@57: -- gear, spec, reputations, bag, bank, and void storage items. yellowfive@57: function Amr:ExportCharacter() yellowfive@57: yellowfive@57: local data = getEquipped() yellowfive@57: scanBags() yellowfive@57: yellowfive@81: -- scan current spec's talents just before exporting yellowfive@81: scanTalents() yellowfive@81: yellowfive@81: data.Talents = Amr.db.char.Talents yellowfive@81: data.Artifacts = Amr.db.char.Artifacts yellowfive@57: data.Equipped = Amr.db.char.Equipped yellowfive@57: data.Reputations = getReputations() yellowfive@57: data.BagItems = Amr.db.char.BagItems yellowfive@57: data.BankItems = Amr.db.char.BankItems yellowfive@57: data.VoidItems = Amr.db.char.VoidItems yellowfive@57: yellowfive@57: return data yellowfive@57: end yellowfive@57: yellowfive@57: function Amr:InitializeExport() yellowfive@57: Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID) yellowfive@57: if unitID and unitID ~= "player" then return end yellowfive@57: getEquipped() yellowfive@57: end) yellowfive@57: end yellowfive@57: yellowfive@57: Amr:AddEventHandler("BANKFRAME_OPENED", scanBank) yellowfive@57: Amr:AddEventHandler("PLAYERBANKSLOTS_CHANGED", scanBank) yellowfive@57: yellowfive@57: Amr:AddEventHandler("VOID_STORAGE_OPEN", scanVoid) yellowfive@57: Amr:AddEventHandler("VOID_STORAGE_CONTENTS_UPDATE", scanVoid) yellowfive@57: Amr:AddEventHandler("VOID_STORAGE_DEPOSIT_UPDATE", scanVoid) yellowfive@57: Amr:AddEventHandler("VOID_STORAGE_UPDATE", scanVoid) yellowfive@81: yellowfive@81: Amr:AddEventHandler("PLAYER_TALENT_UPDATE", scanTalents) yellowfive@81: Amr:AddEventHandler("ARTIFACT_UPDATE", scanArtifact)