Compare with Previous | Blame | View Log
--localize
--add queuing system for multiple items
--collect all enchant ids & remove need for dropdown
-- ESOutpost © ZAM Network LLC
-- All Rights Reserved
local wm = GetWindowManager()
local strformat = string.format
local IsItemBound = IsItemBound
local ZO_Alert = ZO_Alert
local M = ESOutpostMaps
local gui = ESOutpostGUI
local dataForString = {}
local server
local function strsplit(inputstr, sep)
local t, i = {}, 1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
local function RGBPercToHex(r,g,b)
r = r <= 1 and r >= 0 and r or 0
g = g <= 1 and g >= 0 and g or 0
b = b <= 1 and b >= 0 and b or 0
return string.format("%02x%02x%02x", r*255, g*255, b*255)
end
local function wipe(tbl)
for k,v in pairs(tbl) do
k = nil
end
end
local function DataIsComplete()
local missingText = "|cC5C29EESO|rutpost: Your data is not complete."
local isComplete
if not gui.lvlNum:IsHidden() and gui.lvlNum:GetText() == "" then
--d("missing level")
isComplete = false
elseif not gui.traitValuebg:IsHidden() and gui.traitValue:GetText() == "" then
--d("missing traitvalue")
isComplete = false
elseif not gui.enchant:IsHidden() and gui.enchant.dropdown:GetSelectedItem() == "Select Enchant" then
--d("missing enchant")
isComplete = false
elseif (not gui.enchantValueXbg:IsHidden() and gui.enchantValueX:GetText() == "") or (not gui.enchantValueYbg:IsHidden() and gui.enchantValueY:GetText() == "") then
--d("missing enchantvalue")
isComplete = false
else
--d("data complete!")
isComplete = true
end
if isComplete then
return true
else
ZO_Alert(nil, SOUNDS.SKILL_GAINED, missingText)
return false
end
end
local function GenerateString()
if not DataIsComplete() then
return
else
gui.genstring:SetText("Generating String")
dataForString[5] = (gui.lvlNum.vr and "VR" or "")..gui.lvlNum:GetText()
dataForString[12] = gui.traitValue:GetText()
dataForString[13] = gui.enchant.hash
dataForString[14] = gui.enchantValueX:GetText()
dataForString[15] = gui.enchantValueY:GetText()
gui.genstring:SetText(table.concat(dataForString, ":"))
gui.copy:SetEnabled(true)
end
end
gui.generate:SetHandler("OnClicked", GenerateString)
local function ItemTraitToggle(hasTrait, hasStatValue, stat)
gui.trait:ClearAnchors()
if not hasStatValue then
gui.trait:SetAnchor(LEFT, gui.statValue, LEFT)
else
gui.trait:SetAnchor(LEFT, gui.statValue, RIGHT, 20, 0)
end
gui.traitValue:Clear()
gui.traitValuebg:SetHidden(not hasTrait)
end
local canShowEnchants = {[ITEMTYPE_WEAPON] = true, [ITEMTYPE_ARMOR] = true, [ITEMTYPE_GLYPH_WEAPON] = true, [ITEMTYPE_GLYPH_JEWELRY] = true, [ITEMTYPE_GLYPH_ARMOR] = true}
local function EnchantToggle(rawItemType, weaponType, equipType, isLocked)
if canShowEnchants[rawItemType] then
gui.enchant:SetHidden(false)
gui.enchant.dropdown:ClearItems()
local enchants
if equipType == EQUIP_TYPE_RING or equipType == EQUIP_TYPE_NECK or rawItemType == ITEMTYPE_GLYPH_JEWELRY then
enchants = M.jewelryEnchants
elseif rawItemType == ITEMTYPE_ARMOR or weaponType == "shield" or rawItemType == ITEMTYPE_GLYPH_ARMOR then
enchants = M.armorEnchants
else
enchants = M.weaponEnchants
end
for i=1,#enchants do
local entry = gui.enchant.dropdown:CreateItemEntry(enchants[i].text, gui.enchant.callback)
entry.vars = enchants[i].vars
entry.hash = enchants[i].hash
gui.enchant.dropdown:AddItem(entry, ZO_COMBOBOX_SUPRESS_UPDATE)
end
else
gui.enchant:SetHidden(true)
end
gui.enchant.dropdown:SetSelectedItem("Select Enchant")
gui.enchantValueX:Clear()
gui.enchantValueY:Clear()
gui.enchantValueXbg:SetHidden(true)
gui.enchantValueYbg:SetHidden(true)
gui.enchant.type = ""
gui.enchant.hash = ""
if isLocked then
gui.locked:SetDimensions(16, 16)
else
gui.locked:SetDimensions(0, 0)
end
end
local function CanCollectData(control, silent)
if control == GuiRoot then return end
if not M.server[server] then
if not silent then
ZO_Alert(nil, SOUNDS.SKILL_GAINED, "|cC5C29EESO|rutpost: You must be on either the NA or EU Megaserver to sell an item through |cC5C29EESO|rutpost.")
end
return false
elseif control.bagId == 0 then
if not silent then
ZO_Alert(nil, SOUNDS.SKILL_GAINED, "|cC5C29EESO|rutpost: You cannot appraise an item that is equipped.")
end
return false
elseif control:GetParent() == ZO_BuyBackListContents or control:GetParent() == ZO_StoreWindowListContents then
if not silent then
ZO_Alert(nil, SOUNDS.SKILL_GAINED, "|cC5C29EESO|rutpost: You cannot appraise an item from this window.")
end
return false
elseif not control.dataEntry or not control.dataEntry.data or not control.dataEntry.data.bagId then
return false
elseif IsItemBound(control.dataEntry.data.bagId, control.dataEntry.data.slotIndex) then
if not silent then
ZO_Alert(nil, SOUNDS.SKILL_GAINED, "|cC5C29EESO|rutpost: You cannot sell that item.")
end
return false
else
return true
end
end
function CollectESOutpostItemData() --global - keybound function
local control = moc()
if control.outpostBtn then control = control.row end
if not CanCollectData(control) then return end
local controlData = control.dataEntry.data
local bagId = controlData.bagId
local slotIndex = controlData.slotIndex
gui.tooltip:ClearLines()
gui.tooltip:SetBagItem(bagId, slotIndex)
wipe(dataForString)
gui.genstring:Clear()
gui.copy:SetEnabled(false)
local link = GetItemLink(bagId, slotIndex)
local itemLinkData = strsplit(link, ":")
local icon, stack, _, _, locked, equipType, itemStyle, quality = GetItemInfo(bagId, slotIndex)
local soundCat = GetItemSoundCategory(bagId, slotIndex)
PlayItemSound(soundCat, ITEM_SOUND_ACTION_SLOT)
gui.icon.texture:SetTexture(icon)
local name = controlData.name
gui.name:SetText(strformat("%s|c%s%s", stack>1 and "x"..stack.." " or "", RGBPercToHex(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality)), name))
local level = tonumber(itemLinkData[5])
local isVeteran = level > 49
gui.lvl:SetText(isVeteran and "|t32:32:EsoUI\\Art\\UnitFrames\\target_veteranrank_icon.dds|tRank" or "Level")
gui.lvlNum:SetText(isVeteran and GetItemLevel(bagId, slotIndex)-50-quality or level or 0)
gui.lvlNum.vr = isVeteran
local rawItemType = GetItemType(bagId, slotIndex) or "none"
local weaponType, armorType, itemType
if rawItemType == ITEMTYPE_WEAPON then
weaponType = GetItemWeaponType(bagId, slotIndex)
itemType = GetString("SI_WEAPONTYPE", weaponType) or "Weapon"
elseif rawItemType == ITEMTYPE_ARMOR then
armorType = GetItemArmorType(bagId, slotIndex)
itemType = GetString("SI_ARMORTYPE", armorType)
itemType = itemType and itemType.." Armor" or "Armor"
else
itemType = GetString("SI_ITEMTYPE", rawItemType)
end
local equipTypeText = GetString("SI_EQUIPTYPE", equipType) or ""
gui.type:SetText(strformat("%s%s", itemType, equipTypeText=="" and "" or " ("..equipTypeText..")"))
local statValue = controlData.statValue --or 0
local rawTrait = GetItemTrait(bagId, slotIndex)
local trait = GetString("SI_ITEMTRAITTYPE", rawTrait)
gui.statValue:SetText(statValue>0 and strformat("%s %d", (weaponType == "shield" and "Armor") or (rawItemType == ITEMTYPE_WEAPON and "Damage") or (rawItemType == ITEMTYPE_ARMOR and "Armor"), statValue) or "")
gui.trait:SetText(rawTrait>0 and trait or "")
ItemTraitToggle(rawTrait>0, statValue>0, statValue)
EnchantToggle(rawItemType, weaponType, equipType, locked)
dataForString = {
[1] = name:gsub(":", [[\58]]),
[2] = M.itemQuality[quality],
[3] = stack,
[4] = icon:sub(18, -5), --only the file name of the icon, not the whole path
[5] = "", --placeholder for level - double-check this number before generating the string
[6] = M.itemType[rawItemType] or "",
[7] = weaponType and M.weaponType[weaponType] or armorType and M.armorType[armorType] or "",
[8] = "", --"None" - placeholder for staffType
[9] = M.equipType[equipType] or "",
[10] = statValue or "",
[11] = M.traitType[rawTrait],
[12] = "", --placeholder for traitValue
[13] = "", --placeholder for enchant
[14] = "", --placeholder for enchant valueX
[15] = "", --placeholder for enchant valueY
[16] = locked and "l" or "u",
[17] = M.itemStyle[itemStyle] or "",
[18] = itemLinkData[3], --itemID
[19] = M.server[server] or ""
}
gui:SetHidden(false)
end
EVENT_MANAGER:RegisterForEvent("ESOutpost", EVENT_ADD_ON_LOADED, function(event, addon)
if addon == "ESOutpost" then
ZO_CreateStringId("SI_BINDING_NAME_ESOUTPOST_LINK", "Get ESOutpost Link")
local keybindStripDescriptor = {
alignment = KEYBIND_STRIP_ALIGN_RIGHT,
order = 1000,
name = "ESOutpost",
keybind = "ESOUTPOST_LINK",
callback = function(descriptor) CollectESOutpostItemData() end,
icon = "ESOutpost\\ESO-Outpost-Logo-Small.dds",
}
local keybindAdded
local function KeybindVisibility()
if CanCollectData(moc(), true) then
if not keybindAdded then
KEYBIND_STRIP:AddKeybindButton(keybindStripDescriptor)
keybindAdded = true
end
else
if keybindAdded then
KEYBIND_STRIP:RemoveKeybindButton(keybindStripDescriptor)
keybindAdded = false
end
end
end
KEYBIND_STRIP.keybinds["ESOUTPOST_LINK"] = nil --not sure why this is needed...
ZO_PlayerInventory:SetHandler("OnShow", function()
EVENT_MANAGER:RegisterForUpdate("ESOutpostKeybindVisibility", 100, KeybindVisibility)
end)
ZO_PlayerInventory:SetHandler("OnHide", function()
EVENT_MANAGER:RegisterForUpdate("ESOutpostKeybindVisibility")
end)
gui:CreateInventoryButtons()
server = GetCVar("LastRealm")
end
end)