-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVendorPriceScan_UI.lua
More file actions
677 lines (578 loc) · 24 KB
/
Copy pathVendorPriceScan_UI.lua
File metadata and controls
677 lines (578 loc) · 24 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
-- Create the library table
if not VendorPriceScan_UI then
VendorPriceScan_UI = {}
end
local lib = VendorPriceScan_UI
-- Local reference to constants
local colors = VendorPriceScan.COLORS
local colorsRGB = VendorPriceScan.COLORS_RGB
local strings = VendorPriceScan.STRINGS
local rarityTypes = VendorPriceScan.RARITY_TYPES
local rarityNames = VendorPriceScan.RARITY_NAMES
local sortTypes = VendorPriceScan.SORT_TYPES
local sortNames = VendorPriceScan.SORT_NAMES
local rowColors = VendorPriceScan.ROW_COLORS
local uiConstants = VendorPriceScan.UI_CONSTANTS
-- Helper function to convert hex color to RGB (0-1 range for SetTextColor)
local function HexToRGB(hexColor)
local r = tonumber(string.sub(hexColor, 3, 4), 16) / 255
local g = tonumber(string.sub(hexColor, 5, 6), 16) / 255
local b = tonumber(string.sub(hexColor, 7, 8), 16) / 255
return r, g, b
end
-- Helper function to count items in a table
local function CountItems(data)
local count = 0
for _ in pairs(data) do
count = count + 1
end
return count
end
-- Helper function to breakdown money into gold, silver, copper
local function BreakdownMoney(price)
local gold = floor(price / 10000)
local silver = floor((price - (gold * 10000)) / 100)
local copper = price - (gold * 10000) - (silver * 100)
return gold, silver, copper
end
-- Helper function to extract itemID from itemLink (compatible with Lua 5.0)
function lib.ExtractItemID(itemLink)
if not itemLink then return nil end
-- Find "item:" in the string
local _, _, itemID = string.find(itemLink, "item:(%d+)")
if itemID then
return tonumber(itemID)
end
return nil
end
-- Helper function to find itemLink by name in bags
function lib.FindItemLinkByName(itemName)
if not itemName then return nil end
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) or 0 do
local link = GetContainerItemLink(bag, slot)
if link and string.find(link, itemName) then
return link
end
end
end
return nil
end
-- Helper function to format money
function lib.FormatMoney(price)
local gold, silver, copper = BreakdownMoney(price)
local priceString = ""
if gold > 0 then
priceString = gold .. "|c" .. colors.GOLD .. "g|r"
if silver > 0 or copper > 0 then
priceString = priceString .. " "
end
end
if silver > 0 then
priceString = priceString .. silver .. "|c" .. colors.SILVER .. "s|r"
if copper > 0 then
priceString = priceString .. " "
end
end
if copper > 0 or (gold == 0 and silver == 0) then
priceString = priceString .. copper .. "|c" .. colors.COPPER .. "c|r"
end
return priceString
end
-- Helper function to format money with custom color (for dimmed/greyed out prices)
function lib.FormatMoneyColor(price, numberColor)
local gold, silver, copper = BreakdownMoney(price)
local priceString = ""
if gold > 0 then
priceString = "|c" .. numberColor .. gold .. "|r|c" .. colors.GOLD_DIM .. "g|r"
if silver > 0 or copper > 0 then
priceString = priceString .. " "
end
end
if silver > 0 then
priceString = priceString .. "|c" .. numberColor .. silver .. "|r|c" .. colors.SILVER_DIM .. "s|r"
if copper > 0 then
priceString = priceString .. " "
end
end
if copper > 0 or (gold == 0 and silver == 0) then
priceString = priceString .. "|c" .. numberColor .. copper .. "|r|c" .. colors.COPPER_DIM .. "c|r"
end
return priceString
end
-- Helper function to check if item matches search
local function ItemMatchesSearch(itemName, itemID, searchText)
if searchText == "" then
return true
end
-- Search by ID
if string.find(tostring(itemID), searchText) then
return true
end
-- Search by name (case insensitive)
if itemName and string.find(string.lower(itemName), searchText) then
return true
end
return false
end
-- Create item frame (reusable)
local function CreateItemFrame(parent, config)
local itemFrame = CreateFrame("Frame", nil, parent)
itemFrame:SetWidth(parent:GetWidth())
itemFrame:SetHeight(uiConstants.ITEM_HEIGHT)
-- Background texture
itemFrame.bgTexture = itemFrame:CreateTexture(nil, "BACKGROUND")
itemFrame.bgTexture:SetAllPoints(itemFrame)
-- Item text
itemFrame.itemText = itemFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
itemFrame.itemText:SetPoint("LEFT", itemFrame, "LEFT", 0, 0)
itemFrame.itemText:SetWidth(config.itemTextWidth or 520)
itemFrame.itemText:SetJustifyH("LEFT")
-- Cache text (for "not in cache")
itemFrame.cacheText = itemFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
itemFrame.cacheText:SetPoint("LEFT", itemFrame.itemText, "LEFT", 0, 0)
itemFrame.cacheText:SetTextColor(colorsRGB.NOT_IN_CACHE[1], colorsRGB.NOT_IN_CACHE[2], colorsRGB.NOT_IN_CACHE[3])
-- Price text
itemFrame.priceText = itemFrame:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
itemFrame.priceText:SetPoint("RIGHT", itemFrame, "RIGHT", 0, 0)
if config.priceTextWidth then
itemFrame.priceText:SetWidth(config.priceTextWidth)
itemFrame.priceText:SetJustifyH("RIGHT")
end
-- Tooltip functionality
itemFrame:EnableMouse(true)
itemFrame:SetScript("OnEnter", function()
if this.itemLink then
GameTooltip:SetOwner(this, "ANCHOR_CURSOR")
GameTooltip:SetHyperlink(this.itemLink)
if config.onTooltip and this.itemData then
GameTooltip:AddLine(" ", 1, 1, 1)
config.onTooltip(GameTooltip, this.itemData)
end
GameTooltip:Show()
end
end)
itemFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
return itemFrame
end
-- Update item frame with data
local function UpdateItemFrame(itemFrame, item, visualIndex, config)
itemFrame:SetPoint("TOPLEFT", itemFrame:GetParent(), "TOPLEFT", 0, uiConstants.VERTICAL_OFFSET - ((visualIndex - 1) * uiConstants.ITEM_HEIGHT))
itemFrame:Show()
-- Update background
if mod(item.originalIndex, 2) == 0 then
itemFrame.bgTexture:SetTexture(rowColors.EVEN[1], rowColors.EVEN[2], rowColors.EVEN[3], rowColors.EVEN[4])
else
itemFrame.bgTexture:SetTexture(rowColors.ODD[1], rowColors.ODD[2], rowColors.ODD[3], rowColors.ODD[4])
end
-- Update item text
local r, g, b, hex = GetItemQualityColor(item.rarity)
itemFrame.itemText:SetTextColor(r, g, b)
local displayText = item.name .. strings.ID_PREFIX .. item.id .. strings.ID_SUFFIX
itemFrame.itemText:SetText(displayText)
-- Update cache text
if item.notInCache then
itemFrame.cacheText:SetPoint("LEFT", itemFrame.itemText, "LEFT", itemFrame.itemText:GetStringWidth(), 0)
itemFrame.cacheText:SetText(strings.NOT_IN_CACHE)
itemFrame.cacheText:Show()
else
itemFrame.cacheText:Hide()
end
-- Update price
itemFrame.priceText:SetText(config.formatPrice(item.data))
-- Store data for tooltip
itemFrame.itemLink = item.link
itemFrame.itemData = item.data
end
-- Update visible frames based on scroll position
local function UpdateVisibleFrames(window)
if not window.filteredItems then return end
local scrollOffset = window.scrollFrame:GetVerticalScroll()
local scrollHeight = window.scrollFrame:GetHeight()
-- Calculate visible range with buffer
local firstVisible = math.max(1, math.floor(scrollOffset / uiConstants.ITEM_HEIGHT))
local lastVisible = math.min(table.getn(window.filteredItems), math.ceil((scrollOffset + scrollHeight) / uiConstants.ITEM_HEIGHT) + 1)
-- Hide all frames first
for _, frame in ipairs(window.itemFramePool) do
frame:Hide()
end
-- Show and update only visible frames
local visibleIndex = 1
for i = firstVisible, lastVisible do
local item = window.filteredItems[i]
if item then
local frame = window.itemFramePool[visibleIndex]
if not frame then
frame = CreateItemFrame(window.content, window.config)
window.itemFramePool[visibleIndex] = frame
end
item.originalIndex = i
UpdateItemFrame(frame, item, i, window.config)
visibleIndex = visibleIndex + 1
end
end
end
-- Create and show the database window
function lib.ShowWindow(config)
local windowName = config.windowName
local existingWindow = _G[windowName]
if existingWindow then
if existingWindow:IsShown() then
existingWindow:Hide()
else
existingWindow:Show()
lib.RefreshWindow(windowName, config)
end
return
end
-- Window dimensions
local windowWidth = config.width or 750
local windowHeight = config.height or 600
-- Create main frame
local window = CreateFrame("Frame", windowName, UIParent)
window:SetWidth(windowWidth)
window:SetHeight(windowHeight)
window:SetPoint("CENTER", UIParent, "CENTER", 0, 50)
window:SetBackdrop({
bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/DialogFrame/UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
window:SetMovable(true)
window:EnableMouse(true)
window:RegisterForDrag("LeftButton")
window:SetScript("OnDragStart", function() this:StartMoving() end)
window:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
-- Store config in window for later use
window.config = config
window.currentSort = config.defaultSort or "id"
window.sortAscending = true
window.currentRarityFilter = -1
window.searchText = ""
window.itemFramePool = {}
-- Title
local title = window:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", window, "TOP", 0, -15)
title:SetText(config.title)
-- Close button
local closeBtn = CreateFrame("Button", nil, window, "UIPanelCloseButton")
closeBtn:SetPoint("TOPRIGHT", window, "TOPRIGHT", -5, -5)
-- Show tooltip title checkbox (declare first, before tooltipCheckbox)
local tooltipTitleCheckbox = CreateFrame("CheckButton", windowName .. "_TooltipTitleCheckbox", window, "UICheckButtonTemplate")
tooltipTitleCheckbox:SetWidth(24)
tooltipTitleCheckbox:SetHeight(24)
-- Declare label variables
local checkboxLabel
local checkboxTitleLabel
-- Function to update tooltip title checkbox state
local function UpdateTooltipTitleCheckbox()
if VendorPriceScan_CharData.showTooltips then
tooltipTitleCheckbox:Enable()
if checkboxLabel then
local r, g, b = checkboxLabel:GetTextColor()
checkboxTitleLabel:SetTextColor(r, g, b)
end
else
tooltipTitleCheckbox:Disable()
tooltipTitleCheckbox:SetChecked(false)
VendorPriceScan_CharData.showTooltipTitle = false
checkboxTitleLabel:SetTextColor(0.5, 0.5, 0.5)
end
end
-- Show tooltips checkbox
local tooltipCheckbox = CreateFrame("CheckButton", windowName .. "_TooltipCheckbox", window, "UICheckButtonTemplate")
tooltipCheckbox:SetWidth(24)
tooltipCheckbox:SetHeight(24)
tooltipCheckbox:SetPoint("TOPRIGHT", window, "TOPRIGHT", -35, -8)
tooltipCheckbox:SetChecked(VendorPriceScan_CharData.showTooltips)
tooltipCheckbox:SetScript("OnClick", function()
VendorPriceScan_CharData.showTooltips = this:GetChecked() == 1
UpdateTooltipTitleCheckbox()
end)
tooltipCheckbox:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPRIGHT", this, "BOTTOMRIGHT", 0, -5)
GameTooltip:SetText(strings.SHOW_TOOLTIPS, 1, 1, 1)
GameTooltip:AddLine(strings.TOOLTIP_CHECKBOX_DESC, 0.9, 0.9, 0.9, 1)
GameTooltip:Show()
end)
tooltipCheckbox:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Checkbox label
checkboxLabel = window:CreateFontString(nil, "OVERLAY", "GameFontNormal")
checkboxLabel:SetPoint("RIGHT", tooltipCheckbox, "LEFT", -5, 0)
checkboxLabel:SetText(strings.SHOW_TOOLTIPS)
-- Position tooltip title checkbox
tooltipTitleCheckbox:SetPoint("TOPRIGHT", tooltipCheckbox, "BOTTOMRIGHT", 0, -5)
tooltipTitleCheckbox:SetChecked(VendorPriceScan_CharData.showTooltipTitle)
tooltipTitleCheckbox:SetScript("OnClick", function()
VendorPriceScan_CharData.showTooltipTitle = this:GetChecked() == 1
end)
tooltipTitleCheckbox:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPRIGHT", this, "BOTTOMRIGHT", 0, -5)
GameTooltip:SetText(strings.SHOW_TOOLTIP_TITLE, 1, 1, 1)
GameTooltip:AddLine(strings.TOOLTIP_TITLE_CHECKBOX_DESC, 0.9, 0.9, 0.9, 1)
GameTooltip:Show()
end)
tooltipTitleCheckbox:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Checkbox label for tooltip title (declare after checkbox is created)
checkboxTitleLabel = window:CreateFontString(nil, "OVERLAY", "GameFontNormal")
checkboxTitleLabel:SetPoint("RIGHT", tooltipTitleCheckbox, "LEFT", -5, 0)
checkboxTitleLabel:SetText(strings.SHOW_TOOLTIP_TITLE)
-- Initialize the state of tooltip title checkbox
UpdateTooltipTitleCheckbox()
-- Search box label
local searchLabel = window:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
searchLabel:SetPoint("TOPLEFT", window, "TOPLEFT", 20, -50)
searchLabel:SetText(strings.SEARCH)
searchLabel:SetTextColor(colorsRGB.LABEL[1], colorsRGB.LABEL[2], colorsRGB.LABEL[3])
-- Search box
local searchBox = CreateFrame("EditBox", windowName .. "_SearchBox", window, "InputBoxTemplate")
searchBox:SetWidth(150)
searchBox:SetHeight(20)
searchBox:SetPoint("TOPLEFT", searchLabel, "TOPRIGHT", 10, 3)
searchBox:SetAutoFocus(false)
searchBox:SetScript("OnTextChanged", function()
window.searchText = string.lower(this:GetText())
lib.RefreshWindow(windowName, config)
end)
searchBox:SetScript("OnEscapePressed", function()
this:ClearFocus()
end)
searchBox:SetScript("OnEnterPressed", function()
this:ClearFocus()
end)
-- Clear search button
local clearBtn = CreateFrame("Button", nil, window, "UIPanelButtonTemplate")
clearBtn:SetWidth(50)
clearBtn:SetHeight(20)
clearBtn:SetPoint("LEFT", searchBox, "RIGHT", 5, 0)
clearBtn:SetText(strings.CLEAR)
clearBtn:SetScript("OnClick", function()
searchBox:SetText("")
window.searchText = ""
lib.RefreshWindow(windowName, config)
end)
-- Sort by label
local sortLabel = window:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
sortLabel:SetPoint("TOPLEFT", window, "TOPLEFT", 20, -80)
sortLabel:SetText(strings.SORT_BY)
sortLabel:SetTextColor(colorsRGB.LABEL[1], colorsRGB.LABEL[2], colorsRGB.LABEL[3])
-- Sort buttons
local sortButtons = {}
for i, sortType in ipairs(sortTypes) do
local btn = CreateFrame("Button", nil, window, "UIPanelButtonTemplate")
btn:SetWidth(60)
btn:SetHeight(20)
if i == 1 then
btn:SetPoint("LEFT", sortLabel, "RIGHT", 5, 0)
else
btn:SetPoint("LEFT", sortButtons[i-1], "RIGHT", 5, 0)
end
btn:SetText(sortType.label)
btn.sortKey = sortType.key
btn:SetScript("OnClick", function()
if window.currentSort == this.sortKey then
window.sortAscending = not window.sortAscending
else
window.currentSort = this.sortKey
window.sortAscending = true
end
lib.RefreshWindow(windowName, config)
end)
sortButtons[i] = btn
end
-- Rarity filter label
local rarityLabel = window:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
rarityLabel:SetPoint("TOPLEFT", window, "TOPLEFT", 20, -110)
rarityLabel:SetText(strings.RARITY)
rarityLabel:SetTextColor(colorsRGB.LABEL[1], colorsRGB.LABEL[2], colorsRGB.LABEL[3])
-- Rarity filter buttons
local rarityButtons = {}
for i, rarityType in ipairs(rarityTypes) do
local btn = CreateFrame("Button", nil, window, "UIPanelButtonTemplate")
btn:SetWidth(80)
btn:SetHeight(20)
if i == 1 then
btn:SetPoint("LEFT", rarityLabel, "RIGHT", 5, 0)
else
btn:SetPoint("LEFT", rarityButtons[i-1], "RIGHT", 3, 0)
end
btn:SetText(rarityType.label)
btn.rarityKey = rarityType.key
-- Color the button text
local btnText = btn:GetFontString()
btnText:SetTextColor(rarityType.color[1], rarityType.color[2], rarityType.color[3])
btn:SetScript("OnClick", function()
window.currentRarityFilter = this.rarityKey
lib.RefreshWindow(windowName, config)
end)
rarityButtons[i] = btn
end
-- Item count text
window.countText = window:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
window.countText:SetPoint("TOP", window, "TOP", 0, -145)
window.countText:SetText(strings.ITEMS .. ": 0")
window.countText:SetTextColor(1, 1, 1)
-- Scroll frame
local scrollFrame = CreateFrame("ScrollFrame", windowName .. "_ScrollFrame", window, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", window, "TOPLEFT", 20, -165)
scrollFrame:SetPoint("BOTTOMRIGHT", window, "BOTTOMRIGHT", -30, 15)
-- Content frame
local content = CreateFrame("Frame", windowName .. "_ContentFrame", scrollFrame)
content:SetWidth(windowWidth - 50)
content:SetHeight(1)
scrollFrame:SetScrollChild(content)
-- Add scroll event handler
scrollFrame:SetScript("OnVerticalScroll", function()
UpdateVisibleFrames(window)
end)
window.content = content
window.scrollFrame = scrollFrame
window:Show()
lib.RefreshWindow(windowName, config)
end
-- Refresh the window content
function lib.RefreshWindow(windowName, config)
local window = _G[windowName]
if not window then return end
-- Update config if provided
if config then
window.config = config
else
config = window.config
end
-- Reset scroll to top
if window.scrollFrame then
window.scrollFrame:SetVerticalScroll(0)
end
-- Collect and filter items
local items = {}
if config.data then
for itemID, rawData in pairs(config.data) do
local itemName, itemLink, itemRarity = GetItemInfo(itemID)
local notInCache = false
local itemData = config.getItemData(itemID, rawData)
if not itemName then
notInCache = true
if itemData.itemName then
itemName = itemData.itemName
else
itemName = "Item #" .. itemID
end
end
if window.currentRarityFilter == -1 or (itemRarity and itemRarity == window.currentRarityFilter) then
if ItemMatchesSearch(itemName, itemID, window.searchText) then
table.insert(items, {
id = itemID,
name = itemName,
link = itemLink,
rarity = itemRarity or 1,
notInCache = notInCache,
data = itemData
})
end
end
end
end
-- Sort items
if window.currentSort == "id" then
if window.sortAscending then
table.sort(items, function(a, b) return a.id < b.id end)
else
table.sort(items, function(a, b) return a.id > b.id end)
end
elseif window.currentSort == "name" then
if window.sortAscending then
table.sort(items, function(a, b) return a.name < b.name end)
else
table.sort(items, function(a, b) return a.name > b.name end)
end
elseif window.currentSort == "price" then
if window.sortAscending then
table.sort(items, function(a, b) return config.sortByPrice(a.data, b.data) end)
else
table.sort(items, function(a, b) return config.sortByPrice(b.data, a.data) end)
end
elseif window.currentSort == "rarity" then
if window.sortAscending then
table.sort(items, function(a, b)
if a.rarity == b.rarity then
return a.name < b.name
end
return a.rarity < b.rarity
end)
else
table.sort(items, function(a, b)
if a.rarity == b.rarity then
return a.name < b.name
end
return a.rarity > b.rarity
end)
end
end
-- Store filtered items in window
window.filteredItems = items
-- Update count text
local totalCount = CountItems(config.data or {})
local filterInfo = ""
local sortDirection = window.sortAscending and strings.ASCENDING or strings.DESCENDING
filterInfo = " (" .. strings.SORTED_BY .. " " .. sortNames[window.currentSort] .. " " .. sortDirection .. ")"
if window.currentRarityFilter ~= -1 then
filterInfo = filterInfo .. " (" .. strings.FILTERED_BY .. " " .. rarityNames[window.currentRarityFilter + 1] .. ")"
end
if window.searchText ~= "" then
filterInfo = filterInfo .. " (" .. strings.SEARCH_FILTER .. " '" .. window.searchText .. "')"
end
window.countText:SetText(strings.SHOWING .. " " .. table.getn(items) .. " " .. strings.OF .. " " .. totalCount .. " " .. strings.ITEMS .. filterInfo)
-- Update content height
local numItems = table.getn(items)
local contentHeight = math.max(1, numItems * uiConstants.ITEM_HEIGHT + uiConstants.CONTENT_HEIGHT_PADDING)
window.content:SetHeight(contentHeight)
-- Update visible frames
UpdateVisibleFrames(window)
-- Update scroll
local scrollHeight = window.scrollFrame:GetHeight()
if contentHeight <= scrollHeight then
window.scrollFrame:SetVerticalScroll(0)
end
window.scrollFrame:UpdateScrollChildRect()
end
-- Utility function to add vendor price to tooltip
function lib.AddVendorPriceToTooltip(tooltip, itemLink, quantity, dataTable)
if not itemLink or not dataTable then return end
local itemID = lib.ExtractItemID(itemLink)
if itemID and dataTable[itemID] then
local itemData = dataTable[itemID]
local pricePerItem = itemData.vendorPrice or 0
-- Don't show tooltip if price is 0
if pricePerItem == 0 then return end
tooltip:AddLine(" ", 1, 1, 1)
if quantity and quantity > 1 then
local totalPrice = pricePerItem * quantity
-- Only add title if showTooltipTitle is true
if VendorPriceScan_CharData.showTooltipTitle then
tooltip:AddLine(strings.VENDOR_PRICE, 1, 1, 1)
end
local eachText = ""
if pricePerItem ~= totalPrice then
eachText = " |c" .. colors.NUMBER_DIM .. "(|r" .. lib.FormatMoneyColor(pricePerItem, colors.NUMBER_DIM) .. " |c" .. colors.NUMBER_DIM .. strings.EACH .. ")|r"
end
tooltip:AddLine(lib.FormatMoney(totalPrice) .. eachText, 1, 1, 1)
else
-- Only add title if showTooltipTitle is true
if VendorPriceScan_CharData.showTooltipTitle then
tooltip:AddLine(strings.VENDOR_PRICE, 1, 1, 1)
end
tooltip:AddLine(lib.FormatMoney(pricePerItem), 1, 1, 1)
end
tooltip:Show()
end
end