From 429b34d7ef53d1e99cfb1ae544dcfbe57efc45b1 Mon Sep 17 00:00:00 2001 From: shagu Date: Sat, 31 Dec 2016 15:59:37 +0100 Subject: [PATCH] api: add firstrun wizard functionality --- pfUI.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pfUI.lua b/pfUI.lua index 7520a7ff..03cb01f7 100644 --- a/pfUI.lua +++ b/pfUI.lua @@ -103,6 +103,50 @@ ScriptErrors:SetScript("OnShow", function(msg) ScriptErrors:Hide() end) +pfUI.firstrun = CreateFrame("Frame", "pfFirstRunWizard", UIParent) +pfUI.firstrun.steps = {} +pfUI.firstrun.next = nil + +pfUI.firstrun:RegisterEvent("PLAYER_ENTERING_WORLD") +pfUI.firstrun:SetScript("OnEvent", function() pfUI.firstrun:NextStep() end) + +function pfUI.firstrun:AddStep(name, yfunc, nfunc, descr, cmpnt) + if not name then return end + pfUI.firstrun.steps[name] = {} + if yfunc then pfUI.firstrun.steps[name].yfunc = yfunc end + if nfunc then pfUI.firstrun.steps[name].nfunc = nfunc end + if descr then pfUI.firstrun.steps[name].descr = descr end + if cmpnt then pfUI.firstrun.steps[name].cmpnt = cmpnt end +end + +function pfUI.firstrun:NextStep() + for name, step in pairs(pfUI.firstrun.steps) do + if not pfUI_init[name] then + local function yes() + pfUI_init[name] = true + if step.yfunc then step.yfunc() end + this:GetParent():Hide() + pfUI.firstrun:NextStep() + end + + local function no() + pfUI_init[name] = true + if step.nfunc then step.nfunc() end + this:GetParent():Hide() + pfUI.firstrun:NextStep() + end + + if step.cmpnt and step.cmpnt == "edit" then + pfUI.api:CreateQuestionDialog(step.descr, yes, no, true) + else + pfUI.api:CreateQuestionDialog(step.descr, yes, no, false) + end + + return + end + end +end + pfUI.info = CreateFrame("Button", "pfInfoBox", UIParent) pfUI.info:Hide()