2025-05-18 01:04:31 +08:00

393 lines
8.8 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-05-01
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "AdventureBox.View" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
partial class AdventureBox
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpContent;
[KUIFlag]
GameObject _goOptions;
[KUIFlag]
Button _btnOption1;
[KUIFlag]
TextMeshProUGUI _tmpOption1;
[KUIFlag]
Button _btnOption2;
[KUIFlag]
TextMeshProUGUI _tmpOption2;
[KUIFlag]
Button _btnOption3;
[KUIFlag]
KUIList __goRewards;
[KUIFlag]
TextMeshProUGUI _tmpAdTips;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private ItemAdventure _adventure;
private Callback _callback;
private SmartCostWidget _smartCostWidget;
#endregion
#region Method
/// <summary>
///
/// </summary>
public void InitView()
{
SetViewData();
__goRewards.AddTemplate<RewardWidget>(true);
this.gameObject.SetActive(false);
_smartCostWidget = _btnOption3.gameObject.AddComponent<SmartCostWidget>();
}
/// <summary>
///
/// </summary>
public void RefreshView()
{
if (this.data is System.Tuple<ItemAdventure, bool, Callback> tuple)
{
Show(tuple.Item1, tuple.Item3);
if (tuple.Item2)
{
AutoSelect();
}
}
else if (this.data is ItemAdventure adventure)
{
Show(adventure);
}
}
/// <summary>
///
/// </summary>
public void UpdateView()
{
}
private void AutoSelect()
{
StartCoroutine(AutoSelectCO());
}
private System.Collections.IEnumerator AutoSelectCO()
{
for (int i = 0; i < 2; i++)
{
yield return new WaitForSeconds(1f);
if (_adventure.option_1 != null && _adventure.option_1.Length > 0)
{
_btnOption1.onClick.Invoke();
}
else if (_adventure.option_2 != null && _adventure.option_2.Length > 0)
{
_btnOption2.onClick.Invoke();
}
else
{
Callback();
}
}
}
private void Callback()
{
CloseWindow(this);
_callback?.Invoke();
_callback = null;
PostNotification(GlobalDefine.EVENT_WINDOW_CLOSED, null, "adventure");
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="callback"></param>
private void Show(ItemAdventure adventure, Callback callback)
{
if (adventure != null)
{
_callback = callback;
Show(adventure);
}
else
{
callback?.Invoke();
}
}
private void Show(ItemAdventure adventure)
{
#if UNITY_EDITOR
Debug.Log($"触发奇遇 {adventure.id}");
#endif
_adventure = adventure;
gameObject.SetActive(true);
_tmpContent.text = adventure.describe;
_goOptions.SetActive(true);
__goRewards.Clear();
if (adventure.option_1 != null && adventure.option_1.Length > 0)
{
_tmpOption1.text = adventure.matter_1;
_btnOption1.gameObject.SetActive(true);
_btnOption1.onClick.RemoveAllListeners();
SetOption(adventure.option_1, _btnOption1);
}
else
{
_btnOption1.gameObject.SetActive(false);
}
if (adventure.option_2 != null && adventure.option_2.Length > 0)
{
_tmpOption2.text = adventure.matter_2;
_btnOption2.gameObject.SetActive(true);
_btnOption2.onClick.RemoveAllListeners();
SetOption(adventure.option_2, _btnOption2);
}
else
{
_btnOption2.gameObject.SetActive(false);
}
if (adventure.option_3 != null && adventure.option_3.Length > 0)
{
_tmpAdTips.gameObject.SetActive(true);
_tmpAdTips.text = adventure.matter_3;
_btnOption3.gameObject.SetActive(true);
_smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
_btnOption3.onClick.RemoveAllListeners();
SetOption(adventure.option_3, _btnOption3, true);
}
else
{
_tmpAdTips.gameObject.SetActive(false);
_btnOption3.gameObject.SetActive(false);
}
}
/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <param name="button"></param>
private void SetOption(int[] options, Button button, bool playAd = false)
{
int action = options[0];
if (action == 0)
{
button.onClick.AddListener(this.OnOption);
}
else if (action == 1)
{
var next = options[1];
button.onClick.AddListener(() =>
{
Show(ItemProxy.Instance.GetStaticItem<ItemAdventure>(next));
});
}
else if (action == 2)
{
button.onClick.AddListener(this.OnOption);
}
else if (action == 3)
{
int eqipmentId = options[1];
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(eqipmentId);
if (propItem != null)
{
__goRewards.GetItem().SetData(propItem);
}
if (playAd)
{
button.onClick.AddListener(
() => AdProxy.Instance.PlayAd("advt", "ads_advt_try", GameLevel.Instance.curStageId.ToString(), (error, message) =>
{
if (error == 0)
{
PlayerProxy.Instance.TryoutEquipment(eqipmentId);
Callback();
}
}));
}
else
{
button.onClick.AddListener(() =>
{
PlayerProxy.Instance.TryoutEquipment(eqipmentId);
Callback();
});
}
}
else if (action == 4)
{
for (int i = 1; i < options.Length; i++)
{
int buffId = options[i];
var buffItem = ItemProxy.Instance.GetStaticItem<ItemBuff>(buffId);
if (buffItem != null)
{
var rewardW = __goRewards.GetItem<RewardWidget>();
rewardW.SetData(buffItem);
if (options.Length > 2)
rewardW.AddListener(() =>
{
rewardW.ClearListener();
EntityMainPlayer.Instance.AddMovesByBuff(buffId);
Callback();
});
}
}
if (playAd)
{
button.onClick.AddListener(
() => AdProxy.Instance.PlayAd("advt", "ads_advt_buff", GameLevel.Instance.curStageId.ToString(), (error, message) =>
{
if (error == 0)
{
for (int i = 1; i < options.Length; i++)
{
EntityMainPlayer.Instance.AddMovesByBuff(options[i]);
}
Callback();
}
}));
}
else
{
button.onClick.AddListener(() =>
{
for (int i = 1; i < options.Length; i++)
{
EntityMainPlayer.Instance.AddMovesByBuff(options[i]);
}
Callback();
});
}
}
else if (action == 5)
{
for (int i = 1; i < options.Length; i++)
{
int movesId = options[i];
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(movesId);
if (movesItem != null)
{
var rewardW = __goRewards.GetItem<RewardWidget>();
rewardW.SetData(movesItem);
if (options.Length > 2)
rewardW.AddListener(() =>
{
rewardW.ClearListener();
MovesShop.Instance.StudyMoves(movesId, true);
MovesShop.Instance.ApplyLastStudiedMoves();
Callback();
});
}
}
if (playAd)
{
button.onClick.AddListener(
() => AdProxy.Instance.PlayAd("advt", "ads_advt_moves", GameLevel.Instance.curStageId.ToString(), (error, message) =>
{
if (error == 0)
{
gameObject.SetActive(false);
for (int i = 1; i < options.Length; i++)
MovesShop.Instance.StudyMoves(options[i], true);
MovesShop.Instance.ApplyLastStudiedMoves();
Callback();
}
}));
}
else
{
button.onClick.AddListener(() =>
{
for (int i = 1; i < options.Length; i++)
MovesShop.Instance.StudyMoves(options[i], true);
MovesShop.Instance.ApplyLastStudiedMoves();
Callback();
});
}
}
else if (action == 6)
{
int eqipmentId = options[1];
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(eqipmentId);
if (propItem != null)
{
__goRewards.GetItem().SetData(propItem);
}
button.onClick.AddListener(() =>
{
EntityMainPlayer.Instance.GetItem(eqipmentId, 1);
Callback();
});
}
else if (action == 7)
{
for (int i = 1; i < options.Length; i++)
{
int movesId = options[i];
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(movesId);
if (movesItem != null)
{
var rewardW = __goRewards.GetItem<RewardWidget>();
rewardW.SetData(movesItem);
if (options.Length > 2)
rewardW.AddListener(() =>
{
rewardW.ClearListener();
Callback();
});
}
}
button.onClick.AddListener(() =>
{
Callback();
});
}
}
private void OnOption()
{
Callback();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
}
}