From 7af8e00e6fc891c5a0f5bc2f73c03d7f8f1328a5 Mon Sep 17 00:00:00 2001 From: lightheel Date: Mon, 4 Aug 2025 11:02:51 -0400 Subject: [PATCH] Re-added missing exit button and health bars. --- .../vbhelper/battle/ArenaBattleSystem.kt | 6 ++ .../vbhelper/screens/BattlesScreen.kt | 95 +++++++++++++++++-- 2 files changed, 95 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/battle/ArenaBattleSystem.kt b/app/src/main/java/com/github/nacabaro/vbhelper/battle/ArenaBattleSystem.kt index fa8d84e..09999f7 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/battle/ArenaBattleSystem.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/battle/ArenaBattleSystem.kt @@ -99,6 +99,12 @@ class ArenaBattleSystem { Log.d(TAG, "Updated HP from API: Player=$playerHP, Opponent=$opponentHP") } + fun initializeHP(playerMaxHP: Float, opponentMaxHP: Float) { + _playerHP = playerMaxHP + _opponentHP = opponentMaxHP + Log.d(TAG, "Initialized HP: Player=$playerMaxHP, Opponent=$opponentMaxHP") + } + fun completeAttackAnimation(playerDamage: Float = 0f, opponentDamage: Float = 0f) { if (playerDamage > 0f) { applyDamage(true, playerDamage) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/BattlesScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/BattlesScreen.kt index 8fc2d47..af5ef13 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/BattlesScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/BattlesScreen.kt @@ -62,6 +62,13 @@ fun BattleScreen( ) { val battleSystem = remember { ArenaBattleSystem() } + // Initialize HP when battle starts + LaunchedEffect(activeCharacter, opponentCharacter) { + val playerMaxHP = activeCharacter?.baseHp?.toFloat() ?: 100f + val opponentMaxHP = opponentCharacter?.baseHp?.toFloat() ?: 100f + battleSystem.initializeHP(playerMaxHP, opponentMaxHP) + } + // Pending damage state for API integration var pendingPlayerDamage by remember { mutableStateOf(0f) } var pendingOpponentDamage by remember { mutableStateOf(0f) } @@ -197,13 +204,29 @@ fun PlayerBattleView( opponent: APIBattleCharacter?, onSetPendingDamage: (Float, Float) -> Unit ) { - Column( - modifier = Modifier - .fillMaxSize() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally + Box( + modifier = Modifier.fillMaxSize() ) { - // Player Digimon + // Exit button at the top-right + Button( + onClick = { /* TODO: Add exit functionality */ }, + modifier = Modifier + .align(Alignment.TopEnd) + .padding(16.dp), + colors = ButtonDefaults.buttonColors(containerColor = Color.Red) + ) { + Text("Exit", color = Color.White, fontSize = 14.sp) + } + + // Main content + Column( + modifier = Modifier + .fillMaxSize() + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.SpaceBetween + ) { + // Player Digimon Box( modifier = Modifier .fillMaxWidth() @@ -262,6 +285,46 @@ fun PlayerBattleView( trackColor = Color.Gray ) + Spacer(modifier = Modifier.height(16.dp)) + + // Health bar + LinearProgressIndicator( + progress = battleSystem.playerHP / (activeCharacter?.baseHp?.toFloat() ?: 100f), + modifier = Modifier + .fillMaxWidth() + .height(10.dp), + color = Color.Green, + trackColor = Color.Gray + ) + + // Health display numbers + Text( + text = "HP: ${battleSystem.playerHP.toInt()}/${activeCharacter?.baseHp ?: 100}", + fontSize = 14.sp, + color = Color.Black + ) + + Spacer(modifier = Modifier.height(16.dp)) + + // Enemy HP bar + LinearProgressIndicator( + progress = battleSystem.opponentHP / (opponent?.baseHp?.toFloat() ?: 100f), + modifier = Modifier + .fillMaxWidth() + .height(10.dp), + color = Color.Red, + trackColor = Color.Gray + ) + + // Enemy HP display numbers + Text( + text = "Enemy HP: ${battleSystem.opponentHP.toInt()}/${opponent?.baseHp ?: 100}", + fontSize = 14.sp, + color = Color.Black + ) + + Spacer(modifier = Modifier.height(16.dp)) + // Attack button Button( onClick = { @@ -355,6 +418,9 @@ fun PlayerBattleView( ) { Text("Attack", color = Color.White, fontSize = 18.sp) } + + Spacer(modifier = Modifier.height(16.dp)) + } } } @@ -420,6 +486,23 @@ fun OpponentBattleView( } } + // Enemy HP bar + LinearProgressIndicator( + progress = battleSystem.opponentHP / (activeCharacter?.baseHp?.toFloat() ?: 100f), + modifier = Modifier + .fillMaxWidth() + .height(10.dp), + color = Color.Red, + trackColor = Color.Gray + ) + + // Enemy HP display numbers + Text( + text = "Enemy HP: ${battleSystem.opponentHP.toInt()}/${activeCharacter?.baseHp ?: 100}", + fontSize = 14.sp, + color = Color.Black + ) + // Spacer for layout balance Spacer(modifier = Modifier.height(120.dp)) }