forked from evl/auctionlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuctionFrame.lua
More file actions
169 lines (140 loc) · 5.47 KB
/
AuctionFrame.lua
File metadata and controls
169 lines (140 loc) · 5.47 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
-------------------------------------------------------------------------------
-- AuctionFrame.lua
--
-- UI functions for modifying the parent auction frame.
-------------------------------------------------------------------------------
-- Index of our tab in the auction frame.
local BuyTabIndex = nil;
local SellTabIndex = nil;
-- Currently open AH tab.
local CurrentTab = nil;
-- Use this update event to do a bunch of housekeeping.
function AuctionLite:AuctionFrame_OnUpdate()
-- Continue pending auction queries.
self:QueryUpdate();
end
-- Handle tab clicks by showing or hiding our frame as appropriate.
function AuctionLite:AuctionFrameTab_OnClick_Hook(tab, arg)
local index = (tab and tab:GetID()) or arg;
CurrentTab = index;
AuctionFrameBuy:Hide();
AuctionFrameSell:Hide();
if index == BuyTabIndex then
AuctionFrameTopLeft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-TopLeft");
AuctionFrameTop:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Top");
AuctionFrameTopRight:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-TopRight");
AuctionFrameBotLeft:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotLeft");
AuctionFrameBot:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Auction-Bot");
AuctionFrameBotRight:SetTexture("Interface\\AuctionFrame\\UI-AuctionFrame-Bid-BotRight");
AuctionFrameBuy:Show();
elseif index == SellTabIndex then
AuctionFrameTopLeft:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-TopLeft");
AuctionFrameTop:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-Top");
AuctionFrameTopRight:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-TopRight");
AuctionFrameBotLeft:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-BotLeft");
AuctionFrameBot:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-Bot");
AuctionFrameBotRight:SetTexture("Interface\\AddOns\\AuctionLite\\Images\\SellFrame-BotRight");
AuctionFrameSell:Show();
end
end
-- Adds our hook to the main auction frame's update handler.
function AuctionLite:HookAuctionFrameUpdate()
local frameUpdate = AuctionFrame:GetScript("OnUpdate");
AuctionFrame:SetScript("OnUpdate", function()
if frameUpdate ~= nil then
frameUpdate();
end
AuctionLite:AuctionFrame_OnUpdate();
end);
end
-- Handle modified clicks on bag spaces.
function AuctionLite:ContainerFrameItemButton_OnModifiedClick_Hook(widget, button)
if AuctionFrame:IsShown() then
local container = widget:GetParent():GetID();
local slot = widget:GetID();
if IsAltKeyDown() and button == "RightButton" then
AuctionFrameTab_OnClick(_G["AuctionFrameTab" .. SellTabIndex]);
self:BagClickSell(container, slot);
elseif IsControlKeyDown() and button == "RightButton" then
AuctionFrameTab_OnClick(_G["AuctionFrameTab" .. BuyTabIndex]);
self:BagClickBuy(container, slot);
end
end
end
-- Intercept calls to ChatEdit_InsertLink to handle shift-click in the
-- "Buy" frame. We use a raw hook so that the stack-splitting frame
-- doesn't show up.
function AuctionLite:ChatEdit_InsertLink_Hook(link)
local handled = false;
-- Is this click ours?
if AuctionFrame:IsShown() and
CurrentTab == BuyTabIndex and
link:find("item:", 1, true) then
local name = GetItemInfo(link);
if name ~= nil then
self:NameClickBuy(name);
handled = true;
end
end
-- It wasn't, so let the existing handler take it.
if not handled then
handled = self.hooks["ChatEdit_InsertLink"](link);
end
return handled;
end
-- Jump to the selected tab on opening the AH.
function AuctionLite:AUCTION_HOUSE_SHOW()
local jumpTab = nil;
if self.db.profile.startTab == "b_buy" then
jumpTab = BuyTabIndex;
elseif self.db.profile.startTab == "c_sell" then
jumpTab = SellTabIndex;
elseif self.db.profile.startTab == "d_last" then
jumpTab = self.db.profile.lastTab;
end
if jumpTab ~= nil and _G["AuctionFrameTab" .. jumpTab] ~= nil then
AuctionFrameTab_OnClick(_G["AuctionFrameTab" .. jumpTab]);
if jumpTab == BuyTabIndex and self.db.profile.startFavoriteScan then
self:ScanFirstFavoritesList()
end
end
if self.db.profile.openBags then
OpenAllBags(true);
end
end
-- Clean up if the auction house is closed.
function AuctionLite:AUCTION_HOUSE_CLOSED()
self.db.profile.lastTab = CurrentTab;
self:ClearBuyFrame();
self:ClearSellFrame();
self:ClearSavedPrices();
self:ResetAuctionCreation();
collectgarbage("collect");
end
-- Create a new tab on the auction frame. Caller provides the name of the
-- tab and the frame object to which it will be linked.
function AuctionLite:CreateTab(name, frame)
-- Find a free index.
local tabIndex = 1;
while getglobal("AuctionFrameTab" .. tabIndex) ~= nil do
tabIndex = tabIndex + 1;
end
-- Create the tab itself.
local tab = CreateFrame("Button", "AuctionFrameTab" .. tabIndex,
AuctionFrame, "AuctionTabTemplate");
tab:SetID(tabIndex);
tab:SetText(name);
tab:SetPoint("TOPLEFT", "AuctionFrameTab" .. (tabIndex - 1),
"TOPRIGHT", -8, 0);
-- Link it into the auction frame.
PanelTemplates_DeselectTab(tab);
PanelTemplates_SetNumTabs(AuctionFrame, tabIndex);
frame:SetParent(AuctionFrame);
frame:SetPoint("TOPLEFT", AuctionFrame, "TOPLEFT", 0, 0);
return tabIndex;
end
-- Add our tabs.
function AuctionLite:AddAuctionFrameTabs()
BuyTabIndex = self:CreateBuyFrame();
SellTabIndex = self:CreateSellFrame();
end