From 68e8cb160f06f7fbd951036d6e49253ff25a6261 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Sat, 29 Mar 2025 01:59:14 -0400 Subject: [PATCH] fix: theme colors and UI improvements --- app/src/main/java/com/mintris/MainActivity.kt | 135 +++++++++--------- .../main/java/com/mintris/game/GameView.kt | 23 +++ .../main/java/com/mintris/game/TitleScreen.kt | 44 ++++-- 3 files changed, 124 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/com/mintris/MainActivity.kt b/app/src/main/java/com/mintris/MainActivity.kt index c084f6c..3e94bac 100644 --- a/app/src/main/java/com/mintris/MainActivity.kt +++ b/app/src/main/java/com/mintris/MainActivity.kt @@ -91,6 +91,14 @@ class MainActivity : AppCompatActivity() { themeSelector = binding.themeSelector blockSkinSelector = binding.blockSkinSelector + // Set up progression screen + progressionScreen = binding.progressionScreen + progressionScreen.visibility = View.GONE + progressionScreen.onContinue = { + progressionScreen.visibility = View.GONE + binding.gameOverContainer.visibility = View.VISIBLE + } + // Load and apply theme preference currentTheme = progressionManager.getSelectedTheme() applyTheme(currentTheme) @@ -109,14 +117,6 @@ class MainActivity : AppCompatActivity() { gameView.setGameBoard(gameBoard) gameView.setHaptics(gameHaptics) - // Set up progression screen - progressionScreen = binding.progressionScreen - progressionScreen.visibility = View.GONE - progressionScreen.onContinue = { - progressionScreen.visibility = View.GONE - binding.gameOverContainer.visibility = View.VISIBLE - } - // Set up theme selector themeSelector.onThemeSelected = { themeId: String -> // Apply the new theme @@ -358,10 +358,7 @@ class MainActivity : AppCompatActivity() { var showingHighScore = false // Show progression screen first with XP animation - binding.gameOverContainer.visibility = View.GONE - progressionScreen.visibility = View.VISIBLE - progressionScreen.applyTheme(currentTheme) - progressionScreen.showProgress(progressionManager, xpGained, newRewards, currentTheme) + showProgressionScreen(xpGained, newRewards) // Override the continue button behavior if high score needs to be shown val originalOnContinue = progressionScreen.onContinue @@ -593,63 +590,55 @@ class MainActivity : AppCompatActivity() { * Apply a theme to the game */ private fun applyTheme(themeId: String) { - // Only apply if the theme is unlocked - if (!progressionManager.isThemeUnlocked(themeId)) return - - // Save the selected theme currentTheme = themeId + val themeColor = 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 + } + + // Get background color for the theme + val backgroundColor = when (themeId) { + PlayerProgressionManager.THEME_CLASSIC -> Color.BLACK + PlayerProgressionManager.THEME_NEON -> Color.parseColor("#0D0221") + PlayerProgressionManager.THEME_MONOCHROME -> Color.parseColor("#1A1A1A") + PlayerProgressionManager.THEME_RETRO -> Color.parseColor("#3F2832") + PlayerProgressionManager.THEME_MINIMALIST -> Color.WHITE + PlayerProgressionManager.THEME_GALAXY -> Color.parseColor("#0B0C10") + else -> Color.BLACK + } + + // Apply background color to root view + binding.root.setBackgroundColor(backgroundColor) + + // Apply theme color to title screen + titleScreen.setThemeColor(themeColor) + titleScreen.setBackgroundColor(backgroundColor) + + // Apply theme color to game over screen + binding.gameOverContainer.setBackgroundColor(backgroundColor) + binding.gameOverText.setTextColor(themeColor) + binding.scoreText.setTextColor(themeColor) + binding.currentLevelText.setTextColor(themeColor) + binding.linesText.setTextColor(themeColor) + binding.comboText.setTextColor(themeColor) + binding.playAgainButton.setTextColor(themeColor) + binding.playAgainButton.setBackgroundResource(android.R.color.transparent) + binding.playAgainButton.setTextSize(24f) + + // Apply theme to progression screen (it will handle its own colors) + progressionScreen.applyTheme(themeId) + + // Apply theme color to game view + gameView.setThemeColor(themeColor) + gameView.setBackgroundColor(backgroundColor) + + // Save theme preference progressionManager.setSelectedTheme(themeId) - - // Apply theme to title screen if it's visible - if (titleScreen.visibility == View.VISIBLE) { - titleScreen.applyTheme(themeId) - } - - // Apply theme colors based on theme ID - when (themeId) { - PlayerProgressionManager.THEME_CLASSIC -> { - // Default black theme - binding.root.setBackgroundColor(Color.BLACK) - } - PlayerProgressionManager.THEME_NEON -> { - // Neon theme with dark purple background - binding.root.setBackgroundColor(Color.parseColor("#0D0221")) - } - PlayerProgressionManager.THEME_MONOCHROME -> { - // Monochrome dark gray - binding.root.setBackgroundColor(Color.parseColor("#1A1A1A")) - } - PlayerProgressionManager.THEME_RETRO -> { - // Retro arcade theme - binding.root.setBackgroundColor(Color.parseColor("#3F2832")) - } - PlayerProgressionManager.THEME_MINIMALIST -> { - // Minimalist white theme - binding.root.setBackgroundColor(Color.WHITE) - - // Update text colors for visibility - binding.scoreText.setTextColor(Color.BLACK) - binding.currentLevelText.setTextColor(Color.BLACK) - binding.linesText.setTextColor(Color.BLACK) - binding.comboText.setTextColor(Color.BLACK) - } - PlayerProgressionManager.THEME_GALAXY -> { - // Galaxy dark blue theme - binding.root.setBackgroundColor(Color.parseColor("#0B0C10")) - } - } - - // Apply theme to progression screen if it's visible and initialized - if (::progressionScreen.isInitialized && progressionScreen.visibility == View.VISIBLE) { - progressionScreen.applyTheme(themeId) - } - - // Apply theme color to the stats button - val textColor = getThemeColor(currentTheme) - binding.statsButton.setTextColor(textColor) - - // Update the game view to apply theme - gameView.invalidate() } /** @@ -745,4 +734,16 @@ class MainActivity : AppCompatActivity() { } return super.onKeyDown(keyCode, event) } + + private fun showProgressionScreen(xpGained: Long, newRewards: List) { + // Apply theme before showing the screen + progressionScreen.applyTheme(currentTheme) + + // Show the progression screen + binding.gameOverContainer.visibility = View.GONE + progressionScreen.visibility = View.VISIBLE + + // Display progression data + progressionScreen.showProgress(progressionManager, xpGained, newRewards, currentTheme) + } } \ No newline at end of file diff --git a/app/src/main/java/com/mintris/game/GameView.kt b/app/src/main/java/com/mintris/game/GameView.kt index e4d7625..1095af8 100644 --- a/app/src/main/java/com/mintris/game/GameView.kt +++ b/app/src/main/java/com/mintris/game/GameView.kt @@ -153,6 +153,7 @@ class GameView @JvmOverloads constructor( // Block skin private var currentBlockSkin: String = "block_skin_1" private val blockSkinPaints = mutableMapOf() + private var currentThemeColor = Color.WHITE private enum class Direction { HORIZONTAL, VERTICAL @@ -1050,4 +1051,26 @@ class GameView @JvmOverloads constructor( } pulseAnimator?.start() } + + /** + * Set the theme color for the game view + */ + fun setThemeColor(color: Int) { + currentThemeColor = color + blockPaint.color = color + ghostBlockPaint.color = color + glowPaint.color = color + blockGlowPaint.color = color + borderGlowPaint.color = color + pulsePaint.color = color + invalidate() + } + + /** + * Set the background color for the game view + */ + override fun setBackgroundColor(color: Int) { + super.setBackgroundColor(color) + invalidate() + } } diff --git a/app/src/main/java/com/mintris/game/TitleScreen.kt b/app/src/main/java/com/mintris/game/TitleScreen.kt index 4c7a80f..34627f7 100644 --- a/app/src/main/java/com/mintris/game/TitleScreen.kt +++ b/app/src/main/java/com/mintris/game/TitleScreen.kt @@ -46,8 +46,9 @@ class TitleScreen @JvmOverloads constructor( // Callback for when the user touches the screen var onStartGame: (() -> Unit)? = null - // Theme color + // Theme color and background color private var themeColor = Color.WHITE + private var backgroundColor = Color.BLACK // Define tetromino shapes (I, O, T, S, Z, J, L) private val tetrominoShapes = arrayOf( @@ -110,7 +111,7 @@ class TitleScreen @JvmOverloads constructor( init { // Title text settings titlePaint.apply { - color = Color.WHITE + color = themeColor textSize = 120f textAlign = Paint.Align.CENTER typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD) @@ -119,7 +120,7 @@ class TitleScreen @JvmOverloads constructor( // "Touch to start" text settings promptPaint.apply { - color = Color.WHITE + color = themeColor textSize = 50f textAlign = Paint.Align.CENTER typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL) @@ -129,7 +130,7 @@ class TitleScreen @JvmOverloads constructor( // High scores text settings highScorePaint.apply { - color = Color.WHITE + color = themeColor textSize = 70f textAlign = Paint.Align.LEFT // Changed to LEFT alignment typeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL) // Changed to monospace @@ -137,16 +138,16 @@ class TitleScreen @JvmOverloads constructor( alpha = 200 } - // General paint settings for tetrominos (white) + // General paint settings for tetrominos paint.apply { - color = Color.WHITE + color = themeColor style = Paint.Style.FILL isAntiAlias = true } // Glow paint settings for tetrominos glowPaint.apply { - color = Color.WHITE + color = themeColor style = Paint.Style.FILL isAntiAlias = true alpha = 60 @@ -184,8 +185,8 @@ class TitleScreen @JvmOverloads constructor( try { super.onDraw(canvas) - // Draw background - canvas.drawColor(Color.BLACK) + // Draw background using the current background color + canvas.drawColor(backgroundColor) // Add any pending tetrominos tetrominos.addAll(tetrominosToAdd) @@ -340,7 +341,7 @@ class TitleScreen @JvmOverloads constructor( glowPaint.color = themeColor // Update background color - setBackgroundColor(when (themeId) { + backgroundColor = when (themeId) { PlayerProgressionManager.THEME_CLASSIC -> Color.BLACK PlayerProgressionManager.THEME_NEON -> Color.parseColor("#0D0221") PlayerProgressionManager.THEME_MONOCHROME -> Color.parseColor("#1A1A1A") @@ -348,8 +349,29 @@ class TitleScreen @JvmOverloads constructor( PlayerProgressionManager.THEME_MINIMALIST -> Color.WHITE PlayerProgressionManager.THEME_GALAXY -> Color.parseColor("#0B0C10") else -> Color.BLACK - }) + } invalidate() } + + /** + * Set the theme color for the title screen + */ + fun setThemeColor(color: Int) { + themeColor = color + titlePaint.color = color + promptPaint.color = color + highScorePaint.color = color + paint.color = color + glowPaint.color = color + invalidate() + } + + /** + * Set the background color for the title screen + */ + override fun setBackgroundColor(color: Int) { + backgroundColor = color + invalidate() + } } \ No newline at end of file