diff --git a/app/src/main/java/net/imshit/aircraftwar/gui/GameActivity.kt b/app/src/main/java/net/imshit/aircraftwar/gui/GameActivity.kt index 2b399a4..9de416d 100644 --- a/app/src/main/java/net/imshit/aircraftwar/gui/GameActivity.kt +++ b/app/src/main/java/net/imshit/aircraftwar/gui/GameActivity.kt @@ -1,12 +1,23 @@ package net.imshit.aircraftwar.gui import android.content.Context +import android.content.DialogInterface import android.content.Intent import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.text.InputType import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.content.res.AppCompatResources import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout +import com.google.android.material.textfield.TextInputLayout.END_ICON_CLEAR_TEXT +import net.imshit.aircraftwar.R import net.imshit.aircraftwar.databinding.ActivityGameBinding import net.imshit.aircraftwar.logic.Difficulty import net.imshit.aircraftwar.logic.game.Games @@ -30,7 +41,14 @@ class GameActivity : AppCompatActivity() { gameMode = getSerializableExtra("gameMode", Difficulty::class.java) ?: Difficulty.EASY soundMode = getBooleanExtra("soundMode", true) } - val game: Games = Games.getGames(this, gameMode, soundMode) + val game: Games = Games.getGames(this, gameMode, soundMode).apply { + mainHandle = object : Handler(Looper.getMainLooper()) { + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + onGameOver(gameMode, msg.what) + } + } + } with(ActivityGameBinding.inflate(layoutInflater)) { root.addView(game, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) setContentView(root) @@ -41,4 +59,32 @@ class GameActivity : AppCompatActivity() { hide(WindowInsetsCompat.Type.systemBars()) } } + + private fun onGameOver(gameMode: Difficulty, score: Int) { + val edit = TextInputLayout(this).apply { + setPadding(64, 64, 64, 0) + hint = getString(R.string.game_dialog_content) + startIconDrawable = + AppCompatResources.getDrawable(this@GameActivity, R.drawable.ic_account_circle_24) + endIconMode = END_ICON_CLEAR_TEXT + isCounterEnabled = true + counterMaxLength = 16 + addView(TextInputEditText(context).apply { + inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PERSON_NAME + }) + } + val listener = DialogInterface.OnClickListener { dialog, which -> + when (which) { + DialogInterface.BUTTON_POSITIVE -> { + // TODO: 添加记录 + } + } + ScoreboardActivity.actionStart(this, gameMode) + this@GameActivity.finish() + } + MaterialAlertDialogBuilder(this).setTitle(R.string.game_dialog_title) + .setIcon(R.drawable.ic_assignment_turned_in_24) + .setPositiveButton(android.R.string.ok, listener) + .setNegativeButton(android.R.string.cancel, listener).setView(edit).show() + } } \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt b/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt index 568b0c6..5dc2f57 100644 --- a/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt +++ b/app/src/main/java/net/imshit/aircraftwar/gui/ScoreboardActivity.kt @@ -9,10 +9,9 @@ import net.imshit.aircraftwar.logic.Difficulty class ScoreboardActivity : AppCompatActivity() { companion object { - fun actionStart(context: Context, gameMode: Difficulty, score: Int) { + fun actionStart(context: Context, gameMode: Difficulty) { context.startActivity(Intent(context, ScoreboardActivity::class.java).apply { putExtra("gameMode", gameMode) - putExtra("score", score) }) } } diff --git a/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt b/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt index 30bfbeb..045fd35 100644 --- a/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt +++ b/app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt @@ -5,6 +5,8 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint +import android.os.Handler +import android.os.Message import android.util.AttributeSet import android.view.SurfaceHolder import android.view.SurfaceView @@ -46,6 +48,8 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : context = context, attrs = attrs, soundMode = false ) + var mainHandle: Handler? = null + // utils lateinit var images: ImageManager private val musicStrategy: MusicStrategies = @@ -91,7 +95,7 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : private val enemyListenerLists = listOf>(enemyAircrafts, enemyBullets) private val heroList = mutableListOf() private val drawingElementLists = - listOf(heroList, animations, props, enemyBullets, heroBullets, enemyAircrafts) + listOf(enemyBullets, heroBullets, enemyAircrafts, props, animations, heroList) private val lifeBarElementLists = listOf(heroList, enemyAircrafts) init { @@ -248,6 +252,9 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) : this.musicStrategy.setBgm(BgmType.NONE) this.musicStrategy.playGameOver() this.logicThread.interrupt() + this.mainHandle?.sendMessage(Message.obtain().apply { + what = score + }) } private fun gameStop() { diff --git a/app/src/main/res/drawable-night/ic_assignment_turned_in_24.xml b/app/src/main/res/drawable-night/ic_assignment_turned_in_24.xml new file mode 100644 index 0000000..bc39456 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_assignment_turned_in_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_account_circle_24.xml b/app/src/main/res/drawable/ic_account_circle_24.xml new file mode 100644 index 0000000..8fafa94 --- /dev/null +++ b/app/src/main/res/drawable/ic_account_circle_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_assignment_turned_in_24.xml b/app/src/main/res/drawable/ic_assignment_turned_in_24.xml new file mode 100644 index 0000000..a6a18ed --- /dev/null +++ b/app/src/main/res/drawable/ic_assignment_turned_in_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 7a4f50b..f27a7e9 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -8,6 +8,8 @@ Medium Mode Hard Mode Sound + New record! + Your name Scoreboard Manage Space About diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 894ec99..acd876c 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -8,6 +8,8 @@ 困难模式 音效 得分:%d + 新的游戏记录! + 你的名字 排行榜 关于 管理空间 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 894ec99..acd876c 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -8,6 +8,8 @@ 困难模式 音效 得分:%d + 新的游戏记录! + 你的名字 排行榜 关于 管理空间 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 640187b..889df89 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,6 +6,8 @@ @string/app_name 游戏界面 得分:%d + 新的游戏记录! + 你的名字 排行榜 管理空间 简单模式