468 lines
15 KiB
C#
468 lines
15 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-11-03
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "MovesShopPanel" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using PureMVC.Interfaces;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G.UI
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class MovesShopPanel : KUIWidget
|
|
{
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
GameObject _goPanel;
|
|
[KUIFlag]
|
|
GameObject _goTitle;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpTitle;
|
|
[KUIFlag]
|
|
Button __btnAdGetAll;
|
|
[KUIFlag]
|
|
Button __btnAdRefresh;
|
|
[KUIFlag]
|
|
KUIList __listMoves;
|
|
|
|
[KUIFlag]
|
|
GameObject _goPanel2;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpTitle2;
|
|
[KUIFlag]
|
|
Button __btnAdGet;
|
|
[KUIFlag]
|
|
Button _btnGet;
|
|
[KUIFlag]
|
|
KUIList __listGetMoves;
|
|
|
|
[KUIFlag]
|
|
GameObject _goPanel3;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpTitle3;
|
|
[KUIFlag]
|
|
Button __btnAdGetAll3;
|
|
[KUIFlag]
|
|
Button _btnGet3;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpGet3;
|
|
[KUIFlag]
|
|
KUIList __listMoves3;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpSelect;
|
|
|
|
#pragma warning restore CS0649 // 字段已被赋值,但从未使用过它的值
|
|
|
|
public readonly HashSet<int> selectedMoves = new HashSet<int>();
|
|
|
|
private readonly List<ItemMoves> _getMoves = new List<ItemMoves>();
|
|
|
|
private bool _showGet;
|
|
|
|
private SmartCostWidget _smart_btnAdGetAll;
|
|
private SmartCostWidget _smart_btnAdRefresh;
|
|
private SmartCostWidget _smart_btnAdGet;
|
|
private SmartCostWidget _smart_btnAdGetAll3;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
bool blockAd
|
|
{
|
|
get { return LevelProxy.Instance.currentCompletedLevel < 1; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void Refresh()
|
|
{
|
|
_showGet = false;
|
|
|
|
if (!GameLevel.Instance.studyLevelSkill)
|
|
{
|
|
if (MovesShop.Instance.movesPoint > 2)
|
|
{
|
|
ShowStudyMuti();
|
|
}
|
|
else
|
|
{
|
|
ShowStudy(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowStudy(true);
|
|
}
|
|
}
|
|
|
|
private void RefreshSelect()
|
|
{
|
|
int point = MovesShop.Instance.movesPoint;
|
|
_tmpSelect.text = $"从以下武学中选择{selectedMoves.Count}/{point}本进行修炼";
|
|
_btnGet3.interactable = selectedMoves.Count == point;
|
|
_tmpGet3.text = $"已选{selectedMoves.Count}/{point}";
|
|
}
|
|
|
|
private void ShowStudy(bool level)
|
|
{
|
|
_goPanel.SetActive(true);
|
|
_goPanel2.SetActive(false);
|
|
_goPanel3.SetActive(false);
|
|
|
|
var showMoves = MovesShop.Instance.showMoves;
|
|
__listMoves.Clear();
|
|
ItemMoves recommend = null;
|
|
MovesWidget recommendWidget = null;
|
|
for (int i = 0; i < showMoves.Count; i++)
|
|
{
|
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(showMoves[i]);
|
|
var widget = __listMoves.GetItem<MovesWidget>();
|
|
widget.SetData(movesItem);
|
|
if (recommend == null || recommend.order < movesItem.order)
|
|
{
|
|
recommend = movesItem;
|
|
recommendWidget = widget;
|
|
}
|
|
}
|
|
|
|
if (recommendWidget != null)
|
|
{
|
|
recommendWidget.ShowRecomment();
|
|
}
|
|
|
|
if (level)
|
|
{
|
|
__btnAdGetAll.gameObject.SetActive(false);
|
|
__btnAdRefresh.gameObject.SetActive(!blockAd);
|
|
if (!blockAd)
|
|
{
|
|
_smart_btnAdRefresh.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|
}
|
|
//_btnAdRefresh.gameObject.SetActive(_canAdRefresh);
|
|
|
|
_goTitle.SetActive(true);
|
|
_tmpTitle.text = $"本次闯关升到了{Mathf.Max(1, MovesShop.Instance.totalMovesPoint - 1)}级";
|
|
}
|
|
else
|
|
{
|
|
__btnAdRefresh.gameObject.SetActive(false);
|
|
__btnAdGetAll.gameObject.SetActive(true);
|
|
_smart_btnAdGetAll.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|
_goTitle.SetActive(false);
|
|
}
|
|
|
|
if ("auto".Equals(this.data))
|
|
{
|
|
StartCoroutine(AutoSelect());
|
|
}
|
|
|
|
SoundProxy.PlayFxAsync("Sounds/attack_skill.mp3");
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void ShowStudyMuti()
|
|
{
|
|
selectedMoves.Clear();
|
|
|
|
_goPanel.SetActive(false);
|
|
_goPanel2.SetActive(false);
|
|
_goPanel3.SetActive(true);
|
|
|
|
var showMoves = MovesShop.Instance.showMoves;
|
|
__listMoves3.Clear();
|
|
for (int i = 0; i < showMoves.Count; i++)
|
|
{
|
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(showMoves[i]);
|
|
__listMoves3.GetItem().SetData(movesItem);
|
|
}
|
|
_smart_btnAdGetAll3.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|
RefreshSelect();
|
|
}
|
|
|
|
private void ShowGet(ItemMoves moves)
|
|
{
|
|
_showGet = true;
|
|
|
|
_goPanel.SetActive(false);
|
|
_goPanel2.SetActive(true);
|
|
_goPanel3.SetActive(false);
|
|
|
|
__listGetMoves.Clear();
|
|
__listGetMoves.GetItem().SetData(moves);
|
|
|
|
__btnAdGet.gameObject.SetActive(false);
|
|
|
|
// 可以双倍
|
|
if (!blockAd && moves.targetType == 2)
|
|
{
|
|
var buffItem = ItemProxy.Instance.GetStaticItem<ItemBuff>(moves.targetId);
|
|
if (buffItem != null && (buffItem.kind == 1 || buffItem.kind == 2))
|
|
{
|
|
__btnAdGet.gameObject.SetActive(true);
|
|
_smart_btnAdGet.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|
}
|
|
}
|
|
|
|
var shopMoves = MovesShop.Instance.showMoves;
|
|
KStatistics.Instance.ReportEvent_BattleChoose(GameLevel.Instance.infinityMode ? "无尽" : "普通", GameLevel.Instance.curChapterId, GameLevel.Instance.curLevelId, GameLevel.Instance.curStageId, 1, shopMoves.SafeGet(0), shopMoves.SafeGet(1), shopMoves.SafeGet(2), moves.id);
|
|
}
|
|
|
|
private IEnumerator AutoSelect()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
if (_goPanel.activeSelf)
|
|
{
|
|
var showMoves = MovesShop.Instance.showMoves;
|
|
ItemMoves recommend = null;
|
|
for (int i = 0; i < showMoves.Count; i++)
|
|
{
|
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(showMoves[i]);
|
|
if (recommend == null || recommend.order < movesItem.order)
|
|
{
|
|
recommend = movesItem;
|
|
}
|
|
}
|
|
MovesShop.Instance.StudyMoves(recommend.id);
|
|
}
|
|
yield return new WaitForSeconds(1f);
|
|
OnGetBtnClick();
|
|
}
|
|
|
|
private void OnCloseBtnClick()
|
|
{
|
|
MovesShop.Instance.ApplyLastStudiedMoves();
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnRefreshBtnClick()
|
|
{
|
|
if (!MovesShop.Instance.RefreshMovesShop(false))
|
|
{
|
|
AdProxy.Instance.PlayAd("skill", "ads_skill_refresh", GameLevel.Instance.curStageId.ToString(), (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
MovesShop.Instance.RefreshMovesShop(true);
|
|
Refresh();
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Refresh();
|
|
}
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnGetAllBtnClick()
|
|
{
|
|
AdProxy.Instance.PlayAd("skill", "ads_skill_study_all", GameLevel.Instance.reportStageId.ToString(), (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
MovesShop.Instance.StudyAllMoves(true);
|
|
GetMoves(false);
|
|
}
|
|
});
|
|
var shopMoves = MovesShop.Instance.showMoves;
|
|
KStatistics.Instance.ReportEvent_BattleChoose(GameLevel.Instance.infinityMode ? "无尽" : "普通", GameLevel.Instance.curChapterId, GameLevel.Instance.curLevelId, GameLevel.Instance.curStageId, 1, shopMoves.SafeGet(0), shopMoves.SafeGet(1), shopMoves.SafeGet(2), -1000);
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnAdGetBtnClick()
|
|
{
|
|
AdProxy.Instance.PlayAd("skill", "ads_skill_study_double", GameLevel.Instance.reportStageId.ToString(), (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
OnDoubleGetBtnClick();
|
|
}
|
|
});
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnDoubleGetBtnClick()
|
|
{
|
|
GetMoves(true);
|
|
}
|
|
|
|
private void OnGetBtnClick()
|
|
{
|
|
GetMoves(false);
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void GetMoves(bool doubleValue)
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
MovesShop.Instance.ApplyLastStudiedMoves(doubleValue);
|
|
PostNotification(GlobalDefine.EVENT_GAME_WINDOW, nameof(MovesShopPanel), nameof(BattlePanel));
|
|
}
|
|
|
|
private void OnGetAll3BtnClick()
|
|
{
|
|
MovesShop.Instance.StudyMoves(selectedMoves, false);
|
|
ShowAllGetAdMoves();
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnAdGetAll3BtnClick()
|
|
{
|
|
AdProxy.Instance.PlayAd("skill", "ads_skill_study_all", GameLevel.Instance.reportStageId.ToString(), (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
MovesShop.Instance.StudyAllMoves(true);
|
|
GetMoves(false);
|
|
}
|
|
});
|
|
var shopMoves = MovesShop.Instance.showMoves;
|
|
KStatistics.Instance.ReportEvent_BattleChoose(GameLevel.Instance.infinityMode ? "无尽" : "普通", GameLevel.Instance.curChapterId, GameLevel.Instance.curLevelId, GameLevel.Instance.curStageIndex, 1, shopMoves.SafeGet(0), shopMoves.SafeGet(1), shopMoves.SafeGet(2), -1000);
|
|
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnMovesSelect(ItemMoves moves, bool select)
|
|
{
|
|
if (select)
|
|
selectedMoves.Add(moves.id);
|
|
else
|
|
selectedMoves.Remove(moves.id);
|
|
RefreshSelect();
|
|
}
|
|
|
|
private void ShowAllGetAdMoves()
|
|
{
|
|
bool flag = false;
|
|
foreach (var id in selectedMoves)
|
|
{
|
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(id);
|
|
if (movesItem != null && movesItem.targetType == 2)
|
|
{
|
|
ShowGet(movesItem);
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
GetMoves(false);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
public static MovesShopPanel Instance;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
|
|
SetViewData();
|
|
|
|
__btnAdRefresh.onClick.AddListener(this.OnRefreshBtnClick);
|
|
_smart_btnAdRefresh = __btnAdRefresh.gameObject.AddComponent<SmartCostWidget>();
|
|
__btnAdGetAll.onClick.AddListener(this.OnGetAllBtnClick);
|
|
_smart_btnAdGetAll =__btnAdGetAll.gameObject.AddComponent<SmartCostWidget>();
|
|
|
|
_btnGet.onClick.AddListener(this.OnGetBtnClick);
|
|
__btnAdGet.onClick.AddListener(this.OnAdGetBtnClick);
|
|
_smart_btnAdGet = __btnAdGet.gameObject.AddComponent<SmartCostWidget>();
|
|
|
|
_btnGet3.onClick.AddListener(this.OnGetAll3BtnClick);
|
|
__btnAdGetAll3.onClick.AddListener(this.OnAdGetAll3BtnClick);
|
|
_smart_btnAdGetAll3 = __btnAdGetAll3.gameObject.AddComponent<SmartCostWidget>();
|
|
|
|
__listMoves.AddTemplate<MovesWidget>(true);
|
|
__listGetMoves.AddTemplate<MovesWidget>(true);
|
|
__listMoves3.AddTemplate<MovesWidget>(true);
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
__listMoves.GetItem();
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
RegisterThis();
|
|
//Refresh();
|
|
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_WINDOW_OPEN, null, "skill_shop");
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UnregisterThis();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Meditor
|
|
|
|
readonly int[] _listNotificationInterests = new int[]
|
|
{
|
|
GlobalDefine.EVENT_SKILL_CARD_STATE_CHANGED,
|
|
GlobalDefine.EVENT_SKILL_CARD_SELECTED,
|
|
};
|
|
|
|
public override IList<int> ListNotificationInterests()
|
|
{
|
|
return _listNotificationInterests;
|
|
}
|
|
|
|
public override void HandleNotification(INotification notification)
|
|
{
|
|
if (notification.Name == GlobalDefine.EVENT_SKILL_CARD_STATE_CHANGED)
|
|
{
|
|
if (!_showGet && notification.Type == "study")
|
|
{
|
|
if (notification.Body is ItemMoves movesItem)
|
|
{
|
|
ShowGet(movesItem);
|
|
MovesShop.Instance.StudyMoves(movesItem.id);
|
|
}
|
|
}
|
|
}
|
|
else if (notification.Name == GlobalDefine.EVENT_SKILL_CARD_SELECTED)
|
|
{
|
|
if (notification.Type == bool.TrueString)
|
|
{
|
|
OnMovesSelect((ItemMoves)notification.Body, true);
|
|
}
|
|
else
|
|
{
|
|
OnMovesSelect((ItemMoves)notification.Body, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|