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

387 lines
13 KiB
C#

using System.Collections.Generic;
using Games.LogicObj;
using GCGame;
using GCGame.Table;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Fellow;
public class PetsInfoWnd : MonoBehaviour
{
public UICameraTexture modelTexture; // 模型展示的RenderTexture
public UIContainerSelect _Container;
public UIContainerBase _AttrContainer;
public Image Qulity;
public Image Icon;
public Text Name;
public Text Level;
public Text SoulHave;
public Text HasCount;
public UIImgText Power;
public Slider ConstCount;
public Button ActivityBtn;
public Button CancleFightChangeShow;
public Button CancelHelpChangeShow;
public GameObject GetConstBtn;
public GameObject Btns;
private Dictionary<int,PetBookAddAttr.AttrInfo> m_addAttrInfos = new Dictionary<int,PetBookAddAttr.AttrInfo>();
private int Duty = 0;
private void Update()
{
if(Duty>0)
{
Duty--;
if(Duty==0)
{
PetInfoChange();
}
}
}
private void CountAttrInfo(int ProID,int ProValue,int ProCurr)
{
if (ProID < 0)
return;
PetBookAddAttr.AttrInfo attr = new PetBookAddAttr.AttrInfo();
if (m_addAttrInfos.ContainsKey(ProID))
{
attr = m_addAttrInfos[ProID];
}
attr.ProID = ProID;
attr.PropValue += ProValue;
attr.PropCurrAdd = ProCurr;
m_addAttrInfos[ProID] = attr;
}
private void AttrShow()
{
m_addAttrInfos.Clear();
Dictionary<int, Tab_FellowHandBook> handBooks = TableManager.GetFellowHandBook();
List<int> keys = new List<int>(handBooks.Keys);
PetsHoldBookInfo bookInfo = null;
for (int i=0;i<keys.Count;i++)
{
Tab_FellowHandBook handBook = handBooks[keys[i]];
if (bookInfo == null || bookInfo.PetID!=handBook.FellowID)
bookInfo = GameManager.gameManager.PlayerDataPool.FellowBookData.GetPetBookInfo(handBook.FellowID);
int level = 1;
if (bookInfo != null)
level = bookInfo.BookLevel > 0 ? bookInfo.BookLevel : 1;
if (handBook.Level== level)
{
for (int j = 0; j < handBook.getPropIdCount(); j++)
{
CountAttrInfo(handBook.GetPropIdbyIndex(j), bookInfo.BookLevel == 0 ? 0 : handBook.GetPropValbyIndex(j), 0);
}
}
}
_AttrContainer.InitContentItem(m_addAttrInfos.Values);
}
public void RespHandBookInfos()
{
Duty = 4;
}
public void OnSelectPet()
{
List<int> shows = GameManager.gameManager.PlayerDataPool.FellowBookData.GetPetBooksId();
if (shows.Count <= 0)
return;
int selId = GameManager.gameManager.PlayerDataPool.FellowBookData.GetCanSelectPetID();
if (selId == -1)
return;
List<int> selects = new List<int>();
selects.Add(selId == -1 ? shows[0] : selId);
AttrShow();
_Container.InitSelectContent(shows, selects, OnSelect);
Power.text = GameManager.gameManager.PlayerDataPool.FellowBookData.PetBookTotlePower.ToString();
}
public void PetInfoChange()
{
_Container.RefreshItems();
AttrShow();
Power.text = GameManager.gameManager.PlayerDataPool.FellowBookData.PetBookTotlePower.ToString();
if (m_currSelectBook == null || m_currSelectBook.MaxLevel || GameManager.gameManager.PlayerDataPool.FellowBookData.CostCout(m_currSelectBook, 3) <= 0)
{
PetsHoldBookInfo NextSel = null;
int selPetId = GameManager.gameManager.PlayerDataPool.FellowBookData.GetCanSelectPetID();
if (selPetId != -1)
{
NextSel = GameManager.gameManager.PlayerDataPool.FellowBookData.GetPetBookInfo(selPetId);
}
if (NextSel != null && NextSel != m_currSelectBook)
{
List<int> selects = new List<int>();
selects.Add(NextSel.PetID);
_Container.SetSelect(selects);
}
else
{
OnSelect(-1);
}
}
else
{
OnSelect(-1);
}
}
public void OnItemFresh()
{
Duty = 4;
}
private PetsHoldBookInfo m_currSelectBook;
public void OnSelect(object obj)
{
int petID = (int)obj;
PetsHoldBookInfo book = GameManager.gameManager.PlayerDataPool.FellowBookData.GetPetBookInfo(petID);
if (book != null)
{
m_currSelectBook = book;
}
if (m_currSelectBook == null)
return;
int level = m_currSelectBook.BookLevel > 0 ? m_currSelectBook.BookLevel : 1;
Tab_FellowHandBook handBook = TableManager.GetFellowHandBookByID(m_currSelectBook.PetID * 100 + level, 0);
Tab_FellowHandBook handBookNext = TableManager.GetFellowHandBookByID(m_currSelectBook.PetID * 100 + level + 1,0);
Name.text = m_currSelectBook.Name;
Level.text = StrDictionary.GetClientDictionaryString("#{46518}", m_currSelectBook.BookLevel);
ActivityBtn.gameObject.SetActive(m_currSelectBook.BookLevel <= 0);
int TurnToType = GameManager.gameManager.PlayerDataPool.FellowBookData.FightType(m_currSelectBook.PetID);
CancleFightChangeShow.gameObject.SetActive((TurnToType & 1) != 0);
CancelHelpChangeShow.gameObject.SetActive((TurnToType & 2) != 0);
LoadAssetBundle.Instance.SetImageSprite(Qulity, Utils.GetItemQualityFrame(m_currSelectBook.Quility));
LoadAssetBundle.Instance.SetImageSprite(Icon, m_currSelectBook.headIcon);
Btns.SetActive(handBookNext != null);
if(handBook!=null && m_currSelectBook.BookLevel > 0)
{
Power.text = handBook.Power.ToString();
}
else
{
Power.text = "0";
}
if (handBook!=null || handBookNext!=null)
{
modelTexture.InitModelPath("", TableManager.GetCharModelByID(handBook == null ? handBookNext.ModelId : handBook.ModelId, 0), LoadAssetBundle.BUNDLE_PATH_PET, true, delegate ()
{
modelTexture.gameObject.SetActive(true);
});
}
_AttrContainer.RefreshItems(null);
if (handBookNext != null)
{
for (int index = 0; index < handBookNext.getPropIdCount(); index++)
{
int valueAdd = 0;
if (m_currSelectBook.BookLevel <= 0 && handBook != null)
valueAdd = handBook.GetPropValbyIndex(index);
else
{
if (handBook == null)
valueAdd = handBookNext.GetPropValbyIndex(index);
else
valueAdd = (handBookNext.GetPropValbyIndex(index) - handBook.GetPropValbyIndex(index));
}
CountAttrInfo(handBookNext.GetPropIdbyIndex(index),0, valueAdd);
}
_AttrContainer.RefreshItems();
}
if (handBookNext != null)
{
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(handBookNext.ConstPetSoulID);
Tab_FellowBase tab_FellowBase = TableManager.GetFellowBaseByID(handBookNext.ConstPetSoulID, 0);
if (tab_FellowBase == null || tab_FellowBase.Quility > 3)
{
RedTipPoint.RedPointStateChange(RedTipPoint.PointType.PetBookLevel,false);
}
else
{
RedTipPoint.RedPointStateChange(RedTipPoint.PointType.PetBookLevel, hasCount > 0);
}
ConstCount.value = m_currSelectBook.Exp * 1.0f / handBookNext.ConstNum;
SoulHave.text = string.Format("{0}/{1}", m_currSelectBook.Exp * 1.0f, handBookNext.ConstNum);
HasCount.text = hasCount.ToString();
m_HasCount = hasCount;
GetConstBtn.SetActive(false);
if (handBookNext==null)
{
ConstCount.value = 1;
SoulHave.text = StrDictionary.GetClientDictionaryString("#{20162}");
}
else
{
GetConstBtn.SetActive(hasCount <= 0 );
}
}
else
{
ConstCount.value = 1;
SoulHave.text = StrDictionary.GetClientDictionaryString("#{20162}");
HasCount.text = "";
m_HasCount = 0;
GetConstBtn.SetActive(false);
RedTipPoint.RedPointStateChange(RedTipPoint.PointType.PetBookLevel, false);
}
}
private int m_HasCount;
public void Activity_Click()
{
if (m_currSelectBook == null)
return;
if(m_HasCount <= 0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#20169}"));
return;
}
if (m_currSelectBook.BookLevel<=0 && m_HasCount > 0)
{
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{20163}"),null, delegate()
{
AskActivity();
}, null);
return;
}
AskActivity();
}
private void AskActivity()
{
AskFellowPromote();
}
public void LevelUp_Click()
{
AskFellowPromote();
}
private void AskFellowPromote()
{
if (m_currSelectBook == null)
return;
ReqHandbookFellowPromote cmd = new ReqHandbookFellowPromote();
cmd.FellowId = m_currSelectBook.PetID;
cmd.SendMsg();
}
private void AskChangeShow(int type)
{
if (m_currSelectBook == null)
return;
ReqHandbookFellowChangeShow cmd = new ReqHandbookFellowChangeShow();
cmd.ChangeType = type;
cmd.FellowId = m_currSelectBook.PetID;
cmd.SendMsg();
}
public void Fight_Click()
{
if (m_currSelectBook == null)
return;
if(m_currSelectBook.BookLevel<=0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#20164}"));
return;
}
if (GameManager.gameManager.PlayerDataPool.FellowContainer.GetCalledPet() == Games.GlobeDefine.GlobeVar.INVALID_GUID)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#20165}"));
return;
}
AskChangeShow(1);
}
public void Help_Click()
{
if (m_currSelectBook == null)
return;
if (m_currSelectBook.BookLevel <= 0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#20164}"));
return;
}
if (GameManager.gameManager.PlayerDataPool.FellowContainer.GetHelpedPet() == Games.GlobeDefine.GlobeVar.INVALID_GUID)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#20166}"));
return;
}
AskChangeShow(2);
}
public void Cancel_Help()
{
ReqHandbookFellowCancelChangeShow cmd = new ReqHandbookFellowCancelChangeShow();
cmd.ChangeType = 2;
cmd.SendMsg();
}
public void Cancel_Fight()
{
ReqHandbookFellowCancelChangeShow cmd = new ReqHandbookFellowCancelChangeShow();
cmd.ChangeType = 1;
cmd.SendMsg();
}
public void GetPetTip()
{
if (m_currSelectBook == null)
return;
ItemTooltipsLogic.ShowItemTooltip(m_currSelectBook.PetID, ItemTooltipsLogic.ShowType.Info, Vector3.zero);
}
public void GetConstItem()
{
if (m_currSelectBook == null)
return;
Tab_FellowHandBook handBook = TableManager.GetFellowHandBookByID(m_currSelectBook.PetID * 100 + m_currSelectBook.BookLevel,0);
Tab_FellowHandBook handBookNext = TableManager.GetFellowHandBookByID(m_currSelectBook.PetID * 100 + m_currSelectBook.BookLevel+1, 0);
if (handBook == null)
handBook = handBookNext;
if (handBook!=null)
ItemTooltipsLogic.ShowItemTooltip(handBook.ConstPetSoulID, ItemTooltipsLogic.ShowType.GetPath, Vector3.zero);
}
private void CloneAttr(GameObject AttrObject,string proName, int proValue, int nextAdd)
{
if (AttrObject == null)
return;
AttrObject.SetActive(true);
Text[] texts = AttrObject.GetComponentsInChildren<Text>();
for(int i=0;i<texts.Length;i++)
{
if (texts[i].gameObject.name.Contains("AttrName"))
{
texts[i].text = proName;
}
if (texts[i].gameObject.name.Contains("Value"))
{
texts[i].text = proValue.ToString();
}
if (texts[i].gameObject.name.Contains("NextAdd"))
{
if(nextAdd==0)
{
texts[i].text = "";
}
else
texts[i].text = "+"+ nextAdd.ToString();
}
}
}
}