少年修仙传客户端代码仓库
Client_PangDeRong
2018-10-19 a8aaf25139e25e2a52b42a48b815bd37f73a06f7
4232 【前端】许愿池功能开发
4个文件已修改
152 ■■■■ 已修改文件
System/OpenServerActivity/PoolItemCell.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/WishingPoolModel.cs 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/WishingPoolWin.cs 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/WindowBase/ModelCenter.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/OpenServerActivity/PoolItemCell.cs
@@ -4,39 +4,36 @@
namespace Snxxz.UI
{
    public class PoolItemCell : MonoBehaviour,IDragHandler,IDropHandler
    public class PoolItemCell : MonoBehaviour,IDragHandler
    {
        [SerializeField] CommonItemBaisc itemBaisc;
        [SerializeField] GameObject bestIconObj;
        
        ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        WishingPoolModel wishingModel { get { return ModelCenter.Instance.GetModel<WishingPoolModel>(); } }
        int itemId = 0;
        int index = -1;
        public void OnDrag(PointerEventData eventData)
        {
            Debug.Log("拖拽开始");
            wishingModel.isDraging = true;
            wishingModel.dragItemId = itemId;
            wishingModel.dragIndex = index;
        }
        public void OnDrop(PointerEventData eventData)
        public void Display(int index)
        {
            Debug.Log("拖拽结束");
            wishingModel.ResetDragData();
        }
        public void Display(int itemId)
        {
            this.itemId = itemId;
            this.index = index;
            int id = 0;
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(index,out id);
            bestIconObj.SetActive(false);
            ItemCellModel cellModel = new ItemCellModel(itemId);
            ItemCellModel cellModel = new ItemCellModel(id);
            itemBaisc.Init(cellModel);
            itemBaisc.cellBtn.RemoveAllListeners();
            itemBaisc.cellBtn.AddListener(()=>
            {
                ItemAttrData attrData = new ItemAttrData(itemId);
                ItemAttrData attrData = new ItemAttrData(id);
                tipsModel.SetItemTipsModel(attrData);
            });
        }
    }
}
System/OpenServerActivity/WishingPoolModel.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -6,6 +7,9 @@
{
    public class WishingPoolModel : Model,IBeforePlayerDataInitialize,IPlayerLoginOk
    {
        public event Action<int> UpdateWishingDataEvent;
        public event Action<int> UpdatePoolDataEvent;
        public override void Init()
        {
            
@@ -29,11 +33,11 @@
        #region 本地数据
        public bool isDraging { get; set; }
        public int dragItemId { get; set; }
        public int dragIndex { get; set; }
        public void ResetDragData()
        {
            isDraging = false;
            dragItemId = 0;
            dragIndex = -1;
        }
        #endregion
@@ -43,8 +47,36 @@
        {
            for(int i = 0; i< 8; i++)
            {
                int itemId = 10101 + i;
                poolDataDict.Add(i,itemId);
                int itemId = 1 + i;
                SetWishingPoolData(i,itemId);
            }
        }
        public void SetWishingPoolData(int index, int id)
        {
            if (!poolDataDict.ContainsKey(index))
            {
                poolDataDict.Add(index, id);
            }
            else
            {
                poolDataDict[index] = id;
            }
            if(UpdatePoolDataEvent != null)
            {
                UpdatePoolDataEvent(index);
            }
        }
        public void RemovetWishingPoolData(int index)
        {
            if (poolDataDict.ContainsKey(index))
            {
                poolDataDict.Remove(index);
            }
            if (UpdatePoolDataEvent != null)
            {
                UpdatePoolDataEvent(index);
            }
        }
@@ -59,6 +91,11 @@
            {
                wishingDataDict[index] = id;
            }
            if(UpdateWishingDataEvent != null)
            {
                UpdateWishingDataEvent(index);
            }
        }
        public bool TryGetPoolDataByIndex(int index,out int id)
System/OpenServerActivity/WishingPoolWin.cs
@@ -26,7 +26,9 @@
        protected override void OnPreOpen()
        {
            wishingModel.UpdatePoolDataEvent += UpdatePoolItemByIndex;
            wishingModel.UpdateWishingDataEvent += UpdateWishItemByIndex;
            Display();
        }
        protected override void OnAfterOpen()
@@ -35,7 +37,8 @@
        }
        protected override void OnPreClose()
        {
            wishingModel.UpdatePoolDataEvent -= UpdatePoolItemByIndex;
            wishingModel.UpdateWishingDataEvent -= UpdateWishItemByIndex;
        }
        protected override void OnAfterClose()
@@ -51,6 +54,7 @@
            {
                UpdateWishItemByIndex(i);
            }
            dragItem.dragItemRect.gameObject.SetActive(false);
        }
@@ -58,8 +62,69 @@
        {
           if(wishingModel.isDraging)
            {
               if(TryGetDragItem())
                {
                    Vector2 _pos;
                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform,
                        Input.mousePosition, CameraManager.uiCamera, out _pos))
                    {
                        dragItem.dragItemRect.anchoredPosition3D = _pos;
                    }
                    if (Input.GetMouseButtonUp(0))
                    {
                        dragItem.dragItemRect.gameObject.SetActive(false);
                        CheckWishingCell();
                        wishingModel.ResetDragData();
                    }
                }
            }
        }
        private void CheckWishingCell()
        {
            for(int i = 0; i < wishingCells.Count; i++)
            {
                var rect = wishingCells[i].wishRect;
                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);
                    break;
                }
            }
        }
        private bool TryGetDragItem()
        {
            int id = 0;
            bool isPoolData = wishingModel.TryGetPoolDataByIndex(wishingModel.dragIndex, out id);
            if (isPoolData)
            {
                dragItem.dragItemRect.gameObject.SetActive(true);
                dragItem.dragBestIcon.SetActive(false);
                ItemCellModel cellModel = new ItemCellModel(id);
                dragItem.dragItemBasic.Init(cellModel);
            }
            else
            {
                dragItem.dragItemRect.gameObject.SetActive(false);
            }
            return isPoolData;
        }
        private void UpdatePoolItem()
@@ -78,7 +143,7 @@
            if (isPoolData)
            {
                poolItemCell.gameObject.SetActive(true);
                poolItemCell.Display(id);
                poolItemCell.Display(index);
            }
            else
            {
@@ -114,6 +179,7 @@
        [Serializable]
        public class WishingCell
        {
            public RectTransform wishRect;
            public CommonItemBaisc itemBaisc;
            public GameObject noneItemObj;
            public Button noneItemBtn;
@@ -122,8 +188,9 @@
        [Serializable]
        public class DragItem
        {
            [SerializeField] CommonItemBaisc dragItemBasic;
            [SerializeField] GameObject dragBestIcon;
           public RectTransform dragItemRect;
           public CommonItemBaisc dragItemBasic;
           public GameObject dragBestIcon;
        }
    }
}
System/WindowBase/ModelCenter.cs
@@ -198,6 +198,7 @@
            RegisterModel<FlashRushToBuyModel>();
            RegisterModel<TalentModel>();
            RegisterModel<OpenServerActivityNotifyModel>();
            RegisterModel<WishingPoolModel>();
            inited = true;
        }