diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/repository/alteration/AlterationRepository.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/repository/alteration/AlterationRepository.kt index e1df00c..5b8f383 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/repository/alteration/AlterationRepository.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/repository/alteration/AlterationRepository.kt @@ -159,13 +159,13 @@ class AlterationRepository( } fun activeAlterations( - characterSheetId: String, + characterSheetId: String?, ): List { return activeAlterationsFlow.value[characterSheetId] ?: emptyList() } fun activeAlterationsFlow( - characterSheetId: String, + characterSheetId: String?, ): Flow> { return activeAlterationsFlow.map { it[characterSheetId] ?: emptyList() } } diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/AlterationToggleItem.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/AlterationToggleItem.kt index 0c93876..7b9b868 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/AlterationToggleItem.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/AlterationToggleItem.kt @@ -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, + 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, diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogFactory.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogFactory.kt index 585cea8..f7cb291 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogFactory.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogFactory.kt @@ -33,6 +33,7 @@ class CharacterSheetAlterationDialogFactory( fun convertToDialogUio( characterSheet: CharacterSheet?, alterations: List, + activeAlterations: List, tagMap: Map, filter: LwaTextFieldUio, tags: StateFlow>, @@ -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, ) }, ) diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogViewModel.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogViewModel.kt index 80fcf16..5b7d3a6 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/alterteration/CharacterSheetAlterationDialogViewModel.kt @@ -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> = 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,