local y,w="\083\108\105\100\101\114",23 local O=LibStub and LibStub("\065\099\101\071\085\073-\051\046\048",true)if not O or(O:GetWidgetVersion(y)or 0)>=w then return end local H,C,M=math.min,math.max,math.floor local T,I=tonumber,pairs local b=PlaySound local t,z=CreateFrame,UIParent local function x(y)local w=y.value or 0 if y.ispercent then y.editbox:SetText(("\037\115\037\037"):format(M(w*1000+.5)/10))else y.editbox:SetText(M(w*100+.5)/100)end end local function e(y)local w,O=y.min or 0,y.max or 100 if y.ispercent then y.lowtext:SetFormattedText("\037\115\037\037",w*100)y.hightext:SetFormattedText("\037\115\037\037",O*100)else y.lowtext:SetText(w)y.hightext:SetText(O)end end local function W(y)y.obj:Fire("\079\110\069\110\116\101\114")end local function X(y)y.obj:Fire("\079\110\076\101\097\118\101")end local function R(y)y.obj.slider:EnableMouseWheel(true)O:ClearFocus()end local function D(y,w)local O=y.obj if not y.setup then if O.step and O.step>0 then local y=O.min or 0 w=M((w-y)/O.step+.5)*O.step+y end if w~=O.value and not O.disabled then O.value=w O:Fire("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",w)end if O.value then x(O)end end end local function l(y)local w=y.obj w:Fire("\079\110\077\111\117\115\101\085\112",w.value)end local function Z(y,w)local O=y.obj if not O.disabled then local y=O.value if w>0 then y=H(y+(O.step or 1),O.max)else y=C(y-(O.step or 1),O.min)end O.slider:SetValue(y)end end local function U(y)y:ClearFocus()end local function q(y)local w=y.obj local O=y:GetText()if w.ispercent then O=O:gsub("\037\037","")O=T(O)/100 else O=T(O)end if O then b(856)w.slider:SetValue(O)w:Fire("\079\110\077\111\117\115\101\085\112",O)end end local function u(y)y:SetBackdropBorderColor(.5,.5,.5,1)end local function J(y)y:SetBackdropBorderColor(.3,.3,.3,.8)end local g={OnAcquire=function(y)y:SetWidth(200)y:SetHeight(44)y:SetDisabled(false)y:SetIsPercent(nil)y:SetSliderValues(0,100,1)y:SetValue(0)y.slider:EnableMouseWheel(false)end;SetDisabled=function(y,w)y.disabled=w if w then y.slider:EnableMouse(false)y.label:SetTextColor(.5,.5,.5)y.hightext:SetTextColor(.5,.5,.5)y.lowtext:SetTextColor(.5,.5,.5)y.editbox:SetTextColor(.5,.5,.5)y.editbox:EnableMouse(false)y.editbox:ClearFocus()else y.slider:EnableMouse(true)y.label:SetTextColor(1,.82,0)y.hightext:SetTextColor(1,1,1)y.lowtext:SetTextColor(1,1,1)y.editbox:SetTextColor(1,1,1)y.editbox:EnableMouse(true)end end,SetValue=function(y,w)y.slider.setup=true y.slider:SetValue(w)y.value=w x(y)y.slider.setup=nil end;GetValue=function(y)return y.value end,SetLabel=function(y,w)y.label:SetText(w)end;SetSliderValues=function(y,w,O,H)local C=y.slider C.setup=true y.min=w y.max=O y.step=H C:SetMinMaxValues(w or 0,O or 100)e(y)C:SetValueStep(H or 1)if y.value then C:SetValue(y.value)end C.setup=nil end;SetIsPercent=function(y,w)y.ispercent=w e(y)x(y)end}local n={bgFile="\073\110\116\101\114\102\097\099\101\092\066\117\116\116\111\110\115\092\085\073-\083\108\105\100\101\114\066\097\114-\066\097\099\107\103\114\111\117\110\100";edgeFile="\073\110\116\101\114\102\097\099\101\092\066\117\116\116\111\110\115\092\085\073-\083\108\105\100\101\114\066\097\114-\066\111\114\100\101\114";tile=true;tileSize=8;edgeSize=8,insets={left=3,right=3;top=6,bottom=6}}local N={bgFile="\073\110\116\101\114\102\097\099\101\092\067\104\097\116\070\114\097\109\101\092\067\104\097\116\070\114\097\109\101\066\097\099\107\103\114\111\117\110\100",edgeFile="\073\110\116\101\114\102\097\099\101\092\067\104\097\116\070\114\097\109\101\092\067\104\097\116\070\114\097\109\101\066\097\099\107\103\114\111\117\110\100";tile=true,edgeSize=1,tileSize=5}local function c()local w=t("\070\114\097\109\101",nil,z)w:EnableMouse(true)w:SetScript("\079\110\077\111\117\115\101\068\111\119\110",R)local H=w:CreateFontString(nil,"\079\086\069\082\076\065\089","\071\097\109\101\070\111\110\116\078\111\114\109\097\108")H:SetPoint("\084\079\080\076\069\070\084")H:SetPoint("\084\079\080\082\073\071\072\084")H:SetJustifyH("\067\069\078\084\069\082")H:SetHeight(15)local C=t("\083\108\105\100\101\114",nil,w,"\066\097\099\107\100\114\111\112\084\101\109\112\108\097\116\101")C:SetOrientation("\072\079\082\073\090\079\078\084\065\076")C:SetHeight(15)C:SetHitRectInsets(0,0,-10,0)C:SetBackdrop(n)C:SetThumbTexture("\073\110\116\101\114\102\097\099\101\092\066\117\116\116\111\110\115\092\085\073-\083\108\105\100\101\114\066\097\114-\066\117\116\116\111\110-\072\111\114\105\122\111\110\116\097\108")C:SetPoint("\084\079\080",H,"\066\079\084\084\079\077")C:SetPoint("\076\069\070\084",3,0)C:SetPoint("\082\073\071\072\084",-3,0)C:SetValue(0)C:SetScript("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",D)C:SetScript("\079\110\069\110\116\101\114",W)C:SetScript("\079\110\076\101\097\118\101",X)C:SetScript("\079\110\077\111\117\115\101\085\112",l)C:SetScript("\079\110\077\111\117\115\101\087\104\101\101\108",Z)local M=C:CreateFontString(nil,"\065\082\084\087\079\082\075","\071\097\109\101\070\111\110\116\072\105\103\104\108\105\103\104\116\083\109\097\108\108")M:SetPoint("\084\079\080\076\069\070\084",C,"\066\079\084\084\079\077\076\069\070\084",2,3)local T=C:CreateFontString(nil,"\065\082\084\087\079\082\075","\071\097\109\101\070\111\110\116\072\105\103\104\108\105\103\104\116\083\109\097\108\108")T:SetPoint("\084\079\080\082\073\071\072\084",C,"\066\079\084\084\079\077\082\073\071\072\084",-2,3)local b=t("\069\100\105\116\066\111\120",nil,w,"\066\097\099\107\100\114\111\112\084\101\109\112\108\097\116\101")b:SetAutoFocus(false)b:SetFontObject(GameFontHighlightSmall)b:SetPoint("\084\079\080",C,"\066\079\084\084\079\077")b:SetHeight(14)b:SetWidth(70)b:SetJustifyH("\067\069\078\084\069\082")b:EnableMouse(true)b:SetBackdrop(N)b:SetBackdropColor(0,0,0,.5)b:SetBackdropBorderColor(.3,.3,.3,.8)b:SetScript("\079\110\069\110\116\101\114",u)b:SetScript("\079\110\076\101\097\118\101",J)b:SetScript("\079\110\069\110\116\101\114\080\114\101\115\115\101\100",q)b:SetScript("\079\110\069\115\099\097\112\101\080\114\101\115\115\101\100",U)local x={label=H,slider=C;lowtext=M;hightext=T;editbox=b,alignoffset=25;frame=w;type=y}for y,w in I(g)do x[y]=w end C.obj,b.obj=x,x return O:RegisterAsWidget(x)end O:RegisterWidgetType(y,c,w)
--[[-----------------------------------------------------------------------------
Slider Widget
Graphical Slider, like, for Range values.
-------------------------------------------------------------------------------]]
local Type, Version = "Slider", 23
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end

-- Lua APIs
local min, max, floor = math.min, math.max, math.floor
local tonumber, pairs = tonumber, pairs

-- WoW APIs
local PlaySound = PlaySound
local CreateFrame, UIParent = CreateFrame, UIParent

--[[-----------------------------------------------------------------------------
Support functions
-------------------------------------------------------------------------------]]
local function UpdateText(self)
	local value = self.value or 0
	if self.ispercent then
		self.editbox:SetText(("%s%%"):format(floor(value * 1000 + 0.5) / 10))
	else
		self.editbox:SetText(floor(value * 100 + 0.5) / 100)
	end
end

local function UpdateLabels(self)
	local min_value, max_value = (self.min or 0), (self.max or 100)
	if self.ispercent then
		self.lowtext:SetFormattedText("%s%%", (min_value * 100))
		self.hightext:SetFormattedText("%s%%", (max_value * 100))
	else
		self.lowtext:SetText(min_value)
		self.hightext:SetText(max_value)
	end
end

--[[-----------------------------------------------------------------------------
Scripts
-------------------------------------------------------------------------------]]
local function Control_OnEnter(frame)
	frame.obj:Fire("OnEnter")
end

local function Control_OnLeave(frame)
	frame.obj:Fire("OnLeave")
end

local function Frame_OnMouseDown(frame)
	frame.obj.slider:EnableMouseWheel(true)
	AceGUI:ClearFocus()
end

local function Slider_OnValueChanged(frame, newvalue)
	local self = frame.obj
	if not frame.setup then
		if self.step and self.step > 0 then
			local min_value = self.min or 0
			newvalue = floor((newvalue - min_value) / self.step + 0.5) * self.step + min_value
		end
		if newvalue ~= self.value and not self.disabled then
			self.value = newvalue
			self:Fire("OnValueChanged", newvalue)
		end
		if self.value then
			UpdateText(self)
		end
	end
end

local function Slider_OnMouseUp(frame)
	local self = frame.obj
	self:Fire("OnMouseUp", self.value)
end

local function Slider_OnMouseWheel(frame, v)
	local self = frame.obj
	if not self.disabled then
		local value = self.value
		if v > 0 then
			value = min(value + (self.step or 1), self.max)
		else
			value = max(value - (self.step or 1), self.min)
		end
		self.slider:SetValue(value)
	end
end

local function EditBox_OnEscapePressed(frame)
	frame:ClearFocus()
end

local function EditBox_OnEnterPressed(frame)
	local self = frame.obj
	local value = frame:GetText()
	if self.ispercent then
		value = value:gsub('%%', '')
		value = tonumber(value) / 100
	else
		value = tonumber(value)
	end

	if value then
		PlaySound(856) -- SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON
		self.slider:SetValue(value)
		self:Fire("OnMouseUp", value)
	end
end

local function EditBox_OnEnter(frame)
	frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
end

local function EditBox_OnLeave(frame)
	frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8)
end

--[[-----------------------------------------------------------------------------
Methods
-------------------------------------------------------------------------------]]
local methods = {
	["OnAcquire"] = function(self)
		self:SetWidth(200)
		self:SetHeight(44)
		self:SetDisabled(false)
		self:SetIsPercent(nil)
		self:SetSliderValues(0,100,1)
		self:SetValue(0)
		self.slider:EnableMouseWheel(false)
	end,

	-- ["OnRelease"] = nil,

	["SetDisabled"] = function(self, disabled)
		self.disabled = disabled
		if disabled then
			self.slider:EnableMouse(false)
			self.label:SetTextColor(.5, .5, .5)
			self.hightext:SetTextColor(.5, .5, .5)
			self.lowtext:SetTextColor(.5, .5, .5)
			--self.valuetext:SetTextColor(.5, .5, .5)
			self.editbox:SetTextColor(.5, .5, .5)
			self.editbox:EnableMouse(false)
			self.editbox:ClearFocus()
		else
			self.slider:EnableMouse(true)
			self.label:SetTextColor(1, .82, 0)
			self.hightext:SetTextColor(1, 1, 1)
			self.lowtext:SetTextColor(1, 1, 1)
			--self.valuetext:SetTextColor(1, 1, 1)
			self.editbox:SetTextColor(1, 1, 1)
			self.editbox:EnableMouse(true)
		end
	end,

	["SetValue"] = function(self, value)
		self.slider.setup = true
		self.slider:SetValue(value)
		self.value = value
		UpdateText(self)
		self.slider.setup = nil
	end,

	["GetValue"] = function(self)
		return self.value
	end,

	["SetLabel"] = function(self, text)
		self.label:SetText(text)
	end,

	["SetSliderValues"] = function(self, min_value, max_value, step)
		local frame = self.slider
		frame.setup = true
		self.min = min_value
		self.max = max_value
		self.step = step
		frame:SetMinMaxValues(min_value or 0,max_value or 100)
		UpdateLabels(self)
		frame:SetValueStep(step or 1)
		if self.value then
			frame:SetValue(self.value)
		end
		frame.setup = nil
	end,

	["SetIsPercent"] = function(self, value)
		self.ispercent = value
		UpdateLabels(self)
		UpdateText(self)
	end
}

--[[-----------------------------------------------------------------------------
Constructor
-------------------------------------------------------------------------------]]
local SliderBackdrop  = {
	bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
	edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
	tile = true, tileSize = 8, edgeSize = 8,
	insets = { left = 3, right = 3, top = 6, bottom = 6 }
}

local ManualBackdrop = {
	bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
	edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
	tile = true, edgeSize = 1, tileSize = 5,
}

local function Constructor()
	local frame = CreateFrame("Frame", nil, UIParent)

	frame:EnableMouse(true)
	frame:SetScript("OnMouseDown", Frame_OnMouseDown)

	local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	label:SetPoint("TOPLEFT")
	label:SetPoint("TOPRIGHT")
	label:SetJustifyH("CENTER")
	label:SetHeight(15)

	local slider = CreateFrame("Slider", nil, frame, "BackdropTemplate")
	slider:SetOrientation("HORIZONTAL")
	slider:SetHeight(15)
	slider:SetHitRectInsets(0, 0, -10, 0)
	slider:SetBackdrop(SliderBackdrop)
	slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
	slider:SetPoint("TOP", label, "BOTTOM")
	slider:SetPoint("LEFT", 3, 0)
	slider:SetPoint("RIGHT", -3, 0)
	slider:SetValue(0)
	slider:SetScript("OnValueChanged",Slider_OnValueChanged)
	slider:SetScript("OnEnter", Control_OnEnter)
	slider:SetScript("OnLeave", Control_OnLeave)
	slider:SetScript("OnMouseUp", Slider_OnMouseUp)
	slider:SetScript("OnMouseWheel", Slider_OnMouseWheel)

	local lowtext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	lowtext:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", 2, 3)

	local hightext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
	hightext:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", -2, 3)

	local editbox = CreateFrame("EditBox", nil, frame, "BackdropTemplate")
	editbox:SetAutoFocus(false)
	editbox:SetFontObject(GameFontHighlightSmall)
	editbox:SetPoint("TOP", slider, "BOTTOM")
	editbox:SetHeight(14)
	editbox:SetWidth(70)
	editbox:SetJustifyH("CENTER")
	editbox:EnableMouse(true)
	editbox:SetBackdrop(ManualBackdrop)
	editbox:SetBackdropColor(0, 0, 0, 0.5)
	editbox:SetBackdropBorderColor(0.3, 0.3, 0.30, 0.80)
	editbox:SetScript("OnEnter", EditBox_OnEnter)
	editbox:SetScript("OnLeave", EditBox_OnLeave)
	editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
	editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)

	local widget = {
		label       = label,
		slider      = slider,
		lowtext     = lowtext,
		hightext    = hightext,
		editbox     = editbox,
		alignoffset = 25,
		frame       = frame,
		type        = Type
	}
	for method, func in pairs(methods) do
		widget[method] = func
	end
	slider.obj, editbox.obj = widget, widget

	return AceGUI:RegisterAsWidget(widget)
end

AceGUI:RegisterWidgetType(Type,Constructor,Version)
