149 lines
5.2 KiB
C#
149 lines
5.2 KiB
C#
using System.Globalization;
|
|
using Cysharp.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Game
|
|
{
|
|
[UIType(UIType.GameSceneMainUI)]
|
|
public class GameSceneMainUI : UIBase
|
|
{
|
|
private Button btn_Back;
|
|
private Button btn_Help;
|
|
private TMP_Dropdown dropdown;
|
|
private Button btn_Investment;
|
|
private TMP_Text txt_Jinbei;
|
|
private TMP_Text txt_Message;
|
|
private Image img_Tips;
|
|
private bool isCanInvestment;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
this.btn_Back = self.transform.FindChildDeep<Button>("btn_Back");
|
|
this.btn_Help = self.transform.FindChildDeep<Button>("btn_Help");
|
|
this.btn_Investment = self.transform.FindChildDeep<Button>("btn_Investment");
|
|
this.dropdown = self.transform.FindChildDeep<TMP_Dropdown>("dropdown");
|
|
this.txt_Jinbei = self.transform.FindChildDeep<TMP_Text>("txt_Jinbei");
|
|
this.txt_Message = self.transform.FindChildDeep<TMP_Text>("txt_Message");
|
|
this.img_Tips = self.transform.FindChildDeep<Image>("img_Tips");
|
|
|
|
img_Tips.gameObject.SetActive(false);
|
|
this.btn_Back.onClick.AddListener(ClickBackButton);
|
|
this.btn_Help.onClick.AddListener(ClickHelpButton);
|
|
this.btn_Investment.onClick.AddListener(ClickInvestmentButton);
|
|
EventManager.Instance.Subscribe(InitCurrentPlayerDataEventArgs.EventId, InitCurrentPlayerDataEvent);
|
|
EventManager.Instance.Subscribe(BossStartMoveEventArgs.EventId, BossStartMoveEvent);
|
|
EventManager.Instance.Subscribe(PlayerJinBeiChange_ToMainUIEventArgs.EventId, PlayerJinBeiChange_ToMainUIEvent);
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
this.btn_Back.onClick.RemoveListener(ClickBackButton);
|
|
this.btn_Help.onClick.RemoveListener(ClickHelpButton);
|
|
this.btn_Investment.onClick.RemoveListener(ClickInvestmentButton);
|
|
EventManager.Instance.Unsubscribe(InitCurrentPlayerDataEventArgs.EventId, InitCurrentPlayerDataEvent);
|
|
EventManager.Instance.Unsubscribe(BossStartMoveEventArgs.EventId, BossStartMoveEvent);
|
|
EventManager.Instance.Unsubscribe(PlayerJinBeiChange_ToMainUIEventArgs.EventId, PlayerJinBeiChange_ToMainUIEvent);
|
|
}
|
|
|
|
private void PlayerJinBeiChange_ToMainUIEvent(object sender, GameEventArgs e)
|
|
{
|
|
var args = e as PlayerJinBeiChange_ToMainUIEventArgs;
|
|
if (args.player == Game.playerManager.currentPlayer)
|
|
{
|
|
this.jinBei = 0;
|
|
this.UpdateJinBei();
|
|
}
|
|
}
|
|
|
|
private void BossStartMoveEvent(object sender, GameEventArgs e)
|
|
{
|
|
var args = e as BossStartMoveEventArgs;
|
|
isCanInvestment = !args.isMoveing;
|
|
}
|
|
|
|
private void InitCurrentPlayerDataEvent(object sender, GameEventArgs e)
|
|
{
|
|
var args = e as InitCurrentPlayerDataEventArgs;
|
|
var jinbei = args.player.playerData.jinbei;
|
|
this.txt_Jinbei.text = jinbei.ToString(CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
private float jinBei = 0;
|
|
|
|
private void ClickInvestmentButton()
|
|
{
|
|
if (!isCanInvestment)
|
|
{
|
|
UnityEngine.Debug.Log("Boss is moving");
|
|
return;
|
|
}
|
|
|
|
if (Game.playerManager.currentPlayer.isMoving)
|
|
{
|
|
UnityEngine.Debug.Log("you is moving");
|
|
return;
|
|
}
|
|
|
|
if (Game.roomManager.currentRoom == null)
|
|
{
|
|
UnityEngine.Debug.Log("currentRoom is null");
|
|
return;
|
|
}
|
|
|
|
jinBei = 0;
|
|
var inputFieldText = this.dropdown.captionText.text;
|
|
if (string.IsNullOrEmpty(inputFieldText))
|
|
return;
|
|
|
|
jinBei = float.Parse(inputFieldText);
|
|
EventManager.Instance.FireNow(this, new PlayerJinBeiChange_ToPlayerEventArgs(Game.playerManager.currentPlayer, jinBei, ShowResult));
|
|
}
|
|
|
|
void ShowResult(bool result)
|
|
{
|
|
if (result)
|
|
{
|
|
EventManager.Instance.FireNow(this, new RoomJinBeiChangeEventArgs(Game.roomManager.currentRoom, Game.playerManager.currentPlayer, this.jinBei));
|
|
UpdateJinBei();
|
|
Debug.Log("投注成功");
|
|
}
|
|
else
|
|
Debug.Log("投注失败");
|
|
|
|
//TODO:
|
|
}
|
|
|
|
private void UpdateJinBei()
|
|
{
|
|
var j = Game.playerManager.currentPlayer.playerData.jinbei;
|
|
this.txt_Jinbei.text = j.ToString("F");
|
|
this.jinBei = 0;
|
|
}
|
|
|
|
public void UpdateMessage(string message)
|
|
{
|
|
this.txt_Message.text = message;
|
|
}
|
|
|
|
public async UniTask WaitTimeCloseTips()
|
|
{
|
|
img_Tips.gameObject.SetActive(true);
|
|
await UniTask.Delay(4000);
|
|
this.img_Tips.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void ClickHelpButton()
|
|
{
|
|
Game.uiManager.ShowUI(UIType.GameSceneHelpUI);
|
|
}
|
|
|
|
private void ClickBackButton()
|
|
{
|
|
//TODO:
|
|
}
|
|
}
|
|
} |