-
Notifications
You must be signed in to change notification settings - Fork 8
/
Main.lua
163 lines (133 loc) · 4.39 KB
/
Main.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
local addonName, addonTable = ...;
---@class AuctionFaster
local AuctionFaster = LibStub('AceAddon-3.0'):NewAddon(
'AuctionFaster', 'AceConsole-3.0', 'AceEvent-3.0', 'AceHook-3.0'
);
AuctionFaster.Version = GetAddOnMetadata(addonName, 'Version');
addonTable[1] = AuctionFaster;
_G[addonName] = AuctionFaster;
--- @type StdUi
local StdUi = LibStub('StdUi');
function AuctionFaster:OnInitialize()
self:InitDatabase();
self:RegisterOptionWindow();
self:RegisterEvent('AUCTION_HOUSE_SHOW');
self:RegisterEvent('AUCTION_HOUSE_CLOSED');
if not self.db.auctionDb then
self.db.auctionDb = {};
end
if self.db.enableToolTips then
self:EnableModule('Tooltip');
end
-- These modules must be enabled on start, they handle events themselves
-- Update, this automatically enabled
--self:EnableModule('ItemCache');
--self:EnableModule('Inventory');
--self:EnableModule('Auctions');
--self:EnableModule('ConfirmBuy');
--self:EnableModule('Tutorial');
self.buyModule = self:GetModule('Buy');
self.sellModule = self:GetModule('Sell');
-- TODO: COMMENT THIS OUT
--UIParentLoadAddOn('Blizzard_DebugTools')
end
function AuctionFaster:AUCTION_HOUSE_SHOW()
if self.db.enabled then
self.buyModule:Attach();
self.sellModule:Attach();
if not self.onTabClickHooked then
self:Hook(AuctionHouseFrame, 'SetDisplayMode', 'SetDisplayModeHook', true);
self.onTabClickHooked = true;
end
if self.db.defaultTab == 'SELL' then
AuctionHouseFrame:SetDisplayMode(AuctionHouseFrameDisplayMode.AFSellMode);
elseif self.db.defaultTab == 'BUY' then
AuctionHouseFrame:SetDisplayMode(AuctionHouseFrameDisplayMode.AFBuyMode);
end
end
end
function AuctionFaster:AUCTION_HOUSE_CLOSED()
self.buyModule:Detach();
self.sellModule:Detach();
end
local function stripFrameTextures(frame, strip)
for i = 1, frame:GetNumRegions() do
---@type Region
local region = select(i, frame:GetRegions());
if region and region:GetObjectType() == 'Texture' then
if strip then
region:Hide();
else
region:Show()
end
end
end
end
function AuctionFaster:StripAhTextures()
if not IsAddOnLoaded('ElvUI') then
stripFrameTextures(AuctionHouseFrame, true);
stripFrameTextures(AuctionHouseFrame.NineSlice, true);
end
end
function AuctionFaster:RestoreAhTextures()
if not IsAddOnLoaded('ElvUI') then
stripFrameTextures(AuctionHouseFrame, false);
stripFrameTextures(AuctionHouseFrame.NineSlice, false);
end
end
function AuctionFaster:SetDisplayModeHook(_, displayMode)
if displayMode and displayMode[1] and displayMode[1]:find('AF') == 1 then
self:StripAhTextures();
else
self:RestoreAhTextures();
end
end
function AuctionFaster:GetDefaultItemSettings()
return {
rememberStack = true,
rememberLastPrice = false,
alwaysUndercut = true,
useCustomDuration = false,
priceModel = 'Simple',
duration = self.db.auctionDuration,
}
end
AuctionFaster.auctionTabs = {};
function AuctionFaster:AddAuctionHouseTab(buttonText, title, module, displayMode)
local n = #AuctionHouseFrame.Tabs + 1;
local auctionTab = StdUi:PanelWithTitle(AuctionHouseFrame, nil, nil, title, 160);
auctionTab.titlePanel:SetBackdrop(nil);
auctionTab:Hide();
auctionTab:SetAllPoints();
auctionTab.tabId = n;
local tabButton = CreateFrame('Button', 'AuctionFrameTab' .. n, AuctionHouseFrame, 'AuctionHouseFrameDisplayModeTabTemplate');
tabButton.displayMode = displayMode;
StdUi:StripTextures(tabButton);
tabButton.backdrop = StdUi:Panel(tabButton);
tabButton.backdrop:SetFrameLevel(tabButton:GetFrameLevel() - 1);
StdUi:GlueAcross(tabButton.backdrop, tabButton, 10, -3, -10, 3);
tabButton:Hide();
tabButton:SetID(n);
tabButton:SetText(buttonText);
tabButton:SetNormalFontObject(GameFontHighlightSmall);
tabButton:SetPoint('LEFT', AuctionHouseFrame.Tabs[n - 1], 'RIGHT', -15, 0);
tabButton:Show();
-- reference the actual tab
tabButton.auctionFasterTab = auctionTab;
tabButton.auctionFasterTab.module = module;
auctionTab.tabButton = tabButton;
PanelTemplates_SetNumTabs(AuctionHouseFrame, n);
tinsert(self.auctionTabs, auctionTab);
tinsert(AuctionHouseFrame.Tabs, tabButton);
AuctionHouseFrame.tabsForDisplayMode[displayMode] = n;
AuctionHouseFrame[displayMode[1]] = auctionTab;
return auctionTab;
end
AuctionFaster.Colors = {
[1] = 'FFBCCF02', -- Success
[2] = 'FF1394CC', -- Info
[3] = 'FFF0563D', -- Error
};
function AuctionFaster:Echo(type, message)
self:Print(WrapTextInColorCode(message, self.Colors[type]));
end