Files
JJBB/Assets/Project/Script/GUI/Childs/ChildStudyPanel.cs

423 lines
14 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using GCGame.Table;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChildStudyPanel : MonoBehaviour, ChildRefreshInterface, SyncSingleChildInterface{
public static ChildStudyPanel Instance;
void Awake()
{
Instance = this;
}
private void OnDestroy()
{
Instance = null;
}
private void OnEnable()
{
UIManager.ShowUI(UIInfo.MoneyInfoPanel);
RefreshChildData();
}
private void OnDisable()
{
_CurSelectSkillType = -1;
UIManager.CloseUI(UIInfo.MoneyInfoPanel);
}
public List<ChildHeadIcon> _ChildSelectItemList;
public ChildSkillPanel _ChildSkillPanel;
public Text _SkillName;
public Text _SkillDesc;
//孩子当前学习状态
public GameObject _ChildStatePanel;
public Text _ChildStateDescText;
public RemainTimeCoroutine _ChildStateRemainTimeText;
//模型
public ChildModelAndEffectCtr _ModelEffectCtr;
//技能进度
public Slider _SkillExpSlider;
public Text _SkillProgressText;
//描述
public Text _CurLevelSkillDesc;
public Text _NextLevelSkillDesc;
public Text _LearnConditionDesc;
public Text _StudyExp;
public Text _ChildStudyExp;
public Text _StudyCostDesc;
//满级须屏蔽
public GameObject _NextLevelTitleObj;
public GameObject _NextLevelDescObj;
public GameObject _StudyCostObj;
public GameObject _ItemPanel;
public GameObject _HideObj;
public GameObject _ItemBtn;
public GameObject _ItemLearnBtn;
public List<CommonItem_Base> _ItemList;
public GameObject _SliderPanel;
public GameObject _OperationPanel;
//技能升级道具
public void OnSkillCommonItem()
{
foreach(var tab in TableManager.GetChildrenSkillParam())
{
if(tab.Value.Type == _CurSelectSkillType)
{
List<int> _ItemIdList = new List<int>();
for (int index = 0; index < tab.Value.getLevelUpItemIdCount(); index++)
{
var itemId = tab.Value.GetLevelUpItemIdbyIndex(index);
if (itemId != -1)
_ItemIdList.Add(itemId);
}
ChildItemCtrBase.ShowItemBase(_ItemIdList);
break;
}
}
}
public void OnSkillLearnBtn()
{
if (ChildData.GetChildByIndex(_CurSelectChildIndex) == null)
{
Debug.LogError("Child is null");
return;
}
var studyTab = TableManager.GetChildrenStudyLevelUpByID(_CurSelectStudyId, 0);
if (studyTab == null)
{
Debug.LogError("studyTab is null : " + _CurSelectStudyId);
return;
}
if(studyTab.MoneyType != -1 && studyTab.MoneyVal > 0)
{
if (!JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE)studyTab.MoneyType, studyTab.MoneyVal))
return;
}
List<CStdyCItem> itemList = new List<CStdyCItem>();
for(int index = 0; index < studyTab.getItemIdCount(); index++)
{
if(studyTab.GetItemIdbyIndex(index) != -1 && studyTab.GetItemValbyIndex(index) > 0)
{
CStdyCItem item = new CStdyCItem();
item.itemid = studyTab.GetItemIdbyIndex(index);
item.num = studyTab.GetItemValbyIndex(index);
itemList.Add(item);
}
}
//客户端要慢一分钟
if((ChildData.GetChildByIndex(_CurSelectChildIndex).study.studyingEndtime + 60) > GlobalData.ServerAnsiTime)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{86822}"));
return;
}
ReqChildrenStudy req = new ReqChildrenStudy();
req.childrenGuid = ChildData.GetChildByIndex(_CurSelectChildIndex).guid;
req.costMoneyType = studyTab.MoneyType;
req.costMoneyNum = studyTab.MoneyVal;
req.type = _CurSelectSkillType;
req.list = itemList;
req.endTime = ChildData.GetChildByIndex(_CurSelectChildIndex).study.studyingEndtime;
req.SendMsg();
}
private int _CurSelectSkillType = -1;
private int _CurSelectStudyId = -1;
public void OnSkillItemBtn(int studyId)
{
_CurSelectStudyId = studyId;
var studyTab = TableManager.GetChildrenStudyLevelUpByID(studyId, 0);
if(studyTab == null)
{
Debug.LogError("studyTab is null : " + studyId);
return;
}
_CurSelectSkillType = studyTab.StudyType;
InitSkillDesc(studyTab);
RefreshSkillProgress();
}
void RefreshSkillProgress()
{
var studyTab = TableManager.GetChildrenStudyLevelUpByID(_CurSelectStudyId, 0);
if (studyTab == null)
{
Debug.LogError("studyTab is null : " + _CurSelectStudyId);
return;
}
var childData = ChildData.GetChildByIndex(_CurSelectChildIndex);
var curExp = 0;
if(childData != null)
{
switch (studyTab.StudyType)
{
case 1:
{
curExp = childData.study.curExpMath;
}
break;
case 2:
{
curExp = childData.study.curExpArt;
}
break;
case 3:
{
curExp = childData.study.curExpWarcraft;
}
break;
case 4:
{
curExp = childData.study.curExpStamina;
}
break;
default:
{
Debug.LogError("No skill data");
curExp = 0;
}
break;
}
_SkillExpSlider.value = (float)curExp / (float)studyTab.ExpNeed;
_SkillProgressText.EnsureVal(curExp + "/" + studyTab.ExpNeed);
}
}
//显示技能描述详情
private void InitSkillDesc(Tab_ChildrenStudyLevelUp studyTab)
{
_SkillName.text = studyTab.SkillName;
_CurLevelSkillDesc.text = StrDictionary.GetClientDictionaryString("#{" + studyTab.DescStrId + "}");
var nextLevelTab = GetNextLevelStudyTab(studyTab);
if (nextLevelTab == null)
{
_NextLevelTitleObj.SetActive(false);
_NextLevelDescObj.SetActive(false);
_StudyCostObj.SetActive(false);
_ItemLearnBtn.SetActive(false);
_ItemBtn.SetActive(false);
_ItemPanel.SetActive(false);
_SliderPanel.SetActive(false);
_HideObj.SetActive(false);
}
else
{
_NextLevelTitleObj.SetActive(true);
_NextLevelDescObj.SetActive(true);
_StudyCostObj.SetActive(true);
_ItemLearnBtn.SetActive(true);
_ItemBtn.SetActive(true);
_ItemPanel.SetActive(true);
_SliderPanel.SetActive(true);
_HideObj.SetActive(true);
_NextLevelSkillDesc.text = StrDictionary.GetClientDictionaryString("#{" + nextLevelTab.DescStrId + "}");
_StudyCostDesc.text = studyTab.MoneyType == -1 ? "" : studyTab.MoneyVal + GCGame.Utils.GetMoneyName(studyTab.MoneyType);
var childLevelUpTab = TableManager.GetChildrenLevelUpByID(studyTab.LevelLimit, 0);
if(childLevelUpTab != null)
{
var childStateTypeTab = TableManager.GetChildrenStateTypeByID(childLevelUpTab.CurStateType, 0);
_LearnConditionDesc.text = StrDictionary.GetClientDictionaryString("#{86821}", childStateTypeTab.StateDesc);
}
else
{
Debug.LogError("childLevelUpTab is null : " + studyTab.LevelLimit);
}
var childLevel = ChildData.GetChildByIndex(_CurSelectChildIndex).basic.curLevel;
_StudyExp.text = TableManager.GetChildrenLevelUpByID(childLevel, 0) == null ? "0" : (TableManager.GetChildrenLevelUpByID(childLevel, 0).SkillExpByClass + "");
_ChildStudyExp.text = TableManager.GetChildrenLevelUpByID(childLevel, 0) == null ? "0" : (TableManager.GetChildrenLevelUpByID(childLevel, 0).ExpByClass + "");
for (int index = 0; index < studyTab.getItemIdCount() && index < _ItemList.Count; index++)
{
_ItemList[index].InitItem(studyTab.GetItemIdbyIndex(index), studyTab.GetItemValbyIndex(index));
}
}
}
public void OnHelpBtn()
{
MessageHelpLogic.ShowHelpMessage(1);
}
private int _CurSelectChildIndex = -1;
public void OnChildHeadIcon(int index)
{
_CurSelectChildIndex = index;
ChildPanel.PlayeChildSoundByIndex(_CurSelectChildIndex);
_ChildSelectItemList[0].ShowMark(index == 0);
_ChildSelectItemList[1].ShowMark(index == 1);
SetCurSelectChild();
IsInitEmbyroPanel();
InitChildSkillPanel();
InitCharModel();
InitStudyState();
}
//选中当前子女
void SetCurSelectChild()
{
SelectCurChildren req = new SelectCurChildren();
req.childrenGuid = ChildData.GetChildByIndex(_CurSelectChildIndex).guid;
req.SendMsg();
}
void InitCharModel()
{
_ModelEffectCtr.ShowChild(_CurSelectChildIndex);
}
bool IsInitEmbyroPanel()
{
if (ChildData.GetChildByIndex(_CurSelectChildIndex).basic.embryoEndtime > GlobalData.ServerAnsiTime)
{
ShowOperationBtn(false);
_OperationPanel.SetActive(false);
}
else
{
ShowOperationBtn(true);
_OperationPanel.SetActive(true);
}
return ChildData.GetChildByIndex(_CurSelectChildIndex).basic.embryoEndtime > GlobalData.ServerAnsiTime;
}
public void OnEmbryoTimeEndCallBack()
{
ShowOperationBtn(true);
InitChildHeadIcon(_CurSelectChildIndex);
}
void ShowOperationBtn(bool isShow)
{
_ItemBtn.SetActive(isShow);
_ItemLearnBtn.SetActive(isShow);
}
public void RefreshChildData(RetChildren childData = null)
{
if (childData == null)
childData = ChildData.ChildPacket;
InitChildHeadIcon();
_ChildSkillPanel.gameObject.SetActive(ChildData.ChildPacket == null ? false : true);
}
void InitChildSkillPanel()
{
_ChildSkillPanel.InitSkillItem(_CurSelectChildIndex, _CurSelectSkillType != -1 ? _CurSelectSkillType : 1);
}
void InitChildHeadIcon(int childIndex = 0)
{
if(ChildData.ChildPacket == null)
{
for (int index = 0; index < _ChildSelectItemList.Count; index++)
{
_ChildSelectItemList[index].gameObject.SetActive(false);
}
return;
}
for(int index = 0; index < ChildData.ChildPacket.list.Count; index++)
{
_ChildSelectItemList[index].gameObject.SetActive(true);
_ChildSelectItemList[index].InitChildHeadIcon(ChildData.ChildPacket.list[index].basic.gender
, ChildData.GetChildByIndex(index).basic.embryoEndtime > GlobalData.ServerAnsiTime);
}
for(int index = ChildData.ChildPacket.list.Count ; index < _ChildSelectItemList.Count; index++)
{
_ChildSelectItemList[index].gameObject.SetActive(false);
}
//默认选中显示第一个
OnChildHeadIcon(childIndex);
}
void InitStudyState()
{
if (ChildData.GetChildByIndex(_CurSelectChildIndex) == null)
{
_ChildStatePanel.SetActive(false);
return;
}
if (ChildData.GetChildByIndex(_CurSelectChildIndex).study.studyingType != 0)
{
_ChildStatePanel.SetActive(true);
var strId = 86800 + ChildData.GetChildByIndex(_CurSelectChildIndex).study.studyingType - 1;
_ChildStateDescText.text = StrDictionary.GetClientDictionaryString("#{" + strId + "}");
_ChildStateRemainTimeText.StartCountTime(ChildData.GetChildByIndex(_CurSelectChildIndex).study.studyingEndtime + 60, () => {
_ChildStatePanel.SetActive(false);
});
}
else
{
_ChildStatePanel.SetActive(false);
}
}
public void RefreshSingleChild(CNode info)
{
if (info.guid == ChildData.GetChildByIndex(_CurSelectChildIndex).guid)
OnChildHeadIcon(_CurSelectChildIndex);
}
//获取当前类型技能最大等级
private int _CurTypeMaxLevel = 0;
private int GetCurTypeMaxLevel(int type)
{
if (_CurTypeMaxLevel > 0)
return _CurTypeMaxLevel;
var markLevel = 0;
foreach(var tab in TableManager.GetChildrenStudyLevelUp())
{
if (tab.Value.StudyType == type && tab.Value.Level >= markLevel)
{
markLevel = tab.Value.Level;
}
}
_CurTypeMaxLevel = markLevel;
return markLevel;
}
private Tab_ChildrenStudyLevelUp GetNextLevelStudyTab(Tab_ChildrenStudyLevelUp curTab)
{
var maxLevel = GetCurTypeMaxLevel(curTab.StudyType);
//已达到最大等级
if (curTab.Level >= maxLevel)
return null;
var needLevel = curTab.Level + 1;
foreach (var tab in TableManager.GetChildrenStudyLevelUp())
{
if (tab.Value.StudyType == curTab.StudyType && tab.Value.Level == needLevel)
return tab.Value;
}
return null;
}
}