Update the Alteration dialog to track equipment alterations.
This commit is contained in:
parent
5b633de981
commit
3b9503243a
4 changed files with 18 additions and 7 deletions
|
|
@ -159,13 +159,13 @@ class AlterationRepository(
|
|||
}
|
||||
|
||||
fun activeAlterations(
|
||||
characterSheetId: String,
|
||||
characterSheetId: String?,
|
||||
): List<Alteration> {
|
||||
return activeAlterationsFlow.value[characterSheetId] ?: emptyList()
|
||||
}
|
||||
|
||||
fun activeAlterationsFlow(
|
||||
characterSheetId: String,
|
||||
characterSheetId: String?,
|
||||
): Flow<List<Alteration>> {
|
||||
return activeAlterationsFlow.map { it[characterSheetId] ?: emptyList() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import androidx.compose.runtime.Stable
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTag
|
||||
|
|
@ -28,6 +29,7 @@ data class AlterationToggleItemUio(
|
|||
val id: String,
|
||||
val label: String,
|
||||
val tags: List<GMTagUio>,
|
||||
val enable: Boolean,
|
||||
val active: Boolean,
|
||||
)
|
||||
|
||||
|
|
@ -47,10 +49,11 @@ fun AlterationToggleItem(
|
|||
Row(
|
||||
modifier = Modifier
|
||||
.clip(shape = MaterialTheme.lwa.shapes.gameMaster)
|
||||
.clickable(onClick = onAlteration)
|
||||
.clickable(enabled = alteration.enable, onClick = onAlteration)
|
||||
.background(color = MaterialTheme.lwa.colorScheme.elevated.base1dp)
|
||||
.minimumInteractiveComponentSize()
|
||||
.padding(paddingValues = padding)
|
||||
.graphicsLayer { this.alpha = if (alteration.enable) 1f else 0.5f }
|
||||
.then(other = modifier),
|
||||
horizontalArrangement = Arrangement.spacedBy(space = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class CharacterSheetAlterationDialogFactory(
|
|||
fun convertToDialogUio(
|
||||
characterSheet: CharacterSheet?,
|
||||
alterations: List<Alteration>,
|
||||
activeAlterations: List<Alteration>,
|
||||
tagMap: Map<String, Tag>,
|
||||
filter: LwaTextFieldUio,
|
||||
tags: StateFlow<List<GMTagUio>>,
|
||||
|
|
@ -46,6 +47,8 @@ class CharacterSheetAlterationDialogFactory(
|
|||
filter = filter,
|
||||
tags = tags,
|
||||
alterations = alterations.map { alteration ->
|
||||
val isActive = activeAlterations.contains(alteration)
|
||||
val isPersonal = characterSheet.alterations.contains(alteration.id)
|
||||
AlterationToggleItemUio(
|
||||
id = alteration.id,
|
||||
label = alteration.metadata.name,
|
||||
|
|
@ -53,7 +56,8 @@ class CharacterSheetAlterationDialogFactory(
|
|||
tags = alteration.tags.mapNotNull { tagMap[it] },
|
||||
selectedTagId = selectedTagId
|
||||
),
|
||||
active = characterSheet.alterations.contains(alteration.id),
|
||||
enable = isPersonal || isActive.not(), // disable alteration coming from equipment
|
||||
active = isActive,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ import com.pixelized.desktop.lwa.ui.composable.textfield.createLwaTextFieldFlow
|
|||
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagFactory
|
||||
import com.pixelized.desktop.lwa.ui.screen.gamemaster.common.tag.GMTagUio
|
||||
import com.pixelized.desktop.lwa.utils.extention.unAccent
|
||||
import com.pixelized.shared.lwa.model.alteration.Alteration
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
|
|
@ -43,7 +45,7 @@ class CharacterSheetAlterationDialogViewModel(
|
|||
)
|
||||
private val filter = _filter.createLwaTextField()
|
||||
|
||||
private val selectedAlterationsFlow = combine(
|
||||
private val filteredAlterationsFlow: Flow<List<Alteration>> = combine(
|
||||
alterationRepository.alterationFlow.map { it.values },
|
||||
_filter.valueFlow.map { it.unAccent() },
|
||||
selectedTagIdFlow,
|
||||
|
|
@ -72,14 +74,16 @@ class CharacterSheetAlterationDialogViewModel(
|
|||
.flatMapLatest { characterSheetId ->
|
||||
combine(
|
||||
characterSheetRepository.characterDetailFlow(characterSheetId = characterSheetId),
|
||||
alterationRepository.activeAlterationsFlow(characterSheetId = characterSheetId),
|
||||
tagRepository.alterationsTagFlow(),
|
||||
selectedAlterationsFlow,
|
||||
filteredAlterationsFlow,
|
||||
selectedTagIdFlow,
|
||||
) { characterSheet, tagMap, alterations, selectedTagId ->
|
||||
) { characterSheet, activeAlterations, tagMap, alterations, selectedTagId ->
|
||||
dialogFactory.convertToDialogUio(
|
||||
characterSheet = characterSheet,
|
||||
tagMap = tagMap,
|
||||
alterations = alterations,
|
||||
activeAlterations = activeAlterations,
|
||||
filter = filter,
|
||||
tags = tags,
|
||||
selectedTagId = selectedTagId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue