Tercio@11: Tercio@22: local major, minor = "DetailsFramework-1.0", 8 Tercio@11: local DF, oldminor = LibStub:NewLibrary (major, minor) Tercio@11: Tercio@18: if (not DF) then Tercio@20: DetailsFrameworkCanLoad = false Tercio@11: return Tercio@11: end Tercio@11: Tercio@20: DetailsFrameworkCanLoad = true Tercio@18: Tercio@11: local _type = type Tercio@11: local _unpack = unpack Tercio@11: local _ Tercio@11: local upper = string.upper Tercio@11: Tercio@11: DF.LabelNameCounter = 1 Tercio@11: DF.PictureNameCounter = 1 Tercio@11: DF.BarNameCounter = 1 Tercio@11: DF.DropDownCounter = 1 Tercio@11: DF.PanelCounter = 1 Tercio@11: DF.ButtonCounter = 1 Tercio@11: DF.SliderCounter = 1 Tercio@11: DF.SplitBarCounter = 1 Tercio@11: Tercio@22: LibStub:GetLibrary("AceTimer-3.0"):Embed (DF) Tercio@22: Tercio@11: do Tercio@11: local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)fw.lua") Tercio@11: if (path) then Tercio@11: DF.folder = "Interface\\AddOns\\" .. path Tercio@11: else Tercio@11: DF.folder = "" Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: DF.debug = false Tercio@11: Tercio@11: _G ["DetailsFramework"] = DF Tercio@11: Tercio@11: DF.embeds = DF.embeds or {} Tercio@11: local embed_functions = { Tercio@20: "RemoveRealName", Tercio@20: "table", Tercio@20: "BuildDropDownFontList", Tercio@11: "SetFontSize", Tercio@11: "SetFontFace", Tercio@11: "SetFontColor", Tercio@11: "GetFontSize", Tercio@11: "GetFontFace", Tercio@17: "SetFontOutline", Tercio@11: "trim", Tercio@11: "Msg", Tercio@11: "CreateFlashAnimation", Tercio@11: "Fade", Tercio@11: "NewColor", Tercio@11: "IsHtmlColor", Tercio@11: "ParseColors", Tercio@11: "BuildMenu", Tercio@11: "ShowTutorialAlertFrame", Tercio@11: "GetNpcIdFromGuid", Tercio@11: "ShowFeedbackPanel", Tercio@20: "SetAsOptionsPanel", Tercio@11: Tercio@11: "CreateDropDown", Tercio@11: "CreateButton", Tercio@11: "CreateColorPickButton", Tercio@11: "CreateLabel", Tercio@11: "CreateBar", Tercio@11: "CreatePanel", Tercio@11: "CreateFillPanel", Tercio@11: "ColorPick", Tercio@11: "IconPick", Tercio@11: "CreateSimplePanel", Tercio@11: "CreateChartPanel", Tercio@11: "CreateImage", Tercio@11: "CreateScrollBar", Tercio@11: "CreateSwitch", Tercio@11: "CreateSlider", Tercio@11: "CreateSplitBar", Tercio@11: "CreateTextEntry", Tercio@11: "Create1PxPanel", Tercio@11: "CreateFeedbackButton", Tercio@20: "CreateOptionsFrame", Tercio@22: "NewSpecialLuaEditorEntry", Tercio@20: "ShowPromptPanel", Tercio@22: "ShowTextPromptPanel", Tercio@11: "www_icons", Tercio@22: "GetTemplate", Tercio@22: "GetFrameworkFolder", Tercio@11: } Tercio@11: Tercio@20: DF.table = {} Tercio@20: Tercio@22: function DF:GetFrameworkFolder() Tercio@22: return DF.folder Tercio@22: end Tercio@22: Tercio@20: function DF.table.reverse (t) Tercio@20: local new = {} Tercio@20: local index = 1 Tercio@20: for i = #t, 1, -1 do Tercio@20: new [index] = t[i] Tercio@20: index = index + 1 Tercio@20: end Tercio@20: return new Tercio@20: end Tercio@20: Tercio@20: --> copy from table2 to table1 overwriting values Tercio@20: function DF.table.copy (t1, t2) Tercio@20: for key, value in pairs (t2) do Tercio@20: if (type (value) == "table") then Tercio@20: t1 [key] = t1 [key] or {} Tercio@20: DF.table.copy (t1 [key], t2 [key]) Tercio@20: else Tercio@20: t1 [key] = value Tercio@20: end Tercio@20: end Tercio@20: return t1 Tercio@20: end Tercio@20: Tercio@20: --> copy values that does exist on table2 but not on table1 Tercio@20: function DF.table.deploy (t1, t2) Tercio@20: for key, value in pairs (t2) do Tercio@20: if (type (value) == "table") then Tercio@20: t1 [key] = t1 [key] or {} Tercio@20: DF.table.deploy (t1 [key], t2 [key]) Tercio@22: elseif (t1 [key] == nil) then Tercio@20: t1 [key] = value Tercio@20: end Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: function DF.table.dump (t, s, deep) Tercio@20: s = s or "" Tercio@20: deep = deep or 0 Tercio@20: local space = "" Tercio@20: for i = 1, deep do Tercio@20: space = space .. " " Tercio@20: end Tercio@20: for key, value in pairs (t) do Tercio@20: local tpe = _type (value) Tercio@20: if (type (key) ~= "string") then Tercio@20: key = "unknown?" Tercio@20: end Tercio@20: if (tpe == "table") then Tercio@20: s = s .. space .. "[" .. key .. "] = |cFFa9ffa9table {|r\n" Tercio@20: s = s .. DF.table.dump (value, nil, deep+1) Tercio@20: s = s .. space .. "|cFFa9ffa9}|r\n" Tercio@20: elseif (tpe == "string") then Tercio@20: s = s .. space .. "[" .. key .. "] = '|cFFfff1c1" .. value .. "|r'\n" Tercio@20: elseif (tpe == "number") then Tercio@20: s = s .. space .. "[" .. key .. "] = |cFFffc1f4" .. value .. "|r\n" Tercio@20: elseif (tpe == "function") then Tercio@20: s = s .. space .. "[" .. key .. "] = function()\n" Tercio@20: elseif (tpe == "boolean") then Tercio@20: s = s .. space .. "[" .. key .. "] = |cFF99d0ff" .. (value and "true" or "false") .. "|r\n" Tercio@20: end Tercio@20: end Tercio@20: return s Tercio@20: end Tercio@20: Tercio@11: DF.www_icons = { Tercio@11: texture = "feedback_sites", Tercio@11: wowi = {0, 0.7890625, 0, 37/128}, Tercio@11: curse = {0, 0.7890625, 38/123, 79/128}, Tercio@11: mmoc = {0, 0.7890625, 80/123, 123/128}, Tercio@11: } Tercio@11: Tercio@11: function DF:Embed (target) Tercio@11: for k, v in pairs (embed_functions) do Tercio@11: target[v] = self[v] Tercio@11: end Tercio@11: self.embeds [target] = true Tercio@11: return target Tercio@11: end Tercio@11: Tercio@20: function DF:RemoveRealName (name) Tercio@20: return name:gsub (("%-.*"), "") Tercio@20: end Tercio@20: Tercio@11: function DF:SetFontSize (fontString, ...) Tercio@11: local fonte, _, flags = fontString:GetFont() Tercio@11: fontString:SetFont (fonte, max (...), flags) Tercio@11: end Tercio@11: function DF:SetFontFace (fontString, fontface) Tercio@11: local _, size, flags = fontString:GetFont() Tercio@11: fontString:SetFont (fontface, size, flags) Tercio@11: end Tercio@11: function DF:SetFontColor (fontString, r, g, b, a) Tercio@11: r, g, b, a = DF:ParseColors (r, g, b, a) Tercio@11: fontString:SetTextColor (r, g, b, a) Tercio@11: end Tercio@11: Tercio@11: function DF:GetFontSize (fontString) Tercio@11: local _, size = fontString:GetFont() Tercio@11: return size Tercio@11: end Tercio@11: function DF:GetFontFace (fontString) Tercio@11: local fontface = fontString:GetFont() Tercio@11: return fontface Tercio@11: end Tercio@11: Tercio@11: function DF:SetFontOutline (fontString, outline) Tercio@11: local fonte, size = fontString:GetFont() Tercio@11: if (outline) then Tercio@11: if (_type (outline) == "boolean" and outline) then Tercio@11: outline = "OUTLINE" Tercio@11: elseif (outline == 1) then Tercio@11: outline = "OUTLINE" Tercio@11: elseif (outline == 2) then Tercio@11: outline = "THICKOUTLINE" Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: fontString:SetFont (fonte, size, outline) Tercio@11: end Tercio@11: Tercio@11: function DF:trim (s) Tercio@11: local from = s:match"^%s*()" Tercio@11: return from > #s and "" or s:match(".*%S", from) Tercio@11: end Tercio@11: Tercio@11: function DF:Msg (msg) Tercio@11: print ("|cFFFFFFAA" .. self.__name .. "|r " .. msg) Tercio@11: end Tercio@11: Tercio@11: function DF:GetNpcIdFromGuid (guid) Tercio@11: local NpcId = select ( 6, strsplit ( "-", guid ) ) Tercio@11: if (NpcId) then Tercio@11: return tonumber ( NpcId ) Tercio@11: end Tercio@11: return 0 Tercio@11: end Tercio@11: Tercio@11: local onFinish = function (self) Tercio@11: if (self.showWhenDone) then Tercio@11: self.frame:SetAlpha (1) Tercio@11: else Tercio@11: self.frame:SetAlpha (0) Tercio@11: self.frame:Hide() Tercio@11: end Tercio@11: Tercio@11: if (self.onFinishFunc) then Tercio@11: self:onFinishFunc (self.frame) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local stop = function (self) Tercio@11: local FlashAnimation = self.FlashAnimation Tercio@11: FlashAnimation:Stop() Tercio@11: end Tercio@11: Tercio@11: local flash = function (self, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime, loopType) Tercio@11: Tercio@11: local FlashAnimation = self.FlashAnimation Tercio@11: Tercio@11: local fadeIn = FlashAnimation.fadeIn Tercio@11: local fadeOut = FlashAnimation.fadeOut Tercio@11: Tercio@11: fadeIn:Stop() Tercio@11: fadeOut:Stop() Tercio@11: Tercio@11: fadeIn:SetDuration (fadeInTime or 1) Tercio@11: fadeIn:SetEndDelay (flashInHoldTime or 0) Tercio@11: Tercio@11: fadeOut:SetDuration (fadeOutTime or 1) Tercio@11: fadeOut:SetEndDelay (flashOutHoldTime or 0) Tercio@11: Tercio@11: FlashAnimation.duration = flashDuration Tercio@11: FlashAnimation.loopTime = FlashAnimation:GetDuration() Tercio@11: FlashAnimation.finishAt = GetTime() + flashDuration Tercio@11: FlashAnimation.showWhenDone = showWhenDone Tercio@11: Tercio@11: FlashAnimation:SetLooping (loopType or "REPEAT") Tercio@11: Tercio@11: self:Show() Tercio@11: self:SetAlpha (0) Tercio@11: FlashAnimation:Play() Tercio@11: end Tercio@11: Tercio@11: function DF:CreateFlashAnimation (frame, onFinishFunc, onLoopFunc) Tercio@11: local FlashAnimation = frame:CreateAnimationGroup() Tercio@11: Tercio@11: FlashAnimation.fadeOut = FlashAnimation:CreateAnimation ("Alpha") --> fade out anime Tercio@11: FlashAnimation.fadeOut:SetOrder (1) Tercio@11: FlashAnimation.fadeOut:SetChange (1) Tercio@11: Tercio@11: FlashAnimation.fadeIn = FlashAnimation:CreateAnimation ("Alpha") --> fade in anime Tercio@11: FlashAnimation.fadeIn:SetOrder (2) Tercio@11: FlashAnimation.fadeIn:SetChange (-1) Tercio@11: Tercio@11: frame.FlashAnimation = FlashAnimation Tercio@11: FlashAnimation.frame = frame Tercio@11: FlashAnimation.onFinishFunc = onFinishFunc Tercio@11: Tercio@11: FlashAnimation:SetScript ("OnLoop", onLoopFunc) Tercio@11: FlashAnimation:SetScript ("OnFinished", onFinish) Tercio@11: Tercio@11: frame.Flash = flash Tercio@11: frame.Stop = stop Tercio@11: end Tercio@11: Tercio@11: ----------------------------------------- Tercio@11: Tercio@11: local fade_IN_finished_func = function (frame) Tercio@11: if (frame.fading_in) then Tercio@11: frame.hidden = true Tercio@11: frame.faded = true Tercio@11: frame.fading_in = false Tercio@11: frame:Hide() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local fade_OUT_finished_func = function (frame) Tercio@11: if (frame:IsShown() and frame.fading_out) then Tercio@11: frame.hidden = false Tercio@11: frame.faded = false Tercio@11: frame.fading_out = false Tercio@11: else Tercio@11: frame:SetAlpha(0) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local just_fade_func = function (frame) Tercio@11: frame.hidden = false Tercio@11: frame.faded = true Tercio@11: frame.fading_in = false Tercio@11: end Tercio@11: Tercio@11: local anim_OUT_alpha_func = function (frame) Tercio@11: frame.fading_out = false Tercio@11: end Tercio@11: Tercio@11: local anim_IN_alpha_func = function (frame) Tercio@11: frame.fading_in = false Tercio@11: end Tercio@11: Tercio@11: function DF:Fade (frame, tipo, velocidade, parametros) Tercio@11: Tercio@11: if (_type (frame) == "table") then Tercio@11: if (frame.dframework) then Tercio@11: frame = frame.widget Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: velocidade = velocidade or 0.3 Tercio@11: Tercio@11: if (upper (tipo) == "IN") then Tercio@11: Tercio@11: if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --> ja esta escondida Tercio@11: return Tercio@11: elseif (frame.fading_in) then --> ja esta com uma animação, se for true Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (frame.fading_out) then --> se tiver uma animação de aparecer em andamento se for true Tercio@11: frame.fading_out = false Tercio@11: end Tercio@11: Tercio@11: UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0) Tercio@11: frame.fading_in = true Tercio@11: Tercio@11: frame.fadeInfo.finishedFunc = fade_IN_finished_func Tercio@11: frame.fadeInfo.finishedArg1 = frame Tercio@11: Tercio@11: elseif (upper (tipo) == "OUT") then --> aparecer Tercio@11: if (frame:GetAlpha() == 1 and not frame.hidden and not frame.fading_in) then --> ja esta na tela Tercio@11: return Tercio@11: elseif (frame.fading_out) then --> já ta com fading out Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (frame.fading_in) then --> se tiver uma animação de hidar em andamento se for true Tercio@11: frame.fading_in = false Tercio@11: end Tercio@11: Tercio@11: frame:Show() Tercio@11: UIFrameFadeOut (frame, velocidade, frame:GetAlpha(), 1.0) Tercio@11: frame.fading_out = true Tercio@11: Tercio@11: frame.fadeInfo.finishedFunc = fade_OUT_finished_func Tercio@11: frame.fadeInfo.finishedArg1 = frame Tercio@11: Tercio@11: elseif (tipo == 0) then --> força o frame a ser mostrado Tercio@11: frame.hidden = false Tercio@11: frame.faded = false Tercio@11: frame.fading_out = false Tercio@11: frame.fading_in = false Tercio@11: frame:Show() Tercio@11: frame:SetAlpha (1) Tercio@11: Tercio@11: elseif (tipo == 1) then --> força o frame a ser hidado Tercio@11: frame.hidden = true Tercio@11: frame.faded = true Tercio@11: frame.fading_out = false Tercio@11: frame.fading_in = false Tercio@11: frame:SetAlpha (0) Tercio@11: frame:Hide() Tercio@11: Tercio@11: elseif (tipo == -1) then --> apenas da fade sem hidar Tercio@11: if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then --> ja esta escondida Tercio@11: return Tercio@11: elseif (frame.fading_in) then --> ja esta com uma animação, se for true Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (frame.fading_out) then --> se tiver uma animação de aparecer em andamento se for true Tercio@11: frame.fading_out = false Tercio@11: end Tercio@11: Tercio@11: UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), 0) Tercio@11: frame.fading_in = true Tercio@11: frame.fadeInfo.finishedFunc = just_fade_func Tercio@11: frame.fadeInfo.finishedArg1 = frame Tercio@11: Tercio@11: elseif (upper (tipo) == "ALPHAANIM") then Tercio@11: Tercio@11: local value = velocidade Tercio@11: local currentApha = frame:GetAlpha() Tercio@11: frame:Show() Tercio@11: Tercio@11: if (currentApha < value) then Tercio@11: if (frame.fading_in) then --> se tiver uma animação de hidar em andamento se for true Tercio@11: frame.fading_in = false Tercio@11: frame.fadeInfo.finishedFunc = nil Tercio@11: end Tercio@11: UIFrameFadeOut (frame, 0.3, currentApha, value) Tercio@11: frame.fading_out = true Tercio@11: Tercio@11: frame.fadeInfo.finishedFunc = anim_OUT_alpha_func Tercio@11: frame.fadeInfo.finishedArg1 = frame Tercio@11: Tercio@11: else Tercio@11: if (frame.fading_out) then --> se tiver uma animação de hidar em andamento se for true Tercio@11: frame.fading_out = false Tercio@11: frame.fadeInfo.finishedFunc = nil Tercio@11: end Tercio@11: UIFrameFadeIn (frame, 0.3, currentApha, value) Tercio@11: frame.fading_in = true Tercio@11: Tercio@11: frame.fadeInfo.finishedFunc = anim_IN_alpha_func Tercio@11: frame.fadeInfo.finishedArg1 = frame Tercio@11: end Tercio@11: Tercio@11: elseif (upper (tipo) == "ALPHA") then --> setando um alpha determinado Tercio@11: if (frame.fading_in or frame.fading_out) then Tercio@11: frame.fadeInfo.finishedFunc = nil Tercio@11: UIFrameFadeIn (frame, velocidade, frame:GetAlpha(), frame:GetAlpha()) Tercio@11: end Tercio@11: frame.hidden = false Tercio@11: frame.faded = false Tercio@11: frame.fading_in = false Tercio@11: frame.fading_out = false Tercio@11: frame:Show() Tercio@11: frame:SetAlpha (velocidade) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: --> points Tercio@11: Tercio@11: function DF:CheckPoints (v1, v2, v3, v4, v5, object) Tercio@11: Tercio@11: if (not v1 and not v2) then Tercio@11: return "topleft", object.widget:GetParent(), "topleft", 0, 0 Tercio@11: end Tercio@11: Tercio@11: if (_type (v1) == "string") then Tercio@11: local frameGlobal = _G [v1] Tercio@11: if (frameGlobal and frameGlobal.GetObjectType) then Tercio@11: return DF:CheckPoints (frameGlobal, v2, v3, v4, v5, object) Tercio@11: end Tercio@11: Tercio@11: elseif (_type (v2) == "string") then Tercio@11: local frameGlobal = _G [v2] Tercio@11: if (frameGlobal and frameGlobal.GetObjectType) then Tercio@11: return DF:CheckPoints (v1, frameGlobal, v3, v4, v5, object) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (_type (v1) == "string" and _type (v2) == "table") then --> :setpoint ("left", frame, _, _, _) Tercio@11: if (not v3 or _type (v3) == "number") then --> :setpoint ("left", frame, 10, 10) Tercio@11: v1, v2, v3, v4, v5 = v1, v2, v1, v3, v4 Tercio@11: end Tercio@11: Tercio@11: elseif (_type (v1) == "string" and _type (v2) == "number") then --> :setpoint ("topleft", x, y) Tercio@11: v1, v2, v3, v4, v5 = v1, object.widget:GetParent(), v1, v2, v3 Tercio@11: Tercio@11: elseif (_type (v1) == "number") then --> :setpoint (x, y) Tercio@11: v1, v2, v3, v4, v5 = "topleft", object.widget:GetParent(), "topleft", v1, v2 Tercio@11: Tercio@11: elseif (_type (v1) == "table") then --> :setpoint (frame, x, y) Tercio@11: v1, v2, v3, v4, v5 = "topleft", v1, "topleft", v2, v3 Tercio@11: Tercio@11: end Tercio@11: Tercio@11: if (not v2) then Tercio@11: v2 = object.widget:GetParent() Tercio@11: elseif (v2.dframework) then Tercio@11: v2 = v2.widget Tercio@11: end Tercio@11: Tercio@11: return v1 or "topleft", v2, v3 or "topleft", v4 or 0, v5 or 0 Tercio@11: end Tercio@11: Tercio@11: Tercio@11: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: --> colors Tercio@11: Tercio@11: function DF:NewColor (_colorname, _colortable, _green, _blue, _alpha) Tercio@11: assert (_type (_colorname) == "string", "NewColor: colorname must be a string.") Tercio@11: assert (not DF.alias_text_colors [_colorname], "NewColor: colorname already exists.") Tercio@11: Tercio@11: if (_type (_colortable) == "table") then Tercio@11: if (_colortable[1] and _colortable[2] and _colortable[3]) then Tercio@11: _colortable[4] = _colortable[4] or 1 Tercio@11: DF.alias_text_colors [_colorname] = _colortable Tercio@11: else Tercio@11: error ("invalid color table.") Tercio@11: end Tercio@11: elseif (_colortable and _green and _blue) then Tercio@11: _alpha = _alpha or 1 Tercio@11: DF.alias_text_colors [_colorname] = {_colortable, _green, _blue, _alpha} Tercio@11: else Tercio@11: error ("invalid parameter.") Tercio@11: end Tercio@11: Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: function DF:IsHtmlColor (color) Tercio@11: return DF.alias_text_colors [color] Tercio@11: end Tercio@11: Tercio@11: local tn = tonumber Tercio@11: function DF:ParseColors (_arg1, _arg2, _arg3, _arg4) Tercio@11: if (_type (_arg1) == "table") then Tercio@11: _arg1, _arg2, _arg3, _arg4 = _unpack (_arg1) Tercio@11: Tercio@11: elseif (_type (_arg1) == "string") then Tercio@11: Tercio@11: if (string.find (_arg1, "#")) then Tercio@11: _arg1 = _arg1:gsub ("#","") Tercio@11: if (string.len (_arg1) == 8) then --alpha Tercio@11: _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, tn ("0x" .. _arg1:sub (7, 8))/255, tn ("0x" .. _arg1:sub (1, 2))/255 Tercio@11: else Tercio@11: _arg1, _arg2, _arg3, _arg4 = tn ("0x" .. _arg1:sub (1, 2))/255, tn ("0x" .. _arg1:sub (3, 4))/255, tn ("0x" .. _arg1:sub (5, 6))/255, 1 Tercio@11: end Tercio@11: Tercio@11: else Tercio@11: local color = DF.alias_text_colors [_arg1] Tercio@11: if (color) then Tercio@11: _arg1, _arg2, _arg3, _arg4 = _unpack (color) Tercio@11: else Tercio@11: _arg1, _arg2, _arg3, _arg4 = _unpack (DF.alias_text_colors.none) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (not _arg1) then Tercio@11: _arg1 = 1 Tercio@11: end Tercio@11: if (not _arg2) then Tercio@11: _arg2 = 1 Tercio@11: end Tercio@11: if (not _arg3) then Tercio@11: _arg3 = 1 Tercio@11: end Tercio@11: if (not _arg4) then Tercio@11: _arg4 = 1 Tercio@11: end Tercio@11: Tercio@11: return _arg1, _arg2, _arg3, _arg4 Tercio@11: end Tercio@11: Tercio@11: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: --> menus Tercio@11: Tercio@22: function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template) Tercio@22: Tercio@22: if (not parent.widget_list) then Tercio@22: DF:SetAsOptionsPanel (parent) Tercio@22: end Tercio@11: Tercio@11: local cur_x = x_offset Tercio@11: local cur_y = y_offset Tercio@11: local max_x = 0 Tercio@11: Tercio@11: height = abs ((height or parent:GetHeight()) - abs (y_offset) + 20) Tercio@11: height = height*-1 Tercio@11: Tercio@11: for index, widget_table in ipairs (menu) do Tercio@11: Tercio@20: if (widget_table.type == "blank" or widget_table.type == "space") then Tercio@20: -- do nothing Tercio@20: Tercio@20: elseif (widget_table.type == "label" or widget_table.type == "text") then Tercio@22: local label = DF:CreateLabel (parent, widget_table.get() or widget_table.text, widget_table.text_template or text_template or widget_table.size, widget_table.color, widget_table.font, nil, "$parentWidget" .. index, "overlay") Tercio@20: label._get = widget_table.get Tercio@20: label.widget_type = "label" Tercio@20: label:SetPoint (cur_x, cur_y) Tercio@20: tinsert (parent.widget_list, label) Tercio@20: Tercio@20: elseif (widget_table.type == "select" or widget_table.type == "dropdown") then Tercio@22: local dropdown = DF:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get(), dropdown_template) Tercio@11: dropdown.tooltip = widget_table.desc Tercio@20: dropdown._get = widget_table.get Tercio@20: dropdown.widget_type = "select" Tercio@22: local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12) Tercio@11: dropdown:SetPoint ("left", label, "right", 2) Tercio@11: label:SetPoint (cur_x, cur_y) Tercio@11: Tercio@11: local size = label.widget:GetStringWidth() + 140 + 4 Tercio@11: if (size > max_x) then Tercio@11: max_x = size Tercio@11: end Tercio@11: Tercio@20: tinsert (parent.widget_list, dropdown) Tercio@20: Tercio@11: elseif (widget_table.type == "toggle" or widget_table.type == "switch") then Tercio@22: local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get(), nil, nil, nil, nil, switch_template) Tercio@11: switch.tooltip = widget_table.desc Tercio@20: switch._get = widget_table.get Tercio@20: switch.widget_type = "toggle" Tercio@11: switch.OnSwitch = widget_table.set Tercio@11: Tercio@22: if (switch_is_box) then Tercio@22: switch:SetAsCheckBox() Tercio@22: end Tercio@22: Tercio@22: local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12) Tercio@11: switch:SetPoint ("left", label, "right", 2) Tercio@11: label:SetPoint (cur_x, cur_y) Tercio@11: Tercio@11: local size = label.widget:GetStringWidth() + 60 + 4 Tercio@11: if (size > max_x) then Tercio@11: max_x = size Tercio@11: end Tercio@11: Tercio@20: tinsert (parent.widget_list, switch) Tercio@20: Tercio@11: elseif (widget_table.type == "range" or widget_table.type == "slider") then Tercio@11: local is_decimanls = widget_table.usedecimals Tercio@22: local slider = DF:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(), is_decimanls, nil, nil, slider_template) Tercio@11: slider.tooltip = widget_table.desc Tercio@20: slider._get = widget_table.get Tercio@20: slider.widget_type = "range" Tercio@11: slider:SetHook ("OnValueChange", widget_table.set) Tercio@11: Tercio@22: local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12) Tercio@11: slider:SetPoint ("left", label, "right", 2) Tercio@11: label:SetPoint (cur_x, cur_y) Tercio@11: Tercio@11: local size = label.widget:GetStringWidth() + 140 + 6 Tercio@11: if (size > max_x) then Tercio@11: max_x = size Tercio@11: end Tercio@11: Tercio@20: tinsert (parent.widget_list, slider) Tercio@20: Tercio@11: elseif (widget_table.type == "color" or widget_table.type == "color") then Tercio@22: local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set, nil, button_template) Tercio@11: colorpick.tooltip = widget_table.desc Tercio@20: colorpick._get = widget_table.get Tercio@20: colorpick.widget_type = "color" Tercio@11: Tercio@11: local default_value, g, b, a = widget_table.get() Tercio@11: if (type (default_value) == "table") then Tercio@11: colorpick:SetColor (unpack (default_value)) Tercio@11: else Tercio@11: colorpick:SetColor (default_value, g, b, a) Tercio@11: end Tercio@11: Tercio@22: local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or text_template or 12) Tercio@11: colorpick:SetPoint ("left", label, "right", 2) Tercio@11: label:SetPoint (cur_x, cur_y) Tercio@11: Tercio@11: local size = label.widget:GetStringWidth() + 60 + 4 Tercio@11: if (size > max_x) then Tercio@11: max_x = size Tercio@11: end Tercio@11: Tercio@20: tinsert (parent.widget_list, colorpick) Tercio@20: Tercio@11: elseif (widget_table.type == "execute" or widget_table.type == "button") then Tercio@11: Tercio@22: local button = DF:NewButton (parent, nil, "$parentWidget" .. index, nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name, nil, button_template) Tercio@22: if (not button_template) then Tercio@22: button:InstallCustomTexture() Tercio@22: end Tercio@22: Tercio@11: button:SetPoint (cur_x, cur_y) Tercio@11: button.tooltip = widget_table.desc Tercio@20: button.widget_type = "execute" Tercio@11: Tercio@11: local size = button:GetWidth() + 4 Tercio@11: if (size > max_x) then Tercio@11: max_x = size Tercio@11: end Tercio@11: Tercio@20: tinsert (parent.widget_list, button) Tercio@20: Tercio@11: end Tercio@11: Tercio@11: if (widget_table.spacement) then Tercio@11: cur_y = cur_y - 30 Tercio@11: else Tercio@11: cur_y = cur_y - 20 Tercio@11: end Tercio@11: Tercio@11: if (cur_y < height) then Tercio@11: cur_y = y_offset Tercio@11: cur_x = cur_x + max_x + 30 Tercio@11: Tercio@11: max_x = 0 Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: --> tutorials Tercio@11: Tercio@11: function DF:ShowTutorialAlertFrame (maintext, desctext, clickfunc) Tercio@11: Tercio@11: local TutorialAlertFrame = _G.DetailsFrameworkTutorialAlertFrame Tercio@11: Tercio@11: if (not TutorialAlertFrame) then Tercio@11: Tercio@11: TutorialAlertFrame = CreateFrame ("ScrollFrame", "DetailsFrameworkTutorialAlertFrame", UIParent, "DetailsFrameworkTutorialAlertFrameTemplate") Tercio@11: TutorialAlertFrame.isFirst = true Tercio@11: TutorialAlertFrame:SetPoint ("left", UIParent, "left", -20, 100) Tercio@11: Tercio@11: TutorialAlertFrame:SetWidth (290) Tercio@11: TutorialAlertFrame.ScrollChild:SetWidth (256) Tercio@11: Tercio@11: local scrollname = TutorialAlertFrame.ScrollChild:GetName() Tercio@11: _G [scrollname .. "BorderTopLeft"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderTopRight"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderBotLeft"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderBotRight"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderLeft"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderRight"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderBottom"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "BorderTop"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: Tercio@11: local iconbg = _G [scrollname .. "QuestIconBg"] Tercio@11: iconbg:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]]) Tercio@11: iconbg:SetTexCoord (0, 1, 0, 1) Tercio@11: iconbg:SetSize (100, 100) Tercio@11: iconbg:ClearAllPoints() Tercio@11: iconbg:SetPoint ("bottomleft", TutorialAlertFrame.ScrollChild, "bottomleft") Tercio@11: Tercio@11: _G [scrollname .. "Exclamation"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: _G [scrollname .. "QuestionMark"]:SetVertexColor (1, 0.8, 0, 1) Tercio@11: Tercio@11: _G [scrollname .. "TopText"]:SetText ("Details!") --string Tercio@11: _G [scrollname .. "QuestName"]:SetText ("") --string Tercio@11: _G [scrollname .. "BottomText"]:SetText ("") --string Tercio@11: Tercio@11: TutorialAlertFrame.ScrollChild.IconShine:SetTexture ([[Interface\MainMenuBar\UI-MainMenuBar-EndCap-Human]]) Tercio@11: Tercio@11: TutorialAlertFrame:SetScript ("OnMouseUp", function (self) Tercio@11: if (self.clickfunc and type (self.clickfunc) == "function") then Tercio@11: self.clickfunc() Tercio@11: end Tercio@11: self:Hide() Tercio@11: end) Tercio@11: TutorialAlertFrame:Hide() Tercio@11: end Tercio@11: Tercio@11: if (type (maintext) == "string") then Tercio@11: TutorialAlertFrame.ScrollChild.QuestName:SetText (maintext) Tercio@11: else Tercio@11: TutorialAlertFrame.ScrollChild.QuestName:SetText ("") Tercio@11: end Tercio@11: Tercio@11: if (type (desctext) == "string") then Tercio@11: TutorialAlertFrame.ScrollChild.BottomText:SetText (desctext) Tercio@11: else Tercio@11: TutorialAlertFrame.ScrollChild.BottomText:SetText ("") Tercio@11: end Tercio@11: Tercio@11: TutorialAlertFrame.clickfunc = clickfunc Tercio@11: TutorialAlertFrame:Show() Tercio@11: DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST") Tercio@11: end Tercio@11: Tercio@20: local refresh_options = function (self) Tercio@20: for _, widget in ipairs (self.widget_list) do Tercio@20: if (widget._get) then Tercio@20: if (widget.widget_type == "label") then Tercio@20: if (widget._get()) then Tercio@20: widget:SetText (widget._get()) Tercio@20: end Tercio@20: elseif (widget.widget_type == "select") then Tercio@20: widget:Select (widget._get()) Tercio@20: elseif (widget.widget_type == "toggle" or widget.widget_type == "range") then Tercio@20: widget:SetValue (widget._get()) Tercio@20: elseif (widget.widget_type == "color") then Tercio@20: local default_value, g, b, a = widget._get() Tercio@20: if (type (default_value) == "table") then Tercio@20: widget:SetColor (unpack (default_value)) Tercio@20: else Tercio@20: widget:SetColor (default_value, g, b, a) Tercio@20: end Tercio@20: end Tercio@20: end Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: function DF:SetAsOptionsPanel (frame) Tercio@20: frame.RefreshOptions = refresh_options Tercio@20: frame.widget_list = {} Tercio@20: end Tercio@20: Tercio@11: function DF:CreateOptionsFrame (name, title, template) Tercio@11: Tercio@11: template = template or 1 Tercio@11: Tercio@11: if (template == 2) then Tercio@11: local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate") Tercio@11: tinsert (UISpecialFrames, name) Tercio@11: options_frame:SetSize (500, 200) Tercio@20: options_frame.RefreshOptions = refresh_options Tercio@20: options_frame.widget_list = {} Tercio@11: Tercio@11: options_frame:SetScript ("OnMouseDown", function(self, button) Tercio@11: if (button == "RightButton") then Tercio@11: if (self.moving) then Tercio@11: self.moving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: end Tercio@11: return options_frame:Hide() Tercio@11: elseif (button == "LeftButton" and not self.moving) then Tercio@11: self.moving = true Tercio@11: self:StartMoving() Tercio@11: end Tercio@11: end) Tercio@11: options_frame:SetScript ("OnMouseUp", function(self) Tercio@11: if (self.moving) then Tercio@11: self.moving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: options_frame:SetMovable (true) Tercio@11: options_frame:EnableMouse (true) Tercio@11: options_frame:SetFrameStrata ("DIALOG") Tercio@11: options_frame:SetToplevel (true) Tercio@11: Tercio@11: options_frame:Hide() Tercio@11: Tercio@11: options_frame:SetPoint ("center", UIParent, "center") Tercio@11: options_frame.TitleText:SetText (title) Tercio@11: options_frame.portrait:SetTexture ([[Interface\CHARACTERFRAME\TEMPORARYPORTRAIT-FEMALE-BLOODELF]]) Tercio@11: Tercio@11: return options_frame Tercio@11: Tercio@11: elseif (template == 1) then Tercio@11: Tercio@11: local options_frame = CreateFrame ("frame", name, UIParent) Tercio@11: tinsert (UISpecialFrames, name) Tercio@11: options_frame:SetSize (500, 200) Tercio@20: options_frame.RefreshOptions = refresh_options Tercio@20: options_frame.widget_list = {} Tercio@11: Tercio@11: options_frame:SetScript ("OnMouseDown", function(self, button) Tercio@11: if (button == "RightButton") then Tercio@11: if (self.moving) then Tercio@11: self.moving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: end Tercio@11: return options_frame:Hide() Tercio@11: elseif (button == "LeftButton" and not self.moving) then Tercio@11: self.moving = true Tercio@11: self:StartMoving() Tercio@11: end Tercio@11: end) Tercio@11: options_frame:SetScript ("OnMouseUp", function(self) Tercio@11: if (self.moving) then Tercio@11: self.moving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: options_frame:SetMovable (true) Tercio@11: options_frame:EnableMouse (true) Tercio@11: options_frame:SetFrameStrata ("DIALOG") Tercio@11: options_frame:SetToplevel (true) Tercio@11: Tercio@11: options_frame:Hide() Tercio@11: Tercio@11: options_frame:SetPoint ("center", UIParent, "center") Tercio@11: Tercio@11: options_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, Tercio@18: edgeFile = DF.folder .. "border_2", edgeSize = 32, Tercio@11: insets = {left = 1, right = 1, top = 1, bottom = 1}}) Tercio@11: options_frame:SetBackdropColor (0, 0, 0, .7) Tercio@11: Tercio@11: local texturetitle = options_frame:CreateTexture (nil, "artwork") Tercio@11: texturetitle:SetTexture ([[Interface\CURSOR\Interact]]) Tercio@11: texturetitle:SetTexCoord (0, 1, 0, 1) Tercio@11: texturetitle:SetVertexColor (1, 1, 1, 1) Tercio@11: texturetitle:SetPoint ("topleft", options_frame, "topleft", 2, -3) Tercio@11: texturetitle:SetWidth (36) Tercio@11: texturetitle:SetHeight (36) Tercio@11: Tercio@11: local title = DF:NewLabel (options_frame, nil, "$parentTitle", nil, title, nil, 20, "yellow") Tercio@11: title:SetPoint ("left", texturetitle, "right", 2, -1) Tercio@11: DF:SetFontOutline (title, true) Tercio@11: Tercio@11: local c = CreateFrame ("Button", nil, options_frame, "UIPanelCloseButton") Tercio@11: c:SetWidth (32) Tercio@11: c:SetHeight (32) Tercio@11: c:SetPoint ("TOPRIGHT", options_frame, "TOPRIGHT", -3, -3) Tercio@11: c:SetFrameLevel (options_frame:GetFrameLevel()+1) Tercio@11: Tercio@11: return options_frame Tercio@11: end Tercio@22: end Tercio@22: Tercio@22: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@22: --> templates Tercio@22: Tercio@22: DF.font_templates = {} Tercio@22: DF.font_templates ["ORANGE_FONT_TEMPLATE"] = {color = "orange", size = 11, font = "Accidental Presidency"} Tercio@22: DF.font_templates ["OPTIONS_FONT_TEMPLATE"] = {color = "yellow", size = 12, font = "Accidental Presidency"} Tercio@22: Tercio@22: DF.dropdown_templates = {} Tercio@22: DF.dropdown_templates ["OPTIONS_DROPDOWN_TEMPLATE"] = { Tercio@22: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@22: backdropcolor = {1, 1, 1, .5}, Tercio@22: backdropbordercolor = {0, 0, 0, 1}, Tercio@22: onentercolor = {1, 1, 1, .5}, Tercio@22: onenterbordercolor = {1, 1, 1, 1}, Tercio@22: } Tercio@22: Tercio@22: DF.switch_templates = {} Tercio@22: DF.switch_templates ["OPTIONS_CHECKBOX_TEMPLATE"] = { Tercio@22: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@22: backdropcolor = {1, 1, 1, .5}, Tercio@22: backdropbordercolor = {0, 0, 0, 1}, Tercio@22: width = 18, Tercio@22: height = 18, Tercio@22: enabled_backdropcolor = {1, 1, 1, .5}, Tercio@22: disabled_backdropcolor = {1, 1, 1, .2}, Tercio@22: onenterbordercolor = {1, 1, 1, 1}, Tercio@22: } Tercio@22: DF.switch_templates ["OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"] = { Tercio@22: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@22: backdropcolor = {1, 1, 1, .5}, Tercio@22: backdropbordercolor = {0, 0, 0, 1}, Tercio@22: width = 18, Tercio@22: height = 18, Tercio@22: enabled_backdropcolor = {1, 1, 1, .5}, Tercio@22: disabled_backdropcolor = {1, 1, 1, .5}, Tercio@22: onenterbordercolor = {1, 1, 1, 1}, Tercio@22: } Tercio@22: Tercio@22: DF.button_templates = {} Tercio@22: DF.button_templates ["OPTIONS_BUTTON_TEMPLATE"] = { Tercio@22: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@22: backdropcolor = {1, 1, 1, .5}, Tercio@22: backdropbordercolor = {0, 0, 0, 1}, Tercio@22: } Tercio@22: Tercio@22: DF.slider_templates = {} Tercio@22: DF.slider_templates ["OPTIONS_SLIDER_TEMPLATE"] = { Tercio@22: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@22: backdropcolor = {1, 1, 1, .5}, Tercio@22: backdropbordercolor = {0, 0, 0, 1}, Tercio@22: onentercolor = {1, 1, 1, .5}, Tercio@22: onenterbordercolor = {1, 1, 1, 1}, Tercio@22: thumbtexture = [[Interface\Tooltips\UI-Tooltip-Background]], Tercio@22: thumbwidth = 16, Tercio@22: thumbheight = 14, Tercio@22: thumbcolor = {0, 0, 0, 0.5}, Tercio@22: } Tercio@22: Tercio@22: function DF:GetTemplate (type, template_name) Tercio@22: local template_table Tercio@22: if (type == "font") then Tercio@22: template_table = DF.font_templates Tercio@22: elseif (type == "dropdown") then Tercio@22: template_table = DF.dropdown_templates Tercio@22: elseif (type == "button") then Tercio@22: template_table = DF.button_templates Tercio@22: elseif (type == "switch") then Tercio@22: template_table = DF.switch_templates Tercio@22: elseif (type == "slider") then Tercio@22: template_table = DF.slider_templates Tercio@22: end Tercio@22: return template_table [template_name] Tercio@22: end Tercio@22: