Add shadow on circle + change map structure

This commit is contained in:
Thomas Andres Gomez 2023-08-10 16:21:48 +02:00
parent 01e312fce1
commit dc35ac0ef9
7 changed files with 60 additions and 31 deletions

View file

@ -49,7 +49,7 @@ class LocationParser @Inject constructor() {
companion object {
private val COLUMNS = listOf(
"nom", "carte"
"Nom", "Carte"
)
}
}

View file

@ -1,5 +1,6 @@
package com.pixelized.rplexicon.facotry
import androidx.compose.ui.geometry.Offset
import com.google.api.services.sheets.v4.model.ValueRange
import com.pixelized.rplexicon.model.Location
import com.pixelized.rplexicon.utilitary.extentions.checkSheetStructure
@ -30,12 +31,14 @@ class MarqueeParser @Inject constructor() {
?.toFloatOrNull()
val description = item.getOrNull(structure.description) as? String?
if (map != null && name != null && x != null && y != null) {
if (map != null && name != null) {
Location.Marquee(
map = map,
name = name,
x = x,
y = y,
position = when {
x != null && y != null -> Offset(x, y)
else -> Offset.Unspecified
},
description = description,
)
} else {
@ -56,7 +59,7 @@ class MarqueeParser @Inject constructor() {
companion object {
private val COLUMNS = listOf(
"carte", "nom", "x", "y", "description"
"Carte", "Nom", "X", "Y", "Description"
)
}
}

View file

@ -2,6 +2,7 @@ package com.pixelized.rplexicon.model
import android.net.Uri
import androidx.compose.runtime.Stable
import androidx.compose.ui.geometry.Offset
@Stable
data class Location(
@ -15,8 +16,7 @@ data class Location(
data class Marquee(
val map: String,
val name: String,
val x: Float,
val y: Float,
val position: Offset,
val description: String?,
)
}

View file

@ -6,6 +6,7 @@ import androidx.compose.animation.core.animateOffsetAsState
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
@ -28,6 +29,7 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.pixelized.rplexicon.ui.composable.AsyncImage
import com.pixelized.rplexicon.utilitary.extentions.lexicon
import com.skydoves.landscapist.ImageOptions
@Composable
@ -40,6 +42,7 @@ fun FantasyMap(
selectedItem: State<Int>,
onMarquee: (MarqueeUio) -> Unit,
) {
val colorScheme = MaterialTheme.lexicon.colorScheme
val animatedScale = animateFloatAsState(targetValue = state.scale, label = "ScaleAnimation")
val animatedOffset = animateOffsetAsState(targetValue = state.offset, label = "OffsetAnimation")
@ -82,6 +85,18 @@ fun FantasyMap(
.drawWithContent {
drawContent()
item.value.marquees.forEachIndexed { index, item ->
if (item.position != Offset.Unspecified) {
drawCircle(
color = colorScheme.shadow,
radius = 12.dp.toPx() / animatedScale.value,
style = Stroke(
width = 2.dp.toPx() / animatedScale.value,
),
center = Offset(
x = size.width * item.position.x,
y = size.height * item.position.y + 2.dp.toPx() / animatedScale.value,
)
)
drawCircle(
color = when (selectedItem.value) {
index -> Color.Cyan
@ -89,15 +104,16 @@ fun FantasyMap(
},
radius = 12.dp.toPx() / animatedScale.value,
style = Stroke(
width = 2.dp.toPx() / animatedScale.value
width = 2.dp.toPx() / animatedScale.value,
),
center = Offset(
x = size.width * item.position.x,
y = size.height * item.position.y
y = size.height * item.position.y,
)
)
}
}
}
.pointerInput("DetectTapGestures") {
detectTapGestures(
onTap = { tap ->
@ -169,20 +185,26 @@ class FantasyMapState(
fun pan(
offset: Offset,
) {
if (offset != Offset.Unspecified) {
_offset.value = Offset(
x = maxOf(minX, minOf(maxX, offset.x)),
y = maxOf(minY, minOf(maxY, offset.y)),
)
}
}
@Stable
fun computeMarqueeOffset(
origin: Offset,
size: IntSize = imageSize,
): Offset {
return Offset(
return when (origin != Offset.Unspecified) {
true -> Offset(
x = (size.width / 2f - origin.x * size.width) * scale,
y = (size.height / 2f - origin.y * size.height) * scale,
)
else -> origin
}
}
}

View file

@ -28,7 +28,7 @@ class LocationDetailViewModel @Inject constructor(
marquees = source.marquees.map { marquee ->
MarqueeUio(
name = marquee.name,
position = Offset(x = marquee.x, y = marquee.y),
position = marquee.position,
description = marquee.description,
)
}

View file

@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.Color
@Immutable
class LexiconColors(
val base: ColorScheme,
val shadow: Color,
val status: Color,
val navigation: Color,
val placeholder: Color,
@ -25,11 +26,13 @@ fun darkColorScheme(
tertiary = BaseDark.Pink80,
onPrimary = Color.White,
),
shadow: Color = ShadowPalette.shadow,
status: Color = Color.Transparent,
navigation: Color = Color.Transparent,
placeholder: Color = Color(red = 49, green = 48, blue = 51),
) = LexiconColors(
base = base,
shadow = shadow,
status = status,
navigation = navigation,
placeholder = placeholder,
@ -44,11 +47,13 @@ fun lightColorScheme(
tertiary = BaseLight.Pink40,
onPrimary = Color.White,
),
shadow: Color = ShadowPalette.shadow,
status: Color = Color.Transparent,
navigation: Color = Color.Transparent,
placeholder: Color = Color(red = 230, green = 225, blue = 229),
) = LexiconColors(
base = base,
shadow = shadow,
status = status,
navigation = navigation,
placeholder = placeholder,

View file

@ -5,6 +5,5 @@ import androidx.compose.ui.graphics.Color
@Immutable
object ShadowPalette {
val system: Color = Color.Black.copy(alpha = 0.37f)
val scrim: Color = Color.Black.copy(alpha = 0.37f)
val shadow: Color = Color.Black.copy(alpha = 0.25f)
}