156 lines
5.3 KiB
C#
156 lines
5.3 KiB
C#
using System.Globalization;
|
|
using Cysharp.Threading.Tasks;
|
|
using Game.Dinosaurs;
|
|
using Game.MVVM.Model;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Game
|
|
{
|
|
[UIType(UIType.GameSceneMainUI)]
|
|
public class GameSceneMainUI : UIBase
|
|
{
|
|
private bool isCanInvestment;
|
|
private float jinBei = 0;
|
|
private IDinosaursGameManager _dinosaursGameManager;
|
|
|
|
public GameSceneMainView view;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
this.view = self.GetComponentInChildren<GameSceneMainView>();
|
|
|
|
this.view.BindingContext = new GameSceneMainViewModel();
|
|
this.view.BindingContext.OnClickHelp += this.ClickHelpButton;
|
|
this.view.BindingContext.OnClickBack += this.ClickBackButton;
|
|
this.view.BindingContext.OnClickInvestment += this.ClickInvestmentButton;
|
|
this.view.BindingContext.OnClickAddRobot += this.ClickAddRobot;
|
|
this.view.BindingContext.OnClickDeleteAllRobot += this.ClickDeleteAllRobot;
|
|
|
|
EventManager.Instance.Subscribe(InitCurrentPlayerDataEventArgs.EventId, InitCurrentPlayerDataEvent);
|
|
EventManager.Instance.Subscribe(BossStartMoveEventArgs.EventId, BossStartMoveEvent);
|
|
EventManager.Instance.Subscribe(PlayerJinBeiChange_ToMainUIEventArgs.EventId, PlayerJinBeiChange_ToMainUIEvent);
|
|
|
|
this.isCanInvestment = true;
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
this.view.BindingContext.OnClickHelp -= this.ClickHelpButton;
|
|
this.view.BindingContext.OnClickBack -= this.ClickBackButton;
|
|
this.view.BindingContext.OnClickInvestment -= this.ClickInvestmentButton;
|
|
EventManager.Instance.Unsubscribe(InitCurrentPlayerDataEventArgs.EventId, InitCurrentPlayerDataEvent);
|
|
EventManager.Instance.Unsubscribe(BossStartMoveEventArgs.EventId, BossStartMoveEvent);
|
|
EventManager.Instance.Unsubscribe(PlayerJinBeiChange_ToMainUIEventArgs.EventId, PlayerJinBeiChange_ToMainUIEvent);
|
|
}
|
|
|
|
public void SetDinosaursGame(IDinosaursGameManager dinosaursGameManager)
|
|
{
|
|
_dinosaursGameManager = dinosaursGameManager;
|
|
}
|
|
|
|
private void PlayerJinBeiChange_ToMainUIEvent(object sender, GameEventArgs e)
|
|
{
|
|
var args = e as PlayerJinBeiChange_ToMainUIEventArgs;
|
|
if (args.player == _dinosaursGameManager.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.view.BindingContext.JinBeiChange(jinbei);
|
|
}
|
|
|
|
|
|
private void ClickDeleteAllRobot()
|
|
{
|
|
EventManager.Instance.FireNow(this, new DeleteAllRobotEventArgs());
|
|
}
|
|
|
|
private void ClickAddRobot()
|
|
{
|
|
EventManager.Instance.FireNow(this, new AddRobotEventArgs());
|
|
}
|
|
|
|
private void ClickInvestmentButton(float f)
|
|
{
|
|
if (!isCanInvestment)
|
|
{
|
|
UnityEngine.Debug.Log("Boss is moving");
|
|
return;
|
|
}
|
|
|
|
if (_dinosaursGameManager.playerManager.currentPlayer.isMoving)
|
|
{
|
|
UnityEngine.Debug.Log("you is moving");
|
|
return;
|
|
}
|
|
|
|
if (_dinosaursGameManager.roomManager.currentRoom == null)
|
|
{
|
|
UnityEngine.Debug.Log("currentRoom is null");
|
|
return;
|
|
}
|
|
|
|
jinBei = f;
|
|
EventManager.Instance.FireNow(this, new PlayerJinBeiChange_ToPlayerEventArgs(_dinosaursGameManager.playerManager.currentPlayer, jinBei, ShowResult));
|
|
}
|
|
|
|
void ShowResult(bool result)
|
|
{
|
|
if (result)
|
|
{
|
|
EventManager.Instance.FireNow(this, new RoomJinBeiChangeEventArgs(_dinosaursGameManager.roomManager.currentRoom, _dinosaursGameManager.playerManager.currentPlayer, this.jinBei));
|
|
UpdateJinBei();
|
|
Debug.Log("投注成功");
|
|
}
|
|
else
|
|
Debug.Log("投注失败");
|
|
|
|
//TODO:
|
|
}
|
|
|
|
private void UpdateJinBei()
|
|
{
|
|
var j = _dinosaursGameManager.playerManager.currentPlayer.playerData.jinbei;
|
|
this.view.BindingContext.JinBeiChange(j);
|
|
this.jinBei = 0;
|
|
}
|
|
|
|
public void UpdateMessage(string message)
|
|
{
|
|
this.view.BindingContext.MessageChange(message);
|
|
}
|
|
|
|
public async UniTask WaitTimeCloseTips()
|
|
{
|
|
//
|
|
await this.view.WaitTimeCloseTips();
|
|
}
|
|
|
|
private void ClickHelpButton()
|
|
{
|
|
Game.uiManager.ShowUI(UIType.GameSceneHelpUI);
|
|
}
|
|
|
|
private void ClickBackButton()
|
|
{
|
|
//TODO:
|
|
EventManager.Instance.FireNow(this, new BackHallSSceneEventArgs(AssetConstPath.Assets_GameRes_Scene_Game));
|
|
}
|
|
}
|
|
} |