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

local function measureSize(textObj)
	return TextService:GetTextSize(
		textObj.Text,
		textObj.TextSize,
		textObj.Font,
		Vector2.new(textObj.AbsoluteSize.X, 10000)
	)
end

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

	local textSize = nil
	local bounds = nil

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

	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
