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