This repository was archived by the owner on Nov 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSLootTracker-UI-Tracker.lua
More file actions
127 lines (105 loc) · 4.05 KB
/
FSLootTracker-UI-Tracker.lua
File metadata and controls
127 lines (105 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require "Window"
local FSLootTracker = Apollo.GetAddon("FSLootTracker")
local Info = Apollo.GetAddonInfo("FSLootTracker")
local Chronology = Apollo.GetPackage("Chronology").tPackage
local Utils = Apollo.GetPackage("SimpleUtils").tPackage
function FSLootTracker:OnObjectiveTrackerLoaded(wndForm)
if not wndForm or not wndForm:IsValid() then
return
end
Apollo.RemoveEventHandler("ObjectiveTrackerLoaded", self)
Apollo.RegisterEventHandler("ToggleShowTrackedLoot", "OnToggleShowTrackedLoot", self)
self.state.windows.tracker = Apollo.LoadForm(self.xmlDoc, "LootObjectiveTracker", wndForm, self)
self.state.windows.tracker:SetData("0") -- Necessary to ensure that it's ordered first in sorting
self.state.windows.trackerObjectiveList = self.state.windows.tracker:FindChild("ObjectiveList")
self:UpdateCountSum()
-- Initialize Watch List
local tTrackerData = {
["strAddon"] = "Watched Loot",
["bNoBtn"] = false,
["strDefaultSort"] = "0000FSLootTracker",
["strEventMouseLeft"] = "ToggleShowTrackedLoot",
["strText"] = tostring(self.state.watchCountSum),
["strIcon"] = "FSLootSprites:BigChest"
}
Event_FireGenericEvent("ObjectiveTracker_NewAddOn", tTrackerData)
self:ResizeAllTracker()
end
function FSLootTracker:ResizeAllTracker()
local nStartingHeight = self.state.windows.tracker:GetHeight()
local bStartingShown = self.state.windows.tracker:IsShown()
local bStartingCount = self.state.watchCountSum
local listHeight = 0
self:RebuildTrackedWatches()
if self.settings.options.showTrackedLoot then
local arChildren = self.state.windows.trackerObjectiveList:GetChildren()
listHeight = 20 * #arChildren
end
listHeight = listHeight + 32
self.state.windows.tracker:Show(self.settings.options.showTrackedLoot)
local nLeft, nTop, nRight, nBottom = self.state.windows.tracker:GetAnchorOffsets()
self.state.windows.tracker:SetAnchorOffsets(nLeft, nTop, nRight, nTop + listHeight)
if nStartingHeight ~= self.state.windows.tracker:GetHeight() or self.settings.options.showTrackedLoot ~= bStartingShown or self.state.watchCountSum ~= bStartingCount then
local tData =
{
["strAddon"] = "Watched Loot",
["strText"] = tostring(self.state.watchCountSum),
["bChecked"] = self.settings.options.showTrackedLoot,
}
Event_FireGenericEvent("ObjectiveTracker_UpdateAddOn", tData)
end
end
function FSLootTracker:OnToggleShowTrackedLoot()
self.settings.options.showTrackedLoot = not self.settings.options.showTrackedLoot
self:ResizeAllTracker()
end
function FSLootTracker:EmptyTrackedWatches()
for idx,wnd in pairs(self.state.windows.trackerObjectiveWindows) do
wnd:Destroy()
end
self.state.windows.trackerObjectiveList:DestroyChildren()
self.state.windows.trackerObjectiveWindows = {}
end
function FSLootTracker:RebuildTrackedWatches()
self:UpdateCountSum()
self:EmptyTrackedWatches()
for id,name in pairs(self.settings.user.watched) do
self:AddTrackedWatch(id)
end
self.state.windows.trackerObjectiveList:ArrangeChildrenVert()
self:UpdateTrackedWatches()
end
function FSLootTracker:AddTrackedWatch(id)
local wnd = Apollo.LoadForm(self.xmlDoc, "LootObjectiveListItem", self.state.windows.trackerObjectiveList, self)
wnd:SetData(id)
table.insert(self.state.windows.trackerObjectiveWindows, wnd)
end
function FSLootTracker:UpdateTrackedWatches()
for idx,wnd in pairs(self.state.windows.trackerObjectiveWindows) do
id = wnd:GetData()
name = self.settings.user.watched[id]
count = self.state.listItems.watchedItemCounts[id]
if not count then
self.state.listItems.watchedItemCounts[id] = 0
count = 0
end
local color = "ItemQuality_Inferior"
if count > 0 then
color = "ItemQuality_Good"
end
if name then
wnd:FindChild("Title"):SetAML(name .. " : <T Font=\"CRB_InterfaceMedium\" TextColor=\"" .. color .. "\">" .. count .. "</T>")
end
end
end
function FSLootTracker:UpdateCountSum()
local sum = 0
for id,name in pairs(self.settings.user.watched) do
local count = self.state.listItems.watchedItemCounts[id]
if not count then
count = 0
end
sum = sum + count
end
self.state.watchCountSum = sum
end