少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-23 a974a2621a6dcb90b8fe52b23d075814873c0960
System/OpenServerActivity/WishingPoolWin.cs
@@ -8,11 +8,22 @@
    public class WishingPoolWin : Window
    {
        [SerializeField] DragItem dragItem;
        [SerializeField] Text activityDayText;
        [SerializeField] Text totalDayText;
        [SerializeField] Text dayRemainTime;
        [SerializeField] Button lookAllBtn;
        [SerializeField] Button freeRefreshWishBtn;
        [SerializeField] Button moneyRefreshWishBtn;
        [SerializeField] Text moneyValueText;
        [SerializeField] Text freeWishCoolText;
        [SerializeField] List<PoolItemCell> poolItemCells = new List<PoolItemCell>();
        [SerializeField] List<WishingCell> wishingCells = new List<WishingCell>();
        [SerializeField] List<WishItemCell> wishingCells = new List<WishItemCell>();
        [SerializeField] GameObject activityOpenObj;
        [SerializeField] GameObject activityCloseObj;
        ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        WishingPoolModel wishingModel { get { return ModelCenter.Instance.GetModel<WishingPoolModel>(); } }
        OperationWishingWellInfo operation = null;
        #region Built-in
        protected override void BindController()
        {
@@ -21,14 +32,18 @@
        protected override void AddListeners()
        {
            freeRefreshWishBtn.AddListener(ClickFreeRefreshWish);
            moneyRefreshWishBtn.AddListener(ClickMoneyRefreshWish);
            lookAllBtn.AddListener(ClickLook);
        }
        protected override void OnPreOpen()
        {
            Display();
            OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
            wishingModel.UpdatePoolDataEvent += UpdatePoolItemByIndex;
            wishingModel.UpdateWishingDataEvent += UpdateWishItemByIndex;
            Display();
            GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
        }
        protected override void OnAfterOpen()
@@ -39,8 +54,9 @@
        {
            wishingModel.UpdatePoolDataEvent -= UpdatePoolItemByIndex;
            wishingModel.UpdateWishingDataEvent -= UpdateWishItemByIndex;
            GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
            OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
        }
        protected override void OnAfterClose()
        {
@@ -49,15 +65,23 @@
        private void Display()
        {
            operation = wishingModel.GetOperationWishing();
            if (operation == null) return;
            UpdatePoolItem();
            for(int i = 0; i < wishingCells.Count; i++)
            {
                UpdateWishItemByIndex(i);
            }
            dragItem.dragItemRect.gameObject.SetActive(false);
            UpdateFreeWishCool();
            UpdateActivityState();
            UpdateDayRemainTime();
            activityDayText.text = Language.Get("WishingPool103", Language.Get(StringUtility.Contact("Num_CHS_", operation.GetActivityDay())));
            totalDayText.text = Language.Get("WishingPool101", Language.Get(StringUtility.Contact("Num_CHS_", operation.totalDays + 1)));
        }
        #region 许愿逻辑
        protected override void LateUpdate()
        {
           if(wishingModel.isDraging)
@@ -80,30 +104,31 @@
                }
            }
        }
        private void CheckWishingCell()
        {
            for(int i = 0; i < wishingCells.Count; i++)
            {
                var rect = wishingCells[i].wishRect;
                var rect = wishingCells[i].transform as RectTransform;
                var des = RectTransformUtility.CalculateRelativeRectTransformBounds(this.transform, rect);
                var src = RectTransformUtility.CalculateRelativeRectTransformBounds(this.transform, dragItem.dragItemRect);
                var dis = Vector3.Distance(des.center, src.center);
                if (dis < rect.rect.width / 2)
                {
                    int poolId = 0;
                    bool isPoolData = wishingModel.TryGetPoolDataByIndex(wishingModel.dragIndex, out poolId);
                    int wishId = 0;
                    bool isWishData = wishingModel.TryGetWishDataByIndex(i, out wishId);
                    if (wishId == 0)
                    {
                        wishingModel.RemovetWishingPoolData(i);
                    }
                    else
                    {
                        wishingModel.SetWishingPoolData(wishingModel.dragIndex, wishId);
                    }
                    wishingModel.SetWishingData(i,poolId);
                    //WishingPoolModel.WishingWellItem wellPoolItem = null;
                    //bool isPoolData = wishingModel.TryGetPoolDataByIndex(wishingModel.dragIndex, out wellPoolItem);
                    //WishingPoolModel.WishingWellItem wellWishItem = null;
                    //bool isWishData = wishingModel.TryGetWishDataByIndex(i, out wellWishItem);
                    //if (wellWishItem.itemId == 0)
                    //{
                    //    wishingModel.RemovetWishingPoolData(i);
                    //}
                    //else
                    //{
                    //    wishingModel.SetWishingPoolData(wishingModel.dragIndex,wellWishItem);
                    //}
                    //wishingModel.SetWishingData(i,wellPoolItem);
                    wishingModel.SendRefreshWishInfo(wishingModel.dragIndex,i);
                    break;
                }
            }
@@ -111,13 +136,13 @@
        private bool TryGetDragItem()
        {
            int id = 0;
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(wishingModel.dragIndex, out id);
            WishingPoolModel.WishingWellItem wellItem = null;
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(wishingModel.dragIndex, out wellItem);
            if (isPoolData)
            {
                dragItem.dragItemRect.gameObject.SetActive(true);
                dragItem.dragBestIcon.SetActive(false);
                ItemCellModel cellModel = new ItemCellModel(id);
                ItemCellModel cellModel = new ItemCellModel(wellItem.itemId,false,(ulong)wellItem.itemCount,wellItem.isBind);
                dragItem.dragItemBasic.Init(cellModel);
            }
            else
@@ -137,9 +162,9 @@
        private void UpdatePoolItemByIndex(int index)
        {
            int id = 0;
            WishingPoolModel.WishingWellItem wellItem = null;
            var poolItemCell = poolItemCells[index];
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(index, out id);
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(index, out wellItem);
            if (isPoolData)
            {
                poolItemCell.gameObject.SetActive(true);
@@ -153,36 +178,8 @@
        private void UpdateWishItemByIndex(int index)
        {
            int id = 0;
            var wishCell = wishingCells[index];
            bool isWishData = wishingModel.TryGetWishDataByIndex(index, out id);
            if (isWishData)
            {
                wishCell.itemBaisc.gameObject.SetActive(true);
                wishCell.noneItemObj.gameObject.SetActive(false);
                ItemCellModel cellModel = new ItemCellModel(id);
                wishCell.itemBaisc.Init(cellModel);
                wishCell.itemBaisc.cellBtn.RemoveAllListeners();
                wishCell.itemBaisc.cellBtn.AddListener(() =>
                {
                    ItemAttrData attrData = new ItemAttrData(id);
                    tipsModel.SetItemTipsModel(attrData);
                });
            }
            else
            {
                wishCell.itemBaisc.gameObject.SetActive(false);
                wishCell.noneItemObj.gameObject.SetActive(true);
            }
        }
        [Serializable]
        public class WishingCell
        {
            public RectTransform wishRect;
            public CommonItemBaisc itemBaisc;
            public GameObject noneItemObj;
            public Button noneItemBtn;
            wishCell.Display(index);
        }
        [Serializable]
@@ -192,5 +189,81 @@
           public CommonItemBaisc dragItemBasic;
           public GameObject dragBestIcon;
        }
        #endregion
        #region 活动逻辑
        private void OperationEndEvent(Operation type, int state)
        {
            if(type == Operation.WishingWellInfo && state == 1)
            {
                UpdateActivityState();
            }
        }
        private void UpdateSecond()
        {
            if (operation == null) return;
            UpdateFreeWishCool();
            UpdateDayRemainTime();
        }
        private void UpdateDayRemainTime()
        {
            dayRemainTime.text = Language.Get("WishingPool104", TimeUtility.SecondsToHMS(operation.GetResetSurplusTime()));
        }
        private void UpdateFreeWishCool()
        {
            int second = 0;
            bool isCool = wishingModel.TryGetFreeWishCoolTime(out second);
            if (isCool)
            {
                freeRefreshWishBtn.gameObject.SetActive(false);
                freeWishCoolText.gameObject.SetActive(true);
                moneyRefreshWishBtn.gameObject.SetActive(true);
                moneyValueText.text = "100";
                freeWishCoolText.text = Language.Get("WishingPool102", TimeUtility.SecondsToHMS(second));
            }
            else
            {
                freeRefreshWishBtn.gameObject.SetActive(true);
                freeWishCoolText.gameObject.SetActive(false);
                moneyRefreshWishBtn.gameObject.SetActive(false);
            }
        }
        private void UpdateActivityState()
        {
            if (wishingModel.IsOpen)
            {
                activityOpenObj.SetActive(true);
                activityCloseObj.SetActive(false);
            }
            else
            {
                activityOpenObj.SetActive(false);
                activityCloseObj.SetActive(true);
            }
        }
        private void ClickLook()
        {
            WindowCenter.Instance.Open<WishingWarehouseWin>();
        }
        private void ClickMoneyRefreshWish()
        {
            wishingModel.SendRefreshPoolInfo(0);
        }
        private void ClickFreeRefreshWish()
        {
            wishingModel.SendRefreshPoolInfo(1);
        }
        #endregion
    }
}