From 0c4df905e3e71f65a62882c783e6f4280b481c84 Mon Sep 17 00:00:00 2001 From: max Date: Mon, 3 Jun 2024 16:18:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=A1=A5=E5=85=85=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=88=BF=E9=97=B4=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chwl/app/game/core/GameStateAbility.kt | 19 ++++++++++++++----- .../ui/game/widgets/queue/GameQueueWidget.kt | 7 ++++++- app/src/module_game/res/values-ar/strings.xml | 1 + .../module_game/res/values-zh-rTW/strings.xml | 1 + app/src/module_game/res/values/strings.xml | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/module_game/java/com/chwl/app/game/core/GameStateAbility.kt b/app/src/module_game/java/com/chwl/app/game/core/GameStateAbility.kt index 9fc490a75..b100fed29 100644 --- a/app/src/module_game/java/com/chwl/app/game/core/GameStateAbility.kt +++ b/app/src/module_game/java/com/chwl/app/game/core/GameStateAbility.kt @@ -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 = MutableStateFlow(STATE_MATCHING) + val gameStateFlow: MutableStateFlow = MutableStateFlow(null) val gameIconFlow = MutableStateFlow(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,8 +148,15 @@ class GameStateAbility : RoomAbility(), GameIMEngineAbility.Listener { logD("onReceiveMessage 麦位变更") val gameInfo = (attachment as? GameQueueChangedAttachment)?.gameInfo ?: return - safeLaunch { - syncQueue(gameInfo) + if (gameInfo.roomId != roomContext?.roomId) { + logD("onReceiveMessage 房间变更") + safeLaunch { + syncRoomInfo(gameInfo) + } + } else { + safeLaunch { + syncQueue(gameInfo) + } } } diff --git a/app/src/module_game/java/com/chwl/app/game/ui/game/widgets/queue/GameQueueWidget.kt b/app/src/module_game/java/com/chwl/app/game/ui/game/widgets/queue/GameQueueWidget.kt index ac6ae078c..23df34fad 100644 --- a/app/src/module_game/java/com/chwl/app/game/ui/game/widgets/queue/GameQueueWidget.kt +++ b/app/src/module_game/java/com/chwl/app/game/ui/game/widgets/queue/GameQueueWidget.kt @@ -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) diff --git a/app/src/module_game/res/values-ar/strings.xml b/app/src/module_game/res/values-ar/strings.xml index d28149914..cf44fd63a 100644 --- a/app/src/module_game/res/values-ar/strings.xml +++ b/app/src/module_game/res/values-ar/strings.xml @@ -2,6 +2,7 @@ جاري المطابقة تمت المطابقة + فشلت المطابقة عملة ذهبية الفوز بمكافأة %s عملة ذهبية ابدأ diff --git a/app/src/module_game/res/values-zh-rTW/strings.xml b/app/src/module_game/res/values-zh-rTW/strings.xml index 03f6cfd98..b2f4a7d28 100644 --- a/app/src/module_game/res/values-zh-rTW/strings.xml +++ b/app/src/module_game/res/values-zh-rTW/strings.xml @@ -3,6 +3,7 @@ 匹配中 匹配成功 + 匹配失敗 金幣 獲勝獎勵%s金幣 開始 diff --git a/app/src/module_game/res/values/strings.xml b/app/src/module_game/res/values/strings.xml index 7bbf6f860..f4392d906 100644 --- a/app/src/module_game/res/values/strings.xml +++ b/app/src/module_game/res/values/strings.xml @@ -2,6 +2,7 @@ Matching Match successful + Match failed gold coins Winning reward %s gold coins Start