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