2026-05-11 08:39:33 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Kill.Bluetooth;
|
|
|
|
|
|
using Kill.Bluetooth.Protocol;
|
|
|
|
|
|
using Kill.Managers;
|
|
|
|
|
|
using Kill.UI.Components;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Kill.UI.Pages
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 定时任务编辑页面
|
|
|
|
|
|
/// 用于新增和编辑单个定时任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ScheduleEditPage : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 0:模式 1:开始时间 2:结束时间 3:重复
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Button[] buttons;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 0:模式 1:开始时间 2:结束时间 3:重复
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Text[] texts;
|
|
|
|
|
|
|
|
|
|
|
|
// 各选择组件的预设(用于Instantiate)
|
|
|
|
|
|
public MutiSelectPage modeSelectPagePrefab;
|
|
|
|
|
|
public TimeSelection timeSelectionPrefab;
|
|
|
|
|
|
public RepeatSelection repeatSelectionPrefab;
|
|
|
|
|
|
|
|
|
|
|
|
// 实例化的组件(运行时创建)
|
|
|
|
|
|
private MutiSelectPage _modeSelectPageInstance;
|
|
|
|
|
|
private TimeSelection _startTimeSelectionInstance;
|
|
|
|
|
|
private TimeSelection _endTimeSelectionInstance;
|
|
|
|
|
|
private RepeatSelection _repeatSelectionInstance;
|
|
|
|
|
|
|
|
|
|
|
|
// 组件父节点(实例化时作为父物体)
|
|
|
|
|
|
public Transform componentParent;
|
|
|
|
|
|
|
|
|
|
|
|
public Button saveButton;
|
|
|
|
|
|
public Button backButton;
|
|
|
|
|
|
public Button deleteButton;
|
|
|
|
|
|
public WindowTipCtrl deleteTip;
|
|
|
|
|
|
// 当前编辑的任务索引,-1表示新增
|
|
|
|
|
|
private int _editTaskIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
// 当前任务数据
|
|
|
|
|
|
private ScheduleTask _currentTask;
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑完成回调
|
|
|
|
|
|
private Action<ScheduleTask, int> _onSaveCallback;
|
|
|
|
|
|
|
|
|
|
|
|
// 删除回调
|
|
|
|
|
|
private Action<int> _onDeleteCallback;
|
|
|
|
|
|
|
|
|
|
|
|
// 模式选项文本
|
|
|
|
|
|
private List<string> _modeStrs = new List<string>();
|
|
|
|
|
|
private List<string> _modeKeys = new List<string> { "100094", "100095", "100096" };
|
|
|
|
|
|
|
|
|
|
|
|
// 临时存储的选择值
|
|
|
|
|
|
private ScheduleTaskMode _selectedMode;
|
|
|
|
|
|
private byte _startHour;
|
|
|
|
|
|
private byte _startMinute;
|
|
|
|
|
|
private byte _endHour;
|
|
|
|
|
|
private byte _endMinute;
|
|
|
|
|
|
private byte _repeat;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化编辑页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="taskIndex">任务索引,-1表示新增</param>
|
|
|
|
|
|
/// <param name="task">任务数据</param>
|
|
|
|
|
|
/// <param name="onSave">保存回调</param>
|
|
|
|
|
|
/// <param name="onDelete">删除回调</param>
|
|
|
|
|
|
public void Init(int taskIndex, ScheduleTask task, Action<ScheduleTask, int> onSave = null, Action<int> onDelete = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_editTaskIndex = taskIndex;
|
|
|
|
|
|
_onSaveCallback = onSave;
|
|
|
|
|
|
_onDeleteCallback = onDelete;
|
|
|
|
|
|
|
|
|
|
|
|
// 加载多语言
|
|
|
|
|
|
LoadLocalizedStrings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置默认值或现有值
|
|
|
|
|
|
if (taskIndex < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 新增模式:设置默认值
|
|
|
|
|
|
_currentTask = new ScheduleTask
|
|
|
|
|
|
{
|
|
|
|
|
|
TaskId = 0,
|
|
|
|
|
|
Enabled = true,
|
|
|
|
|
|
StartHour = 8,
|
|
|
|
|
|
StartMinute = 0,
|
|
|
|
|
|
EndHour = 12,
|
|
|
|
|
|
EndMinute = 0,
|
|
|
|
|
|
Mode = ScheduleTaskMode.Scan,
|
|
|
|
|
|
Repeat = 0
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 编辑模式:使用传入的任务数据
|
|
|
|
|
|
_currentTask = task;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化临时值
|
|
|
|
|
|
_selectedMode = _currentTask.Mode;
|
|
|
|
|
|
_startHour = _currentTask.StartHour;
|
|
|
|
|
|
_startMinute = _currentTask.StartMinute;
|
|
|
|
|
|
_endHour = _currentTask.EndHour;
|
|
|
|
|
|
_endMinute = _currentTask.EndMinute;
|
|
|
|
|
|
_repeat = _currentTask.Repeat;
|
|
|
|
|
|
|
|
|
|
|
|
// 更新UI显示
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置删除按钮显示状态
|
|
|
|
|
|
if (deleteButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteButton.gameObject.SetActive(taskIndex >= 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 绑定按钮事件
|
|
|
|
|
|
BindButtonEvents();
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[ScheduleEditPage] 初始化 - {(taskIndex < 0 ? "新增" : "编辑")}任务");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载多语言字符串
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void LoadLocalizedStrings()
|
|
|
|
|
|
{
|
|
|
|
|
|
_modeStrs.Clear();
|
|
|
|
|
|
foreach (var key in _modeKeys)
|
|
|
|
|
|
{
|
|
|
|
|
|
_modeStrs.Add(LanguageManager.Instance?.GetLanguage(key) ?? key);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新UI显示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdateUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 更新模式文本
|
|
|
|
|
|
if (texts.Length > 0 && texts[0] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int modeIndex = (int)_selectedMode;
|
|
|
|
|
|
texts[0].text = modeIndex >= 0 && modeIndex < _modeStrs.Count ? _modeStrs[modeIndex] : _selectedMode.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新开始时间文本
|
|
|
|
|
|
if (texts.Length > 1 && texts[1] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
texts[1].text = $"{_startHour:D2}:{_startMinute:D2}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新结束时间文本
|
|
|
|
|
|
if (texts.Length > 2 && texts[2] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
texts[2].text = $"{_endHour:D2}:{_endMinute:D2}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新重复文本
|
|
|
|
|
|
if (texts.Length > 3 && texts[3] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
texts[3].text = GetRepeatDisplayText(_repeat);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取重复显示文本
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string GetRepeatDisplayText(byte repeat)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (repeat == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否7天都重复
|
|
|
|
|
|
byte allDays = ScheduleTask.REPEAT_SUNDAY | ScheduleTask.REPEAT_MONDAY | ScheduleTask.REPEAT_TUESDAY |
|
|
|
|
|
|
ScheduleTask.REPEAT_WEDNESDAY | ScheduleTask.REPEAT_THURSDAY | ScheduleTask.REPEAT_FRIDAY |
|
|
|
|
|
|
ScheduleTask.REPEAT_SATURDAY;
|
|
|
|
|
|
if (repeat == allDays)
|
|
|
|
|
|
{
|
|
|
|
|
|
return LanguageManager.Instance?.GetLanguage("100138") ?? "Everyday";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取星期文本
|
|
|
|
|
|
List<string> weekStr = new List<string>();
|
|
|
|
|
|
List<string> weekStrKeys = new List<string> { "100130", "100124", "100125", "100126", "100127", "100128", "100129" };
|
|
|
|
|
|
foreach (var key in weekStrKeys)
|
|
|
|
|
|
{
|
|
|
|
|
|
weekStr.Add(LanguageManager.Instance?.GetLanguage(key) ?? key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var days = new List<string>();
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_SUNDAY) != 0) days.Add(weekStr[0]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_MONDAY) != 0) days.Add(weekStr[1]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_TUESDAY) != 0) days.Add(weekStr[2]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_WEDNESDAY) != 0) days.Add(weekStr[3]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_THURSDAY) != 0) days.Add(weekStr[4]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_FRIDAY) != 0) days.Add(weekStr[5]);
|
|
|
|
|
|
if ((repeat & ScheduleTask.REPEAT_SATURDAY) != 0) days.Add(weekStr[6]);
|
|
|
|
|
|
|
|
|
|
|
|
return string.Join(", ", days);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 绑定按钮事件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BindButtonEvents()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 模式选择按钮
|
|
|
|
|
|
if (buttons.Length > 0 && buttons[0] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttons[0].onClick.RemoveAllListeners();
|
|
|
|
|
|
buttons[0].onClick.AddListener(OnModeButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 开始时间按钮
|
|
|
|
|
|
if (buttons.Length > 1 && buttons[1] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttons[1].onClick.RemoveAllListeners();
|
|
|
|
|
|
buttons[1].onClick.AddListener(OnStartTimeButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 结束时间按钮
|
|
|
|
|
|
if (buttons.Length > 2 && buttons[2] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttons[2].onClick.RemoveAllListeners();
|
|
|
|
|
|
buttons[2].onClick.AddListener(OnEndTimeButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 重复按钮
|
|
|
|
|
|
if (buttons.Length > 3 && buttons[3] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttons[3].onClick.RemoveAllListeners();
|
|
|
|
|
|
buttons[3].onClick.AddListener(OnRepeatButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存按钮
|
|
|
|
|
|
if (saveButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
saveButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
saveButton.onClick.AddListener(OnSaveButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 返回按钮
|
|
|
|
|
|
if (backButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
backButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
backButton.onClick.AddListener(OnBackButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除按钮
|
|
|
|
|
|
if (deleteButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
deleteButton.onClick.AddListener(OnDeleteButtonClick);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或创建模式选择页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private MutiSelectPage GetOrCreateModeSelectPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_modeSelectPageInstance == null && modeSelectPagePrefab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Transform parent = componentParent != null ? componentParent : transform;
|
|
|
|
|
|
_modeSelectPageInstance = Instantiate(modeSelectPagePrefab, parent);
|
|
|
|
|
|
_modeSelectPageInstance.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return _modeSelectPageInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 模式选择按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnModeButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
var page = GetOrCreateModeSelectPage();
|
|
|
|
|
|
if (page != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
page.gameObject.SetActive(true);
|
|
|
|
|
|
page.Init((int)_selectedMode, OnModeSelected);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 模式选择回调
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnModeSelected(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
_selectedMode = (ScheduleTaskMode)index;
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或创建开始时间选择页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private TimeSelection GetOrCreateStartTimeSelection()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_startTimeSelectionInstance == null && timeSelectionPrefab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Transform parent = componentParent != null ? componentParent : transform;
|
|
|
|
|
|
_startTimeSelectionInstance = Instantiate(timeSelectionPrefab, parent);
|
|
|
|
|
|
_startTimeSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return _startTimeSelectionInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 开始时间按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnStartTimeButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
var page = GetOrCreateStartTimeSelection();
|
|
|
|
|
|
if (page != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
page.gameObject.SetActive(true);
|
|
|
|
|
|
page.Init(_startHour, _startMinute, OnStartTimeSelected);
|
2026-05-18 08:42:33 +08:00
|
|
|
|
page.title.text=LanguageManager.Instance.GetLanguage("100142");
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 开始时间选择回调
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnStartTimeSelected(int hour, int minute)
|
|
|
|
|
|
{
|
|
|
|
|
|
_startHour = (byte)hour;
|
|
|
|
|
|
_startMinute = (byte)minute;
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或创建结束时间选择页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private TimeSelection GetOrCreateEndTimeSelection()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_endTimeSelectionInstance == null && timeSelectionPrefab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Transform parent = componentParent != null ? componentParent : transform;
|
|
|
|
|
|
_endTimeSelectionInstance = Instantiate(timeSelectionPrefab, parent);
|
|
|
|
|
|
_endTimeSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return _endTimeSelectionInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结束时间按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnEndTimeButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
var page = GetOrCreateEndTimeSelection();
|
|
|
|
|
|
if (page != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
page.gameObject.SetActive(true);
|
|
|
|
|
|
page.Init(_endHour, _endMinute, OnEndTimeSelected);
|
2026-05-18 08:42:33 +08:00
|
|
|
|
page.title.text=LanguageManager.Instance.GetLanguage("100143");
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结束时间选择回调
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnEndTimeSelected(int hour, int minute)
|
|
|
|
|
|
{
|
|
|
|
|
|
_endHour = (byte)hour;
|
|
|
|
|
|
_endMinute = (byte)minute;
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或创建重复选择页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private RepeatSelection GetOrCreateRepeatSelection()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_repeatSelectionInstance == null && repeatSelectionPrefab != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Transform parent = componentParent != null ? componentParent : transform;
|
|
|
|
|
|
_repeatSelectionInstance = Instantiate(repeatSelectionPrefab, parent);
|
|
|
|
|
|
_repeatSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return _repeatSelectionInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 重复按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnRepeatButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
var page = GetOrCreateRepeatSelection();
|
|
|
|
|
|
if (page != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 将repeat byte转换为List<int>
|
|
|
|
|
|
List<int> selectedDays = new List<int>();
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_SUNDAY) != 0) selectedDays.Add(0);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_MONDAY) != 0) selectedDays.Add(1);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_TUESDAY) != 0) selectedDays.Add(2);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_WEDNESDAY) != 0) selectedDays.Add(3);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_THURSDAY) != 0) selectedDays.Add(4);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_FRIDAY) != 0) selectedDays.Add(5);
|
|
|
|
|
|
if ((_repeat & ScheduleTask.REPEAT_SATURDAY) != 0) selectedDays.Add(6);
|
|
|
|
|
|
|
|
|
|
|
|
page.gameObject.SetActive(true);
|
|
|
|
|
|
page.Init(selectedDays, OnRepeatSelected);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 重复选择回调
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnRepeatSelected(List<int> days, string displayText)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 将List<int>转换为repeat byte
|
|
|
|
|
|
_repeat = 0;
|
|
|
|
|
|
foreach (var day in days)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (day)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0: _repeat |= ScheduleTask.REPEAT_SUNDAY; break;
|
|
|
|
|
|
case 1: _repeat |= ScheduleTask.REPEAT_MONDAY; break;
|
|
|
|
|
|
case 2: _repeat |= ScheduleTask.REPEAT_TUESDAY; break;
|
|
|
|
|
|
case 3: _repeat |= ScheduleTask.REPEAT_WEDNESDAY; break;
|
|
|
|
|
|
case 4: _repeat |= ScheduleTask.REPEAT_THURSDAY; break;
|
|
|
|
|
|
case 5: _repeat |= ScheduleTask.REPEAT_FRIDAY; break;
|
|
|
|
|
|
case 6: _repeat |= ScheduleTask.REPEAT_SATURDAY; break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
UpdateUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnSaveButtonClick()
|
|
|
|
|
|
{
|
2026-06-08 08:55:10 +08:00
|
|
|
|
// // 验证数据
|
|
|
|
|
|
// if (!ValidateInput())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
2026-05-11 08:39:33 +08:00
|
|
|
|
|
|
|
|
|
|
// 构建任务数据
|
|
|
|
|
|
var task = new ScheduleTask
|
|
|
|
|
|
{
|
|
|
|
|
|
TaskId = (byte)(_editTaskIndex >= 0 ? _editTaskIndex : 0),
|
|
|
|
|
|
Enabled = _currentTask.Enabled,
|
|
|
|
|
|
StartHour = _startHour,
|
|
|
|
|
|
StartMinute = _startMinute,
|
|
|
|
|
|
EndHour = _endHour,
|
|
|
|
|
|
EndMinute = _endMinute,
|
|
|
|
|
|
Mode = _selectedMode,
|
|
|
|
|
|
Repeat = _repeat
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[ScheduleEditPage] 保存任务 - 模式:{_selectedMode}, 时间:{_startHour:D2}:{_startMinute:D2}-{_endHour:D2}:{_endMinute:D2}, 重复:{_repeat}");
|
|
|
|
|
|
|
|
|
|
|
|
_onSaveCallback?.Invoke(task, _editTaskIndex);
|
|
|
|
|
|
ClosePage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 返回按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnBackButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("[ScheduleEditPage] 返回");
|
|
|
|
|
|
ClosePage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除按钮点击
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnDeleteButtonClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_editTaskIndex < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[ScheduleEditPage] 新增模式不能删除");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[ScheduleEditPage] 点击删除任务 {_editTaskIndex},弹出确认提示");
|
|
|
|
|
|
|
|
|
|
|
|
// 显示删除确认提示
|
|
|
|
|
|
if (deleteTip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteTip.gameObject.SetActive(true);
|
|
|
|
|
|
deleteTip.Init(OnDeleteConfirmed, OnDeleteCancelled);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果没有配置deleteTip,直接删除
|
|
|
|
|
|
Debug.LogWarning("[ScheduleEditPage] deleteTip 未配置,直接删除");
|
|
|
|
|
|
ExecuteDelete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 确认删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnDeleteConfirmed()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log($"[ScheduleEditPage] 确认删除任务 {_editTaskIndex}");
|
|
|
|
|
|
// 隐藏提示框
|
|
|
|
|
|
if (deleteTip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteTip.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
ExecuteDelete();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 取消删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnDeleteCancelled()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("[ScheduleEditPage] 取消删除");
|
|
|
|
|
|
// 隐藏提示框
|
|
|
|
|
|
if (deleteTip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
deleteTip.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行删除操作
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void ExecuteDelete()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_editTaskIndex >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_onDeleteCallback?.Invoke(_editTaskIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
ClosePage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 验证输入数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool ValidateInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 验证时间范围
|
|
|
|
|
|
if (_startHour > 23 || _endHour > 23)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[ScheduleEditPage] 小时必须在0-23之间");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_startMinute > 59 || _endMinute > 59)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[ScheduleEditPage] 分钟必须在0-59之间");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 验证开始时间小于结束时间
|
|
|
|
|
|
int startTime = _startHour * 60 + _startMinute;
|
|
|
|
|
|
int endTime = _endHour * 60 + _endMinute;
|
|
|
|
|
|
if (startTime >= endTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[ScheduleEditPage] 开始时间必须小于结束时间");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关闭页面
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void ClosePage()
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 页面显示时的初始化
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 页面隐藏时的清理
|
|
|
|
|
|
// 确保子页面也关闭
|
|
|
|
|
|
if (_modeSelectPageInstance != null) _modeSelectPageInstance.gameObject.SetActive(false);
|
|
|
|
|
|
if (_startTimeSelectionInstance != null) _startTimeSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
if (_endTimeSelectionInstance != null) _endTimeSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
if (_repeatSelectionInstance != null) _repeatSelectionInstance.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 销毁时清理实例化的对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_modeSelectPageInstance != null) Destroy(_modeSelectPageInstance.gameObject);
|
|
|
|
|
|
if (_startTimeSelectionInstance != null) Destroy(_startTimeSelectionInstance.gameObject);
|
|
|
|
|
|
if (_endTimeSelectionInstance != null) Destroy(_endTimeSelectionInstance.gameObject);
|
|
|
|
|
|
if (_repeatSelectionInstance != null) Destroy(_repeatSelectionInstance.gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|