Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@11: local _ Tercio@11: 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: local _string_len = string.len --> lua local Tercio@11: Tercio@11: local cleanfunction = function() end Tercio@11: local APIDropDownFunctions = false Tercio@11: local DropDownMetaFunctions = {} Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> metatables Tercio@11: Tercio@11: DropDownMetaFunctions.__call = function (_table, value) Tercio@11: --> unknow Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> members Tercio@11: Tercio@11: --> selected value Tercio@11: local gmember_value = function (_object) Tercio@11: return _object:GetValue() Tercio@11: end 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: --> frame width Tercio@11: local gmember_width = function (_object) Tercio@11: return _object.button:GetWidth() Tercio@11: end Tercio@11: --> frame height Tercio@11: local gmember_height = function (_object) Tercio@11: return _object.button:GetHeight() Tercio@11: end Tercio@11: --> current text Tercio@11: local gmember_text = function (_object) Tercio@11: return _object.label:GetText() Tercio@11: end Tercio@11: --> menu creation function Tercio@11: local gmember_function = function (_object) Tercio@11: return _object:GetFunction() Tercio@11: end Tercio@11: --> menu width Tercio@11: local gmember_menuwidth = function (_object) Tercio@11: return _rawget (self, "realsizeW") Tercio@11: end Tercio@11: --> menu height Tercio@11: local gmember_menuheight = function (_object) Tercio@11: return _rawget (self, "realsizeH") Tercio@11: end Tercio@11: Tercio@11: local get_members_function_index = { Tercio@11: ["value"] = gmember_value, Tercio@11: ["text"] = gmember_text, Tercio@11: ["shown"] = gmember_shown, Tercio@11: ["width"] = gmember_width, Tercio@11: ["menuwidth"] = gmember_menuwidth, Tercio@11: ["height"] = gmember_height, Tercio@11: ["menuheight"] = gmember_menuheight, Tercio@11: ["tooltip"] = gmember_tooltip, Tercio@11: ["func"] = gmember_function, Tercio@11: } Tercio@11: Tercio@11: DropDownMetaFunctions.__index = function (_table, _member_requested) Tercio@11: Tercio@11: local func = get_members_function_index [_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 DropDownMetaFunctions [_member_requested] Tercio@11: end Tercio@11: 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: --> frame width Tercio@11: local smember_width = function (_object, _value) Tercio@11: return _object.dropdown:SetWidth (_value) Tercio@11: end Tercio@11: --> frame height Tercio@11: local smember_height = function (_object, _value) Tercio@11: return _object.dropdown:SetHeight (_value) Tercio@11: end Tercio@11: --> menu creation function Tercio@11: local smember_function = function (_object, _value) Tercio@11: return _object:SetFunction (_value) Tercio@11: end Tercio@11: --> menu width Tercio@11: local smember_menuwidth = function (_object, _value) Tercio@11: _object:SetMenuSize (_value, nil) Tercio@11: end Tercio@11: --> menu height Tercio@11: local smember_menuheight = function (_object, _value) Tercio@11: _object:SetMenuSize (nil, _value) Tercio@11: end Tercio@11: Tercio@11: local set_members_function_index = { Tercio@11: ["tooltip"] = smember_tooltip, Tercio@11: ["show"] = smember_show, Tercio@11: ["hide"] = smember_hide, Tercio@11: ["width"] = smember_width, Tercio@11: ["menuwidth"] = smember_menuwidth, Tercio@11: ["height"] = smember_height, Tercio@11: ["menuheight"] = smember_menuheight, Tercio@11: ["func"] = smember_function, Tercio@11: } Tercio@11: Tercio@11: DropDownMetaFunctions.__newindex = function (_table, _key, _value) Tercio@11: local func = set_members_function_index [_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: function DropDownMetaFunctions:IsShown() Tercio@11: return self.dropdown:IsShown() Tercio@11: end Tercio@11: function DropDownMetaFunctions:Show() Tercio@11: return self.dropdown:Show() Tercio@11: end Tercio@11: function DropDownMetaFunctions:Hide() Tercio@11: return self.dropdown:Hide() Tercio@11: end Tercio@11: Tercio@11: --> menu width and height Tercio@11: function DropDownMetaFunctions:SetMenuSize (w, h) Tercio@11: if (w) then Tercio@11: return _rawset (self, "realsizeW", w) Tercio@11: end Tercio@11: if (h) then Tercio@11: return _rawset (self, "realsizeH", h) Tercio@11: end Tercio@11: end Tercio@11: function DropDownMetaFunctions:GetMenuSize() Tercio@11: return _rawget (self, "realsizeW"), _rawget (self, "realsizeH") Tercio@11: end Tercio@11: Tercio@11: --> function Tercio@11: function DropDownMetaFunctions:SetFunction (func) Tercio@11: return _rawset (self, "func", func) Tercio@11: end Tercio@11: function DropDownMetaFunctions:GetFunction() Tercio@11: return _rawget (self, "func") Tercio@11: end Tercio@11: Tercio@11: --> value Tercio@11: function DropDownMetaFunctions:GetValue() Tercio@11: return _rawget (self, "myvalue") Tercio@11: end Tercio@11: function DropDownMetaFunctions:SetValue (value) Tercio@11: return _rawset (self, "myvalue", value) Tercio@11: end Tercio@11: Tercio@11: --> setpoint Tercio@11: function DropDownMetaFunctions: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 DropDownMetaFunctions:SetSize (w, h) Tercio@11: if (w) then Tercio@11: self.dropdown:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: return self.dropdown:SetHeight (h) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: --> tooltip Tercio@11: function DropDownMetaFunctions: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 DropDownMetaFunctions:GetTooltip() Tercio@11: return _rawget (self, "have_tooltip") Tercio@11: end Tercio@11: Tercio@11: --> frame levels Tercio@11: function DropDownMetaFunctions:GetFrameLevel() Tercio@11: return self.dropdown:GetFrameLevel() Tercio@11: end Tercio@11: function DropDownMetaFunctions:SetFrameLevel (level, frame) Tercio@11: if (not frame) then Tercio@11: return self.dropdown:SetFrameLevel (level) Tercio@11: else Tercio@11: local framelevel = frame:GetFrameLevel (frame) + level Tercio@11: return self.dropdown:SetFrameLevel (framelevel) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: --> frame stratas Tercio@11: function DropDownMetaFunctions:GetFrameStrata() Tercio@11: return self.dropdown:GetFrameStrata() Tercio@11: end Tercio@11: function DropDownMetaFunctions:SetFrameStrata (strata) Tercio@11: if (_type (strata) == "table") then Tercio@11: self.dropdown:SetFrameStrata (strata:GetFrameStrata()) Tercio@11: else Tercio@11: self.dropdown:SetFrameStrata (strata) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: --> enabled Tercio@11: function DropDownMetaFunctions:IsEnabled() Tercio@11: return self.dropdown:IsEnabled() Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Enable() Tercio@11: Tercio@11: self:SetAlpha (1) Tercio@11: _rawset (self, "lockdown", false) Tercio@11: Tercio@11: if (self.OnEnable) then Tercio@11: self.OnEnable (self) Tercio@11: end Tercio@11: --return self.dropdown:Enable() Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Disable() Tercio@11: Tercio@11: self:SetAlpha (.4) Tercio@11: _rawset (self, "lockdown", true) Tercio@11: Tercio@11: if (self.OnDisable) then Tercio@11: self.OnDisable (self) Tercio@11: end Tercio@11: --return self.dropdown:Disable() Tercio@11: end Tercio@11: Tercio@11: --> fixed value Tercio@11: function DropDownMetaFunctions:SetFixedParameter (value) Tercio@11: _rawset (self, "FixedValue", value) Tercio@11: end Tercio@11: Tercio@11: --> hooks Tercio@11: function DropDownMetaFunctions:SetHook (hookType, func) Tercio@11: if (func) then Tercio@11: _rawset (self, hookType.."Hook", func) Tercio@11: else Tercio@11: _rawset (self, hookType.."Hook", nil) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> scripts Tercio@11: Tercio@11: local last_opened = false Tercio@11: Tercio@11: local function isOptionVisible (thisOption) Tercio@11: if (_type (thisOption.shown) == "boolean" or _type (thisOption.shown) == "function") then Tercio@11: if (not thisOption.shown) then Tercio@11: return false Tercio@11: elseif (not thisOption.shown()) then Tercio@11: return false Tercio@11: end Tercio@11: end Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Refresh() Tercio@11: local menu = self.func() Tercio@11: Tercio@11: if (#menu == 0) then Tercio@11: self:NoOption (true) Tercio@11: self.no_options = true Tercio@11: return false Tercio@11: Tercio@11: elseif (self.no_options) then Tercio@11: self.no_options = false Tercio@11: self:NoOption (false) Tercio@11: self:NoOptionSelected() Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:NoOptionSelected() Tercio@11: self.label:SetText (self.empty_text or "no option selected") Tercio@11: self.label:SetTextColor (1, 1, 1, 0.4) Tercio@11: if (self.empty_icon) then Tercio@11: self.icon:SetTexture (self.empty_icon) Tercio@11: else Tercio@11: self.icon:SetTexture ([[Interface\COMMON\UI-ModelControlPanel]]) Tercio@11: self.icon:SetTexCoord (0.625, 0.78125, 0.328125, 0.390625) Tercio@11: end Tercio@11: self.icon:SetVertexColor (1, 1, 1, 0.4) Tercio@11: Tercio@11: self.last_select = nil Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:NoOption (state) Tercio@11: if (state) then Tercio@11: self:Disable() Tercio@11: self:SetAlpha (0.5) Tercio@11: self.no_options = true Tercio@11: self.label:SetText ("no options") Tercio@11: self.label:SetTextColor (1, 1, 1, 0.4) Tercio@11: self.icon:SetTexture ([[Interface\CHARACTERFRAME\UI-Player-PlayTimeUnhealthy]]) Tercio@11: self.icon:SetTexCoord (0, 1, 0, 1) Tercio@11: self.icon:SetVertexColor (1, 1, 1, 0.4) Tercio@11: else Tercio@11: self.no_options = false Tercio@11: self:Enable() Tercio@11: self:SetAlpha (1) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Select (optionName, byOptionNumber) Tercio@11: Tercio@11: if (type (optionName) == "boolean" and not optionName) then Tercio@11: self:NoOptionSelected() Tercio@11: return false Tercio@11: end Tercio@11: Tercio@11: local menu = self.func() Tercio@11: Tercio@11: if (#menu == 0) then Tercio@11: self:NoOption (true) Tercio@11: return true Tercio@11: else Tercio@11: self:NoOption (false) Tercio@11: end Tercio@11: Tercio@11: if (byOptionNumber and type (optionName) == "number") then Tercio@11: if (not menu [optionName]) then --> invalid index Tercio@11: self:NoOptionSelected() Tercio@11: return false Tercio@11: end Tercio@11: self:Selected (menu [optionName]) Tercio@11: return true Tercio@11: end Tercio@11: Tercio@11: for _, thisMenu in ipairs (menu) do Tercio@11: if ( ( thisMenu.label == optionName or thisMenu.value == optionName ) and isOptionVisible (thisMenu)) then Tercio@11: self:Selected (thisMenu) Tercio@11: return true Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: return false Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:SetEmptyTextAndIcon (text, icon) Tercio@11: if (text) then Tercio@11: self.empty_text = text Tercio@11: end Tercio@11: if (icon) then Tercio@11: self.empty_icon = icon Tercio@11: end Tercio@11: Tercio@11: self:Selected (self.last_select) Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Selected (_table) Tercio@11: Tercio@11: if (not _table) then Tercio@11: Tercio@11: --> there is any options? Tercio@11: if (not self:Refresh()) then Tercio@11: self.last_select = nil Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: --> exists options but none selected Tercio@11: self:NoOptionSelected() Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: self.last_select = _table Tercio@11: self:NoOption (false) Tercio@11: Tercio@11: self.label:SetText (_table.label) Tercio@11: self.icon:SetTexture (_table.icon) Tercio@11: Tercio@11: if (_table.icon) then Tercio@11: self.label:SetPoint ("left", self.icon, "right", 2, 0) Tercio@11: if (_table.texcoord) then Tercio@11: self.icon:SetTexCoord (unpack (_table.texcoord)) Tercio@11: else Tercio@11: self.icon:SetTexCoord (0, 1, 0, 1) Tercio@11: end Tercio@11: Tercio@11: if (_table.iconcolor) then Tercio@11: if (type (_table.iconcolor) == "string") then Tercio@11: self.icon:SetVertexColor (DF:ParseColors (_table.iconcolor)) Tercio@11: else Tercio@11: self.icon:SetVertexColor (unpack (_table.iconcolor)) Tercio@11: end Tercio@11: else Tercio@11: self.icon:SetVertexColor (1, 1, 1, 1) Tercio@11: end Tercio@11: Tercio@11: else Tercio@11: self.label:SetPoint ("left", self.label:GetParent(), "left", 4, 0) Tercio@11: end Tercio@11: Tercio@11: self.statusbar:SetTexture (_table.statusbar) Tercio@11: Tercio@11: if (_table.color) then Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) Tercio@11: self.label:SetTextColor (_value1, _value2, _value3, _value4) Tercio@11: else Tercio@11: self.label:SetTextColor (1, 1, 1, 1) Tercio@11: end Tercio@11: Tercio@11: if (_table.font) then Tercio@11: self.label:SetFont (_table.font, 10) Tercio@11: else Tercio@11: self.label:SetFont ("GameFontHighlightSmall", 10) Tercio@11: end Tercio@11: Tercio@11: self:SetValue (_table.value) Tercio@11: Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOptionClick (button) Tercio@11: Tercio@11: --> update name and icon on main frame Tercio@11: button.object:Selected (button.table) Tercio@11: Tercio@11: --> close menu frame Tercio@11: button.object:Close() Tercio@11: Tercio@11: --> exec function if any Tercio@11: if (button.table.onclick) then Tercio@11: button.table.onclick (button:GetParent():GetParent():GetParent().MyObject, button.object.FixedValue, button.table.value) Tercio@11: end Tercio@11: Tercio@11: --> set the value of selected option in main object Tercio@11: button.object.myvalue = button.table.value Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Open() Tercio@11: self.dropdown.dropdownframe:Show() Tercio@11: self.dropdown.dropdownborder:Show() Tercio@11: self.dropdown.arrowTexture:SetTexture ("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down") Tercio@11: self.opened = true Tercio@11: if (last_opened) then Tercio@11: last_opened:Close() Tercio@11: end Tercio@11: last_opened = self Tercio@11: end Tercio@11: Tercio@11: function DropDownMetaFunctions:Close() Tercio@11: --> when menu is being close, just hide the border and the script will call back this again Tercio@11: if (self.dropdown.dropdownborder:IsShown()) then Tercio@11: self.dropdown.dropdownborder:Hide() Tercio@11: return Tercio@11: end Tercio@11: self.dropdown.dropdownframe:Hide() Tercio@11: self.dropdown.arrowTexture:SetTexture ("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up") Tercio@11: Tercio@11: local selectedTexture = _G [self:GetName() .. "_ScrollFrame_ScrollChild_SelectedTexture"] Tercio@11: selectedTexture:Hide() Tercio@11: Tercio@11: self.opened = false Tercio@11: last_opened = false Tercio@11: end Tercio@11: Tercio@11: --> close by escape key Tercio@11: function DetailsFrameworkDropDownOptionsFrameOnHide (frame) Tercio@11: frame:GetParent().MyObject:Close() Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOptionOnEnter (frame) Tercio@11: if (frame.table.desc) then Tercio@17: GameCooltip2:Preset (2) Tercio@11: GameCooltip2:AddLine (frame.table.desc) Tercio@11: if (frame.table.descfont) then Tercio@11: GameCooltip2:SetOption ("TextFont", frame.table.descfont) Tercio@11: end Tercio@11: Tercio@11: GameCooltip2:SetHost (frame, "topleft", "topright", 10, 0) Tercio@11: Tercio@11: GameCooltip2:ShowCooltip (nil, "tooltip") Tercio@11: frame.tooltip = true Tercio@11: end Tercio@11: frame:GetParent().mouseover:SetPoint ("left", frame) Tercio@11: frame:GetParent().mouseover:Show() Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOptionOnLeave (frame) Tercio@11: if (frame.table.desc) then Tercio@11: GameCooltip2:ShowMe (false) Tercio@11: end Tercio@11: frame:GetParent().mouseover:Hide() Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnMouseDown (button) Tercio@11: Tercio@11: local object = button.MyObject Tercio@11: Tercio@11: if (not object.opened and not _rawget (object, "lockdown")) then --> click to open Tercio@11: Tercio@11: local menu = object:func() Tercio@11: object.builtMenu = menu Tercio@11: Tercio@11: local frame_witdh = object.realsizeW Tercio@11: Tercio@11: if (menu [1]) then Tercio@11: --> build menu Tercio@11: Tercio@11: local scrollFrame = _G [button:GetName() .. "_ScrollFrame"] Tercio@11: local scrollChild = _G [button:GetName() .. "_ScrollFrame_ScrollChild"] Tercio@11: local scrollBorder = _G [button:GetName() .. "_Border"] Tercio@11: local selectedTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_SelectedTexture"] Tercio@11: local mouseOverTexture = _G [button:GetName() .. "_ScrollFrame_ScrollChild_MouseOverTexture"] Tercio@11: Tercio@11: local i = 1 Tercio@11: local showing = 0 Tercio@11: local currentText = button.text:GetText() or "" Tercio@11: Tercio@11: if (object.OnMouseDownHook) then Tercio@11: local interrupt = object.OnMouseDownHook (button, buttontype, menu, scrollFrame, scrollChild, selectedTexture) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: for _, _table in ipairs (menu) do Tercio@11: Tercio@11: local show = isOptionVisible (_table) Tercio@11: Tercio@11: if (show) then Tercio@11: local _this_row = object.menus [i] Tercio@11: showing = showing + 1 Tercio@11: Tercio@11: if (not _this_row) then Tercio@11: Tercio@11: local name = button:GetName() .. "Row" .. i Tercio@11: local parent = scrollChild Tercio@11: Tercio@11: _this_row = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownOptionTemplate") Tercio@11: local anchor_i = i-1 Tercio@11: _this_row:SetPoint ("topleft", parent, "topleft", 5, (-anchor_i*20)-5) Tercio@11: _this_row:SetPoint ("topright", parent, "topright", -5, (-anchor_i*20)-5) Tercio@11: _this_row.object = object Tercio@11: object.menus [i] = _this_row Tercio@11: end Tercio@11: Tercio@11: _this_row.icon:SetTexture (_table.icon) Tercio@11: if (_table.icon) then Tercio@11: Tercio@11: _this_row.label:SetPoint ("left", _this_row.icon, "right", 5, 0) Tercio@11: Tercio@11: if (_table.texcoord) then Tercio@11: _this_row.icon:SetTexCoord (unpack (_table.texcoord)) Tercio@11: else Tercio@11: _this_row.icon:SetTexCoord (0, 1, 0, 1) Tercio@11: end Tercio@11: Tercio@11: if (_table.iconcolor) then Tercio@11: if (type (_table.iconcolor) == "string") then Tercio@11: _this_row.icon:SetVertexColor (DF:ParseColors (_table.iconcolor)) Tercio@11: else Tercio@11: _this_row.icon:SetVertexColor (unpack (_table.iconcolor)) Tercio@11: end Tercio@11: else Tercio@11: _this_row.icon:SetVertexColor (1, 1, 1, 1) Tercio@11: end Tercio@11: else Tercio@11: _this_row.label:SetPoint ("left", _this_row.statusbar, "left", 2, 0) Tercio@11: end Tercio@11: Tercio@11: if (_table.iconsize) then Tercio@11: _this_row.icon:SetSize (_table.iconsize[1], _table.iconsize[2]) Tercio@11: else Tercio@11: _this_row.icon:SetSize (20, 20) Tercio@11: end Tercio@11: Tercio@11: if (_table.font) then Tercio@11: _this_row.label:SetFont (_table.font, 10.5) Tercio@11: else Tercio@11: _this_row.label:SetFont ("GameFontHighlightSmall", 10.5) Tercio@11: end Tercio@11: Tercio@11: _this_row.statusbar:SetTexture (_table.statusbar) Tercio@11: _this_row.label:SetText (_table.label) Tercio@11: Tercio@11: if (currentText and currentText == _table.label) then Tercio@11: if (_table.icon) then Tercio@11: selectedTexture:SetPoint ("left", _this_row.icon, "left", -3, 0) Tercio@11: else Tercio@11: selectedTexture:SetPoint ("left", _this_row.statusbar, "left", 0, 0) Tercio@11: end Tercio@11: Tercio@11: selectedTexture:Show() Tercio@11: selectedTexture:SetVertexColor (1, 1, 1, .3); Tercio@11: currentText = nil Tercio@11: end Tercio@11: Tercio@11: if (_table.color) then Tercio@11: local _value1, _value2, _value3, _value4 = DF:ParseColors (_table.color) Tercio@11: _this_row.label:SetTextColor (_value1, _value2, _value3, _value4) Tercio@11: else Tercio@11: _this_row.label:SetTextColor (1, 1, 1, 1) Tercio@11: end Tercio@11: Tercio@11: _this_row.table = _table Tercio@11: Tercio@11: local labelwitdh = _this_row.label:GetStringWidth() Tercio@11: if (labelwitdh+40 > frame_witdh) then Tercio@11: frame_witdh = labelwitdh+40 Tercio@11: end Tercio@11: _this_row:Show() Tercio@11: Tercio@11: i = i + 1 Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: if (currentText) then Tercio@11: selectedTexture:Hide() Tercio@11: else Tercio@11: selectedTexture:SetWidth (frame_witdh-20) Tercio@11: end Tercio@11: Tercio@11: for i = showing+1, #object.menus do Tercio@11: object.menus [i]:Hide() Tercio@11: end Tercio@11: Tercio@11: local size = object.realsizeH Tercio@11: Tercio@11: if (showing*20 > size) then Tercio@11: --show scrollbar and setup scroll Tercio@11: object:ShowScroll() Tercio@11: scrollFrame:EnableMouseWheel (true) Tercio@11: object.scroll:Altura (size-35) Tercio@11: object.scroll:SetMinMaxValues (0, (showing*20) - size + 20) Tercio@11: --width Tercio@11: scrollBorder:SetWidth (frame_witdh+20) Tercio@11: scrollFrame:SetWidth (frame_witdh+20) Tercio@11: scrollChild:SetWidth (frame_witdh+20) Tercio@11: --height Tercio@11: scrollBorder:SetHeight (size+20) Tercio@11: scrollFrame:SetHeight (size) Tercio@11: scrollChild:SetHeight ((showing*20)+20) Tercio@11: --mouse over texture Tercio@11: mouseOverTexture:SetWidth (frame_witdh-7) Tercio@11: --selected Tercio@11: selectedTexture:SetWidth (frame_witdh - 9) Tercio@11: Tercio@11: for index, row in ipairs (object.menus) do Tercio@11: row:SetPoint ("topright", scrollChild, "topright", -22, ((-index-1)*20)-5) Tercio@11: end Tercio@11: Tercio@11: else Tercio@11: --hide scrollbar and disable wheel Tercio@11: object:HideScroll() Tercio@11: scrollFrame:EnableMouseWheel (false) Tercio@11: --width Tercio@11: scrollBorder:SetWidth (frame_witdh) Tercio@11: scrollFrame:SetWidth (frame_witdh) Tercio@11: scrollChild:SetWidth (frame_witdh) Tercio@11: --height Tercio@11: scrollBorder:SetHeight ((showing*20) + 25) Tercio@11: scrollFrame:SetHeight ((showing*20) + 25) Tercio@11: --mouse over texture Tercio@11: mouseOverTexture:SetWidth (frame_witdh-10) Tercio@11: --selected Tercio@11: selectedTexture:SetWidth (frame_witdh - 9) Tercio@11: Tercio@11: for index, row in ipairs (object.menus) do Tercio@11: row:SetPoint ("topright", scrollChild, "topright", -5, ((-index-1)*20)-5) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: object.scroll:SetValue (0) Tercio@11: object:Open() Tercio@11: Tercio@11: else Tercio@11: --> clear menu Tercio@11: Tercio@11: end Tercio@11: Tercio@11: else --> click to close Tercio@11: Tercio@11: object:Close() Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnEnter (self) Tercio@11: Tercio@11: if (self.MyObject.OnEnterHook) then Tercio@11: local interrupt = self.MyObject.OnEnterHook (self) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (self.MyObject.onenter_backdrop) then Tercio@11: self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) Tercio@11: else Tercio@11: self:SetBackdropColor (.2, .2, .2, .2) Tercio@11: end Tercio@11: Tercio@11: self.arrowTexture2:Show() Tercio@11: Tercio@11: if (self.MyObject.have_tooltip) then Tercio@17: GameCooltip2:Preset (2) Tercio@17: Tercio@17: if (type (self.MyObject.have_tooltip) == "function") then Tercio@17: GameCooltip2:AddLine (self.MyObject.have_tooltip() or "") Tercio@17: else Tercio@17: GameCooltip2:AddLine (self.MyObject.have_tooltip) Tercio@17: end Tercio@17: Tercio@11: GameCooltip2:SetOwner (self) Tercio@11: GameCooltip2:ShowCooltip() Tercio@11: end Tercio@11: Tercio@11: local parent = self:GetParent().MyObject Tercio@11: if (parent and parent.type == "panel") then Tercio@11: if (parent.GradientEnabled) then Tercio@11: parent:RunGradient() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnLeave (self) Tercio@11: if (self.MyObject.OnLeaveHook) then Tercio@11: local interrupt = self.MyObject.OnLeaveHook (self) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (self.MyObject.onleave_backdrop) then Tercio@11: self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) Tercio@11: else Tercio@11: self:SetBackdropColor (1, 1, 1, .5) Tercio@11: end Tercio@11: Tercio@11: self.arrowTexture2:Hide() Tercio@11: Tercio@11: if (self.MyObject.have_tooltip) then Tercio@11: GameCooltip2:ShowMe (false) Tercio@11: end Tercio@11: Tercio@11: local parent = self:GetParent().MyObject Tercio@11: if (parent and parent.type == "panel") then Tercio@11: if (parent.GradientEnabled) then Tercio@11: parent:RunGradient (false) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnSizeChanged (self, w, h) Tercio@11: self.MyObject.label:SetSize (self:GetWidth()-40, 10) Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnShow (self) Tercio@11: if (self.MyObject and self.MyObject.OnShowHook) then Tercio@11: local interrupt = self.MyObject.OnShowHook (self) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function DetailsFrameworkDropDownOnHide (self) Tercio@11: if (self.MyObject and self.MyObject.OnHideHook) then Tercio@11: local interrupt = self.MyObject.OnHideHook (self) Tercio@11: if (interrupt) then Tercio@11: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: self.MyObject:Close() Tercio@11: end Tercio@11: Tercio@11: Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> object constructor Tercio@11: Tercio@11: function DF:CreateDropDown (parent, func, default, w, h, member, name) Tercio@11: return DF:NewDropDown (parent, parent, name, member, w, h, func, default) Tercio@11: end Tercio@11: Tercio@11: function DF:NewDropDown (parent, container, name, member, w, h, func, default) Tercio@11: Tercio@11: if (not name) then Tercio@11: name = "DetailsFrameworkDropDownNumber" .. DF.DropDownCounter Tercio@11: DF.DropDownCounter = DF.DropDownCounter + 1 Tercio@11: Tercio@11: elseif (not parent) then Tercio@11: return nil 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 DropDownObject = {type = "dropdown", dframework = true} Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = DropDownObject 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: if (default == nil) then Tercio@11: default = 1 Tercio@11: end Tercio@11: Tercio@11: --> default members: Tercio@11: --> hooks Tercio@11: DropDownObject.OnEnterHook = nil Tercio@11: DropDownObject.OnLeaveHook = nil Tercio@11: DropDownObject.OnHideHook = nil Tercio@11: DropDownObject.OnShowHook = nil Tercio@11: DropDownObject.OnMouseDownHook = nil Tercio@11: --> misc Tercio@11: DropDownObject.container = container Tercio@11: DropDownObject.have_tooltip = nil Tercio@11: Tercio@11: DropDownObject.dropdown = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownTemplate") Tercio@11: DropDownObject.widget = DropDownObject.dropdown Tercio@11: Tercio@11: DropDownObject.__it = {nil, nil} Tercio@11: --_G [name] = DropDownObject Tercio@11: Tercio@11: if (not APIDropDownFunctions) then Tercio@11: APIDropDownFunctions = true Tercio@11: local idx = getmetatable (DropDownObject.dropdown).__index Tercio@11: for funcName, funcAddress in pairs (idx) do Tercio@11: if (not DropDownMetaFunctions [funcName]) then Tercio@11: DropDownMetaFunctions [funcName] = function (object, ...) Tercio@11: local x = loadstring ( "return _G."..object.dropdown:GetName()..":"..funcName.."(...)") Tercio@11: return x (...) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: DropDownObject.dropdown.MyObject = DropDownObject Tercio@11: Tercio@11: DropDownObject.dropdown:SetWidth (w) Tercio@11: DropDownObject.dropdown:SetHeight (h) Tercio@11: Tercio@11: DropDownObject.func = func Tercio@11: DropDownObject.realsizeW = 150 Tercio@11: DropDownObject.realsizeH = 150 Tercio@11: DropDownObject.FixedValue = nil Tercio@11: DropDownObject.opened = false Tercio@11: DropDownObject.menus = {} Tercio@11: DropDownObject.myvalue = nil Tercio@11: Tercio@11: DropDownObject.label = _G [name .. "_Text"] Tercio@11: Tercio@11: DropDownObject.icon = _G [name .. "_IconTexture"] Tercio@11: DropDownObject.statusbar = _G [name .. "_StatusBarTexture"] Tercio@11: DropDownObject.select = _G [name .. "_SelectedTexture"] Tercio@11: Tercio@11: local scroll = _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame"] Tercio@11: Tercio@11: DropDownObject.scroll = DF:NewScrollBar (scroll, _G [DropDownObject.dropdown:GetName() .. "_ScrollFrame".."_ScrollChild"], -25, -18) Tercio@11: Tercio@11: function DropDownObject:HideScroll() Tercio@11: scroll.baixo:Hide() Tercio@11: scroll.cima:Hide() Tercio@11: scroll.slider:Hide() Tercio@11: end Tercio@11: function DropDownObject:ShowScroll() Tercio@11: scroll.baixo:Show() Tercio@11: scroll.cima:Show() Tercio@11: scroll.slider:Show() Tercio@11: end Tercio@11: Tercio@11: --button_down_scripts (DropDownObject, scroll.slider, scroll.baixo) Tercio@11: Tercio@11: DropDownObject:HideScroll() Tercio@11: DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10) Tercio@11: Tercio@11: --> setup class Tercio@11: _setmetatable (DropDownObject, DropDownMetaFunctions) Tercio@11: Tercio@11: --> initialize first menu selected Tercio@11: Tercio@11: if (type (default) == "string") then Tercio@11: DropDownObject:Select (default) Tercio@11: Tercio@11: elseif (type (default) == "number") then Tercio@11: if (not DropDownObject:Select (default)) then Tercio@11: DropDownObject:Select (default, true) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: return DropDownObject Tercio@11: Tercio@11: end