using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections;
|
using Snxxz.UI;
|
using System.Collections.Generic;
|
using System;
|
|
|
namespace Snxxz.UI
|
{
|
public class BuyItemInfoWin : 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]
|
RectTransform numberGo;
|
|
[SerializeField]
|
Text vipInfoText;
|
|
[SerializeField]
|
Text buyCountText;
|
|
[SerializeField]
|
Text buyPriceText;
|
|
[SerializeField]
|
RectTransform moneyRect;
|
|
[SerializeField]
|
Image moneyIcon;
|
|
[SerializeField]
|
Button reduceBtn;
|
|
[SerializeField]
|
Button plusBtn;
|
|
[SerializeField]
|
Button buyCountBtn;
|
|
[SerializeField]
|
Button buyBtn;
|
|
[SerializeField] Text buyBtnText;
|
|
[SerializeField]
|
NumKeyBoard numKeyboard;
|
|
[SerializeField]
|
CanvasGroup tipAlpha;
|
|
ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
StoreModel m_storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
BuyItemPopModel buyItem;
|
BuyShopItemLimit shopItemLimit;
|
int canBuyCnt = 0;
|
int buyCnt = 0;
|
int curVipIndex = -1;
|
bool isVipBuy = false;
|
|
Color32 conditionColor = new Color32(255, 244, 205, 255);
|
Color32 conditionRedColor = new Color32(255, 1, 1, 255);
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(OnClickCloseBtn);
|
buyBtn.AddListener(OnClickBuyBtn);
|
reduceBtn.onClick.AddListener(OnClickReduceBuyNum);
|
plusBtn.onClick.AddListener(OnClickPlusBuyNum);
|
buyCountBtn.onClick.AddListener(OnClickCountBtn);
|
numKeyboard.onConfirm.AddListener(OnClickConfirmBtn);
|
numKeyboard.onValueChange.AddListener(OnClickNum);
|
}
|
protected override void OnPreOpen()
|
{
|
buyItem = BuyItemPopModel.Instance;
|
shopItemLimit = m_storeModel.GetBuyShopLimit((uint)buyItem.storeConfig.ID);
|
tipAlpha.alpha = 0;
|
bottomPart.SetActive(false);
|
InitUI();
|
}
|
protected override void OnAfterOpen()
|
{
|
StartCoroutine(SetScrollSize());
|
}
|
|
protected override void OnPreClose()
|
{
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void InitUI()
|
{
|
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.guid, itemTipsModel.curAttrData.packType, false);
|
itemCell.Init(cellModel);
|
|
CheckUselimit();
|
|
string infoDes = itemTipsModel.curAttrData.GetAllInfoDes();
|
if (infoDes.Contains("{Exp}"))
|
{
|
ulong expValue = itemTipsModel.GetAddExpValue(itemTipsModel.curAttrData.itemConfig.EffectValueA1, itemTipsModel.curAttrData.itemConfig.EffectValueB1);
|
infoDes = infoDes.Replace("{Exp}", UIHelper.ReplaceLargeNum(expValue));
|
}
|
if (infoDes.Contains("{FightPower}"))
|
{
|
int fightPower = 0;
|
itemTipsModel.TryGetFightPowerByItemId(itemTipsModel.curAttrData.itemId, out fightPower);
|
infoDes = infoDes.Replace("{FightPower}", fightPower.ToString());
|
}
|
if (infoDes.Contains("{ShareNum}"))
|
{
|
string shareNumDes = itemTipsModel.GetShareNumItemDes(itemTipsModel.curAttrData.itemId);
|
infoDes = infoDes.Replace("{ShareNum}", shareNumDes);
|
}
|
itemDesText.text = infoDes;
|
|
if (itemTipsModel.curAttrData.itemConfig.ExpireTime > 0)
|
{
|
SetDateLimitUI(itemTipsModel.curAttrData.itemConfig.ExpireTime);
|
}
|
else
|
{
|
dateText.gameObject.SetActive(false);
|
}
|
}
|
|
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 = RealmConfig.Get(itemTipsModel.curAttrData.itemConfig.RealmLimit);
|
if (itemTipsModel.curAttrData.itemConfig.RealmLimit <= 0)
|
{
|
realmImg.SetSprite("NoRealm");
|
}
|
else
|
{
|
if (realmConfig != null)
|
{
|
realmImg.SetSprite(realmConfig.Img);
|
}
|
}
|
realmImg.SetNativeSize();
|
|
if (PlayerDatas.Instance.baseData.realmLevel >= itemTipsModel.curAttrData.itemConfig.RealmLimit)
|
{
|
realmTitleText.color = conditionColor;
|
}
|
else
|
{
|
realmTitleText.color = conditionRedColor;
|
}
|
break;
|
case 2:
|
break;
|
}
|
}
|
|
}
|
|
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;
|
SetBottomUI();
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
yield return null;
|
//itemTipsModel.SetCommonTipPos(bgObj);
|
bgObj.localPosition = Vector3.zero;
|
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 SetBottomUI()
|
{
|
bottomPart.gameObject.SetActive(true);
|
numKeyboard.gameObject.SetActive(false);
|
curVipIndex = -1;
|
int nextVipIndex = -1;
|
isVipBuy = buyItem.CheckIsVipBuy(buyItem.storeConfig, out curVipIndex, out nextVipIndex);
|
canBuyCnt = 0;
|
int addBuyCnt = 0;
|
bool isLimitCnt = buyItem.CheckIsLimitBuyCnt(buyItem.storeConfig, out canBuyCnt, out addBuyCnt);
|
bool isReachUpper = false;
|
buyCnt = buyItem.GetCurBuyCnt(1, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
|
|
buyBtn.gameObject.SetActive(true);
|
|
if (isVipBuy)
|
{
|
if (nextVipIndex != -1)
|
{
|
vipInfoText.gameObject.SetActive(true);
|
vipInfoText.text = Language.Get("StoreWin108", canBuyCnt, StringUtility.Contact("V", buyItem.storeConfig.VIPLV[nextVipIndex]), addBuyCnt);
|
}
|
else
|
{
|
vipInfoText.gameObject.SetActive(false);
|
}
|
|
if (curVipIndex != -1)
|
{
|
|
}
|
else
|
{
|
buyBtn.gameObject.SetActive(false);
|
buyCnt = buyItem.GetCurBuyCnt(0, canBuyCnt, out isReachUpper);
|
}
|
}
|
else
|
{
|
vipInfoText.gameObject.SetActive(false);
|
}
|
|
if (buyItem.storeConfig.LimitValue != 0)
|
{
|
switch (m_storeModel.storeFuncType)
|
{
|
case StoreFunc.MysteryStore:
|
break;
|
case StoreFunc.CommonStore:
|
break;
|
case StoreFunc.GrowStrongerStore:
|
break;
|
case StoreFunc.BindStore:
|
break;
|
case StoreFunc.IntegralStore:
|
break;
|
case StoreFunc.BagStore:
|
break;
|
case StoreFunc.RuneStore:
|
break;
|
case StoreFunc.ToolStore:
|
case StoreFunc.MountStoneStore:
|
case StoreFunc.MountSkillBookStore:
|
int unionLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
|
if (unionLv < buyItem.storeConfig.LimitValue)
|
{
|
buyBtn.gameObject.SetActive(false);
|
}
|
break;
|
}
|
}
|
|
buyCountText.text = buyCnt.ToString();
|
RefreshBuyPrice(buyCnt);
|
moneyIcon.SetIconWithMoneyType(buyItem.storeConfig.MoneyType);
|
}
|
|
private ulong _price;
|
private void RefreshBuyPrice(int buyCnt)
|
{
|
if (buyCnt < 1)
|
{
|
_price = (ulong)buyItem.storeConfig.MoneyNumber;
|
}
|
else
|
{
|
_price = (ulong)buyItem.GetBuyPrice(buyItem.storeConfig, buyCnt);
|
}
|
|
if (!m_storeModel.MoneyIsEnough(buyItem.storeConfig.MoneyType, _price))
|
{
|
buyPriceText.text = UIHelper.AppendColor(TextColType.Red, _price.ToString());
|
}
|
else
|
{
|
buyPriceText.text = UIHelper.AppendColor(TextColType.Green, _price.ToString());
|
}
|
|
if (_price <= 0)
|
{
|
moneyRect.gameObject.SetActive(false);
|
buyBtnText.text = Language.Get("MailReceive");
|
}
|
else
|
{
|
buyBtnText.text = Language.Get("ItemHandle_buy");
|
moneyRect.gameObject.SetActive(true);
|
}
|
|
if (_price <= 0 || itemTipsModel.curAttrData.itemConfig.PackCount < 2)
|
{
|
numberGo.gameObject.SetActive(false);
|
|
}
|
else
|
{
|
numberGo.gameObject.SetActive(true);
|
|
}
|
|
}
|
#region 点击事件
|
|
private void OnClickCountBtn()
|
{
|
numKeyboard.gameObject.SetActive(true);
|
}
|
|
private void OnClickNum()
|
{
|
bool isReachUpper = false;
|
buyCnt = buyItem.GetCurBuyCnt(int.Parse(numKeyboard.Value), buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
|
RefreshBuyPrice(buyCnt);
|
numKeyboard.Value = buyCnt.ToString();
|
if (isReachUpper)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
|
}
|
}
|
|
private void OnClickConfirmBtn(bool arg0)
|
{
|
if (arg0)
|
{
|
buyCountText.text = buyCnt.ToString();
|
numKeyboard.gameObject.SetActive(false);
|
}
|
}
|
|
private void OnClickPlusBuyNum()
|
{
|
bool isReachUpper = false;
|
buyCnt += 1;
|
buyCnt = buyItem.GetCurBuyCnt(buyCnt, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
|
buyCountText.text = buyCnt.ToString();
|
RefreshBuyPrice(buyCnt);
|
if (isReachUpper || buyCnt == 0)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
|
}
|
}
|
|
private void OnClickReduceBuyNum()
|
{
|
bool isReachUpper = false;
|
buyCnt -= 1;
|
buyCnt = buyItem.GetCurBuyCnt(buyCnt, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
|
buyCountText.text = buyCnt.ToString();
|
RefreshBuyPrice(buyCnt);
|
}
|
|
private void OnClickBuyBtn()
|
{
|
if (shopItemLimit != null)
|
{
|
int remainNum = 0;
|
if (isVipBuy)
|
{
|
remainNum = buyItem.storeConfig.PurchaseNumber[curVipIndex] - shopItemLimit.BuyCnt;
|
}
|
else
|
{
|
remainNum = buyItem.storeConfig.PurchaseNumber[0] - shopItemLimit.BuyCnt;
|
}
|
if (remainNum < 1)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
|
return;
|
}
|
|
}
|
m_storeModel.SendBuyShopItem(buyItem.storeConfig, buyCnt);
|
OnClickCloseBtn();
|
}
|
|
private void OnClickCloseBtn()
|
{
|
CloseImmediately();
|
}
|
#endregion
|
}
|
}
|