From 2455d8def3d89d5294a3e6105ab4b1ebcbeab409 Mon Sep 17 00:00:00 2001 From: shagu Date: Wed, 28 Mar 2018 20:51:22 +0200 Subject: [PATCH] api: move infobox into ui-widgets --- api/ui-widgets.lua | 76 +++++++++++++++++++++++++++++++++++++++++++ modules/hoverbind.lua | 2 +- modules/unlock.lua | 2 +- pfUI.lua | 57 -------------------------------- 4 files changed, 78 insertions(+), 59 deletions(-) diff --git a/api/ui-widgets.lua b/api/ui-widgets.lua index fdae0551..5374a2ad 100644 --- a/api/ui-widgets.lua +++ b/api/ui-widgets.lua @@ -576,3 +576,79 @@ function pfUI.api.CreateQuestionDialog(text, yes, no, editbox) if question.text:GetStringWidth() > 200 then width = question.text:GetStringWidth() end question:SetWidth( width + 2*padding) end + + +-- [ Question Dialog ] +-- Creates a pfUI infobox popup window: +-- 'text' [string] text that will be displayed. +-- 'time' [number] time in seconds till the popup will be faded +-- 'parent' [frame] frame which will be used as parent for the dialog (defaults to UIParent) +-- 'height' [number] manual height of the popup (defaults to 100) +function pfUI.api.CreateInfoBox(text, time, parent, height) + if not text then return end + if not time then time = 5 end + if not parent then parent = UIParent end + if not height then height = 100 end + + local infobox = pfInfoBox + if not infobox then + infobox = CreateFrame("Button", "pfInfoBox", UIParent) + infobox:Hide() + + infobox:SetScript("OnUpdate", function() + local time = infobox.lastshow + infobox.duration - GetTime() + infobox.timeout:SetValue(time) + + if GetTime() > infobox.lastshow + infobox.duration then + infobox:SetAlpha(infobox:GetAlpha()-0.05) + + if infobox:GetAlpha() <= 0.1 then + infobox:Hide() + infobox:SetAlpha(1) + end + elseif MouseIsOver(this) then + this:SetAlpha(max(0.4, this:GetAlpha() - .1)) + else + this:SetAlpha(min(1, this:GetAlpha() + .1)) + end + end) + + infobox:SetScript("OnClick", function() + this:Hide() + end) + + infobox.text = infobox:CreateFontString("Status", "HIGH", "GameFontNormal") + infobox.text:ClearAllPoints() + infobox.text:SetFontObject(GameFontWhite) + + infobox.timeout = CreateFrame("StatusBar", nil, infobox) + infobox.timeout:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") + infobox.timeout:SetStatusBarColor(.3,1,.8,1) + + infobox:ClearAllPoints() + infobox.text:SetAllPoints(infobox) + infobox.text:SetFont(pfUI.font_default, 14, "OUTLINE") + + pfUI.api.CreateBackdrop(infobox) + infobox:SetPoint("TOP", 0, -25) + + infobox.timeout:ClearAllPoints() + infobox.timeout:SetPoint("TOPLEFT", infobox, "TOPLEFT", 3, -3) + infobox.timeout:SetPoint("TOPRIGHT", infobox, "TOPRIGHT", -3, 3) + infobox.timeout:SetHeight(2) + end + + infobox.text:SetText(text) + infobox.timeout:SetMinMaxValues(0, time) + infobox.timeout:SetValue(time) + + infobox.duration = time + infobox.lastshow = GetTime() + + infobox:SetWidth(infobox.text:GetStringWidth() + 50) + infobox:SetParent(parent) + infobox:SetHeight(height) + + infobox:SetFrameStrata("FULLSCREEN_DIALOG") + infobox:Show() +end diff --git a/modules/hoverbind.lua b/modules/hoverbind.lua index e234c630..ab7ba6dd 100644 --- a/modules/hoverbind.lua +++ b/modules/hoverbind.lua @@ -38,7 +38,7 @@ pfUI:RegisterModule("hoverbind", function () pfUI.hoverbind.edit:Show() local txt = T["|cff33ffccKeybind Mode|r\nThis mode allows you to bind keyboard shortcuts to your actionbars.\nBy hovering a button with your cursor and pressing a key, the key will be assigned to that button.\nHit Escape on a button to remove bindings.\n\nPress Escape or click on an empty area to leave the keybind mode."] - pfUI.info:ShowInfoBox(txt, 30, pfUI.hoverbind.edit) + CreateInfoBox(txt, 30, pfUI.hoverbind.edit) end) pfUI.hoverbind:SetScript("OnHide",function() diff --git a/modules/unlock.lua b/modules/unlock.lua index d7bd900c..4697eec1 100644 --- a/modules/unlock.lua +++ b/modules/unlock.lua @@ -309,7 +309,7 @@ pfUI:RegisterModule("unlock", function () function pfUI.unlock:UnlockFrames() local txt = T["|cff33ffccUnlock Mode|r\nThis mode allows you to move frames by dragging them using the mouse cursor. Frames can be scaled by scrolling up and down.\nTo scale multiple frames at once (eg. raidframes), hold down the shift key while scrolling. Click into an empty space to go back to the pfUI menu."] - pfUI.info:ShowInfoBox(txt, 15, pfUI.unlock) + CreateInfoBox(txt, 15, pfUI.unlock) pfUI.unlock:Show() pfUI.gui:Hide() diff --git a/pfUI.lua b/pfUI.lua index d3f8f40a..0de9a95c 100644 --- a/pfUI.lua +++ b/pfUI.lua @@ -165,60 +165,3 @@ function pfUI.SetupCVars() COMBAT_TEXT_SHOW_HONOR_GAINED = "1" UIParentLoadAddOn("Blizzard_CombatText") end - -pfUI.info = CreateFrame("Button", "pfInfoBox", UIParent) -pfUI.info:Hide() - -pfUI.info.text = pfUI.info:CreateFontString("Status", "HIGH", "GameFontNormal") -pfUI.info.text:ClearAllPoints() -pfUI.info.text:SetFontObject(GameFontWhite) - -pfUI.info.timeout = CreateFrame("StatusBar", nil, pfUI.info) -pfUI.info.timeout:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") -pfUI.info.timeout:SetStatusBarColor(.3,1,.8,1) - -function pfUI.info:ShowInfoBox(text, time, parent, height) - if not text then return end - if not time then time = 5 end - if not parent then parent = UIParent end - if not height then height = 100 end - - pfUI.info:SetParent(parent) - pfUI.info:ClearAllPoints() - pfUI.info.text:SetAllPoints(pfUI.info) - pfUI.info.text:SetText(text) - pfUI.info.text:SetFont(pfUI.font_default, 14, "OUTLINE") - - pfUI.info:SetWidth(pfUI.info.text:GetStringWidth() + 50) - pfUI.info:SetHeight(height) - pfUI.info:SetFrameStrata("DIALOG") - pfUI.api.CreateBackdrop(pfUI.info) - pfUI.info:SetPoint("TOP", 0, -25) - - pfUI.info.timeout:ClearAllPoints() - pfUI.info.timeout:SetPoint("TOPLEFT", pfUI.info, "TOPLEFT", 3, -3) - pfUI.info.timeout:SetPoint("TOPRIGHT", pfUI.info, "TOPRIGHT", -3, 3) - pfUI.info.timeout:SetHeight(2) - pfUI.info.timeout:SetMinMaxValues(0, time) - pfUI.info.timeout:SetValue(time) - - pfUI.info.duration = time - pfUI.info.lastshow = GetTime() - pfUI.info:Show() -end - -pfUI.info:SetScript("OnUpdate", function() - local time = pfUI.info.lastshow + pfUI.info.duration - GetTime() - pfUI.info.timeout:SetValue(time) - - if GetTime() > pfUI.info.lastshow + pfUI.info.duration then - pfUI.info:SetAlpha(pfUI.info:GetAlpha()-0.05) - end - - if pfUI.info:GetAlpha() <= 0.1 then - pfUI.info:Hide() - pfUI.info:SetAlpha(1) - end -end) - -pfUI.info:SetScript("OnClick", function() this:Hide() end)