cleanup StaticPopups

This commit is contained in:
Crum
2018-01-11 12:43:01 -06:00
parent 144eafb090
commit 1feaf7ff5b
+68 -87
View File
@@ -76,7 +76,7 @@ E.PopupDialogs["CONFIRM_LOSE_BINDING_CHANGES"] = {
E:GetModule("ActionBars").bindingsChanged = nil E:GetModule("ActionBars").bindingsChanged = nil
end, end,
OnCancel = function() OnCancel = function()
if(ElvUIBindPopupWindowCheckButton:GetChecked()) then if ElvUIBindPopupWindowCheckButton:GetChecked() then
ElvUIBindPopupWindowCheckButton:SetChecked() ElvUIBindPopupWindowCheckButton:SetChecked()
else else
ElvUIBindPopupWindowCheckButton:SetChecked(1) ElvUIBindPopupWindowCheckButton:SetChecked(1)
@@ -258,7 +258,7 @@ E.PopupDialogs["HARLEM_SHAKE"] = {
text = L["ElvUI needs to perform database optimizations please be patient."], text = L["ElvUI needs to perform database optimizations please be patient."],
button1 = OKAY, button1 = OKAY,
OnAccept = function() OnAccept = function()
if(E.isMassiveShaking) then if E.isMassiveShaking then
E:StopHarlemShake() E:StopHarlemShake()
else else
E:BeginHarlemShake() E:BeginHarlemShake()
@@ -380,9 +380,6 @@ function E:StaticPopup_OnShow()
if OnShow then if OnShow then
OnShow(this.data) OnShow(this.data)
end end
if dialog.hasMoneyInputFrame then
_G[this:GetName().."MoneyInputFrameGold"]:SetFocus()
end
if dialog.enterClicksFirstButton then if dialog.enterClicksFirstButton then
this:SetScript("OnKeyDown", E.StaticPopup_OnKeyDown) this:SetScript("OnKeyDown", E.StaticPopup_OnKeyDown)
end end
@@ -391,12 +388,12 @@ end
function E:StaticPopup_EscapePressed() function E:StaticPopup_EscapePressed()
local closed = nil local closed = nil
for _, frame in pairs(E.StaticPopup_DisplayedFrames) do for _, frame in pairs(E.StaticPopup_DisplayedFrames) do
if(frame:IsShown() and frame.hideOnEscape) then if frame:IsShown() and frame.hideOnEscape then
local standardDialog = E.PopupDialogs[frame.which] local standardDialog = E.PopupDialogs[frame.which]
if(standardDialog) then if standardDialog then
local OnCancel = standardDialog.OnCancel local OnCancel = standardDialog.OnCancel
local noCancelOnEscape = standardDialog.noCancelOnEscape local noCancelOnEscape = standardDialog.noCancelOnEscape
if(OnCancel and not noCancelOnEscape) then if OnCancel and not noCancelOnEscape then
OnCancel(frame, frame.data, "clicked") OnCancel(frame, frame.data, "clicked")
end end
frame:Hide() frame:Hide()
@@ -424,9 +421,9 @@ function E:StaticPopup_CollapseTable()
end end
function E:StaticPopup_SetUpPosition(dialog) function E:StaticPopup_SetUpPosition(dialog)
if(not tContains(E.StaticPopup_DisplayedFrames, dialog)) then if not tContains(E.StaticPopup_DisplayedFrames, dialog) then
local lastFrame = E.StaticPopup_DisplayedFrames[getn(E.StaticPopup_DisplayedFrames)] local lastFrame = E.StaticPopup_DisplayedFrames[getn(E.StaticPopup_DisplayedFrames)]
if(lastFrame) then if lastFrame then
dialog:SetPoint("TOP", lastFrame, "BOTTOM", 0, -4) dialog:SetPoint("TOP", lastFrame, "BOTTOM", 0, -4)
else else
dialog:SetPoint("TOP", E.UIParent, "TOP", 0, -100) dialog:SetPoint("TOP", E.UIParent, "TOP", 0, -100)
@@ -436,7 +433,7 @@ function E:StaticPopup_SetUpPosition(dialog)
end end
function E:StaticPopupSpecial_Show(frame) function E:StaticPopupSpecial_Show(frame)
if(frame.exclusive) then if frame.exclusive then
E:StaticPopup_HideExclusive() E:StaticPopup_HideExclusive()
end end
E:StaticPopup_SetUpPosition(frame) E:StaticPopup_SetUpPosition(frame)
@@ -451,7 +448,7 @@ end
function E:StaticPopup_IsLastDisplayedFrame(frame) function E:StaticPopup_IsLastDisplayedFrame(frame)
for i = getn(E.StaticPopup_DisplayedFrames), 1, -1 do for i = getn(E.StaticPopup_DisplayedFrames), 1, -1 do
local popup = E.StaticPopup_DisplayedFrames[i] local popup = E.StaticPopup_DisplayedFrames[i]
if(popup:IsShown()) then if popup:IsShown() then
return frame == popup return frame == popup
end end
end end
@@ -543,33 +540,33 @@ function E:StaticPopup_OnUpdate()
end end
function E:StaticPopup_OnClick(index) function E:StaticPopup_OnClick(index)
if(not self:IsShown()) then if not self:IsShown() then
return return
end end
local which = self.which local which = self.which
local info = E.PopupDialogs[which] local info = E.PopupDialogs[which]
if(not info) then if not info then
return nil return nil
end end
local hide = true local hide = true
if(index == 1) then if index == 1 then
local OnAccept = info.OnAccept local OnAccept = info.OnAccept
if(OnAccept) then if OnAccept then
hide = not OnAccept(self, self.data, self.data2) hide = not OnAccept(self, self.data, self.data2)
end end
elseif(index == 3) then elseif index == 3 then
local OnAlt = info.OnAlt local OnAlt = info.OnAlt
if(OnAlt) then if OnAlt then
OnAlt(self, self.data, "clicked") OnAlt(self, self.data, "clicked")
end end
else else
local OnCancel = info.OnCancel local OnCancel = info.OnCancel
if(OnCancel) then if OnCancel then
hide = not OnCancel(self, self.data, "clicked") hide = not OnCancel(self, self.data, "clicked")
end end
end end
if(hide and (which == self.which) and (index ~= 3 or not info.noCloseOnAlt)) then if hide and (which == self.which) and (index ~= 3 or not info.noCloseOnAlt) then
self:Hide() self:Hide()
end end
end end
@@ -577,41 +574,41 @@ end
function E:StaticPopup_EditBoxOnEnterPressed() function E:StaticPopup_EditBoxOnEnterPressed()
local EditBoxOnEnterPressed, which, dialog local EditBoxOnEnterPressed, which, dialog
local parent = this:GetParent() local parent = this:GetParent()
if(parent.which) then if parent.which then
which = parent.which which = parent.which
dialog = parent dialog = parent
elseif(parent:GetParent().which) then elseif parent:GetParent().which then
which = parent:GetParent().which which = parent:GetParent().which
dialog = parent:GetParent() dialog = parent:GetParent()
end end
EditBoxOnEnterPressed = E.PopupDialogs[which].EditBoxOnEnterPressed EditBoxOnEnterPressed = E.PopupDialogs[which].EditBoxOnEnterPressed
if(EditBoxOnEnterPressed) then if EditBoxOnEnterPressed then
EditBoxOnEnterPressed(this, dialog.data) EditBoxOnEnterPressed(this, dialog.data)
end end
end end
function E:StaticPopup_EditBoxOnEscapePressed() function E:StaticPopup_EditBoxOnEscapePressed()
local EditBoxOnEscapePressed = E.PopupDialogs[this:GetParent().which].EditBoxOnEscapePressed local EditBoxOnEscapePressed = E.PopupDialogs[this:GetParent().which].EditBoxOnEscapePressed
if(EditBoxOnEscapePressed) then if EditBoxOnEscapePressed then
EditBoxOnEscapePressed(this, this:GetParent().data) EditBoxOnEscapePressed(this, this:GetParent().data)
end end
end end
function E:StaticPopup_EditBoxOnTextChanged(userInput) function E:StaticPopup_EditBoxOnTextChanged(userInput)
local EditBoxOnTextChanged = E.PopupDialogs[this:GetParent().which].EditBoxOnTextChanged local EditBoxOnTextChanged = E.PopupDialogs[this:GetParent().which].EditBoxOnTextChanged
if(EditBoxOnTextChanged) then if EditBoxOnTextChanged then
EditBoxOnTextChanged(this, this:GetParent().data) EditBoxOnTextChanged(this, this:GetParent().data)
end end
end end
function E:StaticPopup_FindVisible(which, data) function E:StaticPopup_FindVisible(which, data)
local info = E.PopupDialogs[which] local info = E.PopupDialogs[which]
if(not info) then if not info then
return nil return nil
end end
for index = 1, MAX_STATIC_POPUPS, 1 do for index = 1, MAX_STATIC_POPUPS, 1 do
local frame = _G["ElvUI_StaticPopup"..index] local frame = _G["ElvUI_StaticPopup"..index]
if(frame:IsShown() and (frame.which == which) and (not info.multiple or (frame.data == data))) then if (frame:IsShown() and (frame.which == which) and (not info.multiple or (frame.data == data))) then
return frame return frame
end end
end end
@@ -620,7 +617,7 @@ end
function E:StaticPopup_Resize(dialog, which) function E:StaticPopup_Resize(dialog, which)
local info = E.PopupDialogs[which] local info = E.PopupDialogs[which]
if(not info) then if not info then
return nil return nil
end end
@@ -632,29 +629,27 @@ function E:StaticPopup_Resize(dialog, which)
local maxHeightSoFar, maxWidthSoFar = (dialog.maxHeightSoFar or 0), (dialog.maxWidthSoFar or 0) local maxHeightSoFar, maxWidthSoFar = (dialog.maxHeightSoFar or 0), (dialog.maxWidthSoFar or 0)
local width = 320 local width = 320
if(dialog.numButtons == 3) then if dialog.numButtons == 3 then
width = 440 width = 440
elseif(info.showAlert or info.showAlertGear or info.closeButton) then elseif info.showAlert or info.showAlertGear or info.closeButton then
width = 420 width = 420
elseif(info.editBoxWidth and info.editBoxWidth > 260) then elseif info.editBoxWidth and info.editBoxWidth > 260 then
width = width + (info.editBoxWidth - 260) width = width + (info.editBoxWidth - 260)
end end
if(width > maxWidthSoFar) then if width > maxWidthSoFar then
dialog:SetWidth(width) dialog:SetWidth(width)
dialog.maxWidthSoFar = width dialog.maxWidthSoFar = width
end end
local height = 32 + text:GetHeight() + 8 + button1:GetHeight() local height = 32 + text:GetHeight() + 8 + button1:GetHeight()
if(info.hasEditBox) then if info.hasEditBox then
height = height + 8 + editBox:GetHeight() height = height + 8 + editBox:GetHeight()
elseif(info.hasMoneyFrame) then elseif info.hasMoneyFrame then
height = height + 16 height = height + 16
elseif(info.hasMoneyInputFrame) then
height = height + 22
end end
if(height > maxHeightSoFar) then if height > maxHeightSoFar then
dialog:SetHeight(height) dialog:SetHeight(height)
dialog.maxHeightSoFar = height dialog.maxHeightSoFar = height
end end
@@ -668,31 +663,31 @@ end
local tempButtonLocs = {} local tempButtonLocs = {}
function E:StaticPopup_Show(which, text_arg1, text_arg2, data) function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
local info = E.PopupDialogs[which] local info = E.PopupDialogs[which]
if(not info) then if not info then
return nil return nil
end end
if(UnitIsDeadOrGhost("player") and not info.whileDead) then if UnitIsDeadOrGhost("player") and not info.whileDead then
if(info.OnCancel) then if info.OnCancel then
info.OnCancel() info.OnCancel()
end end
return nil return nil
end end
if(InCinematic() and not info.interruptCinematic) then if InCinematic() and not info.interruptCinematic then
if(info.OnCancel) then if info.OnCancel then
info.OnCancel() info.OnCancel()
end end
return nil return nil
end end
if(info.cancels) then if info.cancels then
for index = 1, MAX_STATIC_POPUPS, 1 do for index = 1, MAX_STATIC_POPUPS, 1 do
local frame = _G["ElvUI_StaticPopup"..index] local frame = _G["ElvUI_StaticPopup"..index]
if(frame:IsShown() and (frame.which == info.cancels)) then if (frame:IsShown() and (frame.which == info.cancels)) then
frame:Hide() frame:Hide()
local OnCancel = E.PopupDialogs[frame.which].OnCancel local OnCancel = E.PopupDialogs[frame.which].OnCancel
if(OnCancel) then if OnCancel then
OnCancel(frame, frame.data, "override") OnCancel(frame, frame.data, "override")
end end
end end
@@ -701,39 +696,39 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
local dialog = nil local dialog = nil
dialog = E:StaticPopup_FindVisible(which, data) dialog = E:StaticPopup_FindVisible(which, data)
if(dialog) then if dialog then
if(not info.noCancelOnReuse) then if not info.noCancelOnReuse then
local OnCancel = info.OnCancel local OnCancel = info.OnCancel
if(OnCancel) then if OnCancel then
OnCancel(dialog, dialog.data, "override") OnCancel(dialog, dialog.data, "override")
end end
end end
dialog:Hide() dialog:Hide()
end end
if(not dialog) then if not dialog then
local index = 1 local index = 1
if(info.preferredIndex) then if info.preferredIndex then
index = info.preferredIndex index = info.preferredIndex
end end
for i = index, MAX_STATIC_POPUPS do for i = index, MAX_STATIC_POPUPS do
local frame = _G["ElvUI_StaticPopup"..i] local frame = _G["ElvUI_StaticPopup"..i]
if(not frame:IsShown()) then if not frame:IsShown() then
dialog = frame dialog = frame
break break
end end
end end
if(not dialog and info.preferredIndex) then if not dialog and info.preferredIndex then
for i = 1, info.preferredIndex do for i = 1, info.preferredIndex do
local frame = _G["ElvUI_StaticPopup"..i] local frame = _G["ElvUI_StaticPopup"..i]
if(not frame:IsShown()) then if not frame:IsShown() then
dialog = frame dialog = frame
break break
end end
end end
end end
end end
if(not dialog) then if not dialog then
if(info.OnCancel) then if info.OnCancel then
info.OnCancel() info.OnCancel()
end end
return nil return nil
@@ -745,9 +740,9 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
local text = _G[name.."Text"] local text = _G[name.."Text"]
text:SetText(format(info.text, text_arg1, text_arg2)) text:SetText(format(info.text, text_arg1, text_arg2))
if(info.closeButton) then if info.closeButton then
local closeButton = _G[name.."CloseButton"] local closeButton = _G[name.."CloseButton"]
if(info.closeButtonIsHide) then if info.closeButtonIsHide then
closeButton:SetNormalTexture("Interface\\Buttons\\UI-Panel-HideButton-Up") closeButton:SetNormalTexture("Interface\\Buttons\\UI-Panel-HideButton-Up")
closeButton:SetPushedTexture("Interface\\Buttons\\UI-Panel-HideButton-Down") closeButton:SetPushedTexture("Interface\\Buttons\\UI-Panel-HideButton-Down")
else else
@@ -760,17 +755,17 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
end end
local editBox = _G[name.."EditBox"] local editBox = _G[name.."EditBox"]
if(info.hasEditBox) then if info.hasEditBox then
editBox:Show() editBox:Show()
if(info.maxLetters) then if info.maxLetters then
editBox:SetMaxLetters(info.maxLetters) editBox:SetMaxLetters(info.maxLetters)
end end
if(info.maxBytes) then if info.maxBytes then
editBox:SetMaxBytes(info.maxBytes) editBox:SetMaxBytes(info.maxBytes)
end end
editBox:SetText("") editBox:SetText("")
if(info.editBoxWidth) then if info.editBoxWidth then
editBox:SetWidth(info.editBoxWidth) editBox:SetWidth(info.editBoxWidth)
else else
editBox:SetWidth(130) editBox:SetWidth(130)
@@ -779,22 +774,8 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
editBox:Hide() editBox:Hide()
end end
if(info.hasMoneyFrame) then if info.hasMoneyFrame then
_G[name.."MoneyFrame"]:Show() _G[name.."MoneyFrame"]:Show()
_G[name.."MoneyInputFrame"]:Hide()
elseif(info.hasMoneyInputFrame) then
local moneyInputFrame = _G[name.."MoneyInputFrame"]
moneyInputFrame:Show()
_G[name.."MoneyFrame"]:Hide()
if(info.EditBoxOnEnterPressed) then
moneyInputFrame.gold:SetScript("OnEnterPressed", E.StaticPopup_EditBoxOnEnterPressed)
moneyInputFrame.silver:SetScript("OnEnterPressed", E.StaticPopup_EditBoxOnEnterPressed)
moneyInputFrame.copper:SetScript("OnEnterPressed", E.StaticPopup_EditBoxOnEnterPressed)
else
moneyInputFrame.gold:SetScript("OnEnterPressed", nil)
moneyInputFrame.silver:SetScript("OnEnterPressed", nil)
moneyInputFrame.copper:SetScript("OnEnterPressed", nil)
end
else else
_G[name.."MoneyFrame"]:Hide() _G[name.."MoneyFrame"]:Hide()
end end
@@ -810,7 +791,7 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
local button2 = _G[name.."Button2"] local button2 = _G[name.."Button2"]
do do
-- assert(getn(tempButtonLocs == 0)) assert(getn(tempButtonLocs) == 0)
tinsert(tempButtonLocs, button1) tinsert(tempButtonLocs, button1)
tinsert(tempButtonLocs, button2) tinsert(tempButtonLocs, button2)
@@ -819,26 +800,26 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
tempButtonLocs[i]:SetText(info["button"..i]) tempButtonLocs[i]:SetText(info["button"..i])
tempButtonLocs[i]:Hide() tempButtonLocs[i]:Hide()
tempButtonLocs[i]:ClearAllPoints() tempButtonLocs[i]:ClearAllPoints()
if(not (info["button"..i] and ( not info["DisplayButton"..i] or info["DisplayButton"..i](dialog)))) then if not (info["button"..i] and (not info["DisplayButton"..i] or info["DisplayButton"..i](dialog))) then
tremove(tempButtonLocs, i) tremove(tempButtonLocs, i)
end end
end end
local numButtons = getn(tempButtonLocs) local numButtons = getn(tempButtonLocs)
dialog.numButtons = numButtons dialog.numButtons = numButtons
if(numButtons == 2) then if numButtons == 2 then
tempButtonLocs[1]:SetPoint("BOTTOMRIGHT", dialog, "BOTTOM", -6, 16) tempButtonLocs[1]:SetPoint("BOTTOMRIGHT", dialog, "BOTTOM", -6, 16)
elseif(numButtons == 1) then elseif numButtons == 1 then
tempButtonLocs[1]:SetPoint("BOTTOM", dialog, "BOTTOM", 0, 16) tempButtonLocs[1]:SetPoint("BOTTOM", dialog, "BOTTOM", 0, 16)
end end
for i = 1, numButtons do for i = 1, numButtons do
if(i > 1) then if i > 1 then
tempButtonLocs[i]:SetPoint("LEFT", tempButtonLocs[i-1], "RIGHT", 13, 0) tempButtonLocs[i]:SetPoint("LEFT", tempButtonLocs[i-1], "RIGHT", 13, 0)
end end
local width = tempButtonLocs[i]:GetTextWidth() local width = tempButtonLocs[i]:GetTextWidth()
if(width > 110) then if width > 110 then
tempButtonLocs[i]:SetWidth(width + 20) tempButtonLocs[i]:SetWidth(width + 20)
else else
tempButtonLocs[i]:SetWidth(120) tempButtonLocs[i]:SetWidth(120)
@@ -852,11 +833,11 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
end end
local alertIcon = _G[name.."AlertIcon"] local alertIcon = _G[name.."AlertIcon"]
if(info.showAlert) then if info.showAlert then
alertIcon:SetTexture("Interface\\DialogFrame\\DialogAlertIcon") alertIcon:SetTexture("Interface\\DialogFrame\\DialogAlertIcon")
alertIcon:SetPoint("LEFT", 24, 0) alertIcon:SetPoint("LEFT", 24, 0)
alertIcon:Show() alertIcon:Show()
elseif(info.showAlertGear) then elseif info.showAlertGear then
alertIcon:SetTexture("Interface\\DialogFrame\\DialogAlertIcon") alertIcon:SetTexture("Interface\\DialogFrame\\DialogAlertIcon")
alertIcon:SetPoint("LEFT", 24, 0) alertIcon:SetPoint("LEFT", 24, 0)
alertIcon:Show() alertIcon:Show()
@@ -865,7 +846,7 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
alertIcon:Hide() alertIcon:Hide()
end end
if(info.StartDelay) then if info.StartDelay then
dialog.startDelay = info.StartDelay() dialog.startDelay = info.StartDelay()
button1:Disable() button1:Disable()
else else
@@ -878,7 +859,7 @@ function E:StaticPopup_Show(which, text_arg1, text_arg2, data)
E:StaticPopup_Resize(dialog, which) E:StaticPopup_Resize(dialog, which)
if(info.sound) then if info.sound then
PlaySound(info.sound) PlaySound(info.sound)
end end
@@ -888,7 +869,7 @@ end
function E:StaticPopup_Hide(which, data) function E:StaticPopup_Hide(which, data)
for index = 1, MAX_STATIC_POPUPS, 1 do for index = 1, MAX_STATIC_POPUPS, 1 do
local dialog = _G["ElvUI_StaticPopup"..index] local dialog = _G["ElvUI_StaticPopup"..index]
if((dialog.which == which) and (not data or (data == dialog.data))) then if ((dialog.which == which) and (not data or (data == dialog.data))) then
dialog:Hide() dialog:Hide()
end end
end end