270 lines
8.8 KiB
C#
270 lines
8.8 KiB
C#
|
|
using Assets.Scripts;
|
|||
|
|
using Assets.Scripts.UI.Control;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Events;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
public class RowerTaskPanel : PFUIPanel
|
|||
|
|
{
|
|||
|
|
public class RowerType
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 1 里程 2 时间
|
|||
|
|
/// </summary>
|
|||
|
|
public int type { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 里程:m 时间:s
|
|||
|
|
/// </summary>
|
|||
|
|
public float value { get; set; }
|
|||
|
|
}
|
|||
|
|
Transform selector, distance, time;
|
|||
|
|
RowerType rowerType;
|
|||
|
|
|
|||
|
|
public Action<RowerType> callBack { get; set; }
|
|||
|
|
|
|||
|
|
protected override void Awake()
|
|||
|
|
{
|
|||
|
|
distance = transform.Find("Main/Distance");
|
|||
|
|
time = transform.Find("Main/Time");
|
|||
|
|
rowerType = new RowerType();
|
|||
|
|
UIManager.AddEvent(transform.Find("Main/BtnGo").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|||
|
|
{
|
|||
|
|
Go();
|
|||
|
|
});
|
|||
|
|
UIManager.AddEvent(transform.Find("Main/BtnCancel").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|||
|
|
{
|
|||
|
|
Close();
|
|||
|
|
});
|
|||
|
|
//var bg = transform.Find("Main/Time/Inputbg").gameObject;
|
|||
|
|
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.PointerEnter, b =>
|
|||
|
|
// {
|
|||
|
|
// bg.GetComponent<Outline>().enabled = true;
|
|||
|
|
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#353543");
|
|||
|
|
// });
|
|||
|
|
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Select, b =>
|
|||
|
|
//{
|
|||
|
|
// bg.GetComponent<Outline>().enabled = true;
|
|||
|
|
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
|
|||
|
|
//});
|
|||
|
|
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Deselect, b =>
|
|||
|
|
//{
|
|||
|
|
// bg.GetComponent<Outline>().enabled = false;
|
|||
|
|
//});
|
|||
|
|
formList = new List<object>
|
|||
|
|
{
|
|||
|
|
distance.Find("Btn500").GetComponent<Button>(),
|
|||
|
|
distance.Find("Btn2000").GetComponent<Button>(),
|
|||
|
|
distance.Find("Btn5000").GetComponent<Button>(),
|
|||
|
|
distance.Find("Btn10000").GetComponent<Button>(),
|
|||
|
|
distance.Find("Customize").GetComponent<PFUIInputField>(),
|
|||
|
|
time.Find("Btn30").GetComponent<Button>(),
|
|||
|
|
time.Find("CustomizeMin").GetComponent<PFUIInputField>(),
|
|||
|
|
time.Find("CustomizeS").GetComponent<PFUIInputField>(),
|
|||
|
|
};
|
|||
|
|
InitDistance();
|
|||
|
|
}
|
|||
|
|
public override void Show()
|
|||
|
|
{
|
|||
|
|
base.Show();
|
|||
|
|
InitAll();
|
|||
|
|
}
|
|||
|
|
private void Go()
|
|||
|
|
{
|
|||
|
|
if (rowerType.type == 0 || rowerType.value == 0)
|
|||
|
|
{
|
|||
|
|
Utils.showToast(null, "请选择课程");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (callBack != null)
|
|||
|
|
{
|
|||
|
|
callBack.Invoke(rowerType);
|
|||
|
|
}
|
|||
|
|
Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
List<object> formList = null;
|
|||
|
|
private void InitDistance()
|
|||
|
|
{
|
|||
|
|
Func<Transform, float, float, float> calc = (t, a, b) => t.parent.name == "Distance" ? a : a * 60 + b;
|
|||
|
|
AddListener(formList, (t, v) =>
|
|||
|
|
{
|
|||
|
|
if (t.parent.name == "Distance")
|
|||
|
|
{
|
|||
|
|
rowerType.type = 1;
|
|||
|
|
if (float.TryParse(v, out float f))
|
|||
|
|
{
|
|||
|
|
rowerType.value = f;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
rowerType.value = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
rowerType.type = 2;
|
|||
|
|
rowerType.value = 0;
|
|||
|
|
var min = time.Find("CustomizeMin").GetComponent<InputField>().text;
|
|||
|
|
var s = time.Find("CustomizeS").GetComponent<InputField>().text;
|
|||
|
|
if (float.TryParse(min, out float a))
|
|||
|
|
{
|
|||
|
|
rowerType.value += 60 * a;
|
|||
|
|
}
|
|||
|
|
if (float.TryParse(s, out float b))
|
|||
|
|
{
|
|||
|
|
if (b < 0 || b > 59)
|
|||
|
|
{
|
|||
|
|
Utils.showToast(null, "Please enter an integer between 0-59.");
|
|||
|
|
time.Find("CustomizeS").GetComponent<InputField>().text = "";
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
rowerType.value += b;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}, calc);
|
|||
|
|
}
|
|||
|
|
private void AddListener(IEnumerable<object> list, UnityAction<Transform,string> inputCustomAction, Func<Transform, float,float,float> calcButton = null)
|
|||
|
|
{
|
|||
|
|
var btns = list.Where(x => x is Button).Select(x => x as Button);
|
|||
|
|
foreach (var item in list)
|
|||
|
|
{
|
|||
|
|
if (item is Button)
|
|||
|
|
{
|
|||
|
|
var btn = item as Button;
|
|||
|
|
btn.onClick.RemoveAllListeners();
|
|||
|
|
btn.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
rowerType.type = btn.transform.parent.name == "Distance" ? 1 : 2;
|
|||
|
|
if (calcButton == null)
|
|||
|
|
{
|
|||
|
|
rowerType.value = float.Parse(btn.name.Replace("Btn", ""));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
rowerType.value = calcButton.Invoke(btn.transform ,float.Parse(btn.name.Replace("Btn", "")), 0);
|
|||
|
|
}
|
|||
|
|
ClickDistanceBtn(btn, btns);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else if (item is PFUIInputField)
|
|||
|
|
{
|
|||
|
|
var input = item as PFUIInputField;
|
|||
|
|
input.CustomSelect = () =>
|
|||
|
|
{
|
|||
|
|
ClickDistanceBtn(null, btns);
|
|||
|
|
rowerType.type = input.transform.parent.name == "Distance" ? 1 : 2;
|
|||
|
|
SetTextColor(input.gameObject, true);
|
|||
|
|
SetBgColor(input,2);
|
|||
|
|
};
|
|||
|
|
input.CustomDeSelect = () =>
|
|||
|
|
{
|
|||
|
|
SetTextColor(input.gameObject, false);
|
|||
|
|
SetBgColor(input, 3);
|
|||
|
|
};
|
|||
|
|
input.CustomEnter = () =>
|
|||
|
|
{
|
|||
|
|
SetBgColor(input, 1);
|
|||
|
|
};
|
|||
|
|
if (inputCustomAction != null)
|
|||
|
|
{
|
|||
|
|
input.GetComponent<InputField>().onEndEdit.RemoveAllListeners();
|
|||
|
|
input.GetComponent<InputField>().onEndEdit.AddListener((v) => inputCustomAction(input.transform, v));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Dictionary<string, int> inputStatusDict = null;
|
|||
|
|
private void SetBgColor(PFUIInputField input, int v)
|
|||
|
|
{
|
|||
|
|
if (inputStatusDict == null)
|
|||
|
|
{
|
|||
|
|
inputStatusDict = new Dictionary<string, int>
|
|||
|
|
{
|
|||
|
|
{"CustomizeMin",3 },{"CustomizeS",3 }
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
if (!inputStatusDict.ContainsKey(input.name)) return;
|
|||
|
|
//只要有一个select,enter 常亮 两个都exit,deselect 关掉
|
|||
|
|
inputStatusDict[input.name] = v;
|
|||
|
|
var bg = transform.Find("Main/Time/Inputbg").gameObject;
|
|||
|
|
if (inputStatusDict.Count(x=>x.Value == 1) > 0)
|
|||
|
|
{
|
|||
|
|
bg.GetComponent<Outline>().enabled = true;
|
|||
|
|
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#6E6E7D");
|
|||
|
|
}
|
|||
|
|
else if (inputStatusDict.Count(x => x.Value == 2) > 0)
|
|||
|
|
{
|
|||
|
|
bg.GetComponent<Outline>().enabled = true;
|
|||
|
|
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
|
|||
|
|
}
|
|||
|
|
else if(inputStatusDict.Count(x => x.Value == 3) == 2)
|
|||
|
|
{
|
|||
|
|
bg.GetComponent<Outline>().enabled = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void InitAll()
|
|||
|
|
{
|
|||
|
|
foreach (var item in formList)
|
|||
|
|
{
|
|||
|
|
if (item is Button)
|
|||
|
|
{
|
|||
|
|
SetButtonColor(item as Button, false);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
var i = item as PFUIInputField;
|
|||
|
|
i.Text = "";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void ClickDistanceBtn(Button btn, IEnumerable<Button> list)
|
|||
|
|
{
|
|||
|
|
foreach (var item in list)
|
|||
|
|
{
|
|||
|
|
SetButtonColor(item, false);
|
|||
|
|
}
|
|||
|
|
if (btn)
|
|||
|
|
{
|
|||
|
|
SetButtonColor(btn, true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SetButtonColor(Button btn, bool flag)
|
|||
|
|
{
|
|||
|
|
SetTextColor(btn.gameObject, flag);
|
|||
|
|
btn.gameObject.GetComponent<Image>().color = flag ? Utils.HexToColorHtml("#f93086") : Utils.HexToColorHtml("#23232d");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SetTextColor(GameObject btn, bool flag)
|
|||
|
|
{
|
|||
|
|
if (btn.transform.Find("t1"))
|
|||
|
|
{
|
|||
|
|
btn.transform.Find("t1").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (btn.transform.Find("t2"))
|
|||
|
|
{
|
|||
|
|
btn.transform.Find("t2").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// Start is called before the first frame update
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Update is called once per frame
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|