509 lines
14 KiB
C#
509 lines
14 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using GCGame;
|
|
|
|
public class AcaciaTreePanelCtr : MonoBehaviour {
|
|
|
|
// public UICameraTexture modelCamera;
|
|
public Image _TreeIcon;
|
|
public Slider expSlider;
|
|
public Text curLevelDesc;
|
|
public Text nextLevelDesc;
|
|
public Image itemIcon;
|
|
public Image itemQuality;
|
|
public Text itemName;
|
|
public Text itemOwnValue;
|
|
|
|
public Text curAttrPerDesc;
|
|
public Text myAcaciaLevelDesc;
|
|
public Text otherAcaciaLevelDesc;
|
|
|
|
public UIImgText combatValue;
|
|
public List<Text> attrList;
|
|
public Text sliderValue;
|
|
|
|
public GameObject _GainBtn;
|
|
public GameObject btnRedTip; // 按钮上的红点提示
|
|
|
|
public GameObject _LevelUPParticle;
|
|
public GameObject _BtnClickParticle;
|
|
|
|
public List<GameObject> _TreeToParticalList;
|
|
|
|
public GameObject _TrainPanel;
|
|
|
|
public static AcaciaTreePanelCtr Instance;
|
|
private void Awake()
|
|
{
|
|
GetMaxLevel();
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
HideAllParticle();
|
|
GetLevelIncDic();
|
|
Refresh(); //初始化
|
|
ReqCurAcaciaInfo();
|
|
}
|
|
|
|
// 用于红点更新,用于确保红点更新数据完整
|
|
// 正式打开页面会重新执行一遍,待优化
|
|
public void PreInit()
|
|
{
|
|
Awake();
|
|
HideAllParticle();
|
|
GetLevelIncDic();
|
|
Refresh(); //初始化
|
|
ReqCurAcaciaInfo();
|
|
}
|
|
|
|
public void ReqCurAcaciaInfo()
|
|
{
|
|
ReqMarryAcaciaData req = new ReqMarryAcaciaData();
|
|
req.flag = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
//<等级, 提升百分比>
|
|
private Dictionary<int, int> _LevelCanIncAttrDic = new Dictionary<int, int>();
|
|
public void GetLevelIncDic()
|
|
{
|
|
var _AcaciaBaseDic = TableManager.GetAcaciaTreeBase().Values;
|
|
int _OriginInc = -1;
|
|
foreach(var acaciaBase in _AcaciaBaseDic)
|
|
{
|
|
if(acaciaBase.IncPercent > _OriginInc)
|
|
{
|
|
_OriginInc = acaciaBase.IncPercent;
|
|
if (!_LevelCanIncAttrDic.ContainsKey(acaciaBase.ID))
|
|
{
|
|
_LevelCanIncAttrDic[acaciaBase.ID] = acaciaBase.IncPercent;
|
|
}
|
|
}
|
|
}
|
|
|
|
GetMaxLevelAndInc();
|
|
}
|
|
|
|
private int _MaxIncAttrNeedLevel = -1;
|
|
private int _MaxCanIncAttrPer = -1;
|
|
public void GetMaxLevelAndInc()
|
|
{
|
|
foreach (var info in _LevelCanIncAttrDic)
|
|
{
|
|
if(info.Key > _MaxIncAttrNeedLevel)
|
|
{
|
|
_MaxIncAttrNeedLevel = info.Key;
|
|
}
|
|
|
|
if(info.Value > _MaxCanIncAttrPer)
|
|
{
|
|
_MaxCanIncAttrPer = info.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
//初始化默认值
|
|
private int curAcaciaLevel = 0;
|
|
private int itemCount = 0;
|
|
private int loverAcaciaLevel = 0;
|
|
private int itemId = -1;
|
|
private Tab_AcaciaTreeBase acaciaBase = null;
|
|
private int maxLevel = 0;
|
|
private int otherLevel = 0;
|
|
// private int curCharModelId = -1;
|
|
private int curExp = 0;
|
|
public void OnPacketReceive(RetMarryAcaciaData packet)
|
|
{
|
|
curAcaciaLevel = packet.myAcaciaLv;
|
|
itemCount = packet.curAcaciaBean;
|
|
loverAcaciaLevel = packet.partnerAcaciaLv;
|
|
curExp = packet.myAcaciaExp;
|
|
acaciaBase = TableManager.GetAcaciaTreeBaseByID(curAcaciaLevel, 0);
|
|
if(acaciaBase != null)
|
|
{
|
|
itemId = acaciaBase.ConsumeItemId;
|
|
}
|
|
|
|
Refresh();
|
|
|
|
UpdataRedTips();
|
|
}
|
|
|
|
public void RefreshPanel(RetMarryTrainAcaciaData packet)
|
|
{
|
|
if(curAcaciaLevel < packet.myAcaciaLv)
|
|
{
|
|
ShowLevelUPParticle();
|
|
}
|
|
curAcaciaLevel = packet.myAcaciaLv;
|
|
itemCount = packet.curAcaciaBean;
|
|
loverAcaciaLevel = packet.partnerAcaciaLv;
|
|
curExp = packet.myAcaciaExp;
|
|
Refresh();
|
|
}
|
|
|
|
public void ShowLevelUPParticle()
|
|
{
|
|
if(_LevelUPParticle.activeInHierarchy)
|
|
{
|
|
_LevelUPParticle.SetActive(true);
|
|
}
|
|
_LevelUPParticle.GetComponentInChildren<ParticleSystem>().Play();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
acaciaBase = TableManager.GetAcaciaTreeBaseByID(curAcaciaLevel, 0);
|
|
if (acaciaBase != null)
|
|
{
|
|
itemId = acaciaBase.ConsumeItemId;
|
|
}
|
|
InitItemAndCount();
|
|
InitSlider();
|
|
MaxLevelOpt();
|
|
//InitItemInfo();
|
|
InitLevelDesc();
|
|
InitAttrDescPanel();
|
|
InitAttrList();
|
|
InitCharModel();
|
|
}
|
|
|
|
public void MaxLevelOpt()
|
|
{
|
|
if (maxLevel == 0)
|
|
GetMaxLevel();
|
|
|
|
_TrainPanel.SetActive(curAcaciaLevel != maxLevel);
|
|
}
|
|
|
|
public void InitAttrDescPanel()
|
|
{
|
|
if(acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
myAcaciaLevelDesc.text = StrDictionary.GetClientDictionaryString("#{2162}", curAcaciaLevel);
|
|
otherAcaciaLevelDesc.text = StrDictionary.GetClientDictionaryString("#{2162}", loverAcaciaLevel);
|
|
InitAttrIncPerDesc();
|
|
}
|
|
|
|
public void InitAttrIncPerDesc()
|
|
{
|
|
//取夫妻双方最小的等级
|
|
int lowLevel = 0;
|
|
lowLevel = curAcaciaLevel < loverAcaciaLevel ? curAcaciaLevel : loverAcaciaLevel;
|
|
Tab_AcaciaTreeBase acaciaBase = TableManager.GetAcaciaTreeBaseByID(lowLevel, 0);
|
|
if(acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//达到最大值
|
|
if(lowLevel >= _MaxIncAttrNeedLevel)
|
|
{
|
|
curAttrPerDesc.text = StrDictionary.GetClientDictionaryString("#{46529}", acaciaBase.IncPercent);
|
|
}
|
|
else
|
|
{
|
|
//取第一个比当前等级大的等级
|
|
foreach(var info in _LevelCanIncAttrDic)
|
|
{
|
|
if(info.Key > lowLevel)
|
|
{
|
|
curAttrPerDesc.text = StrDictionary.GetClientDictionaryString("#{46521}", acaciaBase.IncPercent, info.Key);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void InitLevelDesc()
|
|
{
|
|
if(acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
curLevelDesc.text = acaciaBase.ID.ToString();
|
|
nextLevelDesc.text = (acaciaBase.ID + 1).ToString();
|
|
}
|
|
|
|
|
|
public void GetMaxLevel()
|
|
{
|
|
var tabDic = TableManager.GetAcaciaTreeBase().Values;
|
|
foreach (var info in tabDic)
|
|
{
|
|
if(info.ID > maxLevel)
|
|
{
|
|
maxLevel = info.ID;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void InitItemInfo()
|
|
{
|
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(itemId, 0);
|
|
if(commonItem == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
itemName.text = commonItem.Name;
|
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Icon);
|
|
if (commonItem.QualityEffect > 0)
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, itemIcon.transform);
|
|
}
|
|
else
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, itemIcon.transform);
|
|
}
|
|
|
|
itemOwnValue.text = itemCount.ToString();
|
|
_GainBtn.SetActive(itemCount <= 0);
|
|
}
|
|
|
|
public void OnGainBtnClick()
|
|
{
|
|
ItemTooltipsLogic.ShowItemTooltip(itemId, ItemTooltipsLogic.ShowType.GetPath, _GainBtn.transform.position);
|
|
}
|
|
|
|
public void InitSlider()
|
|
{
|
|
if (acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
sliderValue.text = StrDictionary.GetClientDictionaryString("#{3318}", curExp, acaciaBase.NextLevelNeedExp);
|
|
expSlider.value = (float)curExp / (float)acaciaBase.NextLevelNeedExp;
|
|
}
|
|
|
|
private int curConsumeItemId = -1;
|
|
public void InitItemAndCount()
|
|
{
|
|
if (acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(acaciaBase.ConsumeItemId, 0);
|
|
if(commonItem == null)
|
|
{
|
|
return;
|
|
}
|
|
curConsumeItemId = acaciaBase.ConsumeItemId;
|
|
itemName.text = commonItem.Name;
|
|
LoadAssetBundle.Instance.SetImageSprite(itemIcon, commonItem.Icon);
|
|
_GainBtn.SetActive(itemCount <= 0);
|
|
itemOwnValue.text = itemCount.ToString();
|
|
//设置品质
|
|
LoadAssetBundle.Instance.SetImageSprite(itemQuality, Utils.GetItemQualityFrame(commonItem.Quality));
|
|
if (commonItem.QualityEffect > 0)
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, itemIcon.transform);
|
|
}
|
|
else
|
|
{
|
|
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, itemIcon.transform);
|
|
}
|
|
|
|
}
|
|
|
|
public void OnItemClick()
|
|
{
|
|
if(curConsumeItemId == -1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ItemTooltipsLogic.ShowItemTooltip(curConsumeItemId, ItemTooltipsLogic.ShowType.Info ,itemIcon.transform.position);
|
|
}
|
|
|
|
public void InitCoupAcaciaLevel(int manLevel, int felmaleLevel)
|
|
{
|
|
myAcaciaLevelDesc.text = StrDictionary.GetClientDictionaryString("#{1166}", manLevel);
|
|
otherAcaciaLevelDesc.text = StrDictionary.GetClientDictionaryString("#{1166}", felmaleLevel);
|
|
}
|
|
|
|
private string _TreeIconPath = "";
|
|
public void InitCharModel()
|
|
{
|
|
if(acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(_TreeIconPath == acaciaBase.IconPath)
|
|
{
|
|
return;
|
|
}
|
|
_TreeIconPath = acaciaBase.IconPath;
|
|
LoadAssetBundle.Instance.SetImageSprite(_TreeIcon, _TreeIconPath, delegate (bool isSucess, GameObject obj)
|
|
{
|
|
_TreeIcon.gameObject.SetActive(true);
|
|
});
|
|
|
|
if(acaciaBase.ParticleIndex != -1)
|
|
{
|
|
if(!_TreeToParticalList[acaciaBase.ParticleIndex].activeInHierarchy)
|
|
{
|
|
_TreeToParticalList[acaciaBase.ParticleIndex].SetActive(true);
|
|
_TreeToParticalList[acaciaBase.ParticleIndex].GetComponentInChildren<ParticleSystem>().Stop();
|
|
_TreeToParticalList[acaciaBase.ParticleIndex].GetComponentInChildren<ParticleSystem>().Play();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void InitAttrList()
|
|
{
|
|
Tab_AcaciaTreeBase acaciaBase = TableManager.GetAcaciaTreeBaseByID(curAcaciaLevel, 0);
|
|
if(acaciaBase == null)
|
|
{
|
|
return;
|
|
}
|
|
combatValue.text = acaciaBase.CombatValue.ToString(); // StrDictionary.GetClientDictionaryString("#{2462}", acaciaBase.CombatValue);
|
|
for (int index = 0; index < attrList.Count; index++)
|
|
{
|
|
attrList[index].gameObject.SetActive(acaciaBase.GetAttrIdbyIndex(index) != -1);
|
|
}
|
|
|
|
for(int index = 0; index < acaciaBase.getAttrIdCount(); index++)
|
|
{
|
|
if(acaciaBase.GetAttrIdbyIndex(index) != -1)
|
|
{
|
|
attrList[index].gameObject.SetActive(true);
|
|
string attrId = "#{" + (acaciaBase.GetAttrIdbyIndex(index) + 10000) + "}";
|
|
attrList[index].text = StrDictionary.GetClientDictionaryString("#{2124}", StrDictionary.GetClientDictionaryString(attrId), acaciaBase.GetAttrValuebyIndex(index));
|
|
}else
|
|
{
|
|
attrList[index].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
//当前是结婚状态 道具大于0
|
|
public void OnTrainBtnClick()
|
|
{
|
|
if (GameManager.gameManager.m_RunningScene == 658)
|
|
{
|
|
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{79512}"));
|
|
return;
|
|
}
|
|
//1.没有结婚
|
|
if (!GameManager.gameManager.PlayerDataPool.IsMarried)
|
|
{
|
|
GUIData.AddNotifyData("#{46514}");
|
|
return;
|
|
}
|
|
|
|
//道具数量不足
|
|
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|
if(backPack.GetItemCountByDataId(curConsumeItemId) < 1)
|
|
{
|
|
GUIData.AddNotifyData("#{42696}");
|
|
return;
|
|
}
|
|
|
|
if(!_LevelUPParticle.activeInHierarchy)
|
|
{
|
|
_BtnClickParticle.SetActive(true);
|
|
_LevelUPParticle.GetComponentInChildren<ParticleSystem>().Play();
|
|
}
|
|
_BtnClickParticle.GetComponentInChildren<ParticleSystem>().Stop();
|
|
_BtnClickParticle.GetComponentInChildren<ParticleSystem>().Play();
|
|
|
|
ReqMarryTrainAcaciaData req = new ReqMarryTrainAcaciaData();
|
|
req.flag = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
HideAllParticle();
|
|
}
|
|
|
|
public void HideAllParticle()
|
|
{
|
|
_LevelUPParticle.GetComponentInChildren<ParticleSystem>().Stop();
|
|
_LevelUPParticle.SetActive(false);
|
|
|
|
_BtnClickParticle.GetComponentInChildren<ParticleSystem>().Stop();
|
|
_BtnClickParticle.SetActive(false);
|
|
}
|
|
|
|
public void UpdataRedTips(Hashtable addparam = null, Hashtable Sendparam = null)
|
|
{
|
|
if(btnRedTip != null)
|
|
{
|
|
bool isShow = HasRedPoint();
|
|
if (btnRedTip.activeSelf != isShow)
|
|
{
|
|
btnRedTip.SetActive(isShow);
|
|
}
|
|
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.AcaciaTree, isShow);
|
|
}
|
|
}
|
|
|
|
|
|
private static int _MaxLevel = 0;
|
|
|
|
public static bool HasRedPoint()
|
|
{
|
|
if (!GameManager.gameManager.PlayerDataPool.IsMarried)
|
|
return false;
|
|
|
|
int temp_curAcaciaLevel = GameManager.gameManager.PlayerDataPool.MyAcaciaData.MyAcaciaLv;
|
|
|
|
if(_MaxLevel == 0)
|
|
{
|
|
foreach (var tab in TableManager.GetAcaciaTreeBase())
|
|
_MaxLevel = _MaxLevel > tab.Key ? _MaxLevel : tab.Key;
|
|
}
|
|
|
|
if (temp_curAcaciaLevel >= _MaxLevel)
|
|
return false;
|
|
|
|
Tab_AcaciaTreeBase acaciaBase = TableManager.GetAcaciaTreeBaseByID(temp_curAcaciaLevel, 0);
|
|
if (acaciaBase == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(acaciaBase.ConsumeItemId, 0);
|
|
if (commonItem == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
int temp_curConsumeItemId = acaciaBase.ConsumeItemId;
|
|
|
|
//1.没有结婚
|
|
if (!GameManager.gameManager.PlayerDataPool.IsMarried)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//道具数量不足
|
|
Games.Item.GameItemContainer backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|
if (backPack.GetItemCountByDataId(temp_curConsumeItemId) < 1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|