97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using Assets.MyGame.Scripts.Net.WebResponses.ChineseChess;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIChineseChessSetCoin : SubUIBase
|
|
{
|
|
public TextMeshProUGUI tmp_CurrGlod;
|
|
public TMP_InputField tmpInput_Coin;
|
|
public Button btn_Enter;
|
|
public List<Button> jinerList; // 金额按钮列表 子对象第0个是textmeshprougui 设置金额 这里有6个按钮
|
|
int currOnClicdindex=999;
|
|
private ChineseChessGameClassList.ChessGameRoom roomData;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
btn_Close.onClick.AddListener(() =>
|
|
{
|
|
WebSocketSendList.EndGameChineseChess(roomData.roomId, null);
|
|
|
|
uIManager.CloseAll();
|
|
WebSocketSendList.GetRoomListChineseChess(1);
|
|
});
|
|
}
|
|
public override void Show(object args = null)
|
|
{
|
|
base.Show(args);
|
|
tmpInput_Coin.text= "";
|
|
if (args != null)
|
|
{
|
|
roomData = (ChineseChessGameClassList.ChessGameRoom)args;
|
|
tmp_CurrGlod.text = ChineseChessMainPanel.FormatGold(GameManager.Instance.user.assets.gold);
|
|
btn_Enter.onClick.RemoveAllListeners();
|
|
btn_Enter.onClick.AddListener(OnEnter);
|
|
|
|
// 加载快捷金额按钮
|
|
LoadBetGoldLimits();
|
|
}
|
|
}
|
|
|
|
private void LoadBetGoldLimits()
|
|
{
|
|
var limits = GameManager.Instance.gameConfig?.chessConfig?.betGoldLimits;
|
|
if (limits == null) return;
|
|
|
|
for (int i = 0; i < jinerList.Count && i < limits.Count; i++)
|
|
{
|
|
long amount = limits[i];
|
|
// child(0) 设置带单位的金额文本
|
|
jinerList[i].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text
|
|
= ChineseChessMainPanel.FormatGold(amount);
|
|
|
|
long captured = amount;
|
|
jinerList[i].onClick.RemoveAllListeners();
|
|
int a = i;
|
|
jinerList[i].onClick.AddListener(() =>
|
|
{
|
|
//if (currOnClicdindex == 999|| currOnClicdindex != a)
|
|
//{
|
|
// currOnClicdindex = a;
|
|
// tmpInput_Coin.text = captured.ToString();
|
|
|
|
//}
|
|
//else if (currOnClicdindex == a)
|
|
//{
|
|
tmpInput_Coin.text = (Convert.ToInt32(tmpInput_Coin.text=="" ? "0" : tmpInput_Coin.text) + captured).ToString();
|
|
//}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void OnEnter()
|
|
{
|
|
SendGold();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 超时自动确认(使用当前输入值或默认100)
|
|
/// </summary>
|
|
public void AutoConfirm()
|
|
{
|
|
SendGold();
|
|
}
|
|
|
|
private void SendGold()
|
|
{
|
|
if (roomData == null) return;
|
|
int gold = string.IsNullOrEmpty(tmpInput_Coin.text) ? 100 : Convert.ToInt32(tmpInput_Coin.text);
|
|
if (gold < 100) gold = 100;
|
|
WebSocketSendList.SelectGlodChineseChess(roomData.roomId, gold, GameManager.Instance.user.BaseInfo.number);
|
|
}
|
|
}
|