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 // Get crit bar progress as float (0.0f to 100.0f)
Text( val critBarProgressFloat = battleSystem.critBarProgress.toFloat()
text = "HP: ${battleSystem.playerHP.toInt()}/${activeCharacter?.baseHp ?: 100}",
fontSize = 14.sp,
color = Color.Black
)
Spacer(modifier = Modifier.height(16.dp)) // Determine player and opponent stages
val playerStage = when (activeCharacter?.stage) {
0 -> 0 // rookie
1 -> 1 // champion
2 -> 2 // ultimate
3 -> 3 // mega
else -> 0
}
// Attack button val opponentStage = when (opponent?.stage) {
Button( 0 -> 0 // rookie
onClick = { 1 -> 1 // champion
println("Attack button clicked!") 2 -> 2 // ultimate
3 -> 3 // mega
else -> 0
}
// Get crit bar progress as float (0.0f to 100.0f) // Send API call with all parameters
val critBarProgressFloat = battleSystem.critBarProgress.toFloat() context?.let { ctx ->
// Start player attack animation
battleSystem.startPlayerAttack()
// Determine player and opponent stages RetrofitHelper().getPVPWinner(
val playerStage = when (activeCharacter?.stage) { ctx,
0 -> 0 // rookie 1,
1 -> 1 // champion 2,
2 -> 2 // ultimate activeCharacter?.name ?: "Player",
3 -> 3 // mega playerStage,
else -> 0 opponentStage,
} opponent?.name ?: "Opponent",
opponentStage
) { apiResult ->
// Handle API response here
println("API Result: $apiResult")
val opponentStage = when (opponent?.stage) { // Update HP based on API response
0 -> 0 // rookie when (apiResult.state) {
1 -> 1 // champion 1 -> {
2 -> 2 // ultimate // Match is still ongoing - update HP and continue
3 -> 3 // mega println("Round ${apiResult.currentRound}: Player HP=${apiResult.playerHP}, Opponent HP=${apiResult.opponentHP}")
else -> 0
}
// Send API call with all parameters // Set pending damage based on API result
context?.let { ctx -> if (apiResult.playerAttackHit) {
// Start player attack animation // Player attack hit - enemy takes damage at end of player animation
battleSystem.startPlayerAttack() println("Player attack hit! Enemy will take ${apiResult.playerAttackDamage} damage")
onSetPendingDamage(0f, apiResult.playerAttackDamage.toFloat()) // Opponent takes damage
RetrofitHelper().getPVPWinner( battleSystem.setAttackHitState(true)
ctx, } else {
1, // Player attack missed - enemy counter-attacks and player takes damage
2, println("Player attack missed! Enemy counter-attacks and player takes ${apiResult.opponentAttackDamage} damage")
activeCharacter?.name ?: "Player", onSetPendingDamage(apiResult.opponentAttackDamage.toFloat(), 0f) // Player takes damage
playerStage, battleSystem.setAttackHitState(false)
opponentStage, }
opponent?.name ?: "Opponent", }
opponentStage 2 -> {
) { apiResult -> // Match is over - transition to results screen
// Handle API response here println("Match is over! Winner: ${apiResult.winner}")
println("API Result: $apiResult") battleSystem.updateHPFromAPI(apiResult.playerHP.toFloat(), apiResult.opponentHP.toFloat())
onAttackClick() // This will transition to battle-results screen
// Update HP based on API response }
when (apiResult.state) { -1 -> {
1 -> { // Error occurred
// Match is still ongoing - update HP and continue println("API Error: ${apiResult.status}")
println("Round ${apiResult.currentRound}: Player HP=${apiResult.playerHP}, Opponent HP=${apiResult.opponentHP}") battleSystem.resetAttackState()
battleSystem.enableAttackButton()
// Set pending damage based on API result }
if (apiResult.playerAttackHit) {
// Player attack hit - enemy takes damage at end of player animation
println("Player attack hit! Enemy will take ${apiResult.playerAttackDamage} damage")
onSetPendingDamage(0f, apiResult.playerAttackDamage.toFloat()) // Opponent takes damage
battleSystem.setAttackHitState(true)
} else {
// Player attack missed - enemy counter-attacks and player takes damage
println("Player attack missed! Enemy counter-attacks and player takes ${apiResult.opponentAttackDamage} damage")
onSetPendingDamage(apiResult.opponentAttackDamage.toFloat(), 0f) // Player takes damage
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))
} }
} }
} }