massive refactoring
This commit is contained in:
+265
-285
@@ -1,5 +1,126 @@
|
||||
Postal = AceLibrary('AceAddon-2.0'):new('AceEvent-2.0', 'AceHook-2.0')
|
||||
Postal.open, Postal.send = {}, {}
|
||||
|
||||
local ATTACHMENTS_MAX = 21
|
||||
local ATTACHMENTS_PER_ROW_SEND = 7
|
||||
local ATTACHMENTS_MAX_ROWS_SEND = 3
|
||||
|
||||
do
|
||||
local state
|
||||
function Postal:UPDATE()
|
||||
if state and state.p() then
|
||||
local callback = state.callback
|
||||
state = nil
|
||||
return callback()
|
||||
end
|
||||
|
||||
if self.Send_State and self.Send_Ready then
|
||||
self.Send_Ready = nil
|
||||
self:Send_SendMail()
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:When(p, callback)
|
||||
state = {
|
||||
p = p,
|
||||
callback = callback,
|
||||
}
|
||||
end
|
||||
|
||||
function Postal:Wait(callback)
|
||||
state = {
|
||||
p = function() return true end,
|
||||
callback = callback,
|
||||
}
|
||||
end
|
||||
|
||||
function Postal:Kill()
|
||||
state = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:OnEnable()
|
||||
self:RegisterEvent('UI_ERROR_MESSAGE')
|
||||
self:RegisterEvent('MAIL_SEND_SUCCESS')
|
||||
self:RegisterEvent('MAIL_CLOSED')
|
||||
self:RegisterEvent('CURSOR_UPDATE')
|
||||
|
||||
self:Hook('ContainerFrameItemButton_OnClick')
|
||||
self:Hook('PickupContainerItem')
|
||||
self:Hook('UseContainerItem')
|
||||
self:Hook('ClickSendMailItemButton')
|
||||
self:Hook('SendMailFrame_Update')
|
||||
self:Hook('SendMailFrame_CanSend')
|
||||
self:Hook('SetItemButtonDesaturated')
|
||||
self:Hook('InboxFrame_OnClick')
|
||||
self:Hook('InboxFrameItem_OnEnter')
|
||||
self:Hook('InboxFrame_Update')
|
||||
|
||||
SendMailFrame:CreateTexture('PostalHorizontalBarLeft', 'BACKGROUND')
|
||||
PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
||||
PostalHorizontalBarLeft:SetWidth(256)
|
||||
PostalHorizontalBarLeft:SetHeight(16)
|
||||
PostalHorizontalBarLeft:SetTexCoord(0, 1, 0, 0.25)
|
||||
SendMailFrame:CreateTexture('PostalHorizontalBarRight', 'BACKGROUND')
|
||||
PostalHorizontalBarRight:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
||||
PostalHorizontalBarRight:SetWidth(75)
|
||||
PostalHorizontalBarRight:SetHeight(16)
|
||||
PostalHorizontalBarRight:SetTexCoord(0, 0.29296875, 0.25, 0.5)
|
||||
PostalHorizontalBarRight:SetPoint('LEFT', PostalHorizontalBarLeft, 'RIGHT')
|
||||
|
||||
do
|
||||
local background = ({SendMailPackageButton:GetRegions()})[1]
|
||||
background:Hide()
|
||||
local count = ({SendMailPackageButton:GetRegions()})[3]
|
||||
count:Hide()
|
||||
SendMailPackageButton:Disable()
|
||||
SendMailPackageButton:SetScript('OnReceiveDrag', nil)
|
||||
SendMailPackageButton:SetScript('OnDragStart', nil)
|
||||
end
|
||||
|
||||
do
|
||||
SendMailMoneyText:SetPoint('TOPLEFT', 0, -2)
|
||||
SendMailMoney:ClearAllPoints()
|
||||
SendMailMoney:SetPoint('TOPLEFT', SendMailMoneyText, 'BOTTOMLEFT', 5, -3)
|
||||
SendMailSendMoneyButton:SetPoint('TOPLEFT', SendMailMoney, 'TOPRIGHT', 0, 12)
|
||||
end
|
||||
|
||||
PostalMailButton:SetScript('OnClick', function()
|
||||
local attachments = self:Send_Attachments()
|
||||
self.Send_State = {
|
||||
first = true,
|
||||
to = SendMailNameEditBox:GetText(),
|
||||
subject = PostalSubjectEditBox:GetText(),
|
||||
body = SendMailBodyEditBox:GetText(),
|
||||
money = MoneyInputFrame_GetCopper(SendMailMoney),
|
||||
cod = SendMailCODButton:GetChecked(),
|
||||
attachments = attachments,
|
||||
total = getn(attachments),
|
||||
}
|
||||
|
||||
self:Send_Clear()
|
||||
SendMailFrame_Update()
|
||||
end)
|
||||
|
||||
-- hack to avoid automatic subject setting/button enabling
|
||||
SendMailMailButton:Hide()
|
||||
SendMailSubjectEditBox:Hide()
|
||||
SendMailSubjectEditBox.SetText = function(self, text) PostalSubjectEditBox:SetText(text) end
|
||||
SendMailNameEditBox:SetScript('OnTabPressed', function()
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
end)
|
||||
SendMailNameEditBox:SetScript('OnEnterPressed', function()
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
end)
|
||||
SendMailBodyEditBox:SetScript('OnTabPressed', function()
|
||||
if IsShiftKeyDown() then
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
else
|
||||
SendMailMoneyGold:SetFocus()
|
||||
end
|
||||
end)
|
||||
|
||||
SendMailFrame_Update()
|
||||
end
|
||||
|
||||
function Postal:OnInitialize()
|
||||
|
||||
@@ -23,40 +144,34 @@ function Postal:OnInitialize()
|
||||
getglobal('MailItem' .. i):SetWidth(280)
|
||||
end
|
||||
|
||||
ATTACHMENTS_MAX = 21
|
||||
ATTACHMENTS_PER_ROW_SEND = 7
|
||||
ATTACHMENTS_MAX_ROWS_SEND = 3
|
||||
|
||||
Postal_MiniMapMailFrame_Show_Orig = MiniMapMailFrame.Show
|
||||
|
||||
self.Inbox_selectedItems = {}
|
||||
Postal.Send_Ready = true
|
||||
|
||||
CreateFrame('GameTooltip', 'PostalTooltip', nil, 'GameTooltipTemplate')
|
||||
PostalTooltip:SetOwner(WorldFrame, 'ANCHOR_NONE')
|
||||
|
||||
self.MiniMapMailFrame_Show_Orig = MiniMapMailFrame.Show
|
||||
|
||||
self.Inbox_selectedItems = {}
|
||||
self.Send_Ready = true
|
||||
end
|
||||
|
||||
function Postal:SendMailFrame_Update()
|
||||
|
||||
MoneyFrame_Update('SendMailCostMoneyFrame', GetSendMailPrice() * max(1, self:GetNumMails()))
|
||||
local itemCount = 0
|
||||
local itemTitle
|
||||
local gap
|
||||
-- local last = 0
|
||||
local last = self:Send_NumAttachments()
|
||||
|
||||
local itemCount = 0
|
||||
local itemTitle
|
||||
local gap
|
||||
-- local last = 0
|
||||
local last = self:GetNumMails()
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment' .. i)
|
||||
|
||||
local texture, count
|
||||
if btn.bag and btn.slot then
|
||||
texture, count = GetContainerItemInfo(btn.bag, btn.slot)
|
||||
if btn.item then
|
||||
texture, count = GetContainerItemInfo(unpack(btn.item))
|
||||
end
|
||||
if not texture then
|
||||
btn:SetNormalTexture(nil)
|
||||
getglobal(btn:GetName()..'Count'):Hide()
|
||||
btn.slot = nil
|
||||
btn.bag = nil
|
||||
btn.item = nil
|
||||
else
|
||||
btn:SetNormalTexture(texture)
|
||||
if count > 1 then
|
||||
@@ -68,6 +183,17 @@ function Postal:SendMailFrame_Update()
|
||||
end
|
||||
end
|
||||
|
||||
if self:Send_NumAttachments() > 0 then
|
||||
SendMailCODButton:Enable()
|
||||
SendMailCODButtonText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
|
||||
else
|
||||
SendMailRadioButton_OnClick(1)
|
||||
SendMailCODButton:Disable()
|
||||
SendMailCODButtonText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
|
||||
end
|
||||
|
||||
MoneyFrame_Update('SendMailCostMoneyFrame', GetSendMailPrice() * max(1, self:Send_NumAttachments()))
|
||||
|
||||
-- Determine how many rows of attachments to show
|
||||
local itemRowCount = 1
|
||||
local temp = last
|
||||
@@ -104,7 +230,6 @@ function Postal:SendMailFrame_Update()
|
||||
local taby = (icony + gapy1)
|
||||
local scrollHeight = 249 - areay
|
||||
|
||||
|
||||
PostalHorizontalBarLeft:SetPoint('TOPLEFT', SendMailFrame, 'BOTTOMLEFT', 2 + 15, 184 + areay - 14)
|
||||
|
||||
SendMailScrollFrame:SetHeight(scrollHeight)
|
||||
@@ -121,8 +246,7 @@ function Postal:SendMailFrame_Update()
|
||||
StationeryBackgroundRight:SetHeight(scrollHeight)
|
||||
StationeryBackgroundRight:SetTexCoord(0, 1.0, 0, scrollHeight / 256)
|
||||
|
||||
|
||||
-- Set Items
|
||||
-- Set Items
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
if cursory >= 0 then
|
||||
getglobal('PostalAttachment'..i):Enable()
|
||||
@@ -138,116 +262,19 @@ function Postal:SendMailFrame_Update()
|
||||
getglobal('PostalAttachment'..i):Hide()
|
||||
end
|
||||
end
|
||||
for i=ATTACHMENTS_MAX+1,ATTACHMENTS_MAX do
|
||||
getglobal('PostalAttachment'..i):Hide()
|
||||
end
|
||||
|
||||
if self:GetNumMails() > 0 then
|
||||
SendMailCODButton:Enable()
|
||||
SendMailCODButtonText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
|
||||
else
|
||||
SendMailRadioButton_OnClick(1)
|
||||
SendMailCODButton:Disable()
|
||||
SendMailCODButtonText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
|
||||
end
|
||||
|
||||
Postal:SendMailFrame_CanSend()
|
||||
end
|
||||
|
||||
function Postal:OnEnable()
|
||||
self:RegisterEvent('UI_ERROR_MESSAGE')
|
||||
self:RegisterEvent('MAIL_SEND_SUCCESS')
|
||||
self:RegisterEvent('MAIL_CLOSED')
|
||||
self:RegisterEvent('CURSOR_UPDATE')
|
||||
|
||||
self:Hook('ContainerFrameItemButton_OnClick')
|
||||
self:Hook('PickupContainerItem')
|
||||
self:Hook('UseContainerItem')
|
||||
self:Hook('ClickSendMailItemButton')
|
||||
self:Hook('SendMailFrame_Update')
|
||||
self:Hook('SendMailFrame_CanSend')
|
||||
self:Hook('SetItemButtonDesaturated')
|
||||
self:Hook('InboxFrame_OnClick')
|
||||
self:Hook('InboxFrameItem_OnEnter')
|
||||
self:Hook('InboxFrame_Update')
|
||||
|
||||
SendMailFrame:CreateTexture('PostalHorizontalBarLeft', 'BACKGROUND')
|
||||
PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
||||
PostalHorizontalBarLeft:SetWidth(256)
|
||||
PostalHorizontalBarLeft:SetHeight(16)
|
||||
PostalHorizontalBarLeft:SetTexCoord(0, 1, 0, 0.25)
|
||||
SendMailFrame:CreateTexture('PostalHorizontalBarRight', 'BACKGROUND')
|
||||
PostalHorizontalBarRight:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
||||
PostalHorizontalBarRight:SetWidth(75)
|
||||
PostalHorizontalBarRight:SetHeight(16)
|
||||
PostalHorizontalBarRight:SetTexCoord(0, 0.29296875, 0.25, 0.5)
|
||||
PostalHorizontalBarRight:SetPoint('LEFT', PostalHorizontalBarLeft, 'RIGHT')
|
||||
|
||||
do
|
||||
local background = ({SendMailPackageButton:GetRegions()})[1]
|
||||
background:Hide()
|
||||
local count = ({SendMailPackageButton:GetRegions()})[3]
|
||||
count:Hide()
|
||||
SendMailPackageButton:Disable()
|
||||
SendMailPackageButton:SetScript('OnReceiveDrag', nil)
|
||||
SendMailPackageButton:SetScript('OnDragStart', nil)
|
||||
end
|
||||
|
||||
do
|
||||
SendMailMoneyText:SetPoint('TOPLEFT', 0, -2)
|
||||
SendMailMoney:ClearAllPoints()
|
||||
SendMailMoney:SetPoint('TOPLEFT', SendMailMoneyText, 'BOTTOMLEFT', 5, -3)
|
||||
SendMailSendMoneyButton:SetPoint('TOPLEFT', SendMailMoney, 'TOPRIGHT', 0, 12)
|
||||
end
|
||||
|
||||
PostalMailButton:SetScript('OnClick', function()
|
||||
local attachments = self:AttachmentList()
|
||||
self.Send_State = {
|
||||
first = true,
|
||||
to = SendMailNameEditBox:GetText(),
|
||||
subject = PostalSubjectEditBox:GetText(),
|
||||
body = SendMailBodyEditBox:GetText(),
|
||||
money = MoneyInputFrame_GetCopper(SendMailMoney),
|
||||
cod = SendMailCODButton:GetChecked(),
|
||||
attachments = attachments,
|
||||
total = getn(attachments),
|
||||
}
|
||||
|
||||
self:SendMail_Clear()
|
||||
self:SendMailFrame_Update()
|
||||
end)
|
||||
|
||||
-- hack to avoid automatic subject setting/button enabling
|
||||
SendMailMailButton:Hide()
|
||||
SendMailSubjectEditBox:Hide()
|
||||
SendMailSubjectEditBox.SetText = function(self, text) PostalSubjectEditBox:SetText(text) end
|
||||
SendMailNameEditBox:SetScript('OnTabPressed', function()
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
end)
|
||||
SendMailNameEditBox:SetScript('OnEnterPressed', function()
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
end)
|
||||
SendMailBodyEditBox:SetScript('OnTabPressed', function()
|
||||
if IsShiftKeyDown() then
|
||||
PostalSubjectEditBox:SetFocus()
|
||||
else
|
||||
SendMailMoneyGold:SetFocus()
|
||||
end
|
||||
end)
|
||||
|
||||
SendMailFrame_Update()
|
||||
self:SendMailFrame_CanSend()
|
||||
end
|
||||
|
||||
function Postal:MAIL_CLOSED()
|
||||
self.Send_State = nil
|
||||
self:Inbox_Abort()
|
||||
self:SendMail_Clear()
|
||||
self:Send_Clear()
|
||||
|
||||
-- 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.
|
||||
for i=1,GetInboxNumItems() do
|
||||
local wasRead = ({ GetInboxHeaderInfo(i) })[9]
|
||||
if not wasRead then
|
||||
if not ({GetInboxHeaderInfo(i)})[9] then
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -256,14 +283,14 @@ function Postal:MAIL_CLOSED()
|
||||
local t = GetTime()
|
||||
MiniMapMailFrame.Show = function()
|
||||
if GetTime() - t > 2 then
|
||||
MiniMapMailFrame.Show = Postal_MiniMapMailFrame_Show_Orig
|
||||
MiniMapMailFrame.Show = self.MiniMapMailFrame_Show_Orig
|
||||
MiniMapMailFrame:Show()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:MAIL_SEND_SUCCESS()
|
||||
Postal.Send_Ready = true
|
||||
function Postal:MAIL_SEND_SUCCESS()
|
||||
self.Send_Ready = true
|
||||
end
|
||||
|
||||
function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
||||
@@ -275,44 +302,69 @@ function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:Send_Attached(item)
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment' .. i)
|
||||
if btn.item and btn.item[1] == item[1] and btn.item[2] == item[2] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
if not self.Send_State then
|
||||
return
|
||||
end
|
||||
for _, attachment in self.Send_State.attachments do
|
||||
if attachment.item and attachment.item[1] == item[1] and attachment.item[2] == item[2] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:AttachmentButton_OnClick()
|
||||
local buttonItem = this.item
|
||||
local cursorItem = self:CursorItem()
|
||||
|
||||
if cursorItem then
|
||||
ClearCursor()
|
||||
if not self:Send_Mailable(cursorItem) then
|
||||
return self:Print('Postal: Cannot attach item.', 1, 0.5, 0)
|
||||
end
|
||||
this.item = cursorItem
|
||||
end
|
||||
|
||||
if buttonItem then
|
||||
this.item = nil
|
||||
PickupContainerItem(unpack(buttonItem))
|
||||
end
|
||||
|
||||
SendMailFrame_Update()
|
||||
end
|
||||
|
||||
-- requires an item lock changed event for a proper update
|
||||
function Postal:Send_AttachItem(item)
|
||||
for i = 1,ATTACHMENTS_MAX do
|
||||
if not getglobal('PostalAttachment'..i).item then
|
||||
if not self:ItemIsMailable(item) then
|
||||
if not self:Send_Mailable(item) then
|
||||
return self:Print('Postal: Cannot attach item.', 1, 0.5, 0)
|
||||
end
|
||||
end
|
||||
getglobal('PostalAttachment'..i).item = item
|
||||
return SendMailFrame_Update()
|
||||
SendMailFrame_Update()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local last_picked_up
|
||||
-- handle the weird built-in mail body textbox onclick
|
||||
function Postal:ClickSendMailItemButton()
|
||||
self:Send_AttachItem(self:CursorItem())
|
||||
ClearCursor()
|
||||
end
|
||||
|
||||
function Postal:CURSOR_UPDATE()
|
||||
Aux.log(tostring(last_picked_up))
|
||||
last_picked_up = nil
|
||||
function Postal:SetItemButtonDesaturated(itemButton, locked)
|
||||
local item = { itemButton:GetParent():GetID(), itemButton:GetID() }
|
||||
if self:Send_Attached(item) then
|
||||
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, true)
|
||||
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
|
||||
end
|
||||
if not CursorHasItem() then
|
||||
self:Wait(function()
|
||||
last_picked_up = item
|
||||
end)
|
||||
end
|
||||
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||
end
|
||||
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, locked)
|
||||
end
|
||||
|
||||
function Postal:UseContainerItem(bag, slot)
|
||||
@@ -322,13 +374,12 @@ function Postal:UseContainerItem(bag, slot)
|
||||
end
|
||||
|
||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
|
||||
return self.hooks['UseContainerItem'].orig(unpack(item))
|
||||
end
|
||||
|
||||
if SendMailFrame:IsVisible() and not CursorHasItem() then
|
||||
self.hooks['UseContainerItem'].orig(unpack(item))
|
||||
elseif SendMailFrame:IsVisible() then
|
||||
self:Send_AttachItem(item)
|
||||
return
|
||||
elseif TradeFrame:IsVisible() and not CursorHasItem() then
|
||||
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||
ClearCursor()
|
||||
elseif TradeFrame:IsVisible() then
|
||||
for i = 1,6 do
|
||||
if not GetTradePlayerItemLink(i) then
|
||||
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||
@@ -336,37 +387,35 @@ function Postal:UseContainerItem(bag, slot)
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
self.hooks['UseContainerItem'].orig(unpack(item))
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local lastPickedUp
|
||||
|
||||
function Postal:CURSOR_UPDATE()
|
||||
lastPickedUp = nil
|
||||
end
|
||||
|
||||
self.hooks['UseContainerItem'].orig(unpack(item))
|
||||
end
|
||||
function Postal:CursorItem()
|
||||
return CursorHasItem() and lastPickedUp
|
||||
end
|
||||
|
||||
-- Handle the dragging of items
|
||||
function Postal:AttachmentButton_OnClick(button)
|
||||
button = button or this
|
||||
local buttonItem = button.item
|
||||
local cursorItem = self:CursorItem()
|
||||
if cursorItem then
|
||||
if not self:ItemIsMailable(unpack(cursorItem)) then
|
||||
self:Print('Postal: Cannot attach item.', 1, 0.5, 0)
|
||||
ClearCursor()
|
||||
function Postal:PickupContainerItem(bag, slot)
|
||||
local item = {bag, slot}
|
||||
if self:Send_Attached(item) then
|
||||
return
|
||||
end
|
||||
|
||||
button.item = cursorItem
|
||||
ClearCursor() -- triggers lock changed event to update the bag frame
|
||||
else
|
||||
button.item = nil
|
||||
self:Wait(function()
|
||||
lastPickedUp = item
|
||||
end)
|
||||
return self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||
end
|
||||
|
||||
if buttonItem then
|
||||
PickupContainerItem(unpack(buttonItem))
|
||||
end
|
||||
SendMailFrame_Update()
|
||||
end
|
||||
|
||||
function Postal:ItemIsMailable(item)
|
||||
-- Make sure tooltip is cleared
|
||||
function Postal:Send_Mailable(item)
|
||||
-- PostalTooltip:ClearLines() TODO
|
||||
PostalTooltip:SetBagItem(unpack(item))
|
||||
for i=1,PostalTooltip:NumLines() do
|
||||
@@ -378,41 +427,30 @@ function Postal:ItemIsMailable(item)
|
||||
return true
|
||||
end
|
||||
|
||||
function Postal:Send_Attached(item)
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment' .. i)
|
||||
if btn.item and btn.item[1] == item[1] and btn.item[2] == item[2] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if not self.Send_State then
|
||||
return
|
||||
end
|
||||
|
||||
for _, attachment in self.Send_State.attachments do
|
||||
if attachment.item[1] == item[1] and attachment.item[2] == item[2] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:GetNumMails()
|
||||
function Postal:Send_NumAttachments()
|
||||
local num = 0
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment'..i)
|
||||
if btn.item then
|
||||
if getglobal('PostalAttachment'..i).item then
|
||||
num = num + 1
|
||||
end
|
||||
end
|
||||
return num
|
||||
end
|
||||
|
||||
function Postal:SendMail_Clear()
|
||||
local num = 0
|
||||
function Postal:Send_Attachments()
|
||||
local arr = {}
|
||||
for i = 1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment' .. i)
|
||||
if btn.item then
|
||||
tinsert(arr, btn.item)
|
||||
end
|
||||
end
|
||||
return arr
|
||||
end
|
||||
|
||||
function Postal:Send_Clear()
|
||||
for i=1,ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment'..i)
|
||||
btn.item = nil
|
||||
getglobal('PostalAttachment'..i).item = nil
|
||||
end
|
||||
PostalMailButton:Disable()
|
||||
SendMailNameEditBox:SetText('')
|
||||
@@ -424,25 +462,14 @@ function Postal:SendMail_Clear()
|
||||
end
|
||||
|
||||
function Postal:SendMailFrame_CanSend()
|
||||
if strlen(SendMailNameEditBox:GetText()) > 0 and (SendMailSendMoneyButton:GetChecked() and MoneyInputFrame_GetCopper(SendMailMoney) or 0) + GetSendMailPrice() * self:GetNumMails() <= GetMoney() then
|
||||
if strlen(SendMailNameEditBox:GetText()) > 0 and (SendMailSendMoneyButton:GetChecked() and MoneyInputFrame_GetCopper(SendMailMoney) or 0) + GetSendMailPrice() * max(1, self:Send_NumAttachments()) <= GetMoney() then
|
||||
PostalMailButton:Enable()
|
||||
else
|
||||
PostalMailButton:Disable()
|
||||
end
|
||||
end
|
||||
|
||||
-- handle the weird built-in mail body textbox onclick
|
||||
function Postal:ClickSendMailItemButton()
|
||||
ClearCursor()
|
||||
self:When(function() return not ({GetContainerItemInfo(unpack(self:CursorItem()))})[3] end, function()
|
||||
if self:CursorItem() then
|
||||
self:Send_AttachItem(self:CursorItem())
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Postal:Send_SendMail()
|
||||
|
||||
local item = tremove(self.Send_State.attachments, 1)
|
||||
|
||||
if item or self.Send_State.first then
|
||||
@@ -459,11 +486,8 @@ function Postal:Send_SendMail()
|
||||
self.hooks['PickupContainerItem'].orig(unpack(item))
|
||||
self.hooks['ClickSendMailItemButton'].orig()
|
||||
|
||||
local name, _, count = GetSendMailItem()
|
||||
|
||||
if not name then
|
||||
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)
|
||||
return
|
||||
if not GetSendMailItem() then
|
||||
return 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)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -478,52 +502,16 @@ function Postal:Send_SendMail()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return SendMail(self.Send_State.to, subject, self.Send_State.body)
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:AttachmentList()
|
||||
local arr = {}
|
||||
for i = 1, ATTACHMENTS_MAX do
|
||||
local btn = getglobal('PostalAttachment' .. i)
|
||||
if btn.item then
|
||||
tinsert(arr, btn.item)
|
||||
end
|
||||
end
|
||||
return arr
|
||||
end
|
||||
|
||||
function Postal:When(p, callback)
|
||||
self.state = {
|
||||
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
|
||||
|
||||
if self.Send_State and self.Send_Ready then
|
||||
self.Send_Ready = nil
|
||||
self:Send_SendMail()
|
||||
end
|
||||
else
|
||||
self.Send_State = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:Inbox_OpenMail(selected)
|
||||
if getn(selected) == 0 then
|
||||
self.opening = false
|
||||
self:Inbox_DisableClicks()
|
||||
self.Inbox_Opening = false
|
||||
self:Inbox_Lock()
|
||||
else
|
||||
self:Inbox_OpenItem(selected[1], GetInboxNumItems(), selected)
|
||||
end
|
||||
@@ -561,14 +549,6 @@ function Postal:Inbox_OpenItem(i, inboxCount, selected)
|
||||
end)
|
||||
end
|
||||
|
||||
function Postal:SetItemButtonDesaturated(itemButton, locked)
|
||||
local item = { itemButton:GetParent():GetID(), itemButton:GetID() }
|
||||
if self:Send_Attached(item) then
|
||||
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, true)
|
||||
end
|
||||
return self.hooks['SetItemButtonDesaturated'].orig(itemButton, locked)
|
||||
end
|
||||
|
||||
function Postal:InboxFrameItem_OnEnter()
|
||||
local didSetTooltip
|
||||
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
||||
@@ -641,15 +621,15 @@ function Postal:Inbox_OpenSelected(all)
|
||||
end
|
||||
sort(selected)
|
||||
end
|
||||
self.opening = true
|
||||
self:Inbox_DisableClicks()
|
||||
self.Inbox_Opening = true
|
||||
self:Inbox_Lock()
|
||||
self:Inbox_OpenMail(selected)
|
||||
self.Inbox_selectedItems = {}
|
||||
end
|
||||
|
||||
function Postal:InboxFrame_Update()
|
||||
self.hooks['InboxFrame_Update'].orig()
|
||||
for i = 1, 7 do
|
||||
for i = 1,7 do
|
||||
local index = (i + (InboxFrame.pageNum - 1) * 7)
|
||||
if index > GetInboxNumItems() then
|
||||
getglobal('PostalBoxItem'..i..'CB'):Hide()
|
||||
@@ -658,20 +638,20 @@ function Postal:InboxFrame_Update()
|
||||
getglobal('PostalBoxItem'..i..'CB'):SetChecked(self.Inbox_selectedItems[index])
|
||||
end
|
||||
end
|
||||
self:Inbox_DisableClicks()
|
||||
self:Inbox_Lock()
|
||||
end
|
||||
|
||||
function Postal:Inbox_DisableClicks()
|
||||
function Postal:Inbox_Lock()
|
||||
for i=1,7 do
|
||||
getglobal('MailItem'..i..'ButtonIcon'):SetDesaturated(self.opening)
|
||||
if self.opening then
|
||||
getglobal('MailItem'..i..'ButtonIcon'):SetDesaturated(self.Inbox_Opening)
|
||||
if self.Inbox_Opening then
|
||||
getglobal('MailItem'..i..'Button'):SetChecked(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Postal:InboxFrame_OnClick(index)
|
||||
if self.opening then
|
||||
if self.Inbox_Opening then
|
||||
this:SetChecked(nil)
|
||||
return
|
||||
else
|
||||
@@ -680,8 +660,8 @@ function Postal:InboxFrame_OnClick(index)
|
||||
end
|
||||
|
||||
function Postal:Inbox_Abort()
|
||||
self.state = nil
|
||||
self.opening = false
|
||||
self:Inbox_DisableClicks()
|
||||
self:Kill()
|
||||
self.Inbox_Opening = false
|
||||
self:Inbox_Lock()
|
||||
self.Inbox_selectedItems = {}
|
||||
end
|
||||
@@ -1,5 +1,4 @@
|
||||
## Interface: 11200
|
||||
## Version: 1.0
|
||||
## Title: Postal
|
||||
## Notes: Postal
|
||||
## Author: shirsig
|
||||
|
||||
+1
-10
@@ -1,7 +1,7 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
||||
<Script file="Postal.lua"/>
|
||||
<frame>
|
||||
<frame parent="MailFrame">
|
||||
<Scripts>
|
||||
<OnUpdate>
|
||||
Postal:UPDATE()
|
||||
@@ -165,15 +165,6 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
||||
<OnLeave>
|
||||
GameTooltip:Hide()
|
||||
</OnLeave>
|
||||
<!--
|
||||
<OnEnter>
|
||||
SendMailAttachment_OnEnter(self, motion);
|
||||
</OnEnter>
|
||||
<OnUpdate>
|
||||
if ( GameTooltip:IsOwned(self) ) then
|
||||
SendMailAttachment_OnEnter(self);
|
||||
end
|
||||
</OnUpdate>-->
|
||||
</Scripts>
|
||||
<HighlightTexture alphaMode="ADD" file="Interface\Buttons\ButtonHilight-Square"/>
|
||||
</Button>
|
||||
|
||||
@@ -7,7 +7,7 @@ A lightweight extension to the Blizzard mail interface which
|
||||
**\<Left Click>** or **\<Left Drag>** to add items to the attachments.<br/>
|
||||
**\<Left Click>** to add items to the trade frame. (not mail related but GMail had this shortcut and I decided to keep it)
|
||||
|
||||
There are two very similar (to eachother) old Vanilla mail addOns commonly found in collections: GMail and CT_MailMod. Both use the same terrible mechanism for automation, unnecessarily making them extremely slow, have a rather ugly send interface and don't hide the "New Mail"-notifier after opening the last mail automatically.
|
||||
There are two very similar (to eachother) old Vanilla mail addOns commonly found in collections: GMail and CT_MailMod. Both use the same terrible mechanism for automation, unnecessarily making them extremely slow, have a rather ugly send interface and don't hide the "New Mail"-notifier after Inbox_Opening the last mail automatically.
|
||||
|
||||
This addOn solves all those problems, being **super fast**, adapting the **retail send layout** and correctly **hiding the notifier**. (the problem there is actually a bug in the wow client and the notifier will reappear after doing a /reload. This cannot be prevented.)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user