using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class GuardTip : MonoBehaviour
|
{
|
#region TopUI
|
[SerializeField]
|
Button closeBtn;
|
[SerializeField]
|
GameObject putOnIcon;
|
[SerializeField]
|
Text titleText;
|
[SerializeField]
|
Text equipScoreDes;
|
[SerializeField]
|
Text equipScoreValue;
|
[SerializeField]
|
Text needLvDes;
|
[SerializeField]
|
Text needLvValue;
|
[SerializeField]
|
List<Text> needPointTextlist = new List<Text>();
|
[SerializeField]
|
List<Text> needPointNumlist = new List<Text>();
|
[SerializeField]
|
Text dateText;
|
[SerializeField]
|
ItemCell itemCell;
|
#endregion
|
|
#region MidUI
|
[SerializeField]
|
RectTransform attrContent;
|
[SerializeField]
|
ScrollRect scrollRect;
|
[SerializeField]
|
LayoutElement scrollLayout;
|
|
[SerializeField]
|
GameObject basicAttr;
|
[SerializeField]
|
Text basicTitleText;
|
[SerializeField]
|
Text basicAttrDes;
|
#endregion
|
|
#region BottomUI
|
[SerializeField]
|
GameObject bottomPart;
|
[SerializeField]
|
EquipSource equipSource;
|
#endregion
|
|
[SerializeField]
|
RectTransform btnGroup;
|
|
[SerializeField]
|
GameObject operateBtn;
|
|
[SerializeField]
|
CanvasGroup tipAlpha;
|
|
Dictionary<PropertyType, int> needPointDict = new Dictionary<PropertyType, int>();
|
|
ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
ItemAttrData itemAttrData;
|
Color32 conditionColor = new Color32(255, 244, 205, 255);
|
|
public void InitModel(ItemAttrData attrData)
|
{
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct += RefreshRemainTime;
|
itemAttrData = attrData;
|
InitUI();
|
closeBtn.AddListener(OnClickCloseBtn);
|
}
|
|
private void OnEnable()
|
{
|
bottomPart.gameObject.SetActive(false);
|
StartCoroutine(SetScrollSize());
|
}
|
|
IEnumerator SetScrollSize()
|
{
|
yield return null;
|
yield return null;
|
attrContent.anchoredPosition3D = new Vector3(attrContent.anchoredPosition3D.x, 0, 0);
|
SetMidUIHeight(attrContent.rect.height);
|
StartCoroutine(ShowBottomPart());
|
}
|
|
IEnumerator ShowBottomPart()
|
{
|
yield return null;
|
bottomPart.gameObject.SetActive(true);
|
SetBottomUI();
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
if (itemAttrData.isCompare)
|
{
|
if (itemAttrData.packType != PackType.Equip)
|
{
|
itemTipsModel.SetCurTips(this.GetComponent<RectTransform>());
|
}
|
else
|
{
|
itemTipsModel.SetCompareTips(this.GetComponent<RectTransform>());
|
}
|
}
|
else
|
{
|
itemTipsModel.SetCurTips(this.GetComponent<RectTransform>());
|
}
|
|
tipAlpha.alpha = 1;
|
}
|
|
private void InitUI()
|
{
|
#region 设置TopUI
|
titleText.text = itemTipsModel.GetItemTipsTitle(itemAttrData);
|
titleText.color = UIHelper.GetUIColor(itemAttrData.itemConfig.ItemColor);
|
ItemCellModel cellModel = new ItemCellModel(itemAttrData.itemId, itemAttrData.isPreview, (ulong)itemAttrData.count,
|
itemAttrData.guid, itemAttrData.packType, itemAttrData.isCompare, itemAttrData.useDataDict);
|
itemCell.Init(cellModel);
|
if (itemAttrData.packType == PackType.Equip)
|
{
|
putOnIcon.SetActive(true);
|
}
|
else
|
{
|
putOnIcon.SetActive(false);
|
}
|
|
equipScoreDes.text = Language.Get("EquipWin_EquipPointText_1");
|
equipScoreValue.text = itemAttrData.score.ToString();
|
RefreshNeedPointUI();
|
needLvDes.text = Language.Get("KnapS110");
|
|
if (itemAttrData.itemConfig.UseLV > 1)
|
{
|
needLvDes.gameObject.SetActive(true);
|
needLvValue.gameObject.SetActive(true);
|
}
|
else
|
{
|
needLvDes.gameObject.SetActive(false);
|
needLvValue.gameObject.SetActive(false);
|
}
|
|
if (itemAttrData.isHavePutLimit)
|
{
|
needLvValue.text = itemAttrData.itemConfig.UseLV.ToString();
|
if (PlayerDatas.Instance.baseData.LV >= itemAttrData.itemConfig.UseLV)
|
{
|
needLvDes.color = conditionColor;
|
needLvValue.color = conditionColor;
|
}
|
else
|
{
|
needLvDes.color = UIHelper.GetUIColor(TextColType.Red);
|
needLvValue.color = UIHelper.GetUIColor(TextColType.Red);
|
}
|
}
|
else
|
{
|
needLvValue.text = 1.ToString();
|
needLvDes.color = conditionColor;
|
needLvValue.color = conditionColor;
|
}
|
|
RefreshRemainTime(itemAttrData.guid);
|
#endregion
|
|
#region 设置MidUI
|
SetBasicAttrUI();
|
#endregion
|
|
#region 设置功能按钮
|
operateBtn.SetActive(false);
|
if (itemAttrData.isCompare)
|
{
|
if (itemAttrData.packType != PackType.Equip)
|
{
|
CreateFuncBtn();
|
}
|
}
|
else
|
{
|
CreateFuncBtn();
|
}
|
#endregion
|
}
|
|
private void OnDisable()
|
{
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct -= RefreshRemainTime;
|
}
|
|
private void RefreshRemainTime(string guid)
|
{
|
if (guid != itemAttrData.guid)
|
{
|
return;
|
}
|
|
var isOverdue = ItemLogicUtility.Instance.IsOverdue(guid);
|
dateText.gameObject.SetActive(!isOverdue);
|
if (!isOverdue)
|
{
|
var item = packModel.GetItemByGuid(guid);
|
SetDateLimitUI(item != null ? item.overdueSurplusTime : 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");
|
}
|
}
|
|
private void RefreshNeedPointUI()
|
{
|
needPointDict.Clear();
|
if (itemAttrData.itemConfig.LimitSTR > 0)
|
{
|
needPointDict.Add(PropertyType.POWER, itemAttrData.itemConfig.LimitSTR);
|
}
|
|
if (itemAttrData.itemConfig.LimitPHY > 0)
|
{
|
needPointDict.Add(PropertyType.AGILITY, itemAttrData.itemConfig.LimitPHY);
|
}
|
|
if (itemAttrData.itemConfig.LimitPNE > 0)
|
{
|
needPointDict.Add(PropertyType.MENTALITY, itemAttrData.itemConfig.LimitPNE);
|
}
|
|
List<PropertyType> needlist = needPointDict.Keys.ToList();
|
|
int i = 0;
|
float offset = 0;
|
for (i = 0; i < needPointTextlist.Count; i++)
|
{
|
if (i < needlist.Count)
|
{
|
needPointTextlist[i].gameObject.SetActive(true);
|
needPointNumlist[i].gameObject.SetActive(true);
|
offset = needPointDict[needlist[i]] - UIHelper.GetPropertyValue(needlist[i]);
|
switch (needlist[i])
|
{
|
case PropertyType.POWER:
|
if (itemAttrData.isHavePutLimit)
|
{
|
SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113"));
|
}
|
else
|
{
|
SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113"));
|
}
|
break;
|
case PropertyType.AGILITY:
|
if (itemAttrData.isHavePutLimit)
|
{
|
SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112"));
|
}
|
else
|
{
|
SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112"));
|
}
|
|
break;
|
case PropertyType.MENTALITY:
|
if (itemAttrData.isHavePutLimit)
|
{
|
SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111"));
|
}
|
else
|
{
|
SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111"));
|
}
|
break;
|
}
|
|
}
|
else
|
{
|
needPointTextlist[i].gameObject.SetActive(false);
|
needPointNumlist[i].gameObject.SetActive(false);
|
}
|
}
|
|
}
|
|
private void SetNeedPointUI(float needPoint, float offset, Text needPoinText, Text needPoinNum, string msg)
|
{
|
if (offset > 0)
|
{
|
needPoinNum.text = UIHelper.AppendColor(TextColType.Red, StringUtility.Contact(needPoint, Language.Get("KnapS118", offset)));
|
needPoinText.text = UIHelper.AppendColor(TextColType.Red, msg);
|
}
|
else
|
{
|
needPoinNum.color = conditionColor;
|
needPoinText.color = conditionColor;
|
needPoinNum.text = needPoint.ToString();
|
needPoinText.text = msg;
|
}
|
}
|
|
#region 设置属性UI
|
private void SetBasicAttrUI()
|
{
|
basicAttr.SetActive(true);
|
basicTitleText.text = Language.Get("RolePanel_BaseAttrText_1");
|
basicAttrDes.text = itemTipsModel.GetBasicAttr(itemAttrData);
|
}
|
|
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;
|
}
|
}
|
#endregion
|
|
private void SetBottomUI()
|
{
|
SetBottomText(equipSource);
|
}
|
|
private void SetBottomText(EquipSource source)
|
{
|
source.jobTitleText.text = Language.Get("EquipWin_JobTitleText_1");
|
source.jobText.text = itemTipsModel.GetEquipJobName(itemAttrData);
|
source.partTitleText.text = Language.Get("EquipWin_PartTitleText_1");
|
source.partText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][0];
|
source.itemDesText.text = itemAttrData.itemConfig.Description;
|
source.sourceText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][1];
|
}
|
|
private void CreateFuncBtn()
|
{
|
btnGroup.anchoredPosition3D = Vector3.zero;
|
if (itemAttrData.tipsFuncBtnDic.Count > 0)
|
{
|
foreach (ItemOperateType key in itemAttrData.tipsFuncBtnDic.Keys)
|
{
|
Button btn = OnGUIButton(btnGroup.gameObject, operateBtn, key.ToString(), Language.Get(StringUtility.Contact("ItemHandle_", key.ToString())));
|
btn.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
OnClickCloseBtn();
|
itemAttrData.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);
|
KnapSackEventMgr.Instance.SetGuardWinTempObj(go);
|
return btn;
|
}
|
|
private void OnClickCloseBtn()
|
{
|
closeBtn.onClick.RemoveAllListeners();
|
KnapSackEventMgr.Instance.HideItemPopWin();
|
}
|
|
}
|
}
|
|
|