157 lines
4.7 KiB
C#
157 lines
4.7 KiB
C#
using Assets.MyGame.Scripts.Net;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static Assets.MyGame.Scripts.Net.WebResponses.ChineseChess.ChineseChessGameClassList;
|
|
|
|
public class HintData
|
|
{
|
|
public ChessGameRoom roomData;
|
|
public int hintType; //1求和2认输
|
|
}
|
|
public class ChineseChessMainPanel : GameMainPanel_Base
|
|
{
|
|
|
|
public Button btn_QiuHe;
|
|
public Button btn_RenShu;
|
|
public ChessGameRoom roomData;
|
|
public static Dictionary<string,ChessGameRoom> dic_RoomData=new Dictionary<string, ChessGameRoom>();
|
|
public Button btn_FanHuiDaTing;
|
|
[Header("Bottom")]
|
|
public TextMeshProUGUI tmp_Name_Bottom;
|
|
public TextMeshProUGUI tmp_CoinCount_Bottom;
|
|
public Image img_Title_Bottom;
|
|
[Header("Top")]
|
|
public TextMeshProUGUI tmp_Name_Top;
|
|
public TextMeshProUGUI tmp_CoinCount_Top;
|
|
public Image img_Title_Top;
|
|
|
|
public void StartGame(string msg)
|
|
{
|
|
|
|
|
|
var va = JsonConvert.DeserializeObject<WebSocketResponseBase<ChessGameRoom>>(msg.ToString());
|
|
ChessGameRoom chessGameRoom = va.arguments[0];
|
|
//UpdateUserData(chessGameRoom);
|
|
//这里要提前设置房间头像金币信息
|
|
switch (chessGameRoom.users.Count)
|
|
{
|
|
case 1:
|
|
{
|
|
//等待加入 文字显示
|
|
tmp_Name_Top.text = "";
|
|
tmp_CoinCount_Top.text = "金币:" + "";
|
|
img_Title_Top.gameObject.SetActive(false);
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
img_Title_Top.gameObject.SetActive(true);
|
|
foreach (var item in chessGameRoom.users)
|
|
{
|
|
if (item.userId == GameManager.Instance.user.id)
|
|
{
|
|
if (item.type == 2)
|
|
{
|
|
subUIManager.ShowAsync(UIPanel.ZGXQSelectCoin, chessGameRoom);
|
|
}
|
|
}
|
|
}
|
|
//subUIManager.ShowAsync(UIPanel.)
|
|
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void UpdateUserData(ChessGameRoom chessGameRoom)
|
|
{
|
|
foreach (var item in chessGameRoom.users)
|
|
{
|
|
if (item.userId == GameManager.Instance.user.id)
|
|
{
|
|
tmp_Name_Bottom.text = item.userName;
|
|
tmp_CoinCount_Bottom.text = "金币:" + item.gold.ToString();
|
|
StartCoroutine(item.DownTexture2d((t2d) =>
|
|
{
|
|
img_Title_Bottom.sprite = Sprite.Create(t2d, new Rect(0, 0, 100, 100), new Vector2(0.5f, 0.5f));
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
tmp_Name_Top.text = item.userName;
|
|
tmp_CoinCount_Top.text = "金币:" + item.gold.ToString();
|
|
StartCoroutine(item.DownTexture2d((t2d) =>
|
|
{
|
|
img_Title_Top.sprite = Sprite.Create(t2d, new Rect(0, 0, 100, 100), new Vector2(0.5f, 0.5f));
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
btn_FanHuiDaTing.onClick.AddListener(() =>
|
|
{
|
|
UIManager.Instance.Close(UIPanel.MainGamePanelZGXQ);
|
|
});
|
|
}
|
|
protected override void OnShow(object args = null)
|
|
{
|
|
base.OnShow(args);
|
|
subUIManager.ShowAsync(UIPanel.ZGXQDistrict, args);
|
|
}
|
|
public void IsShowHint(string id,int type)
|
|
{
|
|
if (GameManager.Instance.user.id!=id)
|
|
{
|
|
subUIManager.ShowAsync(UIPanel.ZGXQHint, new HintData
|
|
{
|
|
roomData = roomData,
|
|
hintType = type
|
|
});
|
|
}
|
|
}
|
|
public void InitRoomData()
|
|
{
|
|
|
|
|
|
btn_QiuHe.onClick.RemoveAllListeners();
|
|
btn_RenShu.onClick.RemoveAllListeners();
|
|
btn_QiuHe.onClick.AddListener(() =>
|
|
{
|
|
WebSocketSendList.GameOperationChineseChess(roomData.roomId,1,GameManager.Instance.user.id);
|
|
|
|
});
|
|
btn_RenShu.onClick.AddListener(() =>
|
|
{
|
|
//WebSocketSendList.GameOperationChineseChess(roomData.roomId, 2, GameManager.Instance.user.id);
|
|
subUIManager.ShowAsync(UIPanel.ZGXQHint, new HintData
|
|
{
|
|
roomData = roomData,
|
|
hintType = 2
|
|
});
|
|
});
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
|
|
}
|
|
protected override void OnHide()
|
|
{
|
|
base.OnHide();
|
|
WebSocketManager.Instance.Close(SocketType.chess);
|
|
Screen.orientation = ScreenOrientation.LandscapeLeft;
|
|
}
|
|
}
|