You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1620 lines
52 KiB

4 years ago
3 years ago
local DF = _G["DetailsFramework"]
4 years ago
if (not DF or not DetailsFrameworkCanLoad) then
3 years ago
return
4 years ago
end
local _
local APISliderFunctions = false
do
local metaPrototype = {
WidgetType = "slider",
dversion = DF.dversion
}
--check if there's a metaPrototype already existing
if (_G[DF.GlobalWidgetControlNames["slider"]]) then
--get the already existing metaPrototype
3 years ago
local oldMetaPrototype = _G[DF.GlobalWidgetControlNames["slider"]]
4 years ago
--check if is older
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < DF.dversion) ) then
--the version is older them the currently loading one
--copy the new values into the old metatable
for funcName, _ in pairs(metaPrototype) do
oldMetaPrototype[funcName] = metaPrototype[funcName]
end
end
else
--first time loading the framework
3 years ago
_G[DF.GlobalWidgetControlNames["slider"]] = metaPrototype
4 years ago
end
end
3 years ago
local DFSliderMetaFunctions = _G[DF.GlobalWidgetControlNames["slider"]]
DF:Mixin(DFSliderMetaFunctions, DF.SetPointMixin)
DF:Mixin(DFSliderMetaFunctions, DF.FrameMixin)
DF:Mixin(DFSliderMetaFunctions, DF.TooltipHandlerMixin)
DF:Mixin(DFSliderMetaFunctions, DF.ScriptHookMixin)
4 years ago
------------------------------------------------------------------------------------------------------------
3 years ago
--metatables
4 years ago
3 years ago
DFSliderMetaFunctions.__call = function(object, value)
4 years ago
if (not value) then
3 years ago
if (object.isSwitch) then
if (type(value) == "boolean") then
object.slider:SetValue(1)
return
4 years ago
end
3 years ago
if (object.slider:GetValue() == 1) then
4 years ago
return false
else
return true
end
end
3 years ago
return object.slider:GetValue()
4 years ago
else
3 years ago
if (object.isSwitch) then
if (type(value) == "boolean") then
4 years ago
if (value) then
3 years ago
object.slider:SetValue(2)
4 years ago
else
3 years ago
object.slider:SetValue(1)
4 years ago
end
else
3 years ago
object.slider:SetValue(value)
4 years ago
end
return
end
3 years ago
return object.slider:SetValue(value)
4 years ago
end
end
------------------------------------------------------------------------------------------------------------
3 years ago
--members
4 years ago
3 years ago
--tooltip
local gmember_tooltip = function(object)
return object:GetTooltip()
4 years ago
end
3 years ago
--shown
local gmember_shown = function(object)
return object:IsShown()
4 years ago
end
3 years ago
--frame width
local gmember_width = function(object)
return object.slider:GetWidth()
4 years ago
end
3 years ago
--frame height
local gmember_height = function(object)
return object.slider:GetHeight()
4 years ago
end
3 years ago
--locked
local gmember_locked = function(object)
return rawget(object, "lockdown")
4 years ago
end
3 years ago
--fractional
local gmember_fractional = function(object)
return rawget(object, "useDecimals")
end
4 years ago
3 years ago
--value
local gmember_value = function(object)
return object()
end
4 years ago
3 years ago
DFSliderMetaFunctions.GetMembers = DFSliderMetaFunctions.GetMembers or {}
DFSliderMetaFunctions.GetMembers["tooltip"] = gmember_tooltip
DFSliderMetaFunctions.GetMembers["shown"] = gmember_shown
DFSliderMetaFunctions.GetMembers["width"] = gmember_width
DFSliderMetaFunctions.GetMembers["height"] = gmember_height
DFSliderMetaFunctions.GetMembers["locked"] = gmember_locked
DFSliderMetaFunctions.GetMembers["fractional"] = gmember_fractional
DFSliderMetaFunctions.GetMembers["value"] = gmember_value
DFSliderMetaFunctions.__index = function(object, key)
local func = DFSliderMetaFunctions.GetMembers[key]
4 years ago
if (func) then
3 years ago
return func(object, key)
4 years ago
end
3 years ago
local alreadyHaveKey = rawget(object, key)
if (alreadyHaveKey) then
return alreadyHaveKey
4 years ago
end
3 years ago
return DFSliderMetaFunctions[key]
4 years ago
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--tooltip
local smember_tooltip = function(object, value)
return object:SetTooltip(value)
4 years ago
end
3 years ago
--show
local smember_show = function(object, value)
if (value) then
return object:Show()
4 years ago
else
3 years ago
return object:Hide()
4 years ago
end
end
3 years ago
--hide
local smember_hide = function(object, value)
if (not value) then
return object:Show()
4 years ago
else
3 years ago
return object:Hide()
4 years ago
end
end
3 years ago
--frame width
local smember_width = function(object, value)
return object.slider:SetWidth(value)
4 years ago
end
3 years ago
--frame height
local smember_height = function(object, value)
return object.slider:SetHeight(value)
4 years ago
end
3 years ago
--locked
local smember_locked = function(object, value)
if (value) then
return object:Disable()
else
return object:Enable()
4 years ago
end
end
3 years ago
--backdrop
local smember_backdrop = function(object, value)
return object.slider:SetBackdrop(value)
4 years ago
end
3 years ago
--fractional
local smember_fractional = function(object, value)
return rawset(object, "useDecimals", value)
4 years ago
end
3 years ago
--value
local smember_value = function(object, value)
object(value)
4 years ago
end
3 years ago
DFSliderMetaFunctions.SetMembers = DFSliderMetaFunctions.SetMembers or {}
DFSliderMetaFunctions.SetMembers["tooltip"] = smember_tooltip
DFSliderMetaFunctions.SetMembers["show"] = smember_show
DFSliderMetaFunctions.SetMembers["hide"] = smember_hide
DFSliderMetaFunctions.SetMembers["backdrop"] = smember_backdrop
DFSliderMetaFunctions.SetMembers["width"] = smember_width
DFSliderMetaFunctions.SetMembers["height"] = smember_height
DFSliderMetaFunctions.SetMembers["locked"] = smember_locked
DFSliderMetaFunctions.SetMembers["fractional"] = smember_fractional
DFSliderMetaFunctions.SetMembers["value"] = smember_value
DFSliderMetaFunctions.__newindex = function(object, key, value)
local func = DFSliderMetaFunctions.SetMembers[key]
if (func) then
return func(object, value)
4 years ago
else
3 years ago
return rawset(object, key, value)
4 years ago
end
end
3 years ago
------------------------------------------------------------------------------------------------------------
--methods
--fixed value
function DFSliderMetaFunctions:SetFixedParameter(value)
rawset(self, "FixedValue", value)
4 years ago
end
function DFSliderMetaFunctions:GetFixedParameter()
return rawget(self, "FixedValue")
end
3 years ago
--set value
function DFSliderMetaFunctions:SetValue(value)
return self(value)
4 years ago
end
3 years ago
function DFSliderMetaFunctions:SetValueNoCallback(value)
self.NoCallback = true
self.slider:SetValue(value)
end
3 years ago
-- thumb size
function DFSliderMetaFunctions:SetThumbSize(width, height)
if (not width) then
width = self.thumb:GetWidth()
end
if (not height) then
height = self.thumb:GetHeight()
4 years ago
end
3 years ago
return self.thumb:SetSize(width, height)
4 years ago
end
3 years ago
--clear focus
4 years ago
function DFSliderMetaFunctions:ClearFocus()
local editbox = DFSliderMetaFunctions.editbox_typevalue
if editbox and self.typing_value then
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
editbox:GetParent().MyObject.value = self.typing_value_started
end
end
3 years ago
--enabled
4 years ago
function DFSliderMetaFunctions:IsEnabled()
3 years ago
return not rawget(self, "lockdown")
4 years ago
end
3 years ago
4 years ago
function DFSliderMetaFunctions:Enable()
self.slider:Enable()
3 years ago
4 years ago
if (not self.is_checkbox) then
if (not self.lock_texture) then
3 years ago
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self.amt, "center")
4 years ago
end
self.lock_texture:Hide()
end
3 years ago
4 years ago
self.slider.amt:Show()
3 years ago
self:SetAlpha(1)
4 years ago
if (self.is_checkbox) then
self.checked_texture:Show()
end
3 years ago
return rawset(self, "lockdown", false)
4 years ago
end
3 years ago
4 years ago
function DFSliderMetaFunctions:Disable()
self:ClearFocus()
self.slider:Disable()
self.slider.amt:Hide()
3 years ago
self:SetAlpha(.4)
4 years ago
if (not self.is_checkbox) then
if (not self.lock_texture) then
3 years ago
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self.amt, "center")
4 years ago
end
3 years ago
4 years ago
self.lock_texture:Show()
end
3 years ago
4 years ago
if (self.is_checkbox) then
self.checked_texture:Show()
end
3 years ago
return rawset(self, "lockdown", true)
4 years ago
end
------------------------------------------------------------------------------------------------------------
3 years ago
--scripts
4 years ago
3 years ago
local OnEnter = function(slider)
local object = slider.MyObject
if (rawget(object, "lockdown")) then
4 years ago
return
end
3 years ago
DetailsFrameworkSliderButtons1:ShowMe(slider, object.bAttachButtonsToLeft)
3 years ago
local kill = object:RunHooksForWidget("OnEnter", slider, object)
4 years ago
if (kill) then
return
end
3 years ago
slider.thumb:SetAlpha(1)
if (object.onenter_backdrop_border_color) then
slider:SetBackdropBorderColor(unpack(object.onenter_backdrop_border_color))
4 years ago
end
3 years ago
object:ShowTooltip()
4 years ago
end
3 years ago
local OnLeave = function(slider)
local object = slider.MyObject
if (rawget(object, "lockdown")) then
4 years ago
return
end
3 years ago
4 years ago
DetailsFrameworkSliderButtons1:PrepareToHide()
3 years ago
local kill = object:RunHooksForWidget("OnLeave", slider, object)
4 years ago
if (kill) then
return
end
3 years ago
slider.thumb:SetAlpha(.7)
if (object.onleave_backdrop_border_color) then
slider:SetBackdropBorderColor(unpack(object.onleave_backdrop_border_color))
4 years ago
end
3 years ago
object:HideTooltip()
4 years ago
end
3 years ago
--parent frame for the plus and minus buttons which shows when the slider is hovered over
local sliderButtonsParentFrame = DetailsFrameworkSliderButtons1 or CreateFrame("frame", "DetailsFrameworkSliderButtons1", UIParent, "BackdropTemplate")
sliderButtonsParentFrame:Hide()
sliderButtonsParentFrame:SetHeight(18) --width is set by setpoint
C_Timer.After(0, function()
if (not sliderButtonsParentFrame.__background) then
DetailsFramework:ApplyStandardBackdrop(sliderButtonsParentFrame) --ApplyStandardBackdrop loads after this file
end
sliderButtonsParentFrame:SetBackdropBorderColor(0, 0, 0, 0)
sliderButtonsParentFrame:SetBackdropColor(.05, .05, .05, .9)
end)
3 years ago
sliderButtonsParentFrame.isGoingToHide = false
local timeToHide = 0
local onUpdateTimeToHide = function(self, elapsed)
timeToHide = timeToHide + elapsed
if (timeToHide > 0.3) then
sliderButtonsParentFrame:Hide()
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
4 years ago
end
end
function sliderButtonsParentFrame:ShowMe(sliderFrame, bAnchorToLeft)
sliderButtonsParentFrame.bAnchorToLeft = bAnchorToLeft
3 years ago
sliderButtonsParentFrame:SetParent(sliderFrame)
sliderButtonsParentFrame:ClearAllPoints()
sliderButtonsParentFrame.buttonMinor:ClearAllPoints()
sliderButtonsParentFrame.buttonPlus:ClearAllPoints()
sliderButtonsParentFrame:SetWidth(35)
if (sliderButtonsParentFrame.bAnchorToLeft) then
sliderButtonsParentFrame:SetPoint("topright", sliderFrame, "topleft", 0, 0)
sliderButtonsParentFrame:SetPoint("bottomright", sliderFrame, "bottomleft", 0, 0)
sliderButtonsParentFrame.buttonPlus:SetPoint("right", sliderButtonsParentFrame, "right", -2, 0)
sliderButtonsParentFrame.buttonMinor:SetPoint("right", sliderButtonsParentFrame.buttonPlus, "left", 0, 0)
else
sliderButtonsParentFrame:SetPoint("topleft", sliderFrame, "topright", 2, 0)
sliderButtonsParentFrame:SetPoint("bottomleft", sliderFrame, "bottomright", 2, 0)
sliderButtonsParentFrame.buttonMinor:SetPoint("left", sliderButtonsParentFrame, "left", 2, 0)
sliderButtonsParentFrame.buttonPlus:SetPoint("left", sliderButtonsParentFrame.buttonMinor, "right", 0, 0)
end
3 years ago
sliderButtonsParentFrame:SetFrameStrata("FULLSCREEN")
sliderButtonsParentFrame:SetFrameLevel(sliderFrame:GetFrameLevel() + 1000)
sliderButtonsParentFrame:Show()
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
4 years ago
end
3 years ago
sliderButtonsParentFrame.host = sliderFrame.MyObject
4 years ago
end
3 years ago
function sliderButtonsParentFrame:PrepareToHide()
sliderButtonsParentFrame.isGoingToHide = true
timeToHide = 0
sliderButtonsParentFrame:SetScript("OnUpdate", onUpdateTimeToHide)
4 years ago
end
3 years ago
local buttonPlus = DetailsFrameworkSliderButtonsPlusButton or CreateFrame("button", "DetailsFrameworkSliderButtonsPlusButton", sliderButtonsParentFrame, "BackdropTemplate")
local buttonMinor = DetailsFrameworkSliderButtonsMinorButton or CreateFrame("button", "DetailsFrameworkSliderButtonsMinorButton", sliderButtonsParentFrame, "BackdropTemplate")
3 years ago
buttonPlus:SetFrameStrata(sliderButtonsParentFrame:GetFrameStrata())
buttonMinor:SetFrameStrata(sliderButtonsParentFrame:GetFrameStrata())
sliderButtonsParentFrame.buttonPlus = buttonPlus
sliderButtonsParentFrame.buttonMinor = buttonMinor
3 years ago
buttonPlus:SetScript("OnEnter", function(self)
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
4 years ago
end
end)
3 years ago
buttonMinor:SetScript("OnEnter", function(self)
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
4 years ago
end
end)
3 years ago
buttonPlus:SetScript("OnLeave", function(self)
sliderButtonsParentFrame:PrepareToHide()
4 years ago
end)
3 years ago
buttonMinor:SetScript("OnLeave", function(self)
sliderButtonsParentFrame:PrepareToHide()
4 years ago
end)
3 years ago
buttonPlus:SetNormalTexture([[Interface\Buttons\UI-PlusButton-Up]])
buttonMinor:SetNormalTexture([[Interface\Buttons\UI-MinusButton-Up]])
buttonPlus:SetPushedTexture([[Interface\Buttons\UI-PlusButton-Down]])
buttonMinor:SetPushedTexture([[Interface\Buttons\UI-MinusButton-Down]])
buttonPlus:SetDisabledTexture([[Interface\Buttons\UI-PlusButton-Disabled]])
buttonMinor:SetDisabledTexture([[Interface\Buttons\UI-MinusButton-Disabled]])
buttonPlus:SetHighlightTexture([[Interface\Buttons\UI-PlusButton-Hilight]])
buttonMinor:SetHighlightTexture([[Interface\Buttons\UI-PlusButton-Hilight]])
C_Timer.After(0, function()
DF:SetButtonTexture(buttonPlus, "AlliedRace-UnlockingFrame-ZoomIn")
DF:SetButtonTexture(buttonMinor, "AlliedRace-UnlockingFrame-ZoomOut")
end)
buttonMinor:ClearAllPoints()
buttonPlus:ClearAllPoints()
3 years ago
buttonMinor:SetPoint("bottomright", sliderButtonsParentFrame, "bottomright", 13, -13)
buttonPlus:SetPoint("left", buttonMinor, "right", -2, 0)
buttonPlus:SetSize(16, 16)
buttonMinor:SetSize(16, 16)
buttonPlus:SetAlpha(0.834)
buttonMinor:SetAlpha(0.834)
3 years ago
--increate the value on pressing the button or holding the button pressed
local buttonPlusOnClick = function()
local sliderObject = sliderButtonsParentFrame.host
local currentValueOnSlider = sliderObject.value
local editboxShowingValue = DFSliderMetaFunctions.editbox_typevalue
if (sliderObject.fine_tuning) then
sliderObject:SetValue(currentValueOnSlider + sliderObject.fine_tuning)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.2f", currentValueOnSlider + sliderObject.fine_tuning)))
4 years ago
end
else
3 years ago
if (sliderObject.useDecimals) then
sliderObject:SetValue(currentValueOnSlider + 0.1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(string.format("%.2f", currentValueOnSlider + 0.1))
4 years ago
end
else
3 years ago
sliderObject:SetValue(currentValueOnSlider + 1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(currentValueOnSlider + 1)))
4 years ago
end
end
end
end
3 years ago
buttonPlus:SetScript("OnMouseUp", function(self)
if (not buttonPlus.got_click) then
3 years ago
buttonPlusOnClick()
4 years ago
end
buttonPlus.got_click = false
3 years ago
self:SetScript("OnUpdate", nil)
4 years ago
end)
3 years ago
--hold the plus or minus button for x amount of time before start changing the value
local delayBeforeStartSimulatingClicks = 0
--after the delay been passed, trigger a click each x seconds
local simulateClickTimer = 0
local buttonPlusOnUpdate = function(self, deltaTime)
delayBeforeStartSimulatingClicks = delayBeforeStartSimulatingClicks + deltaTime
if (delayBeforeStartSimulatingClicks > 0.4) then
simulateClickTimer = simulateClickTimer + deltaTime
if (simulateClickTimer > 0.1) then
simulateClickTimer = 0
buttonPlusOnClick()
buttonPlus.got_click = true
4 years ago
end
end
end
3 years ago
buttonPlus:SetScript("OnMouseDown", function(self)
delayBeforeStartSimulatingClicks = 0
simulateClickTimer = 0
self:SetScript("OnUpdate", buttonPlusOnUpdate)
4 years ago
end)
3 years ago
4 years ago
-- -- --
3 years ago
--increate the value on pressing the button or holding the button pressed
local buttonMinusOnClick = function()
local sliderObject = sliderButtonsParentFrame.host
local currentValueOnSlider = sliderObject.value
local editboxShowingValue = DFSliderMetaFunctions.editbox_typevalue
if (sliderObject.fine_tuning) then
sliderObject:SetValue(currentValueOnSlider - sliderObject.fine_tuning)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.2f", currentValueOnSlider - sliderObject.fine_tuning)))
4 years ago
end
else
3 years ago
if (sliderObject.useDecimals) then
sliderObject:SetValue(currentValueOnSlider - 0.1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(string.format("%.2f", currentValueOnSlider - 0.1))
4 years ago
end
else
3 years ago
sliderObject:SetValue(currentValueOnSlider - 1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(currentValueOnSlider - 1)))
4 years ago
end
end
end
end
3 years ago
buttonMinor:SetScript("OnMouseUp", function(self)
if (not buttonMinor.got_click) then
3 years ago
buttonMinusOnClick()
4 years ago
end
buttonMinor.got_click = false
3 years ago
self:SetScript("OnUpdate", nil)
4 years ago
end)
3 years ago
local buttonMinusOnUpdate = function(self, elapsed)
delayBeforeStartSimulatingClicks = delayBeforeStartSimulatingClicks + elapsed
if (delayBeforeStartSimulatingClicks > 0.4) then
simulateClickTimer = simulateClickTimer + elapsed
if (simulateClickTimer > 0.1) then
simulateClickTimer = 0
buttonMinusOnClick()
buttonMinor.got_click = true
4 years ago
end
end
end
3 years ago
buttonMinor:SetScript("OnMouseDown", function(self)
delayBeforeStartSimulatingClicks = 0
simulateClickTimer = 0
self:SetScript("OnUpdate", buttonMinusOnUpdate)
4 years ago
end)
3 years ago
local do_precision = function(text)
if (type(text) == "string" and text:find("%.")) then
local left, right = strsplit(".", text)
left = tonumber(left)
right = tonumber(right)
4 years ago
if (left and right) then
3 years ago
local newString = tostring(left) .. "." .. tostring(right)
local newNumber = tonumber(newString)
4 years ago
if (newNumber) then
return newNumber
end
end
end
3 years ago
return tonumber(text)
4 years ago
end
DF.TextToFloor = do_precision
3 years ago
4 years ago
function DFSliderMetaFunctions:TypeValue()
if (not self.isSwitch) then
if (not DFSliderMetaFunctions.editbox_typevalue) then
3 years ago
local editbox = CreateFrame("EditBox", "DetailsFrameworkSliderEditBox", UIParent, "BackdropTemplate")
editbox:SetSize(40, 20)
editbox:SetJustifyH("center")
DF:ApplyStandardBackdrop(editbox)
editbox:SetFontObject("GameFontHighlightSmall")
editbox:SetScript("OnEnterPressed", function()
4 years ago
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
3 years ago
editbox:GetParent().MyObject.value = tonumber(editbox:GetText()) --do_precision (editbox:GetText())
4 years ago
end)
3 years ago
editbox:SetScript("OnEscapePressed", function()
4 years ago
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
editbox:GetParent().MyObject.value = self.typing_value_started --do_precision (self.typing_value_started)
end)
3 years ago
editbox:SetScript("OnTextChanged", function()
4 years ago
editbox:GetParent().MyObject.typing_can_change = true
3 years ago
editbox:GetParent().MyObject.value = tonumber(editbox:GetText()) --do_precision
4 years ago
editbox:GetParent().MyObject.typing_can_change = false
end)
3 years ago
4 years ago
DFSliderMetaFunctions.editbox_typevalue = editbox
end
3 years ago
local pvalue = self.previous_value[2]
3 years ago
self:SetValue(pvalue)
4 years ago
self.typing_value = true
self.typing_value_started = pvalue
3 years ago
DFSliderMetaFunctions.editbox_typevalue:SetSize(self.width, self.height)
DFSliderMetaFunctions.editbox_typevalue:SetPoint("center", self.widget, "center")
4 years ago
DFSliderMetaFunctions.editbox_typevalue:SetFocus()
3 years ago
DFSliderMetaFunctions.editbox_typevalue:SetParent(self.widget)
DFSliderMetaFunctions.editbox_typevalue:SetFrameLevel(self.widget:GetFrameLevel()+1)
4 years ago
if (self.useDecimals) then
3 years ago
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.1f", self.value)))
4 years ago
else
3 years ago
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(self.value)))
4 years ago
end
3 years ago
4 years ago
DFSliderMetaFunctions.editbox_typevalue:HighlightText()
3 years ago
4 years ago
DFSliderMetaFunctions.editbox_typevalue:Show()
end
end
3 years ago
local OnMouseDown = function(slider, button)
local object = slider.MyObject
object.IsValueChanging = true
3 years ago
local kill = object:RunHooksForWidget("OnMouseDown", slider, button, object)
4 years ago
if (kill) then
return
end
3 years ago
4 years ago
if (button == "RightButton") then
object:TypeValue()
4 years ago
end
end
3 years ago
local OnMouseUp = function(slider, button)
local object = slider.MyObject
object.IsValueChanging = nil
3 years ago
local kill = object:RunHooksForWidget("OnMouseUp", slider, button, object)
4 years ago
if (kill) then
return
end
end
3 years ago
local OnHide = function(slider)
local object = slider.MyObject
local kill = object:RunHooksForWidget("OnHide", slider, object)
4 years ago
if (kill) then
return
end
3 years ago
if (object.typing_value) then
4 years ago
DFSliderMetaFunctions.editbox_typevalue:ClearFocus()
3 years ago
DFSliderMetaFunctions.editbox_typevalue:SetText("")
object.typing_valu = false
4 years ago
end
end
3 years ago
local OnShow = function(slider)
local object = slider.MyObject
local kill = object:RunHooksForWidget("OnShow", slider, object)
4 years ago
if (kill) then
return
end
end
3 years ago
local OnValueChanged = function(slider)
local object = slider.MyObject
3 years ago
4 years ago
local amt
if (object.useDecimals) then
4 years ago
amt = slider:GetValue()
else
amt = do_precision(slider:GetValue())
end
if (object.typing_value and not object.typing_can_change) then
object:SetValue(object.typing_value_started)
4 years ago
return
end
table.insert(object.previous_value, 1, amt)
table.remove(object.previous_value, 4)
4 years ago
if (object.useDecimals) then
slider.amt:SetText(string.format("%.2f", amt))
else
slider.amt:SetText(math.floor(amt))
end
object.ivalue = amt
if (object.NoCallback) then
object.NoCallback = false
return
end
4 years ago
--some plugins registered OnValueChanged and others with OnValueChange
local kill = object:RunHooksForWidget("OnValueChanged", slider, object.FixedValue, amt, object)
4 years ago
if (kill) then
return
end
local kill = object:RunHooksForWidget("OnValueChange", slider, object.FixedValue, amt, object)
4 years ago
if (kill) then
return
3 years ago
end
if (object.OnValueChanged) then
object.OnValueChanged(slider, object.FixedValue, amt)
4 years ago
end
end
------------------------------------------------------------------------------------------------------------
3 years ago
--object constructor
4 years ago
3 years ago
local SwitchOnClick = function(self, button, forced_value, value)
local object = self.MyObject
4 years ago
if (rawget(object, "lockdown")) then
4 years ago
return
end
3 years ago
4 years ago
if (forced_value) then
rawset(object, "value", not value)
4 years ago
end
if (rawget(object, "value")) then --actived
rawset(object, "value", false)
3 years ago
if (object.backdrop_disabledcolor) then
object:SetBackdropColor(unpack(object.backdrop_disabledcolor))
4 years ago
else
object:SetBackdropColor(1, 0, 0, 0.4)
4 years ago
end
3 years ago
if (object.is_checkbox) then
object.checked_texture:Hide()
4 years ago
else
object._text:SetText(object._ltext)
object._thumb:ClearAllPoints()
object._thumb:SetPoint("left", object.widget, "left")
4 years ago
end
else
rawset(object, "value", true)
if (object.backdrop_enabledcolor) then
object:SetBackdropColor(unpack(object.backdrop_enabledcolor))
4 years ago
else
object:SetBackdropColor(0, 0, 1, 0.4)
4 years ago
end
if (object.is_checkbox) then
object.checked_texture:Show()
4 years ago
else
object._text:SetText(object._rtext)
object._thumb:ClearAllPoints()
object._thumb:SetPoint("right", object.widget, "right")
4 years ago
end
end
if (object.OnSwitch and not forced_value) then
local value = rawget(object, "value")
if (object.return_func) then
value = object:return_func (value)
4 years ago
end
local success, errorText = xpcall(object.OnSwitch, geterrorhandler(), object, object.FixedValue, value)
4 years ago
if (not success) then
return
end
3 years ago
--trigger hooks
object:RunHooksForWidget("OnSwitch", object, object.FixedValue, value)
4 years ago
end
end
3 years ago
local switch_get_value = function(self)
4 years ago
return self.value
end
3 years ago
local switch_set_value = function(self, value)
4 years ago
if (self.switch_func) then
value = self:switch_func(value)
4 years ago
end
3 years ago
4 years ago
SwitchOnClick (self.widget, nil, true, value)
end
3 years ago
local switch_set_fixparameter = function(self, value)
rawset(self, "FixedValue", value)
4 years ago
end
local switch_get_fixparameter = function(self)
return rawget(self, "FixedValue")
end
3 years ago
local switch_disable = function(self)
4 years ago
if (self.is_checkbox) then
self.checked_texture:Hide()
else
self._text:Hide()
if (not self.lock_texture) then
3 years ago
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self._thumb, "center")
4 years ago
end
self.lock_texture:Show()
end
3 years ago
self:SetAlpha(.4)
rawset(self, "lockdown", true)
4 years ago
end
3 years ago
local switch_enable = function(self)
4 years ago
if (self.is_checkbox) then
3 years ago
if (rawget(self, "value")) then
4 years ago
self.checked_texture:Show()
else
self.checked_texture:Hide()
end
else
if (not self.lock_texture) then
3 years ago
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self._thumb, "center")
4 years ago
end
self.lock_texture:Hide()
self._text:Show()
end
3 years ago
self:SetAlpha(1)
return rawset(self, "lockdown", false)
4 years ago
end
3 years ago
local set_switch_func = function(self, newFunction)
4 years ago
self.OnSwitch = newFunction
end
local get_switch_func = function(self)
return self.OnSwitch
end
local setCheckedTexture = function(self, texture, xOffSet, yOffSet, sizePercent, color)
if (texture) then
self.checked_texture:SetTexture(texture, "CLAMP", "CLAMP", "TRILINEAR")
end
if (xOffSet or yOffSet) then
self.checked_texture:SetPoint("center", self.button, "center", xOffSet or -1, yOffSet or -1)
else
self.checked_texture:SetPoint("center", self.button, "center", -1, -1)
end
if (sizePercent and type(sizePercent) == "number") then
local width = self:GetWidth() * sizePercent
self.checked_texture:SetSize(width, width)
end
if (color) then
local r, g, b, a = DF:ParseColors(color)
self.checked_texture:SetVertexColor(r, g, b, a)
end
end
3 years ago
local set_as_checkbok = function(self)
4 years ago
if self.is_checkbox and self.checked_texture then return end
3 years ago
local checked = self:CreateTexture(self:GetName() .. "CheckTexture", "overlay")
checked:SetTexture([[Interface\Buttons\UI-CheckBox-Check]])
checked:SetPoint("center", self.button, "center", -1, -1)
4 years ago
local size_pct = self:GetWidth()/32
checked:SetSize(32 * size_pct, 32 * size_pct)
4 years ago
self.checked_texture = checked
3 years ago
self.SetCheckedTexture = setCheckedTexture
self.SetChecked = switch_set_value
self.GetChecked = switch_get_value
4 years ago
self._thumb:Hide()
self._text:Hide()
self.is_checkbox = true
3 years ago
if (rawget(self, "value")) then
4 years ago
self.checked_texture:Show()
if (self.backdrop_enabledcolor) then
3 years ago
self:SetBackdropColor(unpack(self.backdrop_enabledcolor))
4 years ago
else
3 years ago
self:SetBackdropColor(0, 0, 1, 0.4)
end
4 years ago
else
self.checked_texture:Hide()
if (self.backdrop_disabledcolor) then
3 years ago
self:SetBackdropColor(unpack(self.backdrop_disabledcolor))
4 years ago
else
3 years ago
self:SetBackdropColor(0, 0, 1, 0.4)
4 years ago
end
end
end
---@class df_checkbox : df_button, df_widgets
---@field OnSwitch fun(self:df_checkbox, fixedValue:any, value:boolean)
---@field SetValue fun(self:df_button, value:boolean)
---@field GetValue fun(self:df_button):boolean
---@field SetFixedParameter fun(self:df_button, value:any)
---@field GetFixedParameter fun(self:df_button):any
---@field Disable fun(self:df_button)
---@field Enable fun(self:df_button)
---@field SetAsCheckBox fun(self:df_button)
---@field SetTemplate fun(self:df_button, template: table)
---@field GetSwitchFunction fun(self:df_button):function
---@field SetSwitchFunction fun(self:df_button, newOnSwitchFunction: function)
---@field GetCapsule fun(self:df_button):df_button capsule only exists in the actual frame of the encapsulated widget
---@field SetCheckedTexture fun(self:df_button, texture:string)
function DF:CreateSwitch(parent, onSwitch, defaultValue, width, height, leftText, rightText, member, name, colorInverted, switchFunc, returnFunc, withLabel, switch_template, label_template)
local switch, label = DF:NewSwitch(parent, parent, name, member, width or 60, height or 20, leftText, rightText, defaultValue, colorInverted, switchFunc, returnFunc, withLabel, switch_template, label_template)
if (onSwitch) then
switch.OnSwitch = onSwitch
4 years ago
end
---@cast switch df_checkbox
---@cast label df_label
4 years ago
return switch, label
end
function DF:NewSwitch(parent, container, name, member, width, height, leftText, rightText, defaultValue, colorInverted, switch_func, return_func, with_label, switch_template, label_template)
3 years ago
--early checks
4 years ago
if (not name) then
name = "DetailsFrameWorkSlider" .. DF.SwitchCounter
DF.SwitchCounter = DF.SwitchCounter + 1
4 years ago
elseif (not parent) then
3 years ago
return error("Details! FrameWork: parent not found.", 2)
4 years ago
end
4 years ago
if (not container) then
container = parent
end
3 years ago
--defaults
leftText = leftText or "OFF"
rightText = rightText or "ON"
3 years ago
--build frames
width = width or 60
height = height or 20
3 years ago
local slider = DF:NewButton(parent, container, name, member, width, height)
4 years ago
slider.HookList.OnSwitch = {}
slider.type = "switch"
3 years ago
4 years ago
slider.switch_func = switch_func
slider.return_func = return_func
slider.SetValue = switch_set_value
slider.GetValue = switch_get_value
slider.SetFixedParameter = switch_set_fixparameter
slider.GetFixedParameter = switch_get_fixparameter
4 years ago
slider.Disable = switch_disable
slider.Enable = switch_enable
slider.SetAsCheckBox = set_as_checkbok
slider.SetTemplate = DFSliderMetaFunctions.SetTemplate
slider.SetSwitchFunction = set_switch_func
slider.GetSwitchFunction = get_switch_func
3 years ago
4 years ago
if (member) then
parent[member] = slider
4 years ago
end
3 years ago
slider:SetBackdrop({edgeFile = [[Interface\Buttons\UI-SliderBar-Border]], edgeSize = 8,
4 years ago
bgFile = [[Interface\AddOns\Details\images\background]], insets = {left = 3, right = 3, top = 5, bottom = 5}})
3 years ago
local thumb = slider:CreateTexture(nil, "artwork")
thumb:SetTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
thumb:SetSize(34+(height*0.2), height*1.2)
3 years ago
thumb:SetAlpha(0.7)
thumb:SetPoint("left", slider.widget, "left")
local text = slider:CreateFontString(nil, "overlay", "GameFontHighlightSmall")
text:SetTextColor(.8, .8, .8, 1)
text:SetPoint("center", thumb, "center")
4 years ago
slider._text = text
slider._thumb = thumb
slider._ltext = leftText
slider._rtext = rightText
4 years ago
slider.thumb = thumb
slider.invert_colors = colorInverted
4 years ago
3 years ago
slider:SetScript("OnClick", SwitchOnClick)
slider:SetValue(defaultValue)
4 years ago
slider.isSwitch = true
3 years ago
4 years ago
if (switch_template) then
3 years ago
slider:SetTemplate(switch_template)
4 years ago
end
3 years ago
4 years ago
if (with_label) then
3 years ago
local label = DF:CreateLabel(slider.widget, with_label, nil, nil, nil, "label", nil, "overlay")
4 years ago
label.text = with_label
PixelUtil.SetPoint(slider.widget, "left", label.widget, "right", 2, 0)
4 years ago
with_label = label
3 years ago
4 years ago
if (label_template) then
3 years ago
label:SetTemplate(label_template)
4 years ago
end
end
return slider, with_label
end
3 years ago
function DFSliderMetaFunctions:SetTemplate(template)
template = DF:ParseTemplate(self.type, template)
4 years ago
--slider e switch
if (template.width) then
PixelUtil.SetWidth(self.widget, template.width)
4 years ago
end
if (template.height) then
PixelUtil.SetHeight(self.widget, template.height)
4 years ago
end
3 years ago
4 years ago
if (template.backdrop) then
3 years ago
self:SetBackdrop(template.backdrop)
4 years ago
end
if (template.backdropcolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.backdropcolor)
self:SetBackdropColor(r, g, b, a)
4 years ago
end
if (template.backdropbordercolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.backdropbordercolor)
self:SetBackdropBorderColor(r, g, b, a)
4 years ago
self.onleave_backdrop_border_color = {r, g, b, a}
end
3 years ago
4 years ago
if (template.onenterbordercolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.onenterbordercolor)
4 years ago
self.onenter_backdrop_border_color = {r, g, b, a}
end
3 years ago
4 years ago
if (template.onleavebordercolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.onleavebordercolor)
4 years ago
self.onleave_backdrop_border_color = {r, g, b, a}
end
if (template.thumbtexture) then
if (self.thumb) then
DF:SetAtlas(self.thumb, template.thumbtexture)
end
end
if (template.slider_left) then
if (self.slider_left) then
DF:SetAtlas(self.slider_left, template.slider_left)
end
end
if (template.slider_right) then
if (self.slider_right) then
DF:SetAtlas(self.slider_right, template.slider_right)
end
end
if (template.slider_middle) then
if (self.slider_middle) then
self:SetBackdrop(nil)
DF:SetAtlas(self.slider_middle, template.slider_middle)
4 years ago
end
end
4 years ago
if (template.thumbwidth) then
if (self.thumb) then
3 years ago
self.thumb:SetWidth(template.thumbwidth)
4 years ago
end
end
if (template.thumbheight) then
if (self.thumb) then
3 years ago
self.thumb:SetHeight(template.thumbheight)
4 years ago
end
end
if (template.thumbcolor) then
if (self.thumb) then
3 years ago
local r, g, b, a = DF:ParseColors(template.thumbcolor)
self.thumb:SetVertexColor(r, g, b, a)
4 years ago
end
end
3 years ago
if (template.amount_color) then
DF:SetFontColor(self.amt, template.amount_color)
end
if (template.amount_outline) then
DF:SetFontOutline(self.amt, template.amount_outline)
end
if (template.amount_size) then
DF:SetFontSize(self.amt, template.amount_size)
end
4 years ago
--switch only
if (template.enabled_backdropcolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.enabled_backdropcolor)
4 years ago
self.backdrop_enabledcolor = {r, g, b, a}
end
if (template.disabled_backdropcolor) then
3 years ago
local r, g, b, a = DF:ParseColors(template.disabled_backdropcolor)
4 years ago
self.backdrop_disabledcolor = {r, g, b, a}
end
if (template.is_checkbox) then
self:SetAsCheckBox()
self:SetCheckedTexture(template.checked_texture, template.checked_xoffset or 0, template.checked_yoffset or 0, template.checked_size_percent or 0.7, template.checked_color)
end
if (template.rounded_corner) then
self:SetBackdrop(nil)
DF:AddRoundedCornersToFrame(self.widget or self, template.rounded_corner)
end
4 years ago
end
--DF:Mixin(DFSliderMetaFunctions, DF.SetPointMixin)
--DF:Mixin(DFSliderMetaFunctions, DF.FrameMixin)
--DF:Mixin(DFSliderMetaFunctions, DF.TooltipHandlerMixin)
---@class df_slider : slider, df_scripthookmixin, df_widgets
---@field tooltip string?
---@field widget slider
---@field slider slider
---@field type string
---@field dframework boolean
---@field SetTemplate fun(self:df_slider, template: table|string)
---@field SetFixedParameter fun(value: any)
---@field GetFixedParameter fun()
---@field SetValueNoCallback fun(value: number)
---@field SetThumbSize fun(width:number, height:number)
---@field ClearFocus fun()
---@param parent frame
---@param width number? default 150
---@param height number? default 20
---@param minValue number? default 1
---@param maxValue number? default 2
---@param step number? default 1
---@param defaultv number? default to minValue
---@param isDecemal boolean? default false
---@param member string?
---@param name string?
---@param label string?
---@param sliderTemplate string|table|nil
---@param labelTemplate string|table|nil
---@return df_slider, df_label?
function DF:CreateSlider (parent, width, height, minValue, maxValue, step, defaultv, isDecemal, member, name, label, sliderTemplate, labelTemplate)
local slider, labelText = DF:NewSlider(parent, parent, name, member, width, height, minValue, maxValue, step, defaultv, isDecemal, false, label, sliderTemplate, labelTemplate)
return slider, labelText
4 years ago
end
---@return df_slider, df_label?
3 years ago
function DF:NewSlider (parent, container, name, member, width, height, minValue, maxValue, step, defaultValue, isDecemal, isSwitch, with_label, slider_template, label_template)
4 years ago
if (not name) then
name = "DetailsFrameworkSlider" .. DF.SliderCounter
DF.SliderCounter = DF.SliderCounter + 1
end
4 years ago
if (not parent) then
error("Details! FrameWork: parent not found.", 2)
4 years ago
end
4 years ago
if (not container) then
container = parent
end
3 years ago
if (name:find("$parent")) then
local parentName = DF:GetParentName(parent)
3 years ago
name = name:gsub("$parent", parentName)
4 years ago
end
3 years ago
4 years ago
local SliderObject = {type = "slider", dframework = true}
3 years ago
4 years ago
if (member) then
parent[member] = SliderObject
3 years ago
end
4 years ago
if (parent.dframework) then
parent = parent.widget
end
if (container.dframework) then
container = container.widget
end
3 years ago
--defaults
3 years ago
minValue = minValue or 1
maxValue = maxValue or 2
4 years ago
step = step or 1
3 years ago
defaultValue = defaultValue or minValue
width = width or 160
height = height or 20
3 years ago
--default members
SliderObject.lockdown = false
SliderObject.container = container
3 years ago
SliderObject.slider = CreateFrame("slider", name, parent,"BackdropTemplate")
4 years ago
SliderObject.widget = SliderObject.slider
SliderObject.useDecimals = isDecemal or false
3 years ago
4 years ago
if (SliderObject.useDecimals) then
3 years ago
SliderObject.slider:SetValueStep(0.01)
4 years ago
else
3 years ago
SliderObject.slider:SetValueStep(step)
SliderObject.slider:SetObeyStepOnDrag(true)
4 years ago
end
3 years ago
4 years ago
if (not APISliderFunctions) then
APISliderFunctions = true
3 years ago
local idx = getmetatable(SliderObject.slider).__index
for funcName, funcAddress in pairs(idx) do
if (not DFSliderMetaFunctions[funcName]) then
DFSliderMetaFunctions[funcName] = function(object, ...)
local x = loadstring( "return _G['" .. object.slider:GetName() .. "']:" .. funcName .. "(...)")
3 years ago
return x(...)
4 years ago
end
end
end
end
3 years ago
4 years ago
SliderObject.slider.MyObject = SliderObject
PixelUtil.SetSize(SliderObject.slider, width, height)
SliderObject.slider:SetOrientation("horizontal")
3 years ago
SliderObject.slider:SetMinMaxValues(minValue, maxValue)
SliderObject.slider:SetValue(defaultValue)
SliderObject.ivalue = defaultValue
4 years ago
3 years ago
SliderObject.slider:SetBackdrop({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8})
SliderObject.slider:SetBackdropColor(0.9, 0.7, 0.7, 1.0)
4 years ago
3 years ago
SliderObject.thumb = SliderObject.slider:CreateTexture(nil, "artwork")
SliderObject.thumb:SetTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
SliderObject.thumb:SetSize(30 + (height * 0.2), height * 1.2)
4 years ago
SliderObject.thumb.originalWidth = SliderObject.thumb:GetWidth()
3 years ago
SliderObject.thumb.originalHeight = SliderObject.thumb:GetHeight()
SliderObject.thumb:SetAlpha(0.7)
4 years ago
SliderObject.slider:SetThumbTexture (SliderObject.thumb)
SliderObject.slider.thumb = SliderObject.thumb
3 years ago
SliderObject.slider_left = SliderObject.slider:CreateTexture("$parentLeft", "artwork")
SliderObject.slider_left:SetPoint("topright", SliderObject.slider, "topleft", 0, 0)
SliderObject.slider_left:SetPoint("bottomright", SliderObject.slider, "bottomleft", 0, 0)
SliderObject.slider_left:SetWidth(11)
SliderObject.slider_right = SliderObject.slider:CreateTexture("$parentRight", "artwork")
SliderObject.slider_right:SetPoint("topleft", SliderObject.slider, "topright", 0, 0)
SliderObject.slider_right:SetPoint("bottomleft", SliderObject.slider, "bottomright", 0, 0)
SliderObject.slider_right:SetWidth(11)
SliderObject.slider_middle = SliderObject.slider:CreateTexture("$parentMiddle", "artwork")
SliderObject.slider_middle:SetPoint("topleft", SliderObject.slider_left, "topright", 0, 0)
SliderObject.slider_middle:SetPoint("bottomleft", SliderObject.slider_left, "bottomright", 0, 0)
SliderObject.slider_middle:SetPoint("topright", SliderObject.slider_right, "topleft", 0, 0)
SliderObject.slider_middle:SetPoint("bottomright", SliderObject.slider_right, "bottomleft", 0, 0)
4 years ago
if (not isSwitch) then
SliderObject.have_tooltip = "Right Click to Type the Value"
end
3 years ago
SliderObject.amt = SliderObject.slider:CreateFontString(nil, "overlay", "GameFontHighlightSmall")
local amt = defaultValue
4 years ago
if (amt < 10 and amt >= 1) then
3 years ago
amt = "0" .. amt
4 years ago
end
3 years ago
4 years ago
if (SliderObject.useDecimals) then
3 years ago
SliderObject.amt:SetText(string.format("%.2f", amt))
4 years ago
else
3 years ago
SliderObject.amt:SetText(math.floor(amt))
4 years ago
end
3 years ago
SliderObject.amt:SetTextColor(.8, .8, .8, 1)
SliderObject.amt:SetPoint("center", SliderObject.thumb, "center")
4 years ago
SliderObject.slider.amt = SliderObject.amt
3 years ago
SliderObject.previous_value = {defaultValue or 0, 0, 0}
--hooks
4 years ago
SliderObject.HookList = {
OnEnter = {},
OnLeave = {},
OnHide = {},
OnShow = {},
OnMouseDown = {},
OnMouseUp = {},
3 years ago
4 years ago
OnValueChange = {},
OnValueChanged = {},
}
3 years ago
SliderObject.slider:SetScript("OnEnter", OnEnter)
SliderObject.slider:SetScript("OnLeave", OnLeave)
SliderObject.slider:SetScript("OnHide", OnHide)
SliderObject.slider:SetScript("OnShow", OnShow)
SliderObject.slider:SetScript("OnValueChanged", OnValueChanged)
SliderObject.slider:SetScript("OnMouseDown", OnMouseDown)
SliderObject.slider:SetScript("OnMouseUp", OnMouseUp)
setmetatable(SliderObject, DFSliderMetaFunctions)
SliderObject:SetTooltip("right click to type the value")
4 years ago
if (with_label) then
3 years ago
local label = DF:CreateLabel(SliderObject.slider, with_label, nil, nil, nil, "label", nil, "overlay")
4 years ago
label.text = with_label
3 years ago
SliderObject.slider:SetPoint("left", label.widget, "right", 2, 0)
4 years ago
with_label = label
3 years ago
4 years ago
if (label_template) then
3 years ago
label:SetTemplate(label_template)
4 years ago
end
SliderObject.label = label
4 years ago
end
3 years ago
4 years ago
if (slider_template) then
3 years ago
SliderObject:SetTemplate(slider_template)
4 years ago
end
3 years ago
4 years ago
return SliderObject, with_label
3 years ago
end
DF.AdjustmentSliderOptions = {
width = 70,
height = 20,
scale_factor = 1,
}
DF.AdjustmentSliderFunctions = {
SetScaleFactor = function(self, scalar)
self.options.scale_factor = scalar or 1
end,
GetScaleFactor = function(self, scalar)
return self.options.scale_factor
end,
SetCallback = function(self, func)
self.callback = func
end,
SetPayload = function(self, ...)
self.payload = {...}
end,
RunCallback = function(adjustmentSlider, valueX, valueY, isLiteral)
local result, errorText = pcall(adjustmentSlider.callback, adjustmentSlider, valueX, valueY, isLiteral, adjustmentSlider:DumpPayload())
if (not result) then
DF:Msg("AdjustmentSlider callback Error:", errorText)
return false
end
end,
--calculate if the mouse has moved and call a callback
PressingOnUpdate = function(adjustmentSlider, deltaTime)
if (GetTime() > adjustmentSlider.NextTick) then
--get currentr mouse position
local mouseX, mouseY = GetCursorPosition()
local verticalValue
local horizontalValue
--find distance
local xDelta = adjustmentSlider.MouseX - mouseX --moving the mouse to right or up result in a negative delta
local yDelta = adjustmentSlider.MouseY - mouseY
if (adjustmentSlider.buttonPressed ~= "center") then
if (adjustmentSlider.buttonPressedTime + 0.5 < GetTime()) then
local scaleResultBy = adjustmentSlider:GetScaleFactor()
if (adjustmentSlider.buttonPressed == "left") then
DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, -1 * scaleResultBy, 0, true)
elseif (adjustmentSlider.buttonPressed == "right") then
DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, 1 * scaleResultBy, 0, true)
end
end
elseif (xDelta ~= 0 or yDelta ~= 0) then
if (adjustmentSlider.buttonPressed == "center") then
--invert axis as left is positive and right is negative in the deltas
xDelta = xDelta * -1
yDelta = yDelta * -1
horizontalValue = DF:MapRangeClamped(-20, 20, -1, 1, xDelta)
verticalValue = DF:MapRangeClamped(-20, 20, -1, 1, yDelta)
local speed = 6 --how fast it moves
local mouseDirection = CreateVector2D(mouseX - adjustmentSlider.initialMouseX, mouseY - adjustmentSlider.initialMouseY)
local length = DF:MapRangeClamped(-100, 100, -1, 1, mouseDirection:GetLength())
mouseDirection:Normalize()
mouseDirection:ScaleBy(speed * length)
adjustmentSlider.centerArrowArtwork:SetPoint("center", adjustmentSlider.centerButton.widget, "center", mouseDirection:GetXY())
end
local scaleResultBy = adjustmentSlider:GetScaleFactor()
DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, horizontalValue * scaleResultBy, verticalValue * scaleResultBy, false)
adjustmentSlider.MouseX = mouseX
adjustmentSlider.MouseY = mouseY
end
adjustmentSlider.NextTick = GetTime() + 0.05
end
end,
--button can be the left or right button
OnButtonDownkHook = function(button)
local object = button.MyObject
3 years ago
--change the icon
if (object.direction == "center") then
3 years ago
DF:DisableOnEnterScripts()
end
local adjustmentSlider = object:GetParent()
3 years ago
adjustmentSlider.NextTick = GetTime() + 0.05
--save where the mouse is on the moment of the click
local mouseX, mouseY = GetCursorPosition()
adjustmentSlider.MouseX = mouseX
adjustmentSlider.MouseY = mouseY
adjustmentSlider.initialMouseX = mouseX
adjustmentSlider.initialMouseY = mouseY
adjustmentSlider.buttonPressed = object.direction
3 years ago
--start monitoring the mouse moviment
adjustmentSlider.buttonPressedTime = GetTime()
adjustmentSlider:SetScript("OnUpdate", DF.AdjustmentSliderFunctions.PressingOnUpdate)
end,
--button can be the left or right button
OnButtonUpHook = function(button)
local object = button.MyObject
3 years ago
--change the icon
if (object.direction == "center") then
3 years ago
DF:EnableOnEnterScripts()
end
local adjustmentSlider = object:GetParent()
3 years ago
--check if the mouse did not moved at all, if not send a callback with a value of 1
local mouseX, mouseY = GetCursorPosition()
if (mouseX == adjustmentSlider.MouseX and mouseY == adjustmentSlider.MouseY and adjustmentSlider.buttonPressedTime+0.5 > GetTime()) then
if (object.direction == "left") then
3 years ago
DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, -1, 0, true)
elseif (object.direction == "right") then
3 years ago
DF.AdjustmentSliderFunctions.RunCallback(adjustmentSlider, 1, 0, true)
end
end
adjustmentSlider.centerArrowArtwork:SetPoint("center", adjustmentSlider.centerButton.widget, "center", 0, 0)
adjustmentSlider:SetScript("OnUpdate", nil)
end,
Disable = function(adjustmentSlider)
adjustmentSlider.leftButton:Disable()
adjustmentSlider.rightButton:Disable()
adjustmentSlider.centerButton:Disable()
end,
Enable = function(adjustmentSlider)
adjustmentSlider.leftButton:Enable()
adjustmentSlider.rightButton:Enable()
adjustmentSlider.centerButton:Enable()
end,
}
local createAdjustmentSliderFrames = function(parent, options, name)
--frame it self
local adjustmentSlider = CreateFrame("frame", name, parent, "BackdropTemplate")
DF:Mixin(adjustmentSlider, DF.OptionsFunctions)
DF:Mixin(adjustmentSlider, DF.AdjustmentSliderFunctions)
DF:Mixin(adjustmentSlider, DF.PayloadMixin)
DF:Mixin(adjustmentSlider, DF.SetPointMixin)
--DF:Mixin(adjustmentSlider, DF.FrameMixin)
adjustmentSlider:BuildOptionsTable(DF.AdjustmentSliderOptions, options)
adjustmentSlider:SetSize(adjustmentSlider.options.width, adjustmentSlider.options.height)
local leftButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "left", -1, nil, nil, name .. "LeftButton")
local rightButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "right", 1, nil, nil, name .. "RightButton")
leftButton:SetHook("OnMouseDown", DF.AdjustmentSliderFunctions.OnButtonDownkHook)
rightButton:SetHook("OnMouseDown", DF.AdjustmentSliderFunctions.OnButtonDownkHook)
leftButton:SetHook("OnMouseUp", DF.AdjustmentSliderFunctions.OnButtonUpHook)
rightButton:SetHook("OnMouseUp", DF.AdjustmentSliderFunctions.OnButtonUpHook)
leftButton:SetPoint("left", adjustmentSlider, "left", 0, 0)
rightButton:SetPoint("right", adjustmentSlider, "right", 0, 0)
leftButton:SetIcon("Minimal_SliderBar_Button_Left", 8, 14)
rightButton:SetIcon("Minimal_SliderBar_Button_Right", 8, 14)
leftButton.direction = "left"
rightButton.direction = "right"
--center button
local centerButton = DF:CreateButton(adjustmentSlider, function()end, 20, 20, "", "center", 0, nil, nil, name .. "CenterButton")
centerButton:SetPoint("center", adjustmentSlider, "center", -3, 0)
centerButton:SetIcon("Minimal_SliderBar_Button", nil, nil, nil, nil, "transparent")
centerButton.direction = "center"
centerButton:SetHook("OnMouseDown", DF.AdjustmentSliderFunctions.OnButtonDownkHook)
centerButton:SetHook("OnMouseUp", DF.AdjustmentSliderFunctions.OnButtonUpHook)
local centerArrowArtwork = centerButton:CreateTexture("$parentCenterArrowArtwork", "artwork")
centerArrowArtwork:SetAtlas("Minimal_SliderBar_Button")
centerArrowArtwork:SetPoint("center", centerButton.widget, "center", 0, 0)
centerArrowArtwork:SetSize(16, 16)
centerArrowArtwork:SetAlpha(1)
adjustmentSlider.leftButton = leftButton
adjustmentSlider.rightButton = rightButton
adjustmentSlider.centerButton = centerButton
adjustmentSlider.centerArrowArtwork = centerArrowArtwork
return adjustmentSlider
end
--creates a slider with left and right buttons and a center button, on click the hold, mouse moviments adjust the value and trigger a callback with a normallized x and y values of the mouse movement
--@parent: who is the parent of this frame
--@callback: run when there's a change in any of the two axis
--@options: a table containing options for the frame, see /dump DetailsFramework.AdjustmentSliderOptions
--@name: the name of the frame, if none a generic name is created
function DF:CreateAdjustmentSlider(parent, callback, options, name, ...)
if (not name) then
name = "DetailsFrameworkAdjustmentSlider" .. DF.SliderCounter
DF.SliderCounter = DF.SliderCounter + 1
elseif (not parent) then
return error("DF:CreateAdjustmentSlider(): parent not found.", 2)
end
local ASFrame = createAdjustmentSliderFrames(parent, options, name)
ASFrame:SetPayload(...)
ASFrame.callback = callback
return ASFrame
end
----------------------------------------------------------------------------------------------------------------
function DF:DisableOnEnterScripts()
local ignoreOnEnterZone = DF:CreateOnEnterIgnoreZone()
ignoreOnEnterZone:Show()
end
function DF:EnableOnEnterScripts()
local ignoreOnEnterZone = DF:CreateOnEnterIgnoreZone()
ignoreOnEnterZone:Hide()
end
function DF:CreateOnEnterIgnoreZone()
if (not _G.DetailsFrameworkIgnoreHoverOverFrame) then
local ignoreOnEnterFrame = CreateFrame("frame", "DetailsFrameworkIgnoreHoverOverFrame", UIParent)
ignoreOnEnterFrame:SetFrameStrata("TOOLTIP")
ignoreOnEnterFrame:SetFrameLevel(9999)
ignoreOnEnterFrame:SetAllPoints()
ignoreOnEnterFrame:EnableMouse(true)
ignoreOnEnterFrame:Hide()
end
return _G.DetailsFrameworkIgnoreHoverOverFrame
end