216 lines
6.9 KiB
C#
216 lines
6.9 KiB
C#
using System;
|
|
using AibisDream;
|
|
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.UI
|
|
{
|
|
/// <summary>
|
|
/// 终端 Setting Page(遗留类名 Panel)。可挂在主菜单或局内 Panel 壳下。
|
|
/// </summary>
|
|
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 TerminalButton continueButton;
|
|
[SerializeField] private TerminalButton backToMainButton;
|
|
[SerializeField] private TerminalButton quitButton;
|
|
|
|
public bool IsOpen => gameObject.activeSelf;
|
|
private ITerminalPanelHost _owner;
|
|
private RectTransform _continueButtonRect;
|
|
private Vector2 _continueButtonDefaultPosition;
|
|
private bool _hasContinueButtonDefaultPosition;
|
|
|
|
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 = "日本語" },
|
|
new UIFormOption { prop = "ru", label = "Русский" },
|
|
new UIFormOption { prop = "es", label = "Español" },
|
|
new UIFormOption { prop = "pt-BR", label = "Português (Brasil)" },
|
|
};
|
|
|
|
private static readonly UIFormOption[] TextSpeedOptions =
|
|
{
|
|
new UIFormOption { prop = TextSpeedSettings.SlowValue, label = "setting_textSpeed_slow" },
|
|
new UIFormOption { prop = TextSpeedSettings.DefaultValue, label = "setting_textSpeed_default" },
|
|
new UIFormOption { prop = TextSpeedSettings.FastValue, label = "setting_textSpeed_fast" },
|
|
};
|
|
|
|
public void SetOwner(ITerminalPanelHost owner)
|
|
{
|
|
_owner = owner;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
BindButton(continueButton, BackToGame);
|
|
BindButton(backToMainButton, BackToMain);
|
|
BindButton(quitButton, QuitApp);
|
|
|
|
if (continueButton != null)
|
|
{
|
|
_continueButtonRect = continueButton.transform as RectTransform;
|
|
if (_continueButtonRect != null)
|
|
{
|
|
_continueButtonDefaultPosition = _continueButtonRect.anchoredPosition;
|
|
_hasContinueButtonDefaultPosition = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
UnbindButton(continueButton, BackToGame);
|
|
UnbindButton(backToMainButton, BackToMain);
|
|
UnbindButton(quitButton, QuitApp);
|
|
}
|
|
|
|
private static void BindButton(TerminalButton terminalButton, UnityEngine.Events.UnityAction action)
|
|
{
|
|
terminalButton?.Button?.onClick.AddListener(action);
|
|
}
|
|
|
|
private static void UnbindButton(TerminalButton terminalButton, UnityEngine.Events.UnityAction action)
|
|
{
|
|
terminalButton?.Button?.onClick.RemoveListener(action);
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Show(prepare: PrepareContent);
|
|
}
|
|
else
|
|
{
|
|
PrepareContent();
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void Hide(Action onComplete = null)
|
|
{
|
|
if (panelAnimator != null)
|
|
{
|
|
panelAnimator.Hide(onComplete);
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(false);
|
|
onComplete?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void PrepareContent()
|
|
{
|
|
_owner?.SetHeader("terminal_header_setting", "REPAIR_STATION_07 - AUTH_VERIFIED");
|
|
InitControls();
|
|
RefreshControls();
|
|
RefreshFooterButtons();
|
|
}
|
|
|
|
private void InitControls()
|
|
{
|
|
volumeSlider?.Init("Volume", "setting_volume", 0f, 1f, OnSettingChanged);
|
|
textSpeedOption?.Init("TextSpeed", "setting_textSpeed", TextSpeedOptions, OnSettingChanged);
|
|
windowModeOption?.Init("WindowMode", "setting_window", WindowModeOptions, OnSettingChanged);
|
|
languageOption?.Init("Language", "setting_language", LanguageOptions, OnSettingChanged);
|
|
}
|
|
|
|
private void RefreshControls()
|
|
{
|
|
var settings = SettingLoader.Instance.ReadAll();
|
|
if (settings.TryGetValue("Volume", out var volume))
|
|
{
|
|
volumeSlider?.SetValue(volume);
|
|
}
|
|
|
|
textSpeedOption?.SetValue(TextSpeedSettings.CurrentCanonicalValue);
|
|
|
|
if (settings.TryGetValue("WindowMode", out var windowMode))
|
|
{
|
|
windowModeOption?.SetValue(windowMode);
|
|
}
|
|
|
|
if (settings.TryGetValue("Language", out var language))
|
|
{
|
|
languageOption?.SetValue(LocalizationKit.ResolveLanguage(language));
|
|
}
|
|
}
|
|
|
|
private static void OnSettingChanged(string propName, string value)
|
|
{
|
|
SettingLoader.Instance.Write(propName, value);
|
|
}
|
|
|
|
private void RefreshFooterButtons()
|
|
{
|
|
var inGame = _owner != null && _owner.IsInGameContext;
|
|
|
|
continueButton?.gameObject.SetActive(true);
|
|
backToMainButton?.gameObject.SetActive(inGame);
|
|
quitButton?.gameObject.SetActive(inGame);
|
|
|
|
ApplyContinueButtonLayout(inGame);
|
|
}
|
|
|
|
private void ApplyContinueButtonLayout(bool inGame)
|
|
{
|
|
if (!_hasContinueButtonDefaultPosition || _continueButtonRect == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_continueButtonRect.anchoredPosition = inGame
|
|
? _continueButtonDefaultPosition
|
|
: new Vector2(0f, _continueButtonDefaultPosition.y);
|
|
}
|
|
|
|
private void BackToGame()
|
|
{
|
|
if (_owner == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_owner.IsInGameContext)
|
|
{
|
|
_owner.Close();
|
|
}
|
|
else
|
|
{
|
|
_owner.Back();
|
|
}
|
|
}
|
|
|
|
private void BackToMain()
|
|
{
|
|
_owner?.CloseToMainMenu();
|
|
}
|
|
|
|
private static void QuitApp()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct UIFormOption
|
|
{
|
|
public string prop;
|
|
public string label;
|
|
}
|
|
}
|