working on big refactoring
This commit is contained in:
+270
-225
@@ -1,34 +1,39 @@
|
|||||||
Postal = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.0")
|
Postal = AceLibrary('AceAddon-2.0'):new('AceEvent-2.0', 'AceHook-2.0')
|
||||||
|
Postal.open, Postal.send = {}, {}
|
||||||
|
|
||||||
function Postal:OnInitialize()
|
function Postal:OnInitialize()
|
||||||
|
|
||||||
-- Allows the mail frame to be pushed
|
-- Allows the mail frame to be pushed
|
||||||
if UIPanelWindows["MailFrame"] then
|
if UIPanelWindows['MailFrame'] then
|
||||||
UIPanelWindows["MailFrame"].pushable = 1
|
UIPanelWindows['MailFrame'].pushable = 1
|
||||||
else
|
else
|
||||||
UIPanelWindows["MailFrame"] = { area = "left", pushable = 1 }
|
UIPanelWindows['MailFrame'] = { area = 'left', pushable = 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Close FriendsFrame will close if you try to open a mail with mailframe+friendsframe open
|
-- Close FriendsFrame will close if you try to open a mail with mailframe+friendsframe open
|
||||||
if UIPanelWindows["FriendsFrame"] then
|
if UIPanelWindows['FriendsFrame'] then
|
||||||
UIPanelWindows["FriendsFrame"].pushable = 2
|
UIPanelWindows['FriendsFrame'].pushable = 2
|
||||||
else
|
else
|
||||||
UIPanelWindows["FriendsFrame"] = { area = "left", pushable = 2 }
|
UIPanelWindows['FriendsFrame'] = { area = 'left', pushable = 2 }
|
||||||
end
|
end
|
||||||
|
|
||||||
MailItem1:SetPoint("TOPLEFT", "InboxFrame", "TOPLEFT", 48, -80)
|
MailItem1:SetPoint('TOPLEFT', 'InboxFrame', 'TOPLEFT', 48, -80)
|
||||||
for i=1,7 do
|
for i=1,7 do
|
||||||
getglobal("MailItem" .. i .. "ExpireTime"):SetPoint("TOPRIGHT", "MailItem" .. i, "TOPRIGHT", 10, -4)
|
getglobal('MailItem' .. i .. 'ExpireTime'):SetPoint('TOPRIGHT', 'MailItem' .. i, 'TOPRIGHT', 10, -4)
|
||||||
getglobal("MailItem" .. i):SetWidth(280)
|
getglobal('MailItem' .. i):SetWidth(280)
|
||||||
end
|
end
|
||||||
|
|
||||||
ATTACHMENTS_MAX = 21
|
ATTACHMENTS_MAX = 21
|
||||||
ATTACHMENTS_PER_ROW_SEND = 7
|
ATTACHMENTS_PER_ROW_SEND = 7
|
||||||
ATTACHMENTS_MAX_ROWS_SEND = 3
|
ATTACHMENTS_MAX_ROWS_SEND = 3
|
||||||
|
|
||||||
Postal_SelectedItems = {}
|
Postal_MiniMapMailFrame_Show_Orig = MiniMapMailFrame.Show
|
||||||
|
|
||||||
PostalTooltip:SetOwner(WorldFrame, 'ANCHOR_NONE')
|
self.Inbox_selectedItems = {}
|
||||||
|
Postal.Send_Ready = true
|
||||||
|
|
||||||
|
CreateFrame('GameTooltip', 'PostalTooltip', nil, 'GameTooltipTemplate')
|
||||||
|
PostalTooltip:SetOwner(WorldFrame, 'ANCHOR_NONE')
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:SendMailFrame_Update()
|
function Postal:SendMailFrame_Update()
|
||||||
@@ -67,12 +72,12 @@ function Postal:SendMailFrame_Update()
|
|||||||
local itemRowCount = 1
|
local itemRowCount = 1
|
||||||
local temp = last
|
local temp = last
|
||||||
while temp > ATTACHMENTS_PER_ROW_SEND and itemRowCount < ATTACHMENTS_MAX_ROWS_SEND do
|
while temp > ATTACHMENTS_PER_ROW_SEND and itemRowCount < ATTACHMENTS_MAX_ROWS_SEND do
|
||||||
itemRowCount = itemRowCount + 1;
|
itemRowCount = itemRowCount + 1
|
||||||
temp = temp - ATTACHMENTS_PER_ROW_SEND
|
temp = temp - ATTACHMENTS_PER_ROW_SEND
|
||||||
end
|
end
|
||||||
|
|
||||||
if not gap and temp == ATTACHMENTS_PER_ROW_SEND and itemRowCount < ATTACHMENTS_MAX_ROWS_SEND then
|
if not gap and temp == ATTACHMENTS_PER_ROW_SEND and itemRowCount < ATTACHMENTS_MAX_ROWS_SEND then
|
||||||
itemRowCount = itemRowCount + 1;
|
itemRowCount = itemRowCount + 1
|
||||||
end
|
end
|
||||||
if SendMailFrame.maxRowsShown and last > 0 and itemRowCount < SendMailFrame.maxRowsShown then
|
if SendMailFrame.maxRowsShown and last > 0 and itemRowCount < SendMailFrame.maxRowsShown then
|
||||||
itemRowCount = SendMailFrame.maxRowsShown
|
itemRowCount = SendMailFrame.maxRowsShown
|
||||||
@@ -120,9 +125,9 @@ function Postal:SendMailFrame_Update()
|
|||||||
-- Set Items
|
-- Set Items
|
||||||
for i=1,ATTACHMENTS_MAX do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
if cursory >= 0 then
|
if cursory >= 0 then
|
||||||
getglobal("PostalAttachment"..i):Enable()
|
getglobal('PostalAttachment'..i):Enable()
|
||||||
getglobal("PostalAttachment"..i):Show()
|
getglobal('PostalAttachment'..i):Show()
|
||||||
getglobal("PostalAttachment"..i):SetPoint("TOPLEFT", "SendMailFrame", "BOTTOMLEFT", indentx + (tabx * cursorx), indenty + (taby * cursory));
|
getglobal('PostalAttachment'..i):SetPoint('TOPLEFT', 'SendMailFrame', 'BOTTOMLEFT', indentx + (tabx * cursorx), indenty + (taby * cursory))
|
||||||
|
|
||||||
cursorx = cursorx + 1
|
cursorx = cursorx + 1
|
||||||
if cursorx >= ATTACHMENTS_PER_ROW_SEND then
|
if cursorx >= ATTACHMENTS_PER_ROW_SEND then
|
||||||
@@ -130,20 +135,20 @@ function Postal:SendMailFrame_Update()
|
|||||||
cursorx = 0
|
cursorx = 0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
getglobal("PostalAttachment"..i):Hide()
|
getglobal('PostalAttachment'..i):Hide()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=ATTACHMENTS_MAX+1,ATTACHMENTS_MAX do
|
for i=ATTACHMENTS_MAX+1,ATTACHMENTS_MAX do
|
||||||
getglobal("PostalAttachment"..i):Hide()
|
getglobal('PostalAttachment'..i):Hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:GetNumMails() > 0 then
|
if self:GetNumMails() > 0 then
|
||||||
SendMailCODButton:Enable();
|
SendMailCODButton:Enable()
|
||||||
SendMailCODButtonText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
|
SendMailCODButtonText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
|
||||||
else
|
else
|
||||||
SendMailRadioButton_OnClick(1);
|
SendMailRadioButton_OnClick(1)
|
||||||
SendMailCODButton:Disable();
|
SendMailCODButton:Disable()
|
||||||
SendMailCODButtonText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
|
SendMailCODButtonText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
|
||||||
end
|
end
|
||||||
|
|
||||||
Postal:SendMailFrame_CanSend()
|
Postal:SendMailFrame_CanSend()
|
||||||
@@ -153,6 +158,7 @@ function Postal:OnEnable()
|
|||||||
self:RegisterEvent('UI_ERROR_MESSAGE')
|
self:RegisterEvent('UI_ERROR_MESSAGE')
|
||||||
self:RegisterEvent('MAIL_SEND_SUCCESS')
|
self:RegisterEvent('MAIL_SEND_SUCCESS')
|
||||||
self:RegisterEvent('MAIL_CLOSED')
|
self:RegisterEvent('MAIL_CLOSED')
|
||||||
|
self:RegisterEvent('CURSOR_UPDATE')
|
||||||
|
|
||||||
self:Hook('ContainerFrameItemButton_OnClick')
|
self:Hook('ContainerFrameItemButton_OnClick')
|
||||||
self:Hook('PickupContainerItem')
|
self:Hook('PickupContainerItem')
|
||||||
@@ -195,19 +201,20 @@ function Postal:OnEnable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
PostalMailButton:SetScript('OnClick', function()
|
PostalMailButton:SetScript('OnClick', function()
|
||||||
PostalGlobalFrame.first = true
|
local attachments = self:AttachmentList()
|
||||||
PostalGlobalFrame.to = SendMailNameEditBox:GetText()
|
self.Send_State = {
|
||||||
PostalGlobalFrame.subject = PostalSubjectEditBox:GetText() ~= '' and PostalSubjectEditBox:GetText()
|
first = true,
|
||||||
PostalGlobalFrame.body = SendMailBodyEditBox:GetText()
|
to = SendMailNameEditBox:GetText(),
|
||||||
PostalGlobalFrame.money = MoneyInputFrame_GetCopper(SendMailMoney)
|
subject = PostalSubjectEditBox:GetText(),
|
||||||
PostalGlobalFrame.cod = SendMailCODButton:GetChecked()
|
body = SendMailBodyEditBox:GetText(),
|
||||||
PostalGlobalFrame.queue = Postal:AttachmentList()
|
money = MoneyInputFrame_GetCopper(SendMailMoney),
|
||||||
PostalGlobalFrame.total = getn(PostalGlobalFrame.queue)
|
cod = SendMailCODButton:GetChecked(),
|
||||||
PostalGlobalFrame:Show()
|
attachments = attachments,
|
||||||
POSTAL_CANSENDNEXT = 1
|
total = getn(attachments),
|
||||||
|
}
|
||||||
|
|
||||||
Postal:ClearItems()
|
self:SendMail_Clear()
|
||||||
Postal:SendMailFrame_Update()
|
self:SendMailFrame_Update()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- hack to avoid automatic subject setting/button enabling
|
-- hack to avoid automatic subject setting/button enabling
|
||||||
@@ -228,13 +235,13 @@ function Postal:OnEnable()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Postal:SendMailFrame_Update()
|
SendMailFrame_Update()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:MAIL_CLOSED()
|
function Postal:MAIL_CLOSED()
|
||||||
PostalGlobalFrame:Hide()
|
self.Send_State = nil
|
||||||
Postal:Inbox_Abort()
|
self:Inbox_Abort()
|
||||||
Postal:ClearItems()
|
self:SendMail_Clear()
|
||||||
|
|
||||||
-- Hides the minimap unread mail button if there are no unread mail on closing the mailbox.
|
-- Hides the minimap unread mail button if there are no unread mail on closing the mailbox.
|
||||||
-- Does not scan past the first 50 items since only the first 50 are viewable.
|
-- Does not scan past the first 50 items since only the first 50 are viewable.
|
||||||
@@ -256,112 +263,114 @@ function Postal:MAIL_CLOSED()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:MAIL_SEND_SUCCESS()
|
function Postal:MAIL_SEND_SUCCESS()
|
||||||
POSTAL_CANSENDNEXT = 1
|
Postal.Send_Ready = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
||||||
local bag, slot = this:GetParent():GetID(), this:GetID()
|
local item = {this:GetParent():GetID(), this:GetID()}
|
||||||
if self:SelectedAttachment(bag, slot) or self:QueuedAttachment(bag, slot) then
|
if self:Send_Attached(item) then
|
||||||
return
|
return
|
||||||
end
|
else
|
||||||
self.hooks["ContainerFrameItemButton_OnClick"].orig(btn, ignore)
|
return self.hooks['ContainerFrameItemButton_OnClick'].orig(btn, ignore)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:PickupContainerItem(bag, slot)
|
function Postal:Send_AttachItem(item)
|
||||||
if self:SelectedAttachment(bag, slot) or self:QueuedAttachment(bag, slot) then
|
for i = 1,ATTACHMENTS_MAX do
|
||||||
return
|
if not getglobal('PostalAttachment'..i).item then
|
||||||
end
|
if not self:ItemIsMailable(item) then
|
||||||
if not CursorHasItem() then
|
return self:Print('Postal: Cannot attach item.', 1, 0.5, 0)
|
||||||
PostalFrame.bag = bag
|
|
||||||
PostalFrame.slot = slot
|
|
||||||
end
|
|
||||||
self.hooks["PickupContainerItem"].orig(bag, slot)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal:AttachItem(bag, slot)
|
|
||||||
for i = 1, ATTACHMENTS_MAX do
|
|
||||||
if not getglobal("PostalAttachment" .. i).slot then
|
|
||||||
|
|
||||||
if not self:ItemIsMailable(bag, slot) then
|
|
||||||
Postal:Print("Postal: Cannot attach item.", 1, 0.5, 0)
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
getglobal('PostalAttachment'..i).item = item
|
||||||
|
return SendMailFrame_Update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.hooks["PickupContainerItem"].orig(bag, slot)
|
do
|
||||||
self:AttachmentButton_OnClick(getglobal("PostalAttachment" .. i))
|
local last_picked_up
|
||||||
|
|
||||||
|
function Postal:CURSOR_UPDATE()
|
||||||
|
Aux.log(tostring(last_picked_up))
|
||||||
|
last_picked_up = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:CursorItem()
|
||||||
|
if CursorHasItem() then
|
||||||
|
return last_picked_up
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:PickupContainerItem(bag, slot, force)
|
||||||
|
local item = {bag, slot}
|
||||||
|
if not force and self:Send_Attached(item) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if not CursorHasItem() then
|
||||||
|
self:Wait(function()
|
||||||
|
last_picked_up = item
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:UseContainerItem(bag, slot)
|
function Postal:UseContainerItem(bag, slot)
|
||||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
|
local item = {bag, slot}
|
||||||
return self.hooks["UseContainerItem"].orig(bag, slot)
|
if self:Send_Attached(item) then
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if self:SelectedAttachment(bag, slot) or self:QueuedAttachment(bag, slot) then
|
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
|
||||||
return
|
return self.hooks['UseContainerItem'].orig(unpack(item))
|
||||||
end
|
end
|
||||||
if not CursorHasItem() then
|
|
||||||
PostalFrame.bag = bag
|
|
||||||
PostalFrame.slot = slot
|
|
||||||
end
|
|
||||||
if SendMailFrame:IsVisible() and not CursorHasItem() then
|
|
||||||
self:AttachItem(bag, slot)
|
|
||||||
return
|
|
||||||
elseif TradeFrame:IsVisible() and not CursorHasItem() then
|
|
||||||
for i = 1, 6 do
|
|
||||||
if not GetTradePlayerItemLink(i) then
|
|
||||||
self.hooks["PickupContainerItem"].orig(bag, slot)
|
|
||||||
ClickTradeButton(i)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.hooks["UseContainerItem"].orig(bag, slot)
|
if SendMailFrame:IsVisible() and not CursorHasItem() then
|
||||||
|
self:Send_AttachItem(item)
|
||||||
|
return
|
||||||
|
elseif TradeFrame:IsVisible() and not CursorHasItem() then
|
||||||
|
for i = 1,6 do
|
||||||
|
if not GetTradePlayerItemLink(i) then
|
||||||
|
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||||
|
ClickTradeButton(i)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.hooks['UseContainerItem'].orig(unpack(item))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle the dragging of items
|
-- Handle the dragging of items
|
||||||
function Postal:AttachmentButton_OnClick(button)
|
function Postal:AttachmentButton_OnClick(button)
|
||||||
button = button or this
|
button = button or this
|
||||||
if CursorHasItem() then
|
local buttonItem = button.item
|
||||||
local bag, slot = PostalFrame.bag, PostalFrame.slot
|
local cursorItem = self:CursorItem()
|
||||||
if not bag or not slot then return end
|
if cursorItem then
|
||||||
if not self:ItemIsMailable(bag, slot) then
|
if not self:ItemIsMailable(unpack(cursorItem)) then
|
||||||
Postal:Print("Postal: Cannot attach item.", 1, 0.5, 0)
|
self:Print('Postal: Cannot attach item.', 1, 0.5, 0)
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldBag, oldSlot = button.bag, button.slot
|
button.item = cursorItem
|
||||||
button.bag, button.slot = bag, slot
|
ClearCursor() -- triggers lock changed event to update the bag frame
|
||||||
ClearCursor() -- triggers lock changed event
|
else
|
||||||
|
button.item = nil
|
||||||
if oldBag and oldSlot then
|
|
||||||
self:PickupContainerItem(oldBag, oldSlot)
|
|
||||||
else
|
|
||||||
PostalFrame.bag, PostalFrame.slot = nil, nil
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif button.bag and button.slot then
|
|
||||||
PostalFrame.bag, PostalFrame.slot = button.bag, button.slot
|
|
||||||
self.hooks["PickupContainerItem"].orig(button.bag, button.slot)
|
|
||||||
button.bag, button.slot = nil, nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Postal:SendMailFrame_Update()
|
if buttonItem then
|
||||||
|
PickupContainerItem(unpack(buttonItem))
|
||||||
|
end
|
||||||
|
SendMailFrame_Update()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ItemIsMailable(bag, slot)
|
function Postal:ItemIsMailable(item)
|
||||||
-- Make sure tooltip is cleared
|
-- Make sure tooltip is cleared
|
||||||
for i=1,29 do
|
-- PostalTooltip:ClearLines() TODO
|
||||||
getglobal("PostalTooltipTextLeft" .. i):SetText("")
|
PostalTooltip:SetBagItem(unpack(item))
|
||||||
end
|
|
||||||
|
|
||||||
PostalTooltip:SetBagItem(bag, slot)
|
|
||||||
for i=1,PostalTooltip:NumLines() do
|
for i=1,PostalTooltip:NumLines() do
|
||||||
local text = getglobal("PostalTooltipTextLeft" .. i):GetText()
|
local text = getglobal('PostalTooltipTextLeft' .. i):GetText()
|
||||||
if text == ITEM_SOULBOUND or text == ITEM_BIND_QUEST or text == ITEM_CONJURED or text == ITEM_BIND_ON_PICKUP then
|
if text == ITEM_SOULBOUND or text == ITEM_BIND_QUEST or text == ITEM_CONJURED or text == ITEM_BIND_ON_PICKUP then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -369,40 +378,41 @@ function Postal:ItemIsMailable(bag, slot)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:SelectedAttachment(bag, slot)
|
function Postal:Send_Attached(item)
|
||||||
for i=1,ATTACHMENTS_MAX do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal('PostalAttachment' .. i)
|
||||||
if btn.slot == slot and btn.bag == bag then
|
if btn.item and btn.item[1] == item[1] and btn.item[2] == item[2] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function Postal:QueuedAttachment(bag, slot)
|
if not self.Send_State then
|
||||||
for _, attachment in ipairs(PostalGlobalFrame.queue or {}) do
|
return
|
||||||
if attachment.slot == slot and attachment.bag == bag then
|
end
|
||||||
return true
|
|
||||||
end
|
for _, attachment in self.Send_State.attachments do
|
||||||
end
|
if attachment.item[1] == item[1] and attachment.item[2] == item[2] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:GetNumMails()
|
function Postal:GetNumMails()
|
||||||
local num = 0
|
local num = 0
|
||||||
for i=1,ATTACHMENTS_MAX do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal('PostalAttachment'..i)
|
||||||
if btn.slot and btn.bag then
|
if btn.item then
|
||||||
num = num + 1
|
num = num + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return num
|
return num
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ClearItems()
|
function Postal:SendMail_Clear()
|
||||||
local num = 0
|
local num = 0
|
||||||
for i=1,ATTACHMENTS_MAX do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal('PostalAttachment'..i)
|
||||||
btn.slot = nil
|
btn.item = nil
|
||||||
btn.bag = nil
|
|
||||||
end
|
end
|
||||||
PostalMailButton:Disable()
|
PostalMailButton:Disable()
|
||||||
SendMailNameEditBox:SetText('')
|
SendMailNameEditBox:SetText('')
|
||||||
@@ -424,113 +434,165 @@ end
|
|||||||
-- handle the weird built-in mail body textbox onclick
|
-- handle the weird built-in mail body textbox onclick
|
||||||
function Postal:ClickSendMailItemButton()
|
function Postal:ClickSendMailItemButton()
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
Postal.control.as_soon_as(function() return not ({GetContainerItemInfo(PostalFrame.bag or 0, PostalFrame.slot or 0)})[3] end, function()
|
self:When(function() return not ({GetContainerItemInfo(unpack(self:CursorItem()))})[3] end, function()
|
||||||
if PostalFrame.bag and PostalFrame.slot then
|
if self:CursorItem() then
|
||||||
self:AttachItem(PostalFrame.bag, PostalFrame.slot)
|
self:Send_AttachItem(self:CursorItem())
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:SendMail()
|
function Postal:Send_SendMail()
|
||||||
|
|
||||||
local item = tremove(this.queue, 1)
|
local item = tremove(self.Send_State.attachments, 1)
|
||||||
|
|
||||||
if item or this.first then
|
if item or self.Send_State.first then
|
||||||
|
local subject = self.Send_State.subject
|
||||||
local subject = this.subject or '[No Subject]'
|
subject = subject ~= '' and subject or '[No Subject]'
|
||||||
if this.total > 1 then
|
if self.Send_State.total > 1 then
|
||||||
subject = subject..format(' (Part %d of %d)', this.total - getn(this.queue), this.total)
|
subject = subject..format(' (Part %d of %d)', self.Send_State.total - getn(self.Send_State.attachments), self.Send_State.total)
|
||||||
end
|
end
|
||||||
|
|
||||||
if item then
|
if item then
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
self.hooks["ClickSendMailItemButton"].orig()
|
self.hooks['ClickSendMailItemButton'].orig()
|
||||||
ClearCursor()
|
ClearCursor()
|
||||||
self.hooks["PickupContainerItem"].orig(item.bag, item.slot)
|
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||||
self.hooks["ClickSendMailItemButton"].orig()
|
self.hooks['ClickSendMailItemButton'].orig()
|
||||||
|
|
||||||
local name, _, count = GetSendMailItem()
|
local name, _, count = GetSendMailItem()
|
||||||
|
|
||||||
if not name then
|
if not name then
|
||||||
Postal:Print("Postal: An error occured in POSTAL. This might be related to lag, trying to send items with an item placed in the normal send mail window, or trying to send items that cannot be sent.", 1, 0, 0)
|
self:Print('Postal: An error occured in POSTAL. This might be related to lag, trying to send items with an item placed in the normal send mail window, or trying to send items that cannot be sent.', 1, 0, 0)
|
||||||
PostalGlobalFrame:Hide()
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if this.first then
|
if self.Send_State.first then
|
||||||
this.first = false
|
self.Send_State.first = false
|
||||||
|
|
||||||
if this.money then
|
if self.Send_State.money then
|
||||||
if this.cod then
|
if self.Send_State.cod then
|
||||||
SetSendMailCOD(this.money)
|
SetSendMailCOD(self.Send_State.money)
|
||||||
else
|
else
|
||||||
SetSendMailMoney(this.money)
|
SetSendMailMoney(self.Send_State.money)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
SendMail(this.to, subject, this.body)
|
return SendMail(self.Send_State.to, subject, self.Send_State.body)
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
PostalGlobalFrame:Hide()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:AttachmentList()
|
function Postal:AttachmentList()
|
||||||
local arr = {}
|
local arr = {}
|
||||||
for i = 1, ATTACHMENTS_MAX do
|
for i = 1, ATTACHMENTS_MAX do
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal('PostalAttachment' .. i)
|
||||||
if btn.slot and btn.bag then
|
if btn.item then
|
||||||
tinsert(arr, { slot = btn.slot, bag = btn.bag })
|
tinsert(arr, btn.item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return arr
|
return arr
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ProcessQueue(elapsed)
|
function Postal:When(p, callback)
|
||||||
if not POSTAL_CANSENDNEXT then
|
self.state = {
|
||||||
return
|
p = p,
|
||||||
|
callback = callback,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:Wait(callback)
|
||||||
|
self.state = {
|
||||||
|
p = function() return true end,
|
||||||
|
callback = callback,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:UPDATE()
|
||||||
|
|
||||||
|
if self.state and self.state.p() then
|
||||||
|
return self.state.callback()
|
||||||
end
|
end
|
||||||
POSTAL_CANSENDNEXT = nil
|
|
||||||
self:SendMail()
|
if self.Send_State and self.Send_Ready then
|
||||||
|
self.Send_Ready = nil
|
||||||
|
self:Send_SendMail()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:Inbox_OpenMail(selected)
|
||||||
|
if getn(selected) == 0 then
|
||||||
|
self.opening = false
|
||||||
|
self:Inbox_DisableClicks()
|
||||||
|
else
|
||||||
|
self:Inbox_OpenItem(selected[1], GetInboxNumItems(), selected)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Postal:Inbox_OpenItem(i, inboxCount, selected)
|
||||||
|
self:Wait(function()
|
||||||
|
local _, _, _, _, money, COD, _, item = GetInboxHeaderInfo(i)
|
||||||
|
local newInboxCount = GetInboxNumItems()
|
||||||
|
|
||||||
|
if newInboxCount < inboxCount or COD > 0 then
|
||||||
|
tremove(selected, 1)
|
||||||
|
if newInboxCount < inboxCount then
|
||||||
|
for j, _ in selected do
|
||||||
|
selected[j] = selected[j] - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self:Inbox_OpenMail(selected)
|
||||||
|
elseif item then
|
||||||
|
TakeInboxItem(i)
|
||||||
|
self:When(function() return not ({GetInboxHeaderInfo(i)})[8] or GetInboxNumItems() < inboxCount end, function()
|
||||||
|
return self:Inbox_OpenItem(i, inboxCount, selected)
|
||||||
|
end)
|
||||||
|
elseif money > 0 then
|
||||||
|
TakeInboxMoney(i)
|
||||||
|
self:When(function() return ({GetInboxHeaderInfo(i)})[5] == 0 or GetInboxNumItems() < inboxCount end, function()
|
||||||
|
return self:Inbox_OpenItem(i, inboxCount, selected)
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
DeleteInboxItem(i)
|
||||||
|
self:When(function() return GetInboxNumItems() < inboxCount end, function()
|
||||||
|
return self:Inbox_OpenItem(i, inboxCount, selected)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:SetItemButtonDesaturated(itemButton, locked)
|
function Postal:SetItemButtonDesaturated(itemButton, locked)
|
||||||
local bag, slot = itemButton:GetParent():GetID(), itemButton:GetID()
|
local item = { itemButton:GetParent():GetID(), itemButton:GetID() }
|
||||||
if self:SelectedAttachment(bag, slot) or self:QueuedAttachment(bag, slot) then
|
if self:Send_Attached(item) then
|
||||||
return self.hooks["SetItemButtonDesaturated"].orig(itemButton, true)
|
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, true)
|
||||||
end
|
end
|
||||||
return self.hooks["SetItemButtonDesaturated"].orig(itemButton, locked)
|
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, locked)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:InboxFrameItem_OnEnter()
|
function Postal:InboxFrameItem_OnEnter()
|
||||||
local didSetTooltip
|
local didSetTooltip
|
||||||
|
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
||||||
if this.index then
|
if this.index then
|
||||||
if GetInboxItem(this.index) then
|
if GetInboxItem(this.index) then
|
||||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
|
||||||
GameTooltip:SetInboxItem(this.index)
|
GameTooltip:SetInboxItem(this.index)
|
||||||
didSetTooltip = 1
|
didSetTooltip = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not didSetTooltip then
|
|
||||||
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
|
||||||
end
|
|
||||||
if this.money then
|
if this.money then
|
||||||
GameTooltip:AddLine(ENCLOSED_MONEY, "", 1, 1, 1)
|
GameTooltip:AddLine(ENCLOSED_MONEY, '', 1, 1, 1)
|
||||||
SetTooltipMoney(GameTooltip, this.money)
|
SetTooltipMoney(GameTooltip, this.money)
|
||||||
SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
|
SetMoneyFrameColor('GameTooltipMoneyFrame', HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
|
||||||
elseif this.cod then
|
elseif this.cod then
|
||||||
GameTooltip:AddLine(COD_AMOUNT, "", 1, 1, 1)
|
GameTooltip:AddLine(COD_AMOUNT, '', 1, 1, 1)
|
||||||
SetTooltipMoney(GameTooltip, this.cod)
|
SetTooltipMoney(GameTooltip, this.cod)
|
||||||
if this.cod > GetMoney() then
|
if this.cod > GetMoney() then
|
||||||
SetMoneyFrameColor("GameTooltipMoneyFrame", RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b)
|
SetMoneyFrameColor('GameTooltipMoneyFrame', RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b)
|
||||||
else
|
else
|
||||||
SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
|
SetMoneyFrameColor('GameTooltipMoneyFrame', HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if didSetTooltip and (this.money or this.cod) then
|
if didSetTooltip and (this.money or this.cod) then
|
||||||
GameTooltip:SetHeight(GameTooltip:GetHeight()+getglobal("GameTooltipTextLeft" .. GameTooltip:NumLines()):GetHeight())
|
GameTooltip:SetHeight(GameTooltip:GetHeight()+getglobal('GameTooltipTextLeft' .. GameTooltip:NumLines()):GetHeight())
|
||||||
if GameTooltipMoneyFrame:IsVisible() then
|
if GameTooltipMoneyFrame:IsVisible() then
|
||||||
GameTooltip:SetHeight(GameTooltip:GetHeight()+GameTooltipMoneyFrame:GetHeight())
|
GameTooltip:SetHeight(GameTooltip:GetHeight()+GameTooltipMoneyFrame:GetHeight())
|
||||||
end
|
end
|
||||||
@@ -539,13 +601,13 @@ function Postal:InboxFrameItem_OnEnter()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:UI_ERROR_MESSAGE()
|
function Postal:UI_ERROR_MESSAGE()
|
||||||
if event == "UI_ERROR_MESSAGE" and (arg1 == ERR_INV_FULL or arg1 == ERR_ITEM_MAX_COUNT) then
|
if event == 'UI_ERROR_MESSAGE' and (arg1 == ERR_INV_FULL or arg1 == ERR_ITEM_MAX_COUNT) then
|
||||||
if this.num then
|
if this.num then
|
||||||
if arg1 == ERR_INV_FULL then
|
if arg1 == ERR_INV_FULL then
|
||||||
Postal:Inbox_Abort()
|
self:Inbox_Abort()
|
||||||
Postal:Print("Postal: Inventory full. Aborting.", 1, 0, 0)
|
self:Print('Postal: Inventory full. Aborting.', 1, 0, 0)
|
||||||
elseif arg1 == ERR_ITEM_MAX_COUNT then
|
elseif arg1 == ERR_ITEM_MAX_COUNT then
|
||||||
Postal:Print("Postal: You already have the maximum amount of that item. Skipping.", 1, 0, 0)
|
self:Print('Postal: You already have the maximum amount of that item. Skipping.', 1, 0, 0)
|
||||||
if this.lastVal then
|
if this.lastVal then
|
||||||
for key, va in this.id do
|
for key, va in this.id do
|
||||||
if va >= this.lastVal then
|
if va >= this.lastVal then
|
||||||
@@ -562,81 +624,64 @@ function Postal:Print(msg, r, g, b)
|
|||||||
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b)
|
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal_Inbox_SetSelected()
|
function Postal:Inbox_SetSelected()
|
||||||
local id = this:GetID() + (InboxFrame.pageNum - 1) * 7
|
local index = this:GetID() + (InboxFrame.pageNum - 1) * 7
|
||||||
if not this:GetChecked() then
|
self.Inbox_selectedItems[index] = this:GetChecked()
|
||||||
for k, v in Postal_SelectedItems do
|
|
||||||
if v == id then
|
|
||||||
tremove(Postal_SelectedItems, k)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
tinsert(Postal_SelectedItems, id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal_Inbox_OpenSelected(open_all)
|
function Postal:Inbox_OpenSelected(all)
|
||||||
local selected = {}
|
local selected = {}
|
||||||
if open_all then
|
if all then
|
||||||
for i = 1, GetInboxNumItems() do
|
for i = 1,GetInboxNumItems() do
|
||||||
tinsert(selected, i)
|
tinsert(selected, i)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for _, i in Postal_SelectedItems do
|
for i, _ in self.Inbox_selectedItems do
|
||||||
tinsert(selected, i)
|
tinsert(selected, i)
|
||||||
end
|
end
|
||||||
sort(selected)
|
sort(selected)
|
||||||
end
|
end
|
||||||
PostalInboxFrame.opening = true
|
self.opening = true
|
||||||
Postal:Inbox_DisableClicks()
|
self:Inbox_DisableClicks()
|
||||||
Postal.open.start(selected, function()
|
self:Inbox_OpenMail(selected)
|
||||||
PostalInboxFrame.opening = false
|
self.Inbox_selectedItems = {}
|
||||||
Postal:Inbox_DisableClicks()
|
|
||||||
end)
|
|
||||||
Postal_SelectedItems = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:InboxFrame_Update()
|
function Postal:InboxFrame_Update()
|
||||||
self.hooks["InboxFrame_Update"].orig()
|
self.hooks['InboxFrame_Update'].orig()
|
||||||
for i = 1, 7 do
|
for i = 1, 7 do
|
||||||
local index = (i + (InboxFrame.pageNum - 1) * 7)
|
local index = (i + (InboxFrame.pageNum - 1) * 7)
|
||||||
if index > GetInboxNumItems() then
|
if index > GetInboxNumItems() then
|
||||||
getglobal("PostalBoxItem" .. i .. "CB"):Hide()
|
getglobal('PostalBoxItem'..i..'CB'):Hide()
|
||||||
else
|
else
|
||||||
getglobal("PostalBoxItem" .. i .. "CB"):Show()
|
getglobal('PostalBoxItem'..i..'CB'):Show()
|
||||||
getglobal("PostalBoxItem" .. i .. "CB"):SetChecked(nil)
|
getglobal('PostalBoxItem'..i..'CB'):SetChecked(self.Inbox_selectedItems[index])
|
||||||
for k, v in Postal_SelectedItems do
|
|
||||||
if v == index then
|
|
||||||
getglobal("PostalBoxItem" .. i .. "CB"):SetChecked(1)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Postal:Inbox_DisableClicks()
|
self:Inbox_DisableClicks()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:Inbox_DisableClicks()
|
function Postal:Inbox_DisableClicks()
|
||||||
for i=1,7 do
|
for i=1,7 do
|
||||||
getglobal('MailItem'..i..'ButtonIcon'):SetDesaturated(PostalInboxFrame.opening)
|
getglobal('MailItem'..i..'ButtonIcon'):SetDesaturated(self.opening)
|
||||||
if PostalInboxFrame.opening then
|
if self.opening then
|
||||||
getglobal('MailItem'..i..'Button'):SetChecked(nil)
|
getglobal('MailItem'..i..'Button'):SetChecked(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:InboxFrame_OnClick(index)
|
function Postal:InboxFrame_OnClick(index)
|
||||||
if PostalInboxFrame.opening then
|
if self.opening then
|
||||||
this:SetChecked(nil)
|
this:SetChecked(nil)
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
return self.hooks['InboxFrame_OnClick'].orig(index)
|
||||||
end
|
end
|
||||||
self.hooks['InboxFrame_OnClick'].orig(index)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:Inbox_Abort()
|
function Postal:Inbox_Abort()
|
||||||
Postal.open.stop()
|
self.state = nil
|
||||||
PostalInboxFrame.opening = false
|
self.opening = false
|
||||||
Postal:Inbox_DisableClicks()
|
self:Inbox_DisableClicks()
|
||||||
Postal_SelectedItems = {}
|
self.Inbox_selectedItems = {}
|
||||||
end
|
end
|
||||||
@@ -10,6 +10,3 @@ libs\AceEvent\AceEvent-2.0.lua
|
|||||||
libs\AceAddon\AceAddon-2.0.lua
|
libs\AceAddon\AceAddon-2.0.lua
|
||||||
libs\AceHook\AceHook-2.0.lua
|
libs\AceHook\AceHook-2.0.lua
|
||||||
Postal.xml
|
Postal.xml
|
||||||
util.lua
|
|
||||||
control.xml
|
|
||||||
open.lua
|
|
||||||
|
|||||||
+11
-25
@@ -3,9 +3,9 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
<Script file="Postal.lua"/>
|
<Script file="Postal.lua"/>
|
||||||
<frame>
|
<frame>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnUpdate>
|
||||||
Postal_MiniMapMailFrame_Show_Orig = MiniMapMailFrame.Show
|
Postal:UPDATE()
|
||||||
</OnLoad>
|
</OnUpdate>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</frame>
|
</frame>
|
||||||
|
|
||||||
@@ -156,8 +156,8 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</OnClick>
|
</OnClick>
|
||||||
<OnEnter>
|
<OnEnter>
|
||||||
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
||||||
if this.bag and this.slot then
|
if this.item then
|
||||||
GameTooltip:SetBagItem(this.bag, this.slot)
|
GameTooltip:SetBagItem(unpack(this.item))
|
||||||
else
|
else
|
||||||
GameTooltip:SetText(ATTACHMENT_TEXT, 1.0, 1.0, 1.0)
|
GameTooltip:SetText(ATTACHMENT_TEXT, 1.0, 1.0, 1.0)
|
||||||
end
|
end
|
||||||
@@ -200,14 +200,6 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
<Button name="PostalAttachment20" parent="SendMailFrame" inherits="PostalAttachment"/>
|
<Button name="PostalAttachment20" parent="SendMailFrame" inherits="PostalAttachment"/>
|
||||||
<Button name="PostalAttachment21" parent="SendMailFrame" inherits="PostalAttachment"/>
|
<Button name="PostalAttachment21" parent="SendMailFrame" inherits="PostalAttachment"/>
|
||||||
|
|
||||||
<Frame name="PostalFrame" parent="MailFrame" hidden="true">
|
|
||||||
<Size>
|
|
||||||
<AbsDimension x="384" y="512"/>
|
|
||||||
</Size>
|
|
||||||
</Frame>
|
|
||||||
|
|
||||||
<Frame name="PostalInboxFrame" parent="UIParent">
|
|
||||||
</Frame>
|
|
||||||
<CheckButton name="PostalBoxItemCBTemplate" hidden="true" virtual="true" inherits="OptionsCheckButtonTemplate">
|
<CheckButton name="PostalBoxItemCBTemplate" hidden="true" virtual="true" inherits="OptionsCheckButtonTemplate">
|
||||||
<HitRectInsets>
|
<HitRectInsets>
|
||||||
<AbsInset left="0" right="0" top="0" bottom="0"/>
|
<AbsInset left="0" right="0" top="0" bottom="0"/>
|
||||||
@@ -224,10 +216,11 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
Postal_Inbox_SetSelected()
|
Postal:Inbox_SetSelected()
|
||||||
</OnClick>
|
</OnClick>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</CheckButton>
|
</CheckButton>
|
||||||
|
|
||||||
<CheckButton name="PostalBoxItem1CB" id="1" hidden="true" parent="MailItem1" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem1CB" id="1" hidden="true" parent="MailItem1" inherits="PostalBoxItemCBTemplate"/>
|
||||||
<CheckButton name="PostalBoxItem2CB" id="2" hidden="true" parent="MailItem2" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem2CB" id="2" hidden="true" parent="MailItem2" inherits="PostalBoxItemCBTemplate"/>
|
||||||
<CheckButton name="PostalBoxItem3CB" id="3" hidden="true" parent="MailItem3" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem3CB" id="3" hidden="true" parent="MailItem3" inherits="PostalBoxItemCBTemplate"/>
|
||||||
@@ -235,6 +228,7 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
<CheckButton name="PostalBoxItem5CB" id="5" hidden="true" parent="MailItem5" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem5CB" id="5" hidden="true" parent="MailItem5" inherits="PostalBoxItemCBTemplate"/>
|
||||||
<CheckButton name="PostalBoxItem6CB" id="6" hidden="true" parent="MailItem6" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem6CB" id="6" hidden="true" parent="MailItem6" inherits="PostalBoxItemCBTemplate"/>
|
||||||
<CheckButton name="PostalBoxItem7CB" id="7" hidden="true" parent="MailItem7" inherits="PostalBoxItemCBTemplate"/>
|
<CheckButton name="PostalBoxItem7CB" id="7" hidden="true" parent="MailItem7" inherits="PostalBoxItemCBTemplate"/>
|
||||||
|
|
||||||
<Button name="PostalInboxOpenSelected" parent="InboxFrame" inherits="UIPanelButtonTemplate" text="Open Selected">
|
<Button name="PostalInboxOpenSelected" parent="InboxFrame" inherits="UIPanelButtonTemplate" text="Open Selected">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="120" y="25"/>
|
<AbsDimension x="120" y="25"/>
|
||||||
@@ -248,10 +242,11 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
Postal_Inbox_OpenSelected()
|
Postal:Inbox_OpenSelected()
|
||||||
</OnClick>
|
</OnClick>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button name="PostalInboxOpenAllButton" parent="InboxFrame" inherits="UIPanelButtonTemplate" text="Open All">
|
<Button name="PostalInboxOpenAllButton" parent="InboxFrame" inherits="UIPanelButtonTemplate" text="Open All">
|
||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="120" y="25"/>
|
<AbsDimension x="120" y="25"/>
|
||||||
@@ -265,17 +260,8 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
Postal_Inbox_OpenSelected(true)
|
Postal:Inbox_OpenSelected(true)
|
||||||
</OnClick>
|
</OnClick>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Frame name="PostalGlobalFrame" parent="UIParent" hidden="true">
|
|
||||||
<Scripts>
|
|
||||||
<OnUpdate>
|
|
||||||
Postal:ProcessQueue(arg1)
|
|
||||||
</OnUpdate>
|
|
||||||
</Scripts>
|
|
||||||
</Frame>
|
|
||||||
<GameTooltip name="PostalTooltip" inherits="GameTooltipTemplate"></GameTooltip>
|
|
||||||
</Ui>
|
</Ui>
|
||||||
|
|||||||
-147
@@ -1,147 +0,0 @@
|
|||||||
Postal.control = {}
|
|
||||||
|
|
||||||
local event_listeners = {}
|
|
||||||
local update_listeners = {}
|
|
||||||
|
|
||||||
function Postal.control.on_event()
|
|
||||||
for listener, _ in pairs(event_listeners) do
|
|
||||||
if event == listener.event and not listener.deleted then
|
|
||||||
listener.action()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.control.on_update()
|
|
||||||
event_listeners = Postal.util.set_filter(event_listeners, function(l) return not l.deleted end)
|
|
||||||
update_listeners = Postal.util.set_filter(update_listeners, function(l) return not l.deleted end)
|
|
||||||
|
|
||||||
for listener, _ in pairs(update_listeners) do
|
|
||||||
if not listener.deleted then
|
|
||||||
listener.action()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Postal.control.event_listener(event, action)
|
|
||||||
local self = {}
|
|
||||||
|
|
||||||
local listener = { event=event, action=action }
|
|
||||||
|
|
||||||
function self.set_action(action)
|
|
||||||
listener.action = action
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.start()
|
|
||||||
Postal.util.set_add(event_listeners, listener)
|
|
||||||
if not Postal.util.any(event_listeners, function(l) return l.event == event end) then
|
|
||||||
PostalControlFrame:RegisterEvent(event)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.stop()
|
|
||||||
listener.deleted = true
|
|
||||||
if not Postal.util.any(event_listeners, function(l) return l.event == event end) then
|
|
||||||
PostalControlFrame:UnregisterEvent(event)
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.control.update_listener(action)
|
|
||||||
local self = {}
|
|
||||||
|
|
||||||
local listener = { action=action }
|
|
||||||
|
|
||||||
function self.set_action(action)
|
|
||||||
listener.action = action
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.start()
|
|
||||||
Postal.util.set_add(update_listeners, listener)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.stop()
|
|
||||||
listener.deleted = true
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Postal.control.on_next_update(callback)
|
|
||||||
local listener = Postal.control.update_listener()
|
|
||||||
|
|
||||||
listener.set_action(function()
|
|
||||||
listener:stop()
|
|
||||||
return callback()
|
|
||||||
end)
|
|
||||||
|
|
||||||
listener.start()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.control.on_next_event(event, callback)
|
|
||||||
local listener = Postal.control.event_listener(event)
|
|
||||||
|
|
||||||
listener.set_action(function()
|
|
||||||
listener:stop()
|
|
||||||
return callback()
|
|
||||||
end)
|
|
||||||
|
|
||||||
listener.start()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.control.as_soon_as(p, callback)
|
|
||||||
local listener = Postal.control.update_listener()
|
|
||||||
|
|
||||||
listener.set_action(function()
|
|
||||||
if p() then
|
|
||||||
listener.stop()
|
|
||||||
return callback()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
listener.start()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Postal.control.controller()
|
|
||||||
local self = {}
|
|
||||||
|
|
||||||
local state
|
|
||||||
|
|
||||||
local listener = Postal.control.update_listener()
|
|
||||||
listener.set_action(function()
|
|
||||||
if state and state.p() then
|
|
||||||
local k = state.k
|
|
||||||
state = nil
|
|
||||||
return k()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
listener.start()
|
|
||||||
|
|
||||||
function self.wait(p, k)
|
|
||||||
state = {
|
|
||||||
k = k,
|
|
||||||
p = p,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.reset()
|
|
||||||
state = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.cleanup()
|
|
||||||
listener.stop()
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
|
|
||||||
|
|
||||||
<Script file="control.lua"/>
|
|
||||||
|
|
||||||
<Frame name="PostalControlFrame">
|
|
||||||
<Scripts>
|
|
||||||
<OnEvent>
|
|
||||||
Postal.control.on_event()
|
|
||||||
</OnEvent>
|
|
||||||
<OnUpdate>
|
|
||||||
Postal.control.on_update()
|
|
||||||
</OnUpdate>
|
|
||||||
</Scripts>
|
|
||||||
</Frame>
|
|
||||||
</Ui>
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
Postal.open = {}
|
|
||||||
|
|
||||||
local wait_for_update, open, process, stop
|
|
||||||
|
|
||||||
local controller = (function()
|
|
||||||
local controller
|
|
||||||
return function()
|
|
||||||
controller = controller or Postal.control.controller()
|
|
||||||
return controller
|
|
||||||
end
|
|
||||||
end)()
|
|
||||||
|
|
||||||
function wait_for_update(k)
|
|
||||||
return controller().wait(function() return true end, k)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.open.start(selected, callback)
|
|
||||||
controller().wait(function()
|
|
||||||
process(selected, function()
|
|
||||||
callback()
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.open.stop()
|
|
||||||
controller().wait(function() end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function process(selected, k)
|
|
||||||
if getn(selected) == 0 then
|
|
||||||
return k()
|
|
||||||
else
|
|
||||||
local index = selected[1]
|
|
||||||
|
|
||||||
local inbox_count = GetInboxNumItems()
|
|
||||||
open(index, inbox_count, function(skipped)
|
|
||||||
tremove(selected, 1)
|
|
||||||
if not skipped then
|
|
||||||
for i, _ in ipairs(selected) do
|
|
||||||
selected[i] = selected[i] - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return process(selected, k)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function open(i, inbox_count, k)
|
|
||||||
wait_for_update(function()
|
|
||||||
local _, _, _, _, money, COD_amount, _, has_item = GetInboxHeaderInfo(i)
|
|
||||||
if GetInboxNumItems() < inbox_count then
|
|
||||||
return k(false)
|
|
||||||
elseif COD_amount > 0 then
|
|
||||||
return k(true)
|
|
||||||
elseif has_item then
|
|
||||||
TakeInboxItem(i)
|
|
||||||
controller().wait(function() return not ({GetInboxHeaderInfo(i)})[8] or GetInboxNumItems() < inbox_count end, function()
|
|
||||||
return open(i, inbox_count, k)
|
|
||||||
end)
|
|
||||||
elseif money > 0 then
|
|
||||||
TakeInboxMoney(i)
|
|
||||||
controller().wait(function() return ({GetInboxHeaderInfo(i)})[5] == 0 or GetInboxNumItems() < inbox_count end, function()
|
|
||||||
return open(i, inbox_count, k)
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
DeleteInboxItem(i)
|
|
||||||
controller().wait(function() return GetInboxNumItems() < inbox_count end, function()
|
|
||||||
return open(i, inbox_count, k)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
Postal.util = {}
|
|
||||||
|
|
||||||
function Postal.util.set_add(set, key)
|
|
||||||
set[key] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.set_remove(set, key)
|
|
||||||
set[key] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.set_contains(set, key)
|
|
||||||
return set[key] ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.set_size(set)
|
|
||||||
local size = 0
|
|
||||||
for _,_ in pairs(set) do
|
|
||||||
size = size + 1
|
|
||||||
end
|
|
||||||
return size
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.set_to_array(set)
|
|
||||||
local array = {}
|
|
||||||
for element, _ in pairs(set) do
|
|
||||||
tinsert(array, element)
|
|
||||||
end
|
|
||||||
return array
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.any(xs, p)
|
|
||||||
holds = false
|
|
||||||
for _, x in ipairs(xs) do
|
|
||||||
holds = holds or p(x)
|
|
||||||
end
|
|
||||||
return holds
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.all(xs, p)
|
|
||||||
holds = true
|
|
||||||
for _, x in ipairs(xs) do
|
|
||||||
holds = holds and p(x)
|
|
||||||
end
|
|
||||||
return holds
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.set_filter(xs, p)
|
|
||||||
ys = {}
|
|
||||||
for x, _ in pairs(xs) do
|
|
||||||
if p(x) then
|
|
||||||
Postal.util.set_add(ys, x)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ys
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.filter(xs, p)
|
|
||||||
ys = {}
|
|
||||||
for _, x in ipairs(xs) do
|
|
||||||
if p(x) then
|
|
||||||
tinsert(ys, x)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ys
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.map(xs, f)
|
|
||||||
ys = {}
|
|
||||||
for _, x in ipairs(xs) do
|
|
||||||
tinsert(ys, f(x))
|
|
||||||
end
|
|
||||||
return ys
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal.util.take(n, xs)
|
|
||||||
ys = {}
|
|
||||||
for i=1,n do
|
|
||||||
if xs[i] then
|
|
||||||
tinsert(ys, xs[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ys
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user