added a retail blizzlike completion dropdown
This commit is contained in:
+92
-30
@@ -129,7 +129,7 @@ function self:ADDON_LOADED()
|
|||||||
|
|
||||||
-- hack to avoid automatic subject setting and button disabling from weird blizzard code
|
-- hack to avoid automatic subject setting and button disabling from weird blizzard code
|
||||||
PostalMailButton = SendMailMailButton
|
PostalMailButton = SendMailMailButton
|
||||||
SendMailMailButton = setmetatable({}, {__index = function() return function() end end})
|
SendMailMailButton = setmetatable({}, { __index = function() return function() end end })
|
||||||
SendMailMailButton_OnClick = self.PostalMailButton_OnClick
|
SendMailMailButton_OnClick = self.PostalMailButton_OnClick
|
||||||
PostalSubjectEditBox = SendMailSubjectEditBox
|
PostalSubjectEditBox = SendMailSubjectEditBox
|
||||||
SendMailSubjectEditBox = setmetatable({}, {
|
SendMailSubjectEditBox = setmetatable({}, {
|
||||||
@@ -153,18 +153,25 @@ function self:ADDON_LOADED()
|
|||||||
end)
|
end)
|
||||||
SendMailNameEditBox:SetScript('OnChar', function()
|
SendMailNameEditBox:SetScript('OnChar', function()
|
||||||
Postal_To = nil
|
Postal_To = nil
|
||||||
SendMailFrame_SendeeAutocomplete()
|
self:GetMatches()
|
||||||
AutoCompleteBox:SetPoint('TOPLEFT', SendMailNameEditBox, 'BOTTOMLEFT', 0, 3)
|
end)
|
||||||
for i = 1, 5 do
|
SendMailNameEditBox:SetScript('OnTabPressed', function()
|
||||||
local button = getglobal('AutoCompleteButton' .. i)
|
if AutoCompleteBox:IsVisible() then
|
||||||
button:SetText('kek')
|
if IsShiftKeyDown() then
|
||||||
button:GetFontString():SetPoint('LEFT', button, 'LEFT', 15, 0)
|
self:PreviousMatch()
|
||||||
button:Enable()
|
else
|
||||||
button:Show()
|
self:NextMatch()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
PostalSubjectEditBox:SetFocus()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
SendMailNameEditBox:SetScript('OnEscapePressed', function()
|
||||||
|
if AutoCompleteBox:IsVisible() then
|
||||||
|
AutoCompleteBox:Hide()
|
||||||
|
else
|
||||||
|
this:ClearFocus()
|
||||||
end
|
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
|
||||||
@@ -684,24 +691,79 @@ function self:SendMail_Send()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:FuzzyMatcher(input)
|
do
|
||||||
local uppercaseInput = strupper(input)
|
local inputLength
|
||||||
local pattern = '(.*)'
|
local matches = {}
|
||||||
for i = 1, strlen(uppercaseInput) do
|
local index
|
||||||
if strfind(strsub(uppercaseInput, i, i), '%w') or strfind(strsub(uppercaseInput, i, i), '%s') then
|
|
||||||
pattern = pattern .. strsub(uppercaseInput, i, i) .. '(.-)'
|
local function complete()
|
||||||
end
|
SendMailNameEditBox:SetText(matches[index])
|
||||||
|
SendMailNameEditBox:HighlightText(inputLength, -1)
|
||||||
end
|
end
|
||||||
return function(candidate)
|
|
||||||
local match = { strfind(strupper(candidate), pattern) }
|
function self:PreviousMatch()
|
||||||
if match[1] then
|
if index then
|
||||||
local rating = 0
|
index = abs(min(index - 1, -getn(matches))
|
||||||
for i = 4, getn(match) - 1 do
|
complete()
|
||||||
if strlen(match[i]) == 0 then
|
end
|
||||||
rating = rating + 1
|
end
|
||||||
end
|
|
||||||
end
|
function self:NextMatch()
|
||||||
return rating
|
if index then
|
||||||
end
|
index = mod(index, getn(matches)) + 1
|
||||||
|
complete()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function self:SelectMatch(i)
|
||||||
|
index = i
|
||||||
|
complete()
|
||||||
|
AutoCompleteBox:Hide()
|
||||||
|
end
|
||||||
|
|
||||||
|
function self:GetMatches()
|
||||||
|
local input = SendMailNameEditBox:GetText()
|
||||||
|
inputLength = strlen(input)
|
||||||
|
|
||||||
|
table.setn(matches, 0)
|
||||||
|
|
||||||
|
local name
|
||||||
|
for i = 1, GetNumFriends() do
|
||||||
|
name = GetFriendInfo(i)
|
||||||
|
if strfind(strupper(name), strupper(input), nil, true) == 1 then
|
||||||
|
tinsert(matches, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i = 1, GetNumGuildMembers(true) do
|
||||||
|
name = GetGuildRosterInfo(i)
|
||||||
|
if strfind(strupper(name), strupper(input), nil, true) == 1 then
|
||||||
|
tinsert(matches, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if matches[1] then
|
||||||
|
index = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
table.setn(matches, min(getn(matches), AUTOCOMPLETE_MAX_BUTTONS))
|
||||||
|
if getn(matches) > 0 then
|
||||||
|
for i = 1, AUTOCOMPLETE_MAX_BUTTONS do
|
||||||
|
local button = getglobal('AutoCompleteButton' .. i)
|
||||||
|
if i <= getn(matches) then
|
||||||
|
button:SetText(matches[i])
|
||||||
|
button:GetFontString():SetPoint('LEFT', button, 'LEFT', 15, 0)
|
||||||
|
button:Show()
|
||||||
|
else
|
||||||
|
button:Hide()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
AutoCompleteBox:SetHeight(getn(matches) * AutoCompleteButton1:GetHeight() + 35)
|
||||||
|
AutoCompleteBox:SetWidth(120)
|
||||||
|
AutoCompleteBox:Show()
|
||||||
|
else
|
||||||
|
AutoCompleteBox:Hide()
|
||||||
|
end
|
||||||
|
index = 1
|
||||||
|
complete(index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
+15
-7
@@ -7,7 +7,12 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
<AbsDimension x="120" y="14"/>
|
<AbsDimension x="120" y="14"/>
|
||||||
</Size>
|
</Size>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnClick></OnClick>
|
<OnClick>
|
||||||
|
Postal:SelectMatch(this:GetID())
|
||||||
|
</OnClick>
|
||||||
|
<OnTabPressed>
|
||||||
|
Postal:NextMatch()
|
||||||
|
</OnTabPressed>
|
||||||
</Scripts>
|
</Scripts>
|
||||||
<NormalFont inherits="GameFontNormal"/>
|
<NormalFont inherits="GameFontNormal"/>
|
||||||
<HighlightFont inherits="GameFontHighlight"/>
|
<HighlightFont inherits="GameFontHighlight"/>
|
||||||
@@ -18,6 +23,9 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
<Size>
|
<Size>
|
||||||
<AbsDimension x="5" y="5"/>
|
<AbsDimension x="5" y="5"/>
|
||||||
</Size>
|
</Size>
|
||||||
|
<Anchors>
|
||||||
|
<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT"><Offset><AbsDimension x="0" y="3"/></Offset></Anchor>
|
||||||
|
</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"/>
|
||||||
@@ -43,7 +51,7 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Layer>
|
</Layer>
|
||||||
</Layers>
|
</Layers>
|
||||||
<Frames>
|
<Frames>
|
||||||
<Button name="AutoCompleteButton1" inherits="AutoCompleteButtonTemplate">
|
<Button name="AutoCompleteButton1" inherits="AutoCompleteButtonTemplate" id="1">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT">
|
<Anchor point="TOPLEFT">
|
||||||
<Offset>
|
<Offset>
|
||||||
@@ -53,22 +61,22 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Anchor>
|
</Anchor>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
</Button>
|
</Button>
|
||||||
<Button name="AutoCompleteButton2" inherits="AutoCompleteButtonTemplate">
|
<Button name="AutoCompleteButton2" inherits="AutoCompleteButtonTemplate" id="2">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton1" relativePoint="BOTTOMLEFT"/>
|
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton1" relativePoint="BOTTOMLEFT"/>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
</Button>
|
</Button>
|
||||||
<Button name="AutoCompleteButton3" inherits="AutoCompleteButtonTemplate">
|
<Button name="AutoCompleteButton3" inherits="AutoCompleteButtonTemplate" id="3">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton2" relativePoint="BOTTOMLEFT"/>
|
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton2" relativePoint="BOTTOMLEFT"/>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
</Button>
|
</Button>
|
||||||
<Button name="AutoCompleteButton4" inherits="AutoCompleteButtonTemplate">
|
<Button name="AutoCompleteButton4" inherits="AutoCompleteButtonTemplate" id="4">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton3" relativePoint="BOTTOMLEFT"/>
|
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton3" relativePoint="BOTTOMLEFT"/>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
</Button>
|
</Button>
|
||||||
<Button name="AutoCompleteButton5" inherits="AutoCompleteButtonTemplate">
|
<Button name="AutoCompleteButton5" inherits="AutoCompleteButtonTemplate" id="5">
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton4" relativePoint="BOTTOMLEFT"/>
|
<Anchor point="TOPLEFT" relativeTo="AutoCompleteButton4" relativePoint="BOTTOMLEFT"/>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
@@ -76,7 +84,7 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
|
|||||||
</Frames>
|
</Frames>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
<OnLoad>
|
<OnLoad>
|
||||||
local AUTOCOMPLETE_MAX_BUTTONS = 5
|
AUTOCOMPLETE_MAX_BUTTONS = 5
|
||||||
this:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b)
|
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:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b)
|
||||||
this.maxHeight = AUTOCOMPLETE_MAX_BUTTONS * AutoCompleteButton1:GetHeight()
|
this.maxHeight = AUTOCOMPLETE_MAX_BUTTONS * AutoCompleteButton1:GetHeight()
|
||||||
|
|||||||
Reference in New Issue
Block a user