备份CatanBuilding瘦身独立工程
This commit is contained in:
82
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs
Normal file
82
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LuckyTaskBtn : MonoBehaviour, IUIRedPoint
|
||||
{
|
||||
Button btn;
|
||||
ILuckyTaskUIGetData model;
|
||||
|
||||
public string key;
|
||||
public GameObject redPoint;
|
||||
public GameObject redpoint_big;
|
||||
public TMP_Text text_redpoint_big;
|
||||
void Awake()
|
||||
{
|
||||
btn = GetComponent<Button>();
|
||||
btn.onClick.AddListener(OnClick);
|
||||
}
|
||||
public void Init(ILuckyTaskUIGetData model, string key)
|
||||
{
|
||||
this.model = model;
|
||||
this.key = key;
|
||||
SetKey();
|
||||
}
|
||||
async void OnClick()
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
GameObject taskPanelName = await UIManager.Instance.ShowUI(new UIType(model.TaskPanelName));
|
||||
if (taskPanelName != null)
|
||||
{
|
||||
var panel = taskPanelName.GetComponent<LuckyTaskPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
panel.Init(model);
|
||||
int count = RedPointManager.Instance.GetRedPointCount(key);
|
||||
RedPointManager.Instance.SetRedPointState(key, count > 0, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
RedPointManager.Instance.RemoveRedPoint(key);
|
||||
key = "";
|
||||
}
|
||||
}
|
||||
public void SetKey()
|
||||
{
|
||||
RedPointManager.Instance.AddRedPoint(key, this);
|
||||
SetRedPointState(RedPointManager.Instance.GetRedPointState(key));
|
||||
}
|
||||
|
||||
public void SetRedPointState(bool state)
|
||||
{
|
||||
int count = RedPointManager.Instance.GetRedPointCount(key);
|
||||
if (count > 1)
|
||||
{
|
||||
redpoint_big.SetActive(true);
|
||||
if (count > 99)
|
||||
{
|
||||
text_redpoint_big.text = "99+";
|
||||
}
|
||||
else
|
||||
{
|
||||
text_redpoint_big.text = count.ToString();
|
||||
}
|
||||
state = false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
redpoint_big.SetActive(false);
|
||||
}
|
||||
redPoint.SetActive(state);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b7ca70f61cc7c74fa993a291c27a535
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
107
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs
Normal file
107
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LuckyTaskItem : MonoBehaviour
|
||||
{
|
||||
public LuckyTaskItemData data { get; private set; }
|
||||
GameObject bg_cliam;
|
||||
Button btn_claim;
|
||||
GameObject bg_normal;
|
||||
Button btnGo;
|
||||
TMP_Text taskDescText;
|
||||
List<RewardItemNew> rewardItemNews = new List<RewardItemNew>();
|
||||
GameObject mask;
|
||||
Action<LuckyTaskItem> action;
|
||||
int count = 0;
|
||||
private void Awake()
|
||||
{
|
||||
bg_cliam = transform.Find("bg_cliam").gameObject;
|
||||
btn_claim = transform.Find("bg_cliam/btn_claim/btn_green_c").GetComponent<Button>();
|
||||
bg_normal = transform.Find("bg_normal").gameObject;
|
||||
btnGo = transform.Find("bg_normal/btn_go/btn_green_c").GetComponent<Button>();
|
||||
taskDescText = transform.Find("text_task").GetComponent<TMP_Text>();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var rewardItem = transform.Find($"reward{i + 1}").GetComponent<RewardItemNew>();
|
||||
if (rewardItem != null)
|
||||
{
|
||||
rewardItemNews.Add(rewardItem);
|
||||
}
|
||||
}
|
||||
mask = transform.Find("bg_done").gameObject;
|
||||
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (btnGo != null)
|
||||
{
|
||||
btnGo.onClick.AddListener(OnClick);
|
||||
}
|
||||
if (btn_claim != null)
|
||||
{
|
||||
btn_claim.onClick.AddListener(OnClick);
|
||||
}
|
||||
}
|
||||
public void Init(LuckyTaskItemData luckyTaskItemData, Action<LuckyTaskItem> action)
|
||||
{
|
||||
this.action = action;
|
||||
this.data = luckyTaskItemData;
|
||||
SetItem();
|
||||
}
|
||||
void SetItem()
|
||||
{
|
||||
Refresh();
|
||||
taskDescText.text = data.desc;
|
||||
var itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(data.reward);
|
||||
if (itemData != null)
|
||||
{
|
||||
count = itemData.Count;
|
||||
if (count > rewardItemNews.Count)
|
||||
{
|
||||
count = rewardItemNews.Count;
|
||||
Debug.LogError($"LuckyTask Reward {data.reward} > PanelItem Count");
|
||||
}
|
||||
for (int i = 0; i < rewardItemNews.Count; i++)
|
||||
{
|
||||
if (count > i)
|
||||
{
|
||||
rewardItemNews[i].gameObject.SetActive(true);
|
||||
rewardItemNews[i].SetData(itemData[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardItemNews[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Play()
|
||||
{
|
||||
data.state = -1; // 更新状态为已领取
|
||||
Refresh();
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
rewardItemNews[i].ParticleAttractor(ignorePack: true);
|
||||
}
|
||||
await rewardItemNews[0].ParticleAttractor(ignorePack: true);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
mask.SetActive(data.state == -1);
|
||||
btnGo.gameObject.SetActive(data.state == 0);
|
||||
bg_normal.gameObject.SetActive(data.state <= 0);
|
||||
bg_cliam.gameObject.SetActive(data.state == 1);
|
||||
}
|
||||
void OnClick()
|
||||
{
|
||||
action?.Invoke(this);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96c5aec112649fe43a1a1a1e2adbed53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
311
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs
Normal file
311
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs
Normal file
@@ -0,0 +1,311 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LuckyTaskPanel : MonoBehaviour
|
||||
{
|
||||
ILuckyTaskUIGetData luckyModel;
|
||||
Tables tables;
|
||||
GameObject itemPrefab;
|
||||
CanvasGroup canvasGroup;
|
||||
Transform content;
|
||||
List<LuckyTaskItem> taskItems = new List<LuckyTaskItem>();
|
||||
Dictionary<int, int> taskData;
|
||||
private void Awake()
|
||||
{
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
itemPrefab = transform.Find("root/ScrollView/Viewport/Content/item1").gameObject;
|
||||
itemPrefab.SetActive(false);
|
||||
content = transform.Find("root/ScrollView/Viewport/Content");
|
||||
}
|
||||
public void Init(ILuckyTaskUIGetData panelCallTaskData)
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
this.luckyModel = panelCallTaskData;
|
||||
taskData = luckyModel.DicTasks;
|
||||
SetItem();
|
||||
}
|
||||
public void Init(Dictionary<int, int> dicTasks)
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
taskData = dicTasks;
|
||||
SetItem();
|
||||
}
|
||||
void SetItem()
|
||||
{
|
||||
List<LuckyTaskItemData> taskList = new List<LuckyTaskItemData>();
|
||||
int level = taskData.GetValueOrDefault(-2, 0);
|
||||
foreach (var item in taskData)
|
||||
{
|
||||
if (item.Key <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CommonTask commonTask = tables.TbCommonTask.Get(item.Key);
|
||||
if (commonTask != null)
|
||||
{
|
||||
LuckyTaskItemData luckyTaskData = new LuckyTaskItemData();
|
||||
luckyTaskData.id = item.Key;
|
||||
luckyTaskData.reward = commonTask.TaskReward;
|
||||
|
||||
string desc = LocalizationMgr.GetText(commonTask.TaskDesc_l10n_key);
|
||||
string progressText;
|
||||
if (commonTask.TaskType == ConditionType.RechargeAmount)
|
||||
{
|
||||
//sku.ProdPrice
|
||||
int iapid = commonTask.TaskParam[level];
|
||||
var iap = tables.TbIAPItemList.GetOrDefault(iapid);
|
||||
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iap);
|
||||
GContext.Publish(sKUDetailDataEvent);
|
||||
desc = desc.SafeFormat(sKUDetailDataEvent.price);
|
||||
float TaskParam = iap.VIPPoint;
|
||||
float value = item.Value;
|
||||
float ratio = value / TaskParam;
|
||||
float ProdPrice = sKUDetailDataEvent.prodPrice;
|
||||
float truncatedPrice = (float)Mathf.Ceil(ratio * ProdPrice * 100) / 100;
|
||||
progressText = $"({truncatedPrice:F2}/{ProdPrice})";
|
||||
if (item.Value == -1)
|
||||
{
|
||||
progressText = $"({ProdPrice}/{ProdPrice})";
|
||||
luckyTaskData.state = -1;
|
||||
}
|
||||
else if (value >= TaskParam)
|
||||
{
|
||||
luckyTaskData.state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
luckyTaskData.state = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int taskParam = commonTask.TaskParam[level];
|
||||
progressText = $"({item.Value}/{taskParam})";
|
||||
if (item.Value == -1)
|
||||
{
|
||||
progressText = $"({taskParam}/{taskParam})";
|
||||
luckyTaskData.state = -1;
|
||||
}
|
||||
else if (item.Value >= taskParam)
|
||||
{
|
||||
luckyTaskData.state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
luckyTaskData.state = 0;
|
||||
}
|
||||
desc = desc.SafeFormat(taskParam);
|
||||
}
|
||||
luckyTaskData.desc = desc + progressText;
|
||||
taskList.Add(luckyTaskData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Task ID {item.Key} not found in CommonTask table.");
|
||||
}
|
||||
}
|
||||
taskList.Sort((a, b) => b.state.CompareTo(a.state)); // 按state排序
|
||||
for (int i = 0; i < taskList.Count; i++)
|
||||
{
|
||||
LuckyTaskItem luckyTaskItem = Instantiate(itemPrefab, content).AddComponent<LuckyTaskItem>();
|
||||
luckyTaskItem.gameObject.SetActive(true);
|
||||
luckyTaskItem.Init(taskList[i], OnClickLuckyTaskItem);
|
||||
taskItems.Add(luckyTaskItem);
|
||||
}
|
||||
}
|
||||
|
||||
public async void TaskItemPlay(LuckyTaskItem luckyTaskItem)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
try
|
||||
{
|
||||
await luckyTaskItem.Play();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError($"Error during TaskItemPlay: {ex.Message}");
|
||||
}
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
GContext.Publish(new ShowData());
|
||||
}
|
||||
|
||||
void OnClickLuckyTaskItem(LuckyTaskItem luckyTaskItem)
|
||||
{
|
||||
if (luckyModel == null)
|
||||
{
|
||||
//奖励补领
|
||||
OnClickLuckyTaskItem1(luckyTaskItem);
|
||||
return;
|
||||
}
|
||||
if (luckyTaskItem.data.state == 1)
|
||||
{
|
||||
bool result = luckyModel.OnGetTaskReward(luckyTaskItem.data.id);
|
||||
if (result)
|
||||
{
|
||||
CommonTask commonTask = tables.TbCommonTask.GetOrDefault(luckyTaskItem.data.id);
|
||||
if (commonTask != null)
|
||||
{
|
||||
// 任务奖励
|
||||
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDrop(commonTask.TaskReward, false);
|
||||
if (rewardItem != null)
|
||||
{
|
||||
TaskItemPlay(luckyTaskItem);
|
||||
}
|
||||
}
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("event_lucky_task"))
|
||||
{
|
||||
int round = luckyModel.DicTasks.GetValueOrDefault(-1, 0);
|
||||
e.AddContent("task_id", luckyTaskItem.data.id)
|
||||
.AddContent("round", round)
|
||||
.AddContent("combine_id", round * 100000 + luckyTaskItem.data.id % 10000)
|
||||
.AddContent("task_reward", commonTask.TaskReward);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("任务奖励领取失败");
|
||||
}
|
||||
}
|
||||
else if (luckyTaskItem.data.state == 0)
|
||||
{
|
||||
OnClickGo(luckyTaskItem.data.id);
|
||||
Debug.Log("任务未完成,无法领取奖励");
|
||||
}
|
||||
else if (luckyTaskItem.data.state == -1)
|
||||
{
|
||||
Debug.Log("任务已领取,无法重复领取");
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickLuckyTaskItem1(LuckyTaskItem luckyTaskItem)
|
||||
{
|
||||
if (luckyTaskItem.data.state == 1)
|
||||
{
|
||||
CommonTask commonTask = tables.TbCommonTask.GetOrDefault(luckyTaskItem.data.id);
|
||||
taskData[luckyTaskItem.data.id] = -1; // 标记为已领取
|
||||
if (commonTask != null)
|
||||
{
|
||||
// 任务奖励
|
||||
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDrop(commonTask.TaskReward, false);
|
||||
if (rewardItem != null)
|
||||
{
|
||||
TaskItemPlay(luckyTaskItem);
|
||||
}
|
||||
}
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("event_lucky_task"))
|
||||
{
|
||||
int round = luckyModel.DicTasks.GetValueOrDefault(-1, 0);
|
||||
e.AddContent("task_id", luckyTaskItem.data.id)
|
||||
.AddContent("round", round)
|
||||
.AddContent("combine_id", round * 100000 + luckyTaskItem.data.id % 10000)
|
||||
.AddContent("task_reward", commonTask.TaskReward);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
async void GetReward()
|
||||
{
|
||||
List<int> dropID = new List<int>();
|
||||
int level = taskData.GetValueOrDefault(-2, 0);
|
||||
foreach (var item in taskData)
|
||||
{
|
||||
if (item.Key > 0 && item.Value != -1)
|
||||
{
|
||||
CommonTask commonTask = tables.TbCommonTask.Get(item.Key);
|
||||
if (commonTask != null)
|
||||
{
|
||||
int taskParam = commonTask.TaskParam[level];
|
||||
if (commonTask.TaskType == ConditionType.RechargeAmount)
|
||||
{
|
||||
var iap = tables.TbIAPItemList.GetOrDefault(taskParam);
|
||||
taskParam = iap.VIPPoint;
|
||||
}
|
||||
if (item.Value >= taskParam)
|
||||
{
|
||||
dropID.Add(commonTask.TaskReward);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dropID.Count > 0)
|
||||
{
|
||||
var itemDatas = GContext.container.Resolve<PlayerItemData>().AddItemByDropList(dropID);
|
||||
GContext.Publish(new ShowData());
|
||||
await Awaiters.Seconds(0.5f);
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_COMMON_missions_refreshed"));
|
||||
}
|
||||
}
|
||||
|
||||
async void OnClickGo(int id)
|
||||
{
|
||||
await Awaiters.NextFrame;
|
||||
var task = tables.TbCommonTask.Get(id);
|
||||
switch (task.TaskType)
|
||||
{
|
||||
case ConditionType.Complete1v1Count:
|
||||
case ConditionType.ConsumeEnergy:
|
||||
GContext.Publish(new UnloadActToNextAct());
|
||||
break;
|
||||
case ConditionType.CollectFishCardCount:
|
||||
case ConditionType.ConsumeDiamondCount:
|
||||
await UIManager.Instance.ShowUI(UITypes.FishingShopPanel);
|
||||
GContext.Publish(new LackOfResourceConfirmEvent() { state = 0 });
|
||||
break;
|
||||
case ConditionType.MakeInAppPurchase:
|
||||
case ConditionType.RechargeAmount:
|
||||
int packID = luckyModel.GetLuckyPackID();
|
||||
if (packID <= 0)
|
||||
{
|
||||
Debug.LogError("Lucky Pack ID is invalid or not set.");
|
||||
return;
|
||||
}
|
||||
EventPackManager eventPackManager = tables.TbEventPackManager.GetOrDefault(packID);
|
||||
if (eventPackManager == null)
|
||||
{
|
||||
Debug.LogError($"EventPackManager with ID {packID} not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = await UIManager.Instance.ShowUI(new UIType(eventPackManager.Panel));
|
||||
if (go != null)
|
||||
{
|
||||
EventLuckyTriplePackPanel triple = go.GetComponent<EventLuckyTriplePackPanel>();
|
||||
triple.Init(EventLuckyTriplePackData.Create(luckyModel.EventId, packID));
|
||||
}
|
||||
break;
|
||||
}
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
if (luckyModel == null)
|
||||
{
|
||||
GetReward();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class LuckyTaskItemData
|
||||
{
|
||||
public int id;
|
||||
public string desc;
|
||||
public int target;
|
||||
public int reward;
|
||||
public int progress;
|
||||
/// <summary>
|
||||
/// // 0:未完成 1:可领取 -1:已领取
|
||||
/// </summary>
|
||||
public int state;
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4424ff39b0f54614f81b4bc6d0a0ec13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user