1
This commit is contained in:
@@ -185,7 +185,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: "\u7B49\u5F85\u8BBE\u7F6E\u91D1\u989D0:60"
|
||||
m_text: "\u7B49\u5F85\u73A9\u5BB6\u8FDB\u5165"
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 5d4a713fdd931db4c9ce49f068b54e0a, type: 2}
|
||||
m_sharedMaterial: {fileID: 3593458263369068374, guid: 5d4a713fdd931db4c9ce49f068b54e0a,
|
||||
@@ -395,7 +395,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: "\u7B49\u5F85\u8BBE\u7F6E\u91D1\u989D0:60"
|
||||
m_text: "\u7B49\u5F85\u73A9\u5BB6\u8FDB\u5165"
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 5d4a713fdd931db4c9ce49f068b54e0a, type: 2}
|
||||
m_sharedMaterial: {fileID: 3593458263369068374, guid: 5d4a713fdd931db4c9ce49f068b54e0a,
|
||||
@@ -663,12 +663,16 @@ MonoBehaviour:
|
||||
btn_RenShu: {fileID: 3944003400527962833}
|
||||
btn_HuiQi: {fileID: 7736786247353194216}
|
||||
btn_SheZhi: {fileID: 1337329277101656982}
|
||||
btn_StartGame: {fileID: 7784025018183944699}
|
||||
img_DengDaiZhong: {fileID: 8918328693605437385}
|
||||
btn_FanHuiDaTing: {fileID: 8119276241258304471}
|
||||
tmp_Name_Bottom: {fileID: 125596079223217066}
|
||||
tmp_CoinCount_Bottom: {fileID: 5447871153868539989}
|
||||
tmp_WaitTime_Bottom: {fileID: 6390612456705091986}
|
||||
img_Title_Bottom: {fileID: 4433346702574016089}
|
||||
tmp_Name_Top: {fileID: 394202182545534539}
|
||||
tmp_CoinCount_Top: {fileID: 5805709281203068529}
|
||||
tmp_WaitTime_Top: {fileID: 7342989625873532498}
|
||||
img_Title_Top: {fileID: 5212885171862005544}
|
||||
--- !u!1 &3454273065383728345
|
||||
GameObject:
|
||||
@@ -2151,13 +2155,14 @@ GameObject:
|
||||
- component: {fileID: 14320621407032901}
|
||||
- component: {fileID: 5871214975995360383}
|
||||
- component: {fileID: 8325403799800211823}
|
||||
- component: {fileID: 7784025018183944699}
|
||||
m_Layer: 0
|
||||
m_Name: startGame
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &14320621407032901
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2215,6 +2220,50 @@ MonoBehaviour:
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!114 &7784025018183944699
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7424507310210123598}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Navigation:
|
||||
m_Mode: 3
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 8325403799800211823}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
--- !u!1 &7558497209837568944
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -13,24 +13,39 @@ public class HintData
|
||||
public ChessGameRoom roomData;
|
||||
public int hintType; //1求和2认输
|
||||
}
|
||||
|
||||
public enum CountdownType
|
||||
{
|
||||
WaitPlayer, // 等待玩家进入,超时 → 退出到选房
|
||||
WaitHostStart, // 等待房主开始游戏,超时 → 退出到选房
|
||||
WaitSetCoin, // 等待设置金额,超时 → 退出到选房
|
||||
WaitOpponent, // 等待对手操作,超时 → 自动处理
|
||||
}
|
||||
|
||||
public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
{
|
||||
public Button btn_QiuHe;
|
||||
public Button btn_RenShu;
|
||||
public Button btn_HuiQi;
|
||||
public Button btn_SheZhi;
|
||||
public Button btn_StartGame;
|
||||
public Image img_DengDaiZhong;
|
||||
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 TextMeshProUGUI tmp_WaitTime_Bottom;
|
||||
public Image img_Title_Bottom;
|
||||
[Header("Top")]
|
||||
public TextMeshProUGUI tmp_Name_Top;
|
||||
public TextMeshProUGUI tmp_CoinCount_Top;
|
||||
public TextMeshProUGUI tmp_WaitTime_Top;
|
||||
public Image img_Title_Top;
|
||||
|
||||
private Coroutine waitCountdown;
|
||||
|
||||
public static string FormatGold(long gold)
|
||||
{
|
||||
if (gold >= 100000000)
|
||||
@@ -68,27 +83,49 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
//等待加入 文字显示
|
||||
tmp_Name_Top.text = "ID:";
|
||||
//等待玩家加入
|
||||
tmp_Name_Top.text = "等待玩家进入";
|
||||
tmp_CoinCount_Top.text = "";
|
||||
img_Title_Top.gameObject.SetActive(false);
|
||||
// 上下都显示等待倒计时
|
||||
if (tmp_WaitTime_Bottom != null) tmp_WaitTime_Bottom.text = "等待玩家进入02:00";
|
||||
if (tmp_WaitTime_Top != null) tmp_WaitTime_Top.text = "等待玩家进入02:00";
|
||||
// 默认2分钟
|
||||
StartWaitCountdown(120, CountdownType.WaitPlayer, "等待玩家进入");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
// 玩家已进入,停止等待进入倒计时
|
||||
StopWaitCountdown();
|
||||
img_Title_Top.gameObject.SetActive(true);
|
||||
foreach (var item in chessGameRoom.users)
|
||||
{
|
||||
if (item.userId == GameManager.Instance.user.BaseInfo.number)
|
||||
{
|
||||
if (item.type == 2)
|
||||
{
|
||||
subUIManager.ShowAsync(UIPanel.ZGXQSelectCoin, chessGameRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
//subUIManager.ShowAsync(UIPanel.)
|
||||
|
||||
// 判断是否为房主(房间第一个用户)
|
||||
bool isRoomOwner = chessGameRoom.users.Count > 0
|
||||
&& chessGameRoom.users[0].userId == GameManager.Instance.user.BaseInfo.number;
|
||||
|
||||
if (isRoomOwner)
|
||||
{
|
||||
// 房主:显示开始按钮
|
||||
btn_StartGame.gameObject.SetActive(true);
|
||||
btn_StartGame.onClick.RemoveAllListeners();
|
||||
btn_StartGame.onClick.AddListener(() =>
|
||||
{
|
||||
// 房主点击开始 → 隐藏开始按钮,弹出金币设置
|
||||
btn_StartGame.gameObject.SetActive(false);
|
||||
StopWaitCountdown();
|
||||
subUIManager.ShowAsync(UIPanel.ZGXQSelectCoin, chessGameRoom);
|
||||
StartWaitCountdown(60, CountdownType.WaitSetCoin, "等待设置金额");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// 非房主:隐藏开始按钮
|
||||
btn_StartGame.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// 显示等待房主开始倒计时(60秒)
|
||||
StartWaitCountdown(60, CountdownType.WaitHostStart, "等待房主开始游戏");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -134,8 +171,18 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
protected override void OnShow(object args = null)
|
||||
{
|
||||
base.OnShow(args);
|
||||
// 回到选房间界面时显示等待中
|
||||
if (img_DengDaiZhong != null) img_DengDaiZhong.gameObject.SetActive(true);
|
||||
subUIManager.ShowAsync(UIPanel.ZGXQDistrict, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置金额完毕,隐藏等待中
|
||||
/// </summary>
|
||||
public void OnCoinConfirmed()
|
||||
{
|
||||
if (img_DengDaiZhong != null) img_DengDaiZhong.gameObject.SetActive(false);
|
||||
}
|
||||
public void IsShowHint(string id,int type)
|
||||
{
|
||||
if (GameManager.Instance.user.BaseInfo.number!=id)
|
||||
@@ -149,6 +196,8 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
}
|
||||
public void InitRoomData()
|
||||
{
|
||||
// 游戏已开始,停止所有倒计时
|
||||
StopWaitCountdown();
|
||||
|
||||
|
||||
btn_QiuHe.onClick.RemoveAllListeners();
|
||||
@@ -174,6 +223,63 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始等待倒计时
|
||||
/// </summary>
|
||||
/// <param name="seconds">总秒数</param>
|
||||
/// <param name="type">倒计时类型</param>
|
||||
/// <param name="waitMsg">等待时显示的文字,如"等待玩家进入"</param>
|
||||
public void StartWaitCountdown(int seconds, CountdownType type = CountdownType.WaitPlayer, string waitMsg = null)
|
||||
{
|
||||
if (waitCountdown != null) StopCoroutine(waitCountdown);
|
||||
waitCountdown = StartCoroutine(WaitCountdownRoutine(seconds, type, waitMsg));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止等待倒计时
|
||||
/// </summary>
|
||||
public void StopWaitCountdown()
|
||||
{
|
||||
if (waitCountdown != null)
|
||||
{
|
||||
StopCoroutine(waitCountdown);
|
||||
waitCountdown = null;
|
||||
}
|
||||
if (tmp_WaitTime_Bottom != null) tmp_WaitTime_Bottom.text = "";
|
||||
if (tmp_WaitTime_Top != null) tmp_WaitTime_Top.text = "";
|
||||
}
|
||||
|
||||
private IEnumerator WaitCountdownRoutine(int totalSeconds, CountdownType type, string waitMsg)
|
||||
{
|
||||
int remaining = totalSeconds;
|
||||
while (remaining >= 0)
|
||||
{
|
||||
string timeStr = $"{remaining / 60:D2}:{remaining % 60:D2}";
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
string displayText = string.IsNullOrEmpty(waitMsg) ? timeStr : $"{waitMsg}{timeStr}";
|
||||
if (tmp_WaitTime_Bottom != null)
|
||||
tmp_WaitTime_Bottom.text = displayText;
|
||||
if (tmp_WaitTime_Top != null)
|
||||
tmp_WaitTime_Top.text = displayText;
|
||||
break;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
remaining--;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
// 超时:返回选房间界面
|
||||
subUIManager.CloseAll();
|
||||
WebSocketSendList.GetRoomListChineseChess(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
base.OnHide();
|
||||
|
||||
@@ -11,6 +11,9 @@ public class UIChineseChessSetCoin : SubUIBase
|
||||
public TextMeshProUGUI tmp_CurrGlod;
|
||||
public TMP_InputField tmpInput_Coin;
|
||||
public Button btn_Enter;
|
||||
|
||||
private ChineseChessGameClassList.ChessGameRoom roomData;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -21,13 +24,35 @@ public class UIChineseChessSetCoin : SubUIBase
|
||||
base.Show(args);
|
||||
if (args != null)
|
||||
{
|
||||
var v = (ChineseChessGameClassList.ChessGameRoom)args;
|
||||
roomData = (ChineseChessGameClassList.ChessGameRoom)args;
|
||||
tmp_CurrGlod.text = ChineseChessMainPanel.FormatGold(GameManager.Instance.user.assets.gold);
|
||||
btn_Enter.onClick.RemoveAllListeners();
|
||||
btn_Enter.onClick.AddListener(() =>
|
||||
{
|
||||
WebSocketSendList.SelectGlodChineseChess(v.roomId,Convert.ToInt32( tmpInput_Coin.text)<100?100: Convert.ToInt32(tmpInput_Coin.text),GameManager.Instance.user.BaseInfo.number);
|
||||
});
|
||||
btn_Enter.onClick.AddListener(OnEnter);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnter()
|
||||
{
|
||||
SendGold();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 超时自动确认(使用当前输入值或默认100)
|
||||
/// </summary>
|
||||
public void AutoConfirm()
|
||||
{
|
||||
SendGold();
|
||||
}
|
||||
|
||||
private void SendGold()
|
||||
{
|
||||
if (roomData == null) return;
|
||||
int gold = string.IsNullOrEmpty(tmpInput_Coin.text) ? 100 : Convert.ToInt32(tmpInput_Coin.text);
|
||||
if (gold < 100) gold = 100;
|
||||
WebSocketSendList.SelectGlodChineseChess(roomData.roomId, gold, GameManager.Instance.user.BaseInfo.number);
|
||||
|
||||
// 设置金额完毕,隐藏等待中
|
||||
if (uIManager != null && uIManager.parentUIBase is ChineseChessMainPanel mainPanel)
|
||||
mainPanel.OnCoinConfirmed();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user