Update
This commit is contained in:
@@ -1,63 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Collections.Generic;
|
||||
using PrimeTween;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace UI
|
||||
namespace Hallucinate.UI
|
||||
{
|
||||
public class SettingsController : MonoBehaviour
|
||||
public class SettingsController : BaseUIController
|
||||
{
|
||||
private VisualElement _contentGeneral;
|
||||
private VisualElement _contentGraphics;
|
||||
private VisualElement _contentAudio;
|
||||
private VisualElement _contentControls;
|
||||
private VisualElement _sidebar;
|
||||
private Label _tabTitle;
|
||||
private ScrollView _content;
|
||||
|
||||
private Button _tabGeneral;
|
||||
private Button _tabGraphics;
|
||||
private Button _tabAudio;
|
||||
private Button _tabControls;
|
||||
|
||||
private void OnEnable()
|
||||
public override void Initialize(VisualElement uxmlRoot, UIManager manager)
|
||||
{
|
||||
var root = GetComponent<UIDocument>().rootVisualElement;
|
||||
base.Initialize(uxmlRoot, manager);
|
||||
|
||||
// Tabs
|
||||
_tabGeneral = root.Q<Button>("tab-general");
|
||||
_tabGraphics = root.Q<Button>("tab-graphics");
|
||||
_tabAudio = root.Q<Button>("tab-audio");
|
||||
_tabControls = root.Q<Button>("tab-controls");
|
||||
_sidebar = root.Q<VisualElement>("Sidebar");
|
||||
_tabTitle = root.Q<Label>("TabTitle");
|
||||
_content = root.Q<ScrollView>("SettingsContent");
|
||||
|
||||
// Content
|
||||
_contentGeneral = root.Q<VisualElement>("content-general");
|
||||
_contentGraphics = root.Q<VisualElement>("content-graphics");
|
||||
_contentAudio = root.Q<VisualElement>("content-audio");
|
||||
_contentControls = root.Q<VisualElement>("content-controls");
|
||||
|
||||
// Register Tab Events
|
||||
_tabGeneral?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentGeneral, _tabGeneral));
|
||||
_tabGraphics?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentGraphics, _tabGraphics));
|
||||
_tabAudio?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentAudio, _tabAudio));
|
||||
_tabControls?.RegisterCallback<ClickEvent>(evt => SwitchTab(_contentControls, _tabControls));
|
||||
|
||||
// Close
|
||||
root.Q<Button>("btn-close")?.RegisterCallback<ClickEvent>(evt => UIManager.Instance.ToggleSettings());
|
||||
root.Q<Button>("GeneralTab").clicked += () => SwitchTab("GENERAL");
|
||||
root.Q<Button>("VideoTab").clicked += () => SwitchTab("VIDEO");
|
||||
root.Q<Button>("SoundTab").clicked += () => SwitchTab("SOUND");
|
||||
root.Q<Button>("ControlTab").clicked += () => SwitchTab("CONTROL");
|
||||
root.Q<Button>("CloseSettingsBtn").clicked += () => uiManager.Pop();
|
||||
}
|
||||
|
||||
private void SwitchTab(VisualElement targetContent, Button targetTab)
|
||||
private void SwitchTab(string title)
|
||||
{
|
||||
// Hide all
|
||||
_contentGeneral.style.display = DisplayStyle.None;
|
||||
if(_contentGraphics != null) _contentGraphics.style.display = DisplayStyle.None;
|
||||
if(_contentAudio != null) _contentAudio.style.display = DisplayStyle.None;
|
||||
if(_contentControls != null) _contentControls.style.display = DisplayStyle.None;
|
||||
_tabTitle.text = title;
|
||||
// Clear and add specific settings content
|
||||
_content.Clear();
|
||||
_content.Add(new Label($"Settings for {title} coming soon..."));
|
||||
}
|
||||
|
||||
_tabGeneral.RemoveFromClassList("active-tab");
|
||||
_tabGraphics.RemoveFromClassList("active-tab");
|
||||
_tabAudio.RemoveFromClassList("active-tab");
|
||||
_tabControls.RemoveFromClassList("active-tab");
|
||||
public override async Task PlayTransitionIn()
|
||||
{
|
||||
Show();
|
||||
_sidebar.style.translate = new StyleTranslate(new Translate(Length.Percent(-100), 0));
|
||||
await Tween.Custom(-100f, 0f, duration: 0.4f, ease: Ease.OutQuad,
|
||||
onValueChange: val => _sidebar.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
|
||||
}
|
||||
|
||||
// Show target
|
||||
targetContent.style.display = DisplayStyle.Flex;
|
||||
targetTab.AddToClassList("active-tab");
|
||||
public override async Task PlayTransitionOut()
|
||||
{
|
||||
await Tween.Custom(0f, -100f, duration: 0.4f, ease: Ease.InQuad,
|
||||
onValueChange: val => _sidebar.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user