function mergeProps(g,o)if not g or not o then return end for g,B in pairs(g)do if o[g]~=nil then o[g]=B end end end function methods.CreateGuiObjects(o,g)local B pcall(function()B=Chat:InvokeChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow,nil)end)mergeProps(B,ChatSettings)local u=Instance.new("\070\114\097\109\101")u.BackgroundTransparency=1 u.Active=ChatSettings.WindowDraggable u.Parent=g u.AutoLocalize=false local W=Instance.new("\070\114\097\109\101")W.Selectable=false W.Name="\067\104\097\116\066\097\114\080\097\114\101\110\116\070\114\097\109\101"W.BackgroundTransparency=1 W.Parent=u local I=Instance.new("\070\114\097\109\101")I.Selectable=false I.Name="\067\104\097\110\110\101\108\115\066\097\114\080\097\114\101\110\116\070\114\097\109\101"I.BackgroundTransparency=1 I.Position=UDim2.new(0,0,0,0)I.Parent=u local T=Instance.new("\070\114\097\109\101")T.Selectable=false T.Name="\067\104\097\116\067\104\097\110\110\101\108\080\097\114\101\110\116\070\114\097\109\101"T.BackgroundTransparency=1 T.BackgroundColor3=ChatSettings.BackGroundColor T.BackgroundTransparency=.6 T.BorderSizePixel=0 T.Parent=u local s=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")s.Selectable=false s.Image=""s.BackgroundTransparency=.6 s.BorderSizePixel=0 s.Visible=false s.BackgroundColor3=ChatSettings.BackGroundColor s.Active=true if bubbleChatOnly()then s.Position=UDim2.new(1,-s.AbsoluteSize.X,0,0)else s.Position=UDim2.new(1,-s.AbsoluteSize.X,1,-s.AbsoluteSize.Y)end s.Parent=u local Q=Instance.new("\073\109\097\103\101\076\097\098\101\108")Q.Selectable=false Q.Size=UDim2.new(.8,0,.8,0)Q.Position=UDim2.new(.2,0,.2,0)Q.BackgroundTransparency=1 Q.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\054\049\056\056\048\055\052\051"Q.Parent=s local function V()local g=u while g and not g:IsA("\083\099\114\101\101\110\071\117\105")do g=g.Parent end return g end local f=DEVICE_DESKTOP local h=V()if h.AbsoluteSize.X<=PHONE_SCREEN_WIDTH then f=DEVICE_PHONE elseif h.AbsoluteSize.X<=TABLET_SCREEN_WIDTH then f=DEVICE_TABLET end local q=false local function N()if q then return end q=true if not u:IsDescendantOf(PlayerGui)then return end local g=V()local o=ChatSettings.MinimumWindowSize local B=ChatSettings.MaximumWindowSize local T=I.AbsoluteSize.Y+W.AbsoluteSize.Y local s=o.X.Scale*g.AbsoluteSize.X+o.X.Offset local Q=math.max(o.Y.Scale*g.AbsoluteSize.Y+o.Y.Offset,T)local f=B.X.Scale*g.AbsoluteSize.X+B.X.Offset local h=B.Y.Scale*g.AbsoluteSize.Y+B.Y.Offset local N=u.AbsoluteSize.X local m=u.AbsoluteSize.Y if N<s then local g=UDim2.new(0,s-N,0,0)u.Size=u.Size+g elseif N>f then local g=UDim2.new(0,f-N,0,0)u.Size=u.Size+g end if m<Q then local g=UDim2.new(0,0,0,Q-m)u.Size=u.Size+g elseif m>h then local g=UDim2.new(0,0,0,h-m)u.Size=u.Size+g end local a=u.AbsoluteSize.X/g.AbsoluteSize.X local F=u.AbsoluteSize.Y/g.AbsoluteSize.Y if FFlagFixMouseCapture then a=math.min(a,.45)F=math.min(a,.45)end u.Size=UDim2.new(a,0,F,0)q=false end u.Changed:connect(function(g)if g=="\065\098\115\111\108\117\116\101\083\105\122\101"then N()end end)s.DragBegin:connect(function(g)u.Draggable=false end)local function m(g)if ChatSettings.WindowDraggable==false and ChatSettings.WindowResizable==false then return end local o=(g-u.AbsolutePosition)+s.AbsoluteSize u.Size=UDim2.new(0,o.X,0,o.Y)if bubbleChatOnly()then s.Position=UDim2.new(1,-s.AbsoluteSize.X,0,0)else s.Position=UDim2.new(1,-s.AbsoluteSize.X,1,-s.AbsoluteSize.Y)end end s.DragStopped:connect(function(g,o)u.Draggable=ChatSettings.WindowDraggable end)local a=false s.Changed:connect(function(g)if g=="\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110"and not u.Draggable then if a then return end a=true m(s.AbsolutePosition)a=false end end)local function F(g)if f==DEVICE_PHONE then g=g or ChatSettings.ChatChannelsTabTextSizePhone else g=g or ChatSettings.ChatChannelsTabTextSize end local o=g local B=math.max(32,o+8)+2 return B end local function v(g)if f==DEVICE_PHONE then g=g or ChatSettings.ChatBarTextSizePhone else g=g or ChatSettings.ChatBarTextSize end local o=g local B=(o+14)+10 return B end if bubbleChatOnly()then W.Position=UDim2.new(0,0,0,0)I.Visible=false I.Active=false T.Visible=false T.Active=false local g=0 local o=0 local B=V()if f==DEVICE_PHONE then g=ChatSettings.DefaultWindowSizePhone.X.Scale o=ChatSettings.DefaultWindowSizePhone.X.Offset elseif f==DEVICE_TABLET then g=ChatSettings.DefaultWindowSizeTablet.X.Scale o=ChatSettings.DefaultWindowSizeTablet.X.Offset else g=ChatSettings.DefaultWindowSizeTablet.X.Scale o=ChatSettings.DefaultWindowSizeTablet.X.Offset end local s=v()u.Size=UDim2.new(g,o,0,s)u.Position=ChatSettings.DefaultWindowPosition else local g=V()if f==DEVICE_PHONE then u.Size=ChatSettings.DefaultWindowSizePhone elseif f==DEVICE_TABLET then u.Size=ChatSettings.DefaultWindowSizeTablet else u.Size=ChatSettings.DefaultWindowSizeDesktop end u.Position=ChatSettings.DefaultWindowPosition end if f==DEVICE_PHONE then ChatSettings.ChatWindowTextSize=ChatSettings.ChatWindowTextSizePhone ChatSettings.ChatChannelsTabTextSize=ChatSettings.ChatChannelsTabTextSizePhone ChatSettings.ChatBarTextSize=ChatSettings.ChatBarTextSizePhone end local function K(g)u.Active=g u.Draggable=g end local function d(g)s.Visible=g s.Draggable=g local o=W.Size.Y.Offset if g then W.Size=UDim2.new(1,-o-2,0,o)if not bubbleChatOnly()then W.Position=UDim2.new(0,0,1,-o)end else W.Size=UDim2.new(1,0,0,o)if not bubbleChatOnly()then W.Position=UDim2.new(0,0,1,-o)end end end local function A()local g=F()local o=v()if ChatSettings.ShowChannelsBar then T.Size=UDim2.new(1,0,1,-(((g+o)+2)+2))T.Position=UDim2.new(0,0,0,g+2)else T.Size=UDim2.new(1,0,1,-((o+2)+2))T.Position=UDim2.new(0,0,0,2)end end local function G(g)local o=F(g)I.Size=UDim2.new(1,0,0,o)A()end local function w(g)local o=v(g)W.Size=UDim2.new(1,0,0,o)if not bubbleChatOnly()then W.Position=UDim2.new(0,0,1,-o)end s.Size=UDim2.new(0,o,0,o)s.Position=UDim2.new(1,-o,1,-o)A()d(ChatSettings.WindowResizable)end local function S(g)I.Visible=g A()end G(ChatSettings.ChatChannelsTabTextSize)w(ChatSettings.ChatBarTextSize)K(ChatSettings.WindowDraggable)d(ChatSettings.WindowResizable)S(ChatSettings.ShowChannelsBar)ChatSettings.SettingsChanged:connect(function(g,o)if g=="\087\105\110\100\111\119\068\114\097\103\103\097\098\108\101"then K(o)elseif g=="\087\105\110\100\111\119\082\101\115\105\122\097\098\108\101"then d(o)elseif g=="\067\104\097\116\067\104\097\110\110\101\108\115\084\097\098\084\101\120\116\083\105\122\101"then G(o)elseif g=="\067\104\097\116\066\097\114\084\101\120\116\083\105\122\101"then w(o)elseif g=="\083\104\111\119\067\104\097\110\110\101\108\115\066\097\114"then S(o)end end)o.GuiObject=u o.GuiObjects.BaseFrame=u o.GuiObjects.ChatBarParentFrame=W o.GuiObjects.ChannelsBarParentFrame=I o.GuiObjects.ChatChannelParentFrame=T o.GuiObjects.ChatResizerFrame=s o.GuiObjects.ResizeIcon=Q o:AnimGuiObjects()end function methods.GetChatBar(g)return g.ChatBar end function methods.RegisterChatBar(o,g)o.ChatBar=g o.ChatBar:CreateGuiObjects(o.GuiObjects.ChatBarParentFrame)end function methods.RegisterChannelsBar(o,g)o.ChannelsBar=g o.ChannelsBar:CreateGuiObjects(o.GuiObjects.ChannelsBarParentFrame)end function methods.RegisterMessageLogDisplay(o,g)o.MessageLogDisplay=g o.MessageLogDisplay.GuiObject.Parent=o.GuiObjects.ChatChannelParentFrame end function methods.AddChannel(o,g)if o:GetChannel(g)then error("\067\104\097\110\110\101\108 \'"..(g.."\' \097\108\114\101\097\100\121 \101\120\105\115\116\115\033"))return end local B=moduleChatChannel.new(g,o.MessageLogDisplay)o.Channels[g:lower()]=B B:SetActive(false)local u=o.ChannelsBar:AddChannelTab(g)u.NameTag.MouseButton1Click:connect(function()o:SwitchCurrentChannel(g)end)B:RegisterChannelTab(u)return B end function methods.GetFirstChannel(g)for g,o in pairs(g.Channels)do return o end return nil end function methods.RemoveChannel(o,g)if not o:GetChannel(g)then error("\067\104\097\110\110\101\108 \'"..(g.."\' \100\111\101\115 \110\111\116 \101\120\105\115\116\033"))end local B=g:lower()local u=false if o.Channels[B]==o:GetCurrentChannel()then u=true o:SwitchCurrentChannel(nil)end o.Channels[B]:Destroy()o.Channels[B]=nil o.ChannelsBar:RemoveChannelTab(g)if u then local g=o:GetChannel(ChatSettings.GeneralChannelName)~=nil local u=B==ChatSettings.GeneralChannelName:lower()local W=nil if g and not u then W=ChatSettings.GeneralChannelName else local g=o:GetFirstChannel()W=g and g.Name or nil end o:SwitchCurrentChannel(W)end if not ChatSettings.ShowChannelsBar then if o.ChatBar.TargetChannel==g then o.ChatBar:SetChannelTarget(ChatSettings.GeneralChannelName)end end end function methods.GetChannel(o,g)return g and o.Channels[g:lower()]or nil end function methods.GetTargetMessageChannel(g)if not ChatSettings.ShowChannelsBar then return g.ChatBar.TargetChannel else local o=g:GetCurrentChannel()return o and o.Name end end function methods.GetCurrentChannel(g)return g.CurrentChannel end function methods.SwitchCurrentChannel(o,g)if not ChatSettings.ShowChannelsBar then local B=o:GetChannel(g)if B then o.ChatBar:SetChannelTarget(B.Name)end g=ChatSettings.GeneralChannelName end local B=o:GetCurrentChannel()local u=o:GetChannel(g)if u==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",g))end if u~=B then if B then B:SetActive(false)local g=o.ChannelsBar:GetChannelTab(B.Name)g:SetActive(false)end if u then u:SetActive(true)local g=o.ChannelsBar:GetChannelTab(u.Name)g:SetActive(true)end o.CurrentChannel=u end end function methods.UpdateFrameVisibility(g)g.GuiObject.Visible=g.Visible and g.CoreGuiEnabled end function methods.GetVisible(g)return g.Visible end function methods.SetVisible(o,g)o.Visible=g o:UpdateFrameVisibility()end function methods.GetCoreGuiEnabled(g)return g.CoreGuiEnabled end function methods.SetCoreGuiEnabled(o,g)o.CoreGuiEnabled=g o:UpdateFrameVisibility()end function methods.EnableResizable(g)g.GuiObjects.ChatResizerFrame.Active=true end function methods.DisableResizable(g)g.GuiObjects.ChatResizerFrame.Active=false end function methods.FadeOutBackground(o,g)o.ChannelsBar:FadeOutBackground(g)o.MessageLogDisplay:FadeOutBackground(g)o.ChatBar:FadeOutBackground(g)o.AnimParams.Background_TargetTransparency=1 o.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(g)end function methods.FadeInBackground(o,g)o.ChannelsBar:FadeInBackground(g)o.MessageLogDisplay:FadeInBackground(g)o.ChatBar:FadeInBackground(g)o.AnimParams.Background_TargetTransparency=.6 o.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(g)end function methods.FadeOutText(o,g)o.MessageLogDisplay:FadeOutText(g)o.ChannelsBar:FadeOutText(g)end function methods.FadeInText(o,g)o.MessageLogDisplay:FadeInText(g)o.ChannelsBar:FadeInText(g)end function methods.AnimGuiObjects(g)g.GuiObjects.ChatChannelParentFrame.BackgroundTransparency=g.AnimParams.Background_CurrentTransparency g.GuiObjects.ChatResizerFrame.BackgroundTransparency=g.AnimParams.Background_CurrentTransparency g.GuiObjects.ResizeIcon.ImageTransparency=g.AnimParams.Background_CurrentTransparency end function methods.InitializeAnimParams(g)g.AnimParams.Background_TargetTransparency=.6 g.AnimParams.Background_CurrentTransparency=.6 g.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(0)end function methods.Update(o,g)o.ChatBar:Update(g)o.ChannelsBar:Update(g)o.MessageLogDisplay:Update(g)o.AnimParams.Background_CurrentTransparency=CurveUtil:Expt(o.AnimParams.Background_CurrentTransparency,o.AnimParams.Background_TargetTransparency,o.AnimParams.Background_NormalizedExptValue,g)o:AnimGuiObjects()end

function mergeProps(source, target)
	if not source or not target then return end
	for prop, value in pairs(source) do
		if target[prop] ~= nil then
			target[prop] = value
		end
	end
end

function methods:CreateGuiObjects(targetParent)
	local userDefinedChatWindowStyle 
	pcall(function()
		userDefinedChatWindowStyle= Chat:InvokeChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, nil)
	end)

	-- merge the userdefined settings with the ChatSettings
	mergeProps(userDefinedChatWindowStyle, ChatSettings)

	local BaseFrame = Instance.new("Frame")
	BaseFrame.BackgroundTransparency = 1
	BaseFrame.Active = ChatSettings.WindowDraggable
	BaseFrame.Parent = targetParent
    BaseFrame.AutoLocalize = false

	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
		
		-- cap chat window scale at a value smaller than 0.5 to prevent center of screen overlap
		if FFlagFixMouseCapture then 
			xScale = math.min(xScale, 0.45)
			yScale = math.min(xScale, 0.45)
		end
		
		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
