Files
JJBB/Assets/Project/Script/GUI/Shop/SysShopPageItem.cs
2024-08-23 15:49:34 +08:00

178 lines
5.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using GCGame.Table;
using Games.Item;
using Games.GlobeDefine;
using Module.Log;
using System.Collections.Generic;
public class SysShopPageItem : UIItemSelect
{
#region
public class ShopItemInfo
{
public Tab_CommonItem TabItem;
public MONEYTYPE MoneyType;
public int Price;
public int GroupCount;
public int ItemIdxInShop;
public int LimitID;
public int LimitCount;
public int BuyCnt;
public int isNeed = 0;
public bool needShowLv = false;
}
#endregion
public Text LabelName;
public RewardItem ItemIcon;
public UICurrencyItem ItemPrice;
public Text LabelLimit;
public Image isNeedIcon;
public Text LabelLvRequire; // 物品使用需要的最小等级
public GameObject professionLimit; // 物品的使用职业限制
public ShopItemInfo _ShopItemInfo;
private GameItem m_curGameItem;
public override void Show(Hashtable hash)
{
base.Show(hash);
var shopItem = (ShopItemInfo)hash["InitObj"];
if (shopItem == _ShopItemInfo)
return;
ShowItem(shopItem);
}
public void ShowItem(ShopItemInfo shopItemInfo)
{
if (shopItemInfo == null)
{
return;
}
isNeedIcon.gameObject.SetActive(shopItemInfo.isNeed > 0);
_ShopItemInfo = shopItemInfo;
ItemPrice.ShowCurrency(_ShopItemInfo.MoneyType, _ShopItemInfo.Price);
int groupCount = _ShopItemInfo.GroupCount;
if (groupCount < 0)
{
groupCount = 1;
}
ItemIcon.SetData(_ShopItemInfo.TabItem, groupCount);
LabelName.text = _ShopItemInfo.TabItem.Name;// +"*" + groupCount.ToString();
m_curGameItem = new GameItem();
m_curGameItem.DataID = _ShopItemInfo.TabItem.Id;
if (LabelLvRequire != null)
{
// 当需要显示等级的时候,也通过遮罩显示装备是否和目前职业相匹配
if (_ShopItemInfo.needShowLv)
{
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level >= _ShopItemInfo.TabItem.MinLevelRequire)
{
LabelLvRequire.text = "<color=#0e9100>" + "Lv." + _ShopItemInfo.TabItem.MinLevelRequire.ToString() + "</color>";
}
else
{
LabelLvRequire.text = "<color=#DD3742>" + "Lv." + _ShopItemInfo.TabItem.MinLevelRequire.ToString() + "</color>";
}
if (LabelLvRequire.gameObject.activeSelf == false)
{
LabelLvRequire.gameObject.SetActive(true);
}
}
else
{
if (LabelLvRequire.gameObject.activeSelf == true)
{
LabelLvRequire.gameObject.SetActive(false);
}
}
}
if(professionLimit != null)
{
professionLimit.SetActive(false);
if (_ShopItemInfo.needShowLv)
{
int equipProfession = m_curGameItem.GetProfessionRequire();
if (equipProfession > 0)
{
int nPlayerProfession = Singleton<ObjManager>.Instance.MainPlayer.Profession;
if (((equipProfession >> nPlayerProfession) & 1) == 0)
{
professionLimit.SetActive(true);
}
}
}
}
SetLimit(shopItemInfo.BuyCnt);
}
public GameItem GetGameItem()
{
return m_curGameItem;
}
public void SetLimit(int buyCount)
{
if (LabelLimit == null)
return;
LabelLimit.gameObject.SetActive(false);
// 该函数可被服务器触发所以需要更新BuyCount;
_ShopItemInfo.BuyCnt = buyCount;
Tab_ShopItemLimit shopLimit = TableManager.GetShopItemLimitByID(_ShopItemInfo.LimitID, 0);
if(shopLimit!=null)
{
if(Singleton<ObjManager>.Instance== null || Singleton<ObjManager>.Instance.MainPlayer == null)
{
LogModule.ErrorLog("Instance is null");
return;
}
var _curVipLevel = Singleton<ObjManager>.Instance.MainPlayer.VipCost;
var limitCount = 0;
if (_curVipLevel <= 0)
{
limitCount = shopLimit.GetVipLvbyIndex(0);
}else
{
limitCount = shopLimit.GetVipLvbyIndex(_curVipLevel);
}
var remainLimitCount = limitCount - buyCount + (_ShopItemInfo.MoneyType == MONEYTYPE.MONEYTYPE_YUANBAO ? GlobalData.GetVipLimitBuyCount() : 0);
if (shopLimit.LimitType == 0)
{
LabelLimit.text = StrDictionary.GetClientDictionaryString("#{1306}") + (remainLimitCount > 0 ? remainLimitCount : 0).ToString();
}
else if(shopLimit.LimitType == 1)
{
LabelLimit.text = StrDictionary.GetClientDictionaryString("#{1307}") + (remainLimitCount > 0 ? remainLimitCount : 0).ToString();
}
else if (shopLimit.LimitType == 2)
{
LabelLimit.text = StrDictionary.GetClientDictionaryString("#{63000}") + (remainLimitCount > 0 ? remainLimitCount : 0).ToString();
}
LabelLimit.gameObject.SetActive(true);
}
}
}