328 lines
11 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-01
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "BagPage" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using PureMVC.Interfaces;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class ChaPanel
{
/// <summary>
///
/// </summary>
public class BagPage : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
KUIGrid __gridEquipments;
[KUIFlag]
KUIGrid __gridProps;
[KUIFlag]
Button _btnOneSell;
[KUIFlag]
Button _btnOneSet;
[KUIFlag]
Toggle _tgSort;
[KUIFlag]
TextMeshProUGUI _tmpSortLabel;
[KUIFlag]
Button _btnOneUpGem;
[KUIFlag]
Button _btnOneSetGem;
[KUIFlag]
Button _btnCombine;
[KUIFlag]
Button _btnExpansion;
[KUIFlag]
TextMeshProUGUI _tmpCapacity;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private int _sortModel = 1;
private int _pageType = 0;
private SmartCostWidget _smartCostWidget;
#endregion
#region Method
/// <summary>
///
/// </summary>
public override void Refresh()
{
if (_pageType == 0)
{
__gridProps.gameObject.SetActive(false);
__gridEquipments.gameObject.SetActive(true);
_tgSort.gameObject.SetActive(true);
_btnOneSet.gameObject.SetActive(true);
_btnOneSell.gameObject.SetActive(true);
_btnCombine.gameObject.SetActive(FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.));
_btnOneUpGem.gameObject.SetActive(false);
_btnOneSetGem.gameObject.SetActive(false);
var bagEquipments = BagProxy.Instance.GetBagEquipments(_sortModel);
__gridEquipments.uiPool.SetItemDatas(bagEquipments);
__gridEquipments.RefillItems();//refill
_btnExpansion.gameObject.SetActive(true);
_smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
RefreshBagCapacity();
//_tmpCapacity.text = $"{bagEquipments.Count}/{BagProxy.Instance.bagCapacity}";
}
else
{
__gridEquipments.gameObject.SetActive(false);
__gridProps.gameObject.SetActive(true);
_tgSort.gameObject.SetActive(false);
_btnOneSet.gameObject.SetActive(false);
_btnOneSell.gameObject.SetActive(false);
_btnCombine.gameObject.SetActive(false);
_btnOneUpGem.gameObject.SetActive(true);
_btnOneSetGem.gameObject.SetActive(true);
var bagProps = BagProxy.Instance.GetBagProps();
__gridProps.uiPool.SetItemDatas(bagProps);
__gridProps.RefillItems();
_btnExpansion.gameObject.SetActive(false);
}
}
private void RefreshDataOnly()
{
if (_pageType == 0)
{
var bagEquipments = BagProxy.Instance.GetBagEquipments(_sortModel);
__gridEquipments.uiPool.SetItemDatas(bagEquipments);
__gridEquipments.RefreshItems();
}
else
{
var bagProps = BagProxy.Instance.GetBagProps();
__gridProps.uiPool.SetItemDatas(bagProps);
__gridProps.RefreshItems();
}
}
private void RefreshBagCapacity()
{
int cur = BagProxy.Instance.GetBagItemCount();
int max = BagProxy.Instance.bagCapacity;
if (cur > max)
_tmpCapacity.color = Color.red;
else
_tmpCapacity.color = Color.black;
_tmpCapacity.text = $"{cur}/{max}";
}
public void ShowPage(int index)
{
_pageType = index;
Refresh();
}
private void OnBtnOneSellClick()
{
KUIWindow.OpenWindow<EquipmentSellBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnBtnOneSetClick()
{
BagProxy.Instance.OneKeySetEquipments();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
/// <summary>
///
/// </summary>
private void OnBtnOneUpGemClick()
{
KUIWindow.OpenWindow<GemUpgradeBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
/// <summary>
///
/// </summary>
private void OnBtnOneSetGemClick()
{
if (!BagProxy.Instance.OneKeySetGems())
{
ToastBox.ShowText(KLocalization.GetLocalString(23));
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnCombineBtnClick()
{
KUIWindow.OpenWindow<EquipmentRecastBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnSortToggleValueChanged(bool value)
{
if (value)
{
_tmpSortLabel.text = "按等级排序";
if (_sortModel != 1)
{
_sortModel = 1;
RefreshDataOnly();
}
}
else
{
_tmpSortLabel.text = "按品质排序";
if (_sortModel != 2)
{
_sortModel = 2;
RefreshDataOnly();
}
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnExpansionBtnClick()
{
if (!BagProxy.Instance.isBagCapacityLimit)
{
AdProxy.Instance.PlayAdChange("bag", "add_capacity", (error, message) =>
{
if (error == 0)
{
BagProxy.Instance.bagCapacity += 5;
RefreshBagCapacity();
ToastBox.ShowText("背包容积+5");
}
});
}
else
{
ToastBox.ShowText("背包容积已达上限");
}
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
//var ei = __gridEquipments.uiPool.AddTemplate<EquipmentWidget>(true);
//ei.SetParticleMask(true);
__gridEquipments.uiPool.AddTemplate<EquipmentWidget>(true);
__gridProps.uiPool.AddTemplate<PropWidget>(true);
_tgSort.onValueChanged.AddListener(this.OnSortToggleValueChanged);
_btnOneSet.onClick.AddListener(this.OnBtnOneSetClick);
_btnOneSell.onClick.AddListener(this.OnBtnOneSellClick);
_btnOneUpGem.onClick.AddListener(this.OnBtnOneUpGemClick);
_btnOneSetGem.onClick.AddListener(this.OnBtnOneSetGemClick);
_btnCombine.onClick.AddListener(this.OnCombineBtnClick);
_btnExpansion.onClick.AddListener(this.OnExpansionBtnClick);
_smartCostWidget = _btnExpansion.gameObject.AddComponent<SmartCostWidget>();
}
private bool _started;
private System.Collections.IEnumerator Start()
{
yield return null;
_started = true;
Refresh();
}
private void OnEnable()
{
GlobalVar.BagPageShow = true;
RegisterThis();
if (_started)
Refresh();
}
private void OnDisable()
{
GlobalVar.BagPageShow = false;
UnregisterThis();
}
readonly int[] _notificationInterests = new int[] {
GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED,
GlobalDefine.EVENT_EQUIPMENT_SELL,
GlobalDefine.EVENT_EQUIPMENT_GET,
GlobalDefine.EVENT_EQUIPMENT_LOCK,
GlobalDefine.EVENT_GEM_CHANGED,
GlobalDefine.EVENT_PROP_CHANGED,};
public override IList<int> ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED)
{
if (notification.Type == "set" || notification.Type == "sets")
RefreshDataOnly();
}
else if (notification.Name == GlobalDefine.EVENT_EQUIPMENT_SELL)
{
ToastBox.ShowText(string.Format(KLocalization.GetLocalString(21), notification.Body));
if (notification.Type == "sell")
RefreshDataOnly();
else
Refresh();
}
else if (notification.Name == GlobalDefine.EVENT_EQUIPMENT_GET)
{
Refresh();
}
else if (notification.Name == GlobalDefine.EVENT_EQUIPMENT_LOCK)
{
RefreshDataOnly();
}
else if (notification.Name == GlobalDefine.EVENT_GEM_CHANGED)
{
Refresh();
}
else if (notification.Name == GlobalDefine.EVENT_PROP_CHANGED)
{
Refresh();
}
}
#endregion
}
}
}