function methods.GetMessageModeTextLabel(y)return y:GetMessageModeTextButton()end function methods.IsFocused(y)if y.UserHasChatOff then return false end return(y:GetTextBox()):IsFocused()end function methods.GetVisible(y)return y.GuiObject.Visible end function methods.CaptureFocus(y)if not y.UserHasChatOff then(y:GetTextBox()):CaptureFocus()end end function methods.ReleaseFocus(u,y)(u:GetTextBox()):ReleaseFocus(y)end function methods.ResetText(y)(y:GetTextBox()).Text=""end function methods.SetText(u,y)(u:GetTextBox()).Text=y end function methods.GetEnabled(y)return y.GuiObject.Visible end function methods.SetEnabled(u,y)if u.UserHasChatOff then u.GuiObject.Visible=true else u.GuiObject.Visible=y end end function methods.SetTextLabelText(u,y)if not u.UserHasChatOff then u.TextLabel.Text=y end end function methods.SetTextBoxText(u,y)u.TextBox.Text=y end function methods.GetTextBoxText(y)return y.TextBox.Text end function methods.ResetSize(y)y.TargetYSize=0 y:TweenToTargetYSize()end function methods.CalculateSize(y)if y.CalculatingSizeLock then return end y.CalculatingSizeLock=true local u=y.GuiObject.Size y.GuiObject.Size=UDim2.new(1,0,0,1000)local l=nil local D=nil if y:IsFocused()or y.TextBox.Text~=""then l=y.TextBox.textSize D=y.TextBox.TextBounds.Y else l=y.TextLabel.textSize D=y.TextLabel.TextBounds.Y end y.GuiObject.Size=u local M=D-l if y.TargetYSize~=M then y.TargetYSize=M y:TweenToTargetYSize()end y.CalculatingSizeLock=false end function methods.TweenToTargetYSize(y)local u=UDim2.new(1,0,1,y.TargetYSize)local l=y.GuiObject.Size local D=y.GuiObject.AbsoluteSize.Y y.GuiObject.Size=u local M=y.GuiObject.AbsoluteSize.Y y.GuiObject.Size=l local t=math.abs(M-D)local o=math.min(1,t*(1/y.TweenPixelsPerSecond))local K=pcall(function()y.GuiObject:TweenSize(u,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,o,true)end)if not K then y.GuiObject.Size=u end end function methods.SetTextSize(u,y)if not u:IsInCustomState()then if u.TextBox then u.TextBox.TextSize=y end if u.TextLabel then u.TextLabel.TextSize=y end end end function methods.GetDefaultChannelNameColor(y)if ChatSettings.DefaultChannelNameColor then return ChatSettings.DefaultChannelNameColor end return Color3.fromRGB(35,76,142)end function methods.SetChannelTarget(u,y)local l=u.GuiObjects.MessageModeTextButton local D=u.TextBox local M=u.TextLabel u.TargetChannel=y if not u:IsInCustomState()then if y~=ChatSettings.GeneralChannelName then l.Size=UDim2.new(0,1000,1,0)l.Text=string.format("\091\037\115\093 ",y)local t=u:GetChannelNameColor(y)if t then l.TextColor3=t else l.TextColor3=u:GetDefaultChannelNameColor()end local o=l.TextBounds.X l.Size=UDim2.new(0,o,1,0)D.Size=UDim2.new(1,-o,1,0)D.Position=UDim2.new(0,o,0,0)M.Size=UDim2.new(1,-o,1,0)M.Position=UDim2.new(0,o,0,0)else l.Text=""l.Size=UDim2.new(0,0,0,0)D.Size=UDim2.new(1,0,1,0)D.Position=UDim2.new(0,0,0,0)M.Size=UDim2.new(1,0,1,0)M.Position=UDim2.new(0,0,0,0)end end end function methods.IsInCustomState(y)return y.InCustomState end function methods.ResetCustomState(y)if y.InCustomState then y.CustomState:Destroy()y.CustomState=nil y.InCustomState=false y.ChatBarParentFrame:ClearAllChildren()y:CreateGuiObjects(y.ChatBarParentFrame)y: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(y)if y.InCustomState then return y.CustomState:GetMessage()end return nil end function methods.CustomStateProcessCompletedMessage(u,y)if u.InCustomState then return u.CustomState:ProcessCompletedMessage()end return false end function methods.FadeOutBackground(u,y)u.AnimParams.Background_TargetTransparency=1 u.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(y)u:FadeOutText(y)end function methods.FadeInBackground(u,y)u.AnimParams.Background_TargetTransparency=.6 u.AnimParams.Background_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(y)u:FadeInText(y)end function methods.FadeOutText(u,y)u.AnimParams.Text_TargetTransparency=1 u.AnimParams.Text_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(y)end function methods.FadeInText(u,y)u.AnimParams.Text_TargetTransparency=.4 u.AnimParams.Text_NormalizedExptValue=CurveUtil:NormalizedDefaultExptValueInSeconds(y)end function methods.AnimGuiObjects(y)y.GuiObject.BackgroundTransparency=y.AnimParams.Background_CurrentTransparency y.GuiObjects.TextBoxFrame.BackgroundTransparency=y.AnimParams.Background_CurrentTransparency y.GuiObjects.TextLabel.TextTransparency=y.AnimParams.Text_CurrentTransparency y.GuiObjects.TextBox.TextTransparency=y.AnimParams.Text_CurrentTransparency y.GuiObjects.MessageModeTextButton.TextTransparency=y.AnimParams.Text_CurrentTransparency end function methods.InitializeAnimParams(y)y.AnimParams.Text_TargetTransparency=.4 y.AnimParams.Text_CurrentTransparency=.4 y.AnimParams.Text_NormalizedExptValue=1 y.AnimParams.Background_TargetTransparency=.6 y.AnimParams.Background_CurrentTransparency=.6 y.AnimParams.Background_NormalizedExptValue=1 end function methods.Update(u,y)u.AnimParams.Text_CurrentTransparency=CurveUtil:Expt(u.AnimParams.Text_CurrentTransparency,u.AnimParams.Text_TargetTransparency,u.AnimParams.Text_NormalizedExptValue,y)u.AnimParams.Background_CurrentTransparency=CurveUtil:Expt(u.AnimParams.Background_CurrentTransparency,u.AnimParams.Background_TargetTransparency,u.AnimParams.Background_NormalizedExptValue,y)u:AnimGuiObjects()end function methods.SetChannelNameColor(l,y,u)l.ChannelNameColors[y]=u if l.GuiObjects.MessageModeTextButton.Text==y then l.GuiObjects.MessageModeTextButton.TextColor3=u end end function methods.GetChannelNameColor(u,y)return u.ChannelNameColors[y]end
-- Deprecated in favour of GetMessageModeTextButton
-- Retained for compatibility reasons.
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
