local u={}u.__index=u function getClassicChatEnabled()if ChatSettings.ClassicChatEnabled~=nil then return ChatSettings.ClassicChatEnabled end return Players.ClassicChat end function getBubbleChatEnabled()if ChatSettings.BubbleChatEnabled~=nil then return ChatSettings.BubbleChatEnabled end return Players.BubbleChat end function bubbleChatOnly()return not getClassicChatEnabled()and getBubbleChatEnabled()end function u.CreateGuiObjects(Y,u)local M=Instance.new("\070\114\097\109\101")M.BackgroundTransparency=1 M.Active=ChatSettings.WindowDraggable M.Parent=u local G=Instance.new("\070\114\097\109\101")G.Selectable=false G.Name="\067\104\097\116\066\097\114\080\097\114\101\110\116\070\114\097\109\101"G.BackgroundTransparency=1 G.Parent=M local r=Instance.new("\070\114\097\109\101")r.Selectable=false r.Name="\067\104\097\110\110\101\108\115\066\097\114\080\097\114\101\110\116\070\114\097\109\101"r.BackgroundTransparency=1 r.Position=UDim2.new(0,0,0,0)r.Parent=M local x=Instance.new("\070\114\097\109\101")x.Selectable=false x.Name="\067\104\097\116\067\104\097\110\110\101\108\080\097\114\101\110\116\070\114\097\109\101"x.BackgroundTransparency=1 x.BackgroundColor3=ChatSettings.BackGroundColor x.BackgroundTransparency=.6 x.BorderSizePixel=0 x.Parent=M local j=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")j.Selectable=false j.Image=""j.BackgroundTransparency=.6 j.BorderSizePixel=0 j.Visible=false j.BackgroundColor3=ChatSettings.BackGroundColor j.Active=true if bubbleChatOnly()then j.Position=UDim2.new(1,-j.AbsoluteSize.X,0,0)else j.Position=UDim2.new(1,-j.AbsoluteSize.X,1,-j.AbsoluteSize.Y)end j.Parent=M local k=Instance.new("\073\109\097\103\101\076\097\098\101\108")k.Selectable=false k.Size=UDim2.new(.8,0,.8,0)k.Position=UDim2.new(.2,0,.2,0)k.BackgroundTransparency=1 k.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\054\049\056\056\048\055\052\051"k.Parent=j local function y()local u=M while u and not u:IsA("\083\099\114\101\101\110\071\117\105")do u=u.Parent end return u end local o=DEVICE_DESKTOP local f=y()if f.AbsoluteSize.X<=PHONE_SCREEN_WIDTH then o=DEVICE_PHONE elseif f.AbsoluteSize.X<=TABLET_SCREEN_WIDTH then o=DEVICE_TABLET end local N=false local function A()if N then return end N=true if not M:IsDescendantOf(PlayerGui)then return end local u=y()local Y=ChatSettings.MinimumWindowSize local x=ChatSettings.MaximumWindowSize local j=r.AbsoluteSize.Y+G.AbsoluteSize.Y local k=Y.X.Scale*u.AbsoluteSize.X+Y.X.Offset local o=math.max(Y.Y.Scale*u.AbsoluteSize.Y+Y.Y.Offset,j)local f=x.X.Scale*u.AbsoluteSize.X+x.X.Offset local A=x.Y.Scale*u.AbsoluteSize.Y+x.Y.Offset local P=M.AbsoluteSize.X local T=M.AbsoluteSize.Y if P<k then local u=UDim2.new(0,k-P,0,0)M.Size=M.Size+u elseif P>f then local u=UDim2.new(0,f-P,0,0)M.Size=M.Size+u end if T<o then local u=UDim2.new(0,0,0,o-T)M.Size=M.Size+u elseif T>A then local u=UDim2.new(0,0,0,A-T)M.Size=M.Size+u end local J=M.AbsoluteSize.X/u.AbsoluteSize.X local W=M.AbsoluteSize.Y/u.AbsoluteSize.Y M.Size=UDim2.new(J,0,W,0)N=false end M.Changed:connect(function(u)if u=="\065\098\115\111\108\117\116\101\083\105\122\101"then A()end end)j.DragBegin:connect(function(u)M.Draggable=false end)local function P(u)if ChatSettings.WindowDraggable==false and ChatSettings.WindowResizable==false then return end local Y=(u-M.AbsolutePosition)+j.AbsoluteSize M.Size=UDim2.new(0,Y.X,0,Y.Y)if bubbleChatOnly()then j.Position=UDim2.new(1,-j.AbsoluteSize.X,0,0)else j.Position=UDim2.new(1,-j.AbsoluteSize.X,1,-j.AbsoluteSize.Y)end end j.DragStopped:connect(function(u,Y)M.Draggable=ChatSettings.WindowDraggable end)local T=false j.Changed:connect(function(u)if u=="\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110"and not M.Draggable then if T then return end T=true P(j.AbsolutePosition)T=false end end)local function J(u)if o==DEVICE_PHONE then u=u or ChatSettings.ChatChannelsTabTextSizePhone else u=u or ChatSettings.ChatChannelsTabTextSize end local Y=u local M=math.max(32,Y+8)+2 return M end local function W(u)if o==DEVICE_PHONE then u=u or ChatSettings.ChatBarTextSizePhone else u=u or ChatSettings.ChatBarTextSize end local Y=u local M=(Y+14)+10 return M end if bubbleChatOnly()then G.Position=UDim2.new(0,0,0,0)r.Visible=false r.Active=false x.Visible=false x.Active=false local u=0 local Y=0 local j=y()if o==DEVICE_PHONE then u=ChatSettings.DefaultWindowSizePhone.X.Scale Y=ChatSettings.DefaultWindowSizePhone.X.Offset elseif o==DEVICE_TABLET then u=ChatSettings.DefaultWindowSizeTablet.X.Scale Y=ChatSettings.DefaultWindowSizeTablet.X.Offset else u=ChatSettings.DefaultWindowSizeTablet.X.Scale Y=ChatSettings.DefaultWindowSizeTablet.X.Offset end local k=W()M.Size=UDim2.new(u,Y,0,k)M.Position=ChatSettings.DefaultWindowPosition else local u=y()if o==DEVICE_PHONE then M.Size=ChatSettings.DefaultWindowSizePhone elseif o==DEVICE_TABLET then M.Size=ChatSettings.DefaultWindowSizeTablet else M.Size=ChatSettings.DefaultWindowSizeDesktop end M.Position=ChatSettings.DefaultWindowPosition end if o==DEVICE_PHONE then ChatSettings.ChatWindowTextSize=ChatSettings.ChatWindowTextSizePhone ChatSettings.ChatChannelsTabTextSize=ChatSettings.ChatChannelsTabTextSizePhone ChatSettings.ChatBarTextSize=ChatSettings.ChatBarTextSizePhone end local function p(u)M.Active=u M.Draggable=u end local function n(u)j.Visible=u j.Draggable=u local Y=G.Size.Y.Offset if u then G.Size=UDim2.new(1,-Y-2,0,Y)if not bubbleChatOnly()then G.Position=UDim2.new(0,0,1,-Y)end else G.Size=UDim2.new(1,0,0,Y)if not bubbleChatOnly()then G.Position=UDim2.new(0,0,1,-Y)end end end local function D()local u=J()local Y=W()if ChatSettings.ShowChannelsBar then x.Size=UDim2.new(1,0,1,-(((u+Y)+2)+2))x.Position=UDim2.new(0,0,0,u+2)else x.Size=UDim2.new(1,0,1,-((Y+2)+2))x.Position=UDim2.new(0,0,0,2)end end local function C(u)local Y=J(u)r.Size=UDim2.new(1,0,0,Y)D()end local function Z(u)local Y=W(u)G.Size=UDim2.new(1,0,0,Y)if not bubbleChatOnly()then G.Position=UDim2.new(0,0,1,-Y)end j.Size=UDim2.new(0,Y,0,Y)j.Position=UDim2.new(1,-Y,1,-Y)D()n(ChatSettings.WindowResizable)end local function w(u)r.Visible=u D()end C(ChatSettings.ChatChannelsTabTextSize)Z(ChatSettings.ChatBarTextSize)p(ChatSettings.WindowDraggable)n(ChatSettings.WindowResizable)w(ChatSettings.ShowChannelsBar)ChatSettings.SettingsChanged:connect(function(u,Y)if u=="\087\105\110\100\111\119\068\114\097\103\103\097\098\108\101"then p(Y)elseif u=="\087\105\110\100\111\119\082\101\115\105\122\097\098\108\101"then n(Y)elseif u=="\067\104\097\116\067\104\097\110\110\101\108\115\084\097\098\084\101\120\116\083\105\122\101"then C(Y)elseif u=="\067\104\097\116\066\097\114\084\101\120\116\083\105\122\101"then Z(Y)elseif u=="\083\104\111\119\067\104\097\110\110\101\108\115\066\097\114"then w(Y)end end)Y.GuiObject=M Y.GuiObjects.BaseFrame=M Y.GuiObjects.ChatBarParentFrame=G Y.GuiObjects.ChannelsBarParentFrame=r Y.GuiObjects.ChatChannelParentFrame=x Y.GuiObjects.ChatResizerFrame=j Y.GuiObjects.ResizeIcon=k Y:AnimGuiObjects()end function u.GetChatBar(u)return u.ChatBar end function u.RegisterChatBar(Y,u)Y.ChatBar=u Y.ChatBar:CreateGuiObjects(Y.GuiObjects.ChatBarParentFrame)end function u.RegisterChannelsBar(Y,u)Y.ChannelsBar=u Y.ChannelsBar:CreateGuiObjects(Y.GuiObjects.ChannelsBarParentFrame)end function u.RegisterMessageLogDisplay(Y,u)Y.MessageLogDisplay=u Y.MessageLogDisplay.GuiObject.Parent=Y.GuiObjects.ChatChannelParentFrame end function u.AddChannel(Y,u)if Y:GetChannel(u)then error("\067\104\097\110\110\101\108 \'"..(u.."\' \097\108\114\101\097\100\121 \101\120\105\115\116\115\033"))return end local M=moduleChatChannel.new(u,Y.MessageLogDisplay)Y.Channels[u:lower()]=M M:SetActive(false)local G=Y.ChannelsBar:AddChannelTab(u)G.NameTag.MouseButton1Click:connect(function()Y:SwitchCurrentChannel(u)end)M:RegisterChannelTab(G)return M end function u.GetFirstChannel(u)for u,Y in pairs(u.Channels)do return Y end return nil end function u.RemoveChannel(Y,u)if not Y:GetChannel(u)then error("\067\104\097\110\110\101\108 \'"..(u.."\' \100\111\101\115 \110\111\116 \101\120\105\115\116\033"))end local M=u:lower()local G=false if Y.Channels[M]==Y:GetCurrentChannel()then G=true Y:SwitchCurrentChannel(nil)end Y.Channels[M]:Destroy()Y.Channels[M]=nil Y.ChannelsBar:RemoveChannelTab(u)if G then local u=Y:GetChannel(ChatSettings.GeneralChannelName)~=nil local G=M==ChatSettings.GeneralChannelName:lower()local r=nil if u and not G then r=ChatSettings.GeneralChannelName else local u=Y:GetFirstChannel()r=u and u.Name or nil end Y:SwitchCurrentChannel(r)end if not ChatSettings.ShowChannelsBar then if Y.ChatBar.TargetChannel==u then Y.ChatBar:SetChannelTarget(ChatSettings.GeneralChannelName)end end end function u.GetChannel(Y,u)return u and Y.Channels[u:lower()]or nil end function u.GetTargetMessageChannel(u)if not ChatSettings.ShowChannelsBar then return u.ChatBar.TargetChannel else local Y=u:GetCurrentChannel()return Y and Y.Name end end function u.GetCurrentChannel(u)return u.CurrentChannel end function u.SwitchCurrentChannel(Y,u)if not ChatSettings.ShowChannelsBar then local M=Y:GetChannel(u)if M then Y.ChatBar:SetChannelTarget(M.Name)end u=ChatSettings.GeneralChannelName end local M=Y:GetCurrentChannel()local G=Y:GetChannel(u)if G==nil then error(string.format("\067\104\097\110\110\101\108 \'\037\115\' \100\111\101\115 \110\111\116 \101\120\105\115\116\046",u))end if G~=M then if M then M:SetActive(false)local u=Y.ChannelsBar:GetChannelTab(M.Name)u:SetActive(false)end if G then G:SetActive(true)local u=Y.ChannelsBar:GetChannelTab(G.Name)u:SetActive(true)end Y.CurrentChannel=G end end function u.UpdateFrameVisibility(u)u.GuiObject.Visible=u.Visible and u.CoreGuiEnabled end function u.GetVisible(u)return u.Visible end function u.SetVisible(Y,u)Y.Visible=u Y:UpdateFrameVisibility()end function u.GetCoreGuiEnabled(u)return u.CoreGuiEnabled end function u.SetCoreGuiEnabled(Y,u)Y.CoreGuiEnabled=u Y:UpdateFrameVisibility()end function u.EnableResizable(u)u.GuiObjects.ChatResizerFrame.Active=true end function u.DisableResizable(u)u.GuiObjects.ChatResizerFrame.Active=false end function u.FadeOutBackground(Y,u)Y.ChannelsBar:FadeOutBackground(u)Y.MessageLogDisplay:FadeOutBackground(u)Y.ChatBar:FadeOutBackground(u)Y.AnimParams.Background_TargetTransparency=1 Y.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(u)end function u.FadeInBackground(Y,u)Y.ChannelsBar:FadeInBackground(u)Y.MessageLogDisplay:FadeInBackground(u)Y.ChatBar:FadeInBackground(u)Y.AnimParams.Background_TargetTransparency=.6 Y.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(u)end function u.FadeOutText(Y,u)Y.MessageLogDisplay:FadeOutText(u)Y.ChannelsBar:FadeOutText(u)end function u.FadeInText(Y,u)Y.MessageLogDisplay:FadeInText(u)Y.ChannelsBar:FadeInText(u)end function u.AnimGuiObjects(u)u.GuiObjects.ChatChannelParentFrame.BackgroundTransparency=u.AnimParams.Background_CurrentTransparency u.GuiObjects.ChatResizerFrame.BackgroundTransparency=u.AnimParams.Background_CurrentTransparency u.GuiObjects.ResizeIcon.ImageTransparency=u.AnimParams.Background_CurrentTransparency end function u.InitializeAnimParams(u)u.AnimParams.Background_TargetTransparency=.6 u.AnimParams.Background_CurrentTransparency=.6 u.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(0)end function u.Update(Y,u)Y.ChatBar:Update(u)Y.ChannelsBar:Update(u)Y.MessageLogDisplay:Update(u)Y.AnimParams.Background_CurrentTransparency=CurveUtil:Expt(Y.AnimParams.Background_CurrentTransparency,Y.AnimParams.Background_TargetTransparency,Y.AnimParams.Background_NormalizedExptValue,u)Y:AnimGuiObjects()end

local methods = {}
methods.__index = methods

function getClassicChatEnabled()
	if ChatSettings.ClassicChatEnabled ~= nil then
		return ChatSettings.ClassicChatEnabled
	end
	return Players.ClassicChat
end

function getBubbleChatEnabled()
	if ChatSettings.BubbleChatEnabled ~= nil then
		return ChatSettings.BubbleChatEnabled
	end
	return Players.BubbleChat
end

function bubbleChatOnly()
 	return not getClassicChatEnabled() and getBubbleChatEnabled()
end

function methods:CreateGuiObjects(targetParent)
	local BaseFrame = Instance.new("Frame")
	BaseFrame.BackgroundTransparency = 1
	BaseFrame.Active = ChatSettings.WindowDraggable
	BaseFrame.Parent = targetParent

	local ChatBarParentFrame = Instance.new("Frame")
	ChatBarParentFrame.Selectable = false
	ChatBarParentFrame.Name = "ChatBarParentFrame"
	ChatBarParentFrame.BackgroundTransparency = 1
	ChatBarParentFrame.Parent = BaseFrame

	local ChannelsBarParentFrame = Instance.new("Frame")
	ChannelsBarParentFrame.Selectable = false
	ChannelsBarParentFrame.Name = "ChannelsBarParentFrame"
	ChannelsBarParentFrame.BackgroundTransparency = 1
	ChannelsBarParentFrame.Position = UDim2.new(0, 0, 0, 0)
	ChannelsBarParentFrame.Parent = BaseFrame

	local ChatChannelParentFrame = Instance.new("Frame")
	ChatChannelParentFrame.Selectable = false
	ChatChannelParentFrame.Name = "ChatChannelParentFrame"
	ChatChannelParentFrame.BackgroundTransparency = 1
	ChatChannelParentFrame.BackgroundColor3 = ChatSettings.BackGroundColor
	ChatChannelParentFrame.BackgroundTransparency = 0.6
	ChatChannelParentFrame.BorderSizePixel = 0
	ChatChannelParentFrame.Parent = BaseFrame

	local ChatResizerFrame = Instance.new("ImageButton")
	ChatResizerFrame.Selectable = false
	ChatResizerFrame.Image = ""
	ChatResizerFrame.BackgroundTransparency = 0.6
	ChatResizerFrame.BorderSizePixel = 0
	ChatResizerFrame.Visible = false
	ChatResizerFrame.BackgroundColor3 = ChatSettings.BackGroundColor
	ChatResizerFrame.Active = true
	if bubbleChatOnly() then
		ChatResizerFrame.Position = UDim2.new(1, -ChatResizerFrame.AbsoluteSize.X, 0, 0)
	else
		ChatResizerFrame.Position = UDim2.new(1, -ChatResizerFrame.AbsoluteSize.X, 1, -ChatResizerFrame.AbsoluteSize.Y)
	end
	ChatResizerFrame.Parent = BaseFrame

	local ResizeIcon = Instance.new("ImageLabel")
	ResizeIcon.Selectable = false
	ResizeIcon.Size = UDim2.new(0.8, 0, 0.8, 0)
	ResizeIcon.Position = UDim2.new(0.2, 0, 0.2, 0)
	ResizeIcon.BackgroundTransparency = 1
	ResizeIcon.Image = "rbxassetid://261880743"
	ResizeIcon.Parent = ChatResizerFrame

	local function GetScreenGuiParent()
		--// Travel up parent list until you find the ScreenGui that the chat window is parented to
		local screenGuiParent = BaseFrame
		while (screenGuiParent and not screenGuiParent:IsA("ScreenGui")) do
			screenGuiParent = screenGuiParent.Parent
		end

		return screenGuiParent
	end


	local deviceType = DEVICE_DESKTOP

	local screenGuiParent = GetScreenGuiParent()
	if (screenGuiParent.AbsoluteSize.X <= PHONE_SCREEN_WIDTH) then
		deviceType = DEVICE_PHONE

	elseif (screenGuiParent.AbsoluteSize.X <= TABLET_SCREEN_WIDTH) then
		deviceType = DEVICE_TABLET

	end

	local checkSizeLock = false
	local function doCheckSizeBounds()
		if (checkSizeLock) then return end
		checkSizeLock = true

		if (not BaseFrame:IsDescendantOf(PlayerGui)) then return end

		local screenGuiParent = GetScreenGuiParent()

		local minWinSize = ChatSettings.MinimumWindowSize
		local maxWinSize = ChatSettings.MaximumWindowSize

		local forceMinY = ChannelsBarParentFrame.AbsoluteSize.Y + ChatBarParentFrame.AbsoluteSize.Y

		local minSizePixelX = (minWinSize.X.Scale * screenGuiParent.AbsoluteSize.X) + minWinSize.X.Offset
		local minSizePixelY = math.max((minWinSize.Y.Scale * screenGuiParent.AbsoluteSize.Y) + minWinSize.Y.Offset, forceMinY)

		local maxSizePixelX = (maxWinSize.X.Scale * screenGuiParent.AbsoluteSize.X) + maxWinSize.X.Offset
		local maxSizePixelY = (maxWinSize.Y.Scale * screenGuiParent.AbsoluteSize.Y) + maxWinSize.Y.Offset

		local absSizeX = BaseFrame.AbsoluteSize.X
		local absSizeY = BaseFrame.AbsoluteSize.Y

		if (absSizeX < minSizePixelX) then
			local offset = UDim2.new(0, minSizePixelX - absSizeX, 0, 0)
			BaseFrame.Size = BaseFrame.Size + offset

		elseif (absSizeX > maxSizePixelX) then
			local offset = UDim2.new(0, maxSizePixelX - absSizeX, 0, 0)
			BaseFrame.Size = BaseFrame.Size + offset

		end

		if (absSizeY < minSizePixelY) then
			local offset = UDim2.new(0, 0, 0, minSizePixelY - absSizeY)
			BaseFrame.Size = BaseFrame.Size + offset

		elseif (absSizeY > maxSizePixelY) then
			local offset = UDim2.new(0, 0, 0, maxSizePixelY - absSizeY)
			BaseFrame.Size = BaseFrame.Size + offset

		end

		local xScale = BaseFrame.AbsoluteSize.X / screenGuiParent.AbsoluteSize.X
		local yScale = BaseFrame.AbsoluteSize.Y / screenGuiParent.AbsoluteSize.Y
		BaseFrame.Size = UDim2.new(xScale, 0, yScale, 0)

		checkSizeLock = false
	end


	BaseFrame.Changed:connect(function(prop)
		if (prop == "AbsoluteSize") then
			doCheckSizeBounds()
		end
	end)



	ChatResizerFrame.DragBegin:connect(function(startUdim)
		BaseFrame.Draggable = false
	end)

	local function UpdatePositionFromDrag(atPos)
		if ChatSettings.WindowDraggable == false and ChatSettings.WindowResizable == false then
			return
		end
		local newSize = atPos - BaseFrame.AbsolutePosition + ChatResizerFrame.AbsoluteSize
		BaseFrame.Size = UDim2.new(0, newSize.X, 0, newSize.Y)
		if bubbleChatOnly() then
			ChatResizerFrame.Position = UDim2.new(1, -ChatResizerFrame.AbsoluteSize.X, 0, 0)
		else
			ChatResizerFrame.Position = UDim2.new(1, -ChatResizerFrame.AbsoluteSize.X, 1, -ChatResizerFrame.AbsoluteSize.Y)
		end
	end

	ChatResizerFrame.DragStopped:connect(function(endX, endY)
		BaseFrame.Draggable = ChatSettings.WindowDraggable
		--UpdatePositionFromDrag(Vector2.new(endX, endY))
	end)

	local resizeLock = false
	ChatResizerFrame.Changed:connect(function(prop)
		if (prop == "AbsolutePosition" and not BaseFrame.Draggable) then
			if (resizeLock) then return end
			resizeLock = true

			UpdatePositionFromDrag(ChatResizerFrame.AbsolutePosition)

			resizeLock = false
		end
	end)

	local function CalculateChannelsBarPixelSize(textSize)
		if (deviceType == DEVICE_PHONE) then
			textSize = textSize or ChatSettings.ChatChannelsTabTextSizePhone
		else
			textSize = textSize or ChatSettings.ChatChannelsTabTextSize
		end

		local channelsBarTextYSize = textSize
		local chatChannelYSize = math.max(32, channelsBarTextYSize + 8) + 2

		return chatChannelYSize
	end

	local function CalculateChatBarPixelSize(textSize)
		if (deviceType == DEVICE_PHONE) then
			textSize = textSize or ChatSettings.ChatBarTextSizePhone
		else
			textSize = textSize or ChatSettings.ChatBarTextSize
		end

		local chatBarTextSizeY = textSize
		local chatBarYSize = chatBarTextSizeY + (7 * 2) + (5 * 2)

		return chatBarYSize
	end

	if bubbleChatOnly() then
		ChatBarParentFrame.Position = UDim2.new(0, 0, 0, 0)
		ChannelsBarParentFrame.Visible = false
		ChannelsBarParentFrame.Active = false
		ChatChannelParentFrame.Visible = false
		ChatChannelParentFrame.Active = false

		local useXScale = 0
		local useXOffset = 0

		local screenGuiParent = GetScreenGuiParent()

		if (deviceType == DEVICE_PHONE) then
			useXScale = ChatSettings.DefaultWindowSizePhone.X.Scale
			useXOffset = ChatSettings.DefaultWindowSizePhone.X.Offset

		elseif (deviceType == DEVICE_TABLET) then
			useXScale = ChatSettings.DefaultWindowSizeTablet.X.Scale
			useXOffset = ChatSettings.DefaultWindowSizeTablet.X.Offset

		else
			useXScale = ChatSettings.DefaultWindowSizeTablet.X.Scale
			useXOffset = ChatSettings.DefaultWindowSizeTablet.X.Offset

		end

		local chatBarYSize = CalculateChatBarPixelSize()

		BaseFrame.Size = UDim2.new(useXScale, useXOffset, 0, chatBarYSize)
		BaseFrame.Position = ChatSettings.DefaultWindowPosition

	else

		local screenGuiParent = GetScreenGuiParent()

		if (deviceType == DEVICE_PHONE) then
			BaseFrame.Size = ChatSettings.DefaultWindowSizePhone

		elseif (deviceType == DEVICE_TABLET) then
			BaseFrame.Size = ChatSettings.DefaultWindowSizeTablet

		else
			BaseFrame.Size = ChatSettings.DefaultWindowSizeDesktop

		end

		BaseFrame.Position = ChatSettings.DefaultWindowPosition

	end

	if (deviceType == DEVICE_PHONE) then
		ChatSettings.ChatWindowTextSize = ChatSettings.ChatWindowTextSizePhone
		ChatSettings.ChatChannelsTabTextSize = ChatSettings.ChatChannelsTabTextSizePhone
		ChatSettings.ChatBarTextSize = ChatSettings.ChatBarTextSizePhone
	end

	local function UpdateDraggable(enabled)
		BaseFrame.Active = enabled
		BaseFrame.Draggable = enabled
	end

	local function UpdateResizable(enabled)
		ChatResizerFrame.Visible = enabled
		ChatResizerFrame.Draggable = enabled

		local frameSizeY = ChatBarParentFrame.Size.Y.Offset

		if (enabled) then
			ChatBarParentFrame.Size = UDim2.new(1, -frameSizeY - 2, 0, frameSizeY)
			if not bubbleChatOnly() then
				ChatBarParentFrame.Position = UDim2.new(0, 0, 1, -frameSizeY)
			end
		else
			ChatBarParentFrame.Size = UDim2.new(1, 0, 0, frameSizeY)
			if not bubbleChatOnly() then
				ChatBarParentFrame.Position = UDim2.new(0, 0, 1, -frameSizeY)
			end
		end
	end

	local function UpdateChatChannelParentFrameSize()
		local channelsBarSize = CalculateChannelsBarPixelSize()
		local chatBarSize = CalculateChatBarPixelSize()

		if (ChatSettings.ShowChannelsBar) then
			ChatChannelParentFrame.Size = UDim2.new(1, 0, 1, -(channelsBarSize + chatBarSize + 2 + 2))
			ChatChannelParentFrame.Position = UDim2.new(0, 0, 0, channelsBarSize + 2)

		else
			ChatChannelParentFrame.Size = UDim2.new(1, 0, 1, -(chatBarSize + 2 + 2))
			ChatChannelParentFrame.Position = UDim2.new(0, 0, 0, 2)

		end
	end

	local function UpdateChatChannelsTabTextSize(size)
		local channelsBarSize = CalculateChannelsBarPixelSize(size)
		ChannelsBarParentFrame.Size = UDim2.new(1, 0, 0, channelsBarSize)

		UpdateChatChannelParentFrameSize()
	end

	local function UpdateChatBarTextSize(size)
		local chatBarSize = CalculateChatBarPixelSize(size)

		ChatBarParentFrame.Size = UDim2.new(1, 0, 0, chatBarSize)
		if not bubbleChatOnly() then
			ChatBarParentFrame.Position = UDim2.new(0, 0, 1, -chatBarSize)
		end

		ChatResizerFrame.Size = UDim2.new(0, chatBarSize, 0, chatBarSize)
		ChatResizerFrame.Position = UDim2.new(1, -chatBarSize, 1, -chatBarSize)

		UpdateChatChannelParentFrameSize()
		UpdateResizable(ChatSettings.WindowResizable)
	end

	local function UpdateShowChannelsBar(enabled)
		ChannelsBarParentFrame.Visible = enabled
		UpdateChatChannelParentFrameSize()
	end

	UpdateChatChannelsTabTextSize(ChatSettings.ChatChannelsTabTextSize)
	UpdateChatBarTextSize(ChatSettings.ChatBarTextSize)
	UpdateDraggable(ChatSettings.WindowDraggable)
	UpdateResizable(ChatSettings.WindowResizable)
	UpdateShowChannelsBar(ChatSettings.ShowChannelsBar)

	ChatSettings.SettingsChanged:connect(function(setting, value)
		if (setting == "WindowDraggable") then
			UpdateDraggable(value)

		elseif (setting == "WindowResizable") then
			UpdateResizable(value)

		elseif (setting == "ChatChannelsTabTextSize") then
			UpdateChatChannelsTabTextSize(value)

		elseif (setting == "ChatBarTextSize") then
			UpdateChatBarTextSize(value)

		elseif (setting == "ShowChannelsBar") then
			UpdateShowChannelsBar(value)

		end
	end)

	self.GuiObject = BaseFrame

	self.GuiObjects.BaseFrame = BaseFrame
	self.GuiObjects.ChatBarParentFrame = ChatBarParentFrame
	self.GuiObjects.ChannelsBarParentFrame = ChannelsBarParentFrame
	self.GuiObjects.ChatChannelParentFrame = ChatChannelParentFrame
	self.GuiObjects.ChatResizerFrame = ChatResizerFrame
	self.GuiObjects.ResizeIcon = ResizeIcon
	self:AnimGuiObjects()
end

function methods:GetChatBar()
	return self.ChatBar
end

function methods:RegisterChatBar(ChatBar)
	self.ChatBar = ChatBar
	self.ChatBar:CreateGuiObjects(self.GuiObjects.ChatBarParentFrame)
end

function methods:RegisterChannelsBar(ChannelsBar)
	self.ChannelsBar = ChannelsBar
	self.ChannelsBar:CreateGuiObjects(self.GuiObjects.ChannelsBarParentFrame)
end

function methods:RegisterMessageLogDisplay(MessageLogDisplay)
	self.MessageLogDisplay = MessageLogDisplay
	self.MessageLogDisplay.GuiObject.Parent = self.GuiObjects.ChatChannelParentFrame
end

function methods:AddChannel(channelName)
	if (self:GetChannel(channelName)) then
		error("Channel '" .. channelName .. "' already exists!")
		return
	end

	local channel = moduleChatChannel.new(channelName, self.MessageLogDisplay)
	self.Channels[channelName:lower()] = channel

	channel:SetActive(false)

	local tab = self.ChannelsBar:AddChannelTab(channelName)
	tab.NameTag.MouseButton1Click:connect(function()
		self:SwitchCurrentChannel(channelName)
	end)

	channel:RegisterChannelTab(tab)

	return channel
end

function methods:GetFirstChannel()
	--// Channels are not indexed numerically, so this function is necessary.
	--// Grabs and returns the first channel it happens to, or nil if none exist.
	for i, v in pairs(self.Channels) do
		return v
	end
	return nil
end

function methods:RemoveChannel(channelName)
	if (not self:GetChannel(channelName)) then
		error("Channel '" .. channelName .. "' does not exist!")
	end

	local indexName = channelName:lower()

	local needsChannelSwitch = false
	if (self.Channels[indexName] == self:GetCurrentChannel()) then
		needsChannelSwitch = true

		self:SwitchCurrentChannel(nil)
	end

	self.Channels[indexName]:Destroy()
	self.Channels[indexName] = nil

	self.ChannelsBar:RemoveChannelTab(channelName)

	if (needsChannelSwitch) then
		local generalChannelExists = (self:GetChannel(ChatSettings.GeneralChannelName) ~= nil)
		local removingGeneralChannel = (indexName == ChatSettings.GeneralChannelName:lower())

		local targetSwitchChannel = nil

		if (generalChannelExists and not removingGeneralChannel) then
			targetSwitchChannel = ChatSettings.GeneralChannelName
		else
			local firstChannel = self:GetFirstChannel()
			targetSwitchChannel = (firstChannel and firstChannel.Name or nil)
		end

		self:SwitchCurrentChannel(targetSwitchChannel)
	end

	if not ChatSettings.ShowChannelsBar then
		if self.ChatBar.TargetChannel == channelName then
			self.ChatBar:SetChannelTarget(ChatSettings.GeneralChannelName)
		end
	end
end

function methods:GetChannel(channelName)
	return channelName and self.Channels[channelName:lower()] or nil
end

function methods:GetTargetMessageChannel()
	if (not ChatSettings.ShowChannelsBar) then
		return self.ChatBar.TargetChannel
	else
		local curChannel = self:GetCurrentChannel()
		return curChannel and curChannel.Name
	end
end

function methods:GetCurrentChannel()
	return self.CurrentChannel
end

function methods:SwitchCurrentChannel(channelName)
	if (not ChatSettings.ShowChannelsBar) then
		local targ = self:GetChannel(channelName)
		if (targ) then
			self.ChatBar:SetChannelTarget(targ.Name)
		end

		channelName = ChatSettings.GeneralChannelName
	end

	local cur = self:GetCurrentChannel()
	local new = self:GetChannel(channelName)
	if new == nil then
		error(string.format("Channel '%s' does not exist.", channelName))
	end

	if (new ~= cur) then
		if (cur) then
			cur:SetActive(false)
			local tab = self.ChannelsBar:GetChannelTab(cur.Name)
			tab:SetActive(false)
		end

		if (new) then
			new:SetActive(true)
			local tab = self.ChannelsBar:GetChannelTab(new.Name)
			tab:SetActive(true)
		end

		self.CurrentChannel = new
	end

end

function methods:UpdateFrameVisibility()
	self.GuiObject.Visible = (self.Visible and self.CoreGuiEnabled)
end

function methods:GetVisible()
	return self.Visible
end

function methods:SetVisible(visible)
	self.Visible = visible
	self:UpdateFrameVisibility()
end

function methods:GetCoreGuiEnabled()
	return self.CoreGuiEnabled
end

function methods:SetCoreGuiEnabled(enabled)
	self.CoreGuiEnabled = enabled
	self:UpdateFrameVisibility()
end

function methods:EnableResizable()
	self.GuiObjects.ChatResizerFrame.Active = true
end

function methods:DisableResizable()
	self.GuiObjects.ChatResizerFrame.Active = false
end

function methods:FadeOutBackground(duration)
	self.ChannelsBar:FadeOutBackground(duration)
	self.MessageLogDisplay:FadeOutBackground(duration)
	self.ChatBar:FadeOutBackground(duration)

	self.AnimParams.Background_TargetTransparency = 1
	self.AnimParams.Background_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
end

function methods:FadeInBackground(duration)
	self.ChannelsBar:FadeInBackground(duration)
	self.MessageLogDisplay:FadeInBackground(duration)
	self.ChatBar:FadeInBackground(duration)

	self.AnimParams.Background_TargetTransparency = 0.6
	self.AnimParams.Background_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
end

function methods:FadeOutText(duration)
	self.MessageLogDisplay:FadeOutText(duration)
	self.ChannelsBar:FadeOutText(duration)
end

function methods:FadeInText(duration)
	self.MessageLogDisplay:FadeInText(duration)
	self.ChannelsBar:FadeInText(duration)
end

function methods:AnimGuiObjects()
	self.GuiObjects.ChatChannelParentFrame.BackgroundTransparency = self.AnimParams.Background_CurrentTransparency
	self.GuiObjects.ChatResizerFrame.BackgroundTransparency = self.AnimParams.Background_CurrentTransparency
	self.GuiObjects.ResizeIcon.ImageTransparency = self.AnimParams.Background_CurrentTransparency
end

function methods:InitializeAnimParams()
	self.AnimParams.Background_TargetTransparency = 0.6
	self.AnimParams.Background_CurrentTransparency = 0.6
	self.AnimParams.Background_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(0)
end

function methods:Update(dtScale)
	self.ChatBar:Update(dtScale)
	self.ChannelsBar:Update(dtScale)
	self.MessageLogDisplay:Update(dtScale)

	self.AnimParams.Background_CurrentTransparency = CurveUtil:Expt(
			self.AnimParams.Background_CurrentTransparency,
			self.AnimParams.Background_TargetTransparency,
			self.AnimParams.Background_NormalizedExptValue,
			dtScale
	)

	self:AnimGuiObjects()
end
