📄 ct_mminbox.lua
字号:
tinsert(UISpecialFrames, "CT_MMInbox_OpenAll");
CT_MMINBOX_DELETEDELAY = 1;
CT_MMINBOX_DELETEEVENTDELAY = 1;
EasyMail_LastMailed = nil;
CT_MMInbox_SelectedItems = { };
function CT_MMInbox_OnLoad()
MailItem1:SetPoint("TOPLEFT", "InboxFrame", "TOPLEFT", 48, -80);
for i = 1, 7, 1 do
getglobal("MailItem" .. i .. "ExpireTime"):SetPoint("TOPRIGHT", "MailItem" .. i, "TOPRIGHT", 10, -4);
getglobal("MailItem" .. i):SetWidth(280);
end
this.eventFunc = { };
this:RegisterEvent("MAIL_INBOX_UPDATE");
this:RegisterEvent("UI_ERROR_MESSAGE");
this:RegisterEvent("VARIABLES_LOADED");
Sea.util.hook("SendMailFrame_SendMail","EasyMail_SendMail","before");
Sea.util.hook("FriendsFrameFriendButton_OnClick","EasyMailFriendButton_OnClick","after");
Sea.util.hook("FriendsFrameGuildPlayerStatusButton_OnClick","EasyMailGuild_OnClick","after");
end
function EasyMail_SendMail()
EasyMail_LastMailed = SendMailNameEditBox:GetText();
end
function CT_MMInbox_OnUpdate(elapsed)
if ( CT_Mail_addItem ) then
CT_Mail_addItem[4] = CT_Mail_addItem[4] - elapsed;
if ( CT_Mail_addItem[4] <= 0 ) then
CT_Mail_addItem = nil;
for i = 1, NUM_CONTAINER_FRAMES, 1 do
if ( getglobal("ContainerFrame" .. i):IsVisible() ) then
ContainerFrame_Update(getglobal("ContainerFrame" .. i));
end
end
end
end
if ( this.num and this.elapsed ) then
this.elapsed = this.elapsed - elapsed;
if ( this.elapsed <= 0 ) then
this.elapsed = nil;
if ( this.id[1] ) then
local val = this.id[1];
local success = CT_MMInbox_PickMail(val, this.openSelected);
if ( success ~= 2 ) then
tremove(this.id, 1);
this.num = this.num - 1;
end
if ( success == 1 ) then
for key, va in this.id do
if ( va > val ) then
this.id[key] = va-1;
end
end
this.lastVal = val;
InboxFrame_Update();
else
this.elapsed = 1+CT_MMINBOX_DELETEDELAY;
this.lastVal = nil;
end
if ( this.num == 0 ) then
this.num = nil;
CT_MMInbox_DisableClicks(nil);
end
end
end
end
if ( this.delete ) then
this.delete[1] = this.delete[1] - elapsed;
if ( this.delete[1] <= 0 ) then
local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(this.delete[2]);
if ( money == 0 and not itemID ) then
GetInboxText(this.delete[2]);
DeleteInboxItem(this.delete[2]);
end
this.delete = nil;
this.elapsed = 0.5+CT_MMINBOX_DELETEDELAY;
end
end
end
function CT_MMInbox_OnEvent(event)
if ( event == "MAIL_INBOX_UPDATE" ) then
if ( this.eventDelete ) then
this.delete = { CT_MMINBOX_DELETEEVENTDELAY, this.eventDelete };
this.eventDelete = nil;
end
elseif ( event == "UI_ERROR_MESSAGE" and ( arg1 == ERR_INV_FULL or arg1 == ERR_ITEM_MAX_COUNT ) ) then
if ( this.num ) then
if ( arg1 == ERR_INV_FULL ) then
CT_MMInbox_Abort();
if ( CT_MMInbox_DisplayMessages ) then
CT_MMInbox_Print("<CTMod> Error: Inventory full. Aborting.", 1, 0, 0);
end
elseif ( arg1 == ERR_ITEM_MAX_COUNT ) then
if ( CT_MMInbox_DisplayMessages ) then
CT_MMInbox_Print("<CTMod> Error: You already have the maximum amount of that item. Skipping.", 1, 0, 0);
end
this.elapsed = CT_MMINBOX_DELETEDELAY;
if ( this.lastVal ) then
for key, va in this.id do
if ( va >= this.lastVal ) then
this.id[key] = va+1;
end
end
end
end
end
elseif ( event == "VARIABLES_LOADED" ) then
CT_MMInboxDisplayMessagesCB:SetChecked(CT_MMInbox_DisplayMessages);
end
end
function CT_MMInbox_PickMail(id, openSelected)
if ( not id ) then
return 0;
end
local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(id);
if ( CODAmount > 0 ) then
if ( CT_MMInbox_DisplayMessages ) then
CT_MMInbox_Print("<CTMod> Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r is Cash on Delivery, skipping.", 1, 0, 0);
end
return 0;
elseif ( not hasItem and money == 0 and not openSelected ) then
if ( CT_MMInbox_DisplayMessages ) then
CT_MMInbox_Print("<CTMod> Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r has no money or items, skipping.", 1, 1, 0);
end
return 0;
end
if ( CT_MMInbox_DisplayMessages ) then
CT_MMInbox_Print("<CTMod> Opening mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r: \"|c00FFFFFF" .. ( subject or "<No Subject>" ) .. "|r\" from |c00FFFFFF" .. ( sender or "<Unknown Sender>" ) .. "|r.", 1, 1, 0);
end
local eventDelete;
if ( hasItem ) then
TakeInboxItem(id);
eventDelete = 1;
if ( money > 0 ) then
return 2;
end
end
if ( money > 0 ) then
TakeInboxMoney(id);
eventDelete = 1;
end
if ( eventDelete ) then
CT_MMInboxFrame.eventDelete = id;
else
CT_MMInboxFrame.delete = { CT_MMINBOX_DELETEDELAY, id };
end
return 1;
end
function CT_MMInbox_SetSelected()
local id = this:GetID() + (InboxFrame.pageNum-1)*7;
if ( not this:GetChecked() ) then
for k, v in CT_MMInbox_SelectedItems do
if ( v == id ) then
tremove(CT_MMInbox_SelectedItems, k);
break;
end
end
else
tinsert(CT_MMInbox_SelectedItems, id);
end
end
function CT_MMInbox_OpenSelected(openAll)
CT_MMInbox_DisableClicks(1);
CT_MMInboxFrame.num = 0;
CT_MMInboxFrame.elapsed = CT_MMINBOX_DELETEDELAY;
CT_MMInboxFrame.id = { };
CT_MMInboxFrame.openSelected = not openAll;
if ( openAll ) then
for i = 1, GetInboxNumItems(), 1 do
CT_MMInboxFrame.num = CT_MMInboxFrame.num + 1;
tinsert(CT_MMInboxFrame.id, i);
end
else
for k, v in CT_MMInbox_SelectedItems do
CT_MMInboxFrame.num = CT_MMInboxFrame.num + 1;
tinsert(CT_MMInboxFrame.id, v);
end
end
CT_MMInboxFrame.numMails = CT_MMInboxFrame.num;
CT_MMInbox_SelectedItems = { };
end
-- Hook InboxFrame_Update
CT_MMInbox_oldInboxFrame_Update = InboxFrame_Update;
function CT_MMInbox_newInboxFrame_Update()
CT_MMInbox_oldInboxFrame_Update();
for i = 1, 7, 1 do
local index = (i + (InboxFrame.pageNum-1)*7);
if ( index > GetInboxNumItems() ) then
getglobal("CT_MailBoxItem" .. i .. "CB"):Hide();
else
getglobal("CT_MailBoxItem" .. i .. "CB"):Show();
getglobal("CT_MailBoxItem" .. i .. "CB"):SetChecked(nil);
for k, v in CT_MMInbox_SelectedItems do
if ( v == index ) then
getglobal("CT_MailBoxItem" .. i .. "CB"):SetChecked(1);
break;
end
end
end
end
if ( CT_MMInboxFrame.num ) then
CT_MMInbox_DisableClicks(1, 1);
end
end
InboxFrame_Update = CT_MMInbox_newInboxFrame_Update;
CT_MMInbox_oldInboxFrame_OnClick = InboxFrame_OnClick;
function CT_MMInbox_DisableClicks(disable, loopPrevention)
if ( disable ) then
for i = 1, 7, 1 do
getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(1);
end
InboxFrame_OnClick = function() this:SetChecked(nil) end;
else
for i = 1, 7, 1 do
getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(nil);
end
if ( not loopPrevention ) then
InboxFrame_Update();
end
InboxFrame_OnClick = CT_MMInbox_oldInboxFrame_OnClick;
end
end
function CT_MMInbox_Abort()
CT_MMInboxFrame.num = nil;
CT_MMInboxFrame.elapsed = nil;
CT_MMInboxFrame.id = { };
CT_MMInbox_SelectedItems = { };
CT_MMInbox_DisableClicks();
HideUIPanel(CT_MMInbox_OpenAll);
end
function CT_MMInbox_Print(msg, r, g, b)
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b);
end
CT_MMInbox_oldCloseMail = CloseMail;
function CT_MMInbox_newCloseMail()
CT_MMInbox_oldCloseMail();
CT_MMInbox_Abort();
end
CloseMail = CT_MMInbox_newCloseMail;
CT_MMInbox_oldTakeInboxItem = TakeInboxItem;
function CT_MMInbox_newTakeInboxItem(id)
CT_MMInbox_oldTakeInboxItem(id);
local name, itemTexture, count, quality, canUse = GetInboxItem(id);
tinsert(CT_MMForwardFrame.pickItem, name);
end
TakeInboxItem = CT_MMInbox_newTakeInboxItem;
-- Mail Forwarding
CT_MMForward_BagLinks = { };
function CT_MMForward_DisableAttachments(disable)
if ( not CT_MMForward_oldTakeInboxMoney ) then
CT_MMForward_oldTakeInboxMoney = OpenMailMoneyButton:GetScript("OnClick");
CT_MMForward_oldTakeInboxItem = OpenMailPackageButton:GetScript("OnClick");
end
if ( disable ) then
OpenMailMoneyButtonIconTexture:SetDesaturated(1);
OpenMailPackageButtonIconTexture:SetDesaturated(1);
OpenMailMoneyButton:SetScript("OnClick", function() end);
OpenMailPackageButton:SetScript("OnClick", function() end);
else
OpenMailMoneyButtonIconTexture:SetDesaturated(nil);
OpenMailPackageButtonIconTexture:SetDesaturated(nil);
OpenMailMoneyButton:SetScript("OnClick", CT_MMForward_oldTakeInboxMoney);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -