if UCV == nil then UCV = {} end
UCV.AddonName = "UCV"
local version = 1.0
local active = false
local beforeActive = false
local isLocked = true
local _
local defaults = {
posX = 12,
posY = 12,
sizeX = 230,
sizeY = 288,
active = false,
isLocked = true
}
itemIds = {71200, 71239, 71198, 71199, 114893, 114890, 114891, 114894, 114895, 114892, 114889, 30165}
local function GetLink(id)
if(id == nil) then return "" end
return string.format("|H1:item:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", id)
end
local function GetName(id)
if(id == nil) then return "" end
return zo_strformat("<<t:1>>", GetItemLinkName(GetLink(id)))
end
local function GetIcon(id)
if(id == nil) then return "" end
local iconVal
iconVal, _, _, _, _ = GetItemLinkInfo(GetLink(id))
return iconVal
end
local function GetQuantity(id)
if(id == nil) then return "" end
local qtyVal
_, qtyVal, _, _, _, _, _, _ = GetItemInfo(5, id)
return string.format("%d", qtyVal)
end
function UCV:UpdateDataLines()
local dataLines = {}
local itemLink, tempDataLine = nil
if(#itemIds > 0)then
for i = 1, #itemIds do
itemLink = GetLink(itemIds[i])
if (itemLink ~= "") then
tempDataLine = {
link = itemLink,
qty = GetQuantity(itemIds[i]),
icon = GetIcon(itemIds[i]),
name = GetName(itemIds[i])
}
table.insert(dataLines, tempDataLine)
end
end
end
UCV_GUI_ListHolder.dataLines = dataLines
UCV_GUI_ListHolder:SetParent(UCV_GUI)
UCV:InitializeInventoryLines()
end
function UCV:FillLine(currLine, currItem)
if currItem == nil then
currLine.link = ""
currLine.icon:SetTexture(nil)
currLine.icon:SetAlpha(0)
currLine.name:SetText("")
currLine.qty:SetText("")
else
currLine.link = currItem.link
currLine.icon:SetTexture(currItem.icon)
currLine.icon:SetAlpha(1)
currLine.name:SetText(currItem.name)
currLine.qty:SetText(currItem.qty)
end
end
function UCV:InitializeInventoryLines()
local currLine, currData
for i = 1, #itemIds do
currLine = UCV_GUI_ListHolder.lines[i]
currData = UCV_GUI_ListHolder.dataLines[i]
if( currData ~= nil) then
UCV:FillLine(currLine, currData)
else
UCV:FillLine(currLine, nil)
end
end
end
local function OnReticleHidden(eventCode, hidden)
if(active) then
if(hidden and isLocked) then
UCV_GUI:SetHidden(true)
else
UCV_GUI:SetHidden(false)
UCV:UpdateDataLines()
end
end
end
local function ForceUpdate(eventCode, craftSkill)
if(active) then
UCV:UpdateDataLines()
end
end
local function ForceVisible()
if(active and isLocked) then
isLocked = not isLocked
if(active) then
UCV_GUI:SetHidden(false)
UCV:UpdateDataLines()
end
-- Write isLocked to saved vars.
UCV.savedVars.isLocked = isLocked
else
if(not active) then
d("UCV - The app is not active. Type /ucv to turn on the app.")
end
end
end
local function OnLock()
if(active and not isLocked) then
isLocked = not isLocked
if(active) then
UCV_GUI:SetHidden(false)
UCV:UpdateDataLines()
else
UCV_GUI:SetHidden(true)
end
-- Write isLocked to saved vars.
UCV.savedVars.isLocked = isLocked
elseif(active and isLocked) then
d("UCV - The window is already locked.")
else
if(not active) then
d("The app is not active. Type /ucv to turn on the app.")
end
end
end
function UCV:ToggleActive()
if(HasCraftBagAccess() and CanAnyItemsBeStoredInCraftBag(5)) then
active = not active
-- Write active to saved vars.
UCV.savedVars.active = active
if(active) then
d("Urich's Craftbag Viewer displayed.")
d("UCV slash commands:")
d(" ucv - To deactivate the addon.")
d(" ucv unlock - To unlock the window.")
d(" ucv lock - To lock the window.")
UCV_GUI:SetHidden(false)
UCV:UpdateDataLines()
else
d("Urich's Craftbag Viewer hidden.")
UCV_GUI:SetHidden(true)
end
else
active = false
UCV_GUI:SetHidden(true)
d("You do not have craftbag access.")
end
end
local function BadSlash()
d("Urich's Craftbag Viewer invalid command.")
d("UCV slash commands:")
if(active) then
d(" ucv - To deactivate the addon.")
else
d(" ucv - To activate the addon.")
end
d(" ucv unlock - To unlock the window.")
d(" ucv lock - To lock the window.")
end
function UCV:SavePos()
UCV.savedVars.posX = UCV_GUI:GetLeft()
UCV.savedVars.posY = UCV_GUI:GetTop()
end
function UCV:SaveSize()
UCV.savedVars.sizeX = UCV_GUI:GetWidth()
UCV.savedVars.sizeY = UCV_GUI:GetHeight()
UCV:SavePos()
end
function UCV:CreateLine(i, predecessor, parent)
local record = CreateControlFromVirtual("UCV_CBItem_", parent, "UCV_SlotTemplate", i)
record.icon = record:GetNamedChild("_Icon")
record.name = record:GetNamedChild("_Name")
record.qty = record:GetNamedChild("_Qty")
record:SetHidden(false)
record:SetMouseEnabled(true)
record:SetHeight("24")
if i == 1 then
record:SetAnchor(TOPLEFT, UCV_GUI_ListHolder, TOPLEFT, 0, 0)
record:SetAnchor(TOPRIGHT, UCV_GUI_ListHolder, TOPRIGHT, 0, 0)
else
record:SetAnchor(TOPLEFT, predecessor, BOTTOMLEFT, 0, UCV_GUI_ListHolder.rowHeight)
record:SetAnchor(TOPRIGHT, predecessor, BOTTOMRIGHT, 0, UCV_GUI_ListHolder.rowHeight)
end
record:SetParent(UCV_GUI_ListHolder)
return record
end
function UCV:CreateListHolder()
UCV_GUI_ListHolder.dataLines = {}
UCV_GUI_ListHolder.lines = {}
local predecessor = nil
for i=1, #itemIds do
UCV_GUI_ListHolder.lines[i] = UCV:CreateLine(i, predecessor, UCV_GUI_ListHolder)
predecessor = UCV_GUI_ListHolder.lines[i]
end
UCV:UpdateDataLines()
end
function UCV:OnStart()
if(active) then
UCV_GUI:SetHidden(false)
UCV:CreateListHolder()
UCV_GUI_Header:SetParent(UCV_GUI)
UCV_GUI_Header_Label:SetParent(UCV_GUI_Header)
UCV_GUI_ListHolder:SetParent(UCV_GUI)
else
UCV_GUI:SetHidden(true)
end
end
function UCV_Initialized(eventCode, addonName)
if addonName ~= "UCV" then return end
UCV.savedVars = ZO_SavedVars:New("UCV_Settings", version, nil, defaults)
SLASH_COMMANDS["/ucv"] = function(keyWord)
if(string.lower(keyWord) == "unlock") then
ForceVisible()
elseif(string.lower(keyWord) == "lock") then
OnLock()
elseif(keyWord == "") then
UCV:ToggleActive()
else
BadSlash()
end
end
-- Restore settings
active = UCV.savedVars.active
isLocked = UCV.savedVars.isLocked
UCV_GUI:ClearAnchors()
UCV_GUI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, UCV.savedVars.posX, UCV.savedVars.posY)
UCV_GUI:SetWidth(UCV.savedVars.sizeX)
UCV_GUI:SetHeight(#itemIds * 24 + UCV_GUI_Header:GetHeight() + 12)
UCV:OnStart()
EVENT_MANAGER:RegisterForEvent("UCV", EVENT_RETICLE_HIDDEN_UPDATE, OnReticleHidden)
EVENT_MANAGER:RegisterForEvent("UCV", EVENT_CRAFT_COMPLETED, ForceUpdate)
EVENT_MANAGER:UnregisterForEvent("UCV_Initialized", EVENT_ADD_ON_LOADED)
end
EVENT_MANAGER:RegisterForEvent("UCV_Initialized", EVENT_ADD_ON_LOADED, UCV_Initialized)