Updated attack button to actually perform stage 1 API call.

This commit is contained in:
lightheel 2025-08-03 12:39:03 -04:00
parent 266658342a
commit 2901bcf0da

View File

@ -198,7 +198,8 @@ fun BattleScreen(
activeCharacter: APIBattleCharacter? = null, activeCharacter: APIBattleCharacter? = null,
opponentCharacter: APIBattleCharacter? = null, opponentCharacter: APIBattleCharacter? = null,
onBattleComplete: (String?) -> Unit = {}, onBattleComplete: (String?) -> Unit = {},
onExitBattle: () -> Unit = {} onExitBattle: () -> Unit = {},
context: android.content.Context? = null
) { ) {
var animationProgress by remember { mutableStateOf(0f) } var animationProgress by remember { mutableStateOf(0f) }
@ -266,7 +267,9 @@ fun BattleScreen(
// Apply damage after animation // Apply damage after animation
battleSystem.applyDamage(false, 20f) // Opponent takes damage battleSystem.applyDamage(false, 20f) // Opponent takes damage
}, },
activeCharacter = activeCharacter activeCharacter = activeCharacter,
context = context,
opponent = opponentCharacter
) )
} }
1 -> { 1 -> {
@ -301,7 +304,9 @@ fun PlayerBattleView(
playerName: String, playerName: String,
attackAnimationProgress: Float, attackAnimationProgress: Float,
onAttackClick: () -> Unit, onAttackClick: () -> Unit,
activeCharacter: APIBattleCharacter? = null activeCharacter: APIBattleCharacter? = null,
context: android.content.Context? = null,
opponent: APIBattleCharacter? = null
) { ) {
Column( Column(
modifier = Modifier modifier = Modifier
@ -347,8 +352,10 @@ fun PlayerBattleView(
// Player character with attack animation // Player character with attack animation
Box( Box(
modifier = Modifier.size(80.dp), modifier = Modifier
contentAlignment = Alignment.Center .fillMaxWidth()
.size(80.dp),
contentAlignment = Alignment.CenterStart
) { ) {
SpriteImage( SpriteImage(
spriteName = "00", // The sprite number (00, 01, 02, etc.) spriteName = "00", // The sprite number (00, 01, 02, etc.)
@ -360,7 +367,8 @@ fun PlayerBattleView(
else -> "dim011_mon01" else -> "dim011_mon01"
}, },
modifier = Modifier modifier = Modifier
.size(80.dp), .size(80.dp)
.scale(-1f, 1f), // Flip horizontally
contentScale = ContentScale.Fit contentScale = ContentScale.Fit
) )
/* /*
@ -426,6 +434,45 @@ fun PlayerBattleView(
Button( Button(
onClick = { onClick = {
println("Attack button clicked!") 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 ->
RetrofitHelper().getPVPWinner(
ctx,
1,
2,
activeCharacter?.name ?: "Player",
playerStage,
opponentStage,
opponent?.name ?: "Opponent",
opponentStage
) { apiResult ->
// Handle API response here
println("API Result: $apiResult")
// TODO: Parse response and apply damage/hit/miss logic
}
}
onAttackClick() onAttackClick()
}, },
enabled = battleSystem.isAttackButtonEnabled, enabled = battleSystem.isAttackButtonEnabled,
@ -495,8 +542,10 @@ fun OpponentBattleView(
// Opponent character with attack animation // Opponent character with attack animation
Box( Box(
modifier = Modifier.size(80.dp), modifier = Modifier
contentAlignment = Alignment.Center .fillMaxWidth()
.size(80.dp),
contentAlignment = Alignment.CenterEnd
) { ) {
SpriteImage( SpriteImage(
spriteName = "00", // The sprite number (00, 01, 02, etc.) spriteName = "00", // The sprite number (00, 01, 02, etc.)
@ -856,41 +905,41 @@ fun BattlesScreen() {
"rookie" -> { "rookie" -> {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text("Rookie Battle View") Text("Rookie Battle View")
// Add character selection dropdown // Add character selection dropdown
characterDropdown("rookie") characterDropdown("rookie")
// Display buttons for each opponent // Display buttons for each opponent
opponentsList.forEach { opponent -> opponentsList.forEach { opponent ->
Button( Button(
onClick = { onClick = {
activeCharacter?.let { activeCharacter?.let {
selectedOpponent = opponent selectedOpponent = opponent
RetrofitHelper().getPVPWinner(context, 0, 2, it.name, 0, 0, opponent.name, 0) { apiResult -> RetrofitHelper().getPVPWinner(context, 0, 2, it.name, 0, 0, opponent.name, 0) { apiResult ->
currentView = "battle-main" currentView = "battle-main"
}
} }
} },
}, modifier = Modifier.padding(vertical = 4.dp)
modifier = Modifier.padding(vertical = 4.dp) ) {
) { Text("Battle ${opponent.name}")
Text("Battle ${opponent.name}") }
} }
}
// Show selected character info // Show selected character info
activeCharacter?.let { character -> activeCharacter?.let { character ->
Text("Active Character: ${character.name}") Text("Active Character: ${character.name}")
Text("HP: ${character.currentHp}/${character.baseHp}") Text("HP: ${character.currentHp}/${character.baseHp}")
Text("BP: ${character.baseBp}") Text("BP: ${character.baseBp}")
Text("AP: ${character.baseAp}") Text("AP: ${character.baseAp}")
} }
backButton() backButton()
} }
} }
"champion" -> { "champion" -> {
@ -1019,36 +1068,37 @@ fun BattlesScreen() {
else -> "rookie" else -> "rookie"
} }
// Initialize battle with character stats // Initialize battle with character stats
LaunchedEffect(activeCharacter, selectedOpponent) { LaunchedEffect(activeCharacter, selectedOpponent) {
activeCharacter?.let { playerCharacter -> activeCharacter?.let { playerCharacter ->
selectedOpponent?.let { opponentCharacter -> selectedOpponent?.let { opponentCharacter ->
println("Initializing battle with player: ${playerCharacter.name}, opponent: ${opponentCharacter.name}") println("Initializing battle with player: ${playerCharacter.name}, opponent: ${opponentCharacter.name}")
battleSystem.initializeBattle( battleSystem.initializeBattle(
playerHP = playerCharacter.currentHp.toFloat(), playerHP = playerCharacter.currentHp.toFloat(),
opponentHP = opponentCharacter.currentHp.toFloat(), opponentHP = opponentCharacter.currentHp.toFloat(),
playerMaxHP = playerCharacter.baseHp.toFloat(), playerMaxHP = playerCharacter.baseHp.toFloat(),
opponentMaxHP = opponentCharacter.baseHp.toFloat() opponentMaxHP = opponentCharacter.baseHp.toFloat()
) )
} }
} }
} }
BattleScreen( BattleScreen(
battleSystem = battleSystem, battleSystem = battleSystem,
stage = currentStage, stage = currentStage,
playerName = activeCharacter?.name ?: "Player", playerName = activeCharacter?.name ?: "Player",
opponentName = selectedOpponent?.name ?: "Opponent", opponentName = selectedOpponent?.name ?: "Opponent",
activeCharacter = activeCharacter, activeCharacter = activeCharacter,
opponentCharacter = selectedOpponent, opponentCharacter = selectedOpponent,
onBattleComplete = { winner -> onBattleComplete = { winner ->
println("Battle complete! Winner: $winner") println("Battle complete! Winner: $winner")
currentView = "battle-results" currentView = "battle-results"
}, },
onExitBattle = { onExitBattle = {
currentView = "main" currentView = "main"
} },
) context = context
)
} }
"battle-results" -> { "battle-results" -> {