using System; using UnityEngine; namespace vnxbqy.UI { public class BlessedLandCell : CellView { [SerializeField] RectTransform rectCombatScope; [SerializeField] RectTransform rectItem; [SerializeField] ImageEx imgExclusive; [SerializeField] ButtonEx btnItemCell; [SerializeField] UIEffect hostUIEffect; [SerializeField] UIEffect theftUIEffect; [SerializeField] Transform transHostStart; [SerializeField] Transform transHostEnd; [SerializeField] Transform transTheftStart; [SerializeField] Transform transTheftEnd; [SerializeField] ImageEx imgMyFlag; [SerializeField] ImageEx imgHostCountBG; [SerializeField] ImageEx imgHostArrow; [SerializeField] FrameEffect skeHostSpriteAnimation; [SerializeField] ImageEx imgTheftCountBG; [SerializeField] ImageEx imgTheftArrow; [SerializeField] FrameEffect skeTheftSpriteAnimation; [SerializeField] AvatarCell avatarCell; [SerializeField] TextEx txtHostCount; [SerializeField] TextEx txtTheftCount; [SerializeField] ImageEx imgPublicItemTime; [SerializeField] TextEx txtPublicItemTime; [SerializeField] TextEx txtSuperTime; [SerializeField] ItemCell itemCell; int index; //当前cell的索引 int state; //当前cell的state float itemCellNowX; //itemCell中心点的Y值 float combatScopeLength; //可移动的总长度 float combatScopeMin; //可移动范围底部的Y值 float gridSpacing; //1格的具体距离 MineItemInfo mineItems; BlessedLandModel blessedLandModel { get { return ModelCenter.Instance.GetModel(); } } void Awake() { float itemCellWidth = rectItem.sizeDelta.x; float combatScopeWidth = rectCombatScope.sizeDelta.x; float itemCellSpacing = itemCellWidth / 2; combatScopeLength = combatScopeWidth - itemCellWidth; //总可移动的距离 = 可移动范围的长度 - ItemCell的长度 combatScopeMin = itemCellSpacing; gridSpacing = (float)Math.Round(combatScopeLength / 100, 4); //一格的距离 } void OnEnable() { GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; WindowCenter.Instance.windowBeforeOpenEvent += OnWindowBeforeOpenEvent; WindowCenter.Instance.windowBeforeCloseEvent += OnWindowBeforeCloseEvent; } void OnDisable() { GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; WindowCenter.Instance.windowBeforeOpenEvent -= OnWindowBeforeOpenEvent; WindowCenter.Instance.windowBeforeCloseEvent -= OnWindowBeforeCloseEvent; } private void OnWindowBeforeCloseEvent(Window window) { if (window.name == "BlessedLandDetailsWin" || window.name == "BlessedLandCornucopiaWin" || window.name == "BlessedLandManageWin" || window.name == "BlessedLandOtherWin" || window.name == "BlessedLandPKWin" || window.name == "BlessedLandRecordWin" || window.name == "BlessedLandSeekWin") { state = blessedLandModel.GetMyBlessedLandCellState(index); bool isHost = state == 2 || state == 4 || state == 6 || state == 7; bool isTheft = state == 5 || state == 6 || state == 7; hostUIEffect.SetActive(isHost); theftUIEffect.SetActive(isTheft); } } private void OnWindowBeforeOpenEvent(Window window) { if (window.name == "BlessedLandDetailsWin" || window.name == "BlessedLandCornucopiaWin" || window.name == "BlessedLandManageWin" || window.name == "BlessedLandOtherWin" || window.name == "BlessedLandPKWin" || window.name == "BlessedLandRecordWin" || window.name == "BlessedLandSeekWin") { hostUIEffect.SetActive(false); theftUIEffect.SetActive(false); } } private void OnSecondEvent() { if (state == 1 || state == 2 || state == 4 || state == 5 || state == 6 || state == 7) { if (!MineAreaItemConfig.Has(mineItems.MineID)) return; UpdateItemCellPosition(); ChangeShow(); } } public void Display(int index) { this.index = index; this.gameObject.name = "BlessedLandCell_" + index; mineItems = blessedLandModel.newAreaDataDict[blessedLandModel.myPlayerId].MineItems[index]; if (mineItems.MineID == 0 || !MineAreaItemConfig.GetKeys().Contains(mineItems.MineID.ToString())) { rectItem.SetActive(false); txtSuperTime.SetActive(false); imgExclusive.SetActive(false); imgHostCountBG.SetActive(false); imgTheftCountBG.SetActive(false); skeHostSpriteAnimation.SetActive(false); skeTheftSpriteAnimation.SetActive(false); imgMyFlag.SetActive(false); avatarCell.bgImage.SetActive(false); avatarCell.avatarImage.SetActive(false); avatarCell.avatarFrameImage.SetActive(false); imgHostArrow.SetActive(false); imgTheftArrow.SetActive(false); hostUIEffect.SetActive(false); theftUIEffect.SetActive(false); btnItemCell.SetActive(false); imgPublicItemTime.SetActive(false); txtPublicItemTime.SetActive(false); return; } state = blessedLandModel.GetMyBlessedLandCellState(index); //0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-自己拉 //3 有物品-普通物品-无人拉 4 有物品-普通物品-自己拉 5 有物品-普通物品-对方拉 //6 有物品-普通物品-双方拉-向自己移动 7 有物品-普通物品-双方拉-向对方移动 bool isHost = state == 2 || state == 4 || state == 6 || state == 7; bool isTheft = state == 5 || state == 6 || state == 7; bool isMoveToHost = state == 2 || state == 4 || state == 6; bool isMoveToTheft = state == 5 || state == 7; rectItem.SetActive(state != 0); imgExclusive.SetActive(state == 1 || state == 2); imgHostCountBG.SetActive(isHost); imgTheftCountBG.SetActive(isTheft); skeHostSpriteAnimation.SetActive(isHost); skeTheftSpriteAnimation.SetActive(isTheft); imgMyFlag.SetActive(isHost); avatarCell.bgImage.SetActive(isTheft); avatarCell.avatarImage.SetActive(isTheft); avatarCell.avatarFrameImage.SetActive(isTheft); imgHostArrow.SetActive(isMoveToHost); imgTheftArrow.SetActive(isMoveToTheft); hostUIEffect.SetActive(isHost); theftUIEffect.SetActive(isTheft); btnItemCell.SetActive(true); imgPublicItemTime.SetActive(state == 1 || state == 2 || state == 4 || isTheft); txtPublicItemTime.SetActive(state == 2 || state == 4 || isTheft); txtSuperTime.SetActive(state == 1); var com = hostUIEffect.AddMissingComponent(); com.start = transHostStart; com.end = transHostEnd; com.transmit = hostUIEffect; com.scale = 22; com.enabled = true; com = theftUIEffect.AddMissingComponent(); com.start = transTheftStart; com.end = transTheftEnd; com.transmit = theftUIEffect; com.scale = 22; com.enabled = true; var canvas = rectItem.AddMissingComponent(); canvas.overrideSorting = true; canvas.sortingLayerName = "UI"; canvas.sortingOrder = 3001; ChangeShow(); } void ChangeShow() { txtHostCount.text = mineItems.WorkerCount.ToString(); txtTheftCount.text = mineItems.RobWorkerCount.ToString(); avatarCell.InitUI(mineItems.RobPlayerID < 10000 ? blessedLandModel.GetModelForPlayerId((int)mineItems.RobPlayerID) : AvatarHelper.GetAvatarModel((int)mineItems.RobPlayerID, (int)mineItems.RobFace, (int)mineItems.RobFacePic, mineItems.RobJob)); txtSuperTime.text = TimeUtility.SecondsToDHMS((int)mineItems.UpdTime + blessedLandModel.superRefreshDefaultSpecialItemOutputDurationSeconds - TimeUtility.AllSeconds); txtPublicItemTime.text = TimeUtility.SecondsToDHMS((int)mineItems.EndTime - TimeUtility.AllSeconds); UpdateItemCellPosition(); int itemID = MineAreaItemConfig.Get(mineItems.MineID).ItemID; int itemLV = MineAreaItemConfig.Get(mineItems.MineID).ItemLV; itemCell.Init(new ItemCellModel(itemID, false, (ulong)itemLV)); itemCell.countText.SetActive(true); itemCell.countText.text = Language.Get("FashionDress106", itemLV); btnItemCell.SetListener(() => { ModelCenter.Instance.GetModel().detailsIndex = (byte)index; blessedLandModel.SendCB030Pack(0, blessedLandModel.detailsIndex, (byte)Mathf.Max(mineItems.WorkerCount, 1), 1); WindowCenter.Instance.Open(); }); } void UpdateItemCellPosition() { float consumeTime = Mathf.Max(TimeUtility.AllSeconds - mineItems.UpdTime, 0); float moveSpeed = float.Parse(mineItems.MoveSpeed); float positionAdjustment = consumeTime * moveSpeed * gridSpacing; positionAdjustment = state == 2 || state == 4 || state == 6 ? -positionAdjustment : positionAdjustment; itemCellNowX = combatScopeMin + float.Parse(mineItems.Position) * gridSpacing + positionAdjustment; if (itemCellNowX > combatScopeLength) { itemCellNowX = combatScopeLength; } if (itemCellNowX < combatScopeMin) { itemCellNowX = combatScopeMin; } rectItem.anchoredPosition = new Vector2(itemCellNowX, rectItem.anchoredPosition.y); btnItemCell.GetComponent().anchoredPosition = new Vector2(itemCellNowX, rectItem.anchoredPosition.y); } } }