using System; using UnityEngine; using UnityEngine.UI; public class BlessLVTimeUpWin : UIBase { [SerializeField] ItemCell itemCell; [SerializeField] Text itemCntTxt; [SerializeField] LongPressButton subBtn; [SerializeField] LongPressButton addBtn; [SerializeField] Text timeText; [SerializeField] Button speedBtn; protected override void InitComponent() { addBtn.SetListener(OnClickPlus); addBtn.onPress.AddListener(OnClickPlus); subBtn.SetListener(OnClickReduce); subBtn.onPress.AddListener(OnClickReduce); speedBtn.AddListener(OnSpeedUP); } protected override void OnPreOpen() { int count = (int)PackManager.Instance.GetItemCountByID(PackType.Item, BlessLVManager.Instance.timeUpTreeItemID); itemCell.Init(new ItemCellModel(BlessLVManager.Instance.timeUpTreeItemID, false, count)); itemCell.button.AddListener(() => { ItemTipUtility.Show(BlessLVManager.Instance.timeUpTreeItemID); }); var remainTime = BlessLVManager.Instance.GetLVUPRemainTime(); int needCount = (int)Math.Ceiling((float)remainTime / BlessLVManager.Instance.timeUpTreeItemSubTime); showCount = Math.Min(count, needCount); RefreshCount(needCount, remainTime); RefreshBtn(showCount); } int showCount; void RefreshCount(int needCount, int remainTime) { itemCntTxt.text = showCount + "/" + needCount; timeText.text = Language.Get("L1100", Language.Get("BlessTree8"), TimeUtility.SecondsToDHMSEx(remainTime)) + UIHelper.AppendColor(TextColType.DarkGreen, "(" + TimeUtility.SecondsToDHMSEx(showCount * BlessLVManager.Instance.timeUpTreeItemSubTime) + ")"); } void RefreshBtn(int maxCount) { if (showCount >= maxCount) { addBtn.interactable = false; addBtn.SetColorful(null, false); } else { addBtn.interactable = true; addBtn.SetColorful(null, true); } if (showCount == 0) { subBtn.interactable = false; subBtn.SetColorful(null, false); } else { subBtn.interactable = true; subBtn.SetColorful(null, true); } } void OnClickPlus() { int count = (int)PackManager.Instance.GetItemCountByID(PackType.Item, BlessLVManager.Instance.timeUpTreeItemID); var remainTime = BlessLVManager.Instance.GetLVUPRemainTime(); int needCount = (int)Math.Ceiling((float)remainTime / BlessLVManager.Instance.timeUpTreeItemSubTime); if (showCount == Math.Min(count, needCount)) return; showCount++; RefreshCount(needCount, remainTime); RefreshBtn(Math.Min(count, needCount)); } void OnClickReduce() { if (showCount == 0) return; var remainTime = BlessLVManager.Instance.GetLVUPRemainTime(); showCount--; itemCntTxt.text = showCount.ToString(); int needCount = (int)Math.Ceiling((float)remainTime / BlessLVManager.Instance.timeUpTreeItemSubTime); RefreshCount(needCount, remainTime); int count = (int)PackManager.Instance.GetItemCountByID(PackType.Item, BlessLVManager.Instance.timeUpTreeItemID); RefreshBtn(Math.Min(count, needCount)); } void OnSpeedUP() { var pack = new CB224_tagCMUseTreeLVUPTimeItem(); pack.UseCount = (uint)showCount; GameNetSystem.Instance.SendInfo(pack); CloseWindow(); } }