Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@20: if (not DF or not DetailsFrameworkCanLoad) then Tercio@20: return Tercio@20: end Tercio@20: Tercio@11: local _ 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 SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") Tercio@11: Tercio@11: local cleanfunction = function() end Tercio@11: local APISliderFunctions = false Tercio@39: Tercio@39: do Tercio@39: local metaPrototype = { Tercio@39: WidgetType = "slider", Tercio@39: SetHook = DF.SetHook, Tercio@39: RunHooksForWidget = DF.RunHooksForWidget, Tercio@39: } Tercio@39: Tercio@39: _G [DF.GlobalWidgetControlNames ["slider"]] = _G [DF.GlobalWidgetControlNames ["slider"]] or metaPrototype Tercio@39: end Tercio@39: Tercio@39: local DFSliderMetaFunctions = _G [DF.GlobalWidgetControlNames ["slider"]] Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> metatables Tercio@11: Tercio@35: DFSliderMetaFunctions.__call = function (_table, value) Tercio@11: if (not value) then Tercio@11: if (_table.isSwitch) then Tercio@11: Tercio@11: if (type (value) == "boolean") then --> false Tercio@11: return _table.slider:SetValue (1) Tercio@11: end Tercio@11: Tercio@11: if (_table.slider:GetValue() == 1) then Tercio@11: return false Tercio@11: else Tercio@11: return true Tercio@11: end Tercio@11: end Tercio@11: return _table.slider:GetValue() Tercio@11: else Tercio@11: if (_table.isSwitch) then Tercio@11: if (type (value) == "boolean") then Tercio@11: if (value) then Tercio@11: _table.slider:SetValue (2) Tercio@11: else Tercio@11: _table.slider:SetValue (1) Tercio@11: end Tercio@11: else Tercio@11: _table.slider:SetValue (value) Tercio@11: end Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: return _table.slider:SetValue (value) Tercio@11: end 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: --> frame width Tercio@11: local gmember_width = function (_object) Tercio@11: return _object.slider:GetWidth() Tercio@11: end Tercio@11: --> frame height Tercio@11: local gmember_height = function (_object) Tercio@11: return _object.slider:GetHeight() Tercio@11: end Tercio@11: --> locked Tercio@11: local gmember_locked = function (_object) Tercio@11: return _rawget (_object, "lockdown") Tercio@11: end Tercio@11: --> fractional Tercio@11: local gmember_fractional = function (_object) Tercio@11: return _rawget (_object, "useDecimals") Tercio@11: end Tercio@11: --> value Tercio@11: local gmember_value = function (_object) Tercio@11: return _object() Tercio@11: end Tercio@11: Tercio@39: DFSliderMetaFunctions.GetMembers = DFSliderMetaFunctions.GetMembers or {} Tercio@39: DFSliderMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip Tercio@39: DFSliderMetaFunctions.GetMembers ["shown"] = gmember_shown Tercio@39: DFSliderMetaFunctions.GetMembers ["width"] = gmember_width Tercio@39: DFSliderMetaFunctions.GetMembers ["height"] = gmember_height Tercio@39: DFSliderMetaFunctions.GetMembers ["locked"] = gmember_locked Tercio@39: DFSliderMetaFunctions.GetMembers ["fractional"] = gmember_fractional Tercio@39: DFSliderMetaFunctions.GetMembers ["value"] = gmember_value Tercio@11: Tercio@35: DFSliderMetaFunctions.__index = function (_table, _member_requested) Tercio@11: Tercio@39: local func = DFSliderMetaFunctions.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@35: return DFSliderMetaFunctions [_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.slider:SetWidth (_value) Tercio@11: end Tercio@11: --> frame height Tercio@11: local smember_height = function (_object, _value) Tercio@11: return _object.slider:SetHeight (_value) Tercio@11: end Tercio@11: --> locked Tercio@11: local smember_locked = function (_object, _value) Tercio@11: if (_value) then Tercio@11: return self:Disable() Tercio@11: else Tercio@11: return self:Enable() Tercio@11: end Tercio@11: end Tercio@11: --> backdrop Tercio@11: local smember_backdrop = function (_object, _value) Tercio@11: return _object.slider:SetBackdrop (_value) Tercio@11: end Tercio@11: --> fractional Tercio@11: local smember_fractional = function (_object, _value) Tercio@11: return _rawset (_object, "useDecimals", _value) Tercio@11: end Tercio@11: --> value Tercio@11: local smember_value = function (_object, _value) Tercio@11: _object (_value) Tercio@11: end Tercio@11: Tercio@39: DFSliderMetaFunctions.SetMembers = DFSliderMetaFunctions.SetMembers or {} Tercio@39: DFSliderMetaFunctions.SetMembers ["tooltip"] = smember_tooltip Tercio@39: DFSliderMetaFunctions.SetMembers ["show"] = smember_show Tercio@39: DFSliderMetaFunctions.SetMembers ["hide"] = smember_hide Tercio@39: DFSliderMetaFunctions.SetMembers ["backdrop"] = smember_backdrop Tercio@39: DFSliderMetaFunctions.SetMembers ["width"] = smember_width Tercio@39: DFSliderMetaFunctions.SetMembers ["height"] = smember_height Tercio@39: DFSliderMetaFunctions.SetMembers ["locked"] = smember_locked Tercio@39: DFSliderMetaFunctions.SetMembers ["fractional"] = smember_fractional Tercio@39: DFSliderMetaFunctions.SetMembers ["value"] = smember_value Tercio@11: Tercio@35: DFSliderMetaFunctions.__newindex = function (_table, _key, _value) Tercio@39: local func = DFSliderMetaFunctions.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: --> show & hide Tercio@35: function DFSliderMetaFunctions:IsShown() Tercio@11: return self.slider:IsShown() Tercio@11: end Tercio@35: function DFSliderMetaFunctions:Show() Tercio@11: return self.slider:Show() Tercio@11: end Tercio@35: function DFSliderMetaFunctions:Hide() Tercio@11: return self.slider:Hide() Tercio@11: end Tercio@11: Tercio@11: --> fixed value Tercio@35: function DFSliderMetaFunctions:SetFixedParameter (value) Tercio@11: _rawset (self, "FixedValue", value) Tercio@11: end Tercio@11: Tercio@11: --> set value Tercio@35: function DFSliderMetaFunctions:SetValue (value) Tercio@11: return self (value) Tercio@11: end Tercio@11: Tercio@11: -- thumb size Tercio@35: function DFSliderMetaFunctions:SetThumbSize (w, h) Tercio@11: if (not w) then Tercio@11: w = self.thumb:GetWidth() Tercio@11: end Tercio@11: if (not h) then Tercio@11: h = self.thumb:GetHeight() Tercio@11: end Tercio@11: return self.thumb:SetSize (w, h) Tercio@11: end Tercio@11: Tercio@11: Tercio@11: -- setpoint Tercio@35: function DFSliderMetaFunctions: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@35: function DFSliderMetaFunctions:SetSize (w, h) Tercio@11: if (w) then Tercio@11: self.slider:SetWidth (w) Tercio@11: end Tercio@11: if (h) then Tercio@11: return self.slider:SetHeight (h) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- tooltip Tercio@35: function DFSliderMetaFunctions: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@35: function DFSliderMetaFunctions:GetTooltip() Tercio@11: return _rawget (self, "have_tooltip") Tercio@11: end Tercio@11: Tercio@11: -- frame levels Tercio@35: function DFSliderMetaFunctions:GetFrameLevel() Tercio@11: return self.slider:GetFrameLevel() Tercio@11: end Tercio@35: function DFSliderMetaFunctions:SetFrameLevel (level, frame) Tercio@11: if (not frame) then Tercio@11: return self.slider:SetFrameLevel (level) Tercio@11: else Tercio@11: local framelevel = frame:GetFrameLevel (frame) + level Tercio@11: return self.slider:SetFrameLevel (framelevel) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- frame stratas Tercio@35: function DFSliderMetaFunctions:SetFrameStrata() Tercio@11: return self.slider:GetFrameStrata() Tercio@11: end Tercio@35: function DFSliderMetaFunctions:SetFrameStrata (strata) Tercio@11: if (_type (strata) == "table") then Tercio@11: self.slider:SetFrameStrata (strata:GetFrameStrata()) Tercio@11: else Tercio@11: self.slider:SetFrameStrata (strata) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: -- enabled Tercio@35: function DFSliderMetaFunctions:IsEnabled() Tercio@11: return not _rawget (self, "lockdown") Tercio@11: end Tercio@35: Tercio@35: function DFSliderMetaFunctions:Enable() Tercio@11: self.slider:Enable() Tercio@35: if (not self.is_checkbox) then Tercio@35: if (not self.lock_texture) then Tercio@35: DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture") Tercio@35: self.lock_texture:SetDesaturated (true) Tercio@35: self.lock_texture:SetPoint ("center", self.amt, "center") Tercio@35: end Tercio@35: self.lock_texture:Hide() Tercio@11: end Tercio@11: self.slider.amt:Show() Tercio@11: self:SetAlpha (1) Tercio@35: Tercio@35: if (self.is_checkbox) then Tercio@35: self.checked_texture:Show() Tercio@35: end Tercio@11: return _rawset (self, "lockdown", false) Tercio@11: end Tercio@11: Tercio@35: function DFSliderMetaFunctions:Disable() Tercio@11: Tercio@11: self.slider:Disable() Tercio@11: self.slider.amt:Hide() Tercio@11: self:SetAlpha (.4) Tercio@35: Tercio@35: if (not self.is_checkbox) then Tercio@35: if (not self.lock_texture) then Tercio@35: DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture") Tercio@35: self.lock_texture:SetDesaturated (true) Tercio@35: self.lock_texture:SetPoint ("center", self.amt, "center") Tercio@35: end Tercio@35: self.lock_texture:Show() Tercio@35: end Tercio@11: Tercio@35: if (self.is_checkbox) then Tercio@35: self.checked_texture:Show() Tercio@11: end Tercio@35: Tercio@35: --print ("result 2:", self.checked_texture:IsShown(), self.checked_texture:GetAlpha(), self.checked_texture:GetSize()) Tercio@11: Tercio@11: return _rawset (self, "lockdown", true) Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> scripts Tercio@11: Tercio@11: local OnEnter = function (slider) Tercio@11: if (_rawget (slider.MyObject, "lockdown")) then Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: DetailsFrameworkSliderButtons1:ShowMe (slider) Tercio@11: Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnEnter", slider, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: slider.thumb:SetAlpha (1) Tercio@11: Tercio@22: if (slider.MyObject.onenter_backdrop_border_color) then Tercio@22: slider:SetBackdropBorderColor (unpack (slider.MyObject.onenter_backdrop_border_color)) Tercio@22: end Tercio@22: Tercio@11: if (slider.MyObject.have_tooltip and slider.MyObject.have_tooltip ~= "Right Click to Type the Value") then Tercio@11: GameCooltip2:Preset (2) Tercio@11: GameCooltip2:AddLine (slider.MyObject.have_tooltip) Tercio@11: GameCooltip2:ShowCooltip (slider, "tooltip") Tercio@11: else Tercio@58: GameCooltip2:Preset (2) Tercio@58: GameCooltip2:AddLine ("Right Click to Type the Value", "", 1, "", "", 10) Tercio@11: GameCooltip2:AddIcon ([[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]], 1, 1, 16, 16, 0.015625, 0.15671875, 0.640625, 0.798828125) Tercio@11: GameCooltip2:ShowCooltip (slider, "tooltip") Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnLeave = function (slider) Tercio@11: Tercio@11: if (_rawget (slider.MyObject, "lockdown")) then Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: DetailsFrameworkSliderButtons1:PrepareToHide() Tercio@11: Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnLeave", slider, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: slider.thumb:SetAlpha (.7) Tercio@11: Tercio@22: if (slider.MyObject.onleave_backdrop_border_color) then Tercio@22: slider:SetBackdropBorderColor (unpack (slider.MyObject.onleave_backdrop_border_color)) Tercio@22: end Tercio@22: Tercio@25: GameCooltip2:ShowMe (false) Tercio@25: Tercio@11: end Tercio@11: Tercio@11: Tercio@11: local f = CreateFrame ("frame", "DetailsFrameworkSliderButtons1", UIParent) Tercio@11: f:Hide() Tercio@11: f:SetHeight (18) Tercio@11: Tercio@11: local t = 0 Tercio@11: f.is_going_hide = false Tercio@11: local going_hide = function (self, elapsed) Tercio@11: t = t + elapsed Tercio@11: if (t > 0.3) then Tercio@11: f:Hide() Tercio@11: f:SetScript ("OnUpdate", nil) Tercio@11: f.is_going_hide = false Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: function f:ShowMe (host) Tercio@11: f:SetPoint ("bottomleft", host, "topleft", -3, -5) Tercio@11: f:SetPoint ("bottomright", host, "topright", 3, -5) Tercio@58: --f:SetFrameStrata (host:GetFrameStrata()) Tercio@58: f:SetFrameStrata ("FULLSCREEN") Tercio@58: f:SetFrameLevel (host:GetFrameLevel() + 1000) Tercio@11: f:Show() Tercio@11: if (f.is_going_hide) then Tercio@11: f:SetScript ("OnUpdate", nil) Tercio@11: f.is_going_hide = false Tercio@11: end Tercio@11: Tercio@11: f.host = host.MyObject Tercio@11: end Tercio@11: Tercio@11: function f:PrepareToHide() Tercio@11: f.is_going_hide = true Tercio@11: t = 0 Tercio@11: f:SetScript ("OnUpdate", going_hide) Tercio@11: end Tercio@11: Tercio@11: local button_plus = CreateFrame ("button", "DetailsFrameworkSliderButtonsPlusButton", f) Tercio@11: local button_minor = CreateFrame ("button", "DetailsFrameworkSliderButtonsMinorButton", f) Tercio@39: button_plus:SetFrameStrata (f:GetFrameStrata()) Tercio@39: button_minor:SetFrameStrata (f:GetFrameStrata()) Tercio@11: Tercio@11: button_plus:SetScript ("OnEnter", function (self) Tercio@11: if (f.is_going_hide) then Tercio@11: f:SetScript ("OnUpdate", nil) Tercio@11: f.is_going_hide = false Tercio@11: end Tercio@11: end) Tercio@11: button_minor:SetScript ("OnEnter", function (self) Tercio@11: if (f.is_going_hide) then Tercio@11: f:SetScript ("OnUpdate", nil) Tercio@11: f.is_going_hide = false Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: button_plus:SetScript ("OnLeave", function (self) Tercio@11: f:PrepareToHide() Tercio@11: end) Tercio@11: button_minor:SetScript ("OnLeave", function (self) Tercio@11: f:PrepareToHide() Tercio@11: end) Tercio@11: Tercio@11: button_plus:SetNormalTexture ([[Interface\Buttons\UI-PlusButton-Up]]) Tercio@11: button_minor:SetNormalTexture ([[Interface\Buttons\UI-MinusButton-Up]]) Tercio@11: Tercio@11: button_plus:SetPushedTexture ([[Interface\Buttons\UI-PlusButton-Down]]) Tercio@11: button_minor:SetPushedTexture ([[Interface\Buttons\UI-MinusButton-Down]]) Tercio@11: Tercio@11: button_plus:SetDisabledTexture ([[Interface\Buttons\UI-PlusButton-Disabled]]) Tercio@11: button_minor:SetDisabledTexture ([[Interface\Buttons\UI-MinusButton-Disabled]]) Tercio@11: Tercio@11: button_plus:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]]) Tercio@11: button_minor:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]]) Tercio@11: Tercio@11: --button_minor:SetPoint ("bottomleft", f, "bottomleft", -6, -13) Tercio@11: --button_plus:SetPoint ("bottomright", f, "bottomright", 6, -13) Tercio@11: Tercio@11: button_minor:SetPoint ("bottomright", f, "bottomright", 13, -13) Tercio@11: button_plus:SetPoint ("left", button_minor, "right", -2, 0) Tercio@11: Tercio@11: button_plus:SetSize (16, 16) Tercio@11: button_minor:SetSize (16, 16) Tercio@11: Tercio@11: local timer = 0 Tercio@11: local change_timer = 0 Tercio@11: Tercio@11: -- -- -- Tercio@11: Tercio@11: local plus_button_script = function() Tercio@11: Tercio@11: local current = f.host.value Tercio@35: local editbox = DFSliderMetaFunctions.editbox_typevalue Tercio@11: Tercio@11: if (f.host.fine_tuning) then Tercio@11: f.host:SetValue (current + f.host.fine_tuning) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current + f.host.fine_tuning))) Tercio@11: end Tercio@11: else Tercio@11: if (f.host.useDecimals) then Tercio@11: f.host:SetValue (current + 0.1) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current + 0.1)) Tercio@11: end Tercio@11: else Tercio@11: f.host:SetValue (current + 1) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current + 1))) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: button_plus:SetScript ("OnMouseUp", function (self) Tercio@11: if (not button_plus.got_click) then Tercio@11: plus_button_script() Tercio@11: end Tercio@11: button_plus.got_click = false Tercio@11: self:SetScript ("OnUpdate", nil) Tercio@11: end) Tercio@11: Tercio@11: local on_update = function (self, elapsed) Tercio@11: timer = timer + elapsed Tercio@11: if (timer > 0.4) then Tercio@11: change_timer = change_timer + elapsed Tercio@11: if (change_timer > 0.1) then Tercio@11: change_timer = 0 Tercio@11: plus_button_script() Tercio@11: button_plus.got_click = true Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: button_plus:SetScript ("OnMouseDown", function (self) Tercio@11: timer = 0 Tercio@11: change_timer = 0 Tercio@11: self:SetScript ("OnUpdate", on_update) Tercio@11: end) Tercio@11: Tercio@11: -- -- -- Tercio@11: Tercio@11: local minor_button_script = function() Tercio@11: local current = f.host.value Tercio@35: local editbox = DFSliderMetaFunctions.editbox_typevalue Tercio@11: Tercio@11: if (f.host.fine_tuning) then Tercio@11: f.host:SetValue (current - f.host.fine_tuning) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current - f.host.fine_tuning))) Tercio@11: end Tercio@11: else Tercio@11: if (f.host.useDecimals) then Tercio@11: f.host:SetValue (current - 0.1) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current - 0.1)) Tercio@11: end Tercio@11: else Tercio@11: f.host:SetValue (current - 1) Tercio@35: if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current - 1))) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: button_minor:SetScript ("OnMouseUp", function (self) Tercio@11: if (not button_minor.got_click) then Tercio@11: minor_button_script() Tercio@11: end Tercio@11: button_minor.got_click = false Tercio@11: self:SetScript ("OnUpdate", nil) Tercio@11: end) Tercio@11: Tercio@11: local on_update = function (self, elapsed) Tercio@11: timer = timer + elapsed Tercio@11: if (timer > 0.4) then Tercio@11: change_timer = change_timer + elapsed Tercio@11: if (change_timer > 0.1) then Tercio@11: change_timer = 0 Tercio@11: minor_button_script() Tercio@11: button_minor.got_click = true Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: button_minor:SetScript ("OnMouseDown", function (self) Tercio@11: timer = 0 Tercio@11: change_timer = 0 Tercio@11: self:SetScript ("OnUpdate", on_update) Tercio@11: end) Tercio@11: Tercio@56: local do_precision = function (text) Tercio@56: if (type (text) == "string" and text:find ("%.")) then Tercio@56: local left, right = strsplit (".", text) Tercio@56: left = tonumber (left) Tercio@56: right = tonumber (right) Tercio@56: Tercio@56: if (left and right) then Tercio@56: local newString = tostring (left) .. "." .. tostring (right) Tercio@56: local newNumber = tonumber (newString) Tercio@56: Tercio@56: if (newNumber) then Tercio@56: return newNumber Tercio@56: end Tercio@56: end Tercio@56: end Tercio@56: Tercio@56: return tonumber (text) Tercio@56: end Tercio@56: Tercio@35: function DFSliderMetaFunctions:TypeValue() Tercio@11: if (not self.isSwitch) then Tercio@11: Tercio@35: if (not DFSliderMetaFunctions.editbox_typevalue) then Tercio@11: Tercio@11: local editbox = CreateFrame ("EditBox", "DetailsFrameworkSliderEditBox", UIParent) Tercio@11: Tercio@11: editbox:SetSize (40, 20) Tercio@11: editbox:SetJustifyH ("center") Tercio@11: editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], Tercio@11: edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", --edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], Tercio@11: tile = true, edgeSize = 8, tileSize = 5}) Tercio@11: editbox:SetFontObject ("GameFontHighlightSmall") Tercio@11: Tercio@11: editbox:SetScript ("OnEnterPressed", function() Tercio@11: editbox:ClearFocus() Tercio@11: editbox:Hide() Tercio@11: editbox:GetParent().MyObject.typing_value = false Tercio@56: editbox:GetParent().MyObject.value = tonumber (editbox:GetText()) --do_precision (editbox:GetText()) Tercio@11: end) Tercio@11: Tercio@11: editbox:SetScript ("OnEscapePressed", function() Tercio@11: editbox:ClearFocus() Tercio@11: editbox:Hide() Tercio@11: editbox:GetParent().MyObject.typing_value = false Tercio@56: editbox:GetParent().MyObject.value = self.typing_value_started --do_precision (self.typing_value_started) Tercio@11: end) Tercio@11: Tercio@11: editbox:SetScript ("OnTextChanged", function() Tercio@11: editbox:GetParent().MyObject.typing_can_change = true Tercio@56: editbox:GetParent().MyObject.value = tonumber (editbox:GetText()) --do_precision Tercio@11: editbox:GetParent().MyObject.typing_can_change = false Tercio@11: end) Tercio@11: Tercio@35: DFSliderMetaFunctions.editbox_typevalue = editbox Tercio@11: end Tercio@11: Tercio@11: local pvalue = self.previous_value [2] Tercio@11: self:SetValue (pvalue) Tercio@11: Tercio@11: self.typing_value = true Tercio@11: self.typing_value_started = pvalue Tercio@11: Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetSize (self.width, self.height) Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetPoint ("center", self.widget, "center") Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetFocus() Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetParent (self.widget) Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetFrameLevel (self.widget:GetFrameLevel()+1) Tercio@11: Tercio@11: if (self.useDecimals) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.1f", self.value))) Tercio@11: else Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (self.value))) Tercio@11: end Tercio@11: Tercio@35: DFSliderMetaFunctions.editbox_typevalue:HighlightText() Tercio@11: Tercio@35: DFSliderMetaFunctions.editbox_typevalue:Show() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnMouseDown = function (slider, button) Tercio@39: slider.MyObject.IsValueChanging = true Tercio@39: Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnMouseDown", slider, button, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@39: end Tercio@39: Tercio@11: if (button == "RightButton") then Tercio@11: slider.MyObject:TypeValue() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnMouseUp = function (slider, button) Tercio@39: slider.MyObject.IsValueChanging = nil Tercio@39: Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnMouseUp", slider, button, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@39: end Tercio@11: end Tercio@11: Tercio@11: local OnHide = function (slider) Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnHide", slider, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: Tercio@11: if (slider.MyObject.typing_value) then Tercio@35: DFSliderMetaFunctions.editbox_typevalue:ClearFocus() Tercio@35: DFSliderMetaFunctions.editbox_typevalue:SetText ("") Tercio@11: slider.MyObject.typing_valu = false Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local OnShow = function (slider) Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnShow", slider, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local table_insert = table.insert Tercio@11: local table_remove = table.remove Tercio@11: Tercio@11: local OnValueChanged = function (slider) Tercio@11: Tercio@12: local amt Tercio@12: if (slider.MyObject.useDecimals) then Tercio@12: amt = slider:GetValue() Tercio@12: else Tercio@56: amt = do_precision (slider:GetValue()) Tercio@12: end Tercio@56: Tercio@11: if (slider.MyObject.typing_value and not slider.MyObject.typing_can_change) then Tercio@11: slider.MyObject:SetValue (slider.MyObject.typing_value_started) Tercio@11: return Tercio@11: end Tercio@56: Tercio@11: table_insert (slider.MyObject.previous_value, 1, amt) Tercio@11: table_remove (slider.MyObject.previous_value, 4) Tercio@11: Tercio@39: local capsule = slider.MyObject Tercio@39: local kill = capsule:RunHooksForWidget ("OnValueChanged", slider, capsule.FixedValue, amt, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@11: end Tercio@39: local kill = capsule:RunHooksForWidget ("OnValueChange", slider, capsule.FixedValue, amt, capsule) Tercio@39: if (kill) then Tercio@39: return Tercio@39: end Tercio@39: Tercio@11: if (slider.MyObject.OnValueChanged) then Tercio@11: slider.MyObject.OnValueChanged (slider, slider.MyObject.FixedValue, amt) Tercio@11: end Tercio@11: Tercio@11: if (amt < 10 and amt >= 1) then Tercio@11: amt = "0"..amt Tercio@11: end Tercio@11: Tercio@11: if (slider.MyObject.useDecimals) then Tercio@11: slider.amt:SetText (string.format ("%.2f", amt)) Tercio@11: else Tercio@11: slider.amt:SetText (math.floor (amt)) Tercio@11: end Tercio@11: slider.MyObject.ivalue = amt Tercio@11: end Tercio@11: Tercio@11: ------------------------------------------------------------------------------------------------------------ Tercio@11: --> object constructor Tercio@11: Tercio@11: local SwitchOnClick = function (self, button, forced_value, value) Tercio@11: Tercio@11: local slider = self.MyObject Tercio@11: Tercio@11: if (_rawget (slider, "lockdown")) then Tercio@11: return Tercio@11: end Tercio@11: Tercio@11: if (forced_value) then Tercio@11: _rawset (slider, "value", not value) Tercio@11: end Tercio@11: Tercio@11: if (_rawget (slider, "value")) then --actived Tercio@11: _rawset (slider, "value", false) Tercio@11: Tercio@22: if (slider.backdrop_disabledcolor) then Tercio@22: slider:SetBackdropColor (unpack (slider.backdrop_disabledcolor)) Tercio@22: else Tercio@22: slider:SetBackdropColor (1, 0, 0, 0.4) Tercio@22: end Tercio@22: Tercio@22: if (slider.is_checkbox) then Tercio@22: slider.checked_texture:Hide() Tercio@22: else Tercio@22: slider._text:SetText (slider._ltext) Tercio@22: slider._thumb:ClearAllPoints() Tercio@22: slider._thumb:SetPoint ("left", slider.widget, "left") Tercio@22: end Tercio@11: else Tercio@11: _rawset (slider, "value", true) Tercio@22: if (slider.backdrop_enabledcolor) then Tercio@22: slider:SetBackdropColor (unpack (slider.backdrop_enabledcolor)) Tercio@22: else Tercio@22: slider:SetBackdropColor (0, 0, 1, 0.4) Tercio@22: end Tercio@22: if (slider.is_checkbox) then Tercio@22: slider.checked_texture:Show() Tercio@22: else Tercio@22: slider._text:SetText (slider._rtext) Tercio@22: slider._thumb:ClearAllPoints() Tercio@22: slider._thumb:SetPoint ("right", slider.widget, "right") Tercio@22: end Tercio@11: end Tercio@11: Tercio@11: if (slider.OnSwitch and not forced_value) then Tercio@11: local value = _rawget (slider, "value") Tercio@11: if (slider.return_func) then Tercio@11: value = slider:return_func (value) Tercio@11: end Tercio@11: slider.OnSwitch (slider, slider.FixedValue, value) Tercio@11: end Tercio@11: Tercio@11: end Tercio@11: Tercio@11: local default_switch_func = function (self, passed_value) Tercio@11: if (self.value) then Tercio@11: return false Tercio@11: else Tercio@11: return true Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local switch_get_value = function (self) Tercio@11: return self.value Tercio@11: end Tercio@11: Tercio@11: local switch_set_value = function (self, value) Tercio@11: if (self.switch_func) then Tercio@11: value = self:switch_func (value) Tercio@11: end Tercio@11: Tercio@11: SwitchOnClick (self.widget, nil, true, value) Tercio@11: end Tercio@11: Tercio@11: local switch_set_fixparameter = function (self, value) Tercio@11: _rawset (self, "FixedValue", value) Tercio@11: end Tercio@11: Tercio@11: local switch_disable = function (self) Tercio@11: Tercio@22: if (self.is_checkbox) then Tercio@22: self.checked_texture:Hide() Tercio@22: else Tercio@22: self._text:Hide() Tercio@35: if (not self.lock_texture) then Tercio@35: DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture") Tercio@35: self.lock_texture:SetDesaturated (true) Tercio@35: self.lock_texture:SetPoint ("center", self._thumb, "center") Tercio@35: end Tercio@35: self.lock_texture:Show() Tercio@22: end Tercio@22: Tercio@11: self:SetAlpha (.4) Tercio@11: _rawset (self, "lockdown", true) Tercio@11: end Tercio@11: local switch_enable = function (self) Tercio@22: if (self.is_checkbox) then Tercio@22: if (_rawget (self, "value")) then Tercio@22: self.checked_texture:Show() Tercio@22: else Tercio@22: self.checked_texture:Hide() Tercio@22: end Tercio@22: else Tercio@35: if (not self.lock_texture) then Tercio@35: DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture") Tercio@35: self.lock_texture:SetDesaturated (true) Tercio@35: self.lock_texture:SetPoint ("center", self._thumb, "center") Tercio@35: end Tercio@35: self.lock_texture:Hide() Tercio@22: self._text:Show() Tercio@22: end Tercio@22: Tercio@11: self:SetAlpha (1) Tercio@11: return _rawset (self, "lockdown", false) Tercio@11: end Tercio@11: Tercio@22: local set_as_checkbok = function (self) Tercio@35: local checked = self:CreateTexture (self:GetName() .. "CheckTexture", "overlay") Tercio@22: checked:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]]) Tercio@22: checked:SetPoint ("center", self.button, "center", -1, -1) Tercio@22: local size_pct = self:GetWidth()/32 Tercio@22: checked:SetSize (32*size_pct, 32*size_pct) Tercio@22: self.checked_texture = checked Tercio@22: Tercio@22: self._thumb:Hide() Tercio@22: self._text:Hide() Tercio@22: Tercio@22: self.is_checkbox = true Tercio@22: Tercio@22: if (_rawget (self, "value")) then Tercio@22: self.checked_texture:Show() Tercio@22: if (self.backdrop_enabledcolor) then Tercio@22: self:SetBackdropColor (unpack (self.backdrop_enabledcolor)) Tercio@22: else Tercio@22: self:SetBackdropColor (0, 0, 1, 0.4) Tercio@22: end Tercio@22: else Tercio@22: self.checked_texture:Hide() Tercio@22: if (self.backdrop_disabledcolor) then Tercio@22: self:SetBackdropColor (unpack (self.backdrop_disabledcolor)) Tercio@22: else Tercio@22: self:SetBackdropColor (0, 0, 1, 0.4) Tercio@22: end Tercio@22: end Tercio@35: Tercio@22: end Tercio@22: Tercio@22: function DF:CreateSwitch (parent, on_switch, default_value, w, h, ltext, rtext, member, name, color_inverted, switch_func, return_func, with_label, switch_template, label_template) Tercio@22: local switch, label = DF:NewSwitch (parent, parent, name, member, w or 60, h or 20, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label, switch_template, label_template) Tercio@11: if (on_switch) then Tercio@11: switch.OnSwitch = on_switch Tercio@11: end Tercio@11: return switch, label Tercio@11: end Tercio@11: Tercio@22: function DF:NewSwitch (parent, container, name, member, w, h, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label, switch_template, label_template) Tercio@11: Tercio@11: --> early checks Tercio@11: if (not name) then Tercioo@29: name = "DetailsFrameWorkSlider" .. DF.SwitchCounter Tercioo@29: DF.SwitchCounter = DF.SwitchCounter + 1 Tercio@11: elseif (not parent) then Tercioo@29: return error ("Details! FrameWork: parent not found.", 2) Tercio@11: end Tercio@11: if (not container) then Tercio@11: container = parent Tercio@11: end Tercio@56: Tercio@11: --> defaults Tercio@11: ltext = ltext or "OFF" Tercio@11: rtext = rtext or "ON" Tercio@11: Tercio@11: --> build frames Tercio@11: Tercio@11: w = w or 60 Tercio@11: h = h or 20 Tercio@11: Tercio@11: local slider = DF:NewButton (parent, container, name, member, w, h) Tercio@11: Tercio@11: slider.switch_func = switch_func Tercio@11: slider.return_func = return_func Tercio@11: slider.SetValue = switch_set_value Tercio@11: slider.GetValue = switch_get_value Tercio@11: slider.SetFixedParameter = switch_set_fixparameter Tercio@11: slider.Disable = switch_disable Tercio@11: slider.Enable = switch_enable Tercio@22: slider.SetAsCheckBox = set_as_checkbok Tercio@35: slider.SetTemplate = DFSliderMetaFunctions.SetTemplate Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = slider Tercio@11: end Tercio@11: Tercio@11: slider:SetBackdrop ({edgeFile = [[Interface\Buttons\UI-SliderBar-Border]], edgeSize = 8, Tercio@11: bgFile = [[Interface\AddOns\Details\images\background]], insets = {left = 3, right = 3, top = 5, bottom = 5}}) Tercio@11: Tercio@11: local thumb = slider:CreateTexture (nil, "artwork") Tercio@11: thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob") Tercio@11: thumb:SetSize (34+(h*0.2), h*1.2) Tercio@11: thumb:SetAlpha (0.7) Tercio@11: thumb:SetPoint ("left", slider.widget, "left") Tercio@11: Tercio@11: local text = slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall") Tercio@11: text:SetTextColor (.8, .8, .8, 1) Tercio@11: text:SetPoint ("center", thumb, "center") Tercio@11: Tercio@11: slider._text = text Tercio@11: slider._thumb = thumb Tercio@11: slider._ltext = ltext Tercio@11: slider._rtext = rtext Tercio@11: slider.thumb = thumb Tercio@11: Tercio@11: slider.invert_colors = color_inverted Tercio@11: Tercio@11: slider:SetScript ("OnClick", SwitchOnClick) Tercio@11: Tercio@11: slider:SetValue (default_value) Tercio@11: Tercio@11: slider.isSwitch = true Tercio@11: Tercio@22: if (switch_template) then Tercio@22: slider:SetTemplate (switch_template) Tercio@22: end Tercio@22: Tercio@11: if (with_label) then Tercio@11: local label = DF:CreateLabel (slider.widget, with_label, nil, nil, nil, "label", nil, "overlay") Tercio@11: label.text = with_label Tercio@11: slider.widget:SetPoint ("left", label.widget, "right", 2, 0) Tercio@11: with_label = label Tercio@22: Tercio@22: if (label_template) then Tercio@22: label:SetTemplate (label_template) Tercio@22: end Tercio@11: end Tercio@11: Tercio@11: return slider, with_label Tercio@11: end Tercio@11: Tercio@35: function DFSliderMetaFunctions:SetTemplate (template) Tercio@22: Tercio@22: --slider e switch Tercio@22: if (template.width) then Tercio@22: self:SetWidth (template.width) Tercio@22: end Tercio@22: if (template.height) then Tercio@22: self:SetHeight (template.height) Tercio@22: end Tercio@22: Tercio@22: if (template.backdrop) then Tercio@22: self:SetBackdrop (template.backdrop) Tercio@22: end Tercio@22: if (template.backdropcolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.backdropcolor) Tercio@22: self:SetBackdropColor (r, g, b, a) Tercio@22: end Tercio@22: if (template.backdropbordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.backdropbordercolor) Tercio@22: self:SetBackdropBorderColor (r, g, b, a) Tercio@22: self.onleave_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onenterbordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onenterbordercolor) Tercio@22: self.onenter_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.onleavebordercolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.onleavebordercolor) Tercio@22: self.onleave_backdrop_border_color = {r, g, b, a} Tercio@22: end Tercio@22: Tercio@22: if (template.thumbtexture) then Tercio@22: if (self.thumb) then Tercio@22: self.thumb:SetTexture (template.thumbtexture) Tercio@22: end Tercio@22: end Tercio@22: if (template.thumbwidth) then Tercio@22: if (self.thumb) then Tercio@22: self.thumb:SetWidth (template.thumbwidth) Tercio@22: end Tercio@22: end Tercio@22: if (template.thumbheight) then Tercio@22: if (self.thumb) then Tercio@22: self.thumb:SetHeight (template.thumbheight) Tercio@22: end Tercio@22: end Tercio@22: if (template.thumbcolor) then Tercio@22: if (self.thumb) then Tercio@22: local r, g, b, a = DF:ParseColors (template.thumbcolor) Tercio@22: self.thumb:SetVertexColor (r, g, b, a) Tercio@22: end Tercio@22: end Tercio@22: Tercio@22: --switch only Tercio@22: if (template.enabled_backdropcolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.enabled_backdropcolor) Tercio@22: self.backdrop_enabledcolor = {r, g, b, a} Tercio@22: end Tercio@22: if (template.disabled_backdropcolor) then Tercio@22: local r, g, b, a = DF:ParseColors (template.disabled_backdropcolor) Tercio@22: self.backdrop_disabledcolor = {r, g, b, a} Tercio@22: end Tercio@22: end Tercio@22: Tercio@22: function DF:CreateSlider (parent, w, h, min, max, step, defaultv, isDecemal, member, name, with_label, slider_template, label_template) Tercio@22: local slider, label = DF:NewSlider (parent, parent, name, member, w, h, min, max, step, defaultv, isDecemal, false, with_label, slider_template, label_template) Tercio@11: return slider, label Tercio@11: end Tercio@11: Tercio@22: function DF:NewSlider (parent, container, name, member, w, h, min, max, step, defaultv, isDecemal, isSwitch, with_label, slider_template, label_template) Tercio@11: Tercio@11: --> early checks Tercio@11: if (not name) then Tercio@11: name = "DetailsFrameworkSlider" .. DF.SliderCounter Tercio@11: DF.SliderCounter = DF.SliderCounter + 1 Tercio@11: end Tercio@11: if (not parent) then Tercioo@29: return error ("Details! FrameWork: parent not found.", 2) 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 Tercioo@29: local parentName = DF.GetParentName (parent) Tercioo@29: name = name:gsub ("$parent", parentName) Tercio@11: end Tercio@11: Tercio@11: local SliderObject = {type = "slider", dframework = true} Tercio@11: Tercio@11: if (member) then Tercio@11: parent [member] = SliderObject 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: --> defaults Tercio@11: min = min or 1 Tercio@11: max = max or 2 Tercio@11: step = step or 1 Tercio@11: defaultv = defaultv or min Tercio@11: Tercio@11: w = w or 130 Tercio@11: h = h or 19 Tercio@11: Tercio@11: --> default members: Tercio@11: SliderObject.lockdown = false Tercio@11: SliderObject.container = container Tercio@11: Tercio@11: SliderObject.slider = CreateFrame ("slider", name, parent) Tercio@11: SliderObject.widget = SliderObject.slider Tercio@11: Tercio@56: SliderObject.useDecimals = isDecemal or false Tercio@56: Tercio@56: if (SliderObject.useDecimals) then Tercio@56: SliderObject.slider:SetValueStep (0.01) Tercio@56: else Tercio@56: SliderObject.slider:SetValueStep (step) Tercio@56: end Tercio@56: Tercio@11: if (not APISliderFunctions) then Tercio@11: APISliderFunctions = true Tercio@11: local idx = getmetatable (SliderObject.slider).__index Tercio@11: for funcName, funcAddress in pairs (idx) do Tercio@35: if (not DFSliderMetaFunctions [funcName]) then Tercio@35: DFSliderMetaFunctions [funcName] = function (object, ...) Tercio@20: local x = loadstring ( "return _G['"..object.slider:GetName().."']:"..funcName.."(...)") Tercio@11: return x (...) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: SliderObject.slider.MyObject = SliderObject Tercio@11: SliderObject.slider:SetWidth (w) Tercio@11: SliderObject.slider:SetHeight (h) Tercio@11: SliderObject.slider:SetOrientation ("horizontal") Tercio@11: SliderObject.slider:SetMinMaxValues (min, max) Tercio@11: SliderObject.slider:SetValue (defaultv) Tercio@11: SliderObject.ivalue = defaultv Tercio@11: Tercio@11: SliderObject.slider:SetBackdrop ({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8}) Tercio@11: SliderObject.slider:SetBackdropColor (0.9, 0.7, 0.7, 1.0) Tercio@11: Tercio@11: SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork") Tercio@11: SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob") Tercio@11: SliderObject.thumb:SetSize (30+(h*0.2), h*1.2) Tercio@11: SliderObject.thumb:SetAlpha (0.7) Tercio@11: SliderObject.slider:SetThumbTexture (SliderObject.thumb) Tercio@11: SliderObject.slider.thumb = SliderObject.thumb Tercio@11: Tercio@11: if (not isSwitch) then Tercio@11: SliderObject.have_tooltip = "Right Click to Type the Value" Tercio@11: end Tercio@11: Tercio@11: SliderObject.amt = SliderObject.slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall") Tercio@11: Tercio@11: local amt = defaultv Tercio@11: if (amt < 10 and amt >= 1) then Tercio@11: amt = "0"..amt Tercio@11: end Tercio@11: Tercio@11: if (SliderObject.useDecimals) then Tercio@11: SliderObject.amt:SetText (string.format ("%.2f", amt)) Tercio@11: else Tercio@11: SliderObject.amt:SetText (math.floor (amt)) Tercio@11: end Tercio@11: Tercio@11: SliderObject.amt:SetTextColor (.8, .8, .8, 1) Tercio@11: SliderObject.amt:SetPoint ("center", SliderObject.thumb, "center") Tercio@11: SliderObject.slider.amt = SliderObject.amt Tercio@11: Tercio@11: SliderObject.previous_value = {defaultv or 0, 0, 0} Tercio@11: Tercio@11: --> hooks Tercio@39: SliderObject.HookList = { Tercio@39: OnEnter = {}, Tercio@39: OnLeave = {}, Tercio@39: OnHide = {}, Tercio@39: OnShow = {}, Tercio@39: OnMouseDown = {}, Tercio@39: OnMouseUp = {}, Tercio@11: Tercio@39: OnValueChange = {}, Tercio@39: OnValueChanged = {}, Tercio@39: } Tercio@39: Tercio@39: SliderObject.slider:SetScript ("OnEnter", OnEnter) Tercio@39: SliderObject.slider:SetScript ("OnLeave", OnLeave) Tercio@39: SliderObject.slider:SetScript ("OnHide", OnHide) Tercio@39: SliderObject.slider:SetScript ("OnShow", OnShow) Tercio@39: SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged) Tercio@39: SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown) Tercio@39: SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp) Tercio@39: Tercio@35: _setmetatable (SliderObject, DFSliderMetaFunctions) Tercio@11: Tercio@11: if (with_label) then Tercio@11: local label = DF:CreateLabel (SliderObject.slider, with_label, nil, nil, nil, "label", nil, "overlay") Tercio@11: label.text = with_label Tercio@11: SliderObject.slider:SetPoint ("left", label.widget, "right", 2, 0) Tercio@11: with_label = label Tercio@22: Tercio@22: if (label_template) then Tercio@22: label:SetTemplate (label_template) Tercio@22: end Tercio@22: end Tercio@22: Tercio@22: if (slider_template) then Tercio@22: SliderObject:SetTemplate (slider_template) Tercio@11: end Tercio@11: Tercio@11: return SliderObject, with_label Tercio@11: Tercio@58: end