133 lines
4.2 KiB
C#
133 lines
4.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.UI.Terminal
|
|
{
|
|
public class TerminalSettingPanel : MonoBehaviour, IUIPanel
|
|
{
|
|
[SerializeField] private TerminalPanelAnimator panelAnimator;
|
|
[SerializeField] private TerminalHeaderView header;
|
|
[SerializeField] private TerminalSliderView volumeSlider;
|
|
[SerializeField] private TerminalSliderView textSpeedSlider;
|
|
[SerializeField] private TerminalOptionItemView windowModeOption;
|
|
[SerializeField] private TerminalOptionItemView languageOption;
|
|
[SerializeField] private Button continueButton;
|
|
[SerializeField] private Button backToMainButton;
|
|
[SerializeField] private Button quitButton;
|
|
|
|
public bool IsOpen => gameObject.activeSelf;
|
|
public bool IsCloseable => true;
|
|
|
|
private static readonly UIFormOption[] WindowModeOptions =
|
|
{
|
|
new UIFormOption { prop = "FullScreen", label = "全屏" },
|
|
new UIFormOption { prop = "Windowed", label = "窗口" },
|
|
new UIFormOption { prop = "MaximizedWindow", label = "无边框" },
|
|
};
|
|
|
|
private static readonly UIFormOption[] LanguageOptions =
|
|
{
|
|
new UIFormOption { prop = "zh-Hans", label = "中文" },
|
|
new UIFormOption { prop = "en", label = "English" },
|
|
new UIFormOption { prop = "ja-JP", label = "日本語" },
|
|
};
|
|
|
|
private void Awake()
|
|
{
|
|
continueButton?.onClick.AddListener(BackToGame);
|
|
backToMainButton?.onClick.AddListener(BackToMain);
|
|
quitButton?.onClick.AddListener(QuitApp);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
continueButton?.onClick.RemoveListener(BackToGame);
|
|
backToMainButton?.onClick.RemoveListener(BackToMain);
|
|
quitButton?.onClick.RemoveListener(QuitApp);
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
GameManager.Instance.PauseGame();
|
|
header?.SetText("<设置>", "MUSIC 50/100 - AUDIO INPUT 001");
|
|
InitControls();
|
|
RefreshControls();
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Show();
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Hide();
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
GameManager.Instance.ContinueGame();
|
|
}
|
|
|
|
private void InitControls()
|
|
{
|
|
volumeSlider?.Init("Volume", "音量.....", 0f, 1f, OnSettingChanged);
|
|
textSpeedSlider?.Init("TextSpeed", "文字速度", 0.5f, 8f, OnSettingChanged);
|
|
windowModeOption?.Init("WindowMode", "屏幕模式", WindowModeOptions, OnSettingChanged);
|
|
languageOption?.Init("Language", "语言.....", LanguageOptions, OnSettingChanged);
|
|
}
|
|
|
|
private void RefreshControls()
|
|
{
|
|
var settings = SettingLoader.Instance.ReadAll();
|
|
if (settings.TryGetValue("Volume", out var volume))
|
|
{
|
|
volumeSlider?.SetValue(volume);
|
|
}
|
|
|
|
if (settings.TryGetValue("TextSpeed", out var textSpeed))
|
|
{
|
|
textSpeedSlider?.SetValue(textSpeed);
|
|
}
|
|
|
|
if (settings.TryGetValue("WindowMode", out var windowMode))
|
|
{
|
|
windowModeOption?.SetValue(windowMode);
|
|
}
|
|
|
|
if (settings.TryGetValue("Language", out var language))
|
|
{
|
|
languageOption?.SetValue(language);
|
|
}
|
|
}
|
|
|
|
private static void OnSettingChanged(string propName, string value)
|
|
{
|
|
SettingLoader.Instance.Write(propName, value);
|
|
}
|
|
|
|
private static void BackToGame()
|
|
{
|
|
UIManager.Instance.HidePreferredSettingPanel();
|
|
}
|
|
|
|
private static void BackToMain()
|
|
{
|
|
UIManager.Instance.HidePreferredSettingPanel();
|
|
GameManager.Instance.QuitGame();
|
|
}
|
|
|
|
private static void QuitApp()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|
|
}
|