local function c(c,X)local o=(X-c)%TAU local K=PI-math.abs(math.abs(o)-PI)if(o+TAU)%TAU<PI then return K else return-K end end function init(c)local X=c.SubN local o=c.Frame.RadialDial local K=Enum.UserInputType.MouseMovement c._Maid:Mark(c._ClickedBind)c._Maid:Mark(c._HoverBind)c._Maid:Mark(UIS.LastInputTypeChanged:Connect(function(c)if MOUSE_GROUP[c]or GAMEPAD_GROUP[c]then K=c end end))local V=0 c._Maid:Mark(UIS.InputBegan:Connect(function(X)if not c.Enabled then return end if GAMEPAD_GROUP[X.UserInputType]then if not GAMEPAD_CLICK[X.KeyCode]then return else c._ClickedBind:Fire(c:PickIndex(V))end end local o=c:GetTheta(X.UserInputType)if o then c._ClickedBind:Fire(c:PickIndex(o))end end))c._Maid:Mark(RUNSERVICE.RenderStepped:Connect(function(X)if not c.Enabled then return end local R=c:GetTheta(K)if R and c:IsVisible()then V=R local X=math.rad(c.Frame.Rotation)local K=math.deg((((R-c.Rotation)+X)+EX_OFFSET)+2*TAU)%360 local g=K/(360/c.SubN)+.5 o.Rotation=math.deg(c:GetRotation(g))local l=c:PickIndex(R)if l~=c._LastHoverIndex then c._HoverBind:Fire(c._LastHoverIndex,l)c._LastHoverIndex=l end end end))end
-- Private Methods

local function shortestDist(start, stop)
	local modDiff = (stop - start) % TAU
	local sDist = PI - math.abs(math.abs(modDiff) - PI)
	if (modDiff + TAU) % TAU < PI then
		return sDist
	else
		return -sDist
	end
end

function init(self)
	local subN = self.SubN
	local dial = self.Frame.RadialDial

	local inputType = Enum.UserInputType.MouseMovement

	self._Maid:Mark(self._ClickedBind)
	self._Maid:Mark(self._HoverBind)

	self._Maid:Mark(UIS.LastInputTypeChanged:Connect(function(iType)
		if MOUSE_GROUP[iType] or GAMEPAD_GROUP[iType] then
			inputType = iType
		end
	end))

	local lTheta = 0

	self._Maid:Mark(UIS.InputBegan:Connect(function(input)
		if not self.Enabled then
			return
		end

		if GAMEPAD_GROUP[input.UserInputType] then
			if not GAMEPAD_CLICK[input.KeyCode] then
				return
			else
				self._ClickedBind:Fire(self:PickIndex(lTheta))
			end
		end

		local theta = self:GetTheta(input.UserInputType)
		if theta then
			self._ClickedBind:Fire(self:PickIndex(theta))
		end
	end))

	self._Maid:Mark(RUNSERVICE.RenderStepped:Connect(function(dt)
		if not self.Enabled then
			return
		end

		local theta = self:GetTheta(inputType)
		if theta and self:IsVisible() then
			lTheta = theta

			local frameRot = math.rad(self.Frame.Rotation)
			local toDeg = math.deg(theta - self.Rotation + frameRot + EX_OFFSET + 2 * TAU) % 360
			local closest = toDeg / (360 / self.SubN) + 0.5

			dial.Rotation = math.deg(self:GetRotation(closest))

			local index = self:PickIndex(theta)
			if index ~= self._LastHoverIndex then
				self._HoverBind:Fire(self._LastHoverIndex, index)
				self._LastHoverIndex = index
			end
		end
	end))
end
