192 lines
5.6 KiB
C#
192 lines
5.6 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using TMPro;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 静音设置面板
|
|||
|
|
/// 设置报警静音持续时间
|
|||
|
|
/// </summary>
|
|||
|
|
public class MuteSettingPanel : BasePanel
|
|||
|
|
{
|
|||
|
|
[Header("静音设置")]
|
|||
|
|
// public Slider MuteDurationSlider;
|
|||
|
|
public TextMeshProUGUI MuteDurationText;
|
|||
|
|
// public Toggle EnableMuteToggle;
|
|||
|
|
public TextMeshProUGUI MuteStatusText;
|
|||
|
|
|
|||
|
|
|
|||
|
|
[Header("控制按钮")]
|
|||
|
|
public Button OneMinutetButton;
|
|||
|
|
public Button TwoMinuteButton;
|
|||
|
|
public Button ThreeMinuteButton;
|
|||
|
|
public Button HomeButton;
|
|||
|
|
// public Button ConfirmButton;
|
|||
|
|
public Button BackButton;
|
|||
|
|
|
|||
|
|
private SettingsViewModel _vm;
|
|||
|
|
|
|||
|
|
public override void Init()
|
|||
|
|
{
|
|||
|
|
_vm = new SettingsViewModel();
|
|||
|
|
|
|||
|
|
InitializeUI();
|
|||
|
|
// UpdateMuteStatus();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void InitializeUI()
|
|||
|
|
{
|
|||
|
|
// 初始化静音时长滑块
|
|||
|
|
// if (MuteDurationSlider != null)
|
|||
|
|
// {
|
|||
|
|
// MuteDurationSlider.minValue = 1;
|
|||
|
|
// MuteDurationSlider.maxValue = 3;
|
|||
|
|
// MuteDurationSlider.wholeNumbers = true;
|
|||
|
|
// // MuteDurationSlider.value = _vm.MuteDurationMinutes;
|
|||
|
|
|
|||
|
|
// MuteDurationSlider.onValueChanged.AddListener(OnMuteDurationChanged);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// // 初始化静音开关
|
|||
|
|
// if (EnableMuteToggle != null)
|
|||
|
|
// {
|
|||
|
|
// // 检查DCSAlarmManager当前是否已静音
|
|||
|
|
// EnableMuteToggle.isOn = DCSAlarmManager.Instance != null && DCSAlarmManager.Instance.IsMuted;
|
|||
|
|
|
|||
|
|
// EnableMuteToggle.onValueChanged.AddListener(OnMuteToggleChanged);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// 初始化文本
|
|||
|
|
// UpdateMuteDurationText((int)MuteDurationSlider.value);
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 控制按钮
|
|||
|
|
if(OneMinutetButton != null)
|
|||
|
|
{
|
|||
|
|
OneMinutetButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
ConfirmDialog.Show("确认", "确定要设置静音1分钟吗?", () =>
|
|||
|
|
{
|
|||
|
|
MuteDurationChanged(1);
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if(TwoMinuteButton != null)
|
|||
|
|
{
|
|||
|
|
TwoMinuteButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
ConfirmDialog.Show("确认", "确定要设置静音2分钟吗?", () =>
|
|||
|
|
{
|
|||
|
|
MuteDurationChanged(2);
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if(ThreeMinuteButton != null)
|
|||
|
|
{
|
|||
|
|
ThreeMinuteButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
ConfirmDialog.Show("确认", "确定要设置静音3分钟吗?", () =>
|
|||
|
|
{
|
|||
|
|
MuteDurationChanged(3);
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if (HomeButton != null)
|
|||
|
|
{
|
|||
|
|
HomeButton.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
ConfirmDialog.Show("确认", "是否返回主界面?", () =>
|
|||
|
|
{
|
|||
|
|
ReturnToHome();
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (BackButton != null)
|
|||
|
|
{
|
|||
|
|
BackButton.onClick.AddListener(() =>
|
|||
|
|
ConfirmDialog.Show("确认", "是否返回设置界面?", () =>
|
|||
|
|
{
|
|||
|
|
ClosePanel();
|
|||
|
|
ClosePanel();
|
|||
|
|
})
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void MuteDurationChanged(int minutes)
|
|||
|
|
{
|
|||
|
|
// 保存静音时长设置
|
|||
|
|
_vm.MuteDurationMinutes = minutes;
|
|||
|
|
Debug.Log($"静音时长已设置为 {minutes} 分钟");
|
|||
|
|
UpdateMuteDurationText(minutes);
|
|||
|
|
|
|||
|
|
// 显示成功提示并关闭面板
|
|||
|
|
// ConfirmDialog.Show("设置成功", $"静音时长已设置为 {minutes} 分钟\n请在主界面点击\"报警静音\"按钮激活", () =>
|
|||
|
|
// {
|
|||
|
|
// ClosePanel();
|
|||
|
|
// });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void OnMuteDurationChanged(float value)
|
|||
|
|
{
|
|||
|
|
int minutes = (int)value;
|
|||
|
|
UpdateMuteDurationText(minutes);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// private void OnMuteToggleChanged(bool isMuted)
|
|||
|
|
// {
|
|||
|
|
// if (DCSAlarmManager.Instance != null)
|
|||
|
|
// {
|
|||
|
|
// if (isMuted)
|
|||
|
|
// {
|
|||
|
|
// // 立即应用静音,使用当前设置的时长
|
|||
|
|
// // int muteDuration = (int)MuteDurationSlider.value;
|
|||
|
|
// DCSAlarmManager.Instance.SetMute(true);
|
|||
|
|
// // Debug.Log($"报警已通过DCSAlarmManager静音 {muteDuration} 分钟");
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// // 取消静音
|
|||
|
|
// DCSAlarmManager.Instance.SetMute(false);
|
|||
|
|
// Debug.Log("报警静音已通过DCSAlarmManager取消");
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// UpdateMuteStatus();
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
private void UpdateMuteDurationText(int minutes)
|
|||
|
|
{
|
|||
|
|
if (MuteDurationText != null)
|
|||
|
|
{
|
|||
|
|
MuteDurationText.text = $"静音时长: {minutes} 分钟";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// private void UpdateMuteStatus()
|
|||
|
|
// {
|
|||
|
|
// if (MuteStatusText != null)
|
|||
|
|
// {
|
|||
|
|
// if (DCSAlarmManager.Instance != null && DCSAlarmManager.Instance.IsMuted)
|
|||
|
|
// {
|
|||
|
|
// MuteStatusText.text = "当前状态: 已静音";
|
|||
|
|
// MuteStatusText.color = Color.yellow;
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// MuteStatusText.text = "当前状态: 正常";
|
|||
|
|
// MuteStatusText.color = Color.white;
|
|||
|
|
// if (MuteDurationText != null)
|
|||
|
|
// {
|
|||
|
|
// MuteDurationText.text = "";
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|