-
Notifications
You must be signed in to change notification settings - Fork 2
/
TradeLogFrame.lua
279 lines (251 loc) · 11.4 KB
/
TradeLogFrame.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
local LibDBIcon = LibStub("LibDBIcon-1.0")
function TradeLogFrame_OnLoad(self)
table.insert(UISpecialFrames, self:GetName()); --for esc close frame
TradeLog_SetHyperlink_Origin = ItemRefTooltip.SetHyperlink;
ItemRefTooltip.SetHyperlink = function(self,link)
if(strsub(link, 1, 8)=="tradelog") then
HideUIPanel(self);
return;
end
return TradeLog_SetHyperlink_Origin(self,link);
end
hooksecurefunc("SetItemRef", TradeLogFrame_SetItemRef);
end
function TradeLogFrame_CreateMinimapButton()
local ldb = LibStub("LibDataBroker-1.1"):NewDataObject("TradeLog", {
type = "launcher",
text = TRADE_LIST_TITLE,
icon = [[Interface\MINIMAP\TRACKING\Banker]],
--iconCoords = {0.1, 1.1, -0.06, 0.94},
OnClick = function(self, button)
if( TradeListFrame:IsVisible() ) then
TradeListFrame:Hide();
else
TradeListFrame:Show();
end
end,
OnTooltipShow = function(self)
GameTooltip:AddLine(TRADE_LIST_TITLE);
GameTooltip:AddLine(TRADE_LIST_DESC, nil, nil, nil, true);
GameTooltip:Show()
end,
})
TradeLog_TradesHistory.minimapPos = TradeLog_TradesHistory.minimapPos or 338
LibDBIcon:Register("TradeLog", ldb, TradeLog_TradesHistory);
if ( TradeLog_TradesHistory.hideMinimapIcon ) then LibDBIcon:Hide("TradeLog") end
SLASH_TRADELOGICON1 = "/tradelog";
SlashCmdList["TRADELOGICON"] = function(msg)
if ( msg~="icon" ) then
DEFAULT_CHAT_FRAME:AddMessage("Usage: '/tradelog icon' to toggle minimap icon")
else
TradeLog_TradesHistory.hideMinimapIcon = not TradeLog_TradesHistory.hideMinimapIcon
if ( TradeLog_TradesHistory.hideMinimapIcon ) then
LibDBIcon:Hide("TradeLog")
DEFAULT_CHAT_FRAME:AddMessage("TradeLog minimap icon disabled");
else
LibDBIcon:Show("TradeLog")
DEFAULT_CHAT_FRAME:AddMessage("TradeLog minimap icon enabled");
end
end
end
end
function TradeLogFrame_SetItemRef(link, text, button)
if ( strsub(link, 1, 8) == "tradelog" ) then
local id = 0+gsub(gsub(strsub(link,10),"/2","|"),"/1","/");
if(id and TradeLog_TradesHistory) then
for _, v in ipairs(TradeLog_TradesHistory) do
if(v.id==id) then
TradeLogFrame_FillDetailLog(v);
TradeLogFrame:Show();
return;
end
end
end
end
end;
function TradeLogFrame_FillDetailLog(trade)
--DEFAULT_CHAT_FRAME:AddMessage("|CFF00B4FF|Htradelog:"..TEXT(trade.id).."|h[TradeLog]|h|r");
MoneyFrame_Update("TradeLogRecipientMoneyFrame", trade.targetMoney);
MoneyFrame_Update("TradeLogPlayerMoneyFrame", trade.playerMoney);
TradeLogFramePlayerNameText:SetText(trade.player);
TradeLogFrameRecipientNameText:SetText(trade.who);
TradeLogFrameWhenWhereText:SetText(trade.when.." - "..trade.where);
for i=1,7 do
TradeLogFrame_UpdateItem(getglobal("TradeLogPlayerItem"..i), trade.playerItems[i]);
TradeLogFrame_UpdateItem(getglobal("TradeLogRecipientItem"..i), trade.targetItems[i]);
end
end
function TradeLogFrame_UpdateItem(frame, item)
if(item) then
TradeLogFrame_UpdateItemDetail(frame, item.name, item.texture, item.numItems, item.isUsable, item.enchantment, item.itemLink);
else
TradeLogFrame_UpdateItemDetail(frame);
end
end
function TradeLogFrame_UpdateItemDetail(frame, name, texture, numItems, isUsable, enchantment, itemLink)
local frameName = frame:GetName();
local id = frame:GetID();
local buttonText = getglobal(frameName.."Name");
if(itemLink) then
local found, _, itemString = string.find(itemLink, "^|%x+|H(.+)|h%[.+%]")
frame.itemLink = itemString;
end
--ChatFrame1:AddMessage(itemLink, "\124", "\124\124"))
-- See if its the enchant slot
if ( id == 7 ) then
if ( name ) then
if ( enchantment ) then
buttonText:SetText(GREEN_FONT_COLOR_CODE..enchantment..FONT_COLOR_CODE_CLOSE);
else
buttonText:SetText(HIGHLIGHT_FONT_COLOR_CODE..TRADEFRAME_NOT_MODIFIED_TEXT..FONT_COLOR_CODE_CLOSE);
end
else
buttonText:SetText("");
end
else
buttonText:SetText(name);
end
buttonText:SetTextHeight(12);
TradeLogRecipientMoneyFrame:SetScale(0.9);
TradeLogPlayerMoneyFrame:SetScale(0.9);
local tradeItemButton = getglobal(frameName.."ItemButton");
local tradeItem = frame;
SetItemButtonTexture(tradeItemButton, texture);
SetItemButtonCount(tradeItemButton, numItems);
if ( isUsable or not name ) then
SetItemButtonTextureVertexColor(tradeItemButton, 1.0, 1.0, 1.0);
SetItemButtonNameFrameVertexColor(tradeItem, 1.0, 1.0, 1.0);
SetItemButtonSlotVertexColor(tradeItem, 1.0, 1.0, 1.0);
else
SetItemButtonTextureVertexColor(tradeItemButton, 0.9, 0, 0);
SetItemButtonNameFrameVertexColor(tradeItem, 0.9, 0, 0);
SetItemButtonSlotVertexColor(tradeItem, 1.0, 0, 0);
end
end
function TradeListScrollFrame_Update(self)
local line,offset,count;
count=0;
if(TradeListOnlyCompleteCB:GetChecked()) then
for _, v in ipairs(TradeLog_TradesHistory) do
if(v.result=="complete")then count=count+1 end
end
else
count = table.getn(TradeLog_TradesHistory);
end
FauxScrollFrame_Update(TradeListScrollFrame,count,15,16);
if(not FauxScrollFrame_GetOffset(TradeListScrollFrame)) then
offset = 1;
else
offset=FauxScrollFrame_GetOffset(TradeListScrollFrame)+1;
if(TradeListOnlyCompleteCB:GetChecked()) then
for k, v in ipairs(TradeLog_TradesHistory) do
if(v.result=="complete")then offset = offset - 1 end;
if(offset == 0) then
offset = k;
break;
end
end
end
end
line=1
while line<=15 do
if offset<=table.getn(TradeLog_TradesHistory) then
local trade=TradeLog_TradesHistory[offset];
if(not TradeListOnlyCompleteCB:GetChecked() or trade.result=="complete") then
local _,_,month,day,hour,min = string.find(trade.when, "(%d+)-(%d+) (%d+):(%d+)")
getglobal("TradeListFrameButton"..line).offset = offset;
getglobal("TradeListFrameButton"..line.."Time"):SetText(month..TRADE_LOG_MONTH_SUFFIX..day..TRADE_LOG_DAY_SUFFIX.." "..hour..":"..min);
getglobal("TradeListFrameButton"..line.."Target"):SetText(trade.who);
getglobal("TradeListFrameButton"..line.."Zone"):SetText(trade.where);
getglobal("TradeListFrameButton"..line.."Result"):SetText(TRADE_LOG_RESULT_TEXT_SHORT[trade.result]);
getglobal("TradeListFrameButton"..line):Show();
getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Hide();
getglobal("TradeListFrameButton"..line.."SendItemIcon"):Hide();
getglobal("TradeListFrameButton"..line.."SendItemNum"):Hide();
getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Hide();
getglobal("TradeListFrameButton"..line.."ReceiveItemIcon"):Hide();
getglobal("TradeListFrameButton"..line.."ReceiveItemNum"):Hide();
if(trade.result=="complete")then
if(trade.playerMoney>0)then getglobal("TradeListFrameButton"..line.."SendMoneyIcon"):Show(); end
local numSend = 0;
for i=1,6 do if(trade.playerItems[i]) then numSend = numSend + 1 end end
if(numSend>0)then
getglobal("TradeListFrameButton"..line.."SendItemIcon"):Show();
getglobal("TradeListFrameButton"..line.."SendItemNum"):Show();
getglobal("TradeListFrameButton"..line.."SendItemNum"):SetText("x".. numSend);
end
if(trade.targetMoney>0)then getglobal("TradeListFrameButton"..line.."ReceiveMoneyIcon"):Show(); end
local numReceive = 0;
for i=1,6 do if(trade.targetItems[i]) then numReceive = numReceive + 1 end end
if(numReceive>0)then
getglobal("TradeListFrameButton"..line.."ReceiveItemIcon"):Show();
getglobal("TradeListFrameButton"..line.."ReceiveItemNum"):Show();
getglobal("TradeListFrameButton"..line.."ReceiveItemNum"):SetText("x".. numReceive);
end
getglobal("TradeListFrameButton"..line.."Time" ):SetTextColor(1.0, .82, 0.0);
getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(1.0, 1.0, 1.0);
getglobal("TradeListFrameButton"..line.."Zone" ):SetTextColor(1.0, 1.0, 1.0);
getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(1.0, 1.0, 1.0);
elseif(trade.result=="cancelled")then
getglobal("TradeListFrameButton"..line.."Time" ):SetTextColor(0.7, 0.4, 0.4);
getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(0.7, 0.4, 0.4);
getglobal("TradeListFrameButton"..line.."Zone" ):SetTextColor(0.7, 0.4, 0.4);
getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(0.7, 0.4, 0.4);
else
getglobal("TradeListFrameButton"..line.."Time" ):SetTextColor(0.8, 0.3, 0.3);
getglobal("TradeListFrameButton"..line.."Target" ):SetTextColor(0.8, 0.3, 0.3);
getglobal("TradeListFrameButton"..line.."Zone" ):SetTextColor(0.8, 0.3, 0.3);
getglobal("TradeListFrameButton"..line.."Result" ):SetTextColor(0.8, 0.3, 0.3);
end
line=line+1
end
else
getglobal("TradeListFrameButton"..line):Hide();
line=line+1
end
offset=offset+1
end
end
StaticPopupDialogs["TRADE_LOG_CLEAR_HISTORY"] = {preferredIndex = 3,
text = "CLEAR TRADE HISTORY",
button1 = ACCEPT,
button2 = CANCEL,
whileDead = 1,
OnShow = function(self)
getglobal(self:GetName().."Text"):SetText(TRADE_LIST_CLEAR_CONFIRM);
end,
OnAccept = function(self)
TradeLog_KeepOnlyToday();
end,
timeout = 0,
hideOnEscape = 1
};
function TradeLog_KeepOnlyToday()
local today = {
month = date("%m"),
day = date("%d"),
}
for k, v in ipairs(TradeLog_TradesHistory) do
local _,_,month,day,hour,min = string.find(v.when, "(%d+)-(%d+) (%d+):(%d+)");
if(month==today.month and day==today.day)then
local tmp = {}
for i=k, table.getn(TradeLog_TradesHistory) do
table.insert(tmp, TradeLog_TradesHistory[i]);
end
TradeLog_TradesHistory = nil;
TradeLog_TradesHistory = tmp;
TradeListScrollFrame_Update();
return;
end
end
TradeLog_TradesHistory = nil;
TradeLog_TradesHistory = {};
TradeListScrollFrame_Update();
end
function TradeListFrame_ShowDetail(trade)
TradeLogFrame:Hide();
if(trade.result=="complete")then
TradeLogFrame_FillDetailLog(trade);
TradeLogFrame:Show();
end;
end