using System; using Api; using Message; using Plugins.CxShine.page; using UI.BattleRequest; using UI.Common; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; namespace UI { public class PreparePageComp : MonoBehaviour { public Text MyNameText; public Text EnemyNameText; public Text TimeText; public CockUIItemComp MyCockUIComp; public CockUIItemComp EnemyCockUIComp; public DiamondChooseComp DiamondChooseComp; public GameObject GameStartPanel; private int AllTimeSeconds = 10; private string _battleSession; private int _enemyId; private int currentTimeSeconds; private static readonly string ChooseCock = "ChooseCock"; private static readonly string SelectDiamond = "SelectDiamond"; private bool _ready; // private int _selectDiamond; // private bool _gameStarted; public void init(string battleSession, int enemy) { _battleSession = battleSession; _enemyId = enemy; initMyPlayerInfo(); initEnemyInfo(_enemyId); InvokeRepeating(nameof(TrickTimeSecond), 0, 1.0f); DiamondChooseComp.OnDiamondChange += diamond => { // _selectDiamond = diamond; if (_ready) { return; } ApiComp.Instance.MsgInBattle(_battleSession, new MsgContent { contentType = MsgContentType.SelectDiamond, diamond = diamond }); }; } private void initMyPlayerInfo() { MyNameText.text = AccountManager.Instance.selfInfo.name; MyCockUIComp.ModeCockMy(); // 点击更改cock的时候,发送消息 MyCockUIComp.OnCockChanged += () => { ApiComp.Instance.MsgInBattle(_battleSession, new MsgContent { contentType = ChooseCock, cockId = MyCockUIComp.GetSelectCockId(), }); }; } private void TrickTimeSecond() { // if (_gameStarted) // { // TimeText.text = "Start"; // return; // } if (_ready) { TimeText.text = "Ready"; return; } else { currentTimeSeconds += 1; TimeText.text = (AllTimeSeconds - currentTimeSeconds) + ""; } if (currentTimeSeconds == AllTimeSeconds) { _ready = true; A__ClickReady(); } } public void A__ClickReady() { if (_ready) { return; } MyCockUIComp.DisplayReadyImage(); MyCockUIComp.HideSelectPanel(); int selectCockId = MyCockUIComp.GetSelectCockId(); int diamond = DiamondChooseComp.getSelectDiamond(); ApiComp.Instance.PlayerReady(_battleSession, selectCockId, diamond); Invoke(nameof(WaitClose), AllTimeSeconds - currentTimeSeconds + 10f); } private void WaitClose() { // gameObject.GetComponent().A__ClosePage(); } private void initEnemyInfo(int enemyId) { EnemyCockUIComp.ModeCockEnemy(); ApiComp.Instance.QueryPlayerInfo(enemyId, info => { EnemyNameText.text = "" + info.name; }, null); } private void Start() { MessageComp.Instance.OnBattleClientMsg += OnReceivedBattleMsg; MessageComp.Instance.OnBattlePlayerReady += OnBattlePlayerReady; MessageComp.Instance.OnBattleStart += OnBattleStart; HallComp.Instance.CloseLoading(); } private void OnDestroy() { MessageComp.Instance.OnBattleClientMsg -= OnReceivedBattleMsg; MessageComp.Instance.OnBattlePlayerReady -= OnBattlePlayerReady; MessageComp.Instance.OnBattleStart -= OnBattleStart; MessageComp.Instance.ClearMessage(); BattleInviteManager.Instance.ClosePreparePage(); } private void OnBattleStart(MsgContent msgContent) { // _gameStarted = true; GameStartPanel.SetActive(true); DiamondChooseComp.gameStart(); Debug.Log("收到战斗开始的消息了" + msgContent); GetComponent().A__ClosePage(); GameStartJumper.JumpGameScene(msgContent.battleSession); } private void OnBattlePlayerReady(int playerId, MsgContent msgContent) { Debug.Log("Enemy Ready:" + playerId); if (playerId == _enemyId) { EnemyCockUIComp.DisplayReadyImage(); } } private void OnReceivedBattleMsg(int fromPlayer, MsgContent msgContent) { // Debug.Log("收到敌人的消息了" + fromPlayer + ":" + msgContent); // Debug.Log("_enemyId" + _enemyId); // Debug.Log(">>>>>>>>>>>>"); // Debug.Log(msgContent); if (fromPlayer != _enemyId) { Debug.Log("收非常规的消息 enemy:" + _enemyId + "from:" + fromPlayer); return; } if (ChooseCock.Equals(msgContent.contentType)) { // TipsComp.ShowTips("Enemy Choose Cock:" + msgContent.cockId); EnemyCockUIComp.ChangeCook(msgContent.cockId); } else if (SelectDiamond.Equals(msgContent.contentType)) { // TipsComp.ShowTips("Enemy Select Diamond:" + msgContent.diamond); } } } }