function methods.GetMessageModeTextLabel(a)return a:GetMessageModeTextButton()end function methods.IsFocused(a)if a.UserHasChatOff then return false end return(a:GetTextBox()):IsFocused()end function methods.GetVisible(a)return a.GuiObject.Visible end function methods.CaptureFocus(a)if not a.UserHasChatOff then(a:GetTextBox()):CaptureFocus()end end function methods.ReleaseFocus(z,a)(z:GetTextBox()):ReleaseFocus(a)end function methods.ResetText(a)(a:GetTextBox()).Text=""end function methods.SetText(z,a)(z:GetTextBox()).Text=a end function methods.GetEnabled(a)return a.GuiObject.Visible end function methods.SetEnabled(z,a)if z.UserHasChatOff then z.GuiObject.Visible=true else z.GuiObject.Visible=a end end function methods.SetTextLabelText(z,a)if not z.UserHasChatOff then z.TextLabel.Text=a end end function methods.SetTextBoxText(z,a)z.TextBox.Text=a end function methods.GetTextBoxText(a)return a.TextBox.Text end function methods.ResetSize(a)a.TargetYSize=0 a:TweenToTargetYSize()end function methods.CalculateSize(a)if a.CalculatingSizeLock then return end a.CalculatingSizeLock=true local z=a.GuiObject.Size a.GuiObject.Size=UDim2.new(1,0,0,1000)local U=nil local c=nil if a:IsFocused()or a.TextBox.Text~=""then U=a.TextBox.textSize c=a.TextBox.TextBounds.Y else U=a.TextLabel.textSize c=a.TextLabel.TextBounds.Y end a.GuiObject.Size=z local Q=c-U if a.TargetYSize~=Q then a.TargetYSize=Q a:TweenToTargetYSize()end a.CalculatingSizeLock=false end function methods.TweenToTargetYSize(a)local z=UDim2.new(1,0,1,a.TargetYSize)local U=a.GuiObject.Size local c=a.GuiObject.AbsoluteSize.Y a.GuiObject.Size=z local Q=a.GuiObject.AbsoluteSize.Y a.GuiObject.Size=U local O=math.abs(Q-c)local R=math.min(1,O*(1/a.TweenPixelsPerSecond))local C=pcall(function()a.GuiObject:TweenSize(z,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,R,true)end)if not C then a.GuiObject.Size=z end end function methods.SetTextSize(z,a)if not z:IsInCustomState()then if z.TextBox then z.TextBox.TextSize=a end if z.TextLabel then z.TextLabel.TextSize=a end end end function methods.GetDefaultChannelNameColor(a)if ChatSettings.DefaultChannelNameColor then return ChatSettings.DefaultChannelNameColor end return Color3.fromRGB(35,76,142)end function methods.SetChannelTarget(z,a)local U=z.GuiObjects.MessageModeTextButton local c=z.TextBox local Q=z.TextLabel z.TargetChannel=a if not z:IsInCustomState()then if a~=ChatSettings.GeneralChannelName then U.Size=UDim2.new(0,1000,1,0)U.Text=string.format("\091\037\115\093 ",a)local O=z:GetChannelNameColor(a)if O then U.TextColor3=O else U.TextColor3=z:GetDefaultChannelNameColor()end local R=U.TextBounds.X U.Size=UDim2.new(0,R,1,0)c.Size=UDim2.new(1,-R,1,0)c.Position=UDim2.new(0,R,0,0)Q.Size=UDim2.new(1,-R,1,0)Q.Position=UDim2.new(0,R,0,0)else U.Text=""U.Size=UDim2.new(0,0,0,0)c.Size=UDim2.new(1,0,1,0)c.Position=UDim2.new(0,0,0,0)Q.Size=UDim2.new(1,0,1,0)Q.Position=UDim2.new(0,0,0,0)end end end function methods.IsInCustomState(a)return a.InCustomState end function methods.ResetCustomState(a)if a.InCustomState then a.CustomState:Destroy()a.CustomState=nil a.InCustomState=false a.ChatBarParentFrame:ClearAllChildren()a:CreateGuiObjects(a.ChatBarParentFrame)a:SetTextLabelText(ChatLocalization:Get("\071\097\109\101\067\104\097\116\095\067\104\097\116\077\097\105\110\095\067\104\097\116\066\097\114\084\101\120\116","\084\111 \099\104\097\116 \099\108\105\099\107 \104\101\114\101 \111\114 \112\114\101\115\115 \"\047\" \107\101\121"))end end function methods.GetCustomMessage(a)if a.InCustomState then return a.CustomState:GetMessage()end return nil end function methods.CustomStateProcessCompletedMessage(z,a)if z.InCustomState then return z.CustomState:ProcessCompletedMessage()end return false end function methods.FadeOutBackground(z,a)z.AnimParams.Background_TargetTransparency=1 z.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(a)z:FadeOutText(a)end function methods.FadeInBackground(z,a)z.AnimParams.Background_TargetTransparency=.6 z.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(a)z:FadeInText(a)end function methods.FadeOutText(z,a)z.AnimParams.Text_TargetTransparency=1 z.AnimParams.Text_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(a)end function methods.FadeInText(z,a)z.AnimParams.Text_TargetTransparency=.4 z.AnimParams.Text_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(a)end function methods.AnimGuiObjects(a)a.GuiObject.BackgroundTransparency=a.AnimParams.Background_CurrentTransparency a.GuiObjects.TextBoxFrame.BackgroundTransparency=a.AnimParams.Background_CurrentTransparency a.GuiObjects.TextLabel.TextTransparency=a.AnimParams.Text_CurrentTransparency a.GuiObjects.TextBox.TextTransparency=a.AnimParams.Text_CurrentTransparency a.GuiObjects.MessageModeTextButton.TextTransparency=a.AnimParams.Text_CurrentTransparency end function methods.InitializeAnimParams(a)a.AnimParams.Text_TargetTransparency=.4 a.AnimParams.Text_CurrentTransparency=.4 a.AnimParams.Text_NormalizedExptValue=1 a.AnimParams.Background_TargetTransparency=.6 a.AnimParams.Background_CurrentTransparency=.6 a.AnimParams.Background_NormalizedExptValue=1 end function methods.Update(z,a)z.AnimParams.Text_CurrentTransparency=CurveUtil:Expt(z.AnimParams.Text_CurrentTransparency,z.AnimParams.Text_TargetTransparency,z.AnimParams.Text_NormalizedExptValue,a)z.AnimParams.Background_CurrentTransparency=CurveUtil:Expt(z.AnimParams.Background_CurrentTransparency,z.AnimParams.Background_TargetTransparency,z.AnimParams.Background_NormalizedExptValue,a)z:AnimGuiObjects()end function methods.SetChannelNameColor(U,a,z)U.ChannelNameColors[a]=z if U.GuiObjects.MessageModeTextButton.Text==a then U.GuiObjects.MessageModeTextButton.TextColor3=z end end function methods.GetChannelNameColor(z,a)return z.ChannelNameColors[a]end

function methods:GetMessageModeTextLabel()
	return self:GetMessageModeTextButton()
end

function methods:IsFocused()
	if self.UserHasChatOff then
		return false
	end

	return self:GetTextBox():IsFocused()
end

function methods:GetVisible()
	return self.GuiObject.Visible
end

function methods:CaptureFocus()
	if not self.UserHasChatOff then
		self:GetTextBox():CaptureFocus()
	end
end

function methods:ReleaseFocus(didRelease)
	self:GetTextBox():ReleaseFocus(didRelease)
end

function methods:ResetText()
	self:GetTextBox().Text = ""
end

function methods:SetText(text)
	self:GetTextBox().Text = text
end

function methods:GetEnabled()
	return self.GuiObject.Visible
end

function methods:SetEnabled(enabled)
	if self.UserHasChatOff then
		-- The chat bar can not be removed if a user has chat turned off so that
		-- the chat bar can display a message explaining that chat is turned off.
		self.GuiObject.Visible = true
	else
		self.GuiObject.Visible = enabled
	end
end

function methods:SetTextLabelText(text)
	if not self.UserHasChatOff then
		self.TextLabel.Text = text
	end
end

function methods:SetTextBoxText(text)
	self.TextBox.Text = text
end

function methods:GetTextBoxText()
	return self.TextBox.Text
end

function methods:ResetSize()
	self.TargetYSize = 0
	self:TweenToTargetYSize()
end

function methods:CalculateSize()
	if self.CalculatingSizeLock then
		return
	end
	self.CalculatingSizeLock = true

	local lastPos = self.GuiObject.Size
	self.GuiObject.Size = UDim2.new(1, 0, 0, 1000)

	local textSize = nil
	local bounds = nil

	if self:IsFocused() or self.TextBox.Text ~= "" then
		textSize = self.TextBox.textSize
		bounds = self.TextBox.TextBounds.Y
	else
		textSize = self.TextLabel.textSize
		bounds = self.TextLabel.TextBounds.Y
	end

	self.GuiObject.Size = lastPos

	local newTargetYSize = bounds - textSize
	if (self.TargetYSize ~= newTargetYSize) then
		self.TargetYSize = newTargetYSize
		self:TweenToTargetYSize()
	end

	self.CalculatingSizeLock = false
end

function methods:TweenToTargetYSize()
	local endSize = UDim2.new(1, 0, 1, self.TargetYSize)
	local curSize = self.GuiObject.Size

	local curAbsoluteSizeY = self.GuiObject.AbsoluteSize.Y
	self.GuiObject.Size = endSize
	local endAbsoluteSizeY = self.GuiObject.AbsoluteSize.Y
	self.GuiObject.Size = curSize

	local pixelDistance = math.abs(endAbsoluteSizeY - curAbsoluteSizeY)
	local tweeningTime = math.min(1, (pixelDistance * (1 / self.TweenPixelsPerSecond))) -- pixelDistance * (seconds per pixels)

	local success = pcall(function() self.GuiObject:TweenSize(endSize, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, tweeningTime, true) end)
	if (not success) then
		self.GuiObject.Size = endSize
	end
end

function methods:SetTextSize(textSize)
	if not self:IsInCustomState() then
		if self.TextBox then
			self.TextBox.TextSize = textSize
		end
		if self.TextLabel then
			self.TextLabel.TextSize = textSize
		end
	end
end

function methods:GetDefaultChannelNameColor()
	if ChatSettings.DefaultChannelNameColor then
		return ChatSettings.DefaultChannelNameColor
	end
	return Color3.fromRGB(35, 76, 142)
end

function methods:SetChannelTarget(targetChannel)
	local messageModeTextButton = self.GuiObjects.MessageModeTextButton
	local textBox = self.TextBox
	local textLabel = self.TextLabel

	self.TargetChannel = targetChannel

	if not self:IsInCustomState() then
		if targetChannel ~= ChatSettings.GeneralChannelName then
			messageModeTextButton.Size = UDim2.new(0, 1000, 1, 0)
			messageModeTextButton.Text = string.format("[%s] ", targetChannel)

			local channelNameColor = self:GetChannelNameColor(targetChannel)
			if channelNameColor then
				messageModeTextButton.TextColor3 = channelNameColor
			else
				messageModeTextButton.TextColor3 = self:GetDefaultChannelNameColor()
			end

			local xSize = messageModeTextButton.TextBounds.X
			messageModeTextButton.Size = UDim2.new(0, xSize, 1, 0)
			textBox.Size = UDim2.new(1, -xSize, 1, 0)
			textBox.Position = UDim2.new(0, xSize, 0, 0)
			textLabel.Size = UDim2.new(1, -xSize, 1, 0)
			textLabel.Position = UDim2.new(0, xSize, 0, 0)
		else
			messageModeTextButton.Text = ""
			messageModeTextButton.Size = UDim2.new(0, 0, 0, 0)
			textBox.Size = UDim2.new(1, 0, 1, 0)
			textBox.Position = UDim2.new(0, 0, 0, 0)
			textLabel.Size = UDim2.new(1, 0, 1, 0)
			textLabel.Position = UDim2.new(0, 0, 0, 0)
		end
	end
end

function methods:IsInCustomState()
	return self.InCustomState
end

function methods:ResetCustomState()
	if self.InCustomState then
		self.CustomState:Destroy()
		self.CustomState = nil
		self.InCustomState = false

		self.ChatBarParentFrame:ClearAllChildren()
		self:CreateGuiObjects(self.ChatBarParentFrame)
		self:SetTextLabelText(
			ChatLocalization:Get(
				"GameChat_ChatMain_ChatBarText",
				'To chat click here or press "/" key'
			)
		)
	end
end

function methods:GetCustomMessage()
	if self.InCustomState then
		return self.CustomState:GetMessage()
	end
	return nil
end

function methods:CustomStateProcessCompletedMessage(message)
	if self.InCustomState then
		return self.CustomState:ProcessCompletedMessage()
	end
	return false
end

function methods:FadeOutBackground(duration)
	self.AnimParams.Background_TargetTransparency = 1
	self.AnimParams.Background_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
	self:FadeOutText(duration)
end

function methods:FadeInBackground(duration)
	self.AnimParams.Background_TargetTransparency = 0.6
	self.AnimParams.Background_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
	self:FadeInText(duration)
end

function methods:FadeOutText(duration)
	self.AnimParams.Text_TargetTransparency = 1
	self.AnimParams.Text_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
end

function methods:FadeInText(duration)
	self.AnimParams.Text_TargetTransparency = 0.4
	self.AnimParams.Text_NormalizedExptValue = CurveUtil:NormalizedDefaultExptValueInSeconds(duration)
end

function methods:AnimGuiObjects()
	self.GuiObject.BackgroundTransparency = self.AnimParams.Background_CurrentTransparency
	self.GuiObjects.TextBoxFrame.BackgroundTransparency = self.AnimParams.Background_CurrentTransparency

	self.GuiObjects.TextLabel.TextTransparency = self.AnimParams.Text_CurrentTransparency
	self.GuiObjects.TextBox.TextTransparency = self.AnimParams.Text_CurrentTransparency
	self.GuiObjects.MessageModeTextButton.TextTransparency = self.AnimParams.Text_CurrentTransparency
end

function methods:InitializeAnimParams()
	self.AnimParams.Text_TargetTransparency = 0.4
	self.AnimParams.Text_CurrentTransparency = 0.4
	self.AnimParams.Text_NormalizedExptValue = 1

	self.AnimParams.Background_TargetTransparency = 0.6
	self.AnimParams.Background_CurrentTransparency = 0.6
	self.AnimParams.Background_NormalizedExptValue = 1
end

function methods:Update(dtScale)
	self.AnimParams.Text_CurrentTransparency = CurveUtil:Expt(
			self.AnimParams.Text_CurrentTransparency,
			self.AnimParams.Text_TargetTransparency,
			self.AnimParams.Text_NormalizedExptValue,
			dtScale
	)
	self.AnimParams.Background_CurrentTransparency = CurveUtil:Expt(
			self.AnimParams.Background_CurrentTransparency,
			self.AnimParams.Background_TargetTransparency,
			self.AnimParams.Background_NormalizedExptValue,
			dtScale
	)

	self:AnimGuiObjects()
end

function methods:SetChannelNameColor(channelName, channelNameColor)
	self.ChannelNameColors[channelName] = channelNameColor
	if self.GuiObjects.MessageModeTextButton.Text == channelName then
		self.GuiObjects.MessageModeTextButton.TextColor3 = channelNameColor
	end
end

function methods:GetChannelNameColor(channelName)
	return self.ChannelNameColors[channelName]
end
