浏览代码

1.添加游戏结算页面

王鹏鹏 1 年之前
父节点
当前提交
3070c93c22

+ 6 - 1
baselib/src/main/java/com/yingyangfly/baselib/utils/RxBusCodes.kt

@@ -26,10 +26,15 @@ object RxBusCodes {
     //加载语音
     const val LoadedVoice = 9006
 
-
     //加载语音
     const val EVALUATE_ORDER = 9007
 
+    //退出游戏
+    const val CALLQUITGAME = 9008
+
+    //退出游戏
+    const val QUITGAME = 9009
+
     /**
      * 游戏计时
      */

+ 10 - 1
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -11,10 +11,14 @@ import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
 import com.yingyangfly.baselib.router.RouterUrlCommon
+import com.yingyangfly.baselib.utils.RxBusCodes
 import com.yingyangfly.game.R
 import com.yingyangfly.game.databinding.ActivityGameIntroductionBinding
 import com.yingyangfly.game.dialog.ExitGameDialog
 import com.yingyangfly.game.entity.GameBean
+import gorden.rxbus2.RxBus
+import gorden.rxbus2.Subscribe
+import gorden.rxbus2.ThreadMode
 
 /**
  * 游戏介绍
@@ -84,7 +88,7 @@ class GameIntroductionActivity :
                     runOnUiThread {
                         val exitGameDialog = ExitGameDialog()
                         exitGameDialog.onDialogClickListener = {
-                            finish()
+                            RxBus.get().send(RxBusCodes.CALLQUITGAME)
                         }
                         exitGameDialog.show(supportFragmentManager, "exitGameDialog")
                     }
@@ -106,4 +110,9 @@ class GameIntroductionActivity :
         }
         return true
     }
+
+    @Subscribe(code = RxBusCodes.QUITGAME, threadMode = ThreadMode.MAIN)
+    fun quitGame() {
+        finish()
+    }
 }

+ 32 - 1
game/src/main/java/com/yingyangfly/game/play/PlayGameActivity.kt

@@ -1,6 +1,7 @@
 package com.yingyangfly.game.play
 
 import android.annotation.SuppressLint
+import android.content.Intent
 import android.os.Build
 import android.os.Bundle
 import android.text.TextUtils
@@ -28,6 +29,9 @@ import com.yingyangfly.game.dialog.GameResultDialog
 import com.yingyangfly.game.entity.GameBean
 import com.yingyangfly.game.entity.GameDataBean
 import com.yingyangfly.game.utils.AndroidToJs
+import gorden.rxbus2.RxBus
+import gorden.rxbus2.Subscribe
+import gorden.rxbus2.ThreadMode
 
 /**
  * 玩游戏页面
@@ -45,6 +49,17 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
         super.onCreate(savedInstanceState)
     }
 
+    override fun onNewIntent(intent: Intent?) {
+        super.onNewIntent(intent)
+        runOnUiThread {
+            binding.webView.evaluateJavascript(
+                "javascript:CallContinueGame()"
+            ) {
+
+            }
+        }
+    }
+
     override fun initViews() {
         if (gameBean != null) {
             val url = gameBean!!.gameUrl + "?startLv=" + gameBean!!.gameLevel + "&maxLv=" +
@@ -118,7 +133,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
         }, success = {
             runOnUiThread {
                 if (TextUtils.equals("2", gameDataBean.isPass)) {
-                    //退出游戏
+                    RxBus.get().send(RxBusCodes.QUITGAME)
                     finish()
                 } else if (TextUtils.equals("3", gameDataBean.isPass)) {
                     //游戏通关
@@ -219,6 +234,11 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
                         binding.webView.evaluateJavascript(
                             "javascript:CallPauseGame()"
                         ) {
+                            ARouter.getInstance().build(RouterUrlCommon.gameIntroduction)
+                                .withString("gameCode", gameBean!!.gameCode)
+                                .withString("playClass", gameBean!!.playClass)
+                                .withTransition(R.anim.leftin, R.anim.leftout)
+                                .navigation(mContext)
                         }
                     }
                 }
@@ -268,4 +288,15 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
             }
         }
     }
+
+    @Subscribe(code = RxBusCodes.CALLQUITGAME, threadMode = ThreadMode.MAIN)
+    fun callQuitGame() {
+        runOnUiThread {
+            binding.webView.evaluateJavascript(
+                "javascript:CallQuitGame()"
+            ) {
+
+            }
+        }
+    }
 }