using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections;
|
using Snxxz.UI;
|
using System.Collections.Generic;
|
using System;
|
using System.Linq;
|
|
|
namespace Snxxz.UI
|
{
|
public class BuyPetMatInfoWin : Window
|
{
|
[SerializeField] RectTransform bgObj;
|
|
[SerializeField] ModelShowPerfab modelShow;
|
[Header("顶部UI")]
|
[SerializeField] GameObject topPart;
|
[SerializeField]Text nameText;
|
[SerializeField] List<Text> attrNamelist = new List<Text>();
|
[SerializeField] List<Text> attrValuelist = new List<Text>();
|
[SerializeField] Button closeBtn;
|
[SerializeField] RectTransform skillContent;
|
[Header("中部UI")]
|
[SerializeField] GameObject midPart;
|
[SerializeField]
|
List<PetSkillCell> skillCelllist = new List<PetSkillCell>();
|
|
[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;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
StoreModel _storeModel;
|
StoreModel m_storeModel
|
{
|
get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
|
}
|
PetModel petmodel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
|
MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
|
|
BuyItemPopModel buyItem;
|
BuyShopItemLimit shopItemLimit;
|
int canBuyCnt = 0;
|
int buyCnt = 0;
|
int curVipIndex = -1;
|
bool isVipBuy = false;
|
Dictionary<int, int> petSkillDict;
|
Dictionary<int, List<int>> mountSkillDict;
|
|
Color32 conditionColor = new Color32(255, 244, 205, 255);
|
Color32 conditionRedColor = new Color32(255, 1, 1, 255);
|
PetMatType matType = PetMatType.None;
|
|
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;
|
topPart.SetActive(false);
|
bottomPart.SetActive(false);
|
midPart.SetActive(false);
|
InitUI();
|
}
|
protected override void OnAfterOpen()
|
{
|
StartCoroutine(SetTopShow());
|
}
|
|
protected override void OnPreClose()
|
{
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void InitUI()
|
{
|
petSkillDict = null;
|
mountSkillDict = null;
|
matType = PetMatType.None;
|
if (itemTipsModel.curAttrData == null) return;
|
|
if (itemTipsModel.unlockPetDict.ContainsKey(itemTipsModel.curAttrData.itemId))
|
{
|
matType = PetMatType.Pet;
|
}
|
else if (itemTipsModel.unlockMountDict.ContainsKey(itemTipsModel.curAttrData.itemId))
|
{
|
matType = PetMatType.Mount;
|
}
|
|
SetTopUI();
|
SetMidUI();
|
skillContent.localPosition = Vector3.zero;
|
}
|
|
private void SetTopUI()
|
{
|
Dictionary<int, int> itemEffectDict = null;
|
switch (matType)
|
{
|
case PetMatType.Pet:
|
PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemTipsModel.curAttrData.itemId];
|
itemEffectDict = petmodel.GetPetAttrAddDict(petInfo.ID);
|
break;
|
case PetMatType.Mount:
|
HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemTipsModel.curAttrData.itemId];
|
itemEffectDict = mountModel.GetMountAttrAddDict(horseConfig.HorseID);
|
break;
|
}
|
|
nameText.color = UIHelper.GetUIColor(itemTipsModel.curAttrData.itemConfig.ItemColor);
|
nameText.text = itemTipsModel.curAttrData.itemConfig.ItemName;
|
|
List<int> attrIdlist = itemEffectDict.Keys.ToList();
|
for (int i = 0; i < attrNamelist.Count; i++)
|
{
|
attrNamelist[i].gameObject.SetActive(false);
|
attrValuelist[i].gameObject.SetActive(false);
|
}
|
|
int code = 0;
|
for (int i = 0; i < attrIdlist.Count; i++)
|
{
|
string attrName = "";
|
string attrValue = "";
|
string minAtkName = "";
|
string minAtkValue = "";
|
attrNamelist[code].gameObject.SetActive(true);
|
attrValuelist[code].gameObject.SetActive(true);
|
switch ((PropertyType)attrIdlist[i])
|
{
|
case PropertyType.MinAtk:
|
break;
|
case PropertyType.PetMinAtk:
|
break;
|
case PropertyType.PetMaxAtk:
|
case PropertyType.MaxAtk:
|
itemTipsModel.SetPetAttrStr(attrIdlist[i - 1], itemEffectDict[attrIdlist[i - 1]], out minAtkName, out minAtkValue);
|
itemTipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue, minAtkValue);
|
code += 1;
|
break;
|
default:
|
itemTipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue);
|
code += 1;
|
break;
|
}
|
|
if (code > 0)
|
{
|
attrNamelist[code - 1].text = UIHelper.GetSuitNameByName(attrName);
|
attrValuelist[code - 1].text = attrValue;
|
}
|
}
|
}
|
|
private void SetMidUI()
|
{
|
switch (matType)
|
{
|
case PetMatType.Pet:
|
PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemTipsModel.curAttrData.itemId];
|
petSkillDict = itemTipsModel.GetPetSkillDict(itemTipsModel.curAttrData.itemId);
|
modelShow.SetModelShow(petInfo.ID, ModelShowType.pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower);
|
break;
|
case PetMatType.Mount:
|
HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemTipsModel.curAttrData.itemId];
|
mountSkillDict = itemTipsModel.GetMountSkillDict(itemTipsModel.curAttrData.itemId);
|
modelShow.SetModelShow(horseConfig.Model, ModelShowType.mount, Language.Get("TreasureEffect103"), horseConfig.ShowFightPower);
|
break;
|
}
|
|
List<int> unlockLvlist = null;
|
if (petSkillDict != null)
|
{
|
unlockLvlist = petSkillDict.Keys.ToList();
|
}
|
else if (mountSkillDict != null)
|
{
|
unlockLvlist = mountSkillDict.Keys.ToList();
|
}
|
|
for (int i = 0; i < skillCelllist.Count; i++)
|
{
|
skillCelllist[i].gameObject.SetActive(false);
|
}
|
|
int code = 0;
|
for (int i = 0; i < unlockLvlist.Count; i++)
|
{
|
if (petSkillDict != null)
|
{
|
skillCelllist[code].gameObject.SetActive(true);
|
skillCelllist[code].SetModel(petSkillDict[unlockLvlist[i]], unlockLvlist[i]);
|
code += 1;
|
}
|
else if (mountSkillDict != null)
|
{
|
for (int j = 0; j < mountSkillDict[unlockLvlist[i]].Count; j++)
|
{
|
skillCelllist[code].gameObject.SetActive(true);
|
skillCelllist[code].SetModel(mountSkillDict[unlockLvlist[i]][j], unlockLvlist[i]);
|
code += 1;
|
}
|
}
|
}
|
}
|
|
IEnumerator SetTopShow()
|
{
|
yield return null;
|
topPart.SetActive(true);
|
StartCoroutine(SetMidShow());
|
}
|
|
IEnumerator SetMidShow()
|
{
|
yield return null;
|
midPart.SetActive(true);
|
StartCoroutine(ShowBottomPart());
|
}
|
|
IEnumerator ShowBottomPart()
|
{
|
yield return null;
|
SetBottomUI();
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
tipAlpha.alpha = 1;
|
}
|
|
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)
|
{
|
int unionLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
|
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:
|
if(unionLv < buyItem.storeConfig.LimitValue)
|
{
|
buyBtn.gameObject.SetActive(false);
|
}
|
break;
|
case StoreFunc.MountStoneStore:
|
if (unionLv < buyItem.storeConfig.LimitValue)
|
{
|
buyBtn.gameObject.SetActive(false);
|
}
|
break;
|
case StoreFunc.MountSkillBookStore:
|
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()
|
{
|
buyCnt += 1;
|
bool isReachUpper = false;
|
buyCnt = buyItem.GetCurBuyCnt(buyCnt, buyItem.GetRemainBuyCnt(canBuyCnt, shopItemLimit, isVipBuy), out isReachUpper);
|
buyCountText.text = buyCnt.ToString();
|
RefreshBuyPrice(buyCnt);
|
if (isReachUpper)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("StoreWin109"));
|
}
|
}
|
|
private void OnClickReduceBuyNum()
|
{
|
buyCnt -= 1;
|
bool isReachUpper = false;
|
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
|
}
|
}
|