280 lines
10 KiB
C#
280 lines
10 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using tysdk;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BPTaskSlot : MonoBehaviour, IComparable<BPTaskSlot>
|
|
{
|
|
Button btn_go, btn_finish;
|
|
|
|
GameObject
|
|
go_doneBtn,
|
|
go_normalBg,
|
|
go_finishBg,
|
|
go_doneBg;
|
|
// TMP_Text text_task_finish_notice;
|
|
TMP_Text
|
|
txt_expGet,
|
|
txt_progress,
|
|
text_task;
|
|
// TMP_Text text_task_finish;
|
|
|
|
Image bar;
|
|
RewardItemNew
|
|
_tokenReward,
|
|
_itemReward;
|
|
// Image p_icon_item;
|
|
// public Transform icon_done;
|
|
List<ItemData> itemDatas = new();
|
|
bool _isDailyTask;
|
|
public int TaskID;
|
|
int requiredCount;
|
|
string type;
|
|
|
|
public int State;
|
|
|
|
private void Init()
|
|
{
|
|
btn_go = transform.Find("finish_notice/btn_go/btn_green_c").GetComponent<Button>();
|
|
btn_finish = transform.Find("finish_notice/btn_finish/btn_green_c").GetComponent<Button>();
|
|
|
|
go_doneBtn = transform.Find("finish_notice/done").gameObject;
|
|
go_normalBg = transform.Find("finish_notice/bg").gameObject;
|
|
go_finishBg = transform.Find("finish_notice/bg_finish").gameObject;
|
|
go_doneBg = transform.Find("finish_notice/bg_done").gameObject;
|
|
|
|
txt_progress = transform.Find("finish_notice/btn_go/text_progress").GetComponent<TMP_Text>();
|
|
text_task = transform.Find("finish_notice/text_task").GetComponent<TMP_Text>();
|
|
bar = transform.Find("finish_notice/bg_bar/bar").GetComponent<Image>();
|
|
_tokenReward = transform.Find("finish_notice/icon_exp").GetComponent<RewardItemNew>();
|
|
_itemReward = transform.Find("reward").GetComponent<RewardItemNew>();
|
|
|
|
btn_finish.onClick.AddListener(OnClickFinish);
|
|
btn_go.onClick.AddListener(OnClickGo);
|
|
gameObject.SetActive(true);
|
|
}
|
|
public void Start()
|
|
{
|
|
//but_go.onClick.AddListener(OnClickGo);
|
|
}
|
|
public void SetData(int taskID, bool isDailyTask)
|
|
{
|
|
Init();
|
|
this.TaskID = taskID;
|
|
var tables = GContext.container.Resolve<Tables>();
|
|
|
|
var task = tables.TbBattlePassTask.Get(taskID);
|
|
itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(task.Reward);
|
|
_tokenReward.SetData(itemDatas[0]);
|
|
_itemReward.SetData(itemDatas[1], isCanClick: true, abbr: true);
|
|
_isDailyTask = isDailyTask;
|
|
requiredCount = int.Parse(task.Param[0]);
|
|
text_task.text = LocalizationMgr.GetFormatTextValue(task.Desc_l10n_key, requiredCount);
|
|
type = task.Type.ToString();
|
|
RefreshView();
|
|
}
|
|
public async System.Threading.Tasks.Task ShowReward()
|
|
{
|
|
await _itemReward.PlayClose();
|
|
OnGetReward();
|
|
await _itemReward.ParticleAttractor();
|
|
}
|
|
void RefreshView()
|
|
{
|
|
|
|
var tasks = _isDailyTask ? GContext.container.Resolve<BattlePassDataProvider>().Data.BattleTask.dic_dailyTasks : GContext.container.Resolve<BattlePassDataProvider>().Data.BattleTask.dic_weeklyTasks;
|
|
tasks.TryGetValue(TaskID, out var state);
|
|
var done = state == -1;
|
|
var normal = state < requiredCount && !done;
|
|
var finish = state >= requiredCount;
|
|
State = finish ? 0 : normal ? 1 : 2;
|
|
btn_go.transform.parent.gameObject.SetActive(normal);
|
|
btn_finish.transform.parent.gameObject.SetActive(finish);
|
|
go_doneBtn.SetActive(done);
|
|
|
|
go_normalBg.SetActive(normal);
|
|
go_finishBg.SetActive(finish);
|
|
go_doneBg.SetActive(done);
|
|
|
|
//Done
|
|
if (done)
|
|
{
|
|
_itemReward.SetReceived(true);
|
|
txt_progress.text = requiredCount + "/" + requiredCount;
|
|
bar.fillAmount = 1;
|
|
}
|
|
//Normal
|
|
else if (normal)
|
|
{
|
|
_itemReward.SetReceived(false);
|
|
txt_progress.text = state + "/" + requiredCount;
|
|
bar.fillAmount = (float)state / requiredCount;
|
|
}
|
|
//Finish
|
|
else if (finish)
|
|
{
|
|
_itemReward.SetReceived(false);
|
|
txt_progress.text = requiredCount + "/" + requiredCount;
|
|
bar.fillAmount = 1;
|
|
}
|
|
}
|
|
void OnGetReward()
|
|
{
|
|
RefreshView();
|
|
}
|
|
async void OnClickFinish()
|
|
{
|
|
var task = GContext.container.Resolve<Tables>().TbBattlePassTask.Get(TaskID);
|
|
var playerData = GContext.container.Resolve<PlayerItemData>();
|
|
var startLevel = GContext.container.Resolve<BattlePassDataProvider>().GetBPCurLevel;
|
|
itemDatas = playerData.AddItemByDrop(task.Reward, false);
|
|
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("bp_task_reward"))
|
|
{
|
|
e.AddContent("bp_level", startLevel)
|
|
.AddContent("task_type", task.Type.ToString())
|
|
.AddContent("task_id", task.TaskID)
|
|
.AddContent("item_id", itemDatas[1].id)
|
|
.AddContent("item_num", itemDatas[1].count)
|
|
.AddContent("exp", itemDatas[0].count);
|
|
if (itemDatas != null && itemDatas.Count > 0)
|
|
{
|
|
for (int i = 0; i < itemDatas.Count; i++)
|
|
{
|
|
if (itemDatas[i].id == 1001)
|
|
{
|
|
e.AddContent("reward_hook", itemDatas[i].count);
|
|
}
|
|
else if (itemDatas[i].id == 1002)
|
|
{
|
|
e.AddContent("reward_cash", itemDatas[i].count);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
#endif
|
|
|
|
GContext.container.Resolve<BattlePassDataProvider>().SetTaskDone(TaskID, _isDailyTask);
|
|
RefreshView();
|
|
_ = _itemReward.ParticleAttractor();
|
|
await _tokenReward.ParticleAttractor();
|
|
GContext.Publish(new ShowData());
|
|
GContext.Publish(new BpGetExp());
|
|
}
|
|
|
|
async void OnClickGo()
|
|
{
|
|
await Awaiters.NextFrame;
|
|
var task = GContext.container.Resolve<Tables>().TbBattlePassTask.Get(TaskID);
|
|
switch (task.Type)
|
|
{
|
|
case ConditionType.ConstructionCount:
|
|
OpenConstruction();
|
|
return;
|
|
case ConditionType.Complete1v1Count:
|
|
case ConditionType.ConsumeEnergy:
|
|
case ConditionType.OpenFishBoxCount:
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
break;
|
|
case ConditionType.LoginDays:
|
|
return;
|
|
//case ConditionType.OpenFishBoxCount:
|
|
//await UIManager.Instance.ShowUI(UITypes.FishingBoxPanel);
|
|
//break;
|
|
case ConditionType.ConusumeTicketCount:
|
|
await UIManager.Instance.ShowUI(UITypes.FishingTurntablePanel);
|
|
break;
|
|
case ConditionType.CollectFishCardCount:
|
|
case ConditionType.ConsumeDiamondCount:
|
|
await UIManager.Instance.ShowUI(UITypes.FishingShopPanel);
|
|
GContext.Publish(new LackOfResourceConfirmEvent() { state = 0 });
|
|
break;
|
|
case ConditionType.CompleteChallengeCount:
|
|
//GContext.Publish(new RestartShowHomeUIEvent());
|
|
// var FCC = GContext.container.Resolve<FishingChallengeCenter>();
|
|
var fishingChallengeManager = GContext.container.Resolve<FishingChallengeManager>();
|
|
// int curCount = fishingChallengeManager.number;
|
|
// int allCount = fishingChallengeManager.challengeMatchConfig.DailyTimes;
|
|
|
|
//TODO:LF 结束的状态
|
|
var challengeState = fishingChallengeManager.ChallengeState();
|
|
if (!fishingChallengeManager.ShouldOpen() && challengeState == 0)
|
|
{
|
|
var curTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
var timer = curTime.AddDays(1).Date - curTime;
|
|
ToastPanel.Show( LocalizationMgr.GetFormatTextValue("UI_EventChallangePanel_24", ConvertTools.ConvertTime2(timer)));
|
|
return;
|
|
}
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
if (challengeState == 0)
|
|
{
|
|
//未开始比赛
|
|
// await UIManager.Instance.ShowUI(UITypes.EventChallengeFacePopupPanel);
|
|
}
|
|
else
|
|
{
|
|
fishingChallengeManager.InChallenge();
|
|
return;
|
|
}
|
|
break;
|
|
case ConditionType.UpgradeRodTimes:
|
|
await UIManager.Instance.ShowUI(UITypes.FishingRodBagPanel);
|
|
break;
|
|
default:
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
break;
|
|
}
|
|
CloseBPPanel();
|
|
}
|
|
|
|
void CloseBPPanel()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.BattlePassPanel);
|
|
}
|
|
|
|
async void OpenConstruction()
|
|
{
|
|
var campData = GContext.container.Resolve<CampDataMM>();
|
|
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Loads(campData.AllPrefabs);
|
|
if (isCanEnter)
|
|
{
|
|
//取消自动钓鱼
|
|
//ExitAutoFishing();
|
|
GContext.Publish(new VibrationData(HapticTypes.LightImpact));
|
|
|
|
//Building.Enter();
|
|
GContext.Publish(new UnloadActToNextAct("BuildAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
|
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
}
|
|
}
|
|
|
|
public int CompareTo(BPTaskSlot slot)
|
|
{
|
|
int result = this.State.CompareTo(slot.State);
|
|
|
|
if (result == 0)
|
|
{
|
|
result = this.State.CompareTo(slot.TaskID);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|