103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Kill.Managers;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
namespace Kill.UI.Components
|
||
|
|
{
|
||
|
|
public class RepeatSelection : MonoBehaviour
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 0周日 1周一 2周二 3周三 4周四 5周五 6周六
|
||
|
|
/// </summary>
|
||
|
|
public Button[] repeatButtons;
|
||
|
|
/// <summary>
|
||
|
|
/// 0未选中 1已选中
|
||
|
|
/// </summary>
|
||
|
|
public Sprite[] repeatSprites;
|
||
|
|
public List<int> selectedDays;
|
||
|
|
List<string> weekStr = new List<string>();
|
||
|
|
List<string> weekStrKeys = new List<string> { "100130", "100124", "100125", "100126", "100127", "100128", "100129" };
|
||
|
|
List<string> shortWeekStr = new List<string>();
|
||
|
|
List<string> shortWeekStrKeys = new List<string> { "100137", "100131", "100132", "100133", "100134", "100135", "100136" };
|
||
|
|
string dailyKey = "100138";
|
||
|
|
string dailyStr = "";
|
||
|
|
public Button confirmButton;
|
||
|
|
public Button cancelButton;
|
||
|
|
public Text repeatText;
|
||
|
|
Action<List<int>, string> OnConfirm;
|
||
|
|
private void Start()
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
// #if UNITY_EDITOR
|
||
|
|
// Init(new List<int>{1,2},null);
|
||
|
|
// #endif
|
||
|
|
}
|
||
|
|
public void Init(List<int> days, Action<List<int>, string> onConfirm)
|
||
|
|
{
|
||
|
|
foreach (var item in weekStrKeys)
|
||
|
|
{
|
||
|
|
string str = LanguageManager.Instance.GetLanguage(item);
|
||
|
|
weekStr.Add(str);
|
||
|
|
}
|
||
|
|
foreach (var item in shortWeekStrKeys)
|
||
|
|
{
|
||
|
|
string str = LanguageManager.Instance.GetLanguage(item);
|
||
|
|
shortWeekStr.Add(str);
|
||
|
|
}
|
||
|
|
dailyStr = LanguageManager.Instance.GetLanguage(dailyKey);
|
||
|
|
selectedDays.Clear();
|
||
|
|
selectedDays = days;
|
||
|
|
for (int i = 0; i < repeatButtons.Length; i++)
|
||
|
|
{
|
||
|
|
int index = i;
|
||
|
|
repeatButtons[i].onClick.RemoveAllListeners();
|
||
|
|
repeatButtons[i].onClick.AddListener(() => OnButtonClick(index));
|
||
|
|
repeatButtons[i].GetComponent<Image>().sprite = repeatSprites[selectedDays.Contains(index) ? 1 : 0];
|
||
|
|
repeatButtons[i].GetComponentInChildren<Text>().text = shortWeekStr[index];
|
||
|
|
}
|
||
|
|
OnConfirm = onConfirm;
|
||
|
|
confirmButton.onClick.RemoveAllListeners();
|
||
|
|
cancelButton.onClick.RemoveAllListeners();
|
||
|
|
confirmButton.onClick.AddListener(() => { OnConfirm?.Invoke(selectedDays, repeatText.text); Destroy(gameObject); });
|
||
|
|
cancelButton.onClick.AddListener(() => Destroy(gameObject));
|
||
|
|
UpdateText();
|
||
|
|
}
|
||
|
|
public void OnButtonClick(int index)
|
||
|
|
{
|
||
|
|
if (selectedDays.Contains(index))
|
||
|
|
{
|
||
|
|
selectedDays.Remove(index);
|
||
|
|
repeatButtons[index].GetComponent<Image>().sprite = repeatSprites[0];
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
selectedDays.Add(index);
|
||
|
|
repeatButtons[index].GetComponent<Image>().sprite = repeatSprites[1];
|
||
|
|
}
|
||
|
|
selectedDays.Sort();
|
||
|
|
|
||
|
|
UpdateText();
|
||
|
|
}
|
||
|
|
public void UpdateText()
|
||
|
|
{
|
||
|
|
if (selectedDays.Count == 7)
|
||
|
|
{
|
||
|
|
repeatText.text = dailyStr;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
repeatText.text = "";
|
||
|
|
foreach (var item in selectedDays)
|
||
|
|
{
|
||
|
|
repeatText.text += weekStr[item] + ",";
|
||
|
|
}
|
||
|
|
repeatText.text = repeatText.text.TrimEnd(',');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|