feat:补充游戏切换房间逻辑
This commit is contained in:
@@ -10,6 +10,7 @@ import com.chwl.core.im.custom.bean.GameForcedEndAttachment
|
||||
import com.chwl.core.im.custom.bean.GameQueueChangedAttachment
|
||||
import com.chwl.core.support.room.RoomAbility
|
||||
import com.chwl.core.support.room.RoomContext
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.netease.nimlib.sdk.StatusCode
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum
|
||||
@@ -35,10 +36,10 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 游戏状态: 本地定义状态+匹配状态
|
||||
* 游戏状态:
|
||||
* 匹配状态(服务端定义):(0:匹配中、1:匹配成功、2:游戏结束、3:匹配失败)
|
||||
*/
|
||||
val gameStateFlow: MutableStateFlow<Int?> = MutableStateFlow(STATE_MATCHING)
|
||||
val gameStateFlow: MutableStateFlow<Int?> = MutableStateFlow(null)
|
||||
|
||||
val gameIconFlow = MutableStateFlow<String?>(null)
|
||||
|
||||
@@ -114,8 +115,9 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
|
||||
scoresFlow.value = info.data?.scores
|
||||
gameConfigFlow.value = info.data?.configJson
|
||||
matchRoundIdFlow.value = info.data?.matchRoundId
|
||||
syncGameState(info.data?.matchStatus)
|
||||
syncQueue(info)
|
||||
// 最后变更状态
|
||||
syncGameState(info.data?.matchStatus)
|
||||
}
|
||||
|
||||
private fun syncGameState(matchStatus: Int?) {
|
||||
@@ -146,10 +148,17 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener {
|
||||
logD("onReceiveMessage 麦位变更")
|
||||
val gameInfo =
|
||||
(attachment as? GameQueueChangedAttachment)?.gameInfo ?: return
|
||||
if (gameInfo.roomId != roomContext?.roomId) {
|
||||
logD("onReceiveMessage 房间变更")
|
||||
safeLaunch {
|
||||
syncRoomInfo(gameInfo)
|
||||
}
|
||||
} else {
|
||||
safeLaunch {
|
||||
syncQueue(gameInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配失败
|
||||
CustomAttachment.CUSTOM_MSG_MINI_GAME_MATCH_FAILED -> {
|
||||
|
@@ -77,11 +77,16 @@ class GameQueueWidget : FrameLayoutRoomWidget {
|
||||
|
||||
private fun updateState(gameState: Int?) {
|
||||
when (gameState) {
|
||||
1, 2 -> {
|
||||
GameStateAbility.STATE_MATCH_SUCCESS, GameStateAbility.STATE_GAME_END -> {
|
||||
binding.tvState.setText(R.string.match_successfully)
|
||||
binding.ivState.setImageResource(R.drawable.game_ic_vs)
|
||||
}
|
||||
|
||||
GameStateAbility.STATE_MATCH_FAILED -> {
|
||||
binding.tvState.setText(R.string.match_failed)
|
||||
binding.ivState.setImageResource(R.drawable.game_ic_link)
|
||||
}
|
||||
|
||||
else -> {
|
||||
binding.tvState.setText(R.string.matchmaking)
|
||||
binding.ivState.setImageResource(R.drawable.game_ic_link)
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<string name="matchmaking">جاري المطابقة</string>
|
||||
<string name="match_successfully">تمت المطابقة</string>
|
||||
<string name="match_failed">فشلت المطابقة</string>
|
||||
<string name="game_award_tips_coins_text">عملة ذهبية</string>
|
||||
<string name="game_award_tips_format">الفوز بمكافأة %s عملة ذهبية</string>
|
||||
<string name="start">ابدأ</string>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
<string name="matchmaking">匹配中</string>
|
||||
<string name="match_successfully">匹配成功</string>
|
||||
<string name="match_failed">匹配失敗</string>
|
||||
<string name="game_award_tips_coins_text">金幣</string>
|
||||
<string name="game_award_tips_format">獲勝獎勵%s金幣</string>
|
||||
<string name="start">開始</string>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<string name="matchmaking">Matching</string>
|
||||
<string name="match_successfully">Match successful</string>
|
||||
<string name="match_failed">Match failed</string>
|
||||
<string name="game_award_tips_coins_text">gold coins</string>
|
||||
<string name="game_award_tips_format">Winning reward %s gold coins</string>
|
||||
<string name="start">Start</string>
|
||||
|
Reference in New Issue
Block a user