123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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)
- {
-
- A__ClickReady();
- _ready = true;
- }
- }
- 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<PageComp>().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<PageComp>().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);
- }
- }
- }
- }
|