2021-03-13 03:23:58 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-14 03:56:49 +00:00
|
|
|
using System.IO;
|
2021-03-13 03:23:58 +00:00
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
2021-03-14 03:56:49 +00:00
|
|
|
using UnityEngine.SceneManagement;
|
2021-03-13 03:23:58 +00:00
|
|
|
using UnityEngine.UI;
|
2021-03-14 03:56:49 +00:00
|
|
|
using static Unity.Mathematics.math;
|
2021-03-13 03:23:58 +00:00
|
|
|
|
|
|
|
|
public class MainMenu : MonoBehaviour
|
|
|
|
|
{
|
2021-03-14 03:56:49 +00:00
|
|
|
public bool InGame;
|
|
|
|
|
public Prototype PanelPrototype;
|
|
|
|
|
public float FadeTime = .5f;
|
|
|
|
|
public float FadeDistance = 512;
|
|
|
|
|
public float FadeAlphaExponent = 2;
|
|
|
|
|
public float FadePositionExponent = 2;
|
2021-03-13 03:23:58 +00:00
|
|
|
|
2021-03-14 03:56:49 +00:00
|
|
|
private (PropertiesPanel panel, CanvasGroup group) _currentMenu, _nextMenu;
|
|
|
|
|
private bool _fadeFromRight;
|
|
|
|
|
private float _fadeLerp;
|
|
|
|
|
private bool _fading;
|
|
|
|
|
private Vector3 _panelPosition;
|
|
|
|
|
private DirectoryInfo _saveDirectory;
|
2021-03-13 03:23:58 +00:00
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2021-03-14 03:56:49 +00:00
|
|
|
RegisterResolver.Register();
|
|
|
|
|
_panelPosition = PanelPrototype.transform.position;
|
|
|
|
|
|
|
|
|
|
var panel1 = PanelPrototype.Instantiate<PropertiesPanel>();
|
|
|
|
|
_currentMenu = (panel1, panel1.GetComponent<CanvasGroup>());
|
|
|
|
|
|
|
|
|
|
var panel2 = PanelPrototype.Instantiate<PropertiesPanel>();
|
|
|
|
|
_nextMenu = (panel2, panel2.GetComponent<CanvasGroup>());
|
|
|
|
|
|
|
|
|
|
_currentMenu.panel.gameObject.SetActive(false);
|
|
|
|
|
_saveDirectory = ActionGameManager.GameDataDirectory.CreateSubdirectory("Saves");
|
|
|
|
|
|
2021-03-13 03:23:58 +00:00
|
|
|
ShowMain();
|
2021-03-14 03:56:49 +00:00
|
|
|
Fade(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (_fading)
|
|
|
|
|
{
|
|
|
|
|
_fadeLerp += Time.deltaTime / FadeTime;
|
|
|
|
|
|
|
|
|
|
_currentMenu.panel.transform.position =
|
|
|
|
|
_panelPosition + (_fadeFromRight ? Vector3.left : Vector3.right) * (FadeDistance * pow(_fadeLerp, FadePositionExponent));
|
|
|
|
|
_nextMenu.panel.transform.position =
|
|
|
|
|
_panelPosition + (_fadeFromRight ? Vector3.right : Vector3.left) * (FadeDistance * pow(1-_fadeLerp, FadePositionExponent));
|
|
|
|
|
_currentMenu.group.alpha = pow(1 - _fadeLerp, FadeAlphaExponent);
|
|
|
|
|
_nextMenu.group.alpha = pow(_fadeLerp, FadeAlphaExponent);
|
|
|
|
|
|
|
|
|
|
if (_fadeLerp > 1)
|
|
|
|
|
{
|
|
|
|
|
_fading = false;
|
|
|
|
|
_currentMenu.panel.gameObject.SetActive(false);
|
|
|
|
|
var temp = _currentMenu;
|
|
|
|
|
_currentMenu = _nextMenu;
|
|
|
|
|
_nextMenu = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string TitleSubtitle(string title, string subtitle) => $"{title}\n<smallcaps><size=50%>{subtitle}";
|
|
|
|
|
|
|
|
|
|
private void Fade(bool fromRight)
|
|
|
|
|
{
|
|
|
|
|
_nextMenu.panel.gameObject.SetActive(true);
|
|
|
|
|
_nextMenu.group.alpha = 0;
|
|
|
|
|
_fading = true;
|
|
|
|
|
_fadeLerp = 0;
|
|
|
|
|
_fadeFromRight = fromRight;
|
2021-03-13 03:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowMain()
|
|
|
|
|
{
|
2021-03-14 03:56:49 +00:00
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = TitleSubtitle("aetheria", "terminus");
|
|
|
|
|
if (!InGame)
|
|
|
|
|
{
|
|
|
|
|
if(ActionGameManager.PlayerSettings.CurrentRun != null)
|
|
|
|
|
_nextMenu.panel.AddButton("Continue", () => SceneManager.LoadScene("ARPG"));
|
|
|
|
|
else
|
|
|
|
|
_nextMenu.panel.AddButton("Continue", null);
|
|
|
|
|
}
|
|
|
|
|
_nextMenu.panel.AddButton("New Game",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
// TODO: Initialize Run
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Settings",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowSettings();
|
|
|
|
|
Fade(true);
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Quit", Application.Quit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowSettings()
|
|
|
|
|
{
|
|
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = "settings";
|
|
|
|
|
_nextMenu.panel.AddButton("Gameplay",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowGameplaySettings();
|
|
|
|
|
Fade(true);
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Graphics",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowGraphicsSettings();
|
|
|
|
|
Fade(true);
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Input",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowInputSettings();
|
|
|
|
|
Fade(true);
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Audio",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowAudioSettings();
|
|
|
|
|
Fade(true);
|
|
|
|
|
});
|
|
|
|
|
_nextMenu.panel.AddButton("Back",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowMain();
|
|
|
|
|
Fade(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowGameplaySettings()
|
|
|
|
|
{
|
|
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = TitleSubtitle("gameplay", "settings");
|
|
|
|
|
_nextMenu.panel.AddField("Name",
|
|
|
|
|
() => ActionGameManager.PlayerSettings.Name,
|
|
|
|
|
s => ActionGameManager.PlayerSettings.Name = s);
|
|
|
|
|
_nextMenu.panel.AddButton("Back",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ActionGameManager.SavePlayerSettings();
|
|
|
|
|
ShowSettings();
|
|
|
|
|
Fade(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowGraphicsSettings()
|
|
|
|
|
{
|
|
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = TitleSubtitle("graphics", "settings");
|
|
|
|
|
_nextMenu.panel.AddButton("Back",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowSettings();
|
|
|
|
|
Fade(false);
|
|
|
|
|
});
|
2021-03-13 03:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-14 03:56:49 +00:00
|
|
|
private void ShowInputSettings()
|
2021-03-13 03:23:58 +00:00
|
|
|
{
|
2021-03-14 03:56:49 +00:00
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = TitleSubtitle("input", "settings");
|
|
|
|
|
_nextMenu.panel.AddButton("Back",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowSettings();
|
|
|
|
|
Fade(false);
|
|
|
|
|
});
|
2021-03-13 03:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-14 03:56:49 +00:00
|
|
|
private void ShowAudioSettings()
|
2021-03-13 03:23:58 +00:00
|
|
|
{
|
2021-03-14 03:56:49 +00:00
|
|
|
_nextMenu.panel.Clear();
|
|
|
|
|
_nextMenu.panel.Title.text = TitleSubtitle("audio", "settings");
|
|
|
|
|
_nextMenu.panel.AddButton("Back",
|
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
ShowSettings();
|
|
|
|
|
Fade(false);
|
|
|
|
|
});
|
2021-03-13 03:23:58 +00:00
|
|
|
}
|
|
|
|
|
}
|