using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
/// <summary>
|
/// 游戏主界面(主战斗场景)
|
/// </summary>
|
public class HomeWin : UIBase
|
{
|
|
//经验区
|
[SerializeField] Text playerLevelText;
|
[SerializeField] SmoothSlider expSlider;
|
|
//任务区
|
[SerializeField] Button taskButton; //引导或者领取任务奖励
|
[SerializeField] RichText taskText;
|
[SerializeField] Text taskNumText;
|
[SerializeField] Image awardIcon;
|
[SerializeField] Text awardCnt;
|
[SerializeField] UIEffectPlayer taskEffect;
|
|
|
//关卡
|
[SerializeField] Button bossBtn;
|
|
[SerializeField] Button changeHeroPosBtn;
|
|
[SerializeField] Button autoBtn;
|
|
|
//其他功能入口
|
[SerializeField] Button monthCardBtn;
|
|
/// <summary>
|
/// 初始化组件
|
/// </summary>
|
protected override void InitComponent()
|
{
|
taskButton.AddListener(OnClickTaskButton);
|
bossBtn.AddListener(() =>
|
{
|
UIManager.Instance.OpenWindow<MainBossEnterWin>();
|
});
|
|
changeHeroPosBtn.AddListener(() =>
|
{
|
HeroUIManager.Instance.selectTeamType = TeamType.Story;
|
UIManager.Instance.OpenWindow<HeroPosWin>();
|
});
|
|
autoBtn.AddListener(() =>
|
{
|
//测试拾取所有物品
|
var items = PackManager.Instance.GetItems(PackType.DropItem);
|
List<int> dropindexs = new List<int>();
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
if (dropindexs.Count > 5)
|
{
|
EquipModel.Instance.NotifyItemDrop(dropindexs, BattleManager.Instance.storyBattleField.battleRootNode.blueTeamNodeList[Random.Range(0, 5)].GetComponent<RectTransform>());
|
dropindexs.Clear();
|
}
|
|
dropindexs.Add(item.gridIndex);
|
}
|
if (dropindexs.Count > 0)
|
{
|
EquipModel.Instance.NotifyItemDrop(dropindexs, BattleManager.Instance.storyBattleField.battleRootNode.blueTeamNodeList[Random.Range(0, 5)].GetComponent<RectTransform>());
|
dropindexs.Clear();
|
}
|
});
|
|
|
monthCardBtn.AddListener(() =>
|
{
|
InvestModel.Instance.BuyInvest(InvestModel.monthCardType);
|
});
|
}
|
|
|
|
|
public override void Refresh()
|
{
|
UpdatePlayerInfo();
|
UpdateTask();
|
RefreshRecharge();
|
}
|
|
protected override void OnPreOpen()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh;
|
TaskManager.Instance.OnTaskUpdate += UpdateTask;
|
Refresh();
|
// var battleWin = UIManager.Instance.OpenWindow<BattleWin>();
|
// battleWin.SetBattleField(BattleManager.Instance.storyBattleField);
|
}
|
protected override void OnOpen()
|
{
|
base.OnOpen();
|
|
}
|
|
|
protected override void OnPreClose()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh;
|
TaskManager.Instance.OnTaskUpdate -= UpdateTask;
|
|
// 关闭的时候把战斗界面也给关了 虽然是在外面开的
|
UIManager.Instance.CloseWindow<BattleWin>();
|
}
|
|
void PlayerDataRefresh(PlayerDataType type)
|
{
|
switch (type)
|
{
|
case PlayerDataType.TotalExp:
|
case PlayerDataType.ExpPoint:
|
ShowExp();
|
break;
|
case PlayerDataType.LV:
|
playerLevelText.text = PlayerDatas.Instance.baseData.LV.ToString();
|
break;
|
}
|
|
|
}
|
|
void RefreshRecharge()
|
{
|
monthCardBtn.SetActive(!InvestModel.Instance.IsInvested(InvestModel.monthCardType));
|
}
|
|
/// <summary>
|
/// 更新玩家信息
|
/// </summary>
|
private void UpdatePlayerInfo()
|
{
|
playerLevelText.text = PlayerDatas.Instance.baseData.LV.ToString();
|
ShowExp();
|
|
}
|
|
void ShowExp()
|
{
|
var lvConfig = PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV);
|
expSlider.value = (float)PlayerDatas.Instance.baseData.curExp / lvConfig.EXP;
|
expSlider.Text.text = PlayerDatas.Instance.baseData.curExp + "/" + PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV).EXP;
|
}
|
|
|
void UpdateTask()
|
{
|
var task = TaskManager.Instance.mainTask;
|
if (task.TaskID == 0)
|
{
|
taskButton.SetActive(false);
|
}
|
else
|
{
|
taskButton.SetActive(true);
|
var taskConfig = TaskConfig.Get(task.TaskID);
|
taskText.text = taskConfig.TaskDescribe;
|
taskNumText.text = string.Format("({0}/{1})", task.CurValue, taskConfig.NeedValue);
|
taskNumText.color = task.CurValue >= taskConfig.NeedValue ? UIHelper.GetUIColor(TextColType.NavyYellow) : UIHelper.GetUIColor(TextColType.Red);
|
if (TaskManager.Instance.GetMainTaskState() == 2)
|
{
|
taskEffect.Play();
|
}
|
else
|
{
|
taskEffect.Stop();
|
}
|
awardIcon.SetOrgSprite(ItemConfig.Get(taskConfig.AwardItemList[0][0]).IconKey);
|
awardCnt.text = taskConfig.AwardItemList[0][1].ToString();
|
}
|
}
|
|
void OnClickTaskButton()
|
{
|
if (TaskManager.Instance.GetMainTaskState() == 2)
|
{
|
//领取任务奖励
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 66;
|
getReward.DataEx = (uint)TaskManager.Instance.mainTask.TaskID;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
else
|
{
|
//根据任务类型引导
|
}
|
}
|
}
|