147 lines
4.4 KiB
C#
147 lines
4.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream.UI.Terminal
|
|
{
|
|
public class TerminalSettingPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private TerminalPanelAnimator panelAnimator;
|
|
[SerializeField] private SliderItem volumeSlider;
|
|
[SerializeField] private SelectItem textSpeedOption;
|
|
[SerializeField] private SelectItem windowModeOption;
|
|
[SerializeField] private SelectItem languageOption;
|
|
[SerializeField] private Button continueButton;
|
|
[SerializeField] private Button backToMainButton;
|
|
[SerializeField] private Button quitButton;
|
|
|
|
public bool IsOpen => gameObject.activeSelf;
|
|
private TerminalPanel _owner;
|
|
|
|
private static readonly UIFormOption[] WindowModeOptions =
|
|
{
|
|
new UIFormOption { prop = "FullScreen", label = "setting_window_fullscreen" },
|
|
new UIFormOption { prop = "Windowed", label = "setting_window_windowed" },
|
|
};
|
|
|
|
private static readonly UIFormOption[] LanguageOptions =
|
|
{
|
|
new UIFormOption { prop = "zh-Hans", label = "中文" },
|
|
new UIFormOption { prop = "en", label = "English" },
|
|
new UIFormOption { prop = "ja-JP", label = "日本語" },
|
|
};
|
|
|
|
private static readonly UIFormOption[] TextSpeedOptions =
|
|
{
|
|
new UIFormOption { prop = "0.5", label = "setting_textSpeed_slow" },
|
|
new UIFormOption { prop = "1.0", label = "setting_textSpeed_default" },
|
|
new UIFormOption { prop = "3.0", label = "setting_textSpeed_fast" },
|
|
};
|
|
|
|
public void SetOwner(TerminalPanel owner)
|
|
{
|
|
_owner = owner;
|
|
}
|
|
|
|
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()
|
|
{
|
|
_owner?.SetHeader("<设置>", "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);
|
|
}
|
|
}
|
|
|
|
private void InitControls()
|
|
{
|
|
volumeSlider?.Init("Volume", "音量.....", 0f, 1f, OnSettingChanged);
|
|
textSpeedOption?.Init("TextSpeed", "文字速度", TextSpeedOptions, 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))
|
|
{
|
|
textSpeedOption?.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 void BackToGame()
|
|
{
|
|
if (_owner.Source == TerminalOpenSource.InGame)
|
|
{
|
|
_owner.Close();
|
|
}
|
|
else
|
|
{
|
|
_owner.Back();
|
|
}
|
|
}
|
|
|
|
private void BackToMain()
|
|
{
|
|
_owner.CloseToMainMenu();
|
|
}
|
|
|
|
private static void QuitApp()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|
|
}
|