Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@20: if (not DF or not DetailsFrameworkCanLoad) then Tercio@18: return Tercio@18: end Tercio@18: Tercio@20: local _ Tercio@11: --> lua locals Tercio@11: local _rawset = rawset --> lua local Tercio@11: local _rawget = rawget --> lua local Tercio@11: local _setmetatable = setmetatable --> lua local Tercio@11: local _unpack = unpack --> lua local Tercio@11: local _type = type --> lua local Tercio@11: local _math_floor = math.floor --> lua local Tercio@11: local loadstring = loadstring --> lua local Tercio@11: Tercio@11: local cleanfunction = function() end Tercio@11: local APIFrameFunctions Tercio@11: Tercio@39: do Tercio@39: local metaPrototype = { Tercio@39: WidgetType = "panel", Tercio@39: SetHook = DF.SetHook, Tercio@39: RunHooksForWidget = DF.RunHooksForWidget, Tercio@39: } Tercio@39: Tercio@39: _G [DF.GlobalWidgetControlNames ["panel"]] = _G [DF.GlobalWidgetControlNames ["panel"]] or metaPrototype Tercio@39: end Tercio@39: Tercio@39: local PanelMetaFunctions = _G [DF.GlobalWidgetControlNames ["panel"]] Tercio@39: Tercio@58: --> mixin for options functions Tercio@58: DF.OptionsFunctions = { Tercio@58: SetOption = function (self, optionName, optionValue) Tercio@58: if (self.options) then Tercio@58: self.options [optionName] = optionValue Tercio@58: else Tercio@58: self.options = {} Tercio@58: self.options [optionName] = optionValue Tercio@58: end Tercio@58: end, Tercio@58: Tercio@58: GetOption = function (self, optionName) Tercio@58: return self.options and self.options [optionName] Tercio@58: end, Tercio@58: Tercio@58: GetAllOptions = function (self) Tercio@58: if (self.options) then Tercio@58: local optionsTable = {} Tercio@58: for key, _ in pairs (self.options) do Tercio@58: optionsTable [#optionsTable + 1] = key Tercio@58: end Tercio@58: return optionsTable Tercio@58: else Tercio@58: return {} Tercio@58: end Tercio@58: end, Tercio@58: Tercio@58: BuildOptionsTable = function (self, defaultOptions, userOptions) Tercio@58: self.options = self.options or {} Tercio@58: DF.table.deploy (self.options, userOptions or {}) Tercio@58: DF.table.deploy (self.options, defaultOptions or {}) Tercio@58: end Tercio@58: } Tercio@58: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> metatables Tercio@11: Tercio@11: PanelMetaFunctions.__call = function (_table, value) Tercio@11: --> nothing to do Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> members Tercio@11: Tercio@11: --> tooltip Tercio@11: local gmember_tooltip = function (_object) Tercio@11: return _object:GetTooltip() Tercio@11: end Tercio@11: --> shown Tercio@11: local gmember_shown = function (_object) Tercio@11: return _object:IsShown() Tercio@11: end Tercio@11: --> backdrop color Tercio@11: local gmember_color = function (_object) Tercio@11: return _object.frame:GetBackdropColor() Tercio@11: end Tercio@11: --> backdrop table Tercio@11: local gmember_backdrop = function (_object) Tercio@11: return _object.frame:GetBackdrop() Tercio@11: end Tercio@11: --> frame width Tercio@11: local gmember_width = function (_object) Tercio@11: return _object.frame:GetWidth() Tercio@11: end Tercio@11: --> frame height Tercio@11: local gmember_height = function (_object) Tercio@11: return _object.frame:GetHeight() Tercio@11: end Tercio@11: --> locked Tercio@11: local gmember_locked = function (_object) Tercio@11: return _rawget (_object, "is_locked") Tercio@11: end Tercio@11: Tercio@39: PanelMetaFunctions.GetMembers = PanelMetaFunctions.GetMembers or {} Tercio@39: PanelMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip Tercio@39: PanelMetaFunctions.GetMembers ["shown"] = gmember_shown Tercio@39: PanelMetaFunctions.GetMembers ["color"] = gmember_color Tercio@39: PanelMetaFunctions.GetMembers ["backdrop"] = gmember_backdrop Tercio@39: PanelMetaFunctions.GetMembers ["width"] = gmember_width Tercio@39: PanelMetaFunctions.GetMembers ["height"] = gmember_height Tercio@39: PanelMetaFunctions.GetMembers ["locked"] = gmember_locked Tercio@11: Tercio@11: PanelMetaFunctions.__index = function (_table, _member_requested) Tercio@11: Tercio@39: local func = PanelMetaFunctions.GetMembers [_member_requested] Tercio@11: if (func) then Tercio@11: return func (_table, _member_requested) Tercio@11: end Tercio@11: Tercio@11: local fromMe = _rawget (_table, _member_requested) Tercio@11: if (fromMe) then Tercio@11: return fromMe Tercio@11: end Tercio@11: Tercio@11: return PanelMetaFunctions [_member_requested] Tercio@11: end Tercio@11: Tercio@11: Tercio@11: --> tooltip Tercio@11: local smember_tooltip = function (_object, _value) Tercio@11: return _object:SetTooltip (_value) Tercio@11: end Tercio@11: --> show Tercio@11: local smember_show = function (_object, _value) Tercio@11: if (_value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> hide Tercio@11: local smember_hide = function (_object, _value) Tercio@11: if (not _value) then Tercio@11: return _object:Show() Tercio@11: else Tercio@11: return _object:Hide() Tercio@11: end Tercio@11: end Tercio@11: --> backdrop color Tercio@11: local smember_color = function (_object, _value) Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (_value) Tercio@11: return _object:SetBackdropColor (_value1, _value2, _value3, _value4) Tercio@11: end Tercio@11: --> frame width Tercio@11: local smember_width = function (_object, _value) Tercio@11: return _object.frame:SetWidth (_value) Tercio@11: end Tercio@11: --> frame height Tercio@11: local smember_height = function (_object, _value) Tercio@11: return _object.frame:SetHeight (_value) Tercio@11: end Tercio@11: Tercio@11: --> locked Tercio@11: local smember_locked = function (_object, _value) Tercio@11: if (_value) then Tercio@11: _object.frame:SetMovable (false) Tercio@11: return _rawset (_object, "is_locked", true) Tercio@11: else Tercio@11: _object.frame:SetMovable (true) Tercio@11: _rawset (_object, "is_locked", false) Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: --> backdrop Tercio@11: local smember_backdrop = function (_object, _value) Tercio@11: return _object.frame:SetBackdrop (_value) Tercio@11: end Tercio@11: Tercio@11: --> close with right button Tercio@11: local smember_right_close = function (_object, _value) Tercio@11: return _rawset (_object, "rightButtonClose", _value) Tercio@11: end Tercio@11: Tercio@39: PanelMetaFunctions.SetMembers = PanelMetaFunctions.SetMembers or {} Tercio@39: PanelMetaFunctions.SetMembers["tooltip"] = smember_tooltip Tercio@39: PanelMetaFunctions.SetMembers["show"] = smember_show Tercio@39: PanelMetaFunctions.SetMembers["hide"] = smember_hide Tercio@39: PanelMetaFunctions.SetMembers["color"] = smember_color Tercio@39: PanelMetaFunctions.SetMembers["backdrop"] = smember_backdrop Tercio@39: PanelMetaFunctions.SetMembers["width"] = smember_width Tercio@39: PanelMetaFunctions.SetMembers["height"] = smember_height Tercio@39: PanelMetaFunctions.SetMembers["locked"] = smember_locked Tercio@39: PanelMetaFunctions.SetMembers["close_with_right"] = smember_right_close Tercio@39: Tercio@11: PanelMetaFunctions.__newindex = function (_table, _key, _value) Tercio@39: local func = PanelMetaFunctions.SetMembers [_key] Tercio@11: if (func) then Tercio@11: return func (_table, _value) Tercio@11: else Tercio@11: return _rawset (_table, _key, _value) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> methods Tercio@11: Tercio@11: --> right click to close Tercio@11: function PanelMetaFunctions:CreateRightClickLabel (textType, w, h, close_text) Tercio@11: local text Tercio@11: w = w or 20 Tercio@11: h = h or 20 Tercio@11: Tercio@11: if (close_text) then Tercio@11: text = close_text Tercio@11: else Tercio@11: if (textType) then Tercio@11: textType = string.lower (textType) Tercio@11: if (textType == "short") then Tercio@11: text = "close window" Tercio@11: elseif (textType == "medium") then Tercio@11: text = "close window" Tercio@11: elseif (textType == "large") then Tercio@11: text = "close window" Tercio@11: end Tercio@11: else Tercio@11: text = "close window" Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: return DF:NewLabel (self, _, "$parentRightMouseToClose", nil, "|TInterface\\TUTORIALFRAME\\UI-TUTORIAL-FRAME:"..w..":"..h..":0:1:512:512:8:70:328:409|t " .. text) Tercio@11: end Tercio@11: Tercio@11: --> show & hide Tercio@11: function PanelMetaFunctions:Show() Tercio@11: self.frame:Show() Tercio@11: Tercio@11: end Tercio@11: function PanelMetaFunctions:Hide() Tercio@11: self.frame:Hide() Tercio@11: Tercio@11: end Tercio@11: Tercio@11: -- setpoint Tercio@11: function PanelMetaFunctions:SetPoint (v1, v2, v3, v4, v5) Tercio@11: v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self) Tercio@11: if (not v1) then Tercio@11: print ("Invalid parameter for SetPoint") Tercio@11: return Tercio@11: end Tercio@11: return self.widget:SetPoint (v1, v2, v3, v4, v5) Tercio@11: end Tercio@11: Tercio@11: -- sizes Tercio@11: function PanelMetaFunctions:SetSize (w, h) Tercio@11: if (w) then Tercio@11: self.frame:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: self.frame:SetHeight (h) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- clear Tercio@11: function PanelMetaFunctions:HideWidgets() Tercio@11: for widgetName, widgetSelf in pairs (self) do Tercio@11: if (type (widgetSelf) == "table" and widgetSelf.dframework) then Tercio@11: widgetSelf:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- backdrop Tercio@11: function PanelMetaFunctions:SetBackdrop (background, edge, tilesize, edgesize, tile, left, right, top, bottom) Tercio@11: Tercio@11: if (_type (background) == "boolean" and not background) then Tercio@11: return self.frame:SetBackdrop (nil) Tercio@11: Tercio@11: elseif (_type (background) == "table") then Tercio@11: self.frame:SetBackdrop (background) Tercio@11: Tercio@11: else Tercio@11: local currentBackdrop = self.frame:GetBackdrop() or {edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", tile=true, tileSize=16, edgeSize=16, insets={left=1, right=0, top=0, bottom=0}} Tercio@11: currentBackdrop.bgFile = background or currentBackdrop.bgFile Tercio@11: currentBackdrop.edgeFile = edgeFile or currentBackdrop.edgeFile Tercio@11: currentBackdrop.tileSize = tilesize or currentBackdrop.tileSize Tercio@11: currentBackdrop.edgeSize = edgesize or currentBackdrop.edgeSize Tercio@11: currentBackdrop.tile = tile or currentBackdrop.tile Tercio@11: currentBackdrop.insets.left = left or currentBackdrop.insets.left Tercio@11: currentBackdrop.insets.right = left or currentBackdrop.insets.right Tercio@11: currentBackdrop.insets.top = left or currentBackdrop.insets.top Tercio@11: currentBackdrop.insets.bottom = left or currentBackdrop.insets.bottom Tercio@11: self.frame:SetBackdrop (currentBackdrop) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- backdropcolor Tercio@11: function PanelMetaFunctions:SetBackdropColor (color, arg2, arg3, arg4) Tercio@11: if (arg2) then Tercio@11: self.frame:SetBackdropColor (color, arg2, arg3, arg4 or 1) Tercio@11: else Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (color) Tercio@11: self.frame:SetBackdropColor (_value1, _value2, _value3, _value4) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- border color Tercio@11: function PanelMetaFunctions:SetBackdropBorderColor (color, arg2, arg3, arg4) Tercio@11: if (arg2) then Tercio@11: return self.frame:SetBackdropBorderColor (color, arg2, arg3, arg4) Tercio@11: end Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (color) Tercio@11: self.frame:SetBackdropBorderColor (_value1, _value2, _value3, _value4) Tercio@11: end Tercio@11: Tercio@11: -- tooltip Tercio@11: function PanelMetaFunctions:SetTooltip (tooltip) Tercio@11: if (tooltip) then Tercio@11: return _rawset (self, "have_tooltip", tooltip) Tercio@11: else Tercio@11: return _rawset (self, "have_tooltip", nil) Tercio@11: end Tercio@11: end Tercio@11: function PanelMetaFunctions:GetTooltip() Tercio@11: return _rawget (self, "have_tooltip") Tercio@11: end Tercio@11: Tercio@11: -- frame levels Tercio@11: function PanelMetaFunctions:GetFrameLevel() Tercio@11: return self.widget:GetFrameLevel() Tercio@11: end Tercio@11: function PanelMetaFunctions:SetFrameLevel (level, frame) Tercio@11: if (not frame) then Tercio@11: return self.widget:SetFrameLevel (level) Tercio@11: else Tercio@11: local framelevel = frame:GetFrameLevel (frame) + level Tercio@11: return self.widget:SetFrameLevel (framelevel) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- frame stratas Tercio@11: function PanelMetaFunctions:SetFrameStrata() Tercio@11: return self.widget:GetFrameStrata() Tercio@11: end Tercio@11: function PanelMetaFunctions:SetFrameStrata (strata) Tercio@11: if (_type (strata) == "table") then Tercio@11: self.widget:SetFrameStrata (strata:GetFrameStrata()) Tercio@11: else Tercio@11: self.widget:SetFrameStrata (strata) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> scripts Tercio@11: Tercio@11: local OnEnter = function (frame) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnEnter", frame, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: if (frame.MyObject.have_tooltip) then Tercio@11: GameCooltip2:Reset() Tercio@11: GameCooltip2:SetType ("tooltip") Tercio@11: GameCooltip2:SetColor ("main", "transparent") Tercio@11: GameCooltip2:AddLine (frame.MyObject.have_tooltip) Tercio@11: GameCooltip2:SetOwner (frame) Tercio@11: GameCooltip2:ShowCooltip() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnLeave = function (frame) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnLeave", frame, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: if (frame.MyObject.have_tooltip) then Tercio@11: GameCooltip2:ShowMe (false) Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local OnHide = function (frame) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnHide", frame, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnShow = function (frame) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnShow", frame, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnMouseDown = function (frame, button) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnMouseDown", frame, button, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: if (frame.MyObject.container == UIParent) then Tercio@11: if (not frame.isLocked and frame:IsMovable()) then Tercio@11: frame.isMoving = true Tercio@11: frame:StartMoving() Tercio@11: end Tercio@11: Tercio@11: elseif (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then Tercio@11: if (not frame.isLocked and frame:IsMovable()) then Tercio@11: frame.MyObject.container.isMoving = true Tercio@11: frame.MyObject.container:StartMoving() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local OnMouseUp = function (frame, button) Tercio@39: local capsule = frame.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnMouseUp", frame, button, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: if (button == "RightButton" and frame.MyObject.rightButtonClose) then Tercio@11: frame.MyObject:Hide() Tercio@11: end Tercio@11: Tercio@11: if (frame.MyObject.container == UIParent) then Tercio@11: if (frame.isMoving) then Tercio@11: frame:StopMovingOrSizing() Tercio@11: frame.isMoving = false Tercio@11: end Tercio@11: else Tercio@11: if (frame.MyObject.container.isMoving) then Tercio@11: frame.MyObject.container:StopMovingOrSizing() Tercio@11: frame.MyObject.container.isMoving = false Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> object constructor Tercio@11: function DF:CreatePanel (parent, w, h, backdrop, backdropcolor, bordercolor, member, name) Tercio@11: return DF:NewPanel (parent, parent, name, member, w, h, backdrop, backdropcolor, bordercolor) Tercio@11: end Tercio@11: Tercio@11: function DF:NewPanel (parent, container, name, member, w, h, backdrop, backdropcolor, bordercolor) Tercio@11: Tercio@11: if (not name) then Tercio@11: name = "DetailsFrameworkPanelNumber" .. DF.PanelCounter Tercio@11: DF.PanelCounter = DF.PanelCounter + 1 Tercio@11: Tercio@11: elseif (not parent) then Tercio@11: parent = UIParent Tercio@11: end Tercio@11: if (not container) then Tercio@11: container = parent Tercio@11: end Tercio@11: Tercio@11: if (name:find ("$parent")) then Tercio@11: name = name:gsub ("$parent", parent:GetName()) Tercio@11: end Tercio@11: Tercio@11: local PanelObject = {type = "panel", dframework = true} Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = PanelObject Tercio@11: end Tercio@11: Tercio@11: if (parent.dframework) then Tercio@11: parent = parent.widget Tercio@11: end Tercio@11: if (container.dframework) then Tercio@11: container = container.widget Tercio@11: end Tercio@11: Tercio@11: --> default members: Tercio@11: --> misc Tercio@11: PanelObject.is_locked = true Tercio@11: PanelObject.container = container Tercio@11: PanelObject.rightButtonClose = false Tercio@11: Tercio@11: PanelObject.frame = CreateFrame ("frame", name, parent, "DetailsFrameworkPanelTemplate") Tercio@11: PanelObject.widget = PanelObject.frame Tercio@11: Tercio@11: if (not APIFrameFunctions) then Tercio@11: APIFrameFunctions = {} Tercio@11: local idx = getmetatable (PanelObject.frame).__index Tercio@11: for funcName, funcAddress in pairs (idx) do Tercio@11: if (not PanelMetaFunctions [funcName]) then Tercio@11: PanelMetaFunctions [funcName] = function (object, ...) Tercio@20: local x = loadstring ( "return _G['"..object.frame:GetName().."']:"..funcName.."(...)") Tercio@11: return x (...) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: PanelObject.frame:SetWidth (w or 100) Tercio@11: PanelObject.frame:SetHeight (h or 100) Tercio@11: Tercio@11: PanelObject.frame.MyObject = PanelObject Tercio@11: Tercio@39: PanelObject.HookList = { Tercio@39: OnEnter = {}, Tercio@39: OnLeave = {}, Tercio@39: OnHide = {}, Tercio@39: OnShow = {}, Tercio@39: OnMouseDown = {}, Tercio@39: OnMouseUp = {}, Tercio@39: } Tercio@39: Tercio@11: --> hooks Tercio@11: PanelObject.frame:SetScript ("OnEnter", OnEnter) Tercio@11: PanelObject.frame:SetScript ("OnLeave", OnLeave) Tercio@11: PanelObject.frame:SetScript ("OnHide", OnHide) Tercio@11: PanelObject.frame:SetScript ("OnShow", OnShow) Tercio@11: PanelObject.frame:SetScript ("OnMouseDown", OnMouseDown) Tercio@11: PanelObject.frame:SetScript ("OnMouseUp", OnMouseUp) Tercio@11: Tercio@11: _setmetatable (PanelObject, PanelMetaFunctions) Tercio@11: Tercio@11: if (backdrop) then Tercio@11: PanelObject:SetBackdrop (backdrop) Tercio@11: elseif (_type (backdrop) == "boolean") then Tercio@11: PanelObject.frame:SetBackdrop (nil) Tercio@11: end Tercio@11: Tercio@11: if (backdropcolor) then Tercio@11: PanelObject:SetBackdropColor (backdropcolor) Tercio@11: end Tercio@11: Tercio@11: if (bordercolor) then Tercio@11: PanelObject:SetBackdropBorderColor (bordercolor) Tercio@11: end Tercio@11: Tercio@11: return PanelObject Tercio@11: end Tercio@11: Tercio@11: ------------fill panel Tercio@11: Tercio@11: local button_on_enter = function (self) Tercio@11: self.MyObject._icon:SetBlendMode ("ADD") Tercio@49: if (self.MyObject.onenter_func) then Tercio@49: pcall (self.MyObject.onenter_func, self.MyObject) Tercio@49: end Tercio@11: end Tercio@11: local button_on_leave = function (self) Tercio@11: self.MyObject._icon:SetBlendMode ("BLEND") Tercio@49: if (self.MyObject.onleave_func) then Tercio@49: pcall (self.MyObject.onleave_func, self.MyObject) Tercio@49: end Tercio@11: end Tercio@11: Tercio@20: local add_row = function (self, t, need_update) Tercio@20: local index = #self.rows+1 Tercio@20: Tercio@20: local thisrow = DF:NewPanel (self, self, "$parentHeader_" .. self._name .. index, nil, 1, 20) Tercio@20: thisrow.backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Gold-Background]]} Tercio@20: thisrow.color = "silver" Tercio@20: thisrow.type = t.type Tercio@20: thisrow.func = t.func Tercio@20: thisrow.name = t.name Tercio@20: thisrow.notext = t.notext Tercio@20: thisrow.icon = t.icon Tercio@20: thisrow.iconalign = t.iconalign Tercio@20: Tercio@20: thisrow.hidden = t.hidden or false Tercio@20: Tercio@49: thisrow.onenter = t.onenter Tercio@49: thisrow.onleave = t.onleave Tercio@49: Tercio@20: local text = DF:NewLabel (thisrow, nil, self._name .. "$parentLabel" .. index, "text") Tercio@20: text:SetPoint ("left", thisrow, "left", 2, 0) Tercio@20: text:SetText (t.name) Tercio@20: Tercio@20: tinsert (self._raw_rows, t) Tercio@20: tinsert (self.rows, thisrow) Tercio@20: Tercio@20: if (need_update) then Tercio@20: self:AlignRows() Tercio@20: end Tercio@11: end Tercio@11: Tercio@20: local align_rows = function (self) Tercio@20: Tercio@20: local rows_shown = 0 Tercio@20: for index, row in ipairs (self.rows) do Tercio@20: if (not row.hidden) then Tercio@20: rows_shown = rows_shown + 1 Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: local cur_width = 0 Tercio@20: local row_width = self._width / rows_shown Tercio@22: Tercio@20: local sindex = 1 Tercio@20: Tercio@20: wipe (self._anchors) Tercio@20: Tercio@20: for index, row in ipairs (self.rows) do Tercio@20: if (not row.hidden) then Tercio@20: if (self._autowidth) then Tercio@20: if (self._raw_rows [index].width) then Tercio@20: row.width = self._raw_rows [index].width Tercio@20: else Tercio@20: row.width = row_width Tercio@20: end Tercio@20: row:SetPoint ("topleft", self, "topleft", cur_width, 0) Tercio@20: tinsert (self._anchors, cur_width) Tercio@20: cur_width = cur_width + row_width + 1 Tercio@20: else Tercio@20: row:SetPoint ("topleft", self, "topleft", cur_width, 0) Tercio@20: row.width = self._raw_rows [index].width Tercio@20: tinsert (self._anchors, cur_width) Tercio@20: cur_width = cur_width + self._raw_rows [index].width + 1 Tercio@20: end Tercio@42: Tercio@20: row:Show() Tercio@20: Tercio@20: local type = row.type Tercio@20: Tercio@20: if (type == "text") then Tercio@20: for i = 1, #self.scrollframe.lines do Tercio@20: local line = self.scrollframe.lines [i] Tercio@20: local text = tremove (line.text_available) Tercio@20: if (not text) then Tercio@20: self:CreateRowText (line) Tercio@20: text = tremove (line.text_available) Tercio@20: end Tercio@20: tinsert (line.text_inuse, text) Tercio@20: text:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0) Tercio@20: text:SetWidth (row.width) Tercio@42: Tercio@42: DF:SetFontSize (text, row.textsize or 10) Tercio@42: text:SetJustifyH (row.textalign or "left") Tercio@20: end Tercio@20: elseif (type == "entry") then Tercio@20: for i = 1, #self.scrollframe.lines do Tercio@20: local line = self.scrollframe.lines [i] Tercio@20: local entry = tremove (line.entry_available) Tercio@20: if (not entry) then Tercio@20: self:CreateRowEntry (line) Tercio@20: entry = tremove (line.entry_available) Tercio@20: end Tercio@20: tinsert (line.entry_inuse, entry) Tercio@20: entry:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0) Tercio@20: if (sindex == rows_shown) then Tercio@20: entry:SetWidth (row.width - 25) Tercio@20: else Tercio@20: entry:SetWidth (row.width) Tercio@20: end Tercio@20: entry.func = row.func Tercio@49: Tercio@49: entry.onenter_func = nil Tercio@49: entry.onleave_func = nil Tercio@49: Tercio@49: if (row.onenter) then Tercio@49: entry.onenter_func = row.onenter Tercio@49: end Tercio@49: if (row.onleave) then Tercio@49: entry.onleave_func = row.onleave Tercio@49: end Tercio@20: end Tercio@20: elseif (type == "button") then Tercio@20: for i = 1, #self.scrollframe.lines do Tercio@20: local line = self.scrollframe.lines [i] Tercio@20: local button = tremove (line.button_available) Tercio@20: if (not button) then Tercio@20: self:CreateRowButton (line) Tercio@20: button = tremove (line.button_available) Tercio@20: end Tercio@20: tinsert (line.button_inuse, button) Tercio@20: button:SetPoint ("left", line, "left", self._anchors [#self._anchors], 0) Tercio@20: if (sindex == rows_shown) then Tercio@20: button:SetWidth (row.width - 25) Tercio@20: else Tercio@20: button:SetWidth (row.width) Tercio@20: end Tercio@20: Tercio@20: if (row.icon) then Tercio@20: button._icon.texture = row.icon Tercio@20: button._icon:ClearAllPoints() Tercio@20: if (row.iconalign) then Tercio@20: if (row.iconalign == "center") then Tercio@20: button._icon:SetPoint ("center", button, "center") Tercio@20: elseif (row.iconalign == "right") then Tercio@20: button._icon:SetPoint ("right", button, "right") Tercio@20: end Tercio@20: else Tercio@20: button._icon:SetPoint ("left", button, "left") Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: if (row.name and not row.notext) then Tercio@20: button._text:SetPoint ("left", button._icon, "right", 2, 0) Tercio@20: button._text.text = row.name Tercio@49: end Tercio@49: Tercio@49: button.onenter_func = nil Tercio@49: button.onleave_func = nil Tercio@49: Tercio@49: if (row.onenter) then Tercio@49: button.onenter_func = row.onenter Tercio@49: end Tercio@49: if (row.onleave) then Tercio@49: button.onleave_func = row.onleave Tercio@49: end Tercio@20: Tercio@20: end Tercio@20: elseif (type == "icon") then Tercio@20: for i = 1, #self.scrollframe.lines do Tercio@20: local line = self.scrollframe.lines [i] Tercio@20: local icon = tremove (line.icon_available) Tercio@20: if (not icon) then Tercio@20: self:CreateRowIcon (line) Tercio@20: icon = tremove (line.icon_available) Tercio@20: end Tercio@20: tinsert (line.icon_inuse, icon) Tercio@20: icon:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0) Tercio@20: icon.func = row.func Tercio@20: end Tercio@49: Tercio@49: elseif (type == "texture") then Tercio@49: for i = 1, #self.scrollframe.lines do Tercio@49: local line = self.scrollframe.lines [i] Tercio@49: local texture = tremove (line.texture_available) Tercio@49: if (not texture) then Tercio@49: self:CreateRowTexture (line) Tercio@49: texture = tremove (line.texture_available) Tercio@49: end Tercio@49: tinsert (line.texture_inuse, texture) Tercio@49: texture:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0) Tercio@49: end Tercio@49: Tercio@20: end Tercio@20: Tercio@20: sindex = sindex + 1 Tercio@20: else Tercio@20: row:Hide() Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: if (#self.rows > 0) then Tercio@20: if (self._autowidth) then Tercio@20: self.rows [#self.rows]:SetWidth (row_width - rows_shown + 1) Tercio@20: else Tercio@20: self.rows [#self.rows]:SetWidth (self._raw_rows [rows_shown].width - rows_shown + 1) Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: self.showing_amt = rows_shown Tercio@20: end Tercio@20: Tercio@20: local update_rows = function (self, updated_rows) Tercio@49: Tercio@20: for i = 1, #updated_rows do Tercio@20: local t = updated_rows [i] Tercio@20: local raw = self._raw_rows [i] Tercio@20: Tercio@20: if (not raw) then Tercio@20: self:AddRow (t) Tercio@20: else Tercio@20: raw.name = t.name Tercio@20: raw.hidden = t.hidden or false Tercio@42: raw.textsize = t.textsize Tercio@42: raw.textalign = t.textalign Tercio@20: Tercio@20: local widget = self.rows [i] Tercio@20: widget.name = t.name Tercio@42: widget.textsize = t.textsize Tercio@42: widget.textalign = t.textalign Tercio@20: widget.hidden = t.hidden or false Tercio@20: Tercio@49: -- Tercio@49: widget.onenter = t.onenter Tercio@49: widget.onleave = t.onleave Tercio@49: -- Tercio@49: Tercio@20: widget.text:SetText (t.name) Tercio@42: DF:SetFontSize (widget.text, raw.textsize or 10) Tercio@42: widget.text:SetJustifyH (raw.textalign or "left") Tercio@42: Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: for i = #updated_rows+1, #self._raw_rows do Tercio@20: local raw = self._raw_rows [i] Tercio@20: local widget = self.rows [i] Tercio@20: raw.hidden = true Tercio@20: widget.hidden = true Tercio@20: end Tercio@20: Tercio@20: for index, row in ipairs (self.scrollframe.lines) do Tercio@20: for i = #row.text_inuse, 1, -1 do Tercio@20: tinsert (row.text_available, tremove (row.text_inuse, i)) Tercio@20: end Tercio@20: for i = 1, #row.text_available do Tercio@20: row.text_available[i]:Hide() Tercio@20: end Tercio@20: Tercio@20: for i = #row.entry_inuse, 1, -1 do Tercio@20: tinsert (row.entry_available, tremove (row.entry_inuse, i)) Tercio@20: end Tercio@20: for i = 1, #row.entry_available do Tercio@20: row.entry_available[i]:Hide() Tercio@20: end Tercio@20: Tercio@20: for i = #row.button_inuse, 1, -1 do Tercio@20: tinsert (row.button_available, tremove (row.button_inuse, i)) Tercio@20: end Tercio@20: for i = 1, #row.button_available do Tercio@20: row.button_available[i]:Hide() Tercio@20: end Tercio@20: Tercio@20: for i = #row.icon_inuse, 1, -1 do Tercio@20: tinsert (row.icon_available, tremove (row.icon_inuse, i)) Tercio@20: end Tercio@20: for i = 1, #row.icon_available do Tercio@20: row.icon_available[i]:Hide() Tercio@20: end Tercio@49: Tercio@49: for i = #row.texture_inuse, 1, -1 do Tercio@49: tinsert (row.texture_available, tremove (row.texture_inuse, i)) Tercio@49: end Tercio@49: for i = 1, #row.texture_available do Tercio@49: row.texture_available[i]:Hide() Tercio@49: end Tercio@20: end Tercio@20: Tercio@22: self.current_header = updated_rows Tercio@22: Tercio@20: self:AlignRows() Tercio@20: Tercio@20: end Tercio@20: Tercio@20: local create_panel_text = function (self, row) Tercio@20: row.text_total = row.text_total + 1 Tercio@20: local text = DF:NewLabel (row, nil, self._name .. "$parentLabel" .. row.text_total, "text" .. row.text_total) Tercio@20: tinsert (row.text_available, text) Tercio@20: end Tercio@20: Tercio@20: local create_panel_entry = function (self, row) Tercio@20: row.entry_total = row.entry_total + 1 Tercio@20: local editbox = DF:NewTextEntry (row, nil, "$parentEntry" .. row.entry_total, "entry", 120, 20) Tercio@20: editbox.align = "left" Tercio@20: Tercio@20: editbox:SetHook ("OnEnterPressed", function() Tercio@20: editbox.widget.focuslost = true Tercio@20: editbox:ClearFocus() Tercio@20: editbox.func (editbox.index, editbox.text) Tercio@20: return true Tercio@49: end) Tercio@49: Tercio@49: editbox:SetHook ("OnEnter", function() Tercio@49: if (editbox.onenter_func) then Tercio@49: pcall (editbox.onenter_func, editbox) Tercio@49: end Tercio@49: end) Tercio@49: editbox:SetHook ("OnLeave", function() Tercio@49: if (editbox.onleave_func) then Tercio@49: pcall (editbox.onleave_func, editbox) Tercio@49: end Tercio@49: end) Tercio@20: Tercio@20: editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1}) Tercio@20: editbox:SetBackdropColor (1, 1, 1, 0.1) Tercio@20: editbox:SetBackdropBorderColor (1, 1, 1, 0.1) Tercio@20: editbox.editbox.current_bordercolor = {1, 1, 1, 0.1} Tercio@20: Tercio@20: tinsert (row.entry_available, editbox) Tercio@20: end Tercio@20: Tercio@20: local create_panel_button = function (self, row) Tercio@20: row.button_total = row.button_total + 1 Tercio@20: local button = DF:NewButton (row, nil, "$parentButton" .. row.button_total, "button" .. row.button_total, 120, 20) Tercio@20: Tercio@20: --> create icon and the text Tercio@20: local icon = DF:NewImage (button, nil, 20, 20) Tercio@20: local text = DF:NewLabel (button) Tercio@20: Tercio@20: button._icon = icon Tercio@20: button._text = text Tercio@20: Tercio@20: button:SetHook ("OnEnter", button_on_enter) Tercio@20: button:SetHook ("OnLeave", button_on_leave) Tercio@20: Tercio@20: tinsert (row.button_available, button) Tercio@20: end Tercio@20: Tercio@20: local icon_onclick = function (texture, iconbutton) Tercio@20: iconbutton._icon.texture = texture Tercio@20: iconbutton.func (iconbutton.index, texture) Tercio@20: end Tercio@20: Tercio@20: local create_panel_icon = function (self, row) Tercio@20: row.icon_total = row.icon_total + 1 Tercio@20: local iconbutton = DF:NewButton (row, nil, "$parentIconButton" .. row.icon_total, "iconbutton", 22, 20) Tercio@20: iconbutton:InstallCustomTexture() Tercio@20: Tercio@20: iconbutton:SetHook ("OnEnter", button_on_enter) Tercio@20: iconbutton:SetHook ("OnLeave", button_on_leave) Tercio@20: Tercio@20: iconbutton:SetHook ("OnMouseUp", function() Tercio@20: DF:IconPick (icon_onclick, true, iconbutton) Tercio@20: return true Tercio@20: end) Tercio@20: Tercio@20: local icon = DF:NewImage (iconbutton, nil, 20, 20, "artwork", nil, "_icon", "$parentIcon" .. row.icon_total) Tercio@20: iconbutton._icon = icon Tercio@20: Tercio@20: icon:SetPoint ("center", iconbutton, "center", 0, 0) Tercio@20: Tercio@20: tinsert (row.icon_available, iconbutton) Tercio@20: end Tercio@20: Tercio@49: local create_panel_texture = function (self, row) Tercio@49: row.texture_total = row.texture_total + 1 Tercio@49: local texture = DF:NewImage (row, nil, 20, 20, "artwork", nil, "_icon" .. row.texture_total, "$parentIcon" .. row.texture_total) Tercio@49: tinsert (row.texture_available, texture) Tercio@49: end Tercio@49: Tercio@20: local set_fill_function = function (self, func) Tercio@20: self._fillfunc = func Tercio@20: end Tercio@20: local set_total_function = function (self, func) Tercio@20: self._totalfunc = func Tercio@20: end Tercio@20: local drop_header_function = function (self) Tercio@20: wipe (self.rows) Tercio@20: end Tercio@22: Tercio@22: local fillpanel_update_size = function (self, elapsed) Tercio@22: local panel = self.MyObject Tercio@22: Tercio@22: panel._width = panel:GetWidth() Tercio@22: panel._height = panel:GetHeight() Tercio@22: Tercio@22: panel:UpdateRowAmount() Tercio@22: if (panel.current_header) then Tercio@22: update_rows (panel, panel.current_header) Tercio@22: end Tercio@22: panel:Refresh() Tercio@22: Tercio@22: self:SetScript ("OnUpdate", nil) Tercio@22: end Tercio@22: Tercio@20: -- ~fillpanel Tercio@22: --alias Tercio@22: function DF:CreateFillPanel (parent, rows, w, h, total_lines, fill_row, autowidth, options, member, name) Tercio@22: return DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options) Tercio@22: end Tercio@22: Tercio@11: function DF:NewFillPanel (parent, rows, name, member, w, h, total_lines, fill_row, autowidth, options) Tercio@11: Tercio@11: local panel = DF:NewPanel (parent, parent, name, member, w, h) Tercio@11: panel.backdrop = nil Tercio@11: Tercio@11: options = options or {rowheight = 20} Tercio@11: panel.rows = {} Tercio@20: Tercio@20: panel.AddRow = add_row Tercio@20: panel.AlignRows = align_rows Tercio@20: panel.UpdateRows = update_rows Tercio@20: panel.CreateRowText = create_panel_text Tercio@20: panel.CreateRowEntry = create_panel_entry Tercio@20: panel.CreateRowButton = create_panel_button Tercio@20: panel.CreateRowIcon = create_panel_icon Tercio@49: panel.CreateRowTexture = create_panel_texture Tercio@20: panel.SetFillFunction = set_fill_function Tercio@20: panel.SetTotalFunction = set_total_function Tercio@20: panel.DropHeader = drop_header_function Tercio@20: Tercio@20: panel._name = name Tercio@20: panel._width = w Tercio@20: panel._height = h Tercio@20: panel._raw_rows = {} Tercio@20: panel._anchors = {} Tercio@20: panel._fillfunc = fill_row Tercio@20: panel._totalfunc = total_lines Tercio@20: panel._autowidth = autowidth Tercio@20: Tercio@22: panel:SetScript ("OnSizeChanged", function() Tercio@22: panel:SetScript ("OnUpdate", fillpanel_update_size) Tercio@22: end) Tercio@22: Tercio@11: for index, t in ipairs (rows) do Tercio@20: panel.AddRow (panel, t) Tercio@11: end Tercio@55: Tercio@11: local refresh_fillbox = function (self) Tercio@20: Tercio@11: local offset = FauxScrollFrame_GetOffset (self) Tercio@20: local filled_lines = panel._totalfunc (panel) Tercio@20: Tercio@11: for index = 1, #self.lines do Tercio@20: Tercio@11: local row = self.lines [index] Tercio@11: if (index <= filled_lines) then Tercio@20: Tercio@11: local real_index = index + offset Tercio@20: local results = panel._fillfunc (real_index, panel) Tercio@11: Tercio@49: if (results and results [1]) then Tercio@11: row:Show() Tercio@20: Tercio@49: local text, entry, button, icon, texture = 1, 1, 1, 1, 1 Tercio@11: Tercio@20: for index, t in ipairs (panel.rows) do Tercio@20: if (not t.hidden) then Tercio@20: if (t.type == "text") then Tercio@20: local fontstring = row.text_inuse [text] Tercio@20: text = text + 1 Tercio@20: fontstring:SetText (results [index]) Tercio@20: fontstring.index = real_index Tercio@20: fontstring:Show() Tercio@11: Tercio@20: elseif (t.type == "entry") then Tercio@20: local entrywidget = row.entry_inuse [entry] Tercio@20: entry = entry + 1 Tercio@20: entrywidget.index = real_index Tercio@49: Tercio@49: if (type (results [index]) == "table") then Tercio@49: entrywidget:SetText (results [index].text) Tercio@49: entrywidget.id = results [index].id Tercio@49: entrywidget.data1 = results [index].data1 Tercio@49: entrywidget.data2 = results [index].data2 Tercio@49: else Tercio@49: entrywidget:SetText (results [index]) Tercio@49: end Tercio@49: Tercio@49: entrywidget:SetCursorPosition(0) Tercio@49: Tercio@20: entrywidget:Show() Tercio@20: Tercio@20: elseif (t.type == "button") then Tercio@20: local buttonwidget = row.button_inuse [button] Tercio@20: button = button + 1 Tercio@20: buttonwidget.index = real_index Tercio@22: Tercio@20: if (type (results [index]) == "table") then Tercio@20: if (results [index].text) then Tercio@20: buttonwidget:SetText (results [index].text) Tercio@20: end Tercio@20: Tercio@20: if (results [index].icon) then Tercio@20: buttonwidget._icon:SetTexture (results [index].icon) Tercio@20: end Tercio@20: Tercio@20: if (results [index].func) then Tercio@22: local func = function() Tercio@22: t.func (real_index, results [index].value) Tercio@22: panel:Refresh() Tercio@22: end Tercio@22: buttonwidget:SetClickFunction (func) Tercio@22: else Tercio@22: local func = function() Tercio@22: t.func (real_index, index) Tercio@22: panel:Refresh() Tercio@22: end Tercio@22: buttonwidget:SetClickFunction (func) Tercio@20: end Tercio@49: Tercio@49: buttonwidget.id = results [index].id Tercio@49: buttonwidget.data1 = results [index].data1 Tercio@49: buttonwidget.data2 = results [index].data2 Tercio@49: Tercio@20: else Tercio@22: local func = function() Tercio@22: t.func (real_index, index) Tercio@22: panel:Refresh() Tercio@22: end Tercio@22: buttonwidget:SetClickFunction (func) Tercio@20: buttonwidget:SetText (results [index]) Tercio@11: end Tercio@11: Tercio@20: buttonwidget:Show() Tercio@11: Tercio@20: elseif (t.type == "icon") then Tercio@20: local iconwidget = row.icon_inuse [icon] Tercio@20: icon = icon + 1 Tercio@20: Tercio@20: iconwidget.line = index Tercio@20: iconwidget.index = real_index Tercio@20: Tercio@39: --print (index, results [index]) Tercio@39: if (type (results [index]) == "string") then Tercio@39: local result = results [index]:gsub (".-%\\", "") Tercio@39: iconwidget._icon.texture = results [index] Tercio@39: else Tercio@39: iconwidget._icon:SetTexture (results [index]) Tercio@39: end Tercio@20: Tercio@20: iconwidget:Show() Tercio@49: Tercio@49: elseif (t.type == "texture") then Tercio@49: local texturewidget = row.texture_inuse [texture] Tercio@49: texture = texture + 1 Tercio@49: Tercio@49: texturewidget.line = index Tercio@49: texturewidget.index = real_index Tercio@49: Tercio@49: if (type (results [index]) == "string") then Tercio@49: local result = results [index]:gsub (".-%\\", "") Tercio@49: texturewidget.texture = results [index] Tercio@49: else Tercio@49: texturewidget:SetTexture (results [index]) Tercio@49: end Tercio@49: Tercio@49: texturewidget:Show() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@20: Tercio@11: else Tercio@11: row:Hide() Tercio@11: end Tercio@11: else Tercio@11: row:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function panel:Refresh() Tercio@22: if (type (panel._totalfunc) == "boolean") then Tercio@22: --> not yet initialized Tercio@22: return Tercio@22: end Tercio@20: local filled_lines = panel._totalfunc (panel) Tercio@17: local scroll_total_lines = #panel.scrollframe.lines Tercio@11: local line_height = options.rowheight Tercio@20: refresh_fillbox (panel.scrollframe) Tercio@11: FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height) Tercio@49: panel.scrollframe:Show() Tercio@11: end Tercio@11: Tercio@11: local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate") Tercio@11: scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end) Tercio@11: scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21) Tercio@11: scrollframe:SetPoint ("topright", panel.widget, "topright", -23, -21) Tercio@11: scrollframe:SetPoint ("bottomleft", panel.widget, "bottomleft") Tercio@11: scrollframe:SetPoint ("bottomright", panel.widget, "bottomright", -23, 0) Tercio@11: scrollframe:SetSize (w, h) Tercio@11: panel.scrollframe = scrollframe Tercio@11: scrollframe.lines = {} Tercio@11: Tercio@11: --create lines Tercio@22: function panel:UpdateRowAmount() Tercio@22: local size = options.rowheight Tercio@22: local amount = math.floor (((panel._height-21) / size)) Tercio@22: Tercio@22: for i = #scrollframe.lines+1, amount do Tercio@22: local row = CreateFrame ("frame", panel:GetName() .. "Row_" .. i, panel.widget) Tercio@22: row:SetSize (1, size) Tercio@22: row.color = {1, 1, 1, .2} Tercio@22: Tercio@22: row:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]]}) Tercio@22: Tercio@22: if (i%2 == 0) then Tercio@22: row:SetBackdropColor (.5, .5, .5, 0.2) Tercio@22: else Tercio@22: row:SetBackdropColor (1, 1, 1, 0.00) Tercio@22: end Tercio@22: Tercio@22: row:SetPoint ("topleft", scrollframe, "topleft", 0, (i-1) * size * -1) Tercio@22: row:SetPoint ("topright", scrollframe, "topright", 0, (i-1) * size * -1) Tercio@22: tinsert (scrollframe.lines, row) Tercio@22: Tercio@22: row.text_available = {} Tercio@22: row.text_inuse = {} Tercio@22: row.text_total = 0 Tercio@22: Tercio@22: row.entry_available = {} Tercio@22: row.entry_inuse = {} Tercio@22: row.entry_total = 0 Tercio@22: Tercio@22: row.button_available = {} Tercio@22: row.button_inuse = {} Tercio@22: row.button_total = 0 Tercio@22: Tercio@22: row.icon_available = {} Tercio@22: row.icon_inuse = {} Tercio@22: row.icon_total = 0 Tercio@49: Tercio@49: row.texture_available = {} Tercio@49: row.texture_inuse = {} Tercio@49: row.texture_total = 0 Tercio@20: end Tercio@11: end Tercio@22: panel:UpdateRowAmount() Tercio@22: Tercio@20: panel.AlignRows (panel) Tercio@20: Tercio@11: return panel Tercio@11: end Tercio@11: Tercio@11: Tercio@11: ------------color pick Tercio@11: local color_pick_func = function() Tercio@11: local r, g, b = ColorPickerFrame:GetColorRGB() Tercio@11: local a = OpacitySliderFrame:GetValue() Tercio@11: ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe) Tercio@11: end Tercio@11: local color_pick_func_cancel = function() Tercio@11: ColorPickerFrame:SetColorRGB (unpack (ColorPickerFrame.previousValues)) Tercio@11: local r, g, b = ColorPickerFrame:GetColorRGB() Tercio@11: local a = OpacitySliderFrame:GetValue() Tercio@11: ColorPickerFrame:dcallback (r, g, b, a, ColorPickerFrame.dframe) Tercio@11: end Tercio@11: Tercio@11: function DF:ColorPick (frame, r, g, b, alpha, callback) Tercio@11: Tercio@11: ColorPickerFrame:ClearAllPoints() Tercio@11: ColorPickerFrame:SetPoint ("bottomleft", frame, "topright", 0, 0) Tercio@11: Tercio@11: ColorPickerFrame.dcallback = callback Tercio@11: ColorPickerFrame.dframe = frame Tercio@11: Tercio@11: ColorPickerFrame.func = color_pick_func Tercio@11: ColorPickerFrame.opacityFunc = color_pick_func Tercio@11: ColorPickerFrame.cancelFunc = color_pick_func_cancel Tercio@11: Tercio@11: ColorPickerFrame.opacity = alpha Tercio@11: ColorPickerFrame.hasOpacity = alpha and true Tercio@11: Tercio@11: ColorPickerFrame.previousValues = {r, g, b} Tercio@11: ColorPickerFrame:SetParent (UIParent) Tercio@11: ColorPickerFrame:SetFrameStrata ("tooltip") Tercio@11: ColorPickerFrame:SetColorRGB (r, g, b) Tercio@11: ColorPickerFrame:Show() Tercio@11: Tercio@11: end Tercio@11: Tercio@11: ------------icon pick Tercio@20: function DF:IconPick (callback, close_when_select, param1, param2) Tercio@11: Tercio@11: if (not DF.IconPickFrame) then Tercio@11: Tercio@11: local string_lower = string.lower Tercio@11: Tercio@11: DF.IconPickFrame = CreateFrame ("frame", "DetailsFrameworkIconPickFrame", UIParent) Tercio@11: tinsert (UISpecialFrames, "DetailsFrameworkIconPickFrame") Tercio@58: DF.IconPickFrame:SetFrameStrata ("TOOLTIP") Tercio@11: Tercio@11: DF.IconPickFrame:SetPoint ("center", UIParent, "center") Tercio@11: DF.IconPickFrame:SetWidth (350) Tercio@58: DF.IconPickFrame:SetHeight (277) Tercio@11: DF.IconPickFrame:EnableMouse (true) Tercio@11: DF.IconPickFrame:SetMovable (true) Tercio@11: Tercio@58: DF:CreateTitleBar (DF.IconPickFrame, "Icon Picker") Tercio@58: Tercio@53: DF.IconPickFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@53: Tercio@53: DF.IconPickFrame:SetBackdropBorderColor (0, 0, 0) Tercio@11: DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8) Tercio@58: DF.IconPickFrame:SetFrameLevel (5000) Tercio@11: Tercio@53: DF.IconPickFrame:SetScript ("OnMouseDown", function (self) Tercio@53: if (not self.isMoving) then Tercio@53: DF.IconPickFrame:StartMoving() Tercio@53: self.isMoving = true Tercio@53: end Tercio@53: end) Tercio@53: Tercio@53: DF.IconPickFrame:SetScript ("OnMouseUp", function (self) Tercio@53: if (self.isMoving) then Tercio@53: DF.IconPickFrame:StopMovingOrSizing() Tercio@53: self.isMoving = nil Tercio@53: end Tercio@53: end) Tercio@53: Tercio@11: DF.IconPickFrame.emptyFunction = function() end Tercio@11: DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction Tercio@11: Tercio@11: DF.IconPickFrame.preview = CreateFrame ("frame", nil, UIParent) Tercio@11: DF.IconPickFrame.preview:SetFrameStrata ("tooltip") Tercio@58: DF.IconPickFrame.preview:SetFrameLevel (6001) Tercio@11: DF.IconPickFrame.preview:SetSize (76, 76) Tercio@58: Tercio@58: local preview_image_bg = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76) Tercio@58: preview_image_bg:SetDrawLayer ("background", 0) Tercio@58: preview_image_bg:SetAllPoints (DF.IconPickFrame.preview) Tercio@58: preview_image_bg:SetColorTexture (0, 0, 0) Tercio@58: Tercio@11: local preview_image = DF:NewImage (DF.IconPickFrame.preview, nil, 76, 76) Tercio@11: preview_image:SetAllPoints (DF.IconPickFrame.preview) Tercio@58: Tercio@11: DF.IconPickFrame.preview.icon = preview_image Tercio@11: DF.IconPickFrame.preview:Hide() Tercio@11: Tercio@58: --serach Tercio@11: DF.IconPickFrame.searchLabel = DF:NewLabel (DF.IconPickFrame, nil, "$parentSearchBoxLabel", nil, "search:", font, size, color) Tercio@58: DF.IconPickFrame.searchLabel:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12, -36) Tercio@58: DF.IconPickFrame.searchLabel:SetTemplate (DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) Tercio@58: Tercio@11: DF.IconPickFrame.search = DF:NewTextEntry (DF.IconPickFrame, nil, "$parentSearchBox", nil, 140, 20) Tercio@11: DF.IconPickFrame.search:SetPoint ("left", DF.IconPickFrame.searchLabel, "right", 2, 0) Tercio@58: DF.IconPickFrame.search:SetTemplate (DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) Tercio@58: Tercio@11: DF.IconPickFrame.search:SetHook ("OnTextChanged", function() Tercio@11: DF.IconPickFrame.searching = DF.IconPickFrame.search:GetText() Tercio@11: if (DF.IconPickFrame.searching == "") then Tercio@11: DF.IconPickFrameScroll:Show() Tercio@11: DF.IconPickFrame.searching = nil Tercio@11: DF.IconPickFrame.updateFunc() Tercio@11: else Tercio@11: DF.IconPickFrameScroll:Hide() Tercio@11: FauxScrollFrame_SetOffset (DF.IconPickFrame, 1) Tercio@11: DF.IconPickFrame.last_filter_index = 1 Tercio@11: DF.IconPickFrame.updateFunc() Tercio@11: end Tercio@11: end) Tercio@11: Tercio@58: --manually enter the icon path Tercio@58: DF.IconPickFrame.customIcon = DF:CreateLabel (DF.IconPickFrame, "Icon Path:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) Tercio@58: DF.IconPickFrame.customIcon:SetPoint ("bottomleft", DF.IconPickFrame, "bottomleft", 12, 16) Tercio@58: Tercio@58: DF.IconPickFrame.customIconEntry = DF:CreateTextEntry (DF.IconPickFrame, function()end, 200, 20, "CustomIconEntry", _, _, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) Tercio@58: DF.IconPickFrame.customIconEntry:SetPoint ("left", DF.IconPickFrame.customIcon, "right", 2, 0) Tercio@58: Tercio@58: DF.IconPickFrame.customIconEntry:SetHook ("OnTextChanged", function() Tercio@58: DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2) Tercio@58: DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText()) Tercio@58: DF.IconPickFrame.preview:Show() Tercio@58: end) Tercio@58: Tercio@58: DF.IconPickFrame.customIconEntry:SetHook ("OnEnter", function() Tercio@58: DF.IconPickFrame.preview:SetPoint ("bottom", DF.IconPickFrame.customIconEntry.widget, "top", 0, 2) Tercio@58: DF.IconPickFrame.preview.icon:SetTexture (DF.IconPickFrame.customIconEntry:GetText()) Tercio@58: DF.IconPickFrame.preview:Show() Tercio@58: end) Tercio@58: Tercio@11: --> close button Tercio@11: local close_button = CreateFrame ("button", nil, DF.IconPickFrame, "UIPanelCloseButton") Tercio@11: close_button:SetWidth (32) Tercio@11: close_button:SetHeight (32) Tercio@11: close_button:SetPoint ("TOPRIGHT", DF.IconPickFrame, "TOPRIGHT", -8, -7) Tercio@11: close_button:SetFrameLevel (close_button:GetFrameLevel()+2) Tercio@58: close_button:SetAlpha (0) --just hide, it is used below Tercio@58: Tercio@58: --> accept custom icon button Tercio@58: local accept_custom_icon = function() Tercio@58: local path = DF.IconPickFrame.customIconEntry:GetText() Tercio@58: Tercio@58: DF:QuickDispatch (DF.IconPickFrame.callback, path, DF.IconPickFrame.param1, DF.IconPickFrame.param2) Tercio@58: Tercio@58: if (DF.IconPickFrame.click_close) then Tercio@58: close_button:Click() Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: DF.IconPickFrame.customIconAccept = DF:CreateButton (DF.IconPickFrame, accept_custom_icon, 82, 20, "Accept", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) Tercio@58: DF.IconPickFrame.customIconAccept:SetPoint ("left", DF.IconPickFrame.customIconEntry, "right", 2, 0) Tercio@58: Tercio@58: --fill with icons Tercio@11: Tercio@11: local MACRO_ICON_FILENAMES = {} Tercio@53: local SPELLNAMES_CACHE = {} Tercio@53: Tercio@11: DF.IconPickFrame:SetScript ("OnShow", function() Tercio@53: Tercio@53: MACRO_ICON_FILENAMES [1] = "INV_MISC_QUESTIONMARK"; Tercio@11: local index = 2; Tercio@11: Tercio@11: for i = 1, GetNumSpellTabs() do Tercio@53: local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo (i) Tercio@53: offset = offset + 1 Tercio@53: local tabEnd = offset + numSpells Tercio@53: Tercio@11: for j = offset, tabEnd - 1 do Tercio@11: --to get spell info by slot, you have to pass in a pet argument Tercio@53: local spellType, ID = GetSpellBookItemInfo (j, "player") Tercio@11: if (spellType ~= "FUTURESPELL") then Tercio@53: MACRO_ICON_FILENAMES [index] = GetSpellBookItemTexture (j, "player") or 0 Tercio@53: index = index + 1; Tercio@53: Tercio@53: elseif (spellType == "FLYOUT") then Tercio@53: local _, _, numSlots, isKnown = GetFlyoutInfo (ID) Tercio@11: if (isKnown and numSlots > 0) then Tercio@11: for k = 1, numSlots do Tercio@53: local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo (ID, k) Tercio@11: if (isKnown) then Tercio@53: MACRO_ICON_FILENAMES [index] = GetSpellTexture (spellID) or 0 Tercio@11: index = index + 1; Tercio@11: end Tercio@11: end Tercio@11: end Tercio@53: Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: GetLooseMacroItemIcons (MACRO_ICON_FILENAMES) Tercio@11: GetLooseMacroIcons (MACRO_ICON_FILENAMES) Tercio@11: GetMacroIcons (MACRO_ICON_FILENAMES) Tercio@53: GetMacroItemIcons (MACRO_ICON_FILENAMES) Tercio@58: Tercio@58: --reset the custom icon text entry Tercio@58: DF.IconPickFrame.customIconEntry:SetText ("") Tercio@58: --reset the search text entry Tercio@58: DF.IconPickFrame.search:SetText ("") Tercio@11: end) Tercio@11: Tercio@11: DF.IconPickFrame:SetScript ("OnHide", function() Tercio@53: wipe (MACRO_ICON_FILENAMES) Tercio@58: DF.IconPickFrame.preview:Hide() Tercio@11: collectgarbage() Tercio@11: end) Tercio@11: Tercio@11: DF.IconPickFrame.buttons = {} Tercio@11: Tercio@11: local OnClickFunction = function (self) Tercio@58: Tercio@58: DF:QuickDispatch (DF.IconPickFrame.callback, self.icon:GetTexture(), DF.IconPickFrame.param1, DF.IconPickFrame.param2) Tercio@58: Tercio@11: if (DF.IconPickFrame.click_close) then Tercio@11: close_button:Click() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local onenter = function (self) Tercio@11: DF.IconPickFrame.preview:SetPoint ("bottom", self, "top", 0, 2) Tercio@11: DF.IconPickFrame.preview.icon:SetTexture (self.icon:GetTexture()) Tercio@11: DF.IconPickFrame.preview:Show() Tercio@11: self.icon:SetBlendMode ("ADD") Tercio@11: end Tercio@11: local onleave = function (self) Tercio@11: DF.IconPickFrame.preview:Hide() Tercio@11: self.icon:SetBlendMode ("BLEND") Tercio@11: end Tercio@11: Tercio@11: local backdrop = {bgFile = DF.folder .. "background", tile = true, tileSize = 16, Tercio@11: insets = {left = 0, right = 0, top = 0, bottom = 0}, edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 10} Tercio@11: Tercio@11: for i = 0, 9 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..(i+1), DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..(i+1).."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i+1 Tercio@11: Tercio@58: newcheck:SetPoint ("topleft", DF.IconPickFrame, "topleft", 12 + (i*30), -60) Tercio@11: newcheck:SetID (i+1) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: for i = 11, 20 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i Tercio@11: Tercio@11: newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1) Tercio@11: newcheck:SetID (i) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: for i = 21, 30 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i Tercio@11: Tercio@11: newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1) Tercio@11: newcheck:SetID (i) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: for i = 31, 40 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i Tercio@11: Tercio@11: newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1) Tercio@11: newcheck:SetID (i) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: for i = 41, 50 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i Tercio@11: Tercio@11: newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1) Tercio@11: newcheck:SetID (i) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: for i = 51, 60 do Tercio@11: local newcheck = CreateFrame ("Button", "DetailsFrameworkIconPickFrameButton"..i, DF.IconPickFrame) Tercio@11: local image = newcheck:CreateTexture ("DetailsFrameworkIconPickFrameButton"..i.."Icon", "overlay") Tercio@11: newcheck.icon = image Tercio@11: image:SetPoint ("topleft", newcheck, "topleft", 2, -2); image:SetPoint ("bottomright", newcheck, "bottomright", -2, 2) Tercio@11: newcheck:SetSize (30, 28) Tercio@11: newcheck:SetBackdrop (backdrop) Tercio@11: Tercio@11: newcheck:SetScript ("OnClick", OnClickFunction) Tercio@11: newcheck.param1 = i Tercio@11: Tercio@11: newcheck:SetPoint ("topleft", "DetailsFrameworkIconPickFrameButton"..(i-10), "bottomleft", 0, -1) Tercio@11: newcheck:SetID (i) Tercio@11: DF.IconPickFrame.buttons [#DF.IconPickFrame.buttons+1] = newcheck Tercio@11: newcheck:SetScript ("OnEnter", onenter) Tercio@11: newcheck:SetScript ("OnLeave", onleave) Tercio@11: end Tercio@11: Tercio@11: local scroll = CreateFrame ("ScrollFrame", "DetailsFrameworkIconPickFrameScroll", DF.IconPickFrame, "ListScrollFrameTemplate") Tercio@58: DF:ReskinSlider (scroll) Tercio@11: Tercio@11: local ChecksFrame_Update = function (self) Tercio@11: Tercio@11: local numMacroIcons = #MACRO_ICON_FILENAMES Tercio@11: local macroPopupIcon, macroPopupButton Tercio@11: local macroPopupOffset = FauxScrollFrame_GetOffset (scroll) Tercio@11: local index Tercio@11: Tercio@11: local texture Tercio@11: local filter Tercio@11: if (DF.IconPickFrame.searching) then Tercio@11: filter = string_lower (DF.IconPickFrame.searching) Tercio@11: end Tercio@53: Tercio@53: local pool Tercio@53: local shown = 0 Tercio@11: Tercio@11: if (filter and filter ~= "") then Tercio@53: if (#SPELLNAMES_CACHE == 0) then Tercio@53: --build name cache Tercio@53: local GetSpellInfo = GetSpellInfo Tercio@53: for i = 1, #MACRO_ICON_FILENAMES do Tercio@53: local spellName = GetSpellInfo (MACRO_ICON_FILENAMES [i]) Tercio@53: SPELLNAMES_CACHE [i] = spellName or "NULL" Tercio@11: end Tercio@11: end Tercio@53: Tercio@53: --do the filter Tercio@53: pool = {} Tercio@53: for i = 1, #SPELLNAMES_CACHE do Tercio@53: if (SPELLNAMES_CACHE [i]:find (filter)) then Tercio@53: pool [#pool+1] = MACRO_ICON_FILENAMES [i] Tercio@53: shown = shown + 1 Tercio@53: end Tercio@53: end Tercio@53: else Tercio@53: shown = nil Tercio@53: end Tercio@11: Tercio@53: if (not pool) then Tercio@53: pool = MACRO_ICON_FILENAMES Tercio@53: end Tercio@53: Tercio@53: for i = 1, 60 do Tercio@53: macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"] Tercio@53: macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i] Tercio@53: index = (macroPopupOffset * 10) + i Tercio@53: texture = pool [index] Tercio@53: if ( index <= numMacroIcons and texture ) then Tercio@53: Tercio@53: if (type (texture) == "number") then Tercio@53: macroPopupIcon:SetTexture (texture) Tercio@53: else Tercio@53: macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture) Tercio@53: end Tercio@53: Tercio@53: macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64) Tercio@53: macroPopupButton.IconID = index Tercio@53: macroPopupButton:Show() Tercio@53: else Tercio@11: macroPopupButton:Hide() Tercio@11: end Tercio@53: end Tercio@11: Tercio@53: pool = nil Tercio@11: Tercio@11: -- Scrollbar stuff Tercio@53: FauxScrollFrame_Update (scroll, ceil ((shown or numMacroIcons) / 10) , 5, 20 ) Tercio@11: end Tercio@11: Tercio@11: DF.IconPickFrame.updateFunc = ChecksFrame_Update Tercio@11: Tercio@58: scroll:SetPoint ("topleft", DF.IconPickFrame, "topleft", -18, -58) Tercio@11: scroll:SetWidth (330) Tercio@11: scroll:SetHeight (178) Tercio@11: scroll:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (scroll, offset, 20, ChecksFrame_Update) end) Tercio@11: scroll.update = ChecksFrame_Update Tercio@11: DF.IconPickFrameScroll = scroll Tercio@11: DF.IconPickFrame:Hide() Tercio@11: Tercio@11: end Tercio@11: Tercio@20: DF.IconPickFrame.param1, DF.IconPickFrame.param2 = param1, param2 Tercio@20: Tercio@11: DF.IconPickFrame:Show() Tercio@11: DF.IconPickFrameScroll.update (DF.IconPickFrameScroll) Tercio@11: DF.IconPickFrame.callback = callback or DF.IconPickFrame.emptyFunction Tercio@11: DF.IconPickFrame.click_close = close_when_select Tercio@11: Tercio@11: end Tercio@11: Tercioo@29: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercioo@29: Tercioo@29: function DF:ShowPanicWarning (text) Tercioo@29: if (not DF.PanicWarningWindow) then Tercioo@29: DF.PanicWarningWindow = CreateFrame ("frame", "DetailsFrameworkPanicWarningWindow", UIParent) Tercioo@29: DF.PanicWarningWindow:SetHeight (80) Tercioo@29: DF.PanicWarningWindow:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercioo@29: DF.PanicWarningWindow:SetBackdropColor (1, 0, 0, 0.2) Tercioo@29: DF.PanicWarningWindow:SetPoint ("topleft", UIParent, "topleft", 0, -250) Tercioo@29: DF.PanicWarningWindow:SetPoint ("topright", UIParent, "topright", 0, -250) Tercioo@29: Tercioo@29: DF.PanicWarningWindow.text = DF.PanicWarningWindow:CreateFontString (nil, "overlay", "GameFontNormal") Tercioo@29: DF.PanicWarningWindow.text:SetPoint ("center", DF.PanicWarningWindow, "center") Tercioo@29: DF.PanicWarningWindow.text:SetTextColor (1, 0.6, 0) Tercioo@29: end Tercioo@29: Tercioo@29: DF.PanicWarningWindow.text:SetText (text) Tercioo@29: DF.PanicWarningWindow:Show() Tercioo@29: end Tercioo@29: Tercioo@29: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercioo@29: Tercioo@29: Tercio@11: local simple_panel_mouse_down = function (self, button) Tercio@11: if (button == "RightButton") then Tercio@11: if (self.IsMoving) then Tercio@11: self.IsMoving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: if (self.db and self.db.position) then Tercio@11: DF:SavePositionOnScreen (self) Tercio@11: end Tercio@11: end Tercio@17: if (not self.DontRightClickClose) then Tercio@17: self:Hide() Tercio@17: end Tercio@11: return Tercio@11: end Tercio@11: if (not self.IsMoving and not self.IsLocked) then Tercio@11: self.IsMoving = true Tercio@11: self:StartMoving() Tercio@11: end Tercio@11: end Tercio@11: local simple_panel_mouse_up = function (self, button) Tercio@11: if (self.IsMoving) then Tercio@11: self.IsMoving = false Tercio@11: self:StopMovingOrSizing() Tercio@11: if (self.db and self.db.position) then Tercio@11: DF:SavePositionOnScreen (self) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: local simple_panel_settitle = function (self, title) Tercio@22: self.Title:SetText (title) Tercio@11: end Tercio@11: Tercio@22: local simple_panel_close_click = function (self) Tercio@22: self:GetParent():GetParent():Hide() Tercio@22: end Tercio@22: Tercio@22: local SimplePanel_frame_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true} Tercio@22: local SimplePanel_frame_backdrop_color = {0, 0, 0, 0.9} Tercio@22: local SimplePanel_frame_backdrop_border_color = {0, 0, 0, 1} Tercio@22: Tercio@58: --with_label was making the frame stay in place while its parent moves Tercio@58: --the slider was anchoring to with_label and here here were anchoring the slider again Tercio@39: function DF:CreateScaleBar (frame, config) Tercio@58: local scaleBar, text = DF:CreateSlider (frame, 120, 14, 0.6, 1.6, 0.1, config.scale, true, "ScaleBar", nil, "Scale:", DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE"), DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) Tercio@58: --scaleBar:SetPoint ("right", frame.Close, "left", -26, 0) Tercio@58: text:SetPoint ("topleft", frame, "topleft", 12, -7) Tercio@39: scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) Tercio@39: scaleBar.OnValueChanged = function (_, _, value) Tercio@39: config.scale = value Tercio@39: if (not scaleBar.IsValueChanging) then Tercio@39: frame:SetScale (config.scale) Tercio@39: end Tercio@39: end Tercio@39: scaleBar:SetHook ("OnMouseUp", function() Tercio@39: frame:SetScale (config.scale) Tercio@39: end) Tercio@58: Tercio@58: scaleBar:SetAlpha (0.2) Tercio@58: Tercio@58: return scaleBar Tercio@39: end Tercio@39: Tercio@26: local no_options = {} Tercio@39: function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db) Tercio@49: Tercio@39: if (db and name and not db [name]) then Tercio@39: db [name] = {scale = 1} Tercio@39: end Tercio@11: Tercio@11: if (not name) then Tercioo@29: name = "DetailsFrameworkSimplePanel" .. DF.SimplePanelCounter Tercioo@29: DF.SimplePanelCounter = DF.SimplePanelCounter + 1 Tercio@11: end Tercio@11: if (not parent) then Tercio@11: parent = UIParent Tercio@11: end Tercio@26: Tercio@26: panel_options = panel_options or no_options Tercio@49: Tercio@11: local f = CreateFrame ("frame", name, UIParent) Tercio@11: f:SetSize (w or 400, h or 250) Tercio@11: f:SetPoint ("center", UIParent, "center", 0, 0) Tercio@11: f:SetFrameStrata ("FULLSCREEN") Tercio@11: f:EnableMouse() Tercio@11: f:SetMovable (true) Tercio@22: f:SetBackdrop (SimplePanel_frame_backdrop) Tercio@22: f:SetBackdropColor (unpack (SimplePanel_frame_backdrop_color)) Tercio@22: f:SetBackdropBorderColor (unpack (SimplePanel_frame_backdrop_border_color)) Tercio@26: Tercio@26: f.DontRightClickClose = panel_options.DontRightClickClose Tercio@26: Tercio@26: if (not panel_options.NoTUISpecialFrame) then Tercio@26: tinsert (UISpecialFrames, name) Tercio@26: end Tercio@22: Tercio@22: local title_bar = CreateFrame ("frame", name .. "TitleBar", f) Tercio@22: title_bar:SetPoint ("topleft", f, "topleft", 2, -3) Tercio@22: title_bar:SetPoint ("topright", f, "topright", -2, -3) Tercio@22: title_bar:SetHeight (20) Tercio@22: title_bar:SetBackdrop (SimplePanel_frame_backdrop) Tercio@22: title_bar:SetBackdropColor (.2, .2, .2, 1) Tercio@22: title_bar:SetBackdropBorderColor (0, 0, 0, 1) Tercio@26: f.TitleBar = title_bar Tercio@22: Tercio@22: local close = CreateFrame ("button", name and name .. "CloseButton", title_bar) Tercio@39: close:SetFrameLevel (DF.FRAMELEVEL_OVERLAY) Tercio@22: close:SetSize (16, 16) Tercio@22: close:SetNormalTexture (DF.folder .. "icons") Tercio@22: close:SetHighlightTexture (DF.folder .. "icons") Tercio@22: close:SetPushedTexture (DF.folder .. "icons") Tercio@22: close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@22: close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@22: close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@22: close:SetAlpha (0.7) Tercio@22: close:SetScript ("OnClick", simple_panel_close_click) Tercio@22: f.Close = close Tercio@22: Tercio@22: local title_string = title_bar:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal") Tercio@22: title_string:SetTextColor (.8, .8, .8, 1) Tercio@22: title_string:SetText (title or "") Tercio@22: f.Title = title_string Tercio@22: Tercio@39: if (panel_options.UseScaleBar and db [name]) then Tercio@39: DF:CreateScaleBar (f, db [name]) Tercio@39: f:SetScale (db [name].scale) Tercio@39: end Tercio@39: Tercio@22: f.Title:SetPoint ("center", title_bar, "center") Tercio@22: f.Close:SetPoint ("right", title_bar, "right", -2, 0) Tercio@22: Tercio@11: f:SetScript ("OnMouseDown", simple_panel_mouse_down) Tercio@11: f:SetScript ("OnMouseUp", simple_panel_mouse_up) Tercio@11: Tercio@11: f.SetTitle = simple_panel_settitle Tercio@11: Tercio@11: return f Tercio@11: end Tercio@11: Tercio@11: local Panel1PxBackdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 64, Tercio@11: edgeFile = DF.folder .. "border_3", edgeSize = 9, insets = {left = 2, right = 2, top = 3, bottom = 3}} Tercio@11: Tercio@11: local Panel1PxOnClickClose = function (self) Tercio@11: self:GetParent():Hide() Tercio@11: end Tercio@11: local Panel1PxOnToggleLock = function (self) Tercio@11: if (self.IsLocked) then Tercio@11: self.IsLocked = false Tercio@11: self:SetMovable (true) Tercio@11: self:EnableMouse (true) Tercio@11: self.Lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@11: self.Lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@11: self.Lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@17: if (self.OnUnlock) then Tercio@17: self:OnUnlock() Tercio@17: end Tercio@17: if (self.db) then Tercio@17: self.db.IsLocked = self.IsLocked Tercio@17: end Tercio@11: else Tercio@11: self.IsLocked = true Tercio@11: self:SetMovable (false) Tercio@11: self:EnableMouse (false) Tercio@11: self.Lock:GetNormalTexture():SetTexCoord (16/128, 32/128, 0, 1) Tercio@11: self.Lock:GetHighlightTexture():SetTexCoord (16/128, 32/128, 0, 1) Tercio@11: self.Lock:GetPushedTexture():SetTexCoord (16/128, 32/128, 0, 1) Tercio@17: if (self.OnLock) then Tercio@17: self:OnLock() Tercio@17: end Tercio@17: if (self.db) then Tercio@17: self.db.IsLocked = self.IsLocked Tercio@17: end Tercio@11: end Tercio@11: end Tercio@11: local Panel1PxOnClickLock = function (self) Tercio@11: local f = self:GetParent() Tercio@11: Panel1PxOnToggleLock (f) Tercio@11: end Tercio@11: local Panel1PxSetTitle = function (self, text) Tercio@11: self.Title:SetText (text or "") Tercio@11: end Tercio@11: Tercio@20: local Panel1PxSetLocked= function (self, lock_state) Tercio@20: if (type (lock_state) ~= "boolean") then Tercio@20: return Tercio@20: end Tercio@20: if (lock_state) then Tercio@20: -- lock it Tercio@20: self.IsLocked = false Tercio@20: Panel1PxOnClickLock (self.Lock) Tercio@20: else Tercio@20: -- unlockit Tercio@20: self.IsLocked = true Tercio@20: Panel1PxOnClickLock (self.Lock) Tercio@20: end Tercio@20: end Tercio@20: Tercio@11: local Panel1PxReadConfig = function (self) Tercio@11: local db = self.db Tercio@11: if (db) then Tercio@11: db.IsLocked = db.IsLocked or false Tercio@11: self.IsLocked = db.IsLocked Tercio@11: db.position = db.position or {x = 0, y = 0} Tercio@19: db.position.x = db.position.x or 0 Tercio@19: db.position.y = db.position.y or 0 Tercio@11: DF:RestoreFramePosition (self) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DF:SavePositionOnScreen (frame) Tercio@11: if (frame.db and frame.db.position) then Tercio@11: local x, y = DF:GetPositionOnScreen (frame) Tercio@18: --print ("saving...", x, y, frame:GetName()) Tercio@19: if (x and y) then Tercio@19: frame.db.position.x, frame.db.position.y = x, y Tercio@19: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DF:GetPositionOnScreen (frame) Tercio@11: local xOfs, yOfs = frame:GetCenter() Tercio@11: if (not xOfs) then Tercio@11: return Tercio@11: end Tercio@11: local scale = frame:GetEffectiveScale() Tercio@11: local UIscale = UIParent:GetScale() Tercio@11: xOfs = xOfs*scale - GetScreenWidth()*UIscale/2 Tercio@11: yOfs = yOfs*scale - GetScreenHeight()*UIscale/2 Tercio@11: return xOfs/UIscale, yOfs/UIscale Tercio@11: end Tercio@11: Tercio@11: function DF:RestoreFramePosition (frame) Tercio@11: if (frame.db and frame.db.position) then Tercio@11: local scale, UIscale = frame:GetEffectiveScale(), UIParent:GetScale() Tercio@11: frame:ClearAllPoints() Tercio@19: frame.db.position.x = frame.db.position.x or 0 Tercio@19: frame.db.position.y = frame.db.position.y or 0 Tercio@11: frame:SetPoint ("center", UIParent, "center", frame.db.position.x * UIscale / scale, frame.db.position.y * UIscale / scale) Tercio@11: end Tercio@11: end Tercio@11: Tercio@20: local Panel1PxSavePosition= function (self) Tercio@20: DF:SavePositionOnScreen (self) Tercio@20: end Tercio@20: Tercio@18: local Panel1PxHasPosition = function (self) Tercio@18: local db = self.db Tercio@18: if (db) then Tercio@18: if (db.position and db.position.x and (db.position.x ~= 0 or db.position.y ~= 0)) then Tercio@18: return true Tercio@18: end Tercio@18: end Tercio@18: end Tercio@18: Tercio@13: function DF:Create1PxPanel (parent, w, h, title, name, config, title_anchor, no_special_frame) Tercio@11: local f = CreateFrame ("frame", name, parent or UIParent) Tercio@11: f:SetSize (w or 100, h or 75) Tercio@11: f:SetPoint ("center", UIParent, "center") Tercio@11: Tercio@13: if (name and not no_special_frame) then Tercio@11: tinsert (UISpecialFrames, name) Tercio@11: end Tercio@11: Tercio@11: f:SetScript ("OnMouseDown", simple_panel_mouse_down) Tercio@11: f:SetScript ("OnMouseUp", simple_panel_mouse_up) Tercio@11: Tercio@11: f:SetBackdrop (Panel1PxBackdrop) Tercio@11: f:SetBackdropColor (0, 0, 0, 0.5) Tercio@11: Tercio@17: f.IsLocked = (config and config.IsLocked ~= nil and config.IsLocked) or false Tercio@11: f:SetMovable (true) Tercio@11: f:EnableMouse (true) Tercio@11: f:SetUserPlaced (true) Tercio@11: Tercio@11: f.db = config Tercio@18: --print (config.position.x, config.position.x) Tercio@11: Panel1PxReadConfig (f) Tercio@11: Tercio@11: local close = CreateFrame ("button", name and name .. "CloseButton", f) Tercio@11: close:SetSize (16, 16) Tercio@11: close:SetNormalTexture (DF.folder .. "icons") Tercio@11: close:SetHighlightTexture (DF.folder .. "icons") Tercio@11: close:SetPushedTexture (DF.folder .. "icons") Tercio@11: close:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@11: close:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@11: close:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@11: close:SetAlpha (0.7) Tercio@11: Tercio@11: local lock = CreateFrame ("button", name and name .. "LockButton", f) Tercio@11: lock:SetSize (16, 16) Tercio@11: lock:SetNormalTexture (DF.folder .. "icons") Tercio@11: lock:SetHighlightTexture (DF.folder .. "icons") Tercio@11: lock:SetPushedTexture (DF.folder .. "icons") Tercio@11: lock:GetNormalTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@11: lock:GetHighlightTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@11: lock:GetPushedTexture():SetTexCoord (32/128, 48/128, 0, 1) Tercio@11: lock:SetAlpha (0.7) Tercio@11: Tercio@11: close:SetPoint ("topright", f, "topright", -3, -3) Tercio@11: lock:SetPoint ("right", close, "left", 3, 0) Tercio@11: Tercio@11: close:SetScript ("OnClick", Panel1PxOnClickClose) Tercio@11: lock:SetScript ("OnClick", Panel1PxOnClickLock) Tercio@11: Tercio@11: local title_string = f:CreateFontString (name and name .. "Title", "overlay", "GameFontNormal") Tercio@11: title_string:SetPoint ("topleft", f, "topleft", 5, -5) Tercio@11: title_string:SetText (title or "") Tercio@11: Tercio@11: if (title_anchor) then Tercio@11: if (title_anchor == "top") then Tercio@11: title_string:ClearAllPoints() Tercio@11: title_string:SetPoint ("bottomleft", f, "topleft", 0, 0) Tercio@11: close:ClearAllPoints() Tercio@11: close:SetPoint ("bottomright", f, "topright", 0, 0) Tercio@11: end Tercio@11: f.title_anchor = title_anchor Tercio@11: end Tercio@11: Tercio@11: f.SetTitle = Panel1PxSetTitle Tercio@11: f.Title = title_string Tercio@11: f.Lock = lock Tercio@11: f.Close = close Tercio@18: f.HasPosition = Panel1PxHasPosition Tercio@20: f.SavePosition = Panel1PxSavePosition Tercio@11: Tercio@17: f.IsLocked = not f.IsLocked Tercio@20: f.SetLocked = Panel1PxSetLocked Tercio@17: Panel1PxOnToggleLock (f) Tercio@17: Tercio@11: return f Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@20: -- ~prompt Tercio@20: function DF:ShowPromptPanel (message, func_true, func_false) Tercio@20: Tercio@20: if (not DF.prompt_panel) then Tercio@20: local f = CreateFrame ("frame", "DetailsFrameworkPrompt", UIParent) Tercio@22: f:SetSize (400, 65) Tercio@20: f:SetFrameStrata ("DIALOG") Tercio@22: f:SetPoint ("center", UIParent, "center", 0, 300) Tercio@20: f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@20: f:SetBackdropColor (0, 0, 0, 0.8) Tercio@20: f:SetBackdropBorderColor (0, 0, 0, 1) Tercio@20: Tercio@22: local prompt = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@22: prompt:SetPoint ("top", f, "top", 0, -15) Tercio@22: prompt:SetJustifyH ("center") Tercio@22: f.prompt = prompt Tercio@22: Tercio@22: local button_true = DF:CreateButton (f, nil, 60, 20, "Yes") Tercio@20: button_true:SetPoint ("bottomleft", f, "bottomleft", 5, 5) Tercio@20: f.button_true = button_true Tercio@20: Tercio@22: local button_false = DF:CreateButton (f, nil, 60, 20, "No") Tercio@20: button_false:SetPoint ("bottomright", f, "bottomright", -5, 5) Tercio@20: f.button_false = button_false Tercio@20: Tercio@20: button_true:SetClickFunction (function() Tercio@20: local my_func = button_true.true_function Tercio@20: if (my_func) then Tercio@20: local okey, errormessage = pcall (my_func, true) Tercio@20: if (not okey) then Tercio@20: print ("error:", errormessage) Tercio@20: end Tercio@22: f:Hide() Tercio@20: end Tercio@20: end) Tercio@20: Tercio@20: button_false:SetClickFunction (function() Tercio@20: local my_func = button_false.false_function Tercio@20: if (my_func) then Tercio@20: local okey, errormessage = pcall (my_func, true) Tercio@20: if (not okey) then Tercio@20: print ("error:", errormessage) Tercio@20: end Tercio@22: f:Hide() Tercio@20: end Tercio@20: end) Tercio@20: Tercio@20: f:Hide() Tercio@20: DF.promtp_panel = f Tercio@20: end Tercio@20: Tercio@20: assert (type (func_true) == "function" and type (func_false) == "function", "ShowPromptPanel expects two functions.") Tercio@20: Tercio@22: DF.promtp_panel.prompt:SetText (message) Tercio@20: DF.promtp_panel.button_true.true_function = func_true Tercio@20: DF.promtp_panel.button_false.false_function = func_false Tercio@20: Tercio@20: DF.promtp_panel:Show() Tercio@20: end Tercio@22: Tercio@22: Tercio@22: function DF:ShowTextPromptPanel (message, callback) Tercio@22: Tercio@22: if (not DF.text_prompt_panel) then Tercio@22: Tercio@22: local f = CreateFrame ("frame", "DetailsFrameworkPrompt", UIParent) Tercio@22: f:SetSize (400, 100) Tercio@22: f:SetFrameStrata ("DIALOG") Tercio@22: f:SetPoint ("center", UIParent, "center", 0, 300) Tercio@22: f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@22: f:SetBackdropColor (0, 0, 0, 0.8) Tercio@22: f:SetBackdropBorderColor (0, 0, 0, 1) Tercio@22: Tercio@22: local prompt = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@22: prompt:SetPoint ("top", f, "top", 0, -15) Tercio@22: prompt:SetJustifyH ("center") Tercio@22: f.prompt = prompt Tercioo@29: Tercioo@29: local button_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE") Tercioo@29: local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") Tercioo@29: Tercioo@29: local button_true = DF:CreateButton (f, nil, 60, 20, "Okey", nil, nil, nil, nil, nil, nil, options_dropdown_template, button_text_template) Tercio@22: button_true:SetPoint ("bottomleft", f, "bottomleft", 10, 5) Tercio@22: f.button_true = button_true Tercio@22: Tercioo@29: local button_false = DF:CreateButton (f, function() f.textbox:ClearFocus(); f:Hide() end, 60, 20, "Cancel", nil, nil, nil, nil, nil, nil, options_dropdown_template, button_text_template) Tercio@22: button_false:SetPoint ("bottomright", f, "bottomright", -10, 5) Tercio@22: f.button_false = button_false Tercio@22: Tercioo@29: local textbox = DF:CreateTextEntry (f, function()end, 380, 20, "textbox", nil, nil, options_dropdown_template) Tercio@22: textbox:SetPoint ("topleft", f, "topleft", 10, -45) Tercioo@29: f.EntryBox = textbox Tercio@22: Tercio@22: button_true:SetClickFunction (function() Tercio@22: local my_func = button_true.true_function Tercio@22: if (my_func) then Tercio@22: local okey, errormessage = pcall (my_func, textbox:GetText()) Tercio@22: textbox:ClearFocus() Tercio@22: if (not okey) then Tercio@22: print ("error:", errormessage) Tercio@22: end Tercio@22: f:Hide() Tercio@22: end Tercio@22: end) Tercio@22: Tercio@22: f:Hide() Tercio@22: DF.text_prompt_panel = f Tercio@22: end Tercio@22: Tercio@22: DF.text_prompt_panel:Show() Tercio@22: Tercioo@29: DetailsFrameworkPrompt.EntryBox:SetText ("") Tercio@22: DF.text_prompt_panel.prompt:SetText (message) Tercio@22: DF.text_prompt_panel.button_true.true_function = callback Tercioo@29: Tercio@22: DF.text_prompt_panel.textbox:SetFocus (true) Tercio@22: Tercio@22: end Tercio@22: Tercio@20: ------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@11: --> options button -- ~options Tercio@11: function DF:CreateOptionsButton (parent, callback, name) Tercio@11: Tercio@11: local b = CreateFrame ("button", name, parent) Tercio@11: b:SetSize (14, 14) Tercio@11: b:SetNormalTexture (DF.folder .. "icons") Tercio@11: b:SetHighlightTexture (DF.folder .. "icons") Tercio@11: b:SetPushedTexture (DF.folder .. "icons") Tercio@11: b:GetNormalTexture():SetTexCoord (48/128, 64/128, 0, 1) Tercio@11: b:GetHighlightTexture():SetTexCoord (48/128, 64/128, 0, 1) Tercio@11: b:GetPushedTexture():SetTexCoord (48/128, 64/128, 0, 1) Tercio@11: b:SetAlpha (0.7) Tercio@11: Tercio@11: b:SetScript ("OnClick", callback) Tercio@11: b:SetScript ("OnEnter", function (self) Tercio@11: GameCooltip2:Reset() Tercio@11: GameCooltip2:AddLine ("Options") Tercio@11: GameCooltip2:ShowCooltip (self, "tooltip") Tercio@11: end) Tercio@11: b:SetScript ("OnLeave", function (self) Tercio@11: GameCooltip2:Hide() Tercio@11: end) Tercio@11: Tercio@11: return b Tercio@11: Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@11: --> feedback panel -- ~feedback Tercio@11: Tercio@11: function DF:CreateFeedbackButton (parent, callback, name) Tercio@11: local b = CreateFrame ("button", name, parent) Tercio@11: b:SetSize (12, 13) Tercio@11: b:SetNormalTexture (DF.folder .. "mail") Tercio@11: b:SetPushedTexture (DF.folder .. "mail") Tercio@11: b:SetHighlightTexture (DF.folder .. "mail") Tercio@11: Tercio@11: b:SetScript ("OnClick", callback) Tercio@11: b:SetScript ("OnEnter", function (self) Tercio@11: GameCooltip2:Reset() Tercio@11: GameCooltip2:AddLine ("Send Feedback") Tercio@11: GameCooltip2:ShowCooltip (self, "tooltip") Tercio@11: end) Tercio@11: b:SetScript ("OnLeave", function (self) Tercio@11: GameCooltip2:Hide() Tercio@11: end) Tercio@11: Tercio@11: return b Tercio@11: end Tercio@11: Tercio@11: local backdrop_fb_line = {bgFile = DF.folder .. "background", edgeFile = DF.folder .. "border_3", Tercio@11: tile = true, tileSize = 64, edgeSize = 8, insets = {left = 2, right = 2, top = 2, bottom = 2}} Tercio@11: Tercio@11: local on_enter_feedback = function (self) Tercio@11: self:SetBackdropColor (1, 1, 0, 0.5) Tercio@11: end Tercio@11: local on_leave_feedback = function (self) Tercio@11: self:SetBackdropColor (0, 0, 0, 0.3) Tercio@11: end Tercio@11: Tercio@11: local on_click_feedback = function (self) Tercio@11: Tercio@11: local feedback_link_textbox = DF.feedback_link_textbox Tercio@11: Tercio@11: if (not feedback_link_textbox) then Tercio@11: local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34) Tercio@11: editbox:SetAutoFocus (false) Tercio@11: editbox:SetHook ("OnEditFocusGained", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox:SetHook ("OnEditFocusLost", function() Tercio@11: editbox:Hide() Tercio@11: end) Tercio@11: editbox:SetHook ("OnChar", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox.text = "" Tercio@11: Tercio@11: DF.feedback_link_textbox = editbox Tercio@11: feedback_link_textbox = editbox Tercio@11: end Tercio@11: Tercio@11: feedback_link_textbox.link = self.link Tercio@11: feedback_link_textbox.text = self.link Tercio@11: feedback_link_textbox:Show() Tercio@11: Tercio@11: feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0) Tercio@11: Tercio@11: feedback_link_textbox:HighlightText() Tercio@11: Tercio@11: feedback_link_textbox:SetFocus() Tercio@11: feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2) Tercio@11: end Tercio@11: Tercio@11: local feedback_get_fb_line = function (self) Tercio@11: Tercio@11: local line = self.feedback_lines [self.next_feedback] Tercio@11: if (not line) then Tercio@11: line = CreateFrame ("frame", "AddonFeedbackPanelFB" .. self.next_feedback, self) Tercio@11: line:SetBackdrop (backdrop_fb_line) Tercio@11: line:SetBackdropColor (0, 0, 0, 0.3) Tercio@11: line:SetSize (390, 42) Tercio@11: line:SetPoint ("topleft", self.feedback_anchor, "bottomleft", 0, -5 + ((self.next_feedback-1) * 46 * -1)) Tercio@11: line:SetScript ("OnEnter", on_enter_feedback) Tercio@11: line:SetScript ("OnLeave", on_leave_feedback) Tercio@11: line:SetScript ("OnMouseUp", on_click_feedback) Tercio@11: Tercio@11: line.icon = line:CreateTexture (nil, "overlay") Tercio@11: line.icon:SetSize (90, 36) Tercio@11: Tercio@11: line.desc = line:CreateFontString (nil, "overlay", "GameFontHighlightSmall") Tercio@11: Tercio@11: line.icon:SetPoint ("left", line, "left", 5, 0) Tercio@11: line.desc:SetPoint ("left", line.icon, "right", 5, 0) Tercio@11: Tercio@11: local arrow = line:CreateTexture (nil, "overlay") Tercio@11: arrow:SetTexture ([[Interface\Buttons\JumpUpArrow]]) Tercio@11: arrow:SetRotation (-1.55) Tercio@11: arrow:SetPoint ("right", line, "right", -5, 0) Tercio@11: Tercio@11: self.feedback_lines [self.next_feedback] = line Tercio@11: end Tercio@11: Tercio@11: self.next_feedback = self.next_feedback + 1 Tercio@11: Tercio@11: return line Tercio@11: end Tercio@11: Tercio@11: local on_click_feedback = function (self) Tercio@11: Tercio@11: local feedback_link_textbox = DF.feedback_link_textbox Tercio@11: Tercio@11: if (not feedback_link_textbox) then Tercio@11: local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 275, 34) Tercio@11: editbox:SetAutoFocus (false) Tercio@11: editbox:SetHook ("OnEditFocusGained", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox:SetHook ("OnEditFocusLost", function() Tercio@11: editbox:Hide() Tercio@11: end) Tercio@11: editbox:SetHook ("OnChar", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox.text = "" Tercio@11: Tercio@11: DF.feedback_link_textbox = editbox Tercio@11: feedback_link_textbox = editbox Tercio@11: end Tercio@11: Tercio@11: feedback_link_textbox.link = self.link Tercio@11: feedback_link_textbox.text = self.link Tercio@11: feedback_link_textbox:Show() Tercio@11: Tercio@11: feedback_link_textbox:SetPoint ("topleft", self.icon, "topright", 3, 0) Tercio@11: Tercio@11: feedback_link_textbox:HighlightText() Tercio@11: Tercio@11: feedback_link_textbox:SetFocus() Tercio@11: feedback_link_textbox:SetFrameLevel (self:GetFrameLevel()+2) Tercio@11: end Tercio@11: Tercio@11: local on_enter_addon = function (self) Tercio@11: if (self.tooltip) then Tercio@11: GameCooltip2:Preset (2) Tercio@11: GameCooltip2:AddLine ("|cFFFFFF00" .. self.name .. "|r") Tercio@11: GameCooltip2:AddLine ("") Tercio@11: GameCooltip2:AddLine (self.tooltip) Tercio@11: GameCooltip2:ShowCooltip (self, "tooltip") Tercio@11: end Tercio@11: self.icon:SetBlendMode ("ADD") Tercio@11: end Tercio@11: local on_leave_addon = function (self) Tercio@11: if (self.tooltip) then Tercio@11: GameCooltip2:Hide() Tercio@11: end Tercio@11: self.icon:SetBlendMode ("BLEND") Tercio@11: end Tercio@11: local on_click_addon = function (self) Tercio@11: local addon_link_textbox = DF.addon_link_textbox Tercio@11: Tercio@11: if (not addon_link_textbox) then Tercio@11: local editbox = DF:CreateTextEntry (AddonFeedbackPanel, _, 128, 64) Tercio@11: editbox:SetAutoFocus (false) Tercio@11: editbox:SetHook ("OnEditFocusGained", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox:SetHook ("OnEditFocusLost", function() Tercio@11: editbox:Hide() Tercio@11: end) Tercio@11: editbox:SetHook ("OnChar", function() Tercio@11: editbox.text = editbox.link Tercio@11: editbox:HighlightText() Tercio@11: end) Tercio@11: editbox.text = "" Tercio@11: Tercio@11: DF.addon_link_textbox = editbox Tercio@11: addon_link_textbox = editbox Tercio@11: end Tercio@11: Tercio@11: addon_link_textbox.link = self.link Tercio@11: addon_link_textbox.text = self.link Tercio@11: addon_link_textbox:Show() Tercio@11: Tercio@11: addon_link_textbox:SetPoint ("topleft", self.icon, "topleft", 0, 0) Tercio@11: Tercio@11: addon_link_textbox:HighlightText() Tercio@11: Tercio@11: addon_link_textbox:SetFocus() Tercio@11: addon_link_textbox:SetFrameLevel (self:GetFrameLevel()+2) Tercio@11: end Tercio@11: Tercio@11: local feedback_get_addons_line = function (self) Tercio@11: local line = self.addons_lines [self.next_addons] Tercio@11: if (not line) then Tercio@11: Tercio@11: line = CreateFrame ("frame", "AddonFeedbackPanelSA" .. self.next_addons, self) Tercio@11: line:SetSize (128, 64) Tercio@11: Tercio@11: if (self.next_addons == 1) then Tercio@11: line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5) Tercio@11: elseif (self.next_addons_line_break == self.next_addons) then Tercio@11: line:SetPoint ("topleft", self.addons_anchor, "bottomleft", 0, -5 + floor (self.next_addons_line_break/3) * 66 * -1) Tercio@11: self.next_addons_line_break = self.next_addons_line_break + 3 Tercio@11: else Tercio@11: local previous = self.addons_lines [self.next_addons - 1] Tercio@11: line:SetPoint ("topleft", previous, "topright", 2, 0) Tercio@11: end Tercio@11: Tercio@11: line:SetScript ("OnEnter", on_enter_addon) Tercio@11: line:SetScript ("OnLeave", on_leave_addon) Tercio@11: line:SetScript ("OnMouseUp", on_click_addon) Tercio@11: Tercio@11: line.icon = line:CreateTexture (nil, "overlay") Tercio@11: line.icon:SetSize (128, 64) Tercio@11: Tercio@11: line.icon:SetPoint ("topleft", line, "topleft", 0, 0) Tercio@11: Tercio@11: self.addons_lines [self.next_addons] = line Tercio@11: end Tercio@11: Tercio@11: self.next_addons = self.next_addons + 1 Tercio@11: Tercio@11: return line Tercio@11: end Tercio@11: Tercio@11: local default_coords = {0, 1, 0, 1} Tercio@11: local feedback_add_fb = function (self, table) Tercio@11: local line = self:GetFeedbackLine() Tercio@11: line.icon:SetTexture (table.icon) Tercio@11: line.icon:SetTexCoord (unpack (table.coords or default_coords)) Tercio@11: line.desc:SetText (table.desc) Tercio@11: line.link = table.link Tercio@11: line:Show() Tercio@11: end Tercio@11: Tercio@11: local feedback_add_addon = function (self, table) Tercio@11: local block = self:GetAddonsLine() Tercio@11: block.icon:SetTexture (table.icon) Tercio@11: block.icon:SetTexCoord (unpack (table.coords or default_coords)) Tercio@11: block.link = table.link Tercio@11: block.tooltip = table.desc Tercio@11: block.name = table.name Tercio@11: block:Show() Tercio@11: end Tercio@11: Tercio@11: local feedback_hide_all = function (self) Tercio@11: self.next_feedback = 1 Tercio@11: self.next_addons = 1 Tercio@11: Tercio@11: for index, line in ipairs (self.feedback_lines) do Tercio@11: line:Hide() Tercio@11: end Tercio@11: Tercio@11: for index, line in ipairs (self.addons_lines) do Tercio@11: line:Hide() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- feedback_methods = { { icon = icon path, desc = description, link = url}} Tercio@11: function DF:ShowFeedbackPanel (addon_name, version, feedback_methods, more_addons) Tercio@11: Tercio@11: local f = _G.AddonFeedbackPanel Tercio@11: Tercio@11: if (not f) then Tercio@11: f = DF:Create1PxPanel (UIParent, 400, 100, addon_name .. " Feedback", "AddonFeedbackPanel", nil) Tercio@11: f:SetFrameStrata ("FULLSCREEN") Tercio@11: f:SetPoint ("center", UIParent, "center") Tercio@11: f:SetBackdropColor (0, 0, 0, 0.8) Tercio@11: f.feedback_lines = {} Tercio@11: f.addons_lines = {} Tercio@11: f.next_feedback = 1 Tercio@11: f.next_addons = 1 Tercio@11: f.next_addons_line_break = 4 Tercio@11: Tercio@11: local feedback_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@11: feedback_anchor:SetText ("Feedback:") Tercio@11: feedback_anchor:SetPoint ("topleft", f, "topleft", 5, -30) Tercio@11: f.feedback_anchor = feedback_anchor Tercio@11: local excla_text = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@11: excla_text:SetText ("click and copy the link") Tercio@11: excla_text:SetPoint ("topright", f, "topright", -5, -30) Tercio@11: excla_text:SetTextColor (1, 0.8, 0.2, 0.6) Tercio@11: Tercio@11: local addons_anchor = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@11: addons_anchor:SetText ("AddOns From the Same Author:") Tercio@11: f.addons_anchor = addons_anchor Tercio@11: local excla_text2 = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@11: excla_text2:SetText ("click and copy the link") Tercio@11: excla_text2:SetTextColor (1, 0.8, 0.2, 0.6) Tercio@11: f.excla_text2 = excla_text2 Tercio@11: Tercio@11: f.GetFeedbackLine = feedback_get_fb_line Tercio@11: f.GetAddonsLine = feedback_get_addons_line Tercio@11: f.AddFeedbackMethod = feedback_add_fb Tercio@11: f.AddOtherAddon = feedback_add_addon Tercio@11: f.HideAll = feedback_hide_all Tercio@11: Tercio@11: DF:SetFontSize (f.Title, 14) Tercio@11: Tercio@11: end Tercio@11: Tercio@11: f:HideAll() Tercio@11: f:SetTitle (addon_name) Tercio@11: Tercio@11: for index, feedback in ipairs (feedback_methods) do Tercio@11: f:AddFeedbackMethod (feedback) Tercio@11: end Tercio@11: Tercio@11: f.addons_anchor:SetPoint ("topleft", f, "topleft", 5, f.next_feedback * 50 * -1) Tercio@11: f.excla_text2:SetPoint ("topright", f, "topright", -5, f.next_feedback * 50 * -1) Tercio@11: Tercio@11: for index, addon in ipairs (more_addons) do Tercio@11: f:AddOtherAddon (addon) Tercio@11: end Tercio@11: Tercio@11: f:SetHeight (80 + ((f.next_feedback-1) * 50) + (ceil ((f.next_addons-1)/3) * 66)) Tercio@11: Tercio@11: f:Show() Tercio@11: Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@11: --> chart panel -- ~chart Tercio@11: Tercio@11: local chart_panel_backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, Tercio@11: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}} Tercio@11: Tercio@11: local chart_panel_align_timelabels = function (self, elapsed_time) Tercio@11: Tercio@11: self.TimeScale = elapsed_time Tercio@11: Tercio@11: local linha = self.TimeLabels [17] Tercio@11: local minutos, segundos = math.floor (elapsed_time / 60), math.floor (elapsed_time % 60) Tercio@11: if (segundos < 10) then Tercio@11: segundos = "0" .. segundos Tercio@11: end Tercio@11: Tercio@11: if (minutos > 0) then Tercio@11: if (minutos < 10) then Tercio@11: minutos = "0" .. minutos Tercio@11: end Tercio@11: linha:SetText (minutos .. ":" .. segundos) Tercio@11: else Tercio@11: linha:SetText ("00:" .. segundos) Tercio@11: end Tercio@11: Tercio@11: local time_div = elapsed_time / 16 --786 -- 49.125 Tercio@11: Tercio@11: for i = 2, 16 do Tercio@11: Tercio@11: local linha = self.TimeLabels [i] Tercio@11: Tercio@11: local this_time = time_div * (i-1) Tercio@11: local minutos, segundos = math.floor (this_time / 60), math.floor (this_time % 60) Tercio@11: Tercio@11: if (segundos < 10) then Tercio@11: segundos = "0" .. segundos Tercio@11: end Tercio@11: Tercio@11: if (minutos > 0) then Tercio@11: if (minutos < 10) then Tercio@11: minutos = "0" .. minutos Tercio@11: end Tercio@11: linha:SetText (minutos .. ":" .. segundos) Tercio@11: else Tercio@11: linha:SetText ("00:" .. segundos) Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local chart_panel_set_scale = function (self, amt, func, text) Tercio@11: if (type (amt) ~= "number") then Tercio@11: return Tercio@11: end Tercio@11: Tercio@56: --each line amount, then multiply the line index by this number Tercio@56: local piece = amt / 8 Tercio@56: Tercio@11: for i = 1, 8 do Tercio@11: if (func) then Tercio@56: self ["dpsamt" .. math.abs (i-9)]:SetText (func (piece*i)) Tercio@11: else Tercio@11: if (piece*i > 1) then Tercio@56: self ["dpsamt" .. math.abs (i-9)]:SetText (DF.FormatNumber (piece*i)) Tercio@11: else Tercio@56: self ["dpsamt" .. math.abs (i-9)]:SetText (format ("%.3f", piece*i)) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local chart_panel_can_move = function (self, can) Tercio@11: self.can_move = can Tercio@11: end Tercio@11: Tercio@11: local chart_panel_overlay_reset = function (self) Tercio@11: self.OverlaysAmount = 1 Tercio@11: for index, pack in ipairs (self.Overlays) do Tercio@11: for index2, texture in ipairs (pack) do Tercio@11: texture:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local chart_panel_reset = function (self) Tercio@11: Tercio@11: self.Graphic:ResetData() Tercio@11: self.Graphic.max_value = 0 Tercio@11: Tercio@11: self.TimeScale = nil Tercio@11: self.BoxLabelsAmount = 1 Tercio@11: table.wipe (self.GData) Tercio@11: table.wipe (self.OData) Tercio@11: Tercio@11: for index, box in ipairs (self.BoxLabels) do Tercio@11: box.check:Hide() Tercio@11: box.button:Hide() Tercio@11: box.box:Hide() Tercio@11: box.text:Hide() Tercio@11: box.border:Hide() Tercio@11: box.showing = false Tercio@11: end Tercio@11: Tercio@11: chart_panel_overlay_reset (self) Tercio@11: end Tercio@11: Tercio@11: local chart_panel_enable_line = function (f, thisbox) Tercio@11: Tercio@11: local index = thisbox.index Tercio@11: local type = thisbox.type Tercio@11: Tercio@11: if (thisbox.enabled) then Tercio@11: --disable Tercio@11: thisbox.check:Hide() Tercio@11: thisbox.enabled = false Tercio@11: else Tercio@11: --enable Tercio@11: thisbox.check:Show() Tercio@11: thisbox.enabled = true Tercio@11: end Tercio@11: Tercio@11: if (type == "graphic") then Tercio@11: Tercio@11: f.Graphic:ResetData() Tercio@11: f.Graphic.max_value = 0 Tercio@11: Tercio@11: local max = 0 Tercio@11: local max_time = 0 Tercio@11: Tercio@11: for index, box in ipairs (f.BoxLabels) do Tercio@11: if (box.type == type and box.showing and box.enabled) then Tercio@11: local data = f.GData [index] Tercio@11: Tercio@11: f.Graphic:AddDataSeries (data[1], data[2], nil, data[3]) Tercio@11: Tercio@11: if (data[4] > max) then Tercio@11: max = data[4] Tercio@11: end Tercio@11: if (data [5] > max_time) then Tercio@11: max_time = data [5] Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: f:SetScale (max) Tercio@11: f:SetTime (max_time) Tercio@11: Tercio@11: elseif (type == "overlay") then Tercio@11: Tercio@11: chart_panel_overlay_reset (f) Tercio@11: Tercio@11: for index, box in ipairs (f.BoxLabels) do Tercio@11: if (box.type == type and box.showing and box.enabled) then Tercio@11: Tercio@11: f:AddOverlay (box.index) Tercio@11: Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local create_box = function (self, next_box) Tercio@11: Tercio@11: local thisbox = {} Tercio@11: self.BoxLabels [next_box] = thisbox Tercio@11: Tercio@11: local box = DF:NewImage (self.Graphic, nil, 16, 16, "border") Tercio@11: local text = DF:NewLabel (self.Graphic) Tercio@11: Tercio@11: local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork") Tercio@11: border:SetPoint ("center", box, "center", -3, -4) Tercio@11: border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]]) Tercio@11: Tercio@11: local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay") Tercio@56: checktexture:SetPoint ("center", box, "center", 0, -1) Tercio@11: checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]]) Tercio@11: Tercio@11: thisbox.box = box Tercio@11: thisbox.text = text Tercio@11: thisbox.border = border Tercio@11: thisbox.check = checktexture Tercio@11: thisbox.enabled = true Tercio@11: Tercio@11: local button = CreateFrame ("button", nil, self.Graphic) Tercio@11: button:SetSize (20, 20) Tercio@11: button:SetScript ("OnClick", function() Tercio@11: chart_panel_enable_line (self, thisbox) Tercio@11: end) Tercio@56: button:SetPoint ("topleft", box.widget or box, "topleft", 0, 0) Tercio@56: button:SetPoint ("bottomright", box.widget or box, "bottomright", 0, 0) Tercio@56: Tercio@56: button:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@56: button:SetBackdropColor (0, 0, 0, 0.0) Tercio@56: button:SetBackdropBorderColor (0, 0, 0, 1) Tercio@11: Tercio@11: thisbox.button = button Tercio@11: Tercio@11: thisbox.box:SetPoint ("right", text, "left", -4, 0) Tercio@11: Tercio@11: if (next_box == 1) then Tercio@11: thisbox.text:SetPoint ("topright", self, "topright", -35, -16) Tercio@11: else Tercio@56: thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -17, 0) Tercio@11: end Tercio@11: Tercio@11: return thisbox Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local realign_labels = function (self) Tercio@11: Tercio@56: if (not self.ShowHeader) then Tercio@56: for _, box in ipairs (self.BoxLabels) do Tercio@56: box.check:Hide() Tercio@56: box.button:Hide() Tercio@56: box.border:Hide() Tercio@56: box.box:Hide() Tercio@56: box.text:Hide() Tercio@56: end Tercio@56: return Tercio@56: end Tercio@56: Tercio@11: local width = self:GetWidth() - 108 Tercio@11: Tercio@11: local first_box = self.BoxLabels [1] Tercio@11: first_box.text:SetPoint ("topright", self, "topright", -35, -16) Tercio@11: Tercio@11: local line_width = first_box.text:GetStringWidth() + 26 Tercio@11: Tercio@11: for i = 2, #self.BoxLabels do Tercio@11: Tercio@11: local box = self.BoxLabels [i] Tercio@11: Tercio@11: if (box.box:IsShown()) then Tercio@11: Tercio@11: line_width = line_width + box.text:GetStringWidth() + 26 Tercio@11: Tercio@11: if (line_width > width) then Tercio@11: line_width = box.text:GetStringWidth() + 26 Tercio@11: box.text:SetPoint ("topright", self, "topright", -35, -40) Tercio@11: else Tercio@56: box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -27, 0) Tercio@11: end Tercio@11: else Tercio@11: break Tercio@11: end Tercio@11: end Tercio@11: Tercio@56: if (self.HeaderOnlyIndicator) then Tercio@56: for _, box in ipairs (self.BoxLabels) do Tercio@56: box.check:Hide() Tercio@56: box.button:Hide() Tercio@56: end Tercio@56: return Tercio@56: end Tercio@56: Tercio@11: end Tercio@11: Tercio@11: local chart_panel_add_label = function (self, color, name, type, number) Tercio@56: Tercio@11: local next_box = self.BoxLabelsAmount Tercio@11: local thisbox = self.BoxLabels [next_box] Tercio@11: Tercio@11: if (not thisbox) then Tercio@11: thisbox = create_box (self, next_box) Tercio@11: end Tercio@11: Tercio@11: self.BoxLabelsAmount = self.BoxLabelsAmount + 1 Tercio@56: Tercio@11: thisbox.type = type Tercio@11: thisbox.index = number Tercio@56: Tercio@39: thisbox.box:SetColorTexture (unpack (color)) Tercio@11: thisbox.text:SetText (name) Tercio@11: Tercio@11: thisbox.check:Show() Tercio@11: thisbox.button:Show() Tercio@56: thisbox.border:Hide() Tercio@11: thisbox.box:Show() Tercio@11: thisbox.text:Show() Tercio@56: Tercio@11: thisbox.showing = true Tercio@11: thisbox.enabled = true Tercio@11: Tercio@11: realign_labels (self) Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local line_default_color = {1, 1, 1} Tercio@11: local draw_overlay = function (self, this_overlay, overlayData, color) Tercio@11: Tercio@11: local pixel = self.Graphic:GetWidth() / self.TimeScale Tercio@11: local index = 1 Tercio@56: local r, g, b, a = unpack (color or line_default_color) Tercio@11: Tercio@11: for i = 1, #overlayData, 2 do Tercio@11: local aura_start = overlayData [i] Tercio@11: local aura_end = overlayData [i+1] Tercio@11: Tercio@11: local this_block = this_overlay [index] Tercio@11: if (not this_block) then Tercio@11: this_block = self.Graphic:CreateTexture (nil, "border") Tercio@11: tinsert (this_overlay, this_block) Tercio@11: end Tercio@11: this_block:SetHeight (self.Graphic:GetHeight()) Tercio@11: Tercio@11: this_block:SetPoint ("left", self.Graphic, "left", pixel * aura_start, 0) Tercio@11: if (aura_end) then Tercio@11: this_block:SetWidth ((aura_end-aura_start)*pixel) Tercio@11: else Tercio@11: --malformed table Tercio@11: this_block:SetWidth (pixel*5) Tercio@11: end Tercio@11: Tercio@56: this_block:SetColorTexture (r, g, b, a or 0.25) Tercio@11: this_block:Show() Tercio@11: Tercio@11: index = index + 1 Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local chart_panel_add_overlay = function (self, overlayData, color, name, icon) Tercio@11: Tercio@11: if (not self.TimeScale) then Tercio@11: error ("Use SetTime (time) before adding an overlay.") Tercio@11: end Tercio@11: Tercio@11: if (type (overlayData) == "number") then Tercio@11: local overlay_index = overlayData Tercio@11: draw_overlay (self, self.Overlays [self.OverlaysAmount], self.OData [overlay_index][1], self.OData [overlay_index][2]) Tercio@11: else Tercio@11: local this_overlay = self.Overlays [self.OverlaysAmount] Tercio@11: if (not this_overlay) then Tercio@11: this_overlay = {} Tercio@11: tinsert (self.Overlays, this_overlay) Tercio@11: end Tercio@11: Tercio@11: draw_overlay (self, this_overlay, overlayData, color) Tercio@11: Tercio@11: tinsert (self.OData, {overlayData, color or line_default_color}) Tercio@56: if (name and self.HeaderShowOverlays) then Tercio@11: self:AddLabel (color or line_default_color, name, "overlay", #self.OData) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: self.OverlaysAmount = self.OverlaysAmount + 1 Tercio@11: end Tercio@11: Tercio@56: -- Define the tricube weight function Tercio@56: function calc_cubeweight (i, j, d) Tercio@56: local w = ( 1 - math.abs ((j-i)/d)^3)^3 Tercio@56: if w < 0 then Tercio@56: w = 0; Tercio@56: end Tercio@56: return w Tercio@56: end Tercio@56: Tercio@56: local calc_lowess_smoothing = function (self, data, bandwidth) Tercio@56: local length = #data Tercio@56: local newData = {} Tercio@56: Tercio@56: for i = 1, length do Tercio@56: local A = 0 Tercio@56: local B = 0 Tercio@56: local C = 0 Tercio@56: local D = 0 Tercio@56: local E = 0 Tercio@56: Tercio@56: -- Calculate span of values to be included in the regression Tercio@56: local jmin = floor (i-bandwidth/2) Tercio@56: local jmax = ceil (i+bandwidth/2) Tercio@56: if jmin < 1 then Tercio@56: jmin = 1 Tercio@56: end Tercio@56: if jmax > length then Tercio@56: jmax = length Tercio@56: end Tercio@56: Tercio@56: -- For all the values in the span, compute the weight and then the linear fit Tercio@56: Tercio@56: for j = jmin, jmax do Tercio@56: w = calc_cubeweight (i, j, bandwidth/2) Tercio@56: x = j Tercio@56: y = data [j] Tercio@56: Tercio@56: A = A + w*x Tercio@56: B = B + w*y Tercio@56: C = C + w*x^2 Tercio@56: D = D + w*x*y Tercio@56: E = E + w Tercio@56: end Tercio@56: Tercio@56: -- Calculate a (slope) and b (offset) for the linear fit Tercio@56: local a = (A*B-D*E)/(A^2 - C*E); Tercio@56: local b = (A*D-B*C)/(A^2 - C*E); Tercio@56: Tercio@56: -- Calculate the smoothed value by the formula y=a*x+b (x <- i) Tercio@56: newData [i] = a*i+b; Tercio@56: Tercio@56: end Tercio@56: Tercio@56: return newData Tercio@56: end Tercio@56: Tercio@56: local calc_stddev = function (self, data) Tercio@56: local total = 0 Tercio@56: for i = 1, #data do Tercio@56: total = total + data[i] Tercio@56: end Tercio@56: local mean = total / #data Tercio@56: Tercio@56: local totalDistance = 0 Tercio@56: for i = 1, #data do Tercio@56: totalDistance = totalDistance + ((data[i] - mean) ^ 2) Tercio@56: end Tercio@56: Tercio@56: local deviation = math.sqrt (totalDistance / #data) Tercio@56: return deviation Tercio@56: end Tercio@56: Tercio@56: Tercio@56: Tercio@11: local SMA_table = {} Tercio@11: local SMA_max = 0 Tercio@11: local reset_SMA = function() Tercio@11: table.wipe (SMA_table) Tercio@11: SMA_max = 0 Tercio@11: end Tercio@11: Tercio@11: local calc_SMA Tercio@11: calc_SMA = function (a, b, ...) Tercio@11: if (b) then Tercio@11: return calc_SMA (a + b, ...) Tercio@11: else Tercio@11: return a Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local do_SMA = function (value, max_value) Tercio@11: Tercio@11: if (#SMA_table == 10) then Tercio@11: tremove (SMA_table, 1) Tercio@11: end Tercio@11: Tercio@11: SMA_table [#SMA_table + 1] = value Tercio@11: Tercio@11: local new_value = calc_SMA (unpack (SMA_table)) / #SMA_table Tercio@11: Tercio@11: if (new_value > SMA_max) then Tercio@11: SMA_max = new_value Tercio@11: return new_value, SMA_max Tercio@11: else Tercio@11: return new_value Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@55: local chart_panel_onresize = function (self) Tercio@55: local width, height = self:GetSize() Tercio@55: local spacement = width - 78 - 60 Tercio@55: spacement = spacement / 16 Tercio@55: Tercio@55: for i = 1, 17 do Tercio@55: local label = self.TimeLabels [i] Tercio@56: label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), self.TimeLabelsHeight) Tercio@55: label.line:SetHeight (height - 45) Tercio@55: end Tercio@55: Tercio@55: local spacement = (self.Graphic:GetHeight()) / 8 Tercio@55: for i = 1, 8 do Tercio@55: self ["dpsamt"..i]:SetPoint ("TOPLEFT", self, "TOPLEFT", 27, -25 + (-(spacement* (i-1))) ) Tercio@55: self ["dpsamt"..i].line:SetWidth (width-20) Tercio@55: end Tercio@55: Tercio@55: self.Graphic:SetSize (width - 135, height - 67) Tercio@55: self.Graphic:SetPoint ("topleft", self, "topleft", 108, -35) Tercio@55: end Tercio@55: Tercio@11: local chart_panel_add_data = function (self, graphicData, color, name, elapsed_time, lineTexture, smoothLevel, firstIndex) Tercio@11: Tercio@11: local f = self Tercio@11: self = self.Graphic Tercio@22: Tercio@11: local _data = {} Tercio@11: local max_value = graphicData.max_value Tercio@11: local amount = #graphicData Tercio@11: Tercio@11: local scaleW = 1/self:GetWidth() Tercio@56: Tercio@11: local content = graphicData Tercio@11: tinsert (content, 1, 0) Tercio@11: tinsert (content, 1, 0) Tercio@11: tinsert (content, #content+1, 0) Tercio@11: tinsert (content, #content+1, 0) Tercio@11: Tercio@11: local _i = 3 Tercio@11: Tercio@11: local graphMaxDps = math.max (self.max_value, max_value) Tercio@11: Tercio@11: if (not smoothLevel) then Tercio@11: while (_i <= #content-2) do Tercio@11: local v = (content[_i-2]+content[_i-1]+content[_i]+content[_i+1]+content[_i+2])/5 --> normalize Tercio@11: _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords Tercio@11: _i = _i + 1 Tercio@11: end Tercio@11: Tercio@11: elseif (smoothLevel == "SHORT") then Tercio@11: while (_i <= #content-2) do Tercio@11: local value = (content[_i] + content[_i+1]) / 2 Tercio@11: _data [#_data+1] = {scaleW*(_i-2), value} Tercio@11: _data [#_data+1] = {scaleW*(_i-2), value} Tercio@11: _i = _i + 2 Tercio@11: end Tercio@11: Tercio@11: elseif (smoothLevel == "SMA") then Tercio@11: reset_SMA() Tercio@11: while (_i <= #content-2) do Tercio@11: local value, is_new_max_value = do_SMA (content[_i], max_value) Tercio@11: if (is_new_max_value) then Tercio@11: max_value = is_new_max_value Tercio@11: end Tercio@11: _data [#_data+1] = {scaleW*(_i-2), value} --> x and y coords Tercio@11: _i = _i + 1 Tercio@11: end Tercio@11: Tercio@11: elseif (smoothLevel == -1) then Tercio@11: while (_i <= #content-2) do Tercio@11: local current = content[_i] Tercio@11: Tercio@11: local minus_2 = content[_i-2] * 0.6 Tercio@11: local minus_1 = content[_i-1] * 0.8 Tercio@11: local plus_1 = content[_i+1] * 0.8 Tercio@11: local plus_2 = content[_i+2] * 0.6 Tercio@11: Tercio@11: local v = (current + minus_2 + minus_1 + plus_1 + plus_2)/5 --> normalize Tercio@11: _data [#_data+1] = {scaleW*(_i-2), v/graphMaxDps} --> x and y coords Tercio@11: _i = _i + 1 Tercio@11: end Tercio@11: Tercio@11: elseif (smoothLevel == 1) then Tercio@11: _i = 2 Tercio@11: while (_i <= #content-1) do Tercio@11: local v = (content[_i-1]+content[_i]+content[_i+1])/3 --> normalize Tercio@11: _data [#_data+1] = {scaleW*(_i-1), v/graphMaxDps} --> x and y coords Tercio@11: _i = _i + 1 Tercio@11: end Tercio@11: Tercio@11: elseif (smoothLevel == 2) then Tercio@11: _i = 1 Tercio@11: while (_i <= #content) do Tercio@11: local v = content[_i] --> do not normalize Tercio@11: _data [#_data+1] = {scaleW*(_i), v/graphMaxDps} --> x and y coords Tercio@11: _i = _i + 1 Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: tremove (content, 1) Tercio@11: tremove (content, 1) Tercio@11: tremove (content, #graphicData) Tercio@11: tremove (content, #graphicData) Tercio@11: Tercio@11: if (max_value > self.max_value) then Tercio@11: --> normalize previous data Tercio@11: if (self.max_value > 0) then Tercio@11: local normalizePercent = self.max_value / max_value Tercio@11: for dataIndex, Data in ipairs (self.Data) do Tercio@11: local Points = Data.Points Tercio@11: for i = 1, #Points do Tercio@11: Points[i][2] = Points[i][2]*normalizePercent Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: self.max_value = max_value Tercio@11: f:SetScale (max_value) Tercio@11: Tercio@11: end Tercio@11: Tercio@11: tinsert (f.GData, {_data, color or line_default_color, lineTexture, max_value, elapsed_time}) Tercio@11: if (name) then Tercio@11: f:AddLabel (color or line_default_color, name, "graphic", #f.GData) Tercio@11: end Tercio@11: Tercio@11: if (firstIndex) then Tercio@11: if (lineTexture) then Tercio@11: if (not lineTexture:find ("\\") and not lineTexture:find ("//")) then Tercio@11: local path = string.match (debugstack (1, 1, 0), "AddOns\\(.+)LibGraph%-2%.0%.lua") Tercio@11: if path then Tercio@11: lineTexture = "Interface\\AddOns\\" .. path .. lineTexture Tercio@11: else Tercio@11: lineTexture = nil Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: table.insert (self.Data, 1, {Points = _data, Color = color or line_default_color, lineTexture = lineTexture, ElapsedTime = elapsed_time}) Tercio@11: self.NeedsUpdate = true Tercio@11: else Tercio@11: self:AddDataSeries (_data, color or line_default_color, nil, lineTexture) Tercio@11: self.Data [#self.Data].ElapsedTime = elapsed_time Tercio@11: end Tercio@11: Tercio@11: local max_time = 0 Tercio@11: for _, data in ipairs (self.Data) do Tercio@11: if (data.ElapsedTime > max_time) then Tercio@11: max_time = data.ElapsedTime Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: f:SetTime (max_time) Tercio@11: Tercio@55: chart_panel_onresize (f) Tercio@11: end Tercio@11: Tercio@55: Tercio@11: Tercio@56: Tercio@11: local chart_panel_vlines_on = function (self) Tercio@11: for i = 1, 17 do Tercio@11: local label = self.TimeLabels [i] Tercio@11: label.line:Show() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local chart_panel_vlines_off = function (self) Tercio@11: for i = 1, 17 do Tercio@11: local label = self.TimeLabels [i] Tercio@11: label.line:Hide() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local chart_panel_set_title = function (self, title) Tercio@11: self.chart_title.text = title Tercio@11: end Tercio@11: Tercio@11: local chart_panel_mousedown = function (self, button) Tercio@11: if (button == "LeftButton" and self.can_move) then Tercio@11: if (not self.isMoving) then Tercio@11: self:StartMoving() Tercio@11: self.isMoving = true Tercio@11: end Tercio@11: elseif (button == "RightButton" and not self.no_right_click_close) then Tercio@11: if (not self.isMoving) then Tercio@11: self:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: local chart_panel_mouseup = function (self, button) Tercio@11: if (button == "LeftButton" and self.isMoving) then Tercio@11: self:StopMovingOrSizing() Tercio@11: self.isMoving = nil Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local chart_panel_hide_close_button = function (self) Tercio@11: self.CloseButton:Hide() Tercio@11: end Tercio@11: Tercio@11: local chart_panel_right_click_close = function (self, value) Tercio@11: if (type (value) == "boolean") then Tercio@11: if (value) then Tercio@11: self.no_right_click_close = nil Tercio@11: else Tercio@11: self.no_right_click_close = true Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DF:CreateChartPanel (parent, w, h, name) Tercio@11: Tercio@11: if (not name) then Tercio@11: name = "DFPanel" .. DF.PanelCounter Tercio@11: DF.PanelCounter = DF.PanelCounter + 1 Tercio@11: end Tercio@11: Tercio@11: parent = parent or UIParent Tercio@11: w = w or 800 Tercio@11: h = h or 500 Tercio@11: Tercio@11: local f = CreateFrame ("frame", name, parent) Tercio@11: f:SetSize (w or 500, h or 400) Tercio@11: f:EnableMouse (true) Tercio@11: f:SetMovable (true) Tercio@11: Tercio@11: f:SetScript ("OnMouseDown", chart_panel_mousedown) Tercio@11: f:SetScript ("OnMouseUp", chart_panel_mouseup) Tercio@11: Tercio@11: f:SetBackdrop (chart_panel_backdrop) Tercio@11: f:SetBackdropColor (.3, .3, .3, .3) Tercio@11: Tercio@11: local c = CreateFrame ("Button", nil, f, "UIPanelCloseButton") Tercio@11: c:SetWidth (32) Tercio@11: c:SetHeight (32) Tercio@11: c:SetPoint ("TOPRIGHT", f, "TOPRIGHT", -3, -7) Tercio@11: c:SetFrameLevel (f:GetFrameLevel()+1) Tercio@11: c:SetAlpha (0.9) Tercio@11: f.CloseButton = c Tercio@11: Tercio@11: local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0}) Tercio@11: title:SetPoint ("topleft", f, "topleft", 110, -13) Tercio@11: Tercio@11: f.Overlays = {} Tercio@11: f.OverlaysAmount = 1 Tercio@11: Tercio@11: f.BoxLabels = {} Tercio@11: f.BoxLabelsAmount = 1 Tercio@11: Tercio@56: f.ShowHeader = true Tercio@56: f.HeaderOnlyIndicator = false Tercio@56: f.HeaderShowOverlays = true Tercio@11: Tercio@11: --graphic Tercio@11: local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67) Tercio@11: g:SetXAxis (-1,1) Tercio@11: g:SetYAxis (-1,1) Tercio@11: g:SetGridSpacing (false, false) Tercio@11: g:SetGridColor ({0.5,0.5,0.5,0.3}) Tercio@11: g:SetAxisDrawing (false,false) Tercio@11: g:SetAxisColor({1.0,1.0,1.0,1.0}) Tercio@11: g:SetAutoScale (true) Tercio@11: g:SetLineTexture ("smallline") Tercio@11: g:SetBorderSize ("right", 0.001) Tercio@11: g:SetBorderSize ("left", 0.000) Tercio@11: g:SetBorderSize ("top", 0.002) Tercio@11: g:SetBorderSize ("bottom", 0.001) Tercio@11: g.VerticalLines = {} Tercio@11: g.max_value = 0 Tercio@11: Tercio@11: g:SetLineTexture ("line") Tercio@11: Tercio@11: f.Graphic = g Tercio@11: f.GData = {} Tercio@11: f.OData = {} Tercio@56: f.ChartFrames = {} Tercio@11: Tercio@11: --div lines Tercio@11: for i = 1, 8, 1 do Tercio@11: local line = g:CreateTexture (nil, "overlay") Tercio@56: line:SetColorTexture (1, 1, 1, .05) Tercio@11: line:SetWidth (670) Tercio@11: line:SetHeight (1.1) Tercio@11: Tercio@11: local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall") Tercio@11: f ["dpsamt"..i] = s Tercio@11: s:SetText ("100k") Tercio@11: s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i))) Tercio@11: Tercio@11: line:SetPoint ("topleft", s, "bottom", -27, 0) Tercio@56: line:SetPoint ("topright", g, "right", 0, 0) Tercio@11: s.line = line Tercio@11: end Tercio@11: Tercio@56: --create time labels and the bottom texture to use as a background to these labels Tercio@56: f.TimeLabels = {} Tercio@56: f.TimeLabelsHeight = 16 Tercio@56: Tercio@56: for i = 1, 17 do Tercio@56: local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall") Tercio@56: time:SetText ("00:00") Tercio@56: time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), f.TimeLabelsHeight) Tercio@56: f.TimeLabels [i] = time Tercio@56: Tercio@56: local line = f:CreateTexture (nil, "border") Tercio@56: line:SetSize (1, h-45) Tercio@56: line:SetColorTexture (1, 1, 1, .1) Tercio@56: line:SetPoint ("bottomleft", time, "topright", 0, -10) Tercio@56: line:Hide() Tercio@56: time.line = line Tercio@56: end Tercio@56: Tercio@56: local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture") Tercio@56: bottom_texture:SetColorTexture (.1, .1, .1, .7) Tercio@56: bottom_texture:SetPoint ("topright", g, "bottomright", 0, 0) Tercio@56: bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 12) Tercio@56: Tercio@56: Tercio@56: Tercio@11: f.SetTime = chart_panel_align_timelabels Tercio@11: f.EnableVerticalLines = chart_panel_vlines_on Tercio@11: f.DisableVerticalLines = chart_panel_vlines_off Tercio@11: f.SetTitle = chart_panel_set_title Tercio@11: f.SetScale = chart_panel_set_scale Tercio@11: f.Reset = chart_panel_reset Tercio@11: f.AddLine = chart_panel_add_data Tercio@11: f.CanMove = chart_panel_can_move Tercio@11: f.AddLabel = chart_panel_add_label Tercio@11: f.AddOverlay = chart_panel_add_overlay Tercio@11: f.HideCloseButton = chart_panel_hide_close_button Tercio@11: f.RightClickClose = chart_panel_right_click_close Tercio@56: f.CalcStdDev = calc_stddev Tercio@56: f.CalcLowessSmoothing = calc_lowess_smoothing Tercio@11: Tercio@11: f:SetScript ("OnSizeChanged", chart_panel_onresize) Tercio@11: chart_panel_onresize (f) Tercio@11: Tercio@11: return f Tercio@20: end Tercio@20: Tercio@20: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@20: -- ~gframe Tercio@20: local gframe_on_enter_line = function (self) Tercio@20: self:SetBackdropColor (0, 0, 0, 0) Tercio@20: Tercio@20: local parent = self:GetParent() Tercio@20: local ball = self.ball Tercio@20: ball:SetBlendMode ("ADD") Tercio@20: Tercio@20: local on_enter = parent._onenter_line Tercio@20: if (on_enter) then Tercio@20: return on_enter (self, parent) Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: local gframe_on_leave_line = function (self) Tercio@20: self:SetBackdropColor (0, 0, 0, .6) Tercio@20: Tercio@20: local parent = self:GetParent() Tercio@20: local ball = self.ball Tercio@20: ball:SetBlendMode ("BLEND") Tercio@20: Tercio@20: local on_leave = parent._onleave_line Tercio@20: if (on_leave) then Tercio@20: return on_leave (self, parent) Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: local gframe_create_line = function (self) Tercio@20: local index = #self._lines+1 Tercio@20: Tercio@20: local f = CreateFrame ("frame", nil, self) Tercio@20: self._lines [index] = f Tercio@20: f.id = index Tercio@20: f:SetScript ("OnEnter", gframe_on_enter_line) Tercio@20: f:SetScript ("OnLeave", gframe_on_leave_line) Tercio@20: Tercio@20: f:SetWidth (self._linewidth) Tercio@20: Tercio@20: if (index == 1) then Tercio@20: f:SetPoint ("topleft", self, "topleft") Tercio@20: f:SetPoint ("bottomleft", self, "bottomleft") Tercio@20: else Tercio@20: local previous_line = self._lines [index-1] Tercio@20: f:SetPoint ("topleft", previous_line, "topright") Tercio@20: f:SetPoint ("bottomleft", previous_line, "bottomright") Tercio@20: end Tercio@20: Tercio@20: local t = f:CreateTexture (nil, "background") Tercio@20: t:SetWidth (1) Tercio@20: t:SetPoint ("topright", f, "topright") Tercio@20: t:SetPoint ("bottomright", f, "bottomright") Tercio@39: t:SetColorTexture (1, 1, 1, .1) Tercio@20: f.grid = t Tercio@20: Tercio@20: local b = f:CreateTexture (nil, "overlay") Tercio@20: b:SetTexture ([[Interface\COMMON\Indicator-Yellow]]) Tercio@20: b:SetSize (16, 16) Tercio@20: f.ball = b Tercio@20: local anchor = CreateFrame ("frame", nil, f) Tercio@20: anchor:SetAllPoints (b) Tercio@20: b.tooltip_anchor = anchor Tercio@20: Tercio@20: local spellicon = f:CreateTexture (nil, "artwork") Tercio@20: spellicon:SetPoint ("bottom", b, "bottom", 0, 10) Tercio@20: spellicon:SetSize (16, 16) Tercio@20: f.spellicon = spellicon Tercio@20: Tercio@53: local text = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@53: local textBackground = f:CreateTexture (nil, "artwork") Tercio@53: textBackground:SetSize (30, 16) Tercio@53: textBackground:SetColorTexture (0, 0, 0, 0.5) Tercio@53: textBackground:SetPoint ("bottom", f.ball, "top", 0, -6) Tercio@53: text:SetPoint ("center", textBackground, "center") Tercio@53: DF:SetFontSize (text, 10) Tercio@53: f.text = text Tercio@53: f.textBackground = textBackground Tercio@53: Tercio@20: local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@20: timeline:SetPoint ("bottomright", f, "bottomright", -2, 0) Tercio@40: DF:SetFontSize (timeline, 8) Tercio@20: f.timeline = timeline Tercio@20: Tercio@20: return f Tercio@20: end Tercio@20: Tercio@20: local gframe_getline = function (self, index) Tercio@20: local line = self._lines [index] Tercio@20: if (not line) then Tercio@20: line = gframe_create_line (self) Tercio@20: end Tercio@20: return line Tercio@20: end Tercio@20: Tercio@20: local gframe_reset = function (self) Tercio@20: for i, line in ipairs (self._lines) do Tercio@20: line:Hide() Tercio@20: end Tercio@20: if (self.GraphLib_Lines_Used) then Tercio@20: for i = #self.GraphLib_Lines_Used, 1, -1 do Tercio@20: local line = tremove (self.GraphLib_Lines_Used) Tercio@20: tinsert (self.GraphLib_Lines, line) Tercio@20: line:Hide() Tercio@20: end Tercio@20: end Tercio@20: end Tercio@20: Tercio@20: local gframe_update = function (self, lines) Tercio@20: Tercio@20: local g = LibStub:GetLibrary ("LibGraph-2.0") Tercio@20: local h = self:GetHeight()/100 Tercio@20: local amtlines = #lines Tercio@20: local linewidth = self._linewidth Tercio@20: Tercio@20: local max_value = 0 Tercio@20: for i = 1, amtlines do Tercio@20: if (lines [i].value > max_value) then Tercio@20: max_value = lines [i].value Tercio@20: end Tercio@20: end Tercio@20: Tercio@40: self.MaxValue = max_value Tercio@40: Tercio@20: local o = 1 Tercio@20: local lastvalue = self:GetHeight()/2 Tercio@40: max_value = math.max (max_value, 0.0000001) Tercio@20: Tercio@20: for i = 1, min (amtlines, self._maxlines) do Tercio@20: Tercio@20: local data = lines [i] Tercio@20: Tercio@20: local pvalue = data.value / max_value * 100 Tercio@20: if (pvalue > 98) then Tercio@20: pvalue = 98 Tercio@20: end Tercio@20: pvalue = pvalue * h Tercio@20: Tercio@20: g:DrawLine (self, (o-1)*linewidth, lastvalue, o*linewidth, pvalue, linewidth, {1, 1, 1, 1}, "overlay") Tercio@20: lastvalue = pvalue Tercio@20: Tercio@20: local line = self:GetLine (i) Tercio@20: line:Show() Tercio@20: line.ball:Show() Tercio@20: Tercio@20: line.ball:SetPoint ("bottomleft", self, "bottomleft", (o*linewidth)-8, pvalue-8) Tercio@20: line.spellicon:SetTexture (nil) Tercio@20: line.timeline:SetText (data.text) Tercio@20: line.timeline:Show() Tercio@20: Tercio@53: if (data.utext) then Tercio@53: line.text:Show() Tercio@53: line.textBackground:Show() Tercio@53: line.text:SetText (data.utext) Tercio@53: else Tercio@53: line.text:Hide() Tercio@53: line.textBackground:Hide() Tercio@53: end Tercio@53: Tercio@20: line.data = data Tercio@20: Tercio@20: o = o + 1 Tercio@20: end Tercio@20: Tercio@20: end Tercio@20: Tercio@20: function DF:CreateGFrame (parent, w, h, linewidth, onenter, onleave, member, name) Tercio@20: local f = CreateFrame ("frame", name, parent) Tercio@20: f:SetSize (w or 450, h or 150) Tercio@45: --f.CustomLine = [[Interface\AddOns\Details\Libs\LibGraph-2.0\line]] Tercio@20: Tercio@20: if (member) then Tercio@20: parent [member] = f Tercio@20: end Tercio@20: Tercio@20: f.CreateLine = gframe_create_line Tercio@20: f.GetLine = gframe_getline Tercio@20: f.Reset = gframe_reset Tercio@20: f.UpdateLines = gframe_update Tercio@20: Tercio@40: f.MaxValue = 0 Tercio@40: Tercio@20: f._lines = {} Tercio@20: Tercio@20: f._onenter_line = onenter Tercio@20: f._onleave_line = onleave Tercio@20: Tercio@20: f._linewidth = linewidth or 50 Tercio@20: f._maxlines = floor (f:GetWidth() / f._linewidth) Tercio@20: Tercio@20: return f Tercio@39: end Tercio@39: Tercio@39: Tercio@39: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@39: -- ~buttoncontainer Tercio@39: Tercio@39: function DF:CreateButtonContainer (parent, name) Tercio@39: local f = CreateFrame ("frame", name, parent) Tercio@39: -- f. Tercio@39: end Tercio@39: Tercio@39: Tercio@39: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@39: --> options tabs and buttons -dot Tercio@39: Tercio@39: function DF:FindHighestParent (self) Tercio@39: local f Tercio@39: if (self:GetParent() == UIParent) then Tercio@39: f = self Tercio@39: end Tercio@39: if (not f) then Tercio@39: f = self Tercio@39: for i = 1, 6 do Tercio@39: local parent = f:GetParent() Tercio@39: if (parent == UIParent) then Tercio@39: break Tercio@39: else Tercio@39: f = parent Tercio@39: end Tercio@39: end Tercio@39: end Tercio@39: Tercio@39: return f Tercio@39: end Tercio@39: Tercio@39: DF.TabContainerFunctions = {} Tercio@39: Tercio@39: local button_tab_template = DF.table.copy ({}, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")) Tercio@39: button_tab_template.backdropbordercolor = nil Tercio@39: Tercio@39: DF.TabContainerFunctions.CreateUnderlineGlow = function (button) Tercio@39: local selectedGlow = button:CreateTexture (nil, "background", -4) Tercio@39: selectedGlow:SetPoint ("topleft", button.widget, "bottomleft", -7, 0) Tercio@39: selectedGlow:SetPoint ("topright", button.widget, "bottomright", 7, 0) Tercio@39: selectedGlow:SetTexture ([[Interface\BUTTONS\UI-Panel-Button-Glow]]) Tercio@39: selectedGlow:SetTexCoord (0, 95/128, 30/64, 38/64) Tercio@39: selectedGlow:SetBlendMode ("ADD") Tercio@39: selectedGlow:SetHeight (8) Tercio@39: selectedGlow:SetAlpha (.75) Tercio@39: selectedGlow:Hide() Tercio@39: button.selectedUnderlineGlow = selectedGlow Tercio@39: end Tercio@39: Tercio@39: DF.TabContainerFunctions.OnMouseDown = function (self, button) Tercio@39: --> search for UIParent Tercio@39: local f = DF:FindHighestParent (self) Tercio@39: local container = self:GetParent() Tercio@39: Tercio@39: if (button == "LeftButton") then Tercio@39: if (not f.IsMoving and f:IsMovable()) then Tercio@39: f:StartMoving() Tercio@39: f.IsMoving = true Tercio@39: end Tercio@39: elseif (button == "RightButton") then Tercio@39: if (not f.IsMoving and container.IsContainer) then Tercio@39: if (self.IsFrontPage) then Tercio@39: if (container.CanCloseWithRightClick) then Tercio@39: if (f.CloseFunction) then Tercio@39: f:CloseFunction() Tercio@39: else Tercio@39: f:Hide() Tercio@39: end Tercio@39: end Tercio@39: else Tercio@39: --goes back to front page Tercio@39: DF.TabContainerFunctions.SelectIndex (self, _, 1) Tercio@39: end Tercio@39: end Tercio@39: end Tercio@39: end Tercio@39: Tercio@39: DF.TabContainerFunctions.OnMouseUp = function (self, button) Tercio@39: local f = DF:FindHighestParent (self) Tercio@39: if (f.IsMoving) then Tercio@39: f:StopMovingOrSizing() Tercio@39: f.IsMoving = false Tercio@39: end Tercio@39: end Tercio@39: Tercio@39: DF.TabContainerFunctions.SelectIndex = function (self, fixedParam, menuIndex) Tercio@39: local mainFrame = self.AllFrames and self or self.mainFrame or self:GetParent() Tercio@39: Tercio@39: for i = 1, #mainFrame.AllFrames do Tercio@39: mainFrame.AllFrames[i]:Hide() Tercio@39: if (mainFrame.ButtonNotSelectedBorderColor) then Tercio@39: mainFrame.AllButtons[i]:SetBackdropBorderColor (unpack (mainFrame.ButtonNotSelectedBorderColor)) Tercio@39: end Tercio@39: if (mainFrame.AllButtons[i].selectedUnderlineGlow) then Tercio@39: mainFrame.AllButtons[i].selectedUnderlineGlow:Hide() Tercio@39: end Tercio@39: end Tercio@39: Tercio@39: mainFrame.AllFrames[menuIndex]:Show() Tercio@39: if (mainFrame.ButtonSelectedBorderColor) then Tercio@39: mainFrame.AllButtons[menuIndex]:SetBackdropBorderColor (unpack (mainFrame.ButtonSelectedBorderColor)) Tercio@39: end Tercio@39: if (mainFrame.AllButtons[menuIndex].selectedUnderlineGlow) then Tercio@39: mainFrame.AllButtons[menuIndex].selectedUnderlineGlow:Show() Tercio@39: end Tercio@39: mainFrame.CurrentIndex = menuIndex Tercio@39: end Tercio@39: Tercio@39: DF.TabContainerFunctions.SetIndex = function (self, index) Tercio@39: self.CurrentIndex = index Tercio@39: end Tercio@39: Tercio@39: local tab_container_on_show = function (self) Tercio@39: local index = self.CurrentIndex Tercio@39: self.SelectIndex (self.AllButtons[index], nil, index) Tercio@39: end Tercio@39: Tercio@39: function DF:CreateTabContainer (parent, title, frame_name, frame_list, options_table) Tercio@39: Tercio@39: local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE") Tercio@39: local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") Tercio@39: local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE") Tercio@39: local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE") Tercio@39: local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE") Tercio@39: Tercio@39: options_table = options_table or {} Tercio@39: local frame_width = parent:GetWidth() Tercio@39: local frame_height = parent:GetHeight() Tercio@39: local y_offset = options_table.y_offset or 0 Tercio@39: local button_width = options_table.button_width or 160 Tercio@39: local button_height = options_table.button_height or 20 Tercio@39: local button_anchor_x = options_table.button_x or 230 Tercio@39: local button_anchor_y = options_table.button_y or -32 Tercio@39: local button_text_size = options_table.button_text_size or 10 Tercio@39: Tercio@39: local mainFrame = CreateFrame ("frame", frame_name, parent.widget or parent) Tercio@39: mainFrame:SetAllPoints() Tercio@39: DF:Mixin (mainFrame, DF.TabContainerFunctions) Tercio@39: Tercio@39: local mainTitle = DF:CreateLabel (mainFrame, title, 24, "white") Tercio@39: mainTitle:SetPoint ("topleft", mainFrame, "topleft", 10, -30 + y_offset) Tercio@39: Tercio@39: mainFrame:SetFrameLevel (200) Tercio@39: Tercio@39: mainFrame.AllFrames = {} Tercio@39: mainFrame.AllButtons = {} Tercio@39: mainFrame.CurrentIndex = 1 Tercio@39: mainFrame.IsContainer = true Tercio@39: mainFrame.ButtonSelectedBorderColor = options_table.button_selected_border_color or {1, 1, 0, 1} Tercio@39: mainFrame.ButtonNotSelectedBorderColor = options_table.button_border_color or {0, 0, 0, 0} Tercio@39: Tercio@39: if (options_table.right_click_interact ~= nil) then Tercio@39: mainFrame.CanCloseWithRightClick = options_table.right_click_interact Tercio@39: else Tercio@39: mainFrame.CanCloseWithRightClick = true Tercio@39: end Tercio@39: Tercio@39: for i, frame in ipairs (frame_list) do Tercio@39: local f = CreateFrame ("frame", "$parent" .. frame.name, mainFrame) Tercio@39: f:SetAllPoints() Tercio@39: f:SetFrameLevel (210) Tercio@39: f:Hide() Tercio@39: Tercio@39: local title = DF:CreateLabel (f, frame.title, 16, "silver") Tercio@39: title:SetPoint ("topleft", mainTitle, "bottomleft", 0, 0) Tercio@39: Tercio@39: local tabButton = DF:CreateButton (mainFrame, DF.TabContainerFunctions.SelectIndex, button_width, button_height, frame.title, i, nil, nil, nil, nil, false, button_tab_template) Tercio@39: tabButton:SetFrameLevel (220) Tercio@39: tabButton.textsize = button_text_size Tercio@39: tabButton.mainFrame = mainFrame Tercio@39: DF.TabContainerFunctions.CreateUnderlineGlow (tabButton) Tercio@39: Tercio@58: local right_click_to_back Tercio@39: if (i == 1) then Tercio@58: right_click_to_back = DF:CreateLabel (f, "right click to close", 10, "gray") Tercio@39: right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) Tercio@39: f.IsFrontPage = true Tercio@39: else Tercio@58: right_click_to_back = DF:CreateLabel (f, "right click to go back to main menu", 10, "gray") Tercio@39: right_click_to_back:SetPoint ("bottomright", f, "bottomright", -1, 0) Tercio@39: end Tercio@39: Tercio@58: if (options_table.hide_click_label) then Tercio@58: right_click_to_back:Hide() Tercio@58: end Tercio@58: Tercio@39: f:SetScript ("OnMouseDown", DF.TabContainerFunctions.OnMouseDown) Tercio@39: f:SetScript ("OnMouseUp", DF.TabContainerFunctions.OnMouseUp) Tercio@39: Tercio@39: tinsert (mainFrame.AllFrames, f) Tercio@39: tinsert (mainFrame.AllButtons, tabButton) Tercio@39: end Tercio@39: Tercio@39: --order buttons Tercio@39: local x = button_anchor_x Tercio@39: local y = button_anchor_y Tercio@39: local space_for_buttons = frame_width - (#frame_list*3) - button_anchor_x Tercio@39: local amount_buttons_per_row = floor (space_for_buttons / button_width) Tercio@39: local last_button = mainFrame.AllButtons[1] Tercio@39: Tercio@39: mainFrame.AllButtons[1]:SetPoint ("topleft", mainTitle, "topleft", x, y) Tercio@39: x = x + button_width + 2 Tercio@39: Tercio@39: for i = 2, #mainFrame.AllButtons do Tercio@39: local button = mainFrame.AllButtons [i] Tercio@39: button:SetPoint ("topleft", mainTitle, "topleft", x, y) Tercio@39: x = x + button_width + 2 Tercio@39: Tercio@39: if (i % amount_buttons_per_row == 0) then Tercio@39: x = button_anchor_x Tercio@39: y = y - button_height - 1 Tercio@39: end Tercio@39: end Tercio@39: Tercio@39: --> when show the frame, reset to the current internal index Tercio@39: mainFrame:SetScript ("OnShow", tab_container_on_show) Tercio@39: --> select the first frame Tercio@39: mainFrame.SelectIndex (mainFrame.AllButtons[1], nil, 1) Tercio@39: Tercio@39: return mainFrame Tercio@39: end Tercio@39: Tercio@39: Tercio@39: Tercio@39: Tercio@39: Tercio@40: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@40: -- ~listbox Tercio@39: Tercio@40: local simple_list_box_ResetWidgets = function (self) Tercio@40: for _, widget in ipairs (self.widgets) do Tercio@40: widget:Hide() Tercio@40: end Tercio@40: self.nextWidget = 1 Tercio@40: end Tercio@39: Tercio@40: local simple_list_box_onenter = function (self, capsule) Tercio@40: self:GetParent().options.onenter (self, capsule, capsule.value) Tercio@40: end Tercio@39: Tercio@40: local simple_list_box_onleave = function (self, capsule) Tercio@40: self:GetParent().options.onleave (self, capsule, capsule.value) Tercio@40: GameTooltip:Hide() Tercio@40: end Tercio@39: Tercio@40: local simple_list_box_GetOrCreateWidget = function (self) Tercio@40: local index = self.nextWidget Tercio@40: local widget = self.widgets [index] Tercio@40: if (not widget) then Tercio@40: widget = DF:CreateButton (self, function()end, self.options.width, self.options.row_height, "", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")) Tercio@40: widget:SetHook ("OnEnter", simple_list_box_onenter) Tercio@40: widget:SetHook ("OnLeave", simple_list_box_onleave) Tercio@40: widget.textcolor = self.options.textcolor Tercio@58: widget.textsize = self.options.text_size Tercio@58: widget.onleave_backdrop = self.options.backdrop_color Tercio@58: Tercio@58: widget.XButton = DF:CreateButton (widget, function()end, 16, 16) Tercio@58: widget.XButton:SetPoint ("topright", widget.widget, "topright") Tercio@58: widget.XButton:SetIcon ([[Interface\BUTTONS\UI-Panel-MinimizeButton-Up]], 16, 16, "overlay", nil, nil, 0, -4, 0, false) Tercio@58: widget.XButton.icon:SetDesaturated (true) Tercio@58: Tercio@58: if (not self.options.show_x_button) then Tercio@58: widget.XButton:Hide() Tercio@58: end Tercio@58: Tercio@40: tinsert (self.widgets, widget) Tercio@40: end Tercio@40: self.nextWidget = self.nextWidget + 1 Tercio@40: return widget Tercio@40: end Tercio@39: Tercio@40: local simple_list_box_RefreshWidgets = function (self) Tercio@40: self:ResetWidgets() Tercio@40: local amt = 0 Tercio@40: for value, _ in pairs (self.list_table) do Tercio@40: local widget = self:GetOrCreateWidget() Tercio@40: widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4) Tercio@40: widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4) Tercio@58: Tercio@40: widget:SetClickFunction (self.func, value) Tercio@58: Tercio@58: if (self.options.show_x_button) then Tercio@58: widget.XButton:SetClickFunction (self.options.x_button_func, value) Tercio@58: widget.XButton.value = value Tercio@58: widget.XButton:Show() Tercio@58: else Tercio@58: widget.XButton:Hide() Tercio@58: end Tercio@58: Tercio@40: widget.value = value Tercio@40: Tercio@40: if (self.options.icon) then Tercio@40: if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then Tercio@58: local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1} Tercio@58: widget:SetIcon (self.options.icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords) Tercio@58: Tercio@40: elseif (type (self.options.icon) == "function") then Tercio@40: local icon = self.options.icon (value) Tercio@40: if (icon) then Tercio@58: local coords = type (self.options.iconcoords) == "table" and self.options.iconcoords or {0, 1, 0, 1} Tercio@58: widget:SetIcon (icon, self.options.row_height - 2, self.options.row_height - 2, "overlay", coords) Tercio@40: end Tercio@40: end Tercio@40: else Tercio@40: widget:SetIcon ("", self.options.row_height, self.options.row_height) Tercio@40: end Tercio@40: Tercio@40: if (self.options.text) then Tercio@40: if (type (self.options.text) == "function") then Tercio@40: local text = self.options.text (value) Tercio@40: if (text) then Tercio@40: widget:SetText (text) Tercio@40: else Tercio@40: widget:SetText ("") Tercio@40: end Tercio@40: else Tercio@40: widget:SetText (self.options.text or "") Tercio@40: end Tercio@40: else Tercio@40: widget:SetText ("") Tercio@40: end Tercio@40: Tercio@40: widget.value = value Tercio@58: Tercio@58: local r, g, b, a = DF:ParseColors (self.options.backdrop_color) Tercio@58: widget:SetBackdropColor (r, g, b, a) Tercio@58: Tercio@40: widget:Show() Tercio@40: amt = amt + 1 Tercio@40: end Tercio@40: if (amt == 0) then Tercio@40: self.EmptyLabel:Show() Tercio@40: else Tercio@40: self.EmptyLabel:Hide() Tercio@40: end Tercio@40: end Tercio@39: Tercio@40: local backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1} Tercio@40: local default_options = { Tercio@40: height = 400, Tercio@40: row_height = 16, Tercio@40: width = 230, Tercio@40: icon = false, Tercio@40: text = "", Tercio@58: text_size = 10, Tercio@40: textcolor = "wheat", Tercio@58: Tercio@58: backdrop_color = {1, 1, 1, .5}, Tercio@58: panel_border_color = {0, 0, 0, 0.5}, Tercio@58: Tercio@40: onenter = function (self, capsule) Tercio@40: if (capsule) then Tercio@40: capsule.textcolor = "white" Tercio@40: end Tercio@40: end, Tercio@40: onleave = function (self, capsule) Tercio@40: if (capsule) then Tercio@40: capsule.textcolor = self:GetParent().options.textcolor Tercio@40: end Tercio@40: GameTooltip:Hide() Tercio@40: end, Tercio@40: } Tercio@39: Tercio@40: local simple_list_box_SetData = function (self, t) Tercio@40: self.list_table = t Tercio@40: end Tercio@40: Tercio@40: function DF:CreateSimpleListBox (parent, name, title, empty_text, list_table, onclick, options) Tercio@40: local f = CreateFrame ("frame", name, parent) Tercio@40: Tercio@40: f.ResetWidgets = simple_list_box_ResetWidgets Tercio@40: f.GetOrCreateWidget = simple_list_box_GetOrCreateWidget Tercio@40: f.Refresh = simple_list_box_RefreshWidgets Tercio@40: f.SetData = simple_list_box_SetData Tercio@40: f.nextWidget = 1 Tercio@40: f.list_table = list_table Tercio@40: f.func = function (self, button, value) Tercio@58: --onclick (value) Tercio@58: DF:QuickDispatch (onclick, value) Tercio@40: f:Refresh() Tercio@40: end Tercio@40: f.widgets = {} Tercio@58: Tercio@58: DF:ApplyStandardBackdrop (f) Tercio@58: Tercio@40: f.options = options or {} Tercio@40: self.table.deploy (f.options, default_options) Tercio@40: Tercio@58: if (f.options.x_button_func) then Tercio@58: local original_X_function = f.options.x_button_func Tercio@58: f.options.x_button_func = function (self, button, value) Tercio@58: DF:QuickDispatch (original_X_function, value) Tercio@58: f:Refresh() Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: f:SetBackdropBorderColor (unpack (f.options.panel_border_color)) Tercio@58: Tercio@40: f:SetSize (f.options.width + 2, f.options.height) Tercio@40: Tercio@40: local name = DF:CreateLabel (f, title, 12, "silver") Tercio@40: name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@40: name:SetPoint ("bottomleft", f, "topleft", 0, 2) Tercio@40: f.Title = name Tercio@40: Tercio@40: local emptyLabel = DF:CreateLabel (f, empty_text, 12, "gray") Tercio@40: emptyLabel:SetAlpha (.6) Tercio@40: emptyLabel:SetSize (f.options.width-10, f.options.height) Tercio@40: emptyLabel:SetPoint ("center", 0, 0) Tercio@40: emptyLabel:Hide() Tercio@40: emptyLabel.align = "center" Tercio@40: f.EmptyLabel = emptyLabel Tercio@40: Tercio@40: return f Tercio@40: end Tercio@40: Tercio@40: Tercio@40: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@40: -- ~scrollbox Tercio@40: Tercio@40: DF.SortFunctions = {} Tercio@40: Tercio@40: local SortMember = "" Tercio@40: local SortByMember = function (t1, t2) Tercio@40: return t1[SortMember] > t2[SortMember] Tercio@40: end Tercio@40: local SortByMemberReverse = function (t1, t2) Tercio@40: return t1[SortMember] < t2[SortMember] Tercio@40: end Tercio@40: Tercio@40: DF.SortFunctions.Sort = function (self, t, by, is_reverse) Tercio@40: SortMember = by Tercio@40: if (not is_reverse) then Tercio@40: table.sort (t, SortByMember) Tercio@40: else Tercio@40: table.sort (t, SortByMemberReverse) Tercio@40: end Tercio@40: end Tercio@40: Tercio@40: Tercio@40: DF.ScrollBoxFunctions = {} Tercio@40: Tercio@40: DF.ScrollBoxFunctions.Refresh = function (self) Tercio@40: for _, frame in ipairs (self.Frames) do Tercio@40: frame:Hide() Tercio@40: frame._InUse = nil Tercio@40: end Tercio@40: Tercio@40: local offset = 0 Tercio@40: if (self.IsFauxScroll) then Tercio@40: FauxScrollFrame_Update (self, #self.data, self.LineAmount, self.LineHeight+1) Tercio@40: offset = FauxScrollFrame_GetOffset (self) Tercio@40: end Tercio@40: Tercio@53: local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, self.LineAmount) Tercio@40: if (not okay) then Tercio@40: error ("Details! FrameWork: Refresh(): " .. totalLines) Tercio@40: end Tercio@40: Tercio@40: for _, frame in ipairs (self.Frames) do Tercio@40: if (not frame._InUse) then Tercio@40: frame:Hide() Tercio@40: else Tercio@40: frame:Show() Tercio@40: end Tercio@40: end Tercio@40: Tercio@40: self:Show() Tercio@40: Tercio@53: if (self.HideScrollBar) then Tercio@53: local frameName = self:GetName() Tercio@53: if (frameName) then Tercio@53: local scrollBar = _G [frameName .. "ScrollBar"] Tercio@53: if (scrollBar) then Tercio@53: scrollBar:Hide() Tercio@53: end Tercio@53: else Tercio@53: Tercio@53: end Tercio@53: Tercio@53: end Tercio@53: Tercio@40: return self.Frames Tercio@40: end Tercio@40: Tercio@40: DF.ScrollBoxFunctions.OnVerticalScroll = function (self, offset) Tercio@40: FauxScrollFrame_OnVerticalScroll (self, offset, self.LineHeight, self.Refresh) Tercio@40: return true Tercio@40: end Tercio@40: Tercio@40: DF.ScrollBoxFunctions.CreateLine = function (self, func) Tercio@53: if (not func) then Tercio@53: func = self.CreateLineFunc Tercio@53: end Tercio@40: local okay, newLine = pcall (func, self, #self.Frames+1) Tercio@40: if (okay) then Tercio@40: tinsert (self.Frames, newLine) Tercio@53: newLine.Index = #self.Frames Tercio@40: return newLine Tercio@40: else Tercio@40: error ("Details! FrameWork: CreateLine(): " .. newLine) Tercio@40: end Tercio@40: end Tercio@40: Tercio@40: DF.ScrollBoxFunctions.GetLine = function (self, line_index) Tercio@40: local line = self.Frames [line_index] Tercio@40: if (line) then Tercio@40: line._InUse = true Tercio@40: end Tercio@40: return line Tercio@40: end Tercio@40: Tercio@40: DF.ScrollBoxFunctions.SetData = function (self, data) Tercio@40: self.data = data Tercio@40: end Tercio@40: DF.ScrollBoxFunctions.GetData = function (self) Tercio@40: return self.data Tercio@40: end Tercio@40: Tercio@53: DF.ScrollBoxFunctions.GetFrames = function (self) Tercio@53: return self.Frames Tercio@53: end Tercio@53: Tercio@53: DF.ScrollBoxFunctions.GetNumFramesCreated = function (self) Tercio@53: return #self.Frames Tercio@53: end Tercio@53: Tercio@53: DF.ScrollBoxFunctions.GetNumFramesShown = function (self) Tercio@53: return self.LineAmount Tercio@53: end Tercio@53: Tercio@53: DF.ScrollBoxFunctions.SetNumFramesShown = function (self, new_amount) Tercio@53: --> hide frames which won't be used Tercio@53: if (new_amount < #self.Frames) then Tercio@53: for i = new_amount+1, #self.Frames do Tercio@53: self.Frames [i]:Hide() Tercio@53: end Tercio@53: end Tercio@53: Tercio@53: --> set the new amount Tercio@53: self.LineAmount = new_amount Tercio@53: end Tercio@53: Tercio@53: DF.ScrollBoxFunctions.SetFramesHeight = function (self, new_height) Tercio@53: self.LineHeight = new_height Tercio@53: self:OnSizeChanged() Tercio@53: self:Refresh() Tercio@53: end Tercio@53: Tercio@53: DF.ScrollBoxFunctions.OnSizeChanged = function (self) Tercio@53: if (self.ReajustNumFrames) then Tercio@53: --> how many lines the scroll can show Tercio@53: local amountOfFramesToShow = floor (self:GetHeight() / self.LineHeight) Tercio@53: Tercio@53: --> how many lines the scroll already have Tercio@53: local totalFramesCreated = self:GetNumFramesCreated() Tercio@53: Tercio@53: --> how many lines are current shown Tercio@53: local totalFramesShown = self:GetNumFramesShown() Tercio@53: Tercio@53: --> the amount of frames increased Tercio@53: if (amountOfFramesToShow > totalFramesShown) then Tercio@53: for i = totalFramesShown+1, amountOfFramesToShow do Tercio@53: --> check if need to create a new line Tercio@53: if (i > totalFramesCreated) then Tercio@53: self:CreateLine (self.CreateLineFunc) Tercio@53: end Tercio@53: end Tercio@53: Tercio@53: --> the amount of frames decreased Tercio@53: elseif (amountOfFramesToShow < totalFramesShown) then Tercio@53: --> hide all frames above the new amount to show Tercio@53: for i = totalFramesCreated, amountOfFramesToShow, -1 do Tercio@53: if (self.Frames [i]) then Tercio@53: self.Frames [i]:Hide() Tercio@53: end Tercio@53: end Tercio@53: end Tercio@53: Tercio@53: --> set the new amount of frames Tercio@53: self:SetNumFramesShown (amountOfFramesToShow) Tercio@53: Tercio@53: --> refresh lines Tercio@53: self:Refresh() Tercio@53: end Tercio@53: end Tercio@53: Tercio@53: function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height, create_line_func, auto_amount, no_scroll) Tercio@40: local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate") Tercio@40: Tercio@58: DF:ApplyStandardBackdrop (scroll) Tercio@58: Tercio@40: scroll:SetSize (width, height) Tercio@40: scroll.LineAmount = line_amount Tercio@40: scroll.LineHeight = line_height Tercio@40: scroll.IsFauxScroll = true Tercio@53: scroll.HideScrollBar = no_scroll Tercio@40: scroll.Frames = {} Tercio@53: scroll.ReajustNumFrames = auto_amount Tercio@53: scroll.CreateLineFunc = create_line_func Tercio@40: Tercio@40: DF:Mixin (scroll, DF.SortFunctions) Tercio@40: DF:Mixin (scroll, DF.ScrollBoxFunctions) Tercio@40: Tercio@40: scroll.refresh_func = refresh_func Tercio@40: scroll.data = data Tercio@40: Tercio@40: scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll) Tercio@53: scroll:SetScript ("OnSizeChanged", DF.ScrollBoxFunctions.OnSizeChanged) Tercio@40: Tercio@40: return scroll Tercio@40: end Tercio@40: Tercio@40: Tercio@53: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@53: -- ~resizers Tercio@40: Tercio@53: function DF:CreateResizeGrips (parent) Tercio@53: if (parent) then Tercio@53: local parentName = parent:GetName() Tercio@53: Tercio@53: local leftResizer = CreateFrame ("button", parentName and parentName .. "LeftResizer" or nil, parent) Tercio@53: local rightResizer = CreateFrame ("button", parentName and parentName .. "RightResizer" or nil, parent) Tercio@53: Tercio@53: leftResizer:SetPoint ("bottomleft", parent, "bottomleft") Tercio@53: rightResizer:SetPoint ("bottomright", parent, "bottomright") Tercio@53: leftResizer:SetSize (16, 16) Tercio@53: rightResizer:SetSize (16, 16) Tercio@53: Tercio@53: rightResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]]) Tercio@53: rightResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]]) Tercio@53: rightResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]]) Tercio@53: leftResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]]) Tercio@53: leftResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]]) Tercio@53: leftResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]]) Tercio@53: Tercio@53: leftResizer:GetNormalTexture():SetTexCoord (1, 0, 0, 1) Tercio@53: leftResizer:GetHighlightTexture():SetTexCoord (1, 0, 0, 1) Tercio@53: leftResizer:GetPushedTexture():SetTexCoord (1, 0, 0, 1) Tercio@53: Tercio@53: return leftResizer, rightResizer Tercio@53: end Tercio@53: end Tercio@58: Tercio@58: Tercio@58: --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@58: -- ~keybind Tercio@58: Tercio@58: Tercio@58: -------------------------------- Tercio@58: --> keybind frame ~key Tercio@58: Tercio@58: Tercio@58: local ignoredKeys = { Tercio@58: ["LSHIFT"] = true, Tercio@58: ["RSHIFT"] = true, Tercio@58: ["LCTRL"] = true, Tercio@58: ["RCTRL"] = true, Tercio@58: ["LALT"] = true, Tercio@58: ["RALT"] = true, Tercio@58: ["UNKNOWN"] = true, Tercio@58: } Tercio@58: Tercio@58: local mouseKeys = { Tercio@58: ["LeftButton"] = "type1", Tercio@58: ["RightButton"] = "type2", Tercio@58: ["MiddleButton"] = "type3", Tercio@58: ["Button4"] = "type4", Tercio@58: ["Button5"] = "type5", Tercio@58: ["Button6"] = "type6", Tercio@58: ["Button7"] = "type7", Tercio@58: ["Button8"] = "type8", Tercio@58: ["Button9"] = "type9", Tercio@58: ["Button10"] = "type10", Tercio@58: ["Button11"] = "type11", Tercio@58: ["Button12"] = "type12", Tercio@58: ["Button13"] = "type13", Tercio@58: ["Button14"] = "type14", Tercio@58: ["Button15"] = "type15", Tercio@58: ["Button16"] = "type16", Tercio@58: } Tercio@58: Tercio@58: local keysToMouse = { Tercio@58: ["type1"] = "LeftButton", Tercio@58: ["type2"] = "RightButton", Tercio@58: ["type3"] = "MiddleButton", Tercio@58: ["type4"] = "Button4", Tercio@58: ["type5"] = "Button5", Tercio@58: ["type6"] = "Button6", Tercio@58: ["type7"] = "Button7", Tercio@58: ["type8"] = "Button8", Tercio@58: ["type9"] = "Button9", Tercio@58: ["type10"] = "Button10", Tercio@58: ["type11"] = "Button11", Tercio@58: ["type12"] = "Button12", Tercio@58: ["type13"] = "Button13", Tercio@58: ["type14"] = "Button14", Tercio@58: ["type15"] = "Button15", Tercio@58: ["type16"] = "Button16", Tercio@58: } Tercio@58: Tercio@58: local keybind_set_data = function (self, new_data_table) Tercio@58: self.Data = new_data_table Tercio@58: self.keybindScroll:UpdateScroll() Tercio@58: end Tercio@58: Tercio@58: function DF:CreateKeybindBox (parent, name, data, callback, width, height, line_amount, line_height) Tercio@58: Tercio@58: local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE") Tercio@58: local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") Tercio@58: local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE") Tercio@58: local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE") Tercio@58: local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE") Tercio@58: Tercio@58: local SCROLL_ROLL_AMOUNT = line_amount Tercio@58: Tercio@58: --keybind set frame Tercio@58: local new_keybind_frame = CreateFrame ("frame", name, parent) Tercio@58: new_keybind_frame:SetSize (width, height) Tercio@58: Tercio@58: -- keybind scrollframe Tercio@58: local keybindScroll = CreateFrame ("scrollframe", "$parentScrollFrame", new_keybind_frame, "FauxScrollFrameTemplate") Tercio@58: keybindScroll:SetSize (1019, 348) Tercio@58: keybindScroll.Frames = {} Tercio@58: new_keybind_frame.keybindScroll = keybindScroll Tercio@58: Tercio@58: --waiting the player to press a key Tercio@58: new_keybind_frame.IsListening = false Tercio@58: Tercio@58: --check for valid data table Tercio@58: if (type (data) ~= "table") then Tercio@58: print ("error: data must be a table. DF > CreateKeybindBox()") Tercio@58: return Tercio@58: end Tercio@58: Tercio@58: if (not next (data)) then Tercio@58: --> build data table for the character class Tercio@58: local _, unitClass = UnitClass ("player") Tercio@58: if (unitClass) then Tercio@58: local specIds = DF:GetClassSpecIDs (unitClass) Tercio@58: if (specIds) then Tercio@58: for _, specId in ipairs (specIds) do Tercio@58: data [specId] = {} Tercio@58: end Tercio@58: end Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: new_keybind_frame.Data = data Tercio@58: new_keybind_frame.SetData = keybind_set_data Tercio@58: Tercio@58: new_keybind_frame.EditingSpec = DF:GetCurrentSpec() Tercio@58: new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [new_keybind_frame.EditingSpec] Tercio@58: Tercio@58: local allSpecButtons = {} Tercio@58: local switch_spec = function (self, button, specID) Tercio@58: new_keybind_frame.EditingSpec = specID Tercio@58: new_keybind_frame.CurrentKeybindEditingSet = new_keybind_frame.Data [specID] Tercio@58: Tercio@58: for _, button in ipairs (allSpecButtons) do Tercio@58: button.selectedTexture:Hide() Tercio@58: end Tercio@58: self.MyObject.selectedTexture:Show() Tercio@58: Tercio@58: --feedback ao jogador uma vez que as keybinds podem ter o mesmo valor Tercio@58: C_Timer.After (.04, function() new_keybind_frame:Hide() end) Tercio@58: C_Timer.After (.06, function() new_keybind_frame:Show() end) Tercio@58: Tercio@58: --atualiza a scroll Tercio@58: keybindScroll:UpdateScroll() Tercio@58: end Tercio@58: Tercio@58: --choose which spec to use Tercio@58: local spec1 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec1 Placeholder Text", 1, _, _, "SpecButton1", _, 0, options_button_template, options_text_template) Tercio@58: local spec2 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec2 Placeholder Text", 1, _, _, "SpecButton2", _, 0, options_button_template, options_text_template) Tercio@58: local spec3 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec3 Placeholder Text", 1, _, _, "SpecButton3", _, 0, options_button_template, options_text_template) Tercio@58: local spec4 = DF:CreateButton (new_keybind_frame, switch_spec, 160, 20, "Spec4 Placeholder Text", 1, _, _, "SpecButton4", _, 0, options_button_template, options_text_template) Tercio@58: Tercio@58: --format the button label and icon with the spec information Tercio@58: local className, class = UnitClass ("player") Tercio@58: local i = 1 Tercio@58: local specIds = DF:GetClassSpecIDs (class) Tercio@58: Tercio@58: for index, specId in ipairs (specIds) do Tercio@58: local button = new_keybind_frame ["SpecButton" .. index] Tercio@58: local spec_id, spec_name, spec_description, spec_icon, spec_background, spec_role, spec_class = GetSpecializationInfoByID (specId) Tercio@58: button.text = spec_name Tercio@58: button:SetClickFunction (switch_spec, specId) Tercio@58: button:SetIcon (spec_icon) Tercio@58: button.specID = specId Tercio@58: Tercio@58: local selectedTexture = button:CreateTexture (nil, "background") Tercio@58: selectedTexture:SetAllPoints() Tercio@58: selectedTexture:SetColorTexture (1, 1, 1, 0.5) Tercio@58: if (specId ~= new_keybind_frame.EditingSpec) then Tercio@58: selectedTexture:Hide() Tercio@58: end Tercio@58: button.selectedTexture = selectedTexture Tercio@58: Tercio@58: tinsert (allSpecButtons, button) Tercio@58: i = i + 1 Tercio@58: end Tercio@58: Tercio@58: local specsTitle = DF:CreateLabel (new_keybind_frame, "Config keys for spec:", 12, "silver") Tercio@58: specsTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 10, mainStartY) Tercio@58: Tercio@58: keybindScroll:SetPoint ("topleft", specsTitle.widget, "bottomleft", 0, -120) Tercio@58: Tercio@58: spec1:SetPoint ("topleft", specsTitle, "bottomleft", 0, -10) Tercio@58: spec2:SetPoint ("topleft", specsTitle, "bottomleft", 0, -30) Tercio@58: spec3:SetPoint ("topleft", specsTitle, "bottomleft", 0, -50) Tercio@58: if (class == "DRUID") then Tercio@58: spec4:SetPoint ("topleft", specsTitle, "bottomleft", 0, -70) Tercio@58: end Tercio@58: Tercio@58: local enter_the_key = CreateFrame ("frame", nil, new_keybind_frame) Tercio@58: enter_the_key:SetFrameStrata ("tooltip") Tercio@58: enter_the_key:SetSize (200, 60) Tercio@58: enter_the_key:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}) Tercio@58: enter_the_key:SetBackdropColor (0, 0, 0, 1) Tercio@58: enter_the_key:SetBackdropBorderColor (1, 1, 1, 1) Tercio@58: enter_the_key.text = DF:CreateLabel (enter_the_key, "- Press a keyboard key to bind.\n- Click to bind a mouse button.\n- Press escape to cancel.", 11, "orange") Tercio@58: enter_the_key.text:SetPoint ("center", enter_the_key, "center") Tercio@58: enter_the_key:Hide() Tercio@58: Tercio@58: local registerKeybind = function (self, key) Tercio@58: if (ignoredKeys [key]) then Tercio@58: return Tercio@58: end Tercio@58: if (key == "ESCAPE") then Tercio@58: enter_the_key:Hide() Tercio@58: new_keybind_frame.IsListening = false Tercio@58: new_keybind_frame:SetScript ("OnKeyDown", nil) Tercio@58: return Tercio@58: end Tercio@58: Tercio@58: local bind = (IsShiftKeyDown() and "SHIFT-" or "") .. (IsControlKeyDown() and "CTRL-" or "") .. (IsAltKeyDown() and "ALT-" or "") Tercio@58: bind = bind .. key Tercio@58: Tercio@58: --adiciona para a tabela de keybinds Tercio@58: local keybind = new_keybind_frame.CurrentKeybindEditingSet [self.keybindIndex] Tercio@58: keybind.key = bind Tercio@58: Tercio@58: new_keybind_frame.IsListening = false Tercio@58: new_keybind_frame:SetScript ("OnKeyDown", nil) Tercio@58: Tercio@58: enter_the_key:Hide() Tercio@58: new_keybind_frame.keybindScroll:UpdateScroll() Tercio@58: Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: Tercio@58: local set_keybind_key = function (self, button, keybindIndex) Tercio@58: if (new_keybind_frame.IsListening) then Tercio@58: key = mouseKeys [button] or button Tercio@58: return registerKeybind (new_keybind_frame, key) Tercio@58: end Tercio@58: new_keybind_frame.IsListening = true Tercio@58: new_keybind_frame.keybindIndex = keybindIndex Tercio@58: new_keybind_frame:SetScript ("OnKeyDown", registerKeybind) Tercio@58: Tercio@58: enter_the_key:Show() Tercio@58: enter_the_key:SetPoint ("bottom", self, "top") Tercio@58: end Tercio@58: Tercio@58: local new_key_bind = function (self, button, specID) Tercio@58: tinsert (new_keybind_frame.CurrentKeybindEditingSet, {key = "-none-", action = "_target", actiontext = ""}) Tercio@58: FauxScrollFrame_SetOffset (new_keybind_frame.keybindScroll, max (#new_keybind_frame.CurrentKeybindEditingSet-SCROLL_ROLL_AMOUNT, 0)) Tercio@58: new_keybind_frame.keybindScroll:UpdateScroll() Tercio@58: end Tercio@58: Tercio@58: local set_action_text = function (keybindIndex, _, text) Tercio@58: local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex] Tercio@58: keybind.actiontext = text Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: Tercio@58: local set_action_on_espace_press = function (textentry, capsule) Tercio@58: capsule = capsule or textentry.MyObject Tercio@58: local keybind = new_keybind_frame.CurrentKeybindEditingSet [capsule.CurIndex] Tercio@58: textentry:SetText (keybind.actiontext) Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: Tercio@58: local lock_textentry = { Tercio@58: ["_target"] = true, Tercio@58: ["_taunt"] = true, Tercio@58: ["_interrupt"] = true, Tercio@58: ["_dispel"] = true, Tercio@58: ["_spell"] = false, Tercio@58: ["_macro"] = false, Tercio@58: } Tercio@58: Tercio@58: local change_key_action = function (self, keybindIndex, value) Tercio@58: local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex] Tercio@58: keybind.action = value Tercio@58: new_keybind_frame.keybindScroll:UpdateScroll() Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: local fill_action_dropdown = function() Tercio@58: Tercio@58: local locClass, class = UnitClass ("player") Tercio@58: Tercio@58: local taunt = "" Tercio@58: local interrupt = "" Tercio@58: local dispel = "" Tercio@58: Tercio@58: if (type (dispel) == "table") then Tercio@58: local dispelString = "\n" Tercio@58: for specID, spellid in pairs (dispel) do Tercio@58: local specid, specName = GetSpecializationInfoByID (specID) Tercio@58: local spellName = GetSpellInfo (spellid) Tercio@58: dispelString = dispelString .. "|cFFE5E5E5" .. specName .. "|r: |cFFFFFFFF" .. spellName .. "\n" Tercio@58: end Tercio@58: dispel = dispelString Tercio@58: else Tercio@58: dispel = "" Tercio@58: end Tercio@58: Tercio@58: return { Tercio@58: --{value = "_target", label = "Target", onclick = change_key_action, desc = "Target the unit"}, Tercio@58: --{value = "_taunt", label = "Taunt", onclick = change_key_action, desc = "Cast the taunt spell for your class\n\n|cFFFFFFFFSpell: " .. taunt}, Tercio@58: --{value = "_interrupt", label = "Interrupt", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. interrupt}, Tercio@58: --{value = "_dispel", label = "Dispel", onclick = change_key_action, desc = "Cast the interrupt spell for your class\n\n|cFFFFFFFFSpell: " .. dispel}, Tercio@58: {value = "_spell", label = "Cast Spell", onclick = change_key_action, desc = "Type the spell name in the text box"}, Tercio@58: {value = "_macro", label = "Run Macro", onclick = change_key_action, desc = "Type your macro in the text box"}, Tercio@58: } Tercio@58: end Tercio@58: Tercio@58: local copy_keybind = function (self, button, keybindIndex) Tercio@58: local keybind = new_keybind_frame.CurrentKeybindEditingSet [keybindIndex] Tercio@58: for specID, t in pairs (new_keybind_frame.Data) do Tercio@58: if (specID ~= new_keybind_frame.EditingSpec) then Tercio@58: local key = CopyTable (keybind) Tercio@58: local specid, specName = GetSpecializationInfoByID (specID) Tercio@58: tinsert (new_keybind_frame.Data [specID], key) Tercio@58: DF:Msg ("Keybind copied to " .. specName) Tercio@58: end Tercio@58: end Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: Tercio@58: local delete_keybind = function (self, button, keybindIndex) Tercio@58: tremove (new_keybind_frame.CurrentKeybindEditingSet, keybindIndex) Tercio@58: new_keybind_frame.keybindScroll:UpdateScroll() Tercio@58: DF:QuickDispatch (callback) Tercio@58: end Tercio@58: Tercio@58: local newTitle = DF:CreateLabel (new_keybind_frame, "Create a new Keybind:", 12, "silver") Tercio@58: newTitle:SetPoint ("topleft", new_keybind_frame, "topleft", 200, mainStartY) Tercio@58: local createNewKeybind = DF:CreateButton (new_keybind_frame, new_key_bind, 160, 20, "New Key Bind", 1, _, _, "NewKeybindButton", _, 0, options_button_template, options_text_template) Tercio@58: createNewKeybind:SetPoint ("topleft", newTitle, "bottomleft", 0, -10) Tercio@58: --createNewKeybind:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]]) Tercio@58: Tercio@58: local update_keybind_list = function (self) Tercio@58: Tercio@58: local keybinds = new_keybind_frame.CurrentKeybindEditingSet Tercio@58: FauxScrollFrame_Update (self, #keybinds, SCROLL_ROLL_AMOUNT, 21) Tercio@58: local offset = FauxScrollFrame_GetOffset (self) Tercio@58: Tercio@58: for i = 1, SCROLL_ROLL_AMOUNT do Tercio@58: local index = i + offset Tercio@58: local f = self.Frames [i] Tercio@58: local data = keybinds [index] Tercio@58: Tercio@58: if (data) then Tercio@58: --index Tercio@58: f.Index.text = index Tercio@58: --keybind Tercio@58: local keyBindText = keysToMouse [data.key] or data.key Tercio@58: Tercio@58: keyBindText = keyBindText:gsub ("type1", "LeftButton") Tercio@58: keyBindText = keyBindText:gsub ("type2", "RightButton") Tercio@58: keyBindText = keyBindText:gsub ("type3", "MiddleButton") Tercio@58: Tercio@58: f.KeyBind.text = keyBindText Tercio@58: f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "left") Tercio@58: f.KeyBind:SetClickFunction (set_keybind_key, index, nil, "right") Tercio@58: --action Tercio@58: f.ActionDrop:SetFixedParameter (index) Tercio@58: f.ActionDrop:Select (data.action) Tercio@58: --action text Tercio@58: f.ActionText.text = data.actiontext Tercio@58: f.ActionText:SetEnterFunction (set_action_text, index) Tercio@58: f.ActionText.CurIndex = index Tercio@58: Tercio@58: if (lock_textentry [data.action]) then Tercio@58: f.ActionText:Disable() Tercio@58: else Tercio@58: f.ActionText:Enable() Tercio@58: end Tercio@58: Tercio@58: --copy Tercio@58: f.Copy:SetClickFunction (copy_keybind, index) Tercio@58: --delete Tercio@58: f.Delete:SetClickFunction (delete_keybind, index) Tercio@58: Tercio@58: f:Show() Tercio@58: else Tercio@58: f:Hide() Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: self:Show() Tercio@58: end Tercio@58: Tercio@58: Tercio@58: Tercio@58: keybindScroll:SetScript ("OnVerticalScroll", function (self, offset) Tercio@58: FauxScrollFrame_OnVerticalScroll (self, offset, 21, update_keybind_list) Tercio@58: end) Tercio@58: keybindScroll.UpdateScroll = update_keybind_list Tercio@58: Tercio@58: local backdropColor = {.3, .3, .3, .3} Tercio@58: local backdropColorOnEnter = {.6, .6, .6, .6} Tercio@58: local on_enter = function (self) Tercio@58: self:SetBackdropColor (unpack (backdropColorOnEnter)) Tercio@58: end Tercio@58: local on_leave = function (self) Tercio@58: self:SetBackdropColor (unpack (backdropColor)) Tercio@58: end Tercio@58: Tercio@58: local font = "GameFontHighlightSmall" Tercio@58: Tercio@58: for i = 1, SCROLL_ROLL_AMOUNT do Tercio@58: local f = CreateFrame ("frame", "$KeyBindFrame" .. i, keybindScroll) Tercio@58: f:SetSize (1009, 20) Tercio@58: f:SetPoint ("topleft", keybindScroll, "topleft", 0, -(i-1)*29) Tercio@58: f:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@58: f:SetBackdropColor (unpack (backdropColor)) Tercio@58: f:SetScript ("OnEnter", on_enter) Tercio@58: f:SetScript ("OnLeave", on_leave) Tercio@58: tinsert (keybindScroll.Frames, f) Tercio@58: Tercio@58: f.Index = DF:CreateLabel (f, "1") Tercio@58: f.KeyBind = DF:CreateButton (f, set_key_bind, 100, 20, "", _, _, _, "SetNewKeybindButton", _, 0, options_button_template, options_text_template) Tercio@58: f.ActionDrop = DF:CreateDropDown (f, fill_action_dropdown, 0, 120, 20, "ActionDropdown", _, options_dropdown_template) Tercio@58: f.ActionText = DF:CreateTextEntry (f, function()end, 660, 20, "TextBox", _, _, options_dropdown_template) Tercio@58: f.Copy = DF:CreateButton (f, copy_keybind, 20, 20, "", _, _, _, "CopyKeybindButton", _, 0, options_button_template, options_text_template) Tercio@58: f.Delete = DF:CreateButton (f, delete_keybind, 16, 20, "", _, _, _, "DeleteKeybindButton", _, 2, options_button_template, options_text_template) Tercio@58: Tercio@58: f.Index:SetPoint ("left", f, "left", 10, 0) Tercio@58: f.KeyBind:SetPoint ("left", f, "left", 43, 0) Tercio@58: f.ActionDrop:SetPoint ("left", f, "left", 150, 0) Tercio@58: f.ActionText:SetPoint ("left", f, "left", 276, 0) Tercio@58: f.Copy:SetPoint ("left", f, "left", 950, 0) Tercio@58: f.Delete:SetPoint ("left", f, "left", 990, 0) Tercio@58: Tercio@58: f.Copy:SetIcon ([[Interface\Buttons\UI-GuildButton-PublicNote-Up]], nil, nil, nil, nil, nil, nil, 4) Tercio@58: f.Delete:SetIcon ([[Interface\Buttons\UI-StopButton]], nil, nil, nil, nil, nil, nil, 4) Tercio@58: Tercio@58: f.Copy.tooltip = "copy this keybind to other specs" Tercio@58: f.Delete.tooltip = "erase this keybind" Tercio@58: Tercio@58: --editbox Tercio@58: f.ActionText:SetJustifyH ("left") Tercio@58: f.ActionText:SetHook ("OnEscapePressed", set_action_on_espace_press) Tercio@58: f.ActionText:SetHook ("OnEditFocusGained", function() Tercio@58: local playerSpells = {} Tercio@58: local tab, tabTex, offset, numSpells = GetSpellTabInfo (2) Tercio@58: for i = 1, numSpells do Tercio@58: local index = offset + i Tercio@58: local spellType, spellId = GetSpellBookItemInfo (index, "player") Tercio@58: if (spellType == "SPELL") then Tercio@58: local spellName = GetSpellInfo (spellId) Tercio@58: tinsert (playerSpells, spellName) Tercio@58: end Tercio@58: end Tercio@58: f.ActionText.WordList = playerSpells Tercio@58: end) Tercio@58: Tercio@58: f.ActionText:SetAsAutoComplete ("WordList") Tercio@58: end Tercio@58: Tercio@58: local header = CreateFrame ("frame", "$parentOptionsPanelFrameHeader", keybindScroll) Tercio@58: header:SetPoint ("bottomleft", keybindScroll, "topleft", 0, 2) Tercio@58: header:SetPoint ("bottomright", keybindScroll, "topright", 0, 2) Tercio@58: header:SetHeight (16) Tercio@58: Tercio@58: header.Index = DF:CreateLabel (header, "Index", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: header.Key = DF:CreateLabel (header, "Key", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: header.Action = DF:CreateLabel (header, "Action", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: header.Macro = DF:CreateLabel (header, "Spell Name / Macro", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: header.Copy = DF:CreateLabel (header, "Copy", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: header.Delete = DF:CreateLabel (header, "Delete", DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) Tercio@58: Tercio@58: header.Index:SetPoint ("left", header, "left", 10, 0) Tercio@58: header.Key:SetPoint ("left", header, "left", 43, 0) Tercio@58: header.Action:SetPoint ("left", header, "left", 150, 0) Tercio@58: header.Macro:SetPoint ("left", header, "left", 276, 0) Tercio@58: header.Copy:SetPoint ("left", header, "left", 950, 0) Tercio@58: header.Delete:SetPoint ("left", header, "left", 990, 0) Tercio@58: Tercio@58: new_keybind_frame:SetScript ("OnShow", function() Tercio@58: Tercio@58: --new_keybind_frame.EditingSpec = EnemyGrid.CurrentSpec Tercio@58: --new_keybind_frame.CurrentKeybindEditingSet = EnemyGrid.CurrentKeybindSet Tercio@58: Tercio@58: for _, button in ipairs (allSpecButtons) do Tercio@58: if (new_keybind_frame.EditingSpec ~= button.specID) then Tercio@58: button.selectedTexture:Hide() Tercio@58: else Tercio@58: button.selectedTexture:Show() Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: keybindScroll:UpdateScroll() Tercio@58: end) Tercio@58: Tercio@58: new_keybind_frame:SetScript ("OnHide", function() Tercio@58: if (new_keybind_frame.IsListening) then Tercio@58: new_keybind_frame.IsListening = false Tercio@58: new_keybind_frame:SetScript ("OnKeyDown", nil) Tercio@58: end Tercio@58: end) Tercio@58: Tercio@58: return new_keybind_frame Tercio@58: end Tercio@58: Tercio@58: function DF:BuildKeybindFunctions (data, prefix) Tercio@58: Tercio@58: --~keybind Tercio@58: local classLoc, class = UnitClass ("player") Tercio@58: local bindingList = data Tercio@58: Tercio@58: local bindString = "self:ClearBindings();" Tercio@58: local bindKeyBindTypeFunc = [[local unitFrame = ...;]] Tercio@58: local bindMacroTextFunc = [[local unitFrame = ...;]] Tercio@58: local isMouseBinding Tercio@58: Tercio@58: for i = 1, #bindingList do Tercio@58: local bind = bindingList [i] Tercio@58: local bindType Tercio@58: Tercio@58: --which button to press Tercio@58: if (bind.key:find ("type")) then Tercio@58: local keyNumber = tonumber (bind.key:match ("%d")) Tercio@58: bindType = keyNumber Tercio@58: isMouseBinding = true Tercio@58: else Tercio@58: bindType = prefix .. "" .. i Tercio@58: bindString = bindString .. "self:SetBindingClick (0, '" .. bind.key .. "', self:GetName(), '" .. bindType .. "');" Tercio@58: bindType = "-" .. prefix .. "" .. i Tercio@58: isMouseBinding = nil Tercio@58: end Tercio@58: Tercio@58: --keybind type Tercio@58: local shift, alt, ctrl = bind.key:match ("SHIFT"), bind.key:match ("ALT"), bind.key:match ("CTRL") Tercio@58: local CommandKeys = alt and alt .. "-" or "" Tercio@58: CommandKeys = ctrl and CommandKeys .. ctrl .. "-" or CommandKeys Tercio@58: CommandKeys = shift and CommandKeys .. shift .. "-" or CommandKeys Tercio@58: Tercio@58: local keyBindType Tercio@58: if (isMouseBinding) then Tercio@58: keyBindType = [[unitFrame:SetAttribute ("@COMMANDtype@BINDTYPE", "macro");]] Tercio@58: else Tercio@58: keyBindType = [[unitFrame:SetAttribute ("type@BINDTYPE", "macro");]] Tercio@58: end Tercio@58: Tercio@58: keyBindType = keyBindType:gsub ("@BINDTYPE", bindType) Tercio@58: keyBindType = keyBindType:gsub ("@COMMAND", CommandKeys) Tercio@58: bindKeyBindTypeFunc = bindKeyBindTypeFunc .. keyBindType Tercio@58: Tercio@58: --spell or macro Tercio@58: if (bind.action == "_spell") then Tercio@58: local macroTextLine Tercio@58: if (isMouseBinding) then Tercio@58: macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]] Tercio@58: else Tercio@58: macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "/cast [@mouseover] @SPELL");]] Tercio@58: end Tercio@58: macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType) Tercio@58: macroTextLine = macroTextLine:gsub ("@SPELL", bind.actiontext) Tercio@58: macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys) Tercio@58: bindMacroTextFunc = bindMacroTextFunc .. macroTextLine Tercio@58: Tercio@58: elseif (bind.action == "_macro") then Tercio@58: local macroTextLine Tercio@58: if (isMouseBinding) then Tercio@58: macroTextLine = [[unitFrame:SetAttribute ("@COMMANDmacrotext@BINDTYPE", "@MACRO");]] Tercio@58: else Tercio@58: macroTextLine = [[unitFrame:SetAttribute ("macrotext@BINDTYPE", "@MACRO");]] Tercio@58: end Tercio@58: macroTextLine = macroTextLine:gsub ("@BINDTYPE", bindType) Tercio@58: macroTextLine = macroTextLine:gsub ("@MACRO", bind.actiontext) Tercio@58: macroTextLine = macroTextLine:gsub ("@COMMAND", CommandKeys) Tercio@58: bindMacroTextFunc = bindMacroTextFunc .. macroTextLine Tercio@58: Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: --~key Tercio@58: local bindTypeFuncLoaded = loadstring (bindKeyBindTypeFunc) Tercio@58: local bindMacroFuncLoaded = loadstring (bindMacroTextFunc) Tercio@58: Tercio@58: if (not bindMacroFuncLoaded or not bindTypeFuncLoaded) then Tercio@58: return Tercio@58: end Tercio@58: Tercio@58: return bindString, bindTypeFuncLoaded, bindMacroFuncLoaded Tercio@58: end Tercio@58: Tercio@58: Tercio@58: function DF:SetKeybindsOnProtectedFrame (frame, bind_string, bind_type_func, bind_macro_func) Tercio@58: Tercio@58: bind_type_func (frame) Tercio@58: bind_macro_func (frame) Tercio@58: frame:SetAttribute ("_onenter", bind_string) Tercio@58: Tercio@58: end Tercio@58: Tercio@58: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@58: -- ~standard backdrop Tercio@58: Tercio@58: function DF:ApplyStandardBackdrop (f, darkTheme, alphaScale) Tercio@58: alphaScale = alphaScale or 1.0 Tercio@58: Tercio@58: if (darkTheme) then Tercio@58: f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Cooldown\cooldown2]], tileSize = 32, tile = true}) Tercio@58: f:SetBackdropBorderColor (0, 0, 0, 1) Tercio@58: f:SetBackdropColor (.54, .54, .54, .54 * alphaScale) Tercio@58: else Tercio@58: f:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@58: f:SetBackdropBorderColor (0, 0, 0, 1) Tercio@58: f:SetBackdropColor (0, 0, 0, 0.2 * alphaScale) Tercio@58: end Tercio@58: Tercio@58: if (not f.__background) then Tercio@58: f.__background = f:CreateTexture (nil, "background") Tercio@58: end Tercio@58: Tercio@58: f.__background:SetColorTexture (0.2317647, 0.2317647, 0.2317647) Tercio@58: f.__background:SetVertexColor (0.27, 0.27, 0.27) Tercio@58: f.__background:SetAlpha (0.8 * alphaScale) Tercio@58: f.__background:SetVertTile (true) Tercio@58: f.__background:SetHorizTile (true) Tercio@58: f.__background:SetAllPoints() Tercio@58: end Tercio@58: Tercio@58: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@58: -- ~title bar Tercio@58: Tercio@58: DF.TitleFunctions = { Tercio@58: Tercio@58: SetTitle = function (self, titleText, titleColor, font, size) Tercio@58: self.TitleLabel:SetText (titleText or self.TitleLabel:GetText()) Tercio@58: Tercio@58: if (titleColor) then Tercio@58: local r, g, b, a = DF:ParseColors (titleColor) Tercio@58: self.TitleLabel:SetTextColor (r, g, b, a) Tercio@58: end Tercio@58: Tercio@58: if (font) then Tercio@58: DF:SetFontFace (self.TitleLabel, font) Tercio@58: end Tercio@58: Tercio@58: if (size) then Tercio@58: DF:SetFontSize (self.TitleLabel, size) Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: Tercio@58: } Tercio@58: Tercio@58: function DF:CreateTitleBar (f, titleText) Tercio@58: Tercio@58: local titleBar = CreateFrame ("frame", f:GetName() and f:GetName() .. "TitleBar" or nil, f) Tercio@58: titleBar:SetPoint ("topleft", f, "topleft", 2, -3) Tercio@58: titleBar:SetPoint ("topright", f, "topright", -2, -3) Tercio@58: titleBar:SetHeight (20) Tercio@58: titleBar:SetBackdrop (SimplePanel_frame_backdrop) --it's an upload from this file Tercio@58: titleBar:SetBackdropColor (.2, .2, .2, 1) Tercio@58: titleBar:SetBackdropBorderColor (0, 0, 0, 1) Tercio@58: Tercio@58: local closeButton = CreateFrame ("button", titleBar:GetName() and titleBar:GetName() .. "CloseButton" or nil, titleBar) Tercio@58: closeButton:SetSize (16, 16) Tercio@58: closeButton:SetNormalTexture (DF.folder .. "icons") Tercio@58: closeButton:SetHighlightTexture (DF.folder .. "icons") Tercio@58: closeButton:SetPushedTexture (DF.folder .. "icons") Tercio@58: closeButton:GetNormalTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@58: closeButton:GetHighlightTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@58: closeButton:GetPushedTexture():SetTexCoord (0, 16/128, 0, 1) Tercio@58: closeButton:SetAlpha (0.7) Tercio@58: closeButton:SetScript ("OnClick", simple_panel_close_click) --upvalue from this file Tercio@58: Tercio@58: local titleLabel = titleBar:CreateFontString (titleBar:GetName() and titleBar:GetName() .. "TitleText" or nil, "overlay", "GameFontNormal") Tercio@58: titleLabel:SetTextColor (.8, .8, .8, 1) Tercio@58: titleLabel:SetText (titleText or "") Tercio@58: Tercio@58: --anchors Tercio@58: closeButton:SetPoint ("right", titleBar, "right", -2, 0) Tercio@58: titleLabel:SetPoint ("center", titleBar, "center") Tercio@58: Tercio@58: --members Tercio@58: f.TitleBar = titleBar Tercio@58: f.CloseButton = closeButton Tercio@58: f.TitleLabel = titleLabel Tercio@58: Tercio@58: DF:Mixin (f, DF.TitleFunctions) Tercio@58: Tercio@58: return titleBar Tercio@58: end Tercio@58: Tercio@58: Tercio@58: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Tercio@58: -- ~icon row Tercio@58: Tercio@58: DF.IconRowFunctions = { Tercio@58: Tercio@58: GetIcon = function (self) Tercio@58: local iconFrame = self.IconPool [self.NextIcon] Tercio@58: Tercio@58: if (not iconFrame) then Tercio@58: local newIconFrame = CreateFrame ("cooldown", "$parentIconCooldown" .. self.NextIcon, self, "CooldownFrameTemplate") Tercio@58: newIconFrame:SetSize (self.options.icon_width, self.options.icon_height) Tercio@58: Tercio@58: newIconFrame.Texture = newIconFrame:CreateTexture (nil, "background") Tercio@58: newIconFrame.Texture:SetAllPoints() Tercio@58: Tercio@58: newIconFrame.Text = newIconFrame:CreateFontString (nil, "overlay", "GameFontNormal") Tercio@58: newIconFrame.Text:SetPoint ("center") Tercio@58: newIconFrame.Text:Hide() Tercio@58: Tercio@58: newIconFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}) Tercio@58: newIconFrame:SetBackdropBorderColor (0, 0, 0, 0) Tercio@58: newIconFrame:EnableMouse (false) Tercio@58: Tercio@58: self.IconPool [self.NextIcon] = newIconFrame Tercio@58: iconFrame = newIconFrame Tercio@58: end Tercio@58: Tercio@58: iconFrame:ClearAllPoints() Tercio@58: Tercio@58: local anchor = self.options.anchor Tercio@58: local anchorTo = self.NextIcon == 1 and self or self.IconPool [self.NextIcon - 1] Tercio@58: local xPadding = self.NextIcon == 1 and self.options.left_padding or self.options.icon_padding Tercio@58: local growDirection = self.options.grow_direction Tercio@58: Tercio@58: if (growDirection == 1) then --grow to right Tercio@58: if (self.NextIcon == 1) then Tercio@58: iconFrame:SetPoint ("left", anchorTo, "left", xPadding, 0) Tercio@58: else Tercio@58: iconFrame:SetPoint ("left", anchorTo, "right", xPadding, 0) Tercio@58: end Tercio@58: Tercio@58: elseif (growDirection == 2) then --grow to left Tercio@58: if (self.NextIcon == 1) then Tercio@58: iconFrame:SetPoint ("right", anchorTo, "right", xPadding, 0) Tercio@58: else Tercio@58: iconFrame:SetPoint ("right", anchorTo, "left", xPadding, 0) Tercio@58: end Tercio@58: Tercio@58: end Tercio@58: Tercio@58: DF:SetFontColor (iconFrame.Text, self.options.text_color) Tercio@58: Tercio@58: self.NextIcon = self.NextIcon + 1 Tercio@58: return iconFrame Tercio@58: end, Tercio@58: Tercio@58: SetIcon = function (self, spellId, borderColor, startTime, duration) Tercio@58: local spellName, _, spellIcon = GetSpellInfo (spellId) Tercio@58: Tercio@58: if (spellIcon) then Tercio@58: local iconFrame = self:GetIcon() Tercio@58: iconFrame.Texture:SetTexture (spellIcon) Tercio@58: iconFrame.Texture:SetTexCoord (unpack (self.options.texcoord)) Tercio@58: Tercio@58: if (borderColor) then Tercio@58: iconFrame:SetBackdropBorderColor (Plater:ParseColors (borderColor)) Tercio@58: else Tercio@58: iconFrame:SetBackdropBorderColor (0, 0, 0 ,0) Tercio@58: end Tercio@58: Tercio@58: if (startTime) then Tercio@58: CooldownFrame_Set (iconFrame, startTime, duration, true, true) Tercio@58: Tercio@58: if (self.options.show_text) then Tercio@58: iconFrame.Text:Show() Tercio@58: iconFrame.Text:SetText (floor (startTime + duration - GetTime())) Tercio@58: else Tercio@58: iconFrame.Text:Hide() Tercio@58: end Tercio@58: else Tercio@58: iconFrame.Text:Hide() Tercio@58: end Tercio@58: Tercio@58: iconFrame:Show() Tercio@58: Tercio@58: --> update the size of the frame Tercio@58: self:SetWidth ((self.options.left_padding * 2) + (self.options.icon_padding * (self.NextIcon-2)) + (self.options.icon_width * (self.NextIcon - 1))) Tercio@58: Tercio@58: --> show the frame Tercio@58: self:Show() Tercio@58: Tercio@58: return iconFrame Tercio@58: end Tercio@58: end, Tercio@58: Tercio@58: ClearIcons = function (self) Tercio@58: for i = 1, self.NextIcon -1 do Tercio@58: self.IconPool [i]:Hide() Tercio@58: end Tercio@58: self.NextIcon = 1 Tercio@58: self:Hide() Tercio@58: end, Tercio@58: Tercio@58: GetIconGrowDirection = function (self) Tercio@58: local side = self.options.anchor.side Tercio@58: Tercio@58: if (side == 1) then Tercio@58: return 1 Tercio@58: elseif (side == 2) then Tercio@58: return 2 Tercio@58: elseif (side == 3) then Tercio@58: return 1 Tercio@58: elseif (side == 4) then Tercio@58: return 1 Tercio@58: elseif (side == 5) then Tercio@58: return 2 Tercio@58: elseif (side == 6) then Tercio@58: return 1 Tercio@58: elseif (side == 7) then Tercio@58: return 2 Tercio@58: elseif (side == 8) then Tercio@58: return 1 Tercio@58: elseif (side == 9) then Tercio@58: return 1 Tercio@58: elseif (side == 10) then Tercio@58: return 1 Tercio@58: elseif (side == 11) then Tercio@58: return 2 Tercio@58: elseif (side == 12) then Tercio@58: return 1 Tercio@58: elseif (side == 13) then Tercio@58: return 1 Tercio@58: end Tercio@58: end Tercio@58: } Tercio@58: Tercio@58: local default_icon_row_options = { Tercio@58: icon_width = 20, Tercio@58: icon_height = 20, Tercio@58: texcoord = {.1, .9, .1, .9}, Tercio@58: show_text = true, Tercio@58: text_color = {1, 1, 1, 1}, Tercio@58: left_padding = 2, --distance between right and left Tercio@58: top_padding = 2, --distance between top and bottom Tercio@58: icon_padding = 2, --distance between each icon Tercio@58: backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}, Tercio@58: backdrop_color = {0, 0, 0, 0.5}, Tercio@58: backdrop_border_color = {0, 0, 0, 1}, Tercio@58: anchor = {side = 6, x = 2, y = 0}, Tercio@58: grow_direction = 1, --1 = to right 2 = to left Tercio@58: } Tercio@58: Tercio@58: function DF:CreateIconRow (parent, name, options) Tercio@58: local f = CreateFrame ("frame", name, parent) Tercio@58: f.IconPool = {} Tercio@58: f.NextIcon = 1 Tercio@58: Tercio@58: DF:Mixin (f, DF.IconRowFunctions) Tercio@58: DF:Mixin (f, DF.OptionsFunctions) Tercio@58: Tercio@58: f:BuildOptionsTable (default_icon_row_options, options) Tercio@58: Tercio@58: f:SetSize (f.options.icon_width, f.options.icon_height + (f.options.top_padding * 2)) Tercio@58: f:SetBackdrop (f.options.backdrop) Tercio@58: f:SetBackdropColor (unpack (f.options.backdrop_color)) Tercio@58: f:SetBackdropBorderColor (unpack (f.options.backdrop_border_color)) Tercio@58: Tercio@58: return f Tercio@58: end