You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.8 KiB
104 lines
2.8 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class UIViewNumberSelect : UIView { |
|
|
|
public InputField NumberInput; |
|
public CommonButton ButtonMinus; |
|
public CommonButton ButtonPlus; |
|
public CommonButton ButtonClose; |
|
public CommonButton ButtonEnter; |
|
public CommonButton ButtonCancel; |
|
|
|
public Action<int> CommitAction; |
|
public string EquipName = ""; |
|
public override UIViewType ViewType |
|
{ |
|
get |
|
{ |
|
return UIViewType.Popup; |
|
} |
|
} |
|
|
|
public override void Show() |
|
{ |
|
base.Show(); |
|
NumberInput.ActivateInputField(); |
|
} |
|
private void OnEnable() |
|
{ |
|
NumberInput.onValueChanged.AddListener(NumberInput_OnValueChanged); |
|
ButtonMinus.OnClicked += ButtonMinus_OnClicked; |
|
ButtonPlus.OnClicked += ButtonPlus_OnClicked; |
|
ButtonClose.OnClicked += ButtonClose_OnClicked; |
|
ButtonCancel.OnClicked += ButtonCancel_OnClicked; |
|
ButtonEnter.OnClicked += ButtonEnter_OnClicked; |
|
} |
|
|
|
private void NumberInput_OnValueChanged(string arg0) |
|
{ |
|
if (string.IsNullOrEmpty(arg0)) |
|
{ |
|
arg0 = "0"; |
|
} |
|
int num = int.Parse(arg0); |
|
//num = Mathf.Clamp(num, 0, 99); |
|
// 移动水炮/暴风雪炮/灭火机器人/水幕水带99,其他10 |
|
if (EquipName == "移动水炮" || EquipName == "暴风雪炮" || EquipName == "灭火机器人" || EquipName == "水幕水带") |
|
{ |
|
num = Mathf.Clamp(num, 0, 99); |
|
} |
|
else |
|
{ |
|
num = Mathf.Clamp(num, 0, 10); |
|
} |
|
NumberInput.text = num.ToString(); |
|
} |
|
|
|
private void OnDisable() |
|
{ |
|
NumberInput.onValueChanged.RemoveListener(NumberInput_OnValueChanged); |
|
ButtonMinus.OnClicked -= ButtonMinus_OnClicked; |
|
ButtonPlus.OnClicked -= ButtonPlus_OnClicked; |
|
ButtonClose.OnClicked -= ButtonClose_OnClicked; |
|
ButtonCancel.OnClicked -= ButtonCancel_OnClicked; |
|
ButtonEnter.OnClicked -= ButtonEnter_OnClicked; |
|
CommitAction = null; |
|
NumberInput.text = "0"; |
|
} |
|
private void ButtonEnter_OnClicked(CommonButton obj) |
|
{ |
|
int num = int.Parse(NumberInput.text); |
|
CommitAction(num); |
|
Hide(); |
|
} |
|
|
|
private void ButtonCancel_OnClicked(CommonButton obj) |
|
{ |
|
CommitAction(0); |
|
Hide(); |
|
} |
|
|
|
private void ButtonClose_OnClicked(CommonButton obj) |
|
{ |
|
CommitAction(0); |
|
Hide(); |
|
} |
|
|
|
private void ButtonPlus_OnClicked(CommonButton obj) |
|
{ |
|
int num = int.Parse(NumberInput.text); |
|
num++; |
|
NumberInput.text = num.ToString(); |
|
} |
|
|
|
private void ButtonMinus_OnClicked(CommonButton obj) |
|
{ |
|
int num = int.Parse(NumberInput.text); |
|
num--; |
|
NumberInput.text = num.ToString(); |
|
} |
|
}
|
|
|