refactorings
This commit is contained in:
+71
-79
@@ -17,12 +17,15 @@ function Postal:OnInitialize()
|
|||||||
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
|
||||||
|
|
||||||
POSTAL_NUMITEMBUTTONS = 21
|
ATTACHMENTS_MAX = 21
|
||||||
|
ATTACHMENTS_PER_ROW_SEND = 7
|
||||||
|
ATTACHMENTS_MAX_ROWS_SEND = 3
|
||||||
|
|
||||||
Postal_SelectedItems = {}
|
Postal_SelectedItems = {}
|
||||||
|
|
||||||
PostalGlobalFrame.sendmail = 0
|
PostalGlobalFrame.sendmail = 0
|
||||||
@@ -34,17 +37,12 @@ function Postal:SendMailFrame_Update()
|
|||||||
|
|
||||||
MoneyFrame_Update('SendMailCostMoneyFrame', GetSendMailPrice() * max(1, self:GetNumMails()))
|
MoneyFrame_Update('SendMailCostMoneyFrame', GetSendMailPrice() * max(1, self:GetNumMails()))
|
||||||
|
|
||||||
ATTACHMENTS_PER_ROW_SEND = 7
|
|
||||||
ATTACHMENTS_MAX_SEND = 21
|
|
||||||
ATTACHMENTS_MAX = 21
|
|
||||||
ATTACHMENTS_MAX_ROWS_SEND = 3
|
|
||||||
|
|
||||||
local itemCount = 0
|
local itemCount = 0
|
||||||
local itemTitle
|
local itemTitle
|
||||||
local gap
|
local gap
|
||||||
-- local last = 0
|
-- local last = 0
|
||||||
local last = self:GetNumMails()
|
local last = self:GetNumMails()
|
||||||
for i=1, ATTACHMENTS_MAX_SEND do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
local btn = getglobal('PostalAttachment' .. i)
|
local btn = getglobal('PostalAttachment' .. i)
|
||||||
|
|
||||||
local texture, count
|
local texture, count
|
||||||
@@ -122,7 +120,7 @@ function Postal:SendMailFrame_Update()
|
|||||||
|
|
||||||
|
|
||||||
-- Set Items
|
-- Set Items
|
||||||
for i=1, ATTACHMENTS_MAX_SEND 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()
|
||||||
@@ -137,7 +135,7 @@ function Postal:SendMailFrame_Update()
|
|||||||
getglobal("PostalAttachment"..i):Hide()
|
getglobal("PostalAttachment"..i):Hide()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=ATTACHMENTS_MAX_SEND+1, ATTACHMENTS_MAX do
|
for i=ATTACHMENTS_MAX+1,ATTACHMENTS_MAX do
|
||||||
getglobal("PostalAttachment"..i):Hide()
|
getglobal("PostalAttachment"..i):Hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -154,21 +152,21 @@ function Postal:SendMailFrame_Update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:OnEnable()
|
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:Hook("ContainerFrameItemButton_OnClick")
|
self:Hook('ContainerFrameItemButton_OnClick')
|
||||||
self:Hook("PickupContainerItem")
|
self:Hook('PickupContainerItem')
|
||||||
self:Hook("UseContainerItem")
|
self:Hook('UseContainerItem')
|
||||||
self:Hook("SendMailFrame_Update")
|
self:Hook('SendMailFrame_Update')
|
||||||
self:Hook('SendMailFrame_CanSend')
|
self:Hook('SendMailFrame_CanSend')
|
||||||
self:Hook("ContainerFrame_Update")
|
self:Hook('ContainerFrame_Update')
|
||||||
self:Hook("ClickSendMailItemButton")
|
self:Hook('InboxFrame_OnClick')
|
||||||
self:HookScript(TradeFrame, "OnShow", "TF_Show")
|
self:Hook('ClickSendMailItemButton')
|
||||||
self:Hook("InboxFrameItem_OnEnter")
|
self:HookScript(TradeFrame, 'OnShow', 'TF_Show')
|
||||||
self:Hook("InboxFrame_Update")
|
self:Hook('InboxFrameItem_OnEnter')
|
||||||
self:Hook("CloseMail")
|
self:Hook('InboxFrame_Update')
|
||||||
|
|
||||||
SendMailFrame:CreateTexture('PostalHorizontalBarLeft', 'BACKGROUND')
|
SendMailFrame:CreateTexture('PostalHorizontalBarLeft', 'BACKGROUND')
|
||||||
PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
|
||||||
@@ -237,12 +235,13 @@ function Postal:OnEnable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:MAIL_CLOSED()
|
function Postal:MAIL_CLOSED()
|
||||||
|
PostalGlobalFrame:Hide()
|
||||||
|
Postal:Inbox_Abort()
|
||||||
Postal:ClearItems()
|
Postal:ClearItems()
|
||||||
PostalGlobalFrame.total = 0
|
|
||||||
PostalGlobalFrame.queue = {}
|
|
||||||
-- 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.
|
||||||
for i = 1, GetInboxNumItems() do
|
for i=1,GetInboxNumItems() do
|
||||||
local wasRead = ({ GetInboxHeaderInfo(i) })[9]
|
local wasRead = ({ GetInboxHeaderInfo(i) })[9]
|
||||||
if not wasRead then
|
if not wasRead then
|
||||||
return
|
return
|
||||||
@@ -264,14 +263,15 @@ function Postal:MAIL_SEND_SUCCESS()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
function Postal:ContainerFrameItemButton_OnClick(btn, ignore)
|
||||||
if self:GetItemFrame(this:GetParent():GetID(), this:GetID()) then
|
local bag, slot = this:GetParent():GetID(), this:GetID()
|
||||||
|
if self:GetAttachmentFrame(bag, slot) or self:QueuedAttachment(bag, slot) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.hooks["ContainerFrameItemButton_OnClick"].orig(btn, ignore)
|
self.hooks["ContainerFrameItemButton_OnClick"].orig(btn, ignore)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:PickupContainerItem(bag, slot, special)
|
function Postal:PickupContainerItem(bag, slot, special)
|
||||||
if (self:GetItemFrame(bag, slot) or (Postal_addItem and Postal_addItem[1] == bag and Postal_addItem[2] == slot)) and not special then
|
if (self:GetAttachmentFrame(bag, slot) or (Postal_addItem and Postal_addItem[1] == bag and Postal_addItem[2] == slot)) and not special then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not CursorHasItem() then
|
if not CursorHasItem() then
|
||||||
@@ -286,7 +286,7 @@ function Postal:UseContainerItem(bag, slot)
|
|||||||
return self.hooks["UseContainerItem"].orig(bag, slot)
|
return self.hooks["UseContainerItem"].orig(bag, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:GetItemFrame(bag, slot) or (Postal_addItem and Postal_addItem[1] == bag and Postal_addItem[2] == slot) then
|
if self:GetAttachmentFrame(bag, slot) or (Postal_addItem and Postal_addItem[1] == bag and Postal_addItem[2] == slot) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not CursorHasItem() then
|
if not CursorHasItem() then
|
||||||
@@ -295,7 +295,7 @@ function Postal:UseContainerItem(bag, slot)
|
|||||||
end
|
end
|
||||||
if SendMailFrame:IsVisible() and not CursorHasItem() then
|
if SendMailFrame:IsVisible() and not CursorHasItem() then
|
||||||
local i
|
local i
|
||||||
for i = 1, POSTAL_NUMITEMBUTTONS do
|
for i = 1, ATTACHMENTS_MAX do
|
||||||
if not getglobal("PostalAttachment" .. i).slot then
|
if not getglobal("PostalAttachment" .. i).slot then
|
||||||
|
|
||||||
if self:ItemIsMailable(bag, slot) then
|
if self:ItemIsMailable(bag, slot) then
|
||||||
@@ -304,7 +304,7 @@ function Postal:UseContainerItem(bag, slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.hooks["PickupContainerItem"].orig(bag, slot)
|
self.hooks["PickupContainerItem"].orig(bag, slot)
|
||||||
self:MailButton_OnClick(getglobal("PostalAttachment" .. i))
|
self:AttachmentButton_OnClick(getglobal("PostalAttachment" .. i))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -339,7 +339,7 @@ function Postal:ClickSendMailItemButton()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Handle the dragging of items
|
-- Handle the dragging of items
|
||||||
function Postal:MailButton_OnClick(button)
|
function Postal:AttachmentButton_OnClick(button)
|
||||||
if not button then button = this end
|
if not button then button = this end
|
||||||
if CursorHasItem() then
|
if CursorHasItem() then
|
||||||
local bag = PostalFrame.bag
|
local bag = PostalFrame.bag
|
||||||
@@ -373,7 +373,7 @@ function Postal:MailButton_OnClick(button)
|
|||||||
button.bag = nil
|
button.bag = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1, NUM_CONTAINER_FRAMES do
|
for i=1,NUM_CONTAINER_FRAMES do
|
||||||
if getglobal("ContainerFrame" .. i):IsVisible() then
|
if getglobal("ContainerFrame" .. i):IsVisible() then
|
||||||
ContainerFrame_Update(getglobal("ContainerFrame" .. i))
|
ContainerFrame_Update(getglobal("ContainerFrame" .. i))
|
||||||
end
|
end
|
||||||
@@ -384,12 +384,12 @@ end
|
|||||||
|
|
||||||
function Postal:ItemIsMailable(bag, slot)
|
function Postal:ItemIsMailable(bag, slot)
|
||||||
-- Make sure tooltip is cleared
|
-- Make sure tooltip is cleared
|
||||||
for i = 1, 29 do
|
for i=1,29 do
|
||||||
getglobal("PostalTooltipTextLeft" .. i):SetText("")
|
getglobal("PostalTooltipTextLeft" .. i):SetText("")
|
||||||
end
|
end
|
||||||
|
|
||||||
PostalTooltip:SetBagItem(bag, slot)
|
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 1
|
return 1
|
||||||
@@ -398,21 +398,26 @@ function Postal:ItemIsMailable(bag, slot)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:GetItemFrame(bag, slot)
|
function Postal:GetAttachmentFrame(bag, slot)
|
||||||
local i
|
for i=1,ATTACHMENTS_MAX do
|
||||||
for i = 1, POSTAL_NUMITEMBUTTONS do
|
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal("PostalAttachment" .. i)
|
||||||
if btn.slot == slot and btn.bag == bag then
|
if btn.slot == slot and btn.bag == bag then
|
||||||
return btn
|
return btn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
end
|
||||||
|
|
||||||
|
function Postal:QueuedAttachment(bag, slot)
|
||||||
|
for _, attachment in ipairs(PostalGlobalFrame.queue or {}) do
|
||||||
|
if attachment.slot == slot and attachment.bag == bag then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:GetNumMails()
|
function Postal:GetNumMails()
|
||||||
local i
|
|
||||||
local num = 0
|
local num = 0
|
||||||
for i = 1, POSTAL_NUMITEMBUTTONS 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.slot and btn.bag then
|
||||||
num = num + 1
|
num = num + 1
|
||||||
@@ -422,9 +427,8 @@ function Postal:GetNumMails()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Postal:ClearItems()
|
function Postal:ClearItems()
|
||||||
local i
|
|
||||||
local num = 0
|
local num = 0
|
||||||
for i = 1, POSTAL_NUMITEMBUTTONS do
|
for i=1,ATTACHMENTS_MAX do
|
||||||
local btn = getglobal("PostalAttachment" .. i)
|
local btn = getglobal("PostalAttachment" .. i)
|
||||||
btn.slot = nil
|
btn.slot = nil
|
||||||
btn.bag = nil
|
btn.bag = nil
|
||||||
@@ -478,6 +482,7 @@ function Postal:SendMail()
|
|||||||
|
|
||||||
if not name then
|
if not name then
|
||||||
Postal:Print("Postal: " .. POSTAL_ERROR, 1, 0, 0)
|
Postal:Print("Postal: " .. POSTAL_ERROR, 1, 0, 0)
|
||||||
|
PostalGlobalFrame:Hide()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -503,7 +508,7 @@ end
|
|||||||
|
|
||||||
function Postal:AttachmentList()
|
function Postal:AttachmentList()
|
||||||
local arr = {}
|
local arr = {}
|
||||||
for i = 1, POSTAL_NUMITEMBUTTONS 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.slot and btn.bag then
|
||||||
tinsert(arr, { slot = btn.slot, bag = btn.bag })
|
tinsert(arr, { slot = btn.slot, bag = btn.bag })
|
||||||
@@ -531,7 +536,8 @@ function Postal:ContainerFrame_Update(frame)
|
|||||||
local name = frame:GetName()
|
local name = frame:GetName()
|
||||||
for j=1, frame.size, 1 do
|
for j=1, frame.size, 1 do
|
||||||
local itemButton = getglobal(name.."Item"..j)
|
local itemButton = getglobal(name.."Item"..j)
|
||||||
local locked = self:GetItemFrame(itemButton:GetParent():GetID(), itemButton:GetID()) or (Postal_addItem and Postal_addItem[1] == itemButton:GetParent():GetID() and Postal_addItem[2] == itemButton:GetID())
|
local bag, slot = itemButton:GetParent():GetID(), itemButton:GetID()
|
||||||
|
local locked = self:GetAttachmentFrame(bag, slot) or self:QueuedAttachment(bag, slot) or (Postal_addItem and Postal_addItem[1] == bag and Postal_addItem[2] == slot)
|
||||||
if locked then
|
if locked then
|
||||||
SetItemButtonDesaturated(itemButton, true, 0.5, 0.5, 0.5)
|
SetItemButtonDesaturated(itemButton, true, 0.5, 0.5, 0.5)
|
||||||
end
|
end
|
||||||
@@ -646,11 +652,11 @@ function Postal_Inbox_OpenSelected(open_all)
|
|||||||
tinsert(selected, i)
|
tinsert(selected, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Postal:Inbox_DisableClicks(true)
|
PostalInboxFrame.opening = true
|
||||||
-- PostalInboxFrame.num = true -- TODO remove
|
Postal:Inbox_DisableClicks()
|
||||||
Postal.open.start(selected, function()
|
Postal.open.start(selected, function()
|
||||||
Postal:Inbox_DisableClicks(false)
|
PostalInboxFrame.opening = false
|
||||||
PostalInboxFrame.num = false
|
Postal:Inbox_DisableClicks()
|
||||||
end)
|
end)
|
||||||
Postal_SelectedItems = {}
|
Postal_SelectedItems = {}
|
||||||
end
|
end
|
||||||
@@ -672,44 +678,30 @@ function Postal:InboxFrame_Update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if PostalInboxFrame.num then
|
Postal:Inbox_DisableClicks()
|
||||||
Postal:Inbox_DisableClicks(1, 1)
|
end
|
||||||
|
|
||||||
|
function Postal:Inbox_DisableClicks()
|
||||||
|
for i=1,7 do
|
||||||
|
getglobal('MailItem'..i..'ButtonIcon'):SetDesaturated(PostalInboxFrame.opening)
|
||||||
|
if PostalInboxFrame.opening then
|
||||||
|
getglobal('MailItem'..i..'Button'):SetChecked(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:Inbox_DisableClicks(disable, loopPrevention)
|
function Postal:InboxFrame_OnClick(index)
|
||||||
if disable then
|
if PostalInboxFrame.opening then
|
||||||
for i = 1, 7 do
|
this:SetChecked(nil)
|
||||||
getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(1)
|
return
|
||||||
end
|
|
||||||
if not self:IsHooked("InboxFrame_OnClick") then self:Hook("InboxFrame_OnClick", "DummyFunction") end
|
|
||||||
else
|
|
||||||
for i = 1, 7 do
|
|
||||||
getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(nil)
|
|
||||||
end
|
|
||||||
if not loopPrevention then
|
|
||||||
InboxFrame_Update()
|
|
||||||
end
|
|
||||||
if self:IsHooked("InboxFrame_OnClick") then self:Unhook("InboxFrame_OnClick") end
|
|
||||||
end
|
end
|
||||||
end
|
self.hooks['InboxFrame_OnClick'].orig(index)
|
||||||
|
|
||||||
function Postal:InboxFrame_OnClick()
|
|
||||||
this:SetChecked(nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Postal:Inbox_Abort()
|
function Postal:Inbox_Abort()
|
||||||
Postal.open.stop()
|
Postal.open.stop()
|
||||||
PostalInboxFrame.num = nil
|
PostalInboxFrame.opening = false
|
||||||
|
Postal:Inbox_DisableClicks()
|
||||||
PostalInboxFrame.id = {}
|
PostalInboxFrame.id = {}
|
||||||
Postal_SelectedItems = {}
|
Postal_SelectedItems = {}
|
||||||
Postal:Inbox_DisableClicks()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal:CloseMail()
|
|
||||||
self.hooks["CloseMail"].orig()
|
|
||||||
Postal:Inbox_Abort()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Postal:DummyFunction()
|
|
||||||
end
|
end
|
||||||
+3
-8
@@ -100,11 +100,6 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Offset>
|
</Offset>
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
|
||||||
<OnClick>
|
|
||||||
SendMailMailButton_OnClick();
|
|
||||||
</OnClick>
|
|
||||||
</Scripts>
|
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button name="PostalAttachment" virtual="true">
|
<Button name="PostalAttachment" virtual="true">
|
||||||
@@ -155,13 +150,13 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
this:RegisterForDrag('LeftButton')
|
this:RegisterForDrag('LeftButton')
|
||||||
</OnLoad>
|
</OnLoad>
|
||||||
<OnReceiveDrag>
|
<OnReceiveDrag>
|
||||||
Postal:MailButton_OnClick()
|
Postal:AttachmentButton_OnClick()
|
||||||
</OnReceiveDrag>
|
</OnReceiveDrag>
|
||||||
<OnDragStart>
|
<OnDragStart>
|
||||||
Postal:MailButton_OnClick()
|
Postal:AttachmentButton_OnClick()
|
||||||
</OnDragStart>
|
</OnDragStart>
|
||||||
<OnClick>
|
<OnClick>
|
||||||
Postal:MailButton_OnClick()
|
Postal:AttachmentButton_OnClick()
|
||||||
</OnClick>
|
</OnClick>
|
||||||
<OnEnter>
|
<OnEnter>
|
||||||
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
|
||||||
|
|||||||
Reference in New Issue
Block a user