Re-added missing UI pieces (HP bar, HP numbers, & exit button).

This commit is contained in:
lightheel 2025-08-04 11:22:22 -04:00
parent 31fab9dba4
commit 9d0e68fb8a

View File

@ -207,197 +207,212 @@ fun PlayerBattleView(
Box( Box(
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) { ) {
// Exit button at the top-right // Top section: Exit button, HP bar, and HP numbers
Button( Column(
onClick = { /* TODO: Add exit functionality */ },
modifier = Modifier modifier = Modifier
.align(Alignment.TopEnd) .fillMaxWidth()
.padding(16.dp), .padding(16.dp)
colors = ButtonDefaults.buttonColors(containerColor = Color.Red)
) { ) {
Text("Exit", color = Color.White, fontSize = 14.sp) // Exit button at the top-right
Box(
modifier = Modifier.fillMaxWidth()
) {
Button(
onClick = { /* TODO: Add exit functionality */ },
modifier = Modifier.align(Alignment.TopEnd),
colors = ButtonDefaults.buttonColors(containerColor = Color.Red)
) {
Text("Exit", color = Color.White, fontSize = 14.sp)
}
}
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
)
} }
// Main content // Middle section: Player Digimon only
Column( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(16.dp), .padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally, contentAlignment = Alignment.Center
verticalArrangement = Arrangement.SpaceBetween
) { ) {
// Player Digimon // Player Digimon (center)
Box( Box(
modifier = Modifier
.fillMaxWidth()
.size(80.dp),
contentAlignment = Alignment.CenterStart
) {
SpriteImage(
spriteName = activeCharacter?.charaId ?: "dim011_mon01",
atlasName = activeCharacter?.charaId ?: "dim011_mon01",
modifier = Modifier modifier = Modifier
.size(80.dp) .fillMaxWidth()
.scale(-1f, 1f), // Flip player Digimon horizontally .size(80.dp),
contentScale = ContentScale.Fit contentAlignment = Alignment.Center
) ) {
SpriteImage(
// Attack sprite visibility and positioning based on attack phase spriteName = activeCharacter?.charaId ?: "dim011_mon01",
val shouldShowAttack = when (battleSystem.attackPhase) { atlasName = activeCharacter?.charaId ?: "dim011_mon01",
1 -> true // Player attack on player screen
2 -> true // Player attack on opponent screen
3 -> false // Opponent attack on opponent screen
4 -> false // Opponent attack on player screen
else -> false
}
if (shouldShowAttack) {
val xOffset = when (battleSystem.attackPhase) {
1 -> (attackAnimationProgress * 400 - 200).dp // Player attack on player screen
2 -> (attackAnimationProgress * 400 - 200).dp // Player attack on opponent screen
else -> 0.dp
}
println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
AttackSpriteImage(
characterId = activeCharacter?.charaId ?: "dim011_mon01",
isLarge = true,
modifier = Modifier modifier = Modifier
.size(60.dp) .size(80.dp)
.offset( .scale(-1f, 1f), // Flip player Digimon horizontally
x = xOffset,
y = 0.dp
)
.scale(-1f, 1f), // Flip player attacks
contentScale = ContentScale.Fit contentScale = ContentScale.Fit
) )
// Attack sprite visibility and positioning based on attack phase
val shouldShowAttack = when (battleSystem.attackPhase) {
1 -> true // Player attack on player screen
2 -> true // Player attack on opponent screen
3 -> false // Opponent attack on opponent screen
4 -> false // Opponent attack on player screen
else -> false
}
if (shouldShowAttack) {
val xOffset = when (battleSystem.attackPhase) {
1 -> (attackAnimationProgress * 400 - 200).dp // Player attack on player screen
2 -> (attackAnimationProgress * 400 - 200).dp // Player attack on opponent screen
else -> 0.dp
}
println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
AttackSpriteImage(
characterId = activeCharacter?.charaId ?: "dim011_mon01",
isLarge = true,
modifier = Modifier
.size(60.dp)
.offset(
x = xOffset,
y = 0.dp
)
.scale(-1f, 1f), // Flip player attacks
contentScale = ContentScale.Fit
)
}
} }
} }
// Critical bar // Bottom section: Critical bar and Attack button
LinearProgressIndicator( Column(
progress = battleSystem.critBarProgress / 100f,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(10.dp), .padding(16.dp)
color = Color.Yellow, .align(Alignment.BottomCenter),
trackColor = Color.Gray horizontalAlignment = Alignment.CenterHorizontally
) ) {
// Critical bar
LinearProgressIndicator(
progress = battleSystem.critBarProgress / 100f,
modifier = Modifier
.fillMaxWidth()
.height(10.dp),
color = Color.Yellow,
trackColor = Color.Gray
)
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
// Health bar // Attack button
LinearProgressIndicator( Button(
progress = battleSystem.playerHP / (activeCharacter?.baseHp?.toFloat() ?: 100f), onClick = {
modifier = Modifier println("Attack button clicked!")
.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))
// Attack button
Button(
onClick = {
println("Attack button clicked!")
// Get crit bar progress as float (0.0f to 100.0f)
val critBarProgressFloat = battleSystem.critBarProgress.toFloat()
// Determine player and opponent stages
val playerStage = when (activeCharacter?.stage) {
0 -> 0 // rookie
1 -> 1 // champion
2 -> 2 // ultimate
3 -> 3 // mega
else -> 0
}
val opponentStage = when (opponent?.stage) {
0 -> 0 // rookie
1 -> 1 // champion
2 -> 2 // ultimate
3 -> 3 // mega
else -> 0
}
// Send API call with all parameters
context?.let { ctx ->
// Start player attack animation
battleSystem.startPlayerAttack()
RetrofitHelper().getPVPWinner( // Get crit bar progress as float (0.0f to 100.0f)
ctx, val critBarProgressFloat = battleSystem.critBarProgress.toFloat()
1,
2, // Determine player and opponent stages
activeCharacter?.name ?: "Player", val playerStage = when (activeCharacter?.stage) {
playerStage, 0 -> 0 // rookie
opponentStage, 1 -> 1 // champion
opponent?.name ?: "Opponent", 2 -> 2 // ultimate
opponentStage 3 -> 3 // mega
) { apiResult -> else -> 0
// Handle API response here }
println("API Result: $apiResult")
val opponentStage = when (opponent?.stage) {
0 -> 0 // rookie
1 -> 1 // champion
2 -> 2 // ultimate
3 -> 3 // mega
else -> 0
}
// Send API call with all parameters
context?.let { ctx ->
// Start player attack animation
battleSystem.startPlayerAttack()
// Update HP based on API response RetrofitHelper().getPVPWinner(
when (apiResult.state) { ctx,
1 -> { 1,
// Match is still ongoing - update HP and continue 2,
println("Round ${apiResult.currentRound}: Player HP=${apiResult.playerHP}, Opponent HP=${apiResult.opponentHP}") activeCharacter?.name ?: "Player",
playerStage,
// Set pending damage based on API result opponentStage,
if (apiResult.playerAttackHit) { opponent?.name ?: "Opponent",
// Player attack hit - enemy takes damage at end of player animation opponentStage
println("Player attack hit! Enemy will take ${apiResult.playerAttackDamage} damage") ) { apiResult ->
onSetPendingDamage(0f, apiResult.playerAttackDamage.toFloat()) // Opponent takes damage // Handle API response here
battleSystem.setAttackHitState(true) println("API Result: $apiResult")
} else {
// Player attack missed - enemy counter-attacks and player takes damage // Update HP based on API response
println("Player attack missed! Enemy counter-attacks and player takes ${apiResult.opponentAttackDamage} damage") when (apiResult.state) {
onSetPendingDamage(apiResult.opponentAttackDamage.toFloat(), 0f) // Player takes damage 1 -> {
battleSystem.setAttackHitState(false) // Match is still ongoing - update HP and continue
} println("Round ${apiResult.currentRound}: Player HP=${apiResult.playerHP}, Opponent HP=${apiResult.opponentHP}")
}
2 -> { // Set pending damage based on API result
// Match is over - transition to results screen if (apiResult.playerAttackHit) {
println("Match is over! Winner: ${apiResult.winner}") // Player attack hit - enemy takes damage at end of player animation
battleSystem.updateHPFromAPI(apiResult.playerHP.toFloat(), apiResult.opponentHP.toFloat()) println("Player attack hit! Enemy will take ${apiResult.playerAttackDamage} damage")
onAttackClick() // This will transition to battle-results screen onSetPendingDamage(0f, apiResult.playerAttackDamage.toFloat()) // Opponent takes damage
} battleSystem.setAttackHitState(true)
-1 -> { } else {
// Error occurred // Player attack missed - enemy counter-attacks and player takes damage
println("API Error: ${apiResult.status}") println("Player attack missed! Enemy counter-attacks and player takes ${apiResult.opponentAttackDamage} damage")
battleSystem.resetAttackState() onSetPendingDamage(apiResult.opponentAttackDamage.toFloat(), 0f) // Player takes damage
battleSystem.enableAttackButton() battleSystem.setAttackHitState(false)
}
}
2 -> {
// Match is over - transition to results screen
println("Match is over! Winner: ${apiResult.winner}")
battleSystem.updateHPFromAPI(apiResult.playerHP.toFloat(), apiResult.opponentHP.toFloat())
onAttackClick() // This will transition to battle-results screen
}
-1 -> {
// Error occurred
println("API Error: ${apiResult.status}")
battleSystem.resetAttackState()
battleSystem.enableAttackButton()
}
} }
} }
} }
} },
}, enabled = battleSystem.isAttackButtonEnabled,
enabled = battleSystem.isAttackButtonEnabled, modifier = Modifier
modifier = Modifier .fillMaxWidth()
.fillMaxWidth() .height(50.dp),
.height(50.dp), colors = ButtonDefaults.buttonColors(
colors = ButtonDefaults.buttonColors( containerColor = Color.Red,
containerColor = Color.Red, disabledContainerColor = Color.Gray
disabledContainerColor = Color.Gray ),
), shape = RoundedCornerShape(8.dp)
shape = RoundedCornerShape(8.dp) ) {
) { Text("Attack", color = Color.White, fontSize = 18.sp)
Text("Attack", color = Color.White, fontSize = 18.sp) }
}
Spacer(modifier = Modifier.height(16.dp))
} }
} }
} }