|
|
@@ -13,6 +13,7 @@ import android.webkit.WebSettings
|
|
|
import android.webkit.WebView
|
|
|
import android.webkit.WebViewClient
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
@@ -24,6 +25,7 @@ import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
import com.yingyangfly.game.R
|
|
|
import com.yingyangfly.game.databinding.ActivityPlayGameBinding
|
|
|
+import com.yingyangfly.game.dialog.ExitGameDialog
|
|
|
import com.yingyangfly.game.dialog.GameResultDialog
|
|
|
import com.yingyangfly.game.entity.GameBean
|
|
|
import com.yingyangfly.game.entity.GameDataBean
|
|
|
@@ -39,9 +41,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
private var gameBean: GameBean? = null
|
|
|
private lateinit var webSettings: WebSettings
|
|
|
private var gameResultDialog: GameResultDialog? = null
|
|
|
- private var gameScore = ""
|
|
|
- private var gameLevel = ""
|
|
|
- private var gameTime = ""
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
gameBean = intent.getSerializableExtra("bean") as GameBean
|
|
|
@@ -79,7 +78,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
binding.tvTime.post {
|
|
|
if (TextUtils.isEmpty(it).not()) {
|
|
|
binding.tvTime.text = it
|
|
|
- gameTime = it
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -88,7 +86,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
binding.tvScore.post {
|
|
|
if (TextUtils.isEmpty(it).not()) {
|
|
|
binding.tvScore.text = it
|
|
|
- gameScore = it
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -97,7 +94,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
binding.tvGameLevel.post {
|
|
|
if (TextUtils.isEmpty(it).not()) {
|
|
|
binding.tvGameLevel.text = "第" + it + "关"
|
|
|
- gameLevel = it
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -108,7 +104,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
Log.e("wpp", it)
|
|
|
val gameDataBean = GsonUtil.GsonToBean(it, GameDataBean::class.java)
|
|
|
if (gameDataBean != null) {
|
|
|
- saveData(gameDataBean, "2")
|
|
|
+ saveData(gameDataBean)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -118,18 +114,23 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
/**
|
|
|
* 保存游戏进度
|
|
|
*/
|
|
|
- private fun saveData(gameDataBean: GameDataBean, type: String) {
|
|
|
+ private fun saveData(gameDataBean: GameDataBean) {
|
|
|
viewModel.saveGameRecord(gameBean!!.gameCode, gameBean!!.playClass, gameDataBean, fail = {
|
|
|
- runOnUiThread {
|
|
|
- if (TextUtils.equals("1", type)) {
|
|
|
- finish()
|
|
|
- }
|
|
|
- }
|
|
|
+ it.toast()
|
|
|
}, success = {
|
|
|
runOnUiThread {
|
|
|
- if (TextUtils.equals("1", type)) {
|
|
|
+ if (TextUtils.equals("2", gameDataBean.isPass)) {
|
|
|
+ //退出游戏
|
|
|
finish()
|
|
|
+ } else if (TextUtils.equals("3", gameDataBean.isPass)) {
|
|
|
+ //游戏通关
|
|
|
+ ARouter.getInstance().build(RouterUrlCommon.playGame)
|
|
|
+ .withString("gameCode", gameBean!!.gameCode)
|
|
|
+ .withString("playClass", gameBean!!.playClass)
|
|
|
+ .withTransition(R.anim.leftin, R.anim.leftout)
|
|
|
+ .navigation(mContext)
|
|
|
} else {
|
|
|
+ //游戏成功/失败
|
|
|
gameResultDialog = GameResultDialog()
|
|
|
gameResultDialog?.setData(
|
|
|
gameDataBean.curLevel,
|
|
|
@@ -179,7 +180,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
binding.webView.isDrawingCacheEnabled = true
|
|
|
binding.webView.buildDrawingCache()
|
|
|
binding.webView.buildLayer()
|
|
|
-
|
|
|
binding.webView.webViewClient = object : WebViewClient() {
|
|
|
override fun shouldOverrideUrlLoading(
|
|
|
view: WebView?,
|
|
|
@@ -218,13 +218,17 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
if (v.id == R.id.tvPause) {
|
|
|
runOnUiThread {
|
|
|
- val gameDataBean = GameDataBean().apply {
|
|
|
- curLevel = gameLevel
|
|
|
- curLevelScore = gameScore
|
|
|
- curLevelTime = gameTime
|
|
|
- isPass = "1"
|
|
|
+ val exitGameDialog = ExitGameDialog()
|
|
|
+ exitGameDialog.onDialogClickListener = {
|
|
|
+ if (TextUtils.equals("1", it)) {
|
|
|
+ //暂停游戏
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //退出游戏
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- saveData(gameDataBean, "1")
|
|
|
+ exitGameDialog.show(supportFragmentManager, "exitGameDialog")
|
|
|
}
|
|
|
}
|
|
|
}
|