Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Skill Maker UI Update #1844

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.fate_grand_automata.ui.skill_maker
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -26,17 +27,21 @@ import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import io.github.fate_grand_automata.R
import io.github.fate_grand_automata.scripts.models.AutoSkillAction
Expand All @@ -56,6 +61,11 @@ fun SkillMakerMain(
modifier = Modifier
.padding(vertical = 16.dp)
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures {
vm.clearSelection()
}
}
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -67,7 +77,13 @@ fun SkillMakerMain(

EnemyTarget(
selected = enemyTarget,
onSelectedChange = { vm.setEnemyTarget(it) }
onSelectedChange = { target ->
if (enemyTarget == target) {
vm.deleteIfLastActionIsTarget(target)
} else {
vm.setEnemyTarget(target)
}
}
)

Column(
Expand Down Expand Up @@ -269,7 +285,7 @@ fun SkillHistory(vm: SkillMakerViewModel) {
.let {
if (isSelected) {
it.border(
2.dp,
width = 2.dp,
color = colorResource(android.R.color.darker_gray),
shape = shape
)
Expand All @@ -285,7 +301,10 @@ fun SkillHistory(vm: SkillMakerViewModel) {

Text(
text,
color = Color.White
color = Color.White,
modifier = Modifier.padding(
all = 4.dp
)
)
}
}
Expand All @@ -310,13 +329,25 @@ fun EnemyTarget(
) {
RadioButton(
selected = isSelected,
onClick = onClick
onClick = onClick,
colors = RadioButtonDefaults.colors(
selectedColor = MaterialTheme.colorScheme.error,
unselectedColor = MaterialTheme.colorScheme.onSurfaceVariant
)
)

Text(
stringResource(R.string.skill_maker_main_enemy, it),
modifier = Modifier
.padding(start = 5.dp)
.padding(start = 5.dp),
textDecoration = when (isSelected) {
true -> TextDecoration.Underline
false -> null
},
color = when (isSelected) {
true -> MaterialTheme.colorScheme.error
false -> Color.Unspecified
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SkillMakerViewModel @Inject constructor(
}
)
private val _turn = mutableIntStateOf(
if (state.skillString != null){
if (state.skillString != null) {
state.turn
} else {
model.skillCommand.count { it is SkillMakerEntry.Next } + 1
Expand Down Expand Up @@ -151,6 +151,36 @@ class SkillMakerViewModel @Inject constructor(
}
}

fun deleteIfLastActionIsTarget(target: Int?) {
if (target == null) {
return
}

if (!isEmpty()) {
// Un-select target
when (val last = last) {
// Battle/Turn change
is SkillMakerEntry.Next -> {
// Do nothing
}

is SkillMakerEntry.Action -> {
if (
last.action is AutoSkillAction.TargetEnemy &&
last.action.enemy.autoSkillCode == EnemyTarget.list[target - 1].autoSkillCode
) {
deleteSelected()
revertToPreviousEnemyTarget()
}
}

is SkillMakerEntry.Start -> {
// Do nothing
}
}
}
}

fun unSelectTargets() = setEnemyTarget(null)

val wave: State<Int> = _wave
Expand Down Expand Up @@ -279,7 +309,7 @@ class SkillMakerViewModel @Inject constructor(
prevStage()
prevTurn()
}
if (last is SkillMakerEntry.Next.Turn){
if (last is SkillMakerEntry.Next.Turn) {
prevTurn()
}

Expand All @@ -297,6 +327,10 @@ class SkillMakerViewModel @Inject constructor(
}
}

fun clearSelection() {
_currentIndex.value = model.skillCommand.lastIndex
}

fun onDeleteSelected() {
if (!isEmpty()) {
// Un-select target
Expand Down