Add logic of account storage
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using BrewMonster;
|
||||
using BrewMonster.Scripts;
|
||||
using BrewMonster.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BrewMonster.Scripts.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Money-only account warehouse UI. C++ uses Win_Storage3, but this Unity port keeps it
|
||||
/// separate from <see cref="EC_StorageUI"/> so normal warehouse item logic cannot leak in.
|
||||
/// </summary>
|
||||
public class EC_AccountStorageUI : AUIDialog
|
||||
{
|
||||
[SerializeField] private Button closeButton;
|
||||
[SerializeField] private Button depositMoneyButton;
|
||||
[SerializeField] private Button withdrawMoneyButton;
|
||||
[SerializeField] private Text accountMoneyTextLegacy;
|
||||
[SerializeField] private TMPro.TextMeshProUGUI accountMoneyTextTMP;
|
||||
|
||||
private static EC_AccountStorageUI s_instance;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
s_instance = this;
|
||||
ResolveButtons();
|
||||
WireButtons();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (s_instance == this)
|
||||
s_instance = null;
|
||||
}
|
||||
|
||||
public static void RefreshMoneyStatic()
|
||||
{
|
||||
s_instance?.RefreshMoney();
|
||||
}
|
||||
|
||||
public void RefreshAll()
|
||||
{
|
||||
RefreshMoney();
|
||||
}
|
||||
|
||||
void ResolveButtons()
|
||||
{
|
||||
var buttons = GetComponentsInChildren<Button>(true);
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
var btn = buttons[i];
|
||||
if (btn == null)
|
||||
continue;
|
||||
string n = btn.name.ToLowerInvariant();
|
||||
if (closeButton == null && (n.Contains("close") || n.Contains("cancel") || n == "btn_close"))
|
||||
closeButton = btn;
|
||||
if (depositMoneyButton == null && (n.Contains("deposit") || n.Contains("put_money") || n.Contains("gui_tien")
|
||||
|| n.Contains("send_money") || n == "choosemoney" || n.Contains("btn_put")))
|
||||
depositMoneyButton = btn;
|
||||
if (withdrawMoneyButton == null && (n.Contains("withdraw") || n.Contains("get_money") || n.Contains("rut")
|
||||
|| n.Contains("take_money") || n.Contains("btn_get")))
|
||||
withdrawMoneyButton = btn;
|
||||
}
|
||||
}
|
||||
|
||||
void WireButtons()
|
||||
{
|
||||
if (closeButton != null)
|
||||
{
|
||||
closeButton.onClick.RemoveAllListeners();
|
||||
closeButton.onClick.AddListener(() => CECHostPlayer.PopupAccountBoxDialog(true));
|
||||
}
|
||||
if (depositMoneyButton != null)
|
||||
{
|
||||
depositMoneyButton.onClick.RemoveAllListeners();
|
||||
depositMoneyButton.onClick.AddListener(OnDepositMoneyClicked);
|
||||
}
|
||||
if (withdrawMoneyButton != null)
|
||||
{
|
||||
withdrawMoneyButton.onClick.RemoveAllListeners();
|
||||
withdrawMoneyButton.onClick.AddListener(OnWithdrawMoneyClicked);
|
||||
}
|
||||
}
|
||||
|
||||
void RefreshMoney()
|
||||
{
|
||||
var host = CECGameRun.Instance?.GetHostPlayer();
|
||||
if (host == null)
|
||||
return;
|
||||
|
||||
string accountMoney = host.GetAccountBoxMoneyCnt().ToString();
|
||||
|
||||
if (accountMoneyTextLegacy != null)
|
||||
accountMoneyTextLegacy.text = accountMoney;
|
||||
if (accountMoneyTextTMP != null)
|
||||
accountMoneyTextTMP.text = accountMoney;
|
||||
}
|
||||
|
||||
void OnDepositMoneyClicked()
|
||||
{
|
||||
var host = CECGameRun.Instance?.GetHostPlayer();
|
||||
if (host == null || !host.IsUsingAccountBox())
|
||||
return;
|
||||
|
||||
int max = (int)Mathf.Min(int.MaxValue, host.GetMoneyAmount());
|
||||
if (max <= 0)
|
||||
return;
|
||||
|
||||
DlgQuantity.Show(DlgQuantity.QuantityMode.AccountStorageDepositMoney, max, Mathf.Min(1, max));
|
||||
}
|
||||
|
||||
void OnWithdrawMoneyClicked()
|
||||
{
|
||||
var host = CECGameRun.Instance?.GetHostPlayer();
|
||||
if (host == null || !host.IsUsingAccountBox())
|
||||
return;
|
||||
|
||||
int max = host.GetAccountBoxMoneyCnt();
|
||||
if (max <= 0)
|
||||
return;
|
||||
|
||||
DlgQuantity.Show(DlgQuantity.QuantityMode.AccountStorageWithdrawMoney, max, Mathf.Min(1, max));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f04de4d418987314e84daf47df9e9a9b
|
||||
Reference in New Issue
Block a user