2024-05-15 12:53:03 +08:00
|
|
|
|
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/****************************************************
|
2024-05-15 13:18:54 +08:00
|
|
|
|
文件:Assets/Code/Scripts/Gameplay/UI/UI_BuyEnergyController.cs
|
2024-05-15 12:53:03 +08:00
|
|
|
|
作者:yuntao-Hu
|
|
|
|
|
|
时间:2024/5
|
|
|
|
|
|
描述:补充体力UI界面
|
|
|
|
|
|
说明:
|
2024-05-13 15:55:47 +08:00
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
|
|
using Toggle = UnityEngine.UI.Toggle;
|
|
|
|
|
|
using ScrollView = PhxhSDK.PhxhScrollView;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Gameplay;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using static UnityEngine.Rendering.DebugUI;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using Gameplay.Common;
|
|
|
|
|
|
using cfg.ActorCfg;
|
2024-05-14 20:10:28 +08:00
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using LeanCloud.Realtime.Internal.Protocol;
|
2024-05-15 13:18:54 +08:00
|
|
|
|
using static UI_BuyEnergyController;
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-05-15 13:18:54 +08:00
|
|
|
|
public class UI_BuyEnergyController : UIWindow
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
#region enum
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 补充体力方式 ( 与窗口内顺序对应 )
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum RechargeMethod
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
Recharge_byItem,
|
|
|
|
|
|
Recharge_byCurrency
|
2024-05-15 12:53:03 +08:00
|
|
|
|
}//TODO 考虑后续以json方式存储补充体力方式信息
|
2024-05-14 20:10:28 +08:00
|
|
|
|
#endregion
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
#region Temporary_Constant
|
2024-05-15 12:53:03 +08:00
|
|
|
|
private const int DEFAULT_USAGE_AMOUNT = 1;//默认使用数目,使用时的最小量
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 体力药物品ID
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
private const int ENERGY_ITEM_ID = 8;//TODO 体力药物品ID,考虑加入globalconfig
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
private readonly int[] itemIDs = { ENERGY_ITEM_ID, GLConfig.Inst.data.DiamondItemId };//TODO 考虑后续将补充体力方式改为json配置后需要调整传参
|
2024-05-13 15:55:47 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region UI GameObj
|
|
|
|
|
|
//UI GameObj
|
|
|
|
|
|
///Auto Gen Start///
|
|
|
|
|
|
public Image Image_BG;
|
|
|
|
|
|
public TMP_Text Text_Title;
|
|
|
|
|
|
public TMP_Text Text_Currency;
|
|
|
|
|
|
public Button Button_Close;
|
|
|
|
|
|
public Image Image_DetailBG;
|
|
|
|
|
|
public TMP_Text Text_Detail;
|
|
|
|
|
|
public Image Image_BtnBar;
|
|
|
|
|
|
public TMP_InputField Text_NumInputField;
|
|
|
|
|
|
public Button Button_Min;
|
|
|
|
|
|
public Image Image_Min;
|
|
|
|
|
|
public TMP_Text Text_Min;
|
|
|
|
|
|
public Button Button_Minus;
|
|
|
|
|
|
public Button Button_Max;
|
|
|
|
|
|
public Image Image_Max;
|
|
|
|
|
|
public TMP_Text Text_Max;
|
|
|
|
|
|
public Button Button_Plus;
|
|
|
|
|
|
public Image Image_ItemBG;
|
|
|
|
|
|
public Image Image_ItemRect;
|
|
|
|
|
|
public Image Image_MovePoint;
|
|
|
|
|
|
public Image Image_Arrow;
|
|
|
|
|
|
public TMP_Text Text_NowCount;
|
|
|
|
|
|
public TMP_Text Text_AfterCount;
|
|
|
|
|
|
public Button Button_Return;
|
|
|
|
|
|
public TMP_Text Text_Return;
|
|
|
|
|
|
public Button Button_Buy;
|
|
|
|
|
|
public TMP_Text Text_Buy;
|
|
|
|
|
|
|
|
|
|
|
|
///Auto Gen End///
|
|
|
|
|
|
private RawImage rawImageGaussianBlurMask;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
|
2024-05-15 18:37:08 +08:00
|
|
|
|
#region class
|
2024-05-14 20:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
class MethodButtonObj: UIGameObjectWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
private GameObject chosenCircle;
|
|
|
|
|
|
private TextMeshProUGUI itemAmountText;
|
|
|
|
|
|
private Image buttonIcon;
|
|
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//TODO 考虑后续,将补充体力方式改为json配置后,可能需要调整传参
|
2024-05-14 20:10:28 +08:00
|
|
|
|
public MethodButtonObj(GameObject root, int i, int itemID, bool isScaleShow = true) : base(root, i, isScaleShow)
|
|
|
|
|
|
{
|
|
|
|
|
|
chosenCircle = FindObj("ChooseRect");
|
|
|
|
|
|
itemAmountText = GetComponent<TextMeshProUGUI>("ImageCount/TextCount");
|
|
|
|
|
|
buttonIcon = GetComponent<Image>("ItemIcon");
|
|
|
|
|
|
RefreshIcon(itemID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void BindListener(Action callback)
|
|
|
|
|
|
{
|
|
|
|
|
|
BindButton(GameObject.GetComponent<Button>(), callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async void RefreshIcon(int itemID)
|
|
|
|
|
|
{
|
|
|
|
|
|
var spritePath = CommonUtils.GetItemPath(itemID);
|
|
|
|
|
|
buttonIcon.sprite = await LoadAssetAsync<Sprite>(spritePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetChosen(bool isChosen)
|
|
|
|
|
|
{
|
|
|
|
|
|
chosenCircle.SetActive(isChosen);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetItemAmount(uint amount)
|
|
|
|
|
|
{
|
|
|
|
|
|
itemAmountText.text = amount.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetActive(bool isActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject.SetActive(isActive);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Button_Listener
|
|
|
|
|
|
public void OnClickClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMinClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUsageAmountAndRefresh(DEFAULT_USAGE_AMOUNT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMinusClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_UsageAmount > DEFAULT_USAGE_AMOUNT)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_UsageAmount--;
|
|
|
|
|
|
SetUsageAmountAndRefresh(m_UsageAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMaxClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
SetUsageAmountAndRefresh(MaxConsumeAmountWithoutConvert());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPlusClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_UsageAmount < MaxConsumeAmountWithoutConvert())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_UsageAmount++;
|
|
|
|
|
|
SetUsageAmountAndRefresh(m_UsageAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnReturnClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnBuyClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_UsageAmount <= MaxConsumeAmountWithoutConvert() && m_UsageAmount > 0)
|
|
|
|
|
|
{
|
2024-05-15 18:37:08 +08:00
|
|
|
|
EnergyManager.Instance.BuyEnergy(itemIDs[(int)m_RechargeMethod], (uint)m_UsageAmount);
|
2024-05-14 20:10:28 +08:00
|
|
|
|
CloseWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
#if UNITY_EDITOR
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.Log("购买体力数目超出可选择范围!");
|
2024-05-14 20:10:28 +08:00
|
|
|
|
#endif
|
2024-05-15 18:37:08 +08:00
|
|
|
|
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("BuyEnergy_failed"));
|
2024-05-14 20:10:28 +08:00
|
|
|
|
}
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
2024-05-14 20:10:28 +08:00
|
|
|
|
#endregion
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
private List<MethodButtonObj> rechargeMethodButtons = new List<MethodButtonObj>();
|
|
|
|
|
|
private Dictionary<RechargeMethod, uint> storageItemCount = new Dictionary<RechargeMethod, uint>();
|
|
|
|
|
|
|
2024-05-15 18:37:08 +08:00
|
|
|
|
private uint m_CurrEnergy;
|
2024-05-14 20:10:28 +08:00
|
|
|
|
private int m_UsageAmount;
|
|
|
|
|
|
|
|
|
|
|
|
private RechargeMethod m_RechargeMethod;
|
|
|
|
|
|
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 打开购买体力界面
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static async UniTask<UIWindow> Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
CommonUtils.CaptureScreenshot();
|
|
|
|
|
|
|
2024-05-15 13:18:54 +08:00
|
|
|
|
return await UIManager.Instance.OpenWindow(UINameConst.UI_BuyEnergy);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// deal with input data
|
|
|
|
|
|
public override void PreLoad(object data = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
|
|
public override void OnInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
//bind UI GameObj
|
2024-05-15 13:18:54 +08:00
|
|
|
|
UI_BuyEnergyBinder.GetComponents(this);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
|
|
|
|
|
rawImageGaussianBlurMask.texture = CommonUtils.screenTexture;
|
|
|
|
|
|
|
|
|
|
|
|
GetStorageFromServer();
|
|
|
|
|
|
BindButton();
|
|
|
|
|
|
BindInputFieldListener();
|
|
|
|
|
|
InitEnergyRefreshTimer();
|
2024-05-15 18:37:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 根据体力刷新情况即时更新界面内体力数目显示
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
2024-05-13 15:55:47 +08:00
|
|
|
|
void InitEnergyRefreshTimer()
|
|
|
|
|
|
{
|
2024-05-15 18:37:08 +08:00
|
|
|
|
m_CurrEnergy = EnergyManager.Instance.GetNowEnergy();
|
|
|
|
|
|
|
|
|
|
|
|
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnItemChange(uint itemId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((int)itemId != GLConfig.Inst.data.EnergyPointID)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
m_CurrEnergy = EnergyManager.Instance.GetNowEnergy();
|
|
|
|
|
|
int consume = EnergyManager.Instance.GetConvertConsumes(itemIDs[(int)m_RechargeMethod], m_UsageAmount);
|
|
|
|
|
|
int recharge = EnergyManager.Instance.GetConvertRecharges(itemIDs[(int)m_RechargeMethod], m_UsageAmount);
|
|
|
|
|
|
RefreshDetailText(consume, recharge);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BindInputFieldListener()
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
Text_NumInputField.onEndEdit.AddListener(SnapInputToStep);
|
|
|
|
|
|
}
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 由于货币输入框输入的数值不一定是阶梯值,需要对输入的数值做向下取整到阶梯值
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputAmount"></param>
|
|
|
|
|
|
void SnapInputToStep(string inputAmount)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
int parsedValue;
|
|
|
|
|
|
if (int.TryParse(inputAmount, out parsedValue))
|
|
|
|
|
|
{
|
2024-05-15 18:37:08 +08:00
|
|
|
|
// 对输入的数据做向下取整到阶梯值
|
|
|
|
|
|
int snappedValue = (int)(parsedValue / EnergyManager.Instance.GetConvertConsumes(itemIDs[(int)m_RechargeMethod]));
|
2024-05-13 15:55:47 +08:00
|
|
|
|
if (snappedValue < DEFAULT_USAGE_AMOUNT)
|
|
|
|
|
|
{
|
|
|
|
|
|
snappedValue = DEFAULT_USAGE_AMOUNT;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (snappedValue > MaxConsumeAmountWithoutConvert())
|
|
|
|
|
|
{
|
|
|
|
|
|
snappedValue = MaxConsumeAmountWithoutConvert();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_UsageAmount = snappedValue;
|
|
|
|
|
|
SetUsageAmountAndRefresh(m_UsageAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.LogError("错误输入内容,已舍弃");
|
2024-05-13 15:55:47 +08:00
|
|
|
|
SetUsageAmountAndRefresh(m_UsageAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 注意先初始化storageItemCount字典,再绑定按钮
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
void BindButton()
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
BindMethodButton();
|
|
|
|
|
|
|
|
|
|
|
|
Button_Buy.onClick.AddListener(OnBuyClick);
|
|
|
|
|
|
Button_Close.onClick.AddListener(OnClickClose);
|
|
|
|
|
|
Button_Min.onClick.AddListener(OnMinClick);
|
|
|
|
|
|
Button_Minus.onClick.AddListener(OnMinusClick);
|
|
|
|
|
|
Button_Max.onClick.AddListener(OnMaxClick);
|
|
|
|
|
|
Button_Plus.onClick.AddListener(OnPlusClick);
|
|
|
|
|
|
Button_Return.onClick.AddListener(OnReturnClick);
|
|
|
|
|
|
}
|
2024-05-14 20:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 注意先初始化storageItemCount字典,再绑定补充体力方式选择按钮
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
2024-05-13 15:55:47 +08:00
|
|
|
|
void BindMethodButton()
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//体力补充方式选择按钮
|
2024-05-13 15:55:47 +08:00
|
|
|
|
ScrollView methodButtonView = Image_ItemBG.GetComponentInChildren<ScrollView>();
|
|
|
|
|
|
if (methodButtonView == null)
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.LogError("体力补充方式按钮列表获取失败!");
|
2024-05-13 15:55:47 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
GameObject buttonPrefab = null;
|
2024-05-13 15:55:47 +08:00
|
|
|
|
foreach (Transform buttonGameObj in methodButtonView.content)
|
|
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
buttonGameObj.gameObject.SetActive(false);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
if (buttonGameObj.GetComponent<Button>() != null)
|
|
|
|
|
|
buttonPrefab = buttonGameObj.gameObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Enum.GetValues(typeof(RechargeMethod)).Length; i++)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
var methodButton = new MethodButtonObj(buttonPrefab, i, itemIDs[i]);
|
|
|
|
|
|
methodButton.SetActive(true);
|
|
|
|
|
|
rechargeMethodButtons.Add(methodButton);
|
|
|
|
|
|
|
|
|
|
|
|
RechargeMethod method = (RechargeMethod)i;
|
|
|
|
|
|
methodButton.BindListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (method != m_RechargeMethod)
|
|
|
|
|
|
OnChooseMethod(method);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (storageItemCount.ContainsKey(method))
|
|
|
|
|
|
methodButton.SetItemAmount(storageItemCount[method]);
|
|
|
|
|
|
else
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.LogError("未找到" + method.ToString() + "对应的物品数目!检查正确性或是否初始化storage字典");
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//invoke when open window
|
|
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//TODO 后续补充体力方式增加后,可能要考虑其他物品
|
2024-05-14 20:10:28 +08:00
|
|
|
|
if (isItemRemained(RechargeMethod.Recharge_byItem))
|
|
|
|
|
|
{
|
|
|
|
|
|
OnChooseMethod(RechargeMethod.Recharge_byItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
HideMethodButton(RechargeMethod.Recharge_byItem);
|
|
|
|
|
|
OnChooseMethod(RechargeMethod.Recharge_byCurrency);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SetUsageAmountAndRefresh(amount: DEFAULT_USAGE_AMOUNT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HideMethodButton(RechargeMethod method)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((int)method < rechargeMethodButtons.Count)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
rechargeMethodButtons[(int)method].SetActive(false);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.LogError("不存在" + method.ToString() + "对应的按钮!");
|
2024-05-14 20:10:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//invoke when reload window
|
|
|
|
|
|
protected override void OnReloadWindow(object data = null)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//invoke when close window
|
|
|
|
|
|
protected override void OnHideWindow()
|
|
|
|
|
|
{
|
2024-05-15 18:37:08 +08:00
|
|
|
|
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//invoke when destroy
|
|
|
|
|
|
public override void OnRelease()
|
|
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
foreach(var btn in rechargeMethodButtons)
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.Dispose();
|
|
|
|
|
|
}
|
2024-05-15 18:37:08 +08:00
|
|
|
|
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
|
|
|
|
|
base.OnRelease();
|
2024-05-14 20:10:28 +08:00
|
|
|
|
}
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 初始化补充体力物品数目
|
2024-05-14 20:10:28 +08:00
|
|
|
|
/// </summary>
|
2024-05-13 15:55:47 +08:00
|
|
|
|
void GetStorageFromServer()
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//storageItemCount字典查找物品数目,为后续扩展
|
2024-05-14 20:10:28 +08:00
|
|
|
|
uint m_ItemAmount = Actor.Instance.Item.GetItemCount(ENERGY_ITEM_ID);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
if (!storageItemCount.ContainsKey(RechargeMethod.Recharge_byItem))
|
|
|
|
|
|
{
|
|
|
|
|
|
storageItemCount.Add(RechargeMethod.Recharge_byItem, m_ItemAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
uint m_CurrencyAmount = Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.DiamondItemId);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
if (!storageItemCount.ContainsKey(RechargeMethod.Recharge_byCurrency))
|
|
|
|
|
|
{
|
|
|
|
|
|
storageItemCount.Add(RechargeMethod.Recharge_byCurrency, m_CurrencyAmount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 体力药是否剩余(可用于判断初始化时的补充体力方式)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2024-05-14 20:10:28 +08:00
|
|
|
|
bool isItemRemained(RechargeMethod method)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
if (storageItemCount.ContainsKey(method))
|
|
|
|
|
|
return storageItemCount[method] > 0;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
DebugUtil.LogError("未找到" + method.ToString() + "对应的物品数目!检查正确性或是否初始化storage字典");
|
2024-05-14 20:10:28 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 选中补充体力方式Button
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="chosenMethod"></param>
|
2024-05-14 20:10:28 +08:00
|
|
|
|
void OnChooseMethod(RechargeMethod chosenMethod)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
{
|
2024-05-14 20:10:28 +08:00
|
|
|
|
MethodButtonObj preChosenButton = rechargeMethodButtons[(int)m_RechargeMethod];
|
|
|
|
|
|
MethodButtonObj curChosenButton = rechargeMethodButtons[(int)chosenMethod];
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
m_RechargeMethod = chosenMethod;
|
|
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
preChosenButton.SetChosen(false);
|
|
|
|
|
|
curChosenButton.SetChosen(true);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//切换按钮后,重置界面内相关数目显示
|
2024-05-14 20:10:28 +08:00
|
|
|
|
SetUsageAmountAndRefresh(amount: DEFAULT_USAGE_AMOUNT);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 获取当前选中状态下的最大消耗数目(实际数据需要乘比例转化)
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
int MaxConsumeAmountWithoutConvert()
|
|
|
|
|
|
{
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//道具数目限制
|
2024-05-13 15:55:47 +08:00
|
|
|
|
uint AmountInStorage = storageItemCount[m_RechargeMethod];
|
2024-05-15 18:37:08 +08:00
|
|
|
|
int maxConsumeRate = (int)(AmountInStorage / EnergyManager.Instance.GetConvertConsumes(itemIDs[(int)m_RechargeMethod]));
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//体力上限限制
|
2024-05-14 20:10:28 +08:00
|
|
|
|
DataItem energyData = TableManager.Instance.Tables.Item.Get(GLConfig.Inst.data.EnergyPointID);
|
2024-05-15 18:37:08 +08:00
|
|
|
|
uint energyToMax = (uint)energyData.MaxCount - m_CurrEnergy;
|
|
|
|
|
|
int maxConsumeRateByEnergy = (int)(energyToMax / EnergyManager.Instance.GetConvertRecharges(itemIDs[(int)m_RechargeMethod]));
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-14 20:10:28 +08:00
|
|
|
|
return Math.Min(maxConsumeRate, maxConsumeRateByEnergy);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-15 18:37:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设定使用数目,并刷新界面内相关数目显示
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="amount"></param>
|
|
|
|
|
|
void SetUsageAmountAndRefresh(int amount)
|
|
|
|
|
|
{
|
2024-05-13 15:55:47 +08:00
|
|
|
|
m_UsageAmount = amount;
|
|
|
|
|
|
|
2024-05-15 18:37:08 +08:00
|
|
|
|
int consume = EnergyManager.Instance.GetConvertConsumes(itemIDs[(int)m_RechargeMethod], m_UsageAmount);
|
|
|
|
|
|
int recharge = EnergyManager.Instance.GetConvertRecharges(itemIDs[(int)m_RechargeMethod], m_UsageAmount);
|
|
|
|
|
|
RefreshDetailText(consume, recharge);
|
2024-05-13 15:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// 刷新文字显示
|
2024-05-13 15:55:47 +08:00
|
|
|
|
/// </summary>
|
2024-05-15 12:53:03 +08:00
|
|
|
|
/// <param name="consume">实际道具消耗显示数</param>
|
|
|
|
|
|
/// <param name="recharge">转化体力数量</param>
|
2024-05-13 15:55:47 +08:00
|
|
|
|
void RefreshDetailText(int consume,int recharge)
|
|
|
|
|
|
{
|
2024-05-15 18:37:08 +08:00
|
|
|
|
uint curEnergy = m_CurrEnergy;
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
Text_NumInputField.text = consume.ToString();
|
|
|
|
|
|
Text_NowCount.text = curEnergy.ToString();
|
|
|
|
|
|
Text_AfterCount.text = (curEnergy + recharge).ToString();
|
|
|
|
|
|
|
2024-05-15 12:53:03 +08:00
|
|
|
|
//TODO 配置对应消耗物的json数据
|
2024-05-13 15:55:47 +08:00
|
|
|
|
DataItem dataItem = TableManager.Instance.Tables.Item.Get(ENERGY_ITEM_ID);
|
|
|
|
|
|
DataItem diamond = TableManager.Instance.Tables.Item.Get(GLConfig.Inst.data.DiamondItemId);
|
2024-05-15 12:53:03 +08:00
|
|
|
|
string[] itemNames = { "个" + CommonUtils.GetLocalizeText(dataItem.NameLocal), CommonUtils.GetLocalizeText(diamond.NameLocal) };
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
2024-05-15 18:37:08 +08:00
|
|
|
|
Text_Detail.text = CommonUtils.GetLocalizeText("BuyEnergy_tips", consume, itemNames[(int)m_RechargeMethod], recharge);
|
|
|
|
|
|
|
2024-05-13 15:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|