-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerchantPlusItemListLine.lua
102 lines (82 loc) · 3 KB
/
MerchantPlusItemListLine.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
--
-- Merchant Plus
-- A Modern Scrollable UI for Merchants
--
-- Copyright 2023 - 2024 SimGuy
--
-- Use of this source code is governed by an MIT-style
-- license that can be found in the LICENSE file or at
-- https://opensource.org/licenses/MIT.
--
local _, Shared = ...
-- Import a shared trace function if one exists
local trace = Shared.Trace or function() end
MerchantPlusItemListLineMixin = CreateFromMixins(TemplatedListElementMixin, TableBuilderRowMixin)
-- Upon entering a line, show the tooltip and highlight and update the cursor as appropriate
function MerchantPlusItemListLineMixin:OnLineEnter()
local data = self:GetElementData()
self.HighlightTexture:Show()
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetMerchantItem(data.index)
-- Show compare only on shift key since tooltips are so far right
if IsShiftKeyDown() then
GameTooltip_ShowCompareItem(GameTooltip)
end
if CanAffordMerchantItem(data.index) == false then
SetCursor("BUY_ERROR_CURSOR")
else
SetCursor("BUY_CURSOR")
end
end
-- Upon leaving the line, hide the tooltip, highlight, and reset the cursor
function MerchantPlusItemListLineMixin:OnLineLeave()
self.HighlightTexture:Hide()
GameTooltip:Hide()
ResetCursor()
end
-- Steps to be completed when a line is hidden
function MerchantPlusItemListLineMixin:OnHide()
if ( self.hasStackSplit == 1 ) then
StackSplitFrame:Hide()
end
end
-- Import data into the ItemListLine to emulate an ItemButton so native MerchantFrame functions
-- work on them.
function MerchantPlusItemListLineMixin:UpdateButtonData()
local data = self:GetElementData()
trace("called: UpdateButtonData", data.index)
self:SetID(data.index)
self.price = data.price > 0 and data.price or nil
self.extendedCost = data.extendedCost or nil
self.name = data.name
self.link = data.link
self.texture = data.texture
self.count = data.quantity
self.numInStock = data.numAvailable
self.hasItem = true
self.showNonrefundablePrompt = not C_MerchantFrame.IsMerchantItemRefundable(data.index)
end
-- This should handle all the work related to previewing or buying items.
function MerchantPlusItemListLineMixin:OnClick(button)
trace("clicked:", button)
self:UpdateButtonData()
-- Call the OnModifiedClick function for MerchantItemButton
if IsModifiedClick() then
MerchantItemButton_OnModifiedClick(self, button)
-- Call the OnClick function for MerchantItemButton
else
MerchantItemButton_OnClick(self, button)
end
end
-- This function is called by SplitStackFrame when submitting to
-- actually purchase the requested number of items.
function MerchantPlusItemListLineMixin:SplitStack(split)
local data = self:GetElementData()
trace("called: SplitStack", split)
self:UpdateButtonData()
if data.extendedCost or data.showNonrefundablePrompt then
MerchantFrame_ConfirmExtendedItemCost(self, split)
elseif split > 0 then
BuyMerchantItem(data.index, split)
end
end