functionality complete, just needs some refactoring now

This commit is contained in:
Manuel Simon Hirsig
2016-02-21 21:59:01 +01:00
parent 76974fdfbf
commit 28501dd854
3 changed files with 29 additions and 347 deletions
+20 -256
View File
@@ -28,9 +28,6 @@ function Postal:OnInitialize()
Postal_SelectedItems = {}
Postal_DELETEDELAY = 1
PostalForwardFrame.pickItem = {}
PostalForwardFrame.process = 0
PostalGlobalFrame.queue = {}
PostalGlobalFrame.total = 0
PostalGlobalFrame.sendmail = 0
@@ -177,7 +174,6 @@ function Postal:OnEnable()
self:RegisterEvent("UI_ERROR_MESSAGE")
self:RegisterEvent("MAIL_SEND_SUCCESS")
self:RegisterEvent("MAIL_CLOSED")
self:RegisterEvent("BAG_UPDATE")
self:Hook("ContainerFrameItemButton_OnClick")
self:Hook("PickupContainerItem")
@@ -188,10 +184,8 @@ function Postal:OnEnable()
self:Hook("ClickSendMailItemButton")
self:HookScript(TradeFrame, "OnShow", "TF_Show")
self:Hook("InboxFrameItem_OnEnter")
self:Hook("InboxFrame_OnClick")
self:Hook("InboxFrame_Update")
self:Hook("CloseMail")
self:Hook("OpenMail_Reply")
oldTakeInboxMoney = OpenMailMoneyButton:GetScript("OnClick")
-- NEW
@@ -700,7 +694,6 @@ function Postal:Print(msg, r, g, b)
DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b)
end
function Postal_Inbox_SetSelected()
local id = this:GetID() + (InboxFrame.pageNum - 1) * 7
if not this:GetChecked() then
@@ -792,255 +785,26 @@ function Postal:CloseMail()
Postal:Inbox_Abort()
end
-- function Postal:TakeInboxItem(id)
-- TakeInboxItem(id)
-- local name = GetInboxItem(id)
-- tinsert(PostalForwardFrame.pickItem, name)
-- end
-- Mail Forwarding
function Postal:DisableAttachments(disable)
if disable then
OpenMailMoneyButtonIconTexture:SetDesaturated(1)
OpenMailPackageButtonIconTexture:SetDesaturated(1)
if not self:IsHooked(OpenMailMoneyButton, "OnClick") then self:HookScript(OpenMailMoneyButton, "OnClick", "DummyFunction") end
if not self:IsHooked(OpenMailPackageButton, "OnClick") then self:HookScript(OpenMailPackageButton, "OnClick", "DummyFunction") end
else
OpenMailMoneyButtonIconTexture:SetDesaturated(nil)
OpenMailPackageButtonIconTexture:SetDesaturated(nil)
if self:IsHooked(OpenMailMoneyButton, "OnClick") then self:Unhook(OpenMailMoneyButton, "OnClick") end
if self:IsHooked(OpenMailPackageButton, "OnClick") then self:Unhook(OpenMailPackageButton, "OnClick") end
end
end
function Postal:DummyFunction()
end
function Postal:OpenMail_Reply()
self.hooks["OpenMail_Reply"].orig()
SendMailMoneyCopper:SetText("")
SendMailMoneySilver:SetText("")
SendMailMoneyGold:SetText("")
end
function Postal:OpenReply()
OpenMail_Reply()
local _, _, _, subject, money = GetInboxHeaderInfo(InboxFrame.openMailID)
-- Money
local gold, silver, copper = "", "", ""
if money and money > 0 then
gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD))
silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER)
copper = mod(money, COPPER_PER_SILVER)
end
SendMailMoneyCopper:SetText(copper)
SendMailMoneySilver:SetText(silver)
SendMailMoneyGold:SetText(gold)
-- Items
local _, itemTexture, count = GetInboxItem(InboxFrame.openMailID)
SendMailPackageButton:SetNormalTexture(itemTexture)
if count > 1 then
SendMailPackageButtonCount:SetText(count)
else
SendMailPackageButtonCount:SetText("")
end
-- Text fields
SendMailNameEditBox:SetText("")
local subject = OpenMailSubject:GetText()
local prefix = "FW:".." "
if strsub(subject, 1, strlen(prefix)) ~= prefix then
subject = prefix..subject
end
PostalSubjectEditBox:SetText(subject or "")
SendMailBodyEditBox:SetText(string.gsub(OpenMailBodyText:GetText() or "", "\n", "\n>"))
SendMailNameEditBox:SetFocus()
-- self:Forward_EnableForward(1)
end
function Postal:PostalMailButton_OnClick()
local name = GetInboxItem(InboxFrame.openMailID)
local _, _, _, _, money = GetInboxHeaderInfo(InboxFrame.openMailID)
if name then
PostalForwardFrame.searchItem = name
PostalForwardFrame.forwardStep = 1
TakeInboxItem(InboxFrame.openMailID)
else
PostalForwardFrame.forwardStep = 2
if money and money > 0 then
SetSendMailMoney(money)
PostalForwardFrame.countDown = 2
oldTakeInboxMoney(InboxFrame.openMailID)
else
PostalForwardFrame.countDown = 0.5
end
end
PostalMailButton:Disable()
end
function Postal:Forward_OnUpdate(elapsed)
if this.forwardStep and this.forwardStep > 1 then
if this.countDown then
this.countDown = this.countDown - elapsed
if this.countDown <= 0 then
if this.forwardStep == 2 then
this.countDown = 0.5
this.forwardStep = 3
-- Send the mail
SendMail(SendMailNameEditBox:GetText(), PostalSubjectEditBox:GetText(), SendMailBodyEditBox:GetText())
PostalMailButton:Disable()
elseif this.forwardStep == 3 then
-- Delete the old one
local _, _, _, _, money, _, _, itemID = GetInboxHeaderInfo(InboxFrame.openMailID)
if money == 0 and not itemID then
DeleteInboxItem(InboxFrame.openMailID)
end
MailFrameTab_OnClick(1)
HideUIPanel(OpenMailFrame)
this.countDown = nil
this.forwardStep = nil
end
end
end
end
this.process = this.process - elapsed
if this.process <= 0 then
this.process = 3
if getn(Postal_ScheduledStack) > 0 then
self:ProcessStack()
end
end
end
function Postal:InboxFrame_OnClick(id)
self.hooks["InboxFrame_OnClick"].orig(id)
local _, _, _, _, _, CODAmount = GetInboxHeaderInfo(id)
if CODAmount and CODAmount > 0 then
OpenMailForwardButton:Disable()
else
OpenMailForwardButton:Enable()
end
end
function Postal:Forward_EnableForward(enable)
if enable then
OpenMailForwardButton:Disable()
if not self:IsHooked(SendMailPackageButton, "OnEnter") then self:HookScript(SendMailPackageButton, "OnEnter", "SMPBOE") end
SendMailCODButton:Disable()
self:DisableAttachments(1)
if not self:IsHooked("SendMailMailButton_OnClick") then self:Hook("SendMailMailButton_OnClick") end
if not self:IsHooked("SendMailPackageButton_OnClick") then self:Hook("SendMailPackageButton_OnClick") end
else
OpenMailForwardButton:Enable()
if self:IsHooked(SendMailPackageButton, "OnEnter") then self:Unhook(SendMailPackageButton, "OnEnter") end
SendMailCODButton:Enable()
self:DisableAttachments(nil)
if self:IsHooked("SendMailMailButton_OnClick") then self:Unhook("SendMailMailButton_OnClick") end
if self:IsHooked("SendMailPackageButton_OnClick") then self:Unhook("SendMailPackageButton_OnClick") end
end
end
function Postal:SMPBOE()
GameTooltip:SetOwner(SendMailPackageButton, "ANCHOR_RIGHT")
GameTooltip:SetInboxItem(InboxFrame.openMailID)
end
function Postal:SendMailPackageButton_OnClick()
end
function Postal:Forward_AttachSlot(container, slot)
PickupContainerItem(container, slot)
ClickSendMailItemButton()
PostalForwardFrame.searchItem = nil
PostalForwardFrame.forwardStep = 2
PostalForwardFrame.countDown = 1.5
end
function Postal:BAG_UPDATE()
local old = {}
for k, v in Postal_BagLinks do
if type(v) == "table" then
old[k] = { }
for key, val in v do
old[k][key] = val
end
end
end
Postal_BagLinks = {}
for i = 0, 4 do
Postal_BagLinks[i] = {}
for y = 1, GetContainerNumSlots(i) do
local curr = GetContainerItemLink(i, y)
local _, _, name = string.find(( curr or "" ), "%[(.+)%]")
if name then
if PostalForwardFrame.searchItem then
if name and name == PostalForwardFrame.searchItem and not old[i][y] then
self:Forward_AttachSlot(i, y)
end
else
local _, _, name = string.find(( curr or "" ), "%[(.+)%]")
if name and name == PostalForwardFrame.pickItem[1] and not old[i][y] then
tremove(PostalForwardFrame.pickItem, 1)
for k, v in old do
local hasFound
for key, val in v do
if val == name and ( k ~= i or key ~= y ) then
local _,_, link = string.find((GetContainerItemLink(k, key) or ""), "(item:[%d:]+)")
if link then
local texture, itemCount = GetContainerItemInfo(k,key)
local tex, iC = GetContainerItemInfo(i, y)
local sName, sLink, iQuality, iLevel, sType, sSubType, iCount = GetItemInfo(link)
if sName and itemCount and iCount and iC then
if iCount >= (itemCount+iC) then
if getn(Postal_ScheduledStack) == 0 then
PostalForwardFrame.process = 2
end
tinsert(Postal_ScheduledStack, { i, y, k, key })
hasFound = 1
break
end
end
end
end
end
if hasFound then
break
end
end
end
end
Postal_BagLinks[i][y] = name
end
end
end
end
function Postal:ProcessStack()
local val = tremove(Postal_ScheduledStack, 1)
PickupContainerItem(val[1], val[2])
PickupContainerItem(val[3], val[4])
end
local oldSMMFfunc = SendMailMoneyFrame.onvalueChangedFunc
SendMailMoneyFrame.onvalueChangedFunc = function()
if oldSMMFfunc then
oldSMMFfunc()
end
local subject = PostalSubjectEditBox:GetText()
if subject == "" or string.find(subject, "%[%d+G, %d+S, %d+C%]") then
local copper, silver, gold = SendMailMoneyFrameCopper:GetText(), SendMailMoneyFrameSilver:GetText(), SendMailMoneyFrameGold:GetText()
if not tonumber(copper) then
copper = 0
end
if not tonumber(silver) then
silver = 0
end
if not tonumber(gold) then
gold = 0
end
PostalSubjectEditBox:SetText(format("[%sG, %sS, %sC]", gold, silver, copper))
end
end
-- local oldSMMFfunc = SendMailMoneyFrame.onvalueChangedFunc
-- SendMailMoneyFrame.onvalueChangedFunc = function()
-- if oldSMMFfunc then
-- oldSMMFfunc()
-- end
-- local subject = PostalSubjectEditBox:GetText()
-- if subject == "" or string.find(subject, "%[%d+G, %d+S, %d+C%]") then
-- local copper, silver, gold = SendMailMoneyFrameCopper:GetText(), SendMailMoneyFrameSilver:GetText(), SendMailMoneyFrameGold:GetText()
-- if not tonumber(copper) then
-- copper = 0
-- end
-- if not tonumber(silver) then
-- silver = 0
-- end
-- if not tonumber(gold) then
-- gold = 0
-- end
-- PostalSubjectEditBox:SetText(format("[%sG, %sS, %sC]", gold, silver, copper))
-- end
-- end
-84
View File
@@ -213,64 +213,6 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
<Size>
<AbsDimension x="384" y="512"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT"/>
</Anchors>
<Layers>
<Layer level="BACKGROUND">
<FontString name="PostalTitleText" inherits="GameFontNormal" text="POSTAL_SEND">
<Size>
<AbsDimension x="224" y="14"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="6" y="230"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
<FontString justifyH="left" justifyV="top" name="PostalHelpText" inherits="GameFontNormal" text="POSTAL_HELP">
<Size>
<AbsDimension x="300" y="150"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="30" y="-105"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
<Frames>
<Button name="PostalAbortButton" hidden="true" inherits="UIPanelButtonTemplate" text="POSTAL_ABORT">
<Size>
<AbsDimension x="80" y="22"/>
</Size>
<Anchors>
<Anchor point="BOTTOM" relativePoint="BOTTOM">
<Offset>
<AbsDimension x="0" y="105"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
PostalStatusText:SetText(format(POSTAL_ABORTED, PostalGlobalFrame.total-(getn(PostalGlobalFrame.queue)-1), PostalGlobalFrame.total));
PostalGlobalFrame.queue = { };
PostalGlobalFrame.total = 0;
PostalGlobalFrame:Hide();
</OnClick>
</Scripts>
</Button>
</Frames>
<Scripts>
<OnShow>
PostalNameEditBox:SetFocus()
</OnShow>
</Scripts>
</Frame>
<Frame name="PostalInboxFrame" parent="UIParent">
@@ -342,32 +284,6 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
</Scripts>
</Button>
<!-- Mail forwarding -->
<Button name="OpenMailForwardButton" parent="OpenMailFrame" inherits="UIPanelButtonTemplate" text="Forward">
<Size>
<AbsDimension x="82" y="22"/>
</Size>
<Anchors>
<Anchor point="RIGHT" relativeTo="OpenMailReplyButton" relativePoint="LEFT">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
Postal:OpenReply()
</OnClick>
</Scripts>
</Button>
<Frame name="PostalForwardFrame" parent="UIParent">
<Scripts>
<OnUpdate>
Postal:Forward_OnUpdate(arg1)
</OnUpdate>
</Scripts>
</Frame>
<Frame name="PostalGlobalFrame" parent="UIParent" hidden="true">
<Scripts>
<OnUpdate>
+9 -7
View File
@@ -33,10 +33,12 @@ function process(selected, k)
local index = selected[1]
local inbox_count = GetInboxNumItems()
open(index, inbox_count, function()
open(index, inbox_count, function(skipped)
tremove(selected, 1)
for i, _ in selected do
selected[i] = selected[i] - 1
if not skipped then
for i, _ in ipairs(selected) do
selected[i] = selected[i] - 1
end
end
return process(selected, k)
end)
@@ -47,24 +49,24 @@ function open(i, inbox_count, k)
wait_for_update(function()
local _, _, _, _, money, COD_amount, _, has_item = GetInboxHeaderInfo(i)
if GetInboxNumItems() < inbox_count or COD_amount > 0 then
return k()
return k(COD_amount > 0)
elseif has_item then
local inventory_count_before = inventory_count()
TakeInboxItem(i)
controller().wait(function() return inventory_count() > inventory_count_before end, function()
return open(i, inbox_count, k)
return open(i, inbox_count, k)
end)
elseif money > 0 then
local money_before = GetMoney()
TakeInboxMoney(i)
controller().wait(function() return GetMoney() > money_before end, function()
return open(i, inbox_count, k)
return open(i, inbox_count, k)
end)
else
local inbox_count_before = GetInboxNumItems()
DeleteInboxItem(i)
controller().wait(function() return GetInboxNumItems() < inbox_count_before end, function()
return open(i, inbox_count, k)
return open(i, inbox_count, k)
end)
end
end)