Claro! Vou ajudá-lo a modificar o seu script conforme solicitado. Vamos remover as funções relacionadas a music_note, TextButton, ImageLabel X e substituí-las por uma nova lógica que abrirá o Frame com animação usando um novo TextButton que você irá criar.
Passos a seguir:
- Remover referências ao
ToggleButton e seus elementos (music_note, X, etc.).
- Adicionar uma nova função para lidar com a abertura do
Frame usando o novo TextButton.
Código Modificado
Aqui está o código atualizado com as modificações necessárias:
local Utility = {}
--// services
local TweenService = game:GetService('TweenService')
--// variables
local AnimationFrame = script.Parent.Parent.MainFrame
local Player = game.Players.LocalPlayer
local scroll = AnimationFrame.Content.ScrollingFrame
-- Tween
local function tween(obj, assignedProperty, assignedValue, completeTime, easingStyle, easingDirection)
TweenService:Create(obj, TweenInfo.new(completeTime, easingStyle or Enum.EasingStyle.Quint, easingDirection or Enum.EasingDirection.Out), {
[assignedProperty] = assignedValue
}):Play()
end
Utility.Tween = tween
-- Utility.SetupSectionButton()
local SelectedSectionButton = nil
function Utility.SetupSectionButton(sectionButton, sectionName)
sectionButton.MouseButton1Up:Connect(function()
Utility.DisableSectionButtons(sectionButton)
SelectedSectionButton = sectionButton
tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(255,255,255), 0.5)
tween(sectionButton, 'BackgroundTransparency', 0.3, 0.5)
tween(sectionButton, 'TextColor3', Color3.fromRGB(0,0,0), 0.5)
Utility.Query(sectionName)
end)
sectionButton.MouseEnter:Connect(function()
if SelectedSectionButton ~= sectionButton then
tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(30,30,30), 0.5)
end
end)
sectionButton.MouseLeave:Connect(function()
if SelectedSectionButton ~= sectionButton then
tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(10,10,10), 0.5)
end
end)
end
-- Utility.DisableSectionButtons
function Utility.DisableSectionButtons(exception)
for i,v in pairs(AnimationFrame.Sections:GetChildren()) do
if v:IsA('TextButton') and v ~= exception then
tween(v, 'BackgroundColor3', Color3.fromRGB(10,10,10), 0.5)
tween(v, 'BackgroundTransparency', 0.7, 0.5)
tween(v, 'TextColor3', Color3.fromRGB(255,255,255), 0.5)
end
end
end
-- Utility.SetRunningAnimation()
local SelectedButton = nil
local PlayingAnimation = nil
function Utility.SetRunningAnimation(button)
if SelectedButton then
tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(10, 10, 10), 0.5)
tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5)
if SelectedButton == button then
if PlayingAnimation then
PlayingAnimation:Stop()
end
SelectedButton = nil
PlayingAnimation = nil
return
end
end
SelectedButton = button
tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(255,255,255), 0.5)
tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5)
if PlayingAnimation then
-- stop the running animation
PlayingAnimation:Stop()
end
-- load new animation
PlayingAnimation = Player.Character.Humanoid.Animator:LoadAnimation(button.WorldModel.Animation)
-- Set the animation priority to "Action"
PlayingAnimation.Priority = Enum.AnimationPriority.Action
PlayingAnimation:Play()
end
-- Utility.SetupNewButton()
function Utility.SetupNewButton(newButton)
newButton.MouseEnter:Connect(function()
if SelectedButton ~= newButton then
tween(newButton, 'BackgroundColor3', Color3.fromRGB(100, 100, 100), 0.5)
end
end)
newButton.MouseLeave:Connect(function()
if SelectedButton ~= newButton then
tween(newButton, 'BackgroundColor3', Color3.fromRGB(0,0,0), 0.5)
end
end)
-- Conectar a nova lógica para abrir o Frame com animação
newButton.MouseButton1Up:Connect(function()
Utility.ToggleAnimationFrame()
end)
end
-- Utility.Query()
function Utility.Query(text)
for i, v in pairs(AnimationFrame.Content.ScrollingFrame:GetChildren()) do
if v:IsA('ViewportFrame') then
v.Visible = (not text and true) or string.find(v:GetAttribute('Section'):lower(), text:lower())
end
end
end
-- Nova função para alternar a visibilidade do AnimationFrame com animação
local FrameVisible = false
function Utility.ToggleAnimationFrame()
if FrameVisible then
-- Animar para fechar o frame
tween(AnimationFrame, 'Size', UDim2.new(0, 0, 1, 0), 0.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
tween(AnimationFrame, 'Transparency', 1, 0.5) -- Supondo que exista uma propriedade Transparency ou similar
else
-- Animar para abrir o frame
tween(AnimationFrame, 'Size', UDim2.new(1, 0, 1, 0), 0.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
tween(AnimationFrame, 'Transparency', 0, 0.5) -- Supondo que exista uma propriedade Transparency ou similar
end
FrameVisible = not FrameVisible
end
return Utility
Explicações das Modificações
-
Remoção do ToggleButton e Seus Elementos:
- Removi as variáveis e funções relacionadas a
ToggleButton, music_note e X.
- Removi as funções
EnableToggleButton e DisableToggleButton, já que elas gerenciavam a visibilidade dos ícones que agora não são mais necessários.
-
Adição da Função ToggleAnimationFrame:
- Criei uma nova função
ToggleAnimationFrame que alterna a visibilidade do AnimationFrame com uma animação.
- Utilize propriedades como
Size e Transparency para animar a abertura e fechamento do Frame. Certifique-se de que o AnimationFrame tenha uma propriedade Transparency ou ajuste conforme necessário (por exemplo, caso esteja lidando com objetos filhos específicos que precisam ser animados).
-
Configuração do Novo TextButton:
- Na função
SetupNewButton, além de gerenciar os efeitos de MouseEnter e MouseLeave, conectei o evento MouseButton1Up para chamar a nova função ToggleAnimationFrame.
- Certifique-se de chamar
Utility.SetupNewButton para o seu novo TextButton após criá-lo.
Como Utilizar a Nova Configuração
-
Crie o Novo TextButton:
- Adicione um novo
TextButton na sua interface de usuário onde desejar.
- Suponha que este botão seja chamado
NewToggleButton.
-
Configure o Novo Botão no Script:
- Após criar o botão, chame a função
Utility.SetupNewButton passando o botão como argumento.
-- Supondo que você tenha um botão chamado NewToggleButton no seu UI
local Utility = require(path_to_utility_script)
local newToggleButton = script.Parent.NewToggleButton -- Ajuste o caminho conforme necessário
Utility.SetupNewButton(newToggleButton)
- Personalize as Animações Conforme Necessário:
- A função
ToggleAnimationFrame atualmente anima o Size e Transparency do AnimationFrame. Ajuste estas propriedades conforme a estrutura do seu Frame.
- Se
AnimationFrame não possui uma propriedade Transparency, você pode animar a visibilidade de seus filhos ou usar outras propriedades que façam sentido no contexto do seu UI.
Considerações Finais
- Teste as Animações: Após implementar as mudanças, teste as animações para garantir que elas funcionem conforme o esperado.
- Propriedades dos Objetos: Certifique-se de que os objetos que você está animando possuam as propriedades que estão sendo alteradas (como
Transparency). Caso contrário, ajuste o script para alterar propriedades existentes ou adicione novas regras de animação conforme necessário.
- Organização do Código: Mantenha seu código organizado e bem comentado para facilitar futuras manutenções e alterações.
Espero que isso atenda às suas necessidades! Se precisar de mais assistência ou ajustes, sinta-se à vontade para perguntar.