mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 07:55:21 +01:00
Adjust XP progress bar position and add level badge to pause menu
This commit is contained in:
parent
5c10c6d051
commit
3e22d1c863
4 changed files with 160 additions and 39 deletions
|
@ -322,26 +322,26 @@ class MainActivity : AppCompatActivity() {
|
||||||
// Show progression screen first with XP animation
|
// Show progression screen first with XP animation
|
||||||
binding.gameOverContainer.visibility = View.GONE
|
binding.gameOverContainer.visibility = View.GONE
|
||||||
progressionScreen.visibility = View.VISIBLE
|
progressionScreen.visibility = View.VISIBLE
|
||||||
progressionScreen.showProgress(progressionManager, xpGained, newRewards)
|
progressionScreen.applyTheme(currentTheme)
|
||||||
|
progressionScreen.showProgress(progressionManager, xpGained, newRewards, currentTheme)
|
||||||
|
|
||||||
// Override the continue button behavior if high score needs to be shown
|
// Override the continue button behavior if high score needs to be shown
|
||||||
val originalOnContinue = progressionScreen.onContinue
|
val originalOnContinue = progressionScreen.onContinue
|
||||||
|
|
||||||
// Check if this is a high score
|
progressionScreen.onContinue = {
|
||||||
if (highScoreManager.isHighScore(score)) {
|
// If this is a high score, show high score entry screen
|
||||||
showingHighScore = true
|
if (highScoreManager.isHighScore(score)) {
|
||||||
|
showingHighScore = true
|
||||||
|
showHighScoreEntry(score)
|
||||||
|
} else {
|
||||||
|
// Just show game over screen normally
|
||||||
|
progressionScreen.visibility = View.GONE
|
||||||
|
binding.gameOverContainer.visibility = View.VISIBLE
|
||||||
|
|
||||||
// Set a special onContinue that launches high score entry
|
// Update theme selector if new themes were unlocked
|
||||||
progressionScreen.onContinue = {
|
if (newRewards.any { it.contains("Theme") }) {
|
||||||
val intent = Intent(this, HighScoreEntryActivity::class.java).apply {
|
updateThemeSelector()
|
||||||
putExtra("score", score)
|
|
||||||
putExtra("level", currentLevel)
|
|
||||||
}
|
}
|
||||||
// Use the launcher instead of startActivity
|
|
||||||
highScoreEntryLauncher.launch(intent)
|
|
||||||
|
|
||||||
// Restore original onContinue for next time
|
|
||||||
progressionScreen.onContinue = originalOnContinue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +349,18 @@ class MainActivity : AppCompatActivity() {
|
||||||
vibrate(VibrationEffect.EFFECT_DOUBLE_CLICK)
|
vibrate(VibrationEffect.EFFECT_DOUBLE_CLICK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show high score entry screen
|
||||||
|
*/
|
||||||
|
private fun showHighScoreEntry(score: Int) {
|
||||||
|
val intent = Intent(this, HighScoreEntryActivity::class.java).apply {
|
||||||
|
putExtra("score", score)
|
||||||
|
putExtra("level", currentLevel)
|
||||||
|
}
|
||||||
|
// Use the launcher instead of startActivity
|
||||||
|
highScoreEntryLauncher.launch(intent)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide game over screen
|
* Hide game over screen
|
||||||
*/
|
*/
|
||||||
|
@ -365,6 +377,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
binding.pauseStartButton.visibility = View.VISIBLE
|
binding.pauseStartButton.visibility = View.VISIBLE
|
||||||
binding.resumeButton.visibility = View.GONE
|
binding.resumeButton.visibility = View.GONE
|
||||||
|
|
||||||
|
// Update level badge
|
||||||
|
binding.pauseLevelBadge.setLevel(progressionManager.getPlayerLevel())
|
||||||
|
binding.pauseLevelBadge.setThemeColor(getThemeColor(currentTheme))
|
||||||
|
|
||||||
// Update theme selector
|
// Update theme selector
|
||||||
updateThemeSelector()
|
updateThemeSelector()
|
||||||
}
|
}
|
||||||
|
@ -490,8 +506,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
*/
|
*/
|
||||||
private fun updateThemeSelector() {
|
private fun updateThemeSelector() {
|
||||||
binding.themeSelector.updateThemes(
|
binding.themeSelector.updateThemes(
|
||||||
progressionManager.getUnlockedThemes(),
|
unlockedThemes = progressionManager.getUnlockedThemes(),
|
||||||
currentTheme
|
currentTheme = currentTheme
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,6 +556,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply theme to progression screen if it's visible and initialized
|
||||||
|
if (::progressionScreen.isInitialized && progressionScreen.visibility == View.VISIBLE) {
|
||||||
|
progressionScreen.applyTheme(themeId)
|
||||||
|
}
|
||||||
|
|
||||||
// Update the game view to apply theme
|
// Update the game view to apply theme
|
||||||
gameView.invalidate()
|
gameView.invalidate()
|
||||||
}
|
}
|
||||||
|
@ -559,4 +580,19 @@ class MainActivity : AppCompatActivity() {
|
||||||
val prefs = getSharedPreferences("mintris_settings", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("mintris_settings", Context.MODE_PRIVATE)
|
||||||
return prefs.getString("selected_theme", PlayerProgressionManager.THEME_CLASSIC) ?: PlayerProgressionManager.THEME_CLASSIC
|
return prefs.getString("selected_theme", PlayerProgressionManager.THEME_CLASSIC) ?: PlayerProgressionManager.THEME_CLASSIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the appropriate color for the current theme
|
||||||
|
*/
|
||||||
|
private fun getThemeColor(themeId: String): Int {
|
||||||
|
return when (themeId) {
|
||||||
|
PlayerProgressionManager.THEME_CLASSIC -> Color.WHITE
|
||||||
|
PlayerProgressionManager.THEME_NEON -> Color.parseColor("#FF00FF")
|
||||||
|
PlayerProgressionManager.THEME_MONOCHROME -> Color.LTGRAY
|
||||||
|
PlayerProgressionManager.THEME_RETRO -> Color.parseColor("#FF5A5F")
|
||||||
|
PlayerProgressionManager.THEME_MINIMALIST -> Color.BLACK
|
||||||
|
PlayerProgressionManager.THEME_GALAXY -> Color.parseColor("#66FCF1")
|
||||||
|
else -> Color.WHITE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
67
app/src/main/java/com/mintris/ui/LevelBadge.kt
Normal file
67
app/src/main/java/com/mintris/ui/LevelBadge.kt
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package com.mintris.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom view for displaying the player's level in a fancy badge style
|
||||||
|
*/
|
||||||
|
class LevelBadge @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = 0
|
||||||
|
) : View(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val badgePaint = Paint().apply {
|
||||||
|
color = Color.WHITE
|
||||||
|
isAntiAlias = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private val textPaint = Paint().apply {
|
||||||
|
color = Color.BLACK
|
||||||
|
isAntiAlias = true
|
||||||
|
textAlign = Paint.Align.CENTER
|
||||||
|
textSize = 48f
|
||||||
|
isFakeBoldText = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private var level = 1
|
||||||
|
private var themeColor = Color.WHITE
|
||||||
|
|
||||||
|
fun setLevel(newLevel: Int) {
|
||||||
|
level = newLevel
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setThemeColor(color: Int) {
|
||||||
|
themeColor = color
|
||||||
|
badgePaint.color = color
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
// Adjust text size based on view size
|
||||||
|
textPaint.textSize = h * 0.6f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
|
||||||
|
// Draw badge circle
|
||||||
|
val radius = (width.coerceAtMost(height) / 2f) * 0.9f
|
||||||
|
canvas.drawCircle(width / 2f, height / 2f, radius, badgePaint)
|
||||||
|
|
||||||
|
// Draw level text
|
||||||
|
canvas.drawText(
|
||||||
|
level.toString(),
|
||||||
|
width / 2f,
|
||||||
|
height / 2f + (textPaint.textSize / 3),
|
||||||
|
textPaint
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,21 +23,15 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
|
|
||||||
// Paints for drawing
|
// Paints for drawing
|
||||||
private val backgroundPaint = Paint().apply {
|
private val backgroundPaint = Paint().apply {
|
||||||
color = Color.parseColor("#383838")
|
color = Color.BLACK
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private val progressPaint = Paint().apply {
|
private val progressPaint = Paint().apply {
|
||||||
color = Color.parseColor("#50C878") // Emerald green
|
color = Color.WHITE
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private val progressGlowPaint = Paint().apply {
|
|
||||||
color = Color.parseColor("#70F098") // Lighter emerald for glow
|
|
||||||
isAntiAlias = true
|
|
||||||
setShadowLayer(10f, 0f, 0f, Color.parseColor("#50C878"))
|
|
||||||
}
|
|
||||||
|
|
||||||
private val textPaint = Paint().apply {
|
private val textPaint = Paint().apply {
|
||||||
color = Color.WHITE
|
color = Color.WHITE
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
|
@ -46,7 +40,7 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private val levelBadgePaint = Paint().apply {
|
private val levelBadgePaint = Paint().apply {
|
||||||
color = Color.parseColor("#FFD700") // Gold color for level badge
|
color = Color.WHITE
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +72,9 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
private var levelUpAnimator: ValueAnimator? = null
|
private var levelUpAnimator: ValueAnimator? = null
|
||||||
private var levelBadgeScale = 1f
|
private var levelBadgeScale = 1f
|
||||||
|
|
||||||
|
// Theme-related properties
|
||||||
|
private var themeColor = Color.WHITE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the player's current level and XP values
|
* Set the player's current level and XP values
|
||||||
*/
|
*/
|
||||||
|
@ -97,6 +94,15 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set theme color for elements
|
||||||
|
*/
|
||||||
|
fun setThemeColor(color: Int) {
|
||||||
|
themeColor = color
|
||||||
|
levelBadgePaint.color = color
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animate adding XP to the bar
|
* Animate adding XP to the bar
|
||||||
*/
|
*/
|
||||||
|
@ -173,8 +179,9 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
|
|
||||||
// Update progress bar dimensions based on view size
|
// Update progress bar dimensions based on view size
|
||||||
val verticalPadding = h * 0.2f
|
val verticalPadding = h * 0.2f
|
||||||
|
// Increase left margin to prevent level badge from being cut off
|
||||||
backgroundRect.set(
|
backgroundRect.set(
|
||||||
h * 0.5f, // Left margin = height/2 (for level badge)
|
h * 0.6f, // Increased from 0.5f to 0.6f for more space
|
||||||
verticalPadding,
|
verticalPadding,
|
||||||
w - paddingRight.toFloat(),
|
w - paddingRight.toFloat(),
|
||||||
h - verticalPadding
|
h - verticalPadding
|
||||||
|
@ -188,9 +195,9 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
|
|
||||||
// Draw level badge
|
// Draw level badge with adjusted position
|
||||||
val badgeRadius = height * 0.3f * levelBadgeScale
|
val badgeRadius = height * 0.3f * levelBadgeScale
|
||||||
val badgeCenterX = height * 0.25f
|
val badgeCenterX = height * 0.35f // Adjusted from 0.25f to 0.35f to match new position
|
||||||
val badgeCenterY = height * 0.5f
|
val badgeCenterY = height * 0.5f
|
||||||
|
|
||||||
canvas.drawCircle(badgeCenterX, badgeCenterY, badgeRadius, levelBadgePaint)
|
canvas.drawCircle(badgeCenterX, badgeCenterY, badgeRadius, levelBadgePaint)
|
||||||
|
@ -214,9 +221,6 @@ class XPProgressBar @JvmOverloads constructor(
|
||||||
|
|
||||||
// Only draw if there is progress to show
|
// Only draw if there is progress to show
|
||||||
if (progressRect.width() > 0) {
|
if (progressRect.width() > 0) {
|
||||||
// Draw glow effect first
|
|
||||||
canvas.drawRoundRect(progressRect, cornerRadius, cornerRadius, progressGlowPaint)
|
|
||||||
|
|
||||||
// Draw actual progress bar
|
// Draw actual progress bar
|
||||||
canvas.drawRoundRect(progressRect, cornerRadius, cornerRadius, progressPaint)
|
canvas.drawRoundRect(progressRect, cornerRadius, cornerRadius, progressPaint)
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,14 +255,28 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/settings"
|
android:orientation="horizontal"
|
||||||
android:textColor="@color/white"
|
android:gravity="center"
|
||||||
android:textSize="24sp"
|
android:layout_marginBottom="32dp">
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_marginBottom="32dp" />
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/settings"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginEnd="16dp" />
|
||||||
|
|
||||||
|
<com.mintris.ui.LevelBadge
|
||||||
|
android:id="@+id/pauseLevelBadge"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue