using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System;
|
using TableConfig;
|
|
namespace Snxxz.UI
|
{
|
public class ItemInfoWin : Window
|
{
|
[SerializeField] RectTransform bgObj;
|
|
[SerializeField]
|
Text titleText;
|
[SerializeField]
|
ItemCell itemCell;
|
[SerializeField]
|
Button closeBtn;
|
[SerializeField]
|
Text dateText;
|
|
[SerializeField]
|
Text conditionText;
|
[SerializeField] Text needLvText;
|
|
[SerializeField]
|
Text realmTitleText;
|
[SerializeField] Image realmImg;
|
|
[SerializeField]
|
Text itemTypeText;
|
|
[SerializeField]
|
Text itemDesText;
|
[SerializeField]
|
RectTransform itemDesContent;
|
[SerializeField]
|
ScrollRect scrollRect;
|
[SerializeField]
|
LayoutElement scrollLayout;
|
|
[SerializeField]
|
GameObject bottomPart;
|
|
[SerializeField]
|
Text promptText;
|
|
[SerializeField]
|
RectTransform btnGroup;
|
[SerializeField]
|
GameObject operateBtn;
|
[SerializeField]
|
CanvasGroup tipAlpha;
|
|
[SerializeField] ModelShowPerfab modelShow;
|
|
private List<GameObject> tempObjlist = new List<GameObject>();
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
PackModelInterface _modelInterface;
|
PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
Color32 conditionColor = new Color32(255, 244, 205, 255);
|
Color32 conditionRedColor = new Color32(255, 1, 1, 255);
|
Dictionary<int, int> petSkillDict;
|
Dictionary<int, List<int>> mountSkillDict;
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseWin);
|
}
|
protected override void OnPreOpen()
|
{
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct += RefreshRemainTime;
|
playerPack.RefreshItemDayUseCntAct += RefreshUseCnt;
|
this.transform.localPosition = Vector3.zero;
|
tipAlpha.alpha = 0;
|
bottomPart.SetActive(false);
|
tempObjlist.Clear();
|
InitUI();
|
}
|
|
protected override void OnActived()
|
{
|
StartCoroutine(SetScrollSize());
|
}
|
|
protected override void OnAfterOpen()
|
{
|
this.transform.SetAsLastSibling();
|
}
|
|
protected override void OnPreClose()
|
{
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct -= RefreshRemainTime;
|
playerPack.RefreshItemDayUseCntAct -= RefreshUseCnt;
|
for (int i = 0; i < tempObjlist.Count; i++)
|
{
|
Destroy(tempObjlist[i]);
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void InitUI()
|
{
|
petSkillDict = null;
|
mountSkillDict = null;
|
if (itemTipsModel.curAttrData == null)
|
return;
|
|
itemTypeText.text = itemTipsModel.curAttrData.itemConfig.ItemTypeName;
|
titleText.text = itemTipsModel.curAttrData.itemConfig.ItemName;
|
titleText.color = UIHelper.GetUIColor(itemTipsModel.curAttrData.itemConfig.ItemColor);
|
ItemCellModel cellModel = new ItemCellModel(itemTipsModel.curAttrData.itemId, itemTipsModel.curAttrData.isPreview, (ulong)itemTipsModel.curAttrData.count, itemTipsModel.curAttrData.isBind,
|
itemTipsModel.curAttrData.guid, itemTipsModel.curAttrData.packType, false);
|
itemCell.Init(cellModel);
|
|
CheckUselimit();
|
if(itemTipsModel.curAttrData.itemConfig.Effect1 != 215)
|
{
|
itemDesText.text = itemTipsModel.curAttrData.GetAllInfoDes();
|
}
|
else
|
{
|
ulong expValue = itemTipsModel.GetAddExpValue(itemTipsModel.curAttrData.itemConfig.EffectValueA1, itemTipsModel.curAttrData.itemConfig.EffectValueB1);
|
itemDesText.text = itemTipsModel.curAttrData.GetAllInfoDes().Replace("{0}", UIHelper.ReplaceLargeNum(expValue));
|
}
|
|
operateBtn.SetActive(false);
|
|
CreateFuncBtn();
|
|
if (itemTipsModel.curAttrData.itemConfig.ExpireTime > 0)
|
{
|
|
List<int> itemEffectTime = itemTipsModel.curAttrData.GetUseDataModel((int)ItemUseDataKey.Def_IudetCreateTime);
|
if (itemEffectTime != null && itemEffectTime[0] != 0 && itemTipsModel.curAttrData.guid != "")
|
{
|
RefreshRemainTime(itemTipsModel.curAttrData.guid);
|
}
|
else
|
{
|
SetDateLimitUI(itemTipsModel.curAttrData.itemConfig.ExpireTime);
|
}
|
|
}
|
else
|
{
|
dateText.gameObject.SetActive(false);
|
}
|
|
switch (itemTipsModel.curAttrData.itemConfig.Type)
|
{
|
case 125:
|
bgObj.anchoredPosition3D = new Vector3(197,0,0);
|
modelShow.gameObject.SetActive(true);
|
PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemTipsModel.curAttrData.itemConfig.EffectValueA1];
|
petSkillDict = itemTipsModel.GetPetSkillDict(itemTipsModel.curAttrData.itemConfig.EffectValueA1);
|
modelShow.SetModelShow(petInfo.ID, ModelShowType.pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower);
|
break;
|
case 124:
|
bgObj.anchoredPosition3D = new Vector3(197, 0, 0);
|
modelShow.gameObject.SetActive(true);
|
HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemTipsModel.curAttrData.itemConfig.EffectValueA1];
|
mountSkillDict = itemTipsModel.GetMountSkillDict(itemTipsModel.curAttrData.itemConfig.EffectValueA1);
|
modelShow.SetModelShow(horseConfig.Model, ModelShowType.mount, Language.Get("TreasureEffect103"), horseConfig.ShowFightPower);
|
break;
|
default:
|
modelShow.gameObject.SetActive(false);
|
bgObj.anchoredPosition3D = Vector3.zero;
|
break;
|
}
|
}
|
|
private void CheckUselimit()
|
{
|
int[] uselimits = itemTipsModel.curAttrData.itemConfig.UseCondiType;
|
if (uselimits == null) return;
|
|
conditionText.gameObject.SetActive(false);
|
needLvText.gameObject.SetActive(false);
|
realmTitleText.gameObject.SetActive(false);
|
realmImg.gameObject.SetActive(false);
|
|
for (int i = 0; i < uselimits.Length; i++)
|
{
|
switch(uselimits[i])
|
{
|
case 0:
|
if (itemTipsModel.curAttrData.itemConfig.UseLV > 1)
|
{
|
conditionText.gameObject.SetActive(true);
|
needLvText.gameObject.SetActive(true);
|
}
|
conditionText.text = Language.Get("KnapS110");
|
needLvText.text = itemTipsModel.curAttrData.itemConfig.UseLV.ToString();
|
|
if (PlayerDatas.Instance.baseData.LV >= itemTipsModel.curAttrData.itemConfig.UseLV)
|
{
|
conditionText.color = conditionColor;
|
needLvText.color = conditionColor;
|
}
|
else
|
{
|
conditionText.color = conditionRedColor;
|
needLvText.color = conditionRedColor;
|
}
|
|
break;
|
case 1:
|
realmTitleText.gameObject.SetActive(true);
|
realmImg.gameObject.SetActive(true);
|
realmTitleText.text = Language.Get("RealmLimit1");
|
RealmConfig realmConfig = ConfigManager.Instance.GetTemplate<RealmConfig>(itemTipsModel.curAttrData.itemConfig.RealmLimit);
|
if(itemTipsModel.curAttrData.itemConfig.RealmLimit <= 0)
|
{
|
realmImg.SetSprite("NoRealm");
|
}
|
else
|
{
|
if(realmConfig != null)
|
{
|
realmImg.SetSprite(realmConfig.Img);
|
}
|
}
|
|
if (PlayerDatas.Instance.baseData.realmLevel >= itemTipsModel.curAttrData.itemConfig.RealmLimit)
|
{
|
realmTitleText.color = conditionColor;
|
}
|
else
|
{
|
realmTitleText.color = conditionRedColor;
|
}
|
break;
|
case 2:
|
break;
|
}
|
}
|
|
}
|
|
private void RefreshUseCnt(int id)
|
{
|
if (itemTipsModel.curAttrData == null || id != itemTipsModel.curAttrData.itemId)
|
return;
|
|
int useCnt = playerPack.GetDayUseCntByID(itemTipsModel.curAttrData.itemId);
|
if (itemTipsModel.curAttrData.itemConfig.MaxSkillCnt > 0)
|
{
|
promptText.text = Language.Get("BoxUseCntTip", StringUtility.Contact(useCnt, "/", itemTipsModel.curAttrData.itemConfig.MaxSkillCnt));
|
}
|
}
|
|
private void RefreshRemainTime(string guid)
|
{
|
if (UIHelper.ServerStringTrim(guid) != itemTipsModel.curAttrData.guid)
|
{
|
return;
|
}
|
ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(guid);
|
if (cool != null)
|
{
|
SetDateLimitUI(cool.GetRemainTime());
|
}
|
else
|
{
|
SetDateLimitUI(0);
|
}
|
}
|
|
private void SetDateLimitUI(double time)
|
{
|
dateText.gameObject.SetActive(true);
|
TimeSpan t = TimeSpan.FromSeconds(time);
|
if (t.TotalDays > 1)
|
{
|
dateText.text = Language.Get("EquipInfo_OverdueDay", (int)t.TotalDays);
|
}
|
else if (t.TotalHours > 1)
|
{
|
dateText.text = Language.Get("EquipInfo_OverdueHour", (int)t.TotalHours);
|
}
|
else if (t.TotalMinutes > 1)
|
{
|
dateText.text = Language.Get("EquipInfo_OverdueMin", (int)t.TotalMinutes);
|
}
|
else if (t.TotalMinutes > 0)
|
{
|
dateText.text = Language.Get("EquipInfo_OverdueMin", 1);
|
}
|
else if (t.TotalSeconds <= 0)
|
{
|
dateText.text = Language.Get("EquipInfo_Overdued");
|
}
|
}
|
|
IEnumerator SetScrollSize()
|
{
|
yield return null;
|
yield return null;
|
itemDesContent.anchoredPosition3D = new Vector3(itemDesContent.anchoredPosition3D.x, 0, 0);
|
SetMidUIHeight(itemDesContent.rect.height);
|
StartCoroutine(ShowBottomPart());
|
}
|
|
IEnumerator ShowBottomPart()
|
{
|
yield return null;
|
int useCnt = playerPack.GetDayUseCntByID(itemTipsModel.curAttrData.itemId);
|
if (itemTipsModel.curAttrData.itemConfig.MaxSkillCnt > 0)
|
{
|
promptText.gameObject.SetActive(true);
|
promptText.text = Language.Get("BoxUseCntTip", StringUtility.Contact(useCnt, "/", itemTipsModel.curAttrData.itemConfig.MaxSkillCnt));
|
}
|
else
|
{
|
promptText.gameObject.SetActive(false);
|
}
|
bottomPart.gameObject.SetActive(true);
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
//itemTipsModel.SetCommonTipPos(bgObj);
|
//this.transform.localScale = Vector3.one;
|
tipAlpha.alpha = 1;
|
}
|
|
private void SetMidUIHeight(float midHeight)
|
{
|
scrollRect.enabled = false;
|
|
if (midHeight < itemTipsModel.equipMidHeights[0])
|
{
|
scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[0];
|
}
|
else if (midHeight > itemTipsModel.equipMidHeights[1])
|
{
|
scrollRect.enabled = true;
|
scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[1];
|
}
|
else
|
{
|
scrollLayout.preferredHeight = midHeight;
|
}
|
}
|
|
private void CreateFuncBtn()
|
{
|
btnGroup.anchoredPosition3D = Vector3.zero;
|
if (itemTipsModel.curAttrData.tipsFuncBtnDic.Count > 0)
|
{
|
foreach (ItemWinBtnType key in itemTipsModel.curAttrData.tipsFuncBtnDic.Keys)
|
{
|
Button btn = OnGUIButton(btnGroup.gameObject, operateBtn, key.ToString(), Language.Get(StringUtility.Contact("ItemHandle_", key.ToString())));
|
btn.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
CloseWin();
|
itemTipsModel.curAttrData.tipsFuncBtnDic[key](key, "");
|
});
|
}
|
}
|
}
|
|
private Button OnGUIButton(GameObject parent, GameObject sourceBtn, string btnName, string textName)
|
{
|
GameObject go = Instantiate(sourceBtn);
|
go.name = btnName;
|
go.transform.SetParent(parent.transform);
|
go.transform.Find("BtnText").GetComponent<Text>().text = textName;
|
go.transform.localPosition = Vector3.zero;
|
go.transform.localScale = Vector3.one;
|
Button btn = go.GetComponent<Button>();
|
go.SetActive(true);
|
tempObjlist.Add(go);
|
return btn;
|
}
|
|
private void CloseWin()
|
{
|
CloseImmediately();
|
}
|
}
|
}
|