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

command spell #1880

Closed
wants to merge 7 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
Binary file added app/src/main/assets/En/cancel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private fun AutoBattle.ExitReason.text(): String = when (this) {
AutoBattle.ExitReason.FirstClearRewards -> stringResource(R.string.first_clear_rewards)
AutoBattle.ExitReason.Paused -> stringResource(R.string.script_paused)
AutoBattle.ExitReason.StopAfterThisRun -> stringResource(R.string.stop_after_this_run)
AutoBattle.ExitReason.OutOfCommandSpells -> stringResource(id = R.string.p_stop_on_out_of_command_spell)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ fun SkillMakerUI(
val turn by vm.turn
val wave by vm.wave

val commandSpellRemaining by vm.commandSpell

Crossfade(
current,
animationSpec = spring()
Expand All @@ -106,6 +108,13 @@ fun SkillMakerUI(
SkillMakerNav.Main -> {
SkillMakerMain(
vm = vm,
onCommandSpell = {
if (commandSpellRemaining <=0) {
navigate(SkillMakerNav.CommandSpellWarning)
} else {
navigate(SkillMakerNav.CommandSpell)
}
},
onMasterSkills = { navigate(SkillMakerNav.MasterSkills) },
onAtk = { navigate(SkillMakerNav.Atk) },
onSkill = { vm.initSkill(it) },
Expand All @@ -123,6 +132,14 @@ fun SkillMakerUI(
onOrderChange = { navigate(SkillMakerNav.OrderChange) }
)
}
SkillMakerNav.CommandSpell -> {
SkillMakerCommandSpells(
onCommandSpell = { vm.initSkill(it) },
)
}
SkillMakerNav.CommandSpellWarning -> {
SkillMakerCommandSpellWarning()
}

SkillMakerNav.OrderChange -> {
SkillMakerOrderChange(
Expand Down Expand Up @@ -152,7 +169,7 @@ fun SkillMakerUI(
onSpaceIshtar = {
navigate(SkillMakerNav.SpaceIshtar(nav.skill))
},
showKukulkan = nav.skill !is Skill.Master,
showKukulkan = nav.skill is Skill.Servant,
onKukulkan = {
navigate(SkillMakerNav.Kukulkan(nav.skill))
},
Expand All @@ -163,7 +180,8 @@ fun SkillMakerUI(
),
onMelusine = {
vm.targetSkill(ServantTarget.Melusine)
}
},
showTargetNone = nav.skill !is Skill.CommandSpell,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.github.fate_grand_automata.ui.skill_maker

import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.github.fate_grand_automata.R
import io.github.fate_grand_automata.scripts.models.Skill
import io.github.fate_grand_automata.ui.FGATheme
import io.github.fate_grand_automata.ui.FGATitle
import io.github.fate_grand_automata.util.stringRes

@Composable
fun SkillMakerCommandSpells(
onCommandSpell: (Skill.CommandSpell) -> Unit,
) {
Column(
modifier = Modifier
.fillMaxHeight()
.padding(16.dp)
) {
FGATitle(
stringResource(R.string.skill_maker_command_spell)
)

Row(
modifier = Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically
) {
Skill.CommandSpell.list.forEach {
CommandSpellButton(
skill = it,
color = colorResource(R.color.colorCommandSpell)
) {
onCommandSpell(it)
}
}
}
}
}

@Composable
private fun RowScope.CommandSpellButton(
skill: Skill,
color: Color,
onClick: () -> Unit
) {
Surface(
color = color,
shape = MaterialTheme.shapes.medium,
modifier = Modifier
.padding(5.dp)
.sizeIn(maxWidth = 45.dp)
.aspectRatio(1f)
.fillMaxSize()
.weight(1f, false),
onClick = onClick
) {
Box {
Text(
stringResource(skill.stringRes).uppercase(),
textAlign = TextAlign.Center,
color = Color.White,
modifier = Modifier.align(Alignment.Center)
)
}
}
}

@Composable
fun SkillMakerCommandSpellWarning() {
Column(
modifier = Modifier
.fillMaxHeight()
.padding(16.dp)
) {
FGATitle(
stringResource(R.string.skill_maker_command_spell_warning)
)
}
}

@Preview(name = "Light Mode", widthDp = 600, heightDp = 300)
@Preview(name = "Dark Mode", widthDp = 600, heightDp = 300, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun TestCommandSpell() {
FGATheme {
SkillMakerCommandSpells(onCommandSpell = { })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sealed class SkillMakerEntry {

is AutoSkillAction.ServantSkill -> toString(action.skill, action.targets)
is AutoSkillAction.MasterSkill -> toString(action.skill, action.target)
is AutoSkillAction.CommandSpell -> toString(action.skill, action.target)
is AutoSkillAction.TargetEnemy -> "t${action.enemy.autoSkillCode}"
is AutoSkillAction.OrderChange -> "x${action.starting.autoSkillCode}${action.sub.autoSkillCode}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import io.github.fate_grand_automata.ui.icon
@Composable
fun SkillMakerMain(
vm: SkillMakerViewModel,
onCommandSpell: () -> Unit,
onMasterSkills: () -> Unit,
onAtk: () -> Unit,
onSkill: (Skill.Servant) -> Unit,
Expand Down Expand Up @@ -124,6 +125,8 @@ fun SkillMakerMain(
Skills(onSkill = onSkill)
}

val commandSpellRemaining by vm.commandSpell

Column(
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.End,
Expand All @@ -132,6 +135,20 @@ fun SkillMakerMain(
.width(IntrinsicSize.Max)
.fillMaxHeight()
) {

Button(
colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.colorCommandSpell)),
onClick = onCommandSpell
) {
Text(
stringResource(R.string.skill_maker_command_spell_title_short, 3 - commandSpellRemaining),
textAlign = TextAlign.Center,
color = Color.White
)
}

Spacer(Modifier.height(8.dp))

Button(
colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.colorMasterSkill)),
onClick = onMasterSkills
Expand All @@ -143,7 +160,7 @@ fun SkillMakerMain(
)
}

Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(8.dp))

Button(
shape = CircleShape,
Expand Down Expand Up @@ -237,6 +254,7 @@ val SkillMakerEntry?.colorRes: Int
'g', 'h', 'i' -> R.color.colorServant3
else -> defaultColor
}
is AutoSkillAction.CommandSpell -> R.color.colorCommandSpell

else -> defaultColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ sealed class SkillMakerNav {
data class SpaceIshtar(val skill: Skill) : SkillMakerNav()
data class Kukulkan(val skill: Skill) : SkillMakerNav()
data class KukulkanTarget(val skill: Skill, val firstTarget: ServantTarget) : SkillMakerNav()
data object CommandSpell : SkillMakerNav()
data object CommandSpellWarning : SkillMakerNav()
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fun SkillMakerTarget(
showKukulkan: Boolean,
onKukulkan: () -> Unit,
showMelusine: Boolean,
onMelusine: () -> Unit
onMelusine: () -> Unit,
showTargetNone: Boolean
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -98,8 +99,10 @@ fun SkillMakerTarget(
}
}

Button(onClick = { onSkillTarget(null) }) {
Text(stringResource(R.string.skill_maker_target_none))
if (showTargetNone) {
Button(onClick = { onSkillTarget(null) }) {
Text(stringResource(R.string.skill_maker_target_none))
}
}
}
}
Expand All @@ -125,7 +128,8 @@ private fun TestSkillMaker(
showEmiya: Boolean = false,
showKukulkan: Boolean = false,
showSpaceIshtar: Boolean = false,
showMelusine: Boolean = showEmiya
showMelusine: Boolean = showEmiya,
showTargetNone: Boolean = false
) {
FGATheme {
SkillMakerTarget(
Expand All @@ -137,7 +141,8 @@ private fun TestSkillMaker(
showKukulkan = showKukulkan,
onKukulkan = {},
showMelusine = showMelusine,
onMelusine = {}
onMelusine = {},
showTargetNone = showTargetNone
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import io.github.fate_grand_automata.scripts.models.ServantTarget
import io.github.fate_grand_automata.scripts.models.Skill
import io.github.fate_grand_automata.scripts.prefs.IBattleConfig
import io.github.fate_grand_automata.scripts.prefs.IPreferences
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import androidx.lifecycle.viewModelScope
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -48,6 +54,16 @@ class SkillMakerViewModel @Inject constructor(
m
}

private var _commandSpell =
mutableIntStateOf(
skillCommand.count {
it is SkillMakerEntry.Action && it.action is AutoSkillAction.CommandSpell
}
)

val commandSpell: State<Int> = _commandSpell
.map { it.coerceIn(0..3) }

private val _wave = mutableIntStateOf(
if (state.skillString != null) {
state.wave
Expand Down Expand Up @@ -175,14 +191,18 @@ class SkillMakerViewModel @Inject constructor(
}

fun targetSkill(targets: List<ServantTarget>) {
val skill = (Skill.Servant.list + Skill.Master.list)
val skill = (Skill.Servant.list + Skill.Master.list + Skill.CommandSpell.list)
.first { it.autoSkillCode == currentSkill }

add(
SkillMakerEntry.Action(
when (skill) {
is Skill.Servant -> AutoSkillAction.ServantSkill(skill, targets)
is Skill.Master -> AutoSkillAction.MasterSkill(skill, targets.firstOrNull())
is Skill.CommandSpell -> {
++_commandSpell.value
AutoSkillAction.CommandSpell(skill, targets.firstOrNull())
}
}
)
)
Expand Down Expand Up @@ -307,10 +327,17 @@ class SkillMakerViewModel @Inject constructor(
}

is SkillMakerEntry.Action -> {
if (last.action is AutoSkillAction.TargetEnemy) {
deleteSelected()
revertToPreviousEnemyTarget()
} else deleteSelected()
when(last.action) {
is AutoSkillAction.TargetEnemy -> {
deleteSelected()
revertToPreviousEnemyTarget()
}
is AutoSkillAction.CommandSpell -> {
--_commandSpell.value
deleteSelected()
}
else -> deleteSelected()
}
}
// Do nothing
is SkillMakerEntry.Start -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class ImageLoader @Inject constructor(
Images.OkKR -> "ok-kr.png"
Images.Execute -> "execute.png"
Images.SupportBlankCE -> "support_blank_ce.png"
Images.Cancel -> "cancel.png"
}

override operator fun get(img: Images, gameServer: GameServer?): Pattern = synchronized(regionCachedPatterns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.github.fate_grand_automata.scripts.enums.ShuffleCardsEnum
import io.github.fate_grand_automata.scripts.enums.SpamEnum
import io.github.fate_grand_automata.scripts.enums.SupportClass
import io.github.fate_grand_automata.scripts.enums.SupportSelectionModeEnum
import io.github.fate_grand_automata.scripts.models.Skill

val RefillResourceEnum.stringRes
get() = when (this) {
Expand Down Expand Up @@ -185,4 +186,10 @@ val GameServer.simpleStringRes
GameServer.Kr -> R.string.game_server_kr
is GameServer.En -> R.string.game_server_na
is GameServer.Jp -> R.string.game_server_jp
}

val Skill.CommandSpell.stringRes
get() = when (this) {
Skill.CommandSpell.CS1 -> R.string.skill_maker_command_spell_full_np
Skill.CommandSpell.CS2 -> R.string.skill_maker_command_spell_full_hp
}
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<color name="colorEnemyTarget">#2e7d32</color>
<color name="colorMasterSkill">#006064</color>
<color name="colorCommandSpell">#a03243</color>
<color name="colorStageChange">#616161</color>
<color name="colorServant1">#c62828</color>
<color name="colorServant2">#0277bd</color>
Expand Down
Loading
Loading