annotate Export.lua @ 69:69db1c3025ac v27

fixed some bugs with 6.2 item link format changes, added bib overwolf support
author yellowfive
date Mon, 06 Jul 2015 17:39:57 -0700
parents 01b63b8ed811
children 0515882856f1
rev   line source
yellowfive@57 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
yellowfive@57 3 local AceGUI = LibStub("AceGUI-3.0")
yellowfive@57 4
yellowfive@57 5 local _lastExport = nil
yellowfive@57 6 local _txt = nil
yellowfive@57 7
yellowfive@57 8 local function createLabel(container, text, width)
yellowfive@57 9 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@57 10 lbl:SetWidth(width or 800)
yellowfive@57 11 lbl:SetText(text)
yellowfive@57 12 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@57 13 container:AddChild(lbl)
yellowfive@57 14 return lbl
yellowfive@57 15 end
yellowfive@57 16
yellowfive@57 17 local function onSplashClose()
yellowfive@57 18 Amr:HideCover()
yellowfive@57 19 Amr.db.char.FirstUse = false
yellowfive@57 20 end
yellowfive@57 21
yellowfive@69 22 local function onTextChanged(widget)
yellowfive@69 23 local val = _txt:GetText()
yellowfive@69 24 if val == "overwolf-bib" then
yellowfive@69 25 -- go to the gear tab, open import window, and show a cover
yellowfive@69 26 Amr:ShowTab("Gear")
yellowfive@69 27 Amr:ShowImportWindow(true)
yellowfive@69 28 end
yellowfive@69 29 end
yellowfive@69 30
yellowfive@57 31 -- render a splash screen with first-time help
yellowfive@57 32 local function renderSplash(container)
yellowfive@57 33 local panel = Amr:RenderCoverChrome(container, 700, 450)
yellowfive@57 34
yellowfive@57 35 local lbl = createLabel(panel, L.ExportSplashTitle, 650)
yellowfive@57 36 lbl:SetJustifyH("CENTER")
yellowfive@57 37 lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
yellowfive@57 38 lbl:SetPoint("TOP", panel.content, "TOP", 0, -10)
yellowfive@57 39
yellowfive@57 40 local lbl2 = createLabel(panel, L.ExportSplashSubtitle, 650)
yellowfive@57 41 lbl2:SetJustifyH("CENTER")
yellowfive@57 42 lbl2:SetFont(Amr.CreateFont("Bold", 18, Amr.Colors.TextTan))
yellowfive@57 43 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -20)
yellowfive@57 44
yellowfive@57 45 lbl = createLabel(panel, L.ExportSplash1, 650)
yellowfive@57 46 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@57 47 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -70)
yellowfive@57 48
yellowfive@57 49 lbl2 = createLabel(panel, L.ExportSplash2, 650)
yellowfive@57 50 lbl2:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@57 51 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -15)
yellowfive@57 52
yellowfive@57 53 lbl = createLabel(panel, L.ExportSplash3, 650)
yellowfive@57 54 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@57 55 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -15)
yellowfive@57 56
yellowfive@57 57 local btn = AceGUI:Create("AmrUiButton")
yellowfive@57 58 btn:SetText(L.ExportSplashClose)
yellowfive@57 59 btn:SetBackgroundColor(Amr.Colors.Green)
yellowfive@57 60 btn:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White))
yellowfive@57 61 btn:SetWidth(120)
yellowfive@57 62 btn:SetHeight(28)
yellowfive@57 63 btn:SetPoint("BOTTOM", panel.content, "BOTTOM", 0, 20)
yellowfive@57 64 btn:SetCallback("OnClick", onSplashClose)
yellowfive@57 65 panel:AddChild(btn)
yellowfive@57 66 end
yellowfive@57 67
yellowfive@57 68 -- renders the main UI for the Export tab
yellowfive@57 69 function Amr:RenderTabExport(container)
yellowfive@57 70
yellowfive@57 71 local lbl = createLabel(container, L.ExportTitle)
yellowfive@57 72 lbl:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
yellowfive@57 73 lbl:SetPoint("TOPLEFT", container.content, "TOPLEFT", 0, -40)
yellowfive@57 74
yellowfive@57 75 local lbl2 = createLabel(container, L.ExportHelp1)
yellowfive@57 76 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10)
yellowfive@57 77
yellowfive@57 78 lbl = createLabel(container, L.ExportHelp2)
yellowfive@57 79 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -10)
yellowfive@57 80
yellowfive@57 81 lbl2 = createLabel(container, L.ExportHelp3)
yellowfive@57 82 lbl2:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -10)
yellowfive@57 83
yellowfive@57 84 lbl = createLabel(container, L.ExportHelp4)
yellowfive@57 85 lbl:SetPoint("TOPLEFT", lbl2.frame, "BOTTOMLEFT", 0, -10)
yellowfive@57 86
yellowfive@57 87 _txt = AceGUI:Create("AmrUiTextarea")
yellowfive@57 88 _txt:SetWidth(800)
yellowfive@57 89 _txt:SetHeight(300)
yellowfive@57 90 _txt:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -20)
yellowfive@57 91 _txt:SetFont(Amr.CreateFont("Regular", 12, Amr.Colors.Text))
yellowfive@69 92 _txt:SetCallback("OnTextChanged", onTextChanged)
yellowfive@57 93 container:AddChild(_txt)
yellowfive@57 94
yellowfive@57 95 local data = self:ExportCharacter()
yellowfive@57 96 local txt = Amr.Serializer:SerializePlayerData(data, true)
yellowfive@57 97 _txt:SetText(txt)
yellowfive@57 98 _txt:SetFocus(true)
yellowfive@57 99
yellowfive@57 100 -- update shopping list data
yellowfive@57 101 Amr:UpdateShoppingData(data)
yellowfive@57 102
yellowfive@57 103 -- show help splash if first time a user is using this
yellowfive@57 104 if Amr.db.char.FirstUse then
yellowfive@57 105 Amr:ShowCover(renderSplash)
yellowfive@57 106 AceGUI:ClearFocus()
yellowfive@57 107 end
yellowfive@57 108 end
yellowfive@57 109
yellowfive@57 110 function Amr:ReleaseTabExport()
yellowfive@57 111 end
yellowfive@57 112
yellowfive@57 113 function Amr:GetExportText()
yellowfive@57 114 return _txt:GetText()
yellowfive@57 115 end
yellowfive@57 116
yellowfive@57 117
yellowfive@57 118 -- use some local variables to deal with the fact that a user can close the bank before a scan completes
yellowfive@57 119 local _lastBankBagId = nil
yellowfive@57 120 local _lastBankSlotId = nil
yellowfive@57 121
yellowfive@57 122 local function scanBag(bagId, isBank, bagTable, bagItemsWithCount)
yellowfive@57 123 local numSlots = GetContainerNumSlots(bagId)
yellowfive@57 124 for slotId = 1, numSlots do
yellowfive@57 125 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
yellowfive@57 126 if itemLink ~= nil then
yellowfive@57 127 local itemData = Amr.Serializer.ParseItemLink(itemLink)
yellowfive@57 128 if itemData ~= nil then
yellowfive@57 129 -- only add equippable items to bag data
yellowfive@57 130 if IsEquippableItem(itemLink) or Amr.SetTokenIds[itemData.id] then
yellowfive@57 131 if isBank then
yellowfive@57 132 _lastBankBagId = bagId
yellowfive@57 133 _lastBankSlotId = slotId
yellowfive@57 134 end
yellowfive@57 135
yellowfive@57 136 table.insert(bagTable, itemLink)
yellowfive@57 137 end
yellowfive@57 138
yellowfive@57 139 -- all items and counts, used for e.g. shopping list and reagents, etc.
yellowfive@57 140 if bagItemsWithCount then
yellowfive@57 141 if bagItemsWithCount[itemData.id] then
yellowfive@57 142 bagItemsWithCount[itemData.id] = bagItemsWithCount[itemData.id] + itemCount
yellowfive@57 143 else
yellowfive@57 144 bagItemsWithCount[itemData.id] = itemCount
yellowfive@57 145 end
yellowfive@57 146 end
yellowfive@57 147 end
yellowfive@57 148 end
yellowfive@57 149 end
yellowfive@57 150 end
yellowfive@57 151
yellowfive@57 152 -- get the player's current gear and save it, also returns the data from GetPlayerData for efficiency
yellowfive@57 153 local function getEquipped()
yellowfive@57 154 local data = Amr.Serializer:GetPlayerData(Amr.db.char.SubSpecs)
yellowfive@57 155 local spec = GetActiveSpecGroup()
yellowfive@57 156
yellowfive@57 157 Amr.db.char.Equipped[spec] = data.Equipped[spec]
yellowfive@57 158 Amr.db.char.SubSpecs[spec] = data.SubSpecs[spec]
yellowfive@57 159
yellowfive@57 160 return data
yellowfive@57 161 end
yellowfive@57 162
yellowfive@57 163 local function scanBags()
yellowfive@57 164
yellowfive@57 165 local bagItems = {}
yellowfive@57 166 local itemsAndCounts = {}
yellowfive@57 167
yellowfive@57 168 scanBag(BACKPACK_CONTAINER, false, bagItems, itemsAndCounts) -- backpack
yellowfive@57 169 for bagId = 1, NUM_BAG_SLOTS do
yellowfive@57 170 scanBag(bagId, false, bagItems, itemsAndCounts)
yellowfive@57 171 end
yellowfive@57 172
yellowfive@57 173 Amr.db.char.BagItems = bagItems
yellowfive@57 174 Amr.db.char.BagItemsAndCounts = itemsAndCounts
yellowfive@57 175 end
yellowfive@57 176
yellowfive@57 177 -- scan the player's bank and save the contents, must be at the bank
yellowfive@57 178 local function scanBank()
yellowfive@57 179
yellowfive@57 180 local bankItems = {}
yellowfive@57 181 local itemsAndCounts = {}
yellowfive@57 182
yellowfive@57 183 scanBag(BANK_CONTAINER, true, bankItems, itemsAndCounts)
yellowfive@57 184 scanBag(REAGENTBANK_CONTAINER, true, bankItems, itemsAndCounts)
yellowfive@57 185 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
yellowfive@57 186 scanBag(bagId, true, bankItems, itemsAndCounts)
yellowfive@57 187 end
yellowfive@57 188
yellowfive@57 189 -- see if the scan completed before the window closed, otherwise we don't overwrite with partial data
yellowfive@57 190 if _lastBankBagId ~= nil then
yellowfive@57 191 local itemLink = GetContainerItemLink(_lastBankBagId, _lastBankSlotId)
yellowfive@57 192 if itemLink ~= nil then --still open
yellowfive@57 193 Amr.db.char.BankItems = bankItems
yellowfive@57 194 Amr.db.char.BankItemsAndCounts = itemsAndCounts
yellowfive@57 195 end
yellowfive@57 196 end
yellowfive@57 197
yellowfive@57 198 end
yellowfive@57 199
yellowfive@57 200 -- scan the player's void storage and save the contents, must be at void storage
yellowfive@57 201 local function scanVoid()
yellowfive@57 202
yellowfive@57 203 if IsVoidStorageReady() then
yellowfive@57 204 local voidItems = {}
yellowfive@57 205 local VOID_STORAGE_MAX = 80
yellowfive@57 206 local VOID_STORAGE_PAGES = 2
yellowfive@57 207
yellowfive@57 208 for page = 1,VOID_STORAGE_PAGES do
yellowfive@57 209 for i = 1,VOID_STORAGE_MAX do
yellowfive@57 210 local itemId = GetVoidItemInfo(page, i)
yellowfive@57 211 if itemId then
yellowfive@57 212 local itemLink = GetVoidItemHyperlinkString(((page - 1) * VOID_STORAGE_MAX) + i);
yellowfive@57 213 if itemLink then
yellowfive@57 214 tinsert(voidItems, itemLink)
yellowfive@57 215 end
yellowfive@57 216 end
yellowfive@57 217 end
yellowfive@57 218 end
yellowfive@57 219
yellowfive@57 220 Amr.db.char.VoidItems = voidItems
yellowfive@57 221 end
yellowfive@57 222
yellowfive@57 223 end
yellowfive@57 224
yellowfive@57 225 local function getRepStanding(factionId)
yellowfive@57 226 local name, description, standingId, _ = GetFactionInfoByID(factionId)
yellowfive@57 227 return standingId - 1; -- our rep enum correspond to what the armory returns, are 1 less than what the game returns
yellowfive@57 228 end
yellowfive@57 229
yellowfive@57 230 local function getReputations()
yellowfive@57 231 local reps = {}
yellowfive@57 232
yellowfive@57 233 local repList = {1375,1376,1270,1269,1341,1337,1387,1388,1435}
yellowfive@57 234 for i, repId in pairs(repList) do
yellowfive@57 235 local standing = getRepStanding(repId)
yellowfive@57 236 if standing >= 0 then
yellowfive@57 237 reps[repId] = standing
yellowfive@57 238 end
yellowfive@57 239 end
yellowfive@57 240
yellowfive@57 241 return reps
yellowfive@57 242 end
yellowfive@57 243
yellowfive@57 244 -- Returns a data object containing all information about the current player needed for an export:
yellowfive@57 245 -- gear, spec, reputations, bag, bank, and void storage items.
yellowfive@57 246 function Amr:ExportCharacter()
yellowfive@57 247
yellowfive@57 248 local data = getEquipped()
yellowfive@57 249 scanBags()
yellowfive@57 250
yellowfive@57 251 -- get extra data that is not necessary for the base serializer, but that we add here for completeness
yellowfive@57 252 data.Equipped = Amr.db.char.Equipped
yellowfive@57 253 data.Reputations = getReputations()
yellowfive@57 254 data.BagItems = Amr.db.char.BagItems
yellowfive@57 255 data.BankItems = Amr.db.char.BankItems
yellowfive@57 256 data.VoidItems = Amr.db.char.VoidItems
yellowfive@57 257
yellowfive@57 258 return data
yellowfive@57 259 end
yellowfive@57 260
yellowfive@57 261 function Amr:InitializeExport()
yellowfive@57 262 Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID)
yellowfive@57 263 if unitID and unitID ~= "player" then return end
yellowfive@57 264 getEquipped()
yellowfive@57 265 end)
yellowfive@57 266 end
yellowfive@57 267
yellowfive@57 268 Amr:AddEventHandler("BANKFRAME_OPENED", scanBank)
yellowfive@57 269 Amr:AddEventHandler("PLAYERBANKSLOTS_CHANGED", scanBank)
yellowfive@57 270
yellowfive@57 271 Amr:AddEventHandler("VOID_STORAGE_OPEN", scanVoid)
yellowfive@57 272 Amr:AddEventHandler("VOID_STORAGE_CONTENTS_UPDATE", scanVoid)
yellowfive@57 273 Amr:AddEventHandler("VOID_STORAGE_DEPOSIT_UPDATE", scanVoid)
yellowfive@57 274 Amr:AddEventHandler("VOID_STORAGE_UPDATE", scanVoid)