Add a complete label on the questDetail screen.

This commit is contained in:
Thomas Andres Gomez 2023-08-02 16:10:35 +02:00
parent b865547717
commit 96d08aa3d8
5 changed files with 43 additions and 18 deletions

View file

@ -19,6 +19,11 @@ fun BackgroundImage(
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.TopCenter,
contentScale: ContentScale = ContentScale.Crop,
colorFilter: ColorFilter? = remember {
ColorFilter.colorMatrix(
ColorMatrix().also { it.setToSaturation(0f) }
)
},
model: () -> Any?,
) {
Box(
@ -29,11 +34,7 @@ fun BackgroundImage(
imageOptions = ImageOptions(
alignment = alignment,
contentScale = contentScale,
colorFilter = remember {
ColorFilter.colorMatrix(
ColorMatrix().also { it.setToSaturation(0f) }
)
},
colorFilter = colorFilter,
),
imageModel = model,
previewPlaceholder = R.drawable.im_brulkhai,

View file

@ -6,6 +6,7 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
@ -30,8 +31,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
@ -60,12 +63,12 @@ import java.lang.Integer.min
data class QuestDetailUio(
val id: Int,
val background: Uri?,
val completed: Boolean,
val title: String,
val steps: List<QuestStep>,
) {
@Stable
data class QuestStep(
val completed: Boolean,
val subtitle: String?,
val giverId: Int? = null,
val giver: String?,
@ -79,12 +82,12 @@ data class QuestDetailUio(
@Stable
data class AnnotatedQuestDetailUio(
val title: String,
val completed: Boolean,
val background: Uri?,
val steps: List<AnnotatedQuestStep>,
) {
@Stable
data class AnnotatedQuestStep(
val completed: Boolean,
val subtitle: String?,
val giverId: Int?,
val giver: String?,
@ -101,6 +104,7 @@ private fun QuestDetailUio.annotate(): AnnotatedQuestDetailUio {
val annotatedSteps = steps.map { it.annotate() }
return remember {
AnnotatedQuestDetailUio(
completed = completed,
title = title,
background = background,
steps = annotatedSteps,
@ -115,7 +119,6 @@ private fun QuestDetailUio.QuestStep.annotate(): AnnotatedQuestDetailUio.Annotat
return remember {
AnnotatedQuestDetailUio.AnnotatedQuestStep(
completed = completed,
subtitle = subtitle,
giverId = giverId,
giver = giver,
@ -185,13 +188,28 @@ private fun QuestDetailContent(
Surface(
modifier = Modifier.padding(padding),
) {
BackgroundImage(
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(ratio = 1f)
.scrollOffset(scrollState = state) { -it / 2 },
model = { annotatedQuest.background },
)
) {
BackgroundImage(
modifier = Modifier.matchParentSize(),
model = { annotatedQuest.background },
)
if (annotatedQuest.completed) {
Text(
modifier = Modifier
.align(Alignment.TopEnd)
.padding(top = 32.dp, end = 16.dp)
.rotate(degrees = 12f),
style = MaterialTheme.lexicon.typography.stamp,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.35f),
text = "Completed",
)
}
}
Column(
modifier = Modifier
.verticalScroll(state)
@ -356,11 +374,11 @@ private class QuestDetailPreviewProvider : PreviewParameterProvider<State<QuestD
mutableStateOf(
QuestDetailUio(
id = 0,
completed = true,
background = Uri.parse("https://as1.ftcdn.net/v2/jpg/05/50/22/58/1000_F_550225869_jAkLTRVb7ym7EHJYvDApVXQnpANvRd8O.jpg"),
title = "La chasse aux loups",
steps = listOf(
QuestDetailUio.QuestStep(
completed = false,
subtitle = "Partie 1",
giver = "Sergent d'arme",
place = "DaggerFord",
@ -369,7 +387,6 @@ private class QuestDetailPreviewProvider : PreviewParameterProvider<State<QuestD
description = "Des nobles participant aux festivités de DaggerFord aurait entendu des loups dans la forêt proche. Sur ordre du baron, cette forêt doit être fouillée bien que depuis 300 ans, aucun loup n'y ait été vu.",
),
QuestDetailUio.QuestStep(
completed = false,
subtitle = "Partie 2",
giver = "Sergent d'arme",
place = "DaggerFord",
@ -383,11 +400,11 @@ private class QuestDetailPreviewProvider : PreviewParameterProvider<State<QuestD
mutableStateOf(
QuestDetailUio(
id = 1,
completed = false,
background = Uri.parse("https://cdnb.artstation.com/p/assets/images/images/008/823/761/large/jon-pintar-adventurers-caravan-jon-pintar.jpg?1515529013"),
title = "Les enfants de la caravanes",
steps = listOf(
QuestDetailUio.QuestStep(
completed = false,
subtitle = null,
giver = null,
place = null,

View file

@ -25,11 +25,11 @@ class QuestDetailViewModel @Inject constructor(
quest = mutableStateOf(
QuestDetailUio(
id = source.id,
completed = source.entries.all { it.complete },
background = source.entries.mapNotNull { it.background }.randomOrNull(),
title = source.title,
steps = source.entries.map { entry ->
QuestDetailUio.QuestStep(
completed = entry.complete,
subtitle = entry.subtitle,
giverId = lexiconRepository.findId(entry.questGiver),
giver = entry.questGiver,

View file

@ -12,24 +12,31 @@ import androidx.compose.ui.unit.sp
import com.pixelized.rplexicon.R
@Stable
val regal = FontFamily(
val regalFontFamily = FontFamily(
Font(resId = R.font.regal, weight = FontWeight.Normal),
)
val stampFontFamily = FontFamily(
Font(resId = R.font.rubber_stamp, weight = FontWeight.Normal),
)
@Suppress("MemberVisibilityCanBePrivate")
@Stable
class LexiconTypography(
val base: Typography = Typography(),
val dropCapMedium: TextStyle = base.displaySmall.copy(
fontFamily = regal,
fontFamily = regalFontFamily,
baselineShift = BaselineShift(-0.3f),
letterSpacing = (-6).sp
),
val dropCapLarge: TextStyle = base.displayMedium.copy(
fontFamily = regal,
fontFamily = regalFontFamily,
baselineShift = BaselineShift.Subscript,
letterSpacing = (-8).sp
),
val stamp: TextStyle = base.headlineLarge.copy(
fontFamily = stampFontFamily,
)
) {
val dropCapMediumSpan: SpanStyle = dropCapMedium.toSpanStyle()
val dropCapLargeSpan: SpanStyle = dropCapLarge.toSpanStyle()

Binary file not shown.