-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBattlePetCount.lua
337 lines (303 loc) · 10 KB
/
BattlePetCount.lua
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
local addon_name, addon = ...
LibStub("AceAddon-3.0"):NewAddon(addon, addon_name)
local LPJ = LibStub("LibPetJournal-2.0")
local L = LibStub("AceLocale-3.0"):GetLocale("BattlePetCount")
local GREEN_FONT_COLOR_CODE = "|cff30d030"
local RED_FONT_COLOR_CODE = "|cffff3030"
--
--
--
local defaults = {
profile = {
enableCageTip = true,
enableBattleTip = true,
enableMinimapTip = true,
enableCreatureTip = true,
enableItemTip = true,
itemTipIncludesAll = true,
enableBattleIndicator = true,
enableBattleBorderIcon = true,
preferNamesOverQuality = false,
enablePetCard = true,
useOlderText = false,
useSubTip = false,
showBreedID = true,
showBreedIDShort = false
}
}
local options = {
name = addon_name,
handler = addon,
type = 'group',
get = function(info) return addon.db.profile[info[#info]] end,
set = function(info,v) addon.db.profile[info[#info]] = v end,
args = {
sectionBattle = {
type = 'group',
name = L["OPT_HEADER_BATTLE"],
order = 10,
inline = true,
args = {
enableBattleTip = {
type = "toggle",
name = L["OPT_BATTLE_TIP"],
width = "double",
order = 1,
},
enableBattleIndicator = {
type = "toggle",
name = L["OPT_BATTLE_HINT_BOX"],
width = "double",
order = 2,
},
resetBattleIndicator = {
type = "execute",
name = L["OPT_BATTLE_HINT_RESET"],
disabled = function() return not addon.db.profile.enableBattleIndicator end,
func = function() addon:GetModule("Indicators"):ResetIndicatorPosition() end,
order = 3
},
enableBattleBorderIcon = {
type = "toggle",
name = L["OPT_BATTLE_BORDER_ICON"],
width = "double",
order = 4,
}
}
},
sectionWorld = {
type = 'group',
name = L["OPT_HEADER_WORLD"],
order = 20,
inline = true,
args = {
enableCreatureTip = {
type = "toggle",
name = L["OPT_CREATURE_TIP"],
width = "double",
order = 1,
},
enableMinimapTip = {
type = "toggle",
name = L["OPT_MINIMAP_TIP"],
width = "double",
order = 2
},
}
},
sectionItem = {
type = 'group',
name = L["OPT_HEADER_ITEMS"],
order = 30,
inline = true,
args = {
enableCageTip = {
type = "toggle",
name = L["OPT_CAGE_TIP"],
width = "double",
order = 1,
},
enableItemTip = {
type = "toggle",
name = L["OPT_ITEM_TIP"],
width = "double",
order = 10,
},
itemTipIncludesAll = {
type = "toggle",
name = L["OPT_ITEM_TIP_ALL"],
width = "double",
order = 11,
},
}
},
sectionOther = {
type = 'group',
name = L["OPT_HEADER_OTHER"],
order = 50,
inline = true,
args = {
preferNamesOverQuality = {
type = "toggle",
name = L["OPT_PREFER_NAMES_OVER_QUALITY"],
width = "double",
order = 1
},
enablePetCard = {
type = "toggle",
name = L["OPT_PET_CARD"],
width = "double",
order = 2
},
useOlderText = {
type = "toggle",
name = L["OPT_USE_OLDER_TEXT"],
width = "double",
order = 3,
},
multilineTooltip = {
type = "toggle",
name = L["OPT_MULTILINE_TOOLTIP"],
width = "double",
order = 4,
},
useSubTip = {
type = "toggle",
name = L["OPT_USE_SUB_TIP"],
width = "double",
order = 4,
},
showBreedID = {
type = "toggle",
name = L["OPT_USE_BREEDID_ADDON"],
width = "double",
order = 5,
disabled = function() return not GetBreedID_Journal end,
get = function(info) return addon.db.profile[info[#info]] and GetBreedID_Journal end,
}
}
}
}
}
--
--
--
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("BattlePetCountDB", defaults, true)
self.options = options
LibStub("AceConfig-3.0"):RegisterOptionsTable(self.name, options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.name, self.name, nil)
end
--
--
--
function addon:CanObtainSpecies(speciesID)
local _, _, _, _, _, _, _, _, _, _, obtainable = C_PetJournal.GetPetInfoBySpeciesID(speciesID)
return obtainable
end
function addon:GetPetName(petID)
local _, customName, _, _, _, _, _, petName = C_PetJournal.GetPetInfoByPetID(petID)
return customName or petName
end
function addon:_breedID(petID, toggle)
if toggle == nil then
-- default
toggle = self.db.profile.showBreedID
end
if toggle and GetBreedID_Journal then
return " "..tostring(GetBreedID_Journal(petID))
end
return ""
end
do
local tmp = {}
function addon:OwnedList(speciesID)
wipe(tmp)
local linePrefix = ""
if self.db.profile.multilineTooltip then
linePrefix = "\n - "
end
for _,petID in LPJ:IteratePetIDs() do
if C_PetJournal.GetPetInfoByPetID(petID) == speciesID then
local _, _, level = C_PetJournal.GetPetInfoByPetID(petID)
local _, _, _, _, quality = C_PetJournal.GetPetStats(petID)
local name
if self.db.profile.preferNamesOverQuality then
name = self:GetPetName(petID)
else
name = _G["ITEM_QUALITY"..(quality-1).."_DESC"] or UNKNOWN
end
tinsert(tmp, format("%s|cff%02x%02x%02x%s|r (L%d%s)",
linePrefix,
ITEM_QUALITY_COLORS[quality-1].r*255,
ITEM_QUALITY_COLORS[quality-1].g*255,
ITEM_QUALITY_COLORS[quality-1].b*255,
name, tostring(level), self:_breedID(petID)))
end
end
if #tmp > 0 then
return table.concat(tmp, ", ")
end
end
end
do
local tmp = {}
function addon:ShortOwnedListOnly(speciesID, skipPetID)
local sep = "/"
if self.db.profile.showBreedIDShort and GetBreedID_Journal then
sep = ","
end
wipe(tmp)
for _,petID in LPJ:IteratePetIDs() do
if C_PetJournal.GetPetInfoByPetID(petID) == speciesID and skipPetID ~= petID then
local _, _, level = C_PetJournal.GetPetInfoByPetID(petID)
local _, _, _, _, quality = C_PetJournal.GetPetStats(petID)
tinsert(tmp, format("|cff%02x%02x%02xL%d%s|r",
ITEM_QUALITY_COLORS[quality-1].r*255,
ITEM_QUALITY_COLORS[quality-1].g*255,
ITEM_QUALITY_COLORS[quality-1].b*255,
level, self:_breedID(petID, self.db.profile.showBreedIDShort)))
end
end
if #tmp > 0 then
return table.concat(tmp, sep)
end
end
end
function addon:ShortOwnedList(speciesID)
local text = self:ShortOwnedListOnly(speciesID)
if text then
return format("%s: %s", L["OWNED"], text)
else
return format("|cffee3333%s|r", L["UNOWNED"])
end
end
function addon:PlayersBest(speciesID)
local maxquality = -1
local maxlevel = -1
for iv,petid in LPJ:IteratePetIDs() do
local sid, _, level = C_PetJournal.GetPetInfoByPetID(petid)
if sid == speciesID then
local _, _, _, _, quality = C_PetJournal.GetPetStats(petid)
if maxquality < quality then
maxquality = quality
end
if maxlevel < level then
maxlevel = level
end
end
end
if maxquality == -1 then
return nil
end
return maxquality, maxlevel
end
function addon:CollectedOlderText(speciesID)
local ownedlist = self:OwnedList(speciesID)
if ownedlist then
return format("%s %s", L["YOU_OWN_COLON"], ownedlist)
else
return L["YOU_DONT_OWN"]
end
end
function addon:CollectedText(speciesID)
if not addon:CanObtainSpecies(speciesID) then
return L["UNOBTAINABLE"]
end
if self.db.profile.useOlderText then
return self:CollectedOlderText(speciesID)
end
local owned, maxOwned = C_PetJournal.GetNumCollectedInfo(speciesID)
local ownedColor
if owned < maxOwned then
ownedColor = GREEN_FONT_COLOR_CODE
else
ownedColor = RED_FONT_COLOR_CODE
end
return format("%s%s%s: %s",
ownedColor,
format(ITEM_PET_KNOWN, owned, maxOwned),
FONT_COLOR_CODE_CLOSE,
self:OwnedList(speciesID) or RED_FONT_COLOR_CODE..L["UNOWNED"]
)
end