备份CatanBuilding瘦身独立工程
This commit is contained in:
304
Assets/Scripts/UI/Setting/EventSignupPopupPanel_2.cs
Normal file
304
Assets/Scripts/UI/Setting/EventSignupPopupPanel_2.cs
Normal file
@@ -0,0 +1,304 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using DG.Tweening;
|
||||
using UniRx;
|
||||
using game;
|
||||
|
||||
public class EventSignupPopupPanel_2 : BasePanel
|
||||
{
|
||||
List<SignupDayItem> signupDayItems = new List<SignupDayItem>();
|
||||
Button btn_close;
|
||||
TMP_Text text_time;
|
||||
Tables tables;
|
||||
SigninData signupData;
|
||||
private TimeSpan remaining;
|
||||
Image bar;
|
||||
RewardFly rewardFly;
|
||||
RectTransform icon_done;
|
||||
GameObject effect_HomePanel;
|
||||
GameObject clickMask;
|
||||
Transform reward;
|
||||
List<SignupRewardItem> rewardItems = new List<SignupRewardItem>();
|
||||
|
||||
List<int> drops = new List<int>();
|
||||
List<MonthlySign> monthlySign;
|
||||
GameObject rewardPanel;
|
||||
Button reward_button;
|
||||
|
||||
//Button closeButton;
|
||||
//GameObject tips;
|
||||
//Image icon_1;
|
||||
//TMP_Text text_num_1;
|
||||
//Image icon_2;
|
||||
//TMP_Text text_num_2;
|
||||
//TMP_Text text_condition;
|
||||
|
||||
int curIndex;
|
||||
private void Awake()
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
monthlySign = tables.TbMonthlySign.DataList;
|
||||
signupData = GContext.container.Resolve<SigninData>();
|
||||
for (int i = 1; i < 8; i++)
|
||||
{
|
||||
signupDayItems.Add(transform.Find("root/day" + i).GetComponent<SignupDayItem>());
|
||||
}
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
text_time = transform.Find("root/text_time").GetComponent<TMP_Text>();
|
||||
|
||||
bar = transform.Find("root/bg_bar/bar").GetComponent<Image>();
|
||||
icon_done = transform.Find("root/bg_bar/icon_done").GetComponent<RectTransform>();
|
||||
effect_HomePanel = transform.Find("root/bg_bar/effect_HomePanel").gameObject;
|
||||
reward = transform.Find("root/reward");
|
||||
for (int i = 0; i < reward.childCount; i++)
|
||||
{
|
||||
rewardItems.Add(reward.GetChild(i).GetComponent<SignupRewardItem>());
|
||||
}
|
||||
|
||||
rewardPanel = transform.Find("reward").gameObject;
|
||||
reward_button = transform.Find("reward/btn_play/btn_green").GetComponent<Button>();
|
||||
//closeButton = transform.Find("closeButton").GetComponent<Button>();
|
||||
//tips = transform.Find("tips").gameObject;
|
||||
//icon_1 = tips.transform.Find("icon_1").GetComponent<Image>();
|
||||
//text_num_1 = tips.transform.Find("text_num_1").GetComponent<TMP_Text>();
|
||||
//icon_2 = tips.transform.Find("icon_2").GetComponent<Image>();
|
||||
//text_num_2 = tips.transform.Find("text_num_2").GetComponent<TMP_Text>();
|
||||
//text_condition = tips.transform.Find("text_condition").GetComponent<TMP_Text>();
|
||||
clickMask = transform.Find("clickMask").gameObject;
|
||||
rewardFly = transform.Find("RewardFly").GetComponent<RewardFly>();
|
||||
}
|
||||
protected override void Start()
|
||||
{
|
||||
//closeButton.gameObject.SetActive(false);
|
||||
//tips.SetActive(false);
|
||||
clickMask.SetActive(false);
|
||||
oldPanelName = panelName;
|
||||
base.Start();
|
||||
btn_close.onClick.AddListener(OnClose);
|
||||
reward_button.onClick.AddListener(OnClickReward);
|
||||
//closeButton.onClick.AddListener(() =>
|
||||
//{
|
||||
// tips.SetActive(false);
|
||||
// closeButton.gameObject.SetActive(false);
|
||||
//});
|
||||
int DropID;
|
||||
if (signupData.eventSignID > 0)
|
||||
{
|
||||
SignInit signInit = tables.TbSignInit.GetOrDefault(signupData.eventSignID);
|
||||
var signDayList = signInit.SignDayList;
|
||||
for (int i = 0; i < signDayList.Count; i++)
|
||||
{
|
||||
SignReward dailySign = tables.TbSignReward.GetOrDefault(signDayList[i]);
|
||||
if (dailySign != null)
|
||||
{
|
||||
DropID = dailySign.DropID;
|
||||
signupDayItems[i].ShowData(i, DropID, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < signupDayItems.Count; i++)
|
||||
{
|
||||
DailySign dailySign = tables.TbDailySign.DataList[i];
|
||||
DropID = dailySign.DropID;
|
||||
signupDayItems[i].ShowData(i, DropID, 0);
|
||||
}
|
||||
}
|
||||
DateTime now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
DateTime tomorrow = GlobalUtils.TryParseDateTime(signupData.dailySignEvent.time, now);
|
||||
remaining = tomorrow - now;
|
||||
text_time.text = ConvertTools.ConvertTime2(remaining.Days, remaining.Hours, remaining.Minutes, remaining.Seconds);
|
||||
StartCoroutine(Countdown());
|
||||
SetData();
|
||||
GContext.OnEvent<OnSignEvent>().Subscribe(OnSignEvent).AddTo(disposables);
|
||||
}
|
||||
void SetData()
|
||||
{
|
||||
for (int i = 0; i < rewardItems.Count; i++)
|
||||
{
|
||||
rewardItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
int count = monthlySign.Count;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int index = i;
|
||||
drops.Add(monthlySign[i].DropID);
|
||||
rewardItems[i].gameObject.SetActive(true);
|
||||
rewardItems[i].SetData(() => OnClickReward(index, rewardItems[index].transform.position), monthlySign[i].SignDayAccount.ToString());
|
||||
}
|
||||
|
||||
float fillAmount = GetFillAmount();
|
||||
bar.fillAmount = fillAmount;
|
||||
RefreshPanel();
|
||||
}
|
||||
void RefreshPanel()
|
||||
{
|
||||
ShowRewardPanel();
|
||||
|
||||
bar.DOKill();
|
||||
float fillAmount = GetFillAmount();
|
||||
//float timer = fillAmount - bar.fillAmount;
|
||||
//if (timer > 0.02)
|
||||
//{
|
||||
// bar.DOFillAmount(fillAmount, timer * 2);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
bar.fillAmount = fillAmount;
|
||||
}
|
||||
int count = monthlySign.Count;
|
||||
int id;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
id = monthlySign[i].SignDayAccount;
|
||||
rewardItems[i].SetReceived(signupData.monthlySignEvent.index >= id);
|
||||
}
|
||||
}
|
||||
float GetFillAmount()
|
||||
{
|
||||
float fillAmount = 1 - 0.09f;
|
||||
int doneCount = 0;
|
||||
for (int i = 0; i < monthlySign.Count; i++)
|
||||
{
|
||||
if (monthlySign[i].SignDayAccount >= signupData.monthlySignEvent.index)
|
||||
{
|
||||
fillAmount = i * 0.25f +
|
||||
((float)(signupData.monthlySignEvent.index - doneCount)
|
||||
/ (monthlySign[i].SignDayAccount - doneCount))
|
||||
* (0.25f - 0.09f);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
doneCount = monthlySign[i].SignDayAccount;
|
||||
}
|
||||
}
|
||||
return fillAmount;
|
||||
}
|
||||
async void FlyReward(List<ItemData> itemDatas)
|
||||
{
|
||||
//飞入
|
||||
CollectionItemFly collectionItemFly = new CollectionItemFly
|
||||
{
|
||||
icon = icon_done.GetComponent<Image>().sprite,
|
||||
sourcePos = signupDayItems[signupData.dailySignEvent.index - 1].icon_done.transform.position,
|
||||
destPos = icon_done.transform.position,
|
||||
scale = Vector2.one,
|
||||
isPlayOpen = true,
|
||||
isPlayClose = true,
|
||||
targetIconSize = icon_done.rect.width
|
||||
};
|
||||
rewardFly.gameObject.SetActive(true);
|
||||
await rewardFly.ShowAsync(collectionItemFly);
|
||||
effect_HomePanel.SetActive(true);
|
||||
rewardFly.gameObject.SetActive(false);
|
||||
bar.DOKill();
|
||||
float fillAmount = GetFillAmount();
|
||||
//float timer = fillAmount - bar.fillAmount;
|
||||
bar.DOFillAmount(fillAmount, 0.5f);
|
||||
await Awaiters.Seconds(0.5f);
|
||||
if (itemDatas != null && itemDatas.Count > 0)
|
||||
{
|
||||
GContext.Publish(new ShowData(itemDatas));
|
||||
GContext.Publish(new ShowData());
|
||||
}
|
||||
clickMask.SetActive(false);
|
||||
}
|
||||
|
||||
async void OnSignEvent(OnSignEvent onSignEvent)
|
||||
{
|
||||
//signupDayItems[signupData.dailySignEvent.index-1]
|
||||
clickMask.SetActive(true);
|
||||
ShowRewardPanel();
|
||||
int count = monthlySign.Count;
|
||||
int id;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
id = monthlySign[i].SignDayAccount;
|
||||
rewardItems[i].SetReceived(signupData.monthlySignEvent.index >= id);
|
||||
}
|
||||
await Awaiters.Seconds(1.5f);
|
||||
GContext.Publish(new ShowData());
|
||||
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
||||
GContext.Publish(curRewardQCount);
|
||||
if (curRewardQCount.count <= 0)
|
||||
{
|
||||
FlyReward(onSignEvent.itemDataList);
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.OnEvent<RewardPanelClose>().First().Subscribe((e) =>
|
||||
{
|
||||
FlyReward(onSignEvent.itemDataList);
|
||||
}).AddTo(disposables);
|
||||
}
|
||||
|
||||
}
|
||||
IEnumerator Countdown()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(1);
|
||||
remaining = remaining.Subtract(TimeSpan.FromSeconds(1));
|
||||
text_time.text = ConvertTools.ConvertTime2(remaining.Days, remaining.Hours, remaining.Minutes, remaining.Seconds);
|
||||
if (remaining.TotalSeconds <= 0)
|
||||
{
|
||||
signupData.EventSignEnd();
|
||||
OnClose();
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ShowRewardPanel()
|
||||
{
|
||||
var dailySignEvent = signupData.dailySignEvent;
|
||||
bool isReward = dailySignEvent.lastID != ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear && dailySignEvent.index < 7;
|
||||
rewardPanel.SetActive(isReward);
|
||||
btn_close.gameObject.SetActive(!isReward);
|
||||
}
|
||||
void OnClickReward()
|
||||
{
|
||||
if (signupData.dailySignEvent.index < signupDayItems.Count)
|
||||
{
|
||||
signupDayItems[signupData.dailySignEvent.index].OnClaimBtnClick();
|
||||
}
|
||||
}
|
||||
void OnClose()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.EventSignupPopupPanel_2);
|
||||
}
|
||||
void OnClickReward(int index, Vector3 pos)
|
||||
{
|
||||
item_sanddig_tips.Show(pos, drops[index]);
|
||||
//closeButton.gameObject.SetActive(true);
|
||||
//List<ItemData> items = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(drops[index]);
|
||||
//int id = items[0].id;
|
||||
//float count = items[0].count;
|
||||
//GContext.container.Resolve<IUIService>().SetImageSprite(icon_1, tables.GetItemIconName(id), PanelName);
|
||||
//text_num_1.text = ConvertTools.GetNumberString((int)count);
|
||||
//id = items[1].id;
|
||||
//count = items[1].count;
|
||||
//GContext.container.Resolve<IUIService>().SetImageSprite(icon_2, tables.GetItemIconName(id), PanelName);
|
||||
//text_num_2.text = ConvertTools.GetNumberString((int)count);
|
||||
|
||||
//int doneCount = monthlySign[index].SignDayAccount;
|
||||
//string str = $"{doneCount}/{doneCount} <sprite=0>";
|
||||
//if (signupData.monthlySignEvent.index < doneCount)
|
||||
//{
|
||||
// str = $"{signupData.monthlySignEvent.index}/{doneCount} <sprite=0>";
|
||||
//}
|
||||
//text_condition.text = str;
|
||||
//tips.transform.position = pos;
|
||||
//tips.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user