Add scroll management into the objects list.
This commit is contained in:
parent
3bda885411
commit
5db8e516ba
5 changed files with 51 additions and 38 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.pixelized.rplexicon.data.model
|
||||
|
||||
data class ObjectAction(
|
||||
val prefix: String?,
|
||||
val name: String,
|
||||
val effect: Throw?,
|
||||
)
|
||||
|
|
@ -20,12 +20,12 @@ class ObjectActionParser @Inject constructor(
|
|||
row.isNotEmpty() -> {
|
||||
val character = row[0]?.toItem()
|
||||
val name = row.parse(column = NAME)
|
||||
val effect = throwParser.parse(value = row.parse(column = EFFECT))
|
||||
if (character != null && name != null && effect != null) {
|
||||
if (character != null && name != null) {
|
||||
objects.getOrPut(character) { mutableListOf() }.add(
|
||||
ObjectAction(
|
||||
prefix = row.parse(column = PREFIX),
|
||||
name = name,
|
||||
effect = effect,
|
||||
effect = throwParser.parse(value = row.parse(column = EFFECT)),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -37,8 +37,9 @@ class ObjectActionParser @Inject constructor(
|
|||
}
|
||||
|
||||
companion object {
|
||||
private val PREFIX = column("Préfix")
|
||||
private val NAME = column("Nom")
|
||||
private val EFFECT = column("Effet")
|
||||
private val COLUMNS = listOf(NAME, EFFECT)
|
||||
private val COLUMNS = listOf(PREFIX, NAME, EFFECT)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,12 +6,11 @@ import androidx.compose.foundation.BorderStroke
|
|||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.minimumInteractiveComponentSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Surface
|
||||
|
|
@ -27,15 +26,17 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.rplexicon.R
|
||||
import com.pixelized.rplexicon.data.model.Throw
|
||||
import com.pixelized.rplexicon.ui.theme.LexiconTheme
|
||||
|
||||
@Stable
|
||||
data class ObjectItemUio(
|
||||
val prefix: String?,
|
||||
val name: String,
|
||||
val original: String?,
|
||||
val effect: Throw?,
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun ObjectItem(
|
||||
modifier: Modifier = Modifier,
|
||||
|
|
@ -47,6 +48,7 @@ fun ObjectItem(
|
|||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { onObject(item) }
|
||||
.minimumInteractiveComponentSize()
|
||||
.padding(paddingValues = padding)
|
||||
.then(other = modifier),
|
||||
horizontalArrangement = Arrangement.spacedBy(space = 12.dp),
|
||||
|
|
@ -55,41 +57,37 @@ fun ObjectItem(
|
|||
Column(
|
||||
modifier = Modifier.weight(weight = 1f)
|
||||
) {
|
||||
FlowRow(
|
||||
horizontalArrangement = Arrangement.spacedBy(space = 4.dp),
|
||||
) {
|
||||
Text(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = item.prefix?.let { "$it${item.name}" } ?: item.name,
|
||||
)
|
||||
item.original?.let {
|
||||
Text(
|
||||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
fontWeight = FontWeight.Light,
|
||||
fontStyle = FontStyle.Italic,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = item.name,
|
||||
text = it,
|
||||
)
|
||||
item.original?.let {
|
||||
Text(
|
||||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
fontWeight = FontWeight.Light,
|
||||
fontStyle = FontStyle.Italic,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = it,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
border = BorderStroke(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
onClick = { onUse(item) },
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.character_sheet_action_spell_cast),
|
||||
)
|
||||
if (item.effect != null) {
|
||||
OutlinedButton(
|
||||
border = BorderStroke(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
onClick = { onUse(item) },
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.character_sheet_action_spell_cast),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -103,8 +101,10 @@ private fun ObjectItemPreview() {
|
|||
ObjectItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
item = ObjectItemUio(
|
||||
name = "Potion de guérison",
|
||||
original = "Healing potion",
|
||||
prefix = "Parchemin de ",
|
||||
name = "Bénédiction",
|
||||
original = "Blessing",
|
||||
effect = Throw(1, 1, 0, emptyList()),
|
||||
),
|
||||
onObject = { },
|
||||
onUse = { },
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import com.pixelized.rplexicon.data.model.Throw
|
||||
import com.pixelized.rplexicon.ui.screens.character.composable.actions.ObjectItemUio
|
||||
|
||||
@Composable
|
||||
|
|
@ -12,8 +13,16 @@ fun rememberObjectListStatePreview() = remember {
|
|||
mutableStateOf(
|
||||
listOf(
|
||||
ObjectItemUio(
|
||||
prefix = null,
|
||||
name = "Potion de guérison",
|
||||
original = "Healing potion",
|
||||
effect = null,
|
||||
),
|
||||
ObjectItemUio(
|
||||
prefix = "Parchemin de",
|
||||
name = "Bénédiction",
|
||||
original = "Blessing",
|
||||
effect = Throw(1, 1, 0, emptyList()),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,8 +35,10 @@ class ObjectsViewModel @Inject constructor(
|
|||
objectsRepository.data.collect { objects ->
|
||||
val data = objects[character]?.map {
|
||||
ObjectItemUio(
|
||||
prefix = it.prefix,
|
||||
name = it.name,
|
||||
original = descriptionRepository.find(name = it.name)?.original
|
||||
original = descriptionRepository.find(name = it.name)?.original,
|
||||
effect = it.effect,
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue