using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class PhantasmPavilionWin : Window
|
{
|
[SerializeField] ScrollerController sclTab;
|
[SerializeField] ScrollerController sclItem;
|
[SerializeField] ScrollerController sclAttr;
|
[SerializeField] ItemCell unlockItemCell;
|
[SerializeField] ItemCell starUpItemCell;
|
[SerializeField] AvatarCell avatarCell;
|
[SerializeField] ImageEx imgFace;
|
[SerializeField] UIEffect uiEffect;
|
[SerializeField] TextEx txtTime;
|
[SerializeField] TextEx txtDescriptive;
|
[SerializeField] ButtonEx btnUnLock;
|
[SerializeField] ButtonEx btnAddStar;
|
[SerializeField] ButtonEx btnUse;
|
[SerializeField] Button btnClose;
|
|
[SerializeField] GameObject StarGroup;
|
[SerializeField] List<ImageEx> starList = new List<ImageEx>(); //ÐÇÐÇÏÔʾÒþ²Ø starListºÍstarShowListÊýÁ¿Ò»ÖÂ
|
[SerializeField] List<ImageEx> starShowList = new List<ImageEx>(); //ÐÇÐÇÊÇÁÁÊǰµ
|
PhantasmPavilionModel model { get { return ModelCenter.Instance.GetModel<PhantasmPavilionModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
protected override void AddListeners()
|
{
|
btnUnLock.SetListener(OnClickUnLock);
|
btnAddStar.SetListener(OnClickAddStar);
|
btnUse.SetListener(OnClickUse);
|
btnClose.SetListener(CloseClick);
|
}
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
sclTab.OnRefreshCell += OnRefreshTabCell;
|
sclItem.OnRefreshCell += OnRefreshItemCell;
|
sclAttr.OnRefreshCell += OnRefreshAttrCell;
|
model.TabChangeEvent += OnTabChangeEvent;
|
model.ItemIdChangeEvent += OnItemIdChangeEvent;
|
model.UpdateFaceInfoEvent += UpdateFaceInfoEvent;
|
model.UpdateFacePicInfoEvent += OnUpdateFacePicInfoEvent;
|
model.UpdateEmojiPackInfoEvent += OnUpdateEmojiPackInfoEvent;
|
model.UpdateChatBubbleBoxInfoEvent += OnUpdateUpdateChatBubbleBoxInfoEvent;
|
packModel.refreshItemCountEvent += OnRefreshItemCountEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
|
GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
|
}
|
|
protected override void OnPreClose()
|
{
|
sclTab.OnRefreshCell -= OnRefreshTabCell;
|
sclItem.OnRefreshCell -= OnRefreshItemCell;
|
sclAttr.OnRefreshCell -= OnRefreshAttrCell;
|
model.TabChangeEvent -= OnTabChangeEvent;
|
model.ItemIdChangeEvent -= OnItemIdChangeEvent;
|
model.UpdateFaceInfoEvent -= UpdateFaceInfoEvent;
|
model.UpdateFacePicInfoEvent -= OnUpdateFacePicInfoEvent;
|
model.UpdateEmojiPackInfoEvent -= OnUpdateEmojiPackInfoEvent;
|
model.UpdateChatBubbleBoxInfoEvent -= OnUpdateUpdateChatBubbleBoxInfoEvent;
|
packModel.refreshItemCountEvent -= OnRefreshItemCountEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
|
GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CreateTabScroller();
|
CreateItemScroller();
|
CreateAttrScroller();
|
Display();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
private void OnTabChangeEvent()
|
{
|
sclTab.m_Scorller.RefreshActiveCellViews();
|
var list = model.ShowItemList(model.selectTab, out int fristIndex);
|
if (!list.IsNullOrEmpty())
|
{
|
model.selectItemId = fristIndex;
|
CreateItemScroller();
|
}
|
}
|
|
private void OnItemIdChangeEvent()
|
{
|
sclItem.m_Scorller.RefreshActiveCellViews();
|
CreateAttrScroller();
|
Display();
|
model.UpdateRedPoint();
|
}
|
|
private void UpdateFaceInfoEvent()
|
{
|
RefreshAll();
|
}
|
|
private void OnUpdateFacePicInfoEvent()
|
{
|
RefreshAll();
|
}
|
|
private void OnUpdateEmojiPackInfoEvent()
|
{
|
RefreshAll();
|
}
|
|
private void OnUpdateUpdateChatBubbleBoxInfoEvent()
|
{
|
RefreshAll();
|
}
|
|
private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3)
|
{
|
RefreshAll();
|
}
|
|
private void OnPlayerDataRefreshEvent(PlayerDataType type)
|
{
|
if (type == PlayerDataType.Face || type == PlayerDataType.HairColor || type == PlayerDataType.ExAttr10)
|
{
|
RefreshAll();
|
}
|
}
|
|
private void OnSecondEvent()
|
{
|
sclTab.m_Scorller.RefreshActiveCellViews();
|
sclItem.m_Scorller.RefreshActiveCellViews();
|
Display();
|
model.UpdateRedPoint();
|
}
|
|
private void RefreshAll()
|
{
|
sclTab.m_Scorller.RefreshActiveCellViews();
|
sclItem.m_Scorller.RefreshActiveCellViews();
|
CreateAttrScroller();
|
Display();
|
model.UpdateRedPoint();
|
}
|
|
private void OnRefreshTabCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as PhantasmPavilionTabCell;
|
_cell.Display(_cell.index);
|
}
|
|
private void OnRefreshItemCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as PhantasmPavilionItemCell;
|
_cell.Display(_cell.index);
|
}
|
|
private void OnRefreshAttrCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as PhantasmPavilionAttrCell;
|
_cell.Display(_cell.index);
|
}
|
|
private void CreateTabScroller()
|
{
|
sclTab.Refresh();
|
int enumCount = Enum.GetValues(typeof(PhantasmPavilionTab)).Length;
|
for (int i = 0; i < enumCount; i++)
|
{
|
sclTab.AddCell(ScrollerDataType.Header, i);
|
}
|
sclTab.Restart();
|
}
|
|
private void CreateItemScroller()
|
{
|
sclItem.Refresh();
|
List<int> showItemList = model.ShowItemList(model.selectTab, out int fristIndex);
|
if (!showItemList.IsNullOrEmpty())
|
{
|
int rowCount = (int)Math.Ceiling((double)showItemList.Count / model.MaxItemRowCount);
|
for (int i = 0; i < rowCount; i++)
|
{
|
sclItem.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
sclItem.Restart();
|
}
|
|
private void CreateAttrScroller()
|
{
|
int id = model.selectItemId;
|
PhantasmPavilionTab tab = model.selectTab;
|
int unLockState = model.GetUnLockState(tab, id);// 0 - δ¼¤»î 1 - ¿É¼¤»î 2 - ÒѼ¤»î
|
bool isHaveUnLockAttr = model.TryGetUnLockAttr(tab, id, out int[] lightAttrTypeArr, out int[] lightAttrValueArr);
|
|
sclAttr.Refresh();
|
|
if (isHaveUnLockAttr)
|
{
|
if (unLockState == 2)
|
{
|
if (!model.TryGetInfo(tab, id, out var info))
|
return;
|
bool isHaveAttrProp = model.TryGetAttrProp(tab, id, info.Star, out List<int> attrTypeList, out List<int> oldAttrValueList, out List<int> newAttrValueList);
|
if (isHaveAttrProp)
|
{
|
for (int i = 0; i < attrTypeList.Count; i++)
|
{
|
sclAttr.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
}
|
else
|
{
|
for (int i = 0; i < lightAttrTypeArr.Length; i++)
|
{
|
sclAttr.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
}
|
sclAttr.Restart();
|
}
|
|
private void Display()
|
{
|
int id = model.selectItemId;
|
PhantasmPavilionTab tab = model.selectTab;
|
int unLockState = model.GetUnLockState(tab, id);// 0 - δ¼¤»î 1 - ¿É¼¤»î 2 - ÒѼ¤»î
|
bool isLimitTime = model.IsLimitTime(tab, id);
|
bool isUsing = model.IsUsing(tab, id);
|
bool isNoMaxStar = model.TryGetUpStar(tab, id, out int nowUpStar);
|
bool isInfo = model.TryGetInfo(tab, id, out var info);
|
bool isUnLockAttr = model.TryGetUnLockAttr(tab, id, out int[] lightAttrTypeArr, out int[] lightAttrValueArr);
|
bool isUnlockDefault = model.GetUnlockDefault(tab, id) == 1;
|
bool isMaxStarLV = model.TryGetMaxStarLV(tab, id, out int maxStar);
|
|
bool isUnLockNeedItem = model.TryGetUnLockNeedItem(tab, id, out int itemId, out int count);
|
bool isStarUpNeedItem = model.TryGetStarUpNeedItem(tab, id, nowUpStar, out int itemId1, out int count1);
|
|
sclAttr.SetActive(isUnLockAttr);
|
unlockItemCell.SetActive(isUnLockNeedItem && unLockState != 2);
|
starUpItemCell.SetActive(isStarUpNeedItem && unLockState == 2 && !isLimitTime && isNoMaxStar);
|
btnUnLock.SetActive(isUnLockNeedItem && unLockState != 2);
|
btnAddStar.SetActive(isStarUpNeedItem && unLockState == 2 && !isLimitTime && isNoMaxStar);
|
StarGroup.SetActive(isInfo && isMaxStarLV && unLockState == 2);
|
|
if (model.selectTab == PhantasmPavilionTab.ChatExpression)
|
{
|
btnUse.SetActive(false);
|
}
|
else if (model.selectTab == PhantasmPavilionTab.Avatar)
|
{
|
if (!isUsing && unLockState == 2)
|
{
|
if (!model.IsCustom(id, out int customPlayerID))
|
{
|
btnUse.SetActive(true);
|
}
|
else
|
{
|
btnUse.SetActive(customPlayerID == PlayerDatas.Instance.PlayerId);
|
}
|
}
|
else
|
{
|
btnUse.SetActive(false);
|
}
|
}
|
else
|
{
|
btnUse.SetActive(!isUsing && unLockState == 2);
|
}
|
|
imgFace.SetActive(model.selectTab == PhantasmPavilionTab.ChatBubble || model.selectTab == PhantasmPavilionTab.ChatExpression);
|
model.ShowImage(tab, id, imgFace);
|
|
avatarCell.SetActive(model.selectTab == PhantasmPavilionTab.Avatar || model.selectTab == PhantasmPavilionTab.AvatarFrame);
|
if (model.selectTab == PhantasmPavilionTab.Avatar)
|
{
|
int avatarId = model.selectItemId;
|
int avatarEffect = AvatarHelper.GetAvatarFrameEffectID(avatarId);
|
int avatarFrameId = AvatarHelper.GetMyAvatarFrameID();
|
int avatarFrameEffect = AvatarHelper.GetAvatarFrameEffectID(avatarFrameId);
|
avatarCell.InitUI(new AvatarModel(avatarId, avatarFrameId, avatarEffect, avatarFrameEffect));
|
}
|
else if (model.selectTab == PhantasmPavilionTab.AvatarFrame)
|
{
|
int avatarId = AvatarHelper.GetMyAvatarID();
|
int avatarEffect = AvatarHelper.GetAvatarFrameEffectID(avatarId);
|
int avatarFrameId = model.selectItemId;
|
int avatarFrameEffect = AvatarHelper.GetAvatarFrameEffectID(avatarFrameId);
|
avatarCell.InitUI(new AvatarModel(avatarId, avatarFrameId, avatarEffect, avatarFrameEffect));
|
}
|
|
uiEffect.Stop();
|
if (model.TryGetEffectID(tab, id, out int effectID))
|
{
|
uiEffect.effect = effectID;
|
uiEffect.Play();
|
}
|
|
int subTime = 0;
|
if (info != null)
|
{
|
subTime = (int)(info.EndTime - TimeUtility.AllSeconds);
|
}
|
txtTime.text = Language.Get("FairyEmblem03", !isLimitTime ? Language.Get("PhantasmPavilion03") : isInfo && unLockState == 2 ? TimeUtility.SecondsToDHMSCHS(subTime) : TimeUtility.SecondsToDHMSCHS(model.GetExpireMinutes(tab, id) * 60));
|
txtDescriptive.text = model.GetDescriptive(tab, id);
|
int star = 0;
|
if (info != null)
|
star = info.Star;
|
for (int i = 0; i < starList.Count; i++)
|
{
|
starList[i].SetActive(i < maxStar && i < starList.Count);
|
starShowList[i].SetActive(i < star && i < starList.Count);
|
}
|
model.SetStarColor(star, starShowList);
|
|
if (isUnLockNeedItem)
|
{
|
int hasCnt = packModel.GetItemCountByID(PackType.Item, itemId);
|
var hasCntColor = UIHelper.AppendColor(hasCnt >= count ? TextColType.DarkGreen : TextColType.Red, hasCnt.ToString());
|
unlockItemCell.Init(new ItemCellModel(itemId, false, (ulong)count));
|
starUpItemCell.countText.SetActive(true);
|
unlockItemCell.countText.text = StringUtility.Contact(hasCntColor, "/", count);
|
unlockItemCell.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(itemId);
|
});
|
}
|
|
if (isStarUpNeedItem)
|
{
|
int hasCnt = packModel.GetItemCountByID(PackType.Item, itemId1);
|
var hasCntColor = UIHelper.AppendColor(hasCnt >= count1 ? TextColType.DarkGreen : TextColType.Red, hasCnt.ToString());
|
starUpItemCell.Init(new ItemCellModel(itemId1, false, (ulong)count1));
|
starUpItemCell.countText.SetActive(true);
|
starUpItemCell.countText.text = StringUtility.Contact(hasCntColor, "/", count1);
|
starUpItemCell.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(itemId1);
|
});
|
}
|
}
|
|
private void OnClickUnLock()
|
{
|
int state = model.GetUnLockState(model.selectTab, model.selectItemId);
|
if (state == 2)
|
return;
|
if (!model.TryGetUnLockNeedItem(model.selectTab, model.selectItemId, out int itemId, out int count))
|
return;
|
int hasCnt = packModel.GetItemCountByID(PackType.Item, itemId);
|
if (hasCnt < count)
|
{
|
SysNotifyMgr.Instance.ShowTip("RealmLevelUpError_3");
|
return;
|
}
|
string guid = packModel.GetItemGUIDByID(itemId);
|
if (guid == null)
|
return;
|
var itemModel = packModel.GetItemByGuid(guid);
|
if (itemModel == null)
|
return;
|
|
model.SendCA323UnLockPack(itemModel.gridIndex, count);
|
}
|
|
private void OnClickUse()
|
{
|
model.SendUsePack(model.selectTab, model.selectItemId);
|
}
|
|
private void OnClickAddStar()
|
{
|
if (!model.TryGetUpStar(model.selectTab, model.selectItemId, out int nowUpStar))
|
return;
|
int state = model.GetUnLockState(model.selectTab, model.selectItemId);
|
if (state == 0 || state == 1)
|
return;
|
if (!model.TryGetStarUpNeedItem(model.selectTab, model.selectItemId, nowUpStar, out int itemId, out int count))
|
return;
|
int hasCnt = packModel.GetItemCountByID(PackType.Item, itemId);
|
if (hasCnt < count)
|
{
|
SysNotifyMgr.Instance.ShowTip("RealmLevelUpError_3");
|
return;
|
}
|
model.SendStarUPPack(model.selectTab, model.selectItemId);
|
}
|
}
|
}
|