Skip to content

Commit

Permalink
Merge branch 'feat/skill-desc' into 'master'
Browse files Browse the repository at this point in the history
Add compendium info to EditTalentDialog and EditSkillDialog

See merge request fmasa/wfrp-master!194
  • Loading branch information
fmasa committed Feb 15, 2021
2 parents ffc7fce + 19da137 commit af8c733
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.frantisekmasa.wfrp_master.core.domain

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import cz.frantisekmasa.wfrp_master.core.R

enum class Characteristic {
Expand Down Expand Up @@ -56,4 +57,18 @@ enum class Characteristic {
WEAPON_SKILL -> R.drawable.ic_weapon_skill
WILL_POWER -> R.drawable.ic_will_power
}

@StringRes
fun getNameId(): Int = when(this) {
AGILITY -> R.string.label_agility
BALLISTIC_SKILL -> R.string.label_ballistic_skill
DEXTERITY -> R.string.label_dexterity
INITIATIVE -> R.string.label_initiative
INTELLIGENCE -> R.string.label_intelligence
FELLOWSHIP -> R.string.label_fellowship
STRENGTH -> R.string.label_strength
TOUGHNESS -> R.string.label_toughness
WEAPON_SKILL -> R.string.label_weapon_skill
WILL_POWER -> R.string.label_will_power
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand All @@ -24,14 +25,19 @@ fun CardContainer(
bodyPadding: PaddingValues = PaddingValues(),
content: @Composable ColumnScope.() -> Unit,
) {
Box(Modifier.padding(vertical = 6.dp).then(modifier)) {
Box(
Modifier
.padding(vertical = 6.dp)
.then(modifier)) {
Card(
modifier = Modifier.fillMaxWidth(),
elevation = 2.dp,
shape = RoundedCornerShape(4.dp)
) {
Column(
Modifier.padding(vertical = 16.dp, horizontal = 8.dp).padding(bodyPadding),
Modifier
.padding(vertical = 16.dp, horizontal = 8.dp)
.padding(bodyPadding),
content = content
)
}
Expand All @@ -54,7 +60,8 @@ fun CardTitle(text: String, @DrawableRes iconRes: Int? = null) {
Image(
vectorResource(iconRes),
VisualOnlyIconDescription,
Modifier.padding(end = 4.dp)
Modifier
.padding(end = 4.dp)
.width(24.dp)
.height(24.dp),
colorFilter = ColorFilter.tint(MaterialTheme.colors.onSurface),
Expand All @@ -75,15 +82,20 @@ fun MultiLineTextValue(@StringRes labelRes: Int, value: String) {
}

@Composable
fun SingleLineTextValue(@StringRes labelRes: Int, value: String) {
fun SingleLineTextValue(@StringRes labelRes: Int, value: AnnotatedString) {
if (value.isBlank()) return

Row {
Text(
stringResource(labelRes) + ":",
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(end = 4.dp)
modifier = Modifier.padding(end = Spacing.tiny),
)
Text(value)
}
}

@Composable
fun SingleLineTextValue(@StringRes labelRes: Int, value: String) {
SingleLineTextValue(labelRes, AnnotatedString(value))
}
14 changes: 14 additions & 0 deletions app/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
<string name="race_human">Human</string>
<string name="race_gnome">Gnome</string>

<!-- Characteristics -->
<string name="label_agility">Agility</string>
<string name="label_ballistic_skill">Ballistic Skill</string>
<string name="label_dexterity">Dexterity</string>
<string name="label_fellowship">Fellowship</string>
<string name="label_initiative">Initiative</string>
<string name="label_intelligence">Intelligence</string>
<string name="label_strength">Strength</string>
<string name="label_toughness">Toughness</string>
<string name="label_weapon_skill">Weapon Skill</string>
<string name="label_will_power">Will Power</string>

<!-- End of Domain -->

<!-- Common UI elements -->
Expand All @@ -33,6 +45,8 @@
<string name="button_open">Open</string>
<string name="button_remove">Remove</string>
<string name="open_context_menu">Open context menu</string>
<string name="boolean_yes">Yes</string>
<string name="boolean_no">No</string>

<!-- Form errors -->
<string name="error_cannot_be_empty">Cannot be empty!</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import cz.muni.fi.rpg.ui.character.skills.dialog.EditSkillDialog
import cz.muni.fi.rpg.ui.common.composables.*
import cz.muni.fi.rpg.viewModels.CharacterViewModel
import cz.muni.fi.rpg.viewModels.SkillsViewModel
import java.util.*

@Composable
internal fun SkillsCard(
Expand All @@ -43,22 +44,22 @@ internal fun SkillsCard(
size = EmptyUI.Size.Small
)
} else {
var editedSkill: Skill? by savedInstanceState { null }
var editedSkillId: UUID? by savedInstanceState { null }

for (skill in skills) {
SkillItem(
skill,
characteristics,
onClick = { editedSkill = skill },
onClick = { editedSkillId = skill.id },
onRemove = { onRemove(skill) },
)
}

editedSkill?.let { skill ->
editedSkillId?.let { skillId ->
EditSkillDialog(
viewModel = skillsVm,
skill = skill,
onDismissRequest = { editedSkill = null }
skillId = skillId,
onDismissRequest = { editedSkillId = null }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fun AddSkillDialog(viewModel: SkillsViewModel, onDismissRequest: () -> Unit) {
)
is FillingInAdvances ->
AdvancesForm(
existingSkill = null,
compendiumSkillId = currentState.compendiumSkillId,
viewModel = viewModel,
onDismissRequest = onDismissRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import cz.frantisekmasa.wfrp_master.core.ui.primitives.NumberPicker
import cz.frantisekmasa.wfrp_master.core.ui.primitives.Spacing
import cz.frantisekmasa.wfrp_master.core.ui.scaffolding.SaveAction
import cz.muni.fi.rpg.R
import cz.muni.fi.rpg.model.domain.skills.Skill
import cz.muni.fi.rpg.ui.common.composables.*
import cz.muni.fi.rpg.viewModels.SkillsViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -31,25 +30,20 @@ import java.util.*

@Composable
internal fun AdvancesForm(
existingSkill: Skill?,
compendiumSkillId: UUID,
viewModel: SkillsViewModel,
onDismissRequest: () -> Unit,
) {
var saving by remember { mutableStateOf(false) }
var advances by savedInstanceState { existingSkill?.advances ?: 1 }
var advances by savedInstanceState { 1 }

Scaffold(
topBar = {
TopAppBar(
navigationIcon = { CloseButton(onDismissRequest) },
title = {
Text(
stringResource(
if (existingSkill != null)
R.string.title_skill_edit else
R.string.title_skill_new
)
stringResource(R.string.title_skill_new)
)
},
actions = {
Expand All @@ -64,7 +58,7 @@ internal fun AdvancesForm(

try {
viewModel.saveCompendiumSkill(
skillId = existingSkill?.id ?: UUID.randomUUID(),
skillId = UUID.randomUUID(),
compendiumSkillId = compendiumSkillId,
advances = advances,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package cz.muni.fi.rpg.ui.character.skills.dialog

import androidx.compose.runtime.Composable
import cz.muni.fi.rpg.model.domain.skills.Skill
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.rememberCoroutineScope
import cz.frantisekmasa.wfrp_master.core.ui.dialogs.FullScreenDialog
import cz.muni.fi.rpg.viewModels.SkillsViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*

@Composable
fun EditSkillDialog(
viewModel: SkillsViewModel,
skill: Skill,
skillId: UUID,
onDismissRequest: () -> Unit
) {
val skill = viewModel.skills.observeAsState().value?.firstOrNull { it.id == skillId } ?: return

FullScreenDialog(onDismissRequest = onDismissRequest) {
if (skill.compendiumId != null) {
AdvancesForm(
existingSkill = skill,
compendiumSkillId = skill.compendiumId,
viewModel = viewModel,
onDismissRequest = onDismissRequest
val coroutineScope = rememberCoroutineScope()

SkillDetail(
skill,
onDismissRequest = onDismissRequest,
onAdvancesChange = { advances ->
coroutineScope.launch(Dispatchers.IO) {
viewModel.saveSkill(skill.copy(advances = advances))
}
}
)
} else {
NonCompendiumSkillForm(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cz.muni.fi.rpg.ui.character.skills.dialog

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cz.frantisekmasa.wfrp_master.core.ui.buttons.CloseButton
import cz.frantisekmasa.wfrp_master.core.ui.primitives.NumberPicker
import cz.frantisekmasa.wfrp_master.core.ui.primitives.SingleLineTextValue
import cz.frantisekmasa.wfrp_master.core.ui.primitives.Spacing
import cz.frantisekmasa.wfrp_master.core.ui.scaffolding.SubheadBar
import cz.muni.fi.rpg.R
import cz.muni.fi.rpg.model.domain.skills.Skill

@Composable
fun SkillDetail(
skill: Skill,
onDismissRequest: () -> Unit,
onAdvancesChange: (advances: Int) -> Unit
) {
Scaffold(
topBar = {
TopAppBar(
navigationIcon = { CloseButton(onDismissRequest) },
title = { Text(skill.name) },
)
}
) {
Column(Modifier.verticalScroll(rememberScrollState())) {
AdvancesBar(skill.advances, onAdvancesChange)

Column(Modifier.padding(Spacing.bodyPadding)) {
SingleLineTextValue(
R.string.label_skill_characteristic,
stringResource(skill.characteristic.getNameId()),
)

SingleLineTextValue(
labelRes = R.string.label_skill_advanced,
value = stringResource(
if (skill.advanced) R.string.boolean_yes else R.string.boolean_no
)
)

Text(
text = skill.description,
modifier = Modifier.padding(top = 8.dp),
)
}
}
}
}

@Composable
private fun AdvancesBar(advances: Int, onAdvancesChange: (advances: Int) -> Unit) {
SubheadBar {
Row(
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(stringResource(R.string.label_advances))
NumberPicker(
value = advances,
onIncrement = { onAdvancesChange(advances + 1) },
onDecrement = {
if (advances > 1) {
onAdvancesChange(advances - 1)
}
}
)
}
}
}
Loading

0 comments on commit af8c733

Please sign in to comment.