-- Initialise the History Window
-- 30 label controls seemed adequate for a screen full of information,
-- the scroll bar would simply move the starting point in the data list
-- to decide which one goes on which label
local function InitHistoryWindow(...)
local tlw = WINDOW_MANAGER:CreateTopLevelWindow(nil)
tlw.DataOffset = 0
tlw.MaxLines = 30
tlw.DataLines = {}
tlw.Lines = {}
tlw:SetHeight(625)
tlw:SetWidth(575)
tlw:SetAnchor(CENTER,GuiRoot,CENTER,0,0)
tlw:SetDrawLayer(DL_BACKGROUND)
tlw:SetMouseEnabled(true)
tlw:SetMovable(false)
tlw:SetClampedToScreen(true)
tlw:SetHidden(true)
tlw:SetHandler("OnMouseWheel",function(self,delta)
local value = tlw.DataOffset - delta
if value < 0 then
value = 0
elseif value > #tlw.DataLines - tlw.MaxLines then
value = #tlw.DataLines - tlw.MaxLines
end
tlw.DataOffset = value
tlw.Slider:SetValue(tlw.DataOffset)
UpdateHistoryWindow()
end)
tlw:SetHandler("OnShow",function(self)
local index = 0
-- Make sure we are looking at the latest data
-- I create a quick access table for traversing easily
-- for reading purposes only
UpdateHarvestHistory()
-- Update what the window lines are going to show.
-- This is reading through my table of data generated with the function above.
-- And generating a text line of information to display on the label
tlw.DataLines = {}
for historyIndex,historyData in pairs(harvestHistory) do
for zoneIndex,zoneData in pairs(historyData) do
if zoneIndex ~= "version" then
for itemIndex,itemData in pairs(zoneData) do
for indexIndex,indexData in pairs(itemData) do
index = index + 1
tlw.DataLines[index] = string.format("[%d]: %s %s in %s at %0.3f,%0.3f",index,itemIndex,tostring(indexData["Action"]),zoneIndex,indexData["X"],indexData["Y"])
end
end
end
end
end
tlw.Caption.Text:SetText(addonName .. " ["..addonVersion.."] - " .. #tlw.DataLines or 0 .. " Total")
UpdateHistoryWindow()
end)
tlw.BackGround = WINDOW_MANAGER:CreateControl(nil,tlw,CT_BACKDROP)
tlw.BackGround:SetAnchorFill(tlw)
tlw.BackGround:SetCenterColor(0.0, 0.0, 0.0, 0.5)
tlw.BackGround:SetEdgeColor(1.0, 1.0, 0.0, 0.5)
tlw.BackGround:SetEdgeTexture(nil, 2, 2, 2.0, 2.0)
-- This is what turns a simple slider into a scrollbar
local tex = "/esoui/art/miscellaneous/scrollbox_elevator.dds"
tlw.Slider = WINDOW_MANAGER:CreateControl(nil,tlw,CT_SLIDER)
tlw.Slider:SetDimensions(30,tlw:GetHeight())
tlw.Slider:SetMouseEnabled(true)
tlw.Slider:SetThumbTexture(tex,tex,tex,30,50,0,0,1,1)
tlw.Slider:SetValue(0)
tlw.Slider:SetValueStep(1)
tlw.Slider:SetAnchor(LEFT,tlw,RIGHT,0,0)
-- When we change the slider's value we need to change the data offset and redraw the display
tlw.Slider:SetHandler("OnValueChanged",function(self,value,eventReason)
tlw.DataOffset = math.min(value,#tlw.DataLines - tlw.MaxLines)
UpdateHistoryWindow()
end)
tlw.Caption = WINDOW_MANAGER:CreateControl(nil,tlw,CT_CONTROL)
tlw.Caption:SetDimensions(tlw:GetWidth(),30)
tlw.Caption:SetAnchor(BOTTOMLEFT,tlw,TOPLEFT,0,0)
tlw.Caption:SetHidden(false)
tlw.Caption.Text = WINDOW_MANAGER:CreateControl(nil,tlw.Caption,CT_LABEL)
tlw.Caption.Text:SetAnchorFill(tlw.Caption)
tlw.Caption.Text:SetFont("ZoFontGameLargeBoldShadow")
tlw.Caption.Text:SetDimensions(tlw.Caption:GetWidth(),tlw.Caption:GetHeight())
tlw.Caption.Text:SetText(addonName .. " ["..addonVersion.."] - " .. #harvestHistory or 0 .. " Total")
tlw.Caption.Text:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
tlw.Caption.Text:SetHidden(false)
tlw.Close = WINDOW_MANAGER:CreateControl(nil,tlw,CT_BUTTON)
tlw.Close:SetDimensions(tlw.Caption:GetHeight(),tlw.Caption:GetHeight())
tlw.Close:SetAnchor(BOTTOMRIGHT,tlw.Slider,TOPRIGHT,0,0)
tlw.Close:SetHidden(false)
tlw.Close:SetFont("ZoFontGameLargeBoldShadow")
tlw.Close:SetText("X")
tlw.Close:SetHandler("OnClicked",function(self)
tlw:SetHidden(true)
end)
-- And this is the block of code that generates the group of controls that make up the scrollable area.
-- As well as labels you could add buttons and other controls and attach them to the lines control.
for i=1,tlw.MaxLines do
tlw.Lines[i] = WINDOW_MANAGER:CreateControl(nil,tlw,CT_CONTROL)
tlw.Lines[i]:SetDimensions(tlw:GetWidth(),20)
if i == 1 then
tlw.Lines[i]:SetAnchor(TOPLEFT,tlw,TOPLEFT,5,5)
else
tlw.Lines[i]:SetAnchor(TOPLEFT,tlw.Lines[i-1],BOTTOMLEFT,0,0)
end
tlw.Lines[i].Text = WINDOW_MANAGER:CreateControl(nil,tlw.Lines[i],CT_LABEL)
tlw.Lines[i].Text:SetFont("ZoFontGame")
tlw.Lines[i].Text:SetDimensions(tlw.Lines[i]:GetWidth(),30)
tlw.Lines[i].Text:SetAnchor(LEFT,tlw.Lines[i],LEFT,5,5)
tlw.Lines[i].Text:SetText(string.format("Line %d Data %s",i,"Line " .. i))
tlw.Lines[i]:SetHidden(false)
end
-- transfer simply named control to a more user friendly file wide control name
historyWindow = tlw
end