-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathConfig.lua
More file actions
321 lines (294 loc) · 11.1 KB
/
Copy pathConfig.lua
File metadata and controls
321 lines (294 loc) · 11.1 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local LDB = LibStub("LibDataBroker-1.1", true)
local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true)
local icon_loaded = false
local icon_name = "BisTooltipIcon"
-- local DataStore = LibStub("DataStore")
-- local DataStore_Inventory = LibStub("DataStore_Inventory")
local sources = {
wowtbc = "wowtbc"
}
Bistooltip_source_to_url = {
["wowtbc"] = "wowtbc.gg/wotlk"
}
local db_defaults = {
char = {
class_index = 1,
spec_index = 1,
phase_index = 1,
filter_specs = {},
highlight_spec = {},
data_source = nil,
minimap_icon = true,
tooltip_with_ctrl = false
}
}
local configTable = {
type = "group",
args = {
minimap_icon = {
name = "Show minimap icon",
order = 0,
desc = "Shows/hides minimap icon",
type = "toggle",
set = function(info, val)
BistooltipAddon.db.char.minimap_icon = val
if val == true then
if icon_loaded == true then
LDBIcon:Show(icon_name)
else
BistooltipAddon:addMapIcon()
end
else
LDBIcon:Hide(icon_name)
end
end,
get = function(info)
return BistooltipAddon.db.char.minimap_icon
end
},
filter_class_names = {
name = "Hide class names",
order = 1,
desc = "Removes class name separators from item tooltips",
type = "toggle",
set = function(info, val)
BistooltipAddon.db.char.filter_class_names = val
end,
get = function(info)
return BistooltipAddon.db.char.filter_class_names
end
},
tooltip_with_ctrl = {
name = "Show item tooltips with Ctrl",
order = 2,
desc = "Show item tooltips only when holding Ctrl key",
type = "toggle",
width = "double",
set = function(info, val)
BistooltipAddon.db.char.tooltip_with_ctrl = val
end,
get = function(info)
return BistooltipAddon.db.char.tooltip_with_ctrl
end
},
data_source = {
name = "Data source",
order = 3,
desc = "Changes bis data source",
type = "select",
style = "dropdown",
width = "double",
values = Bistooltip_source_to_url,
set = function(info, key, val)
BistooltipAddon.db.char.data_source = key
BistooltipAddon:changeSpec(key)
end,
get = function(info, key)
return BistooltipAddon.db.char.data_source
end
},
filter_specs = {
name = "Hide specs",
order = 4,
desc = "Removes unselected specs from item tooltips",
type = "multiselect",
values = {}, -- Initialize as an empty table
set = function(info, key, val)
local ci, si = strsplit(":", key)
ci = tonumber(ci)
si = tonumber(si)
local class_name = Bistooltip_classes[ci].name
local spec_name = Bistooltip_classes[ci].specs[si]
BistooltipAddon.db.char.filter_specs[class_name][spec_name] = val
end,
get = function(info, key)
local ci, si = strsplit(":", key)
ci = tonumber(ci)
si = tonumber(si)
local class_name = Bistooltip_classes[ci].name
local spec_name = Bistooltip_classes[ci].specs[si]
if not BistooltipAddon.db.char.filter_specs[class_name] then
BistooltipAddon.db.char.filter_specs[class_name] = {}
end
if BistooltipAddon.db.char.filter_specs[class_name][spec_name] == nil then
BistooltipAddon.db.char.filter_specs[class_name][spec_name] = true
end
return BistooltipAddon.db.char.filter_specs[class_name][spec_name]
end
},
highlight_spec = {
name = "Highlight spec",
order = 5,
desc = "Highlights selected spec in item tooltips",
type = "multiselect",
values = {}, -- Initialize as an empty table
set = function(info, key, val)
if val then
local ci, si = strsplit(":", key)
ci = tonumber(ci)
si = tonumber(si)
local class_name = Bistooltip_classes[ci].name
local spec_name = Bistooltip_classes[ci].specs[si]
BistooltipAddon.db.char.highlight_spec = {
key = key,
class_name = class_name,
spec_name = spec_name
}
else
BistooltipAddon.db.char.highlight_spec = {}
end
end,
get = function(info, key)
return BistooltipAddon.db.char.highlight_spec.key == key
end
}
}
}
local function buildFilterSpecOptions()
local filter_specs_options = {}
for ci, class in ipairs(Bistooltip_classes) do
for si, spec in ipairs(class.specs) do
local option_val = "|T" .. Bistooltip_spec_icons[class.name][spec] .. ":16|t " .. class.name .. " " .. spec
local option_key = ci .. ":" .. si
filter_specs_options[option_key] = option_val
end
end
configTable.args.filter_specs.values = filter_specs_options
configTable.args.highlight_spec.values = filter_specs_options
end
local function openSourceSelectDialog()
local frame = AceGUI:Create("Window")
frame:SetWidth(300)
frame:SetHeight(150)
frame:EnableResize(false)
frame:SetCallback("OnClose", function(widget)
AceGUI:Release(widget)
frame = nil
end)
frame:SetLayout("List")
frame:SetTitle(BistooltipAddon.AddonNameAndVersion)
local labelEmpty = AceGUI:Create("Label")
labelEmpty:SetFont("Fonts\\FRIZQT__.TTF", 14, "")
labelEmpty:SetText(" ")
frame:AddChild(labelEmpty)
local label = AceGUI:Create("Label")
label:SetText("Please select a bis data source to be used for this addon:")
label:SetFont("Fonts\\FRIZQT__.TTF", 14, "")
label:SetRelativeWidth(1)
frame:AddChild(label)
local labelEmpty2 = AceGUI:Create("Label")
labelEmpty2:SetFont("Fonts\\FRIZQT__.TTF", 14, "")
labelEmpty2:SetText(" ")
frame:AddChild(labelEmpty2)
local sourceDropdown = AceGUI:Create("Dropdown")
sourceDropdown:SetCallback("OnValueChanged", function(_, _, key)
BistooltipAddon.db.char.data_source = key
BistooltipAddon:changeSpec(key)
end)
sourceDropdown:SetRelativeWidth(1)
sourceDropdown:SetList(Bistooltip_source_to_url)
sourceDropdown:SetValue(BistooltipAddon.db.char["data_source"])
frame:AddChild(sourceDropdown)
end
local function migrateAddonDB()
if not BistooltipAddon.db.char.version then
BistooltipAddon.db.char.version = 6.1
BistooltipAddon.db.char.highlight_spec = {}
BistooltipAddon.db.char.filter_specs = {}
BistooltipAddon.db.char.class_index = 1
BistooltipAddon.db.char.spec_index = 1
BistooltipAddon.db.char.phase_index = 1
end
-- Set default data source to wowtbc if not already set
if BistooltipAddon.db.char.data_source == nil then
BistooltipAddon.db.char.data_source = "wowtbc"
end
if BistooltipAddon.db.char.version == 6.1 then
BistooltipAddon.db.char.version = 6.2
if BistooltipAddon.db.char.filter_specs["Death knight"] and
BistooltipAddon.db.char.filter_specs["Death knight"]["Blood dps"] == nil then
BistooltipAddon.db.char.filter_specs["Death knight"]["Blood dps"] = true
end
end
end
local config_shown = false
function BistooltipAddon:openConfigDialog()
if config_shown then
InterfaceOptionsFrame_Show()
else
InterfaceOptionsFrame_OpenToCategory(BistooltipAddon.AceAddonName)
end
config_shown = not config_shown
end
local function enableSpec(spec_name)
if spec_name == sources.wowtbc then
Bistooltip_bislists = Bistooltip_wowtbc_bislists
Bistooltip_items = Bistooltip_wowtbc_items
Bistooltip_classes = Bistooltip_wowtbc_classes
Bistooltip_phases = Bistooltip_wowtbc_phases
else
-- Handle unexpected spec_name
return
end
-- Check if Bistooltip_phases is nil or not a table
if type(Bistooltip_phases) ~= "table" then
-- Handle the error or unexpected state
return
end
Bistooltip_phases_string = ""
for i, phase in ipairs(Bistooltip_phases) do
if i ~= 1 then
Bistooltip_phases_string = Bistooltip_phases_string .. "/"
end
Bistooltip_phases_string = Bistooltip_phases_string .. phase
end
buildFilterSpecOptions()
end
function BistooltipAddon:addMapIcon()
if BistooltipAddon.db.char.minimap_icon then
icon_loaded = true
local LDB = LibStub("LibDataBroker-1.1", true)
local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true)
if LDB then
local PC_MinimapBtn = LDB:NewDataObject(icon_name, {
type = "launcher",
text = icon_name,
icon = "interface/icons/inv_weapon_glave_01.blp",
OnClick = function(_, button)
if button == "LeftButton" then
BistooltipAddon:createMainFrame()
end
if button == "RightButton" then
BistooltipAddon:openConfigDialog()
end
end,
OnTooltipShow = function(tt)
tt:AddLine(BistooltipAddon.AddonNameAndVersion)
tt:AddLine("|cffffff00Left click|r to open the BiS lists window")
tt:AddLine("|cffffff00Right click|r to open addon configuration window")
end
})
if LDBIcon then
LDBIcon:Register(icon_name, PC_MinimapBtn, BistooltipAddon.db.char)
end
end
end
end
function BistooltipAddon:changeSpec(spec_name)
BistooltipAddon.db.char.class_index = 1
BistooltipAddon.db.char.spec_index = 1
BistooltipAddon.db.char.phase_index = 1
enableSpec(spec_name)
BistooltipAddon:initBislists()
BistooltipAddon:reloadData()
end
function BistooltipAddon:initConfig()
BistooltipAddon.db = LibStub("AceDB-3.0"):New("BisTooltipDB", db_defaults, "Default")
migrateAddonDB()
enableSpec(BistooltipAddon.db.char.data_source)
buildFilterSpecOptions() -- Ensure this function is called to populate values
LibStub("AceConfig-3.0"):RegisterOptionsTable(BistooltipAddon.AceAddonName, configTable)
AceConfigDialog:AddToBlizOptions(BistooltipAddon.AceAddonName, BistooltipAddon.AceAddonName)
end