|
|
@@ -1,638 +0,0 @@
|
|
|
-package com.adealink.weparty.cocosgame.chat.component
|
|
|
-
|
|
|
-import android.view.Gravity
|
|
|
-import android.view.LayoutInflater
|
|
|
-import android.view.View
|
|
|
-import android.widget.FrameLayout
|
|
|
-import android.widget.TextView
|
|
|
-import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
-import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams
|
|
|
-import androidx.core.view.isVisible
|
|
|
-import androidx.core.view.updateLayoutParams
|
|
|
-import androidx.lifecycle.LifecycleOwner
|
|
|
-import com.adealink.frame.aab.util.getCompatDrawable
|
|
|
-import com.adealink.frame.base.Rlt
|
|
|
-import com.adealink.frame.base.fastLazy
|
|
|
-import com.adealink.frame.effect.listener.IPlayListener
|
|
|
-import com.adealink.frame.effect.view.EffectView
|
|
|
-import com.adealink.frame.log.Log
|
|
|
-import com.adealink.frame.mvvm.view.ViewComponent
|
|
|
-import com.adealink.frame.util.DisplayUtil
|
|
|
-import com.adealink.frame.util.runOnUiThread
|
|
|
-import com.adealink.weparty.R
|
|
|
-import com.adealink.weparty.cocosgame.chat.data.EmotionBubble
|
|
|
-import com.adealink.weparty.cocosgame.chat.data.QuickChatBubble
|
|
|
-import com.adealink.weparty.cocosgame.chat.data.QuickTextBubble
|
|
|
-import com.adealink.weparty.cocosgame.chat.fragment.QuickChatFragment
|
|
|
-import com.adealink.weparty.cocosgame.data.ClickEmotionOpData
|
|
|
-import com.adealink.weparty.cocosgame.data.CocosPosition
|
|
|
-import com.adealink.weparty.cocosgame.data.CocosViewData
|
|
|
-import com.adealink.weparty.cocosgame.data.CocosViewLocation
|
|
|
-import com.adealink.weparty.cocosgame.data.CocosViewSize
|
|
|
-import com.adealink.weparty.cocosgame.data.Game
|
|
|
-import com.adealink.weparty.cocosgame.data.TAG_COCOS_GAME_FLOW
|
|
|
-import com.adealink.weparty.cocosgame.viewmodel.IBaseCocosWebGameViewModel
|
|
|
-import com.adealink.weparty.commonui.ext.gone
|
|
|
-import com.adealink.weparty.commonui.ext.show
|
|
|
-import com.adealink.weparty.commonui.toast.util.showFailedToast
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameEmotionBubbleBottomBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameEmotionBubbleLeftBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameEmotionBubbleRightBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameEmotionBubbleTopBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameQuickTextBubbleBottomBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameQuickTextBubbleLeftBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameQuickTextBubbleRightBinding
|
|
|
-import com.adealink.weparty.databinding.LayoutCocosgameQuickTextBubbleTopBinding
|
|
|
-import com.adealink.weparty.module.emotion.EmotionModule
|
|
|
-import com.adealink.weparty.module.emotion.data.EmotionInfo
|
|
|
-import com.adealink.weparty.module.emotion.data.SendEmotionNotify
|
|
|
-import com.adealink.weparty.module.emotion.effect.EmotionEffectEntity
|
|
|
-import com.adealink.weparty.module.room.RoomModule
|
|
|
-import com.adealink.weparty.module.room.chat.data.EmotionMsgContent
|
|
|
-import com.adealink.weparty.module.room.chat.data.Message
|
|
|
-import com.adealink.weparty.module.room.chat.data.MessageType
|
|
|
-import com.adealink.weparty.module.room.chat.data.QuickMsgContent
|
|
|
-import com.adealink.weparty.module.room.data.SendEmotionScene
|
|
|
-import java.util.LinkedList
|
|
|
-import java.util.Queue
|
|
|
-import kotlin.collections.set
|
|
|
-
|
|
|
-class QuickChatComp(
|
|
|
- lifecycleOwner: LifecycleOwner,
|
|
|
- private val game: Game,
|
|
|
- private val vEmotion: View, //表情按钮
|
|
|
- private val panelContainer: FrameLayout, //表情面板
|
|
|
- private val emotionContainer: ConstraintLayout, //表情气泡容器
|
|
|
- private val cocosViewModel: IBaseCocosWebGameViewModel<*, *, *, *>?
|
|
|
-) : ViewComponent(lifecycleOwner) {
|
|
|
-
|
|
|
- private val chatViewModel by fastLazy { RoomModule.getChatMessageViewModel(requireActivity()) }
|
|
|
- private val emotionViewModel by fastLazy { EmotionModule.getEmotionViewModel(requireActivity()) }
|
|
|
- private var quickChatFragment: QuickChatFragment? = null
|
|
|
-
|
|
|
- //玩家头像位置辅助定位
|
|
|
- private val player2EmotionBubble = HashMap<Long, Pair<CocosViewLocation, View>>(4)
|
|
|
- private val player2QuickTextBubble = HashMap<Long, Pair<CocosViewLocation, View>>(4)
|
|
|
- private val player2BubbleQueue = HashMap<Long, Queue<QuickChatBubble>>(4)
|
|
|
-
|
|
|
- override fun onCreate() {
|
|
|
- super.onCreate()
|
|
|
- initViews()
|
|
|
- observeViewModel()
|
|
|
- }
|
|
|
-
|
|
|
- private fun initViews() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private fun observeViewModel() {
|
|
|
- cocosViewModel?.emotionBtnNodeViewLD?.observe(viewLifecycleOwner) {
|
|
|
- initEmotionBtn(it.position, it.size)
|
|
|
- }
|
|
|
- emotionViewModel?.apply {
|
|
|
- clickedEmotionLD.observeWithoutCache(viewLifecycleOwner) {
|
|
|
- this@QuickChatComp.onEmotionClick(it.first, it.second)
|
|
|
- }
|
|
|
- sendEmotionNotifyLD.observeWithoutCache(viewLifecycleOwner) {
|
|
|
- onEmotionNotify(it)
|
|
|
- }
|
|
|
- }
|
|
|
- chatViewModel?.messageAddLD?.observeWithoutCache(viewLifecycleOwner) {
|
|
|
- it.onEach { msg ->
|
|
|
- if (msg.getMessageType() == MessageType.QUICK_MESSAGE) {
|
|
|
- val quickText = (msg.content as? QuickMsgContent)?.quickText
|
|
|
- if (quickText != null) {
|
|
|
- quickText.senderUid = msg.sendUid
|
|
|
- addQuickChatBubble(QuickTextBubble(msg.sendUid, quickText))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun onEmotionNotify(data: SendEmotionNotify) {
|
|
|
- when (SendEmotionScene.map(data.scene)) {
|
|
|
- SendEmotionScene.UNKNOWN -> {}
|
|
|
- SendEmotionScene.MIC,
|
|
|
- SendEmotionScene.ROOM_CHAT,
|
|
|
- SendEmotionScene.SESSION_DETAIL -> {
|
|
|
- addQuickChatBubble(EmotionBubble(data.fromUid, data.emotionInfo, data.resultIndex))
|
|
|
- }
|
|
|
-
|
|
|
- SendEmotionScene.COCOS_GAME -> {
|
|
|
- chatViewModel?.addMessages(
|
|
|
- listOf(
|
|
|
- Message.crateMessage(
|
|
|
- MessageType.EMOTION,
|
|
|
- EmotionMsgContent(data),
|
|
|
- data.fromUid
|
|
|
- )
|
|
|
- )
|
|
|
- )
|
|
|
- addQuickChatBubble(EmotionBubble(data.fromUid, data.emotionInfo, data.resultIndex))
|
|
|
- }
|
|
|
-
|
|
|
- SendEmotionScene.GAME_PRANK -> {}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun onEmotionClick(emotionInfo: EmotionInfo, scene: SendEmotionScene) {
|
|
|
- val roomId = RoomModule.getJoinedRoomId()
|
|
|
- if (roomId == null || roomId <= 0) {
|
|
|
- return
|
|
|
- }
|
|
|
- emotionViewModel?.sendEmotion(roomId, emotionInfo.id, scene)
|
|
|
- ?.observe(viewLifecycleOwner) { rlt ->
|
|
|
- when (rlt) {
|
|
|
- is Rlt.Success -> hideEmotionQuickTextPanel()
|
|
|
- else -> showFailedToast(rlt)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun switchEmotionQuickTextPanel(data: ClickEmotionOpData) {
|
|
|
- if (isShow()) {
|
|
|
- hideEmotionQuickTextPanel()
|
|
|
- } else {
|
|
|
- initEmotionBtn(data.position, data.size)
|
|
|
- showEmotionQuickTextPanel(data)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun initEmotionBtn(position: CocosPosition, size: CocosViewSize) {
|
|
|
- vEmotion.updateLayoutParams<LayoutParams> {
|
|
|
- width = size.width.toInt()
|
|
|
- height = size.height.toInt()
|
|
|
- leftMargin = (position.x - size.width / 2).toInt()
|
|
|
- bottomMargin = (position.y - size.height / 2).toInt()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun showEmotionQuickTextPanel(data: ClickEmotionOpData) {
|
|
|
- hideEmotionQuickTextPanel()
|
|
|
- quickChatFragment =
|
|
|
- QuickChatFragment.newInstance(data).also {
|
|
|
- it.setHidePanelCallback {
|
|
|
- hideEmotionQuickTextPanel()
|
|
|
- }
|
|
|
- }
|
|
|
- fragmentManager
|
|
|
- .beginTransaction()
|
|
|
- .replace(panelContainer.id, quickChatFragment!!)
|
|
|
- .commitAllowingStateLoss()
|
|
|
- }
|
|
|
-
|
|
|
- fun isShow(): Boolean {
|
|
|
- return quickChatFragment != null
|
|
|
- }
|
|
|
-
|
|
|
- fun hideEmotionQuickTextPanel() {
|
|
|
- quickChatFragment?.let {
|
|
|
- fragmentManager
|
|
|
- .beginTransaction()
|
|
|
- .remove(it)
|
|
|
- .commitAllowingStateLoss()
|
|
|
- }
|
|
|
- quickChatFragment = null
|
|
|
- }
|
|
|
-
|
|
|
- private fun isQuickChatBubbleShow(uid: Long): Boolean {
|
|
|
- val emotionBubbleBinding = player2EmotionBubble[uid]
|
|
|
- if (emotionBubbleBinding != null && emotionBubbleBinding.second.isVisible) {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- val quickTextBubbleBinding = player2QuickTextBubble[uid]
|
|
|
- return quickTextBubbleBinding != null && quickTextBubbleBinding.second.isVisible
|
|
|
- }
|
|
|
-
|
|
|
- private fun addQuickChatBubble(quickChatBubble: QuickChatBubble) {
|
|
|
- val uid = quickChatBubble.uid
|
|
|
- var queue = player2BubbleQueue[uid]
|
|
|
- if (queue == null) {
|
|
|
- queue = LinkedList()
|
|
|
- player2BubbleQueue[uid] = queue
|
|
|
- }
|
|
|
- queue.offer(quickChatBubble)
|
|
|
- if (isQuickChatBubbleShow(uid)) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }
|
|
|
-
|
|
|
- private fun showNextQuickChatBubble(uid: Long) {
|
|
|
- val queue = player2BubbleQueue[uid]
|
|
|
- val bubble = queue?.poll() ?: return
|
|
|
- when (bubble) {
|
|
|
- is EmotionBubble -> showEmotionBubble(bubble)
|
|
|
- is QuickTextBubble -> showQuickTextBubble(bubble)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun showEmotionBubble(bubble: EmotionBubble) {
|
|
|
- Log.d(TAG_COCOS_GAME_FLOW, "showEmotionBubble, $bubble")
|
|
|
- val uid = bubble.uid
|
|
|
- val cacheView = player2EmotionBubble[uid]
|
|
|
- if (cacheView != null) {
|
|
|
- playEmotionBubbleEffect(
|
|
|
- getEmotionEffectView(cacheView.first, cacheView.second),
|
|
|
- bubble,
|
|
|
- onStart = {
|
|
|
- if (isValid) {
|
|
|
- cacheView.second.show()
|
|
|
- }
|
|
|
- },
|
|
|
- onComplete = {
|
|
|
- if (isValid) {
|
|
|
- cacheView.second.gone()
|
|
|
- }
|
|
|
- },
|
|
|
- onError = {
|
|
|
- if (isValid) {
|
|
|
- cacheView.second.gone()
|
|
|
- }
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- cocosViewModel?.getPlayerAvatarView(uid)?.observe(this.lifecycleOwner) {
|
|
|
- Log.d(TAG_COCOS_GAME_FLOW, "getPlayerAvatarView, uid:$uid, data:${it}")
|
|
|
- if (it is Rlt.Success) {
|
|
|
- val position = it.data.position
|
|
|
- val size = it.data.size
|
|
|
- val location = getBubbleLocation(it.data)
|
|
|
-
|
|
|
- //1.添加一个辅助View
|
|
|
- var avatarGuideView = emotionContainer.findViewWithTag<View>("playerAvatar_$uid")
|
|
|
- if (avatarGuideView == null) {
|
|
|
- avatarGuideView = View(context).apply {
|
|
|
- id = View.generateViewId()
|
|
|
- tag = "playerAvatar_$uid"
|
|
|
- background = getCompatDrawable(R.drawable.common_33000000_radius_12_bg)
|
|
|
- }
|
|
|
- emotionContainer.addView(avatarGuideView)
|
|
|
- }
|
|
|
- avatarGuideView.updateLayoutParams<LayoutParams> {
|
|
|
- width = size.width.toInt()
|
|
|
- height = size.height.toInt()
|
|
|
- leftToLeft = LayoutParams.PARENT_ID
|
|
|
- bottomToBottom = LayoutParams.PARENT_ID
|
|
|
- leftMargin = (position.x - size.width / 2).toInt()
|
|
|
- bottomMargin = (position.y - size.height / 2).toInt()
|
|
|
- }
|
|
|
-
|
|
|
- //2.添加气泡
|
|
|
- val bubbleView = when (location) {
|
|
|
- CocosViewLocation.TOP,
|
|
|
- CocosViewLocation.TOP_LEFT,
|
|
|
- CocosViewLocation.TOP_RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleTopBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- leftToLeft = avatarGuideView.id
|
|
|
- rightToRight = avatarGuideView.id
|
|
|
- topToBottom = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.CENTER,
|
|
|
- CocosViewLocation.BOTTOM,
|
|
|
- CocosViewLocation.BOTTOM_LEFT,
|
|
|
- CocosViewLocation.BOTTOM_RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleBottomBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- leftToLeft = avatarGuideView.id
|
|
|
- rightToRight = avatarGuideView.id
|
|
|
- bottomToTop = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.LEFT -> {
|
|
|
- LayoutCocosgameEmotionBubbleLeftBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- leftToRight = avatarGuideView.id
|
|
|
- topToTop = avatarGuideView.id
|
|
|
- bottomToBottom = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleRightBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- rightToLeft = avatarGuideView.id
|
|
|
- topToTop = avatarGuideView.id
|
|
|
- bottomToBottom = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- player2EmotionBubble[uid] = Pair(location, bubbleView)
|
|
|
- playEmotionBubbleEffect(
|
|
|
- getEmotionEffectView(location, bubbleView),
|
|
|
- bubble,
|
|
|
- onStart = {
|
|
|
- if (isValid) {
|
|
|
- bubbleView.show()
|
|
|
- }
|
|
|
- },
|
|
|
- onComplete = {
|
|
|
- if (isValid) {
|
|
|
- bubbleView.gone()
|
|
|
- }
|
|
|
- },
|
|
|
- onError = {
|
|
|
- if (isValid) {
|
|
|
- bubbleView.gone()
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- } else {
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun getEmotionEffectView(location: CocosViewLocation, view: View): EffectView {
|
|
|
- return when (location) {
|
|
|
- CocosViewLocation.TOP,
|
|
|
- CocosViewLocation.TOP_LEFT,
|
|
|
- CocosViewLocation.TOP_RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleTopBinding.bind(view).evEmotion
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.CENTER,
|
|
|
- CocosViewLocation.BOTTOM,
|
|
|
- CocosViewLocation.BOTTOM_LEFT,
|
|
|
- CocosViewLocation.BOTTOM_RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleTopBinding.bind(view).evEmotion
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.LEFT -> {
|
|
|
- LayoutCocosgameEmotionBubbleLeftBinding.bind(view).evEmotion
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.RIGHT -> {
|
|
|
- LayoutCocosgameEmotionBubbleRightBinding.bind(view).evEmotion
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun playEmotionBubbleEffect(
|
|
|
- effectView: EffectView,
|
|
|
- bubble: EmotionBubble,
|
|
|
- onStart: () -> Unit,
|
|
|
- onComplete: () -> Unit,
|
|
|
- onError: () -> Unit
|
|
|
- ) {
|
|
|
- Log.d(TAG_COCOS_GAME_FLOW, "playEmotionBubbleEffect, $bubble")
|
|
|
- val uid = bubble.uid
|
|
|
- val emotion = bubble.emotion
|
|
|
- val effectPath = EmotionModule.getEmotionAnimationResPath(emotion)
|
|
|
- if (effectPath.isNullOrEmpty()) {
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- return
|
|
|
- }
|
|
|
- onStart.invoke()
|
|
|
- effectView.add(
|
|
|
- EmotionEffectEntity(
|
|
|
- path = effectPath,
|
|
|
- emotionInfo = emotion,
|
|
|
- loop = 0,
|
|
|
- resultIndex = bubble.resultIndex,
|
|
|
- showAvatarMask = false,
|
|
|
- showResultOnly = false,
|
|
|
- playListener = object : IPlayListener {
|
|
|
-
|
|
|
- override fun onComplete() {
|
|
|
- onComplete.invoke()
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }
|
|
|
-
|
|
|
- override fun onError(errCode: Int) {
|
|
|
- onError.invoke()
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- private fun showQuickTextBubble(bubble: QuickTextBubble) {
|
|
|
- val uid = bubble.uid
|
|
|
- val cacheView = player2QuickTextBubble[uid]
|
|
|
- if (cacheView != null) {
|
|
|
- showQuickTextBubble(
|
|
|
- getQuickChatTextView(cacheView.first, cacheView.second),
|
|
|
- bubble,
|
|
|
- onStart = {
|
|
|
- if (isValid) {
|
|
|
- cacheView.second.show()
|
|
|
- }
|
|
|
- },
|
|
|
- onComplete = {
|
|
|
- if (isValid) {
|
|
|
- cacheView.second.gone()
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- cocosViewModel?.getPlayerAvatarView(uid)?.observe(this.lifecycleOwner) {
|
|
|
- Log.d(TAG_COCOS_GAME_FLOW, "getPlayerAvatarView, uid:$uid, data:${it}")
|
|
|
- if (it is Rlt.Success) {
|
|
|
- val position = it.data.position
|
|
|
- val size = it.data.size
|
|
|
- val location = getBubbleLocation(it.data)
|
|
|
-
|
|
|
- //1.添加一个辅助View
|
|
|
- var avatarGuideView = emotionContainer.findViewWithTag<View>("playerAvatar_$uid")
|
|
|
- if (avatarGuideView == null) {
|
|
|
- avatarGuideView = View(context).apply {
|
|
|
- id = View.generateViewId()
|
|
|
- tag = "playerAvatar_$uid"
|
|
|
- }
|
|
|
- emotionContainer.addView(avatarGuideView)
|
|
|
- }
|
|
|
- avatarGuideView.updateLayoutParams<LayoutParams> {
|
|
|
- width = size.width.toInt()
|
|
|
- height = size.height.toInt()
|
|
|
- leftToLeft = LayoutParams.PARENT_ID
|
|
|
- bottomToBottom = LayoutParams.PARENT_ID
|
|
|
- leftMargin = (position.x - size.width / 2).toInt()
|
|
|
- bottomMargin = (position.y - size.height / 2).toInt()
|
|
|
- }
|
|
|
-
|
|
|
- //2.添加气泡
|
|
|
- val bubbleView = when (location) {
|
|
|
- CocosViewLocation.TOP,
|
|
|
- CocosViewLocation.TOP_LEFT,
|
|
|
- CocosViewLocation.TOP_RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleTopBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- topToBottom = avatarGuideView.id
|
|
|
- leftToLeft = avatarGuideView.id
|
|
|
- rightToRight = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.BOTTOM,
|
|
|
- CocosViewLocation.CENTER,
|
|
|
- CocosViewLocation.BOTTOM_LEFT,
|
|
|
- CocosViewLocation.BOTTOM_RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleBottomBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- bottomToTop = avatarGuideView.id
|
|
|
- leftToLeft = avatarGuideView.id
|
|
|
- rightToRight = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.LEFT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleLeftBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- leftToRight = avatarGuideView.id
|
|
|
- topToTop = avatarGuideView.id
|
|
|
- bottomToBottom = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleRightBinding.inflate(
|
|
|
- LayoutInflater.from(context),
|
|
|
- emotionContainer,
|
|
|
- true
|
|
|
- ).root.also { root ->
|
|
|
- root.updateLayoutParams<LayoutParams> {
|
|
|
- rightToLeft = avatarGuideView.id
|
|
|
- topToTop = avatarGuideView.id
|
|
|
- bottomToBottom = avatarGuideView.id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- player2QuickTextBubble[uid] = Pair(location, bubbleView)
|
|
|
- showQuickTextBubble(
|
|
|
- getQuickChatTextView(location, bubbleView),
|
|
|
- bubble,
|
|
|
- onStart = {
|
|
|
- if (isValid) {
|
|
|
- bubbleView.show()
|
|
|
- }
|
|
|
- },
|
|
|
- onComplete = {
|
|
|
- if (isValid) {
|
|
|
- bubbleView.gone()
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- } else {
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun getQuickChatTextView(location: CocosViewLocation, view: View): TextView {
|
|
|
- return when (location) {
|
|
|
- CocosViewLocation.TOP,
|
|
|
- CocosViewLocation.TOP_LEFT,
|
|
|
- CocosViewLocation.TOP_RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleTopBinding.bind(view).tvText
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.BOTTOM,
|
|
|
- CocosViewLocation.CENTER,
|
|
|
- CocosViewLocation.BOTTOM_LEFT,
|
|
|
- CocosViewLocation.BOTTOM_RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleBottomBinding.bind(view).tvText
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.LEFT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleLeftBinding.bind(view).tvText
|
|
|
- }
|
|
|
-
|
|
|
- CocosViewLocation.RIGHT -> {
|
|
|
- LayoutCocosgameQuickTextBubbleRightBinding.bind(view).tvText
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun showQuickTextBubble(
|
|
|
- quickChatText: TextView,
|
|
|
- bubble: QuickTextBubble,
|
|
|
- onStart: () -> Unit,
|
|
|
- onComplete: () -> Unit
|
|
|
- ) {
|
|
|
- val uid = bubble.uid
|
|
|
- val text = bubble.quickText
|
|
|
- onStart.invoke()
|
|
|
- quickChatText.text = text.getText()
|
|
|
- runOnUiThread({
|
|
|
- onComplete.invoke()
|
|
|
- showNextQuickChatBubble(uid)
|
|
|
- }, 3000)
|
|
|
- }
|
|
|
-
|
|
|
- private fun getBubbleLocation(data: CocosViewData): CocosViewLocation {
|
|
|
- val l = data.location
|
|
|
- if (l != null) {
|
|
|
- return CocosViewLocation.map(l) ?: CocosViewLocation.BOTTOM
|
|
|
- }
|
|
|
- val position = data.position
|
|
|
- var location = 0
|
|
|
- location = if (position.x > DisplayUtil.getScreenWidth() / 2) {
|
|
|
- location or CocosViewLocation.RIGHT.location
|
|
|
- } else {
|
|
|
- location or CocosViewLocation.LEFT.location
|
|
|
- }
|
|
|
-
|
|
|
- location = if (position.y > DisplayUtil.getScreenHeight() / 2) {
|
|
|
- location or Gravity.BOTTOM
|
|
|
- } else {
|
|
|
- location or Gravity.TOP
|
|
|
- }
|
|
|
- return CocosViewLocation.map(location) ?: CocosViewLocation.BOTTOM
|
|
|
- }
|
|
|
-
|
|
|
- fun clear() {
|
|
|
- player2EmotionBubble.clear()
|
|
|
- player2QuickTextBubble.clear()
|
|
|
- player2BubbleQueue.clear()
|
|
|
- }
|
|
|
-
|
|
|
-}
|