refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-16 08:41:08 +02:00
parent f70d9fe7d3
commit 7fa05c34f3
2 changed files with 83 additions and 51 deletions
+70 -37
View File
@@ -2,7 +2,7 @@ local self = CreateFrame('Frame', nil, MailFrame)
Postal = self Postal = self
self:SetScript('OnUpdate', function() this:UPDATE() end) self:SetScript('OnUpdate', function() this:UPDATE() end)
self:SetScript('OnEvent', function() this[event](this) end) self:SetScript('OnEvent', function() this[event](this) end)
for _, event in {'ADDON_LOADED', 'VARIABLES_LOADED', 'UI_ERROR_MESSAGE', 'CURSOR_UPDATE', 'BAG_UPDATE', 'MAIL_CLOSED', 'MAIL_SEND_SUCCESS'} do for _, event in { 'ADDON_LOADED', 'VARIABLES_LOADED', 'UI_ERROR_MESSAGE', 'CURSOR_UPDATE', 'BAG_UPDATE', 'MAIL_CLOSED', 'MAIL_SEND_SUCCESS' } do
self:RegisterEvent(event) self:RegisterEvent(event)
end end
@@ -14,7 +14,7 @@ function self:pack(...) return arg end
self.hook, self.orig = {}, {} self.hook, self.orig = {}, {}
function self:Hook(...) function self:Hook(...)
for i=1,arg.n do for i = 1, arg.n do
self.orig[arg[i]] = getglobal(arg[i]) self.orig[arg[i]] = getglobal(arg[i])
setglobal(arg[i], self.hook[arg[i]]) setglobal(arg[i], self.hook[arg[i]])
end end
@@ -30,10 +30,10 @@ do
end end
end end
function self:When(predicate, callback) function self:When(predicate, callback)
state = {predicate = predicate, callback = callback} state = { predicate = predicate, callback = callback }
end end
function self:Wait(callback) function self:Wait(callback)
state = {predicate = function() return true end, callback = callback} state = { predicate = function() return true end, callback = callback }
end end
function self:Kill() function self:Kill()
state = nil state = nil
@@ -66,7 +66,7 @@ function self:MAIL_CLOSED()
-- 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
if not ({GetInboxHeaderInfo(i)})[9] then return end if not ({GetInboxHeaderInfo(i)})[9] then return end
end end
MiniMapMailFrame:Hide() MiniMapMailFrame:Hide()
@@ -104,18 +104,18 @@ function self:ADDON_LOADED()
PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]]) PostalHorizontalBarLeft:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
PostalHorizontalBarLeft:SetWidth(256) PostalHorizontalBarLeft:SetWidth(256)
PostalHorizontalBarLeft:SetHeight(16) PostalHorizontalBarLeft:SetHeight(16)
PostalHorizontalBarLeft:SetTexCoord(0, 1, 0, 0.25) PostalHorizontalBarLeft:SetTexCoord(0, 1, 0, .25)
SendMailFrame:CreateTexture('PostalHorizontalBarRight', 'BACKGROUND') SendMailFrame:CreateTexture('PostalHorizontalBarRight', 'BACKGROUND')
PostalHorizontalBarRight:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]]) PostalHorizontalBarRight:SetTexture([[Interface\ClassTrainerFrame\UI-ClassTrainer-HorizontalBar]])
PostalHorizontalBarRight:SetWidth(75) PostalHorizontalBarRight:SetWidth(75)
PostalHorizontalBarRight:SetHeight(16) PostalHorizontalBarRight:SetHeight(16)
PostalHorizontalBarRight:SetTexCoord(0, 0.29296875, 0.25, 0.5) PostalHorizontalBarRight:SetTexCoord(0, .29296875, .25, .5)
PostalHorizontalBarRight:SetPoint('LEFT', PostalHorizontalBarLeft, 'RIGHT') PostalHorizontalBarRight:SetPoint('LEFT', PostalHorizontalBarLeft, 'RIGHT')
do do
local background = ({SendMailPackageButton:GetRegions()})[1] local background = ({ SendMailPackageButton:GetRegions() })[1]
background:Hide() background:Hide()
local count = ({SendMailPackageButton:GetRegions()})[3] local count = ({ SendMailPackageButton:GetRegions() })[3]
count:Hide() count:Hide()
SendMailPackageButton:Disable() SendMailPackageButton:Disable()
SendMailPackageButton:SetScript('OnReceiveDrag', nil) SendMailPackageButton:SetScript('OnReceiveDrag', nil)
@@ -154,9 +154,20 @@ function self:ADDON_LOADED()
SendMailNameEditBox:SetScript('OnChar', function() SendMailNameEditBox:SetScript('OnChar', function()
Postal_To = nil Postal_To = nil
SendMailFrame_SendeeAutocomplete() SendMailFrame_SendeeAutocomplete()
AutoCompleteBox:SetPoint('TOPLEFT', SendMailNameEditBox, 'BOTTOMLEFT', 0, 3)
for i = 1, 5 do
local button = getglobal('AutoCompleteButton' .. i)
button:SetText('kek')
button:GetFontString():SetPoint('LEFT', button, 'LEFT', 15, 0)
button:Enable()
button:Show()
end
AutoCompleteBox:SetHeight(5 * AutoCompleteButton1:GetHeight() + 35)
AutoCompleteBox:SetWidth(120)
AutoCompleteBox:Show()
end) end)
for _, editBox in {SendMailNameEditBox, SendMailSubjectEditBox} do for _, editBox in { SendMailNameEditBox, SendMailSubjectEditBox } do
editBox:SetScript('OnEditFocusGained', function() editBox:SetScript('OnEditFocusGained', function()
this:HighlightText() this:HighlightText()
end) end)
@@ -173,7 +184,7 @@ function self:ADDON_LOADED()
this:SetScript('OnUpdate', nil) this:SetScript('OnUpdate', nil)
end) end)
end end
lastClick = {t=GetTime(), x=x, y=y} lastClick = { t=GetTime(), x=x, y=y }
end) end)
end end
end end
@@ -196,7 +207,7 @@ function self.hook.OpenMail_Reply(...)
end end
function self:Print(msg, r, g, b) function self:Print(msg, r, g, b)
DEFAULT_CHAT_FRAME:AddMessage('Postal: '..msg, r, g, b) DEFAULT_CHAT_FRAME:AddMessage('Postal: ' .. msg, r, g, b)
end end
function self:Present(...) function self:Present(...)
@@ -220,10 +231,10 @@ function self.hook.InboxFrame_Update()
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(self.Inbox_selectedItems[index]) getglobal('PostalBoxItem' .. i .. 'CB'):SetChecked(self.Inbox_selectedItems[index])
end end
end end
self:Inbox_Lock() self:Inbox_Lock()
@@ -318,12 +329,12 @@ function self:Inbox_OpenItem(i, inboxCount, selected)
return self:Inbox_OpenMail(selected) return self:Inbox_OpenMail(selected)
elseif item then elseif item then
TakeInboxItem(i) TakeInboxItem(i)
self:When(function() return not ({GetInboxHeaderInfo(i)})[8] or GetInboxNumItems() < inboxCount or self.Inbox_skip end, function() self:When(function() return not ({ GetInboxHeaderInfo(i) })[8] or GetInboxNumItems() < inboxCount or self.Inbox_skip end, function()
return self:Inbox_OpenItem(i, inboxCount, selected) return self:Inbox_OpenItem(i, inboxCount, selected)
end) end)
elseif money > 0 then elseif money > 0 then
TakeInboxMoney(i) TakeInboxMoney(i)
self:When(function() return ({GetInboxHeaderInfo(i)})[5] == 0 or GetInboxNumItems() < inboxCount or self.Inbox_skip end, function() self:When(function() return ({ GetInboxHeaderInfo(i) })[5] == 0 or GetInboxNumItems() < inboxCount or self.Inbox_skip end, function()
return self:Inbox_OpenItem(i, inboxCount, selected) return self:Inbox_OpenItem(i, inboxCount, selected)
end) end)
else else
@@ -427,19 +438,19 @@ function self.hook.SendMailFrame_Update()
SendMailScrollFrame:SetHeight(scrollHeight) SendMailScrollFrame:SetHeight(scrollHeight)
SendMailScrollChildFrame:SetHeight(scrollHeight) SendMailScrollChildFrame:SetHeight(scrollHeight)
local SendMailScrollFrameTop = ({SendMailScrollFrame:GetRegions()})[3] local SendMailScrollFrameTop = ({ SendMailScrollFrame:GetRegions() })[3]
SendMailScrollFrameTop:SetHeight(scrollHeight) SendMailScrollFrameTop:SetHeight(scrollHeight)
SendMailScrollFrameTop:SetTexCoord(0, 0.484375, 0, scrollHeight / 256) SendMailScrollFrameTop:SetTexCoord(0, .484375, 0, scrollHeight / 256)
StationeryBackgroundLeft:SetHeight(scrollHeight) StationeryBackgroundLeft:SetHeight(scrollHeight)
StationeryBackgroundLeft:SetTexCoord(0, 1.0, 0, scrollHeight / 256) StationeryBackgroundLeft:SetTexCoord(0, 1, 0, scrollHeight / 256)
StationeryBackgroundRight:SetHeight(scrollHeight) StationeryBackgroundRight:SetHeight(scrollHeight)
StationeryBackgroundRight:SetTexCoord(0, 1.0, 0, scrollHeight / 256) StationeryBackgroundRight:SetTexCoord(0, 1, 0, scrollHeight / 256)
-- 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()
@@ -471,34 +482,34 @@ function self.hook.ClickSendMailItemButton()
end end
function self.hook.GetContainerItemInfo(...) function self.hook.GetContainerItemInfo(...)
local item = {arg[1], arg[2]} local item = { arg[1], arg[2] }
local ret = self:pack(self.orig.GetContainerItemInfo(unpack(arg))) local ret = self:pack(self.orig.GetContainerItemInfo(unpack(arg)))
ret[3] = ret[3] or self:SendMail_Attached(item) and 1 or nil ret[3] = ret[3] or self:SendMail_Attached(item) and 1 or nil
return unpack(ret) return unpack(ret)
end end
function self.hook.PickupContainerItem(...) function self.hook.PickupContainerItem(...)
local item = {arg[1], arg[2]} local item = { arg[1], arg[2] }
if self:SendMail_Attached(item) then return end if self:SendMail_Attached(item) then return end
if GetContainerItemInfo(unpack(item)) then self:SetCursorItem(item) end if GetContainerItemInfo(unpack(item)) then self:SetCursorItem(item) end
return self.orig.PickupContainerItem(unpack(arg)) return self.orig.PickupContainerItem(unpack(arg))
end end
function self.hook.SplitContainerItem(...) function self.hook.SplitContainerItem(...)
local item = {arg[1], arg[2]} local item = { arg[1], arg[2] }
if self:SendMail_Attached(item) then return end if self:SendMail_Attached(item) then return end
return self.orig.SplitContainerItem(unpack(arg)) return self.orig.SplitContainerItem(unpack(arg))
end end
function self.hook.UseContainerItem(...) function self.hook.UseContainerItem(...)
local item = {arg[1], arg[2]} local item = { arg[1], arg[2] }
if self:SendMail_Attached(item) then return end if self:SendMail_Attached(item) then return end
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
return self.orig.UseContainerItem(unpack(arg)) return self.orig.UseContainerItem(unpack(arg))
elseif SendMailFrame:IsVisible() then elseif SendMailFrame:IsVisible() then
self:SendMail_SetAttachment(item) self:SendMail_SetAttachment(item)
elseif TradeFrame:IsVisible() then elseif TradeFrame:IsVisible() then
for i=1,6 do for i = 1, 6 do
if not GetTradePlayerItemLink(i) then if not GetTradePlayerItemLink(i) then
self.orig.PickupContainerItem(unpack(arg)) self.orig.PickupContainerItem(unpack(arg))
ClickTradeButton(i) ClickTradeButton(i)
@@ -571,8 +582,8 @@ function self:SendMail_SetAttachment(item, slot)
return return
elseif not slot then elseif not slot then
for i=1,ATTACHMENTS_MAX do for i=1,ATTACHMENTS_MAX do
if not getglobal('PostalAttachment'..i).item then if not getglobal('PostalAttachment' .. i).item then
slot = getglobal('PostalAttachment'..i) slot = getglobal('PostalAttachment' .. i)
break break
end end
end end
@@ -599,8 +610,8 @@ end
function self:SendMail_NumAttachments() function self:SendMail_NumAttachments()
local num = 0 local num = 0
for i=1,ATTACHMENTS_MAX do for i = 1, ATTACHMENTS_MAX do
if getglobal('PostalAttachment'..i).item then if getglobal('PostalAttachment' .. i).item then
num = num + 1 num = num + 1
end end
end end
@@ -609,8 +620,8 @@ end
function self:SendMail_Attachments() function self:SendMail_Attachments()
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.item then if btn.item then
tinsert(arr, btn.item) tinsert(arr, btn.item)
end end
@@ -620,13 +631,13 @@ end
function self:SendMail_Clear() function self:SendMail_Clear()
for i=1,ATTACHMENTS_MAX do for i=1,ATTACHMENTS_MAX do
getglobal('PostalAttachment'..i).item = nil getglobal('PostalAttachment' .. i).item = nil
end end
PostalMailButton:Disable() PostalMailButton:Disable()
SendMailNameEditBox:SetText('') SendMailNameEditBox:SetText''
SendMailNameEditBox:SetFocus() SendMailNameEditBox:SetFocus()
PostalSubjectEditBox:SetText('') PostalSubjectEditBox:SetText''
SendMailBodyEditBox:SetText('') SendMailBodyEditBox:SetText''
MoneyInputFrame_ResetMoney(SendMailMoney) MoneyInputFrame_ResetMoney(SendMailMoney)
SendMailRadioButton_OnClick(1) SendMailRadioButton_OnClick(1)
@@ -671,4 +682,26 @@ function self:SendMail_Send()
self:SendMail_Send() self:SendMail_Send()
end) end)
end end
end
function self:FuzzyMatcher(input)
local uppercaseInput = strupper(input)
local pattern = '(.*)'
for i = 1, strlen(uppercaseInput) do
if strfind(strsub(uppercaseInput, i, i), '%w') or strfind(strsub(uppercaseInput, i, i), '%s') then
pattern = pattern .. strsub(uppercaseInput, i, i) .. '(.-)'
end
end
return function(candidate)
local match = { strfind(strupper(candidate), pattern) }
if match[1] then
local rating = 0
for i = 4, getn(match) - 1 do
if strlen(match[i]) == 0 then
rating = rating + 1
end
end
return rating
end
end
end end
+13 -14
View File
@@ -7,24 +7,17 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
<AbsDimension x="120" y="14"/> <AbsDimension x="120" y="14"/>
</Size> </Size>
<Scripts> <Scripts>
<OnClick function="AutoCompleteButton_OnClick"/> <OnClick></OnClick>
<OnLoad>
this:GetFontString():SetPoint('LEFT', this, 'LEFT', 15, 0)
</OnLoad>
</Scripts> </Scripts>
<ButtonText name="$parentText"/> <NormalFont inherits="GameFontNormal"/>
<NormalFont style="GameFontNormal"/> <HighlightFont inherits="GameFontHighlight"/>
<HighlightFont style="GameFontHighlight"/> <DisabledFont inherits="GameFontDisable"/>
<DisabledFont style="GameFontDisable"/>
<HighlightTexture inherits="UIPanelButtonHighlightTexture"/> <HighlightTexture inherits="UIPanelButtonHighlightTexture"/>
</Button> </Button>
<Frame name="AutoCompleteBox" parent="UIParent" hidden="true"> <Frame name="AutoCompleteBox" parent="SendMailNameEditBox" frameStrata="DIALOG" hidden="true">
<Size> <Size>
<AbsDimension x="5" y="5"/> <AbsDimension x="5" y="5"/>
</Size> </Size>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> <Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
<EdgeSize> <EdgeSize>
<AbsValue val="16"/> <AbsValue val="16"/>
@@ -38,7 +31,7 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
</Backdrop> </Backdrop>
<Layers> <Layers>
<Layer level="ARTWORK"> <Layer level="ARTWORK">
<FontString name="AutoCompleteInstructions" inherits="GameFontDisableSmall" text="PRESS_TAB"> <FontString name="AutoCompleteInstructions" inherits="GameFontDisableSmall">
<Anchors> <Anchors>
<Anchor point="BOTTOMLEFT"> <Anchor point="BOTTOMLEFT">
<Offset> <Offset>
@@ -82,7 +75,13 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
</Button> </Button>
</Frames> </Frames>
<Scripts> <Scripts>
<OnLoad function="AutoComplete_OnLoad"/> <OnLoad>
local AUTOCOMPLETE_MAX_BUTTONS = 5
this:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b)
this:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b)
this.maxHeight = AUTOCOMPLETE_MAX_BUTTONS * AutoCompleteButton1:GetHeight()
AutoCompleteInstructions:SetText("|cffbbbbbbPress Tab|r")
</OnLoad>
</Scripts> </Scripts>
</Frame> </Frame>