Add initiative roll into the character sheet header.
This commit is contained in:
		
							parent
							
								
									ff105e2f81
								
							
						
					
					
						commit
						0e65bd540e
					
				
					 8 changed files with 45 additions and 5 deletions
				
			
		| 
						 | 
					@ -156,6 +156,10 @@ fun CharacterSheetScreen(
 | 
				
			||||||
            onTab = {
 | 
					            onTab = {
 | 
				
			||||||
                scope.launch { pagerState.animateScrollToPage(it) }
 | 
					                scope.launch { pagerState.animateScrollToPage(it) }
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            onInitiative = {
 | 
				
			||||||
 | 
					                overlay.prepareRoll(diceThrow = headerViewModel.initiativeRoll())
 | 
				
			||||||
 | 
					                overlay.showOverlay()
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            onHitPoint = headerViewModel::toggleHitPointDialog,
 | 
					            onHitPoint = headerViewModel::toggleHitPointDialog,
 | 
				
			||||||
            onResource = {
 | 
					            onResource = {
 | 
				
			||||||
                headerViewModel.showSkillEditDialog(item = it)
 | 
					                headerViewModel.showSkillEditDialog(item = it)
 | 
				
			||||||
| 
						 | 
					@ -268,6 +272,7 @@ private fun CharacterSheetContent(
 | 
				
			||||||
    name: String,
 | 
					    name: String,
 | 
				
			||||||
    tabs: State<List<CharacterTabUio>>,
 | 
					    tabs: State<List<CharacterTabUio>>,
 | 
				
			||||||
    header: State<CharacterSheetHeaderUio?>,
 | 
					    header: State<CharacterSheetHeaderUio?>,
 | 
				
			||||||
 | 
					    onInitiative: () -> Unit,
 | 
				
			||||||
    onHitPoint: () -> Unit,
 | 
					    onHitPoint: () -> Unit,
 | 
				
			||||||
    onResource: (ResourcePointUio) -> Unit,
 | 
					    onResource: (ResourcePointUio) -> Unit,
 | 
				
			||||||
    onDeathRoll: () -> Unit,
 | 
					    onDeathRoll: () -> Unit,
 | 
				
			||||||
| 
						 | 
					@ -369,6 +374,7 @@ private fun CharacterSheetContent(
 | 
				
			||||||
                                CharacterSheetHeader(
 | 
					                                CharacterSheetHeader(
 | 
				
			||||||
                                    modifier = Modifier.fillMaxWidth(),
 | 
					                                    modifier = Modifier.fillMaxWidth(),
 | 
				
			||||||
                                    header = header,
 | 
					                                    header = header,
 | 
				
			||||||
 | 
					                                    onInitiative = onInitiative,
 | 
				
			||||||
                                    onHitPoint = onHitPoint,
 | 
					                                    onHitPoint = onHitPoint,
 | 
				
			||||||
                                    onResource = onResource,
 | 
					                                    onResource = onResource,
 | 
				
			||||||
                                    onDeathRoll = onDeathRoll,
 | 
					                                    onDeathRoll = onDeathRoll,
 | 
				
			||||||
| 
						 | 
					@ -511,6 +517,7 @@ private fun CharacterScreenPreview(
 | 
				
			||||||
                onSearch = { },
 | 
					                onSearch = { },
 | 
				
			||||||
                onFullRefresh = { },
 | 
					                onFullRefresh = { },
 | 
				
			||||||
                loader = { },
 | 
					                loader = { },
 | 
				
			||||||
 | 
					                onInitiative = { },
 | 
				
			||||||
                onHitPoint = { },
 | 
					                onHitPoint = { },
 | 
				
			||||||
                onResource = { },
 | 
					                onResource = { },
 | 
				
			||||||
                onDeathRoll = { },
 | 
					                onDeathRoll = { },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,9 +23,9 @@ import com.pixelized.rplexicon.ui.theme.LexiconTheme
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Stable
 | 
					@Stable
 | 
				
			||||||
data class CharacterSheetHeaderUio(
 | 
					data class CharacterSheetHeaderUio(
 | 
				
			||||||
 | 
					    val initiative: LabelPointUio,
 | 
				
			||||||
    val armorClass: LabelPointUio,
 | 
					    val armorClass: LabelPointUio,
 | 
				
			||||||
    val hitPoint: LabelPointUio,
 | 
					    val hitPoint: LabelPointUio,
 | 
				
			||||||
 | 
					 | 
				
			||||||
    val dC: LabelPointUio?,
 | 
					    val dC: LabelPointUio?,
 | 
				
			||||||
    val resource: ResourcePointUio?,
 | 
					    val resource: ResourcePointUio?,
 | 
				
			||||||
    val death: DeathThrowUio? = null
 | 
					    val death: DeathThrowUio? = null
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,7 @@ fun CharacterSheetHeader(
 | 
				
			||||||
    modifier: Modifier = Modifier,
 | 
					    modifier: Modifier = Modifier,
 | 
				
			||||||
    padding: PaddingValues = PaddingValues(start = 16.dp, end = 16.dp, bottom = 4.dp),
 | 
					    padding: PaddingValues = PaddingValues(start = 16.dp, end = 16.dp, bottom = 4.dp),
 | 
				
			||||||
    header: State<CharacterSheetHeaderUio?>,
 | 
					    header: State<CharacterSheetHeaderUio?>,
 | 
				
			||||||
 | 
					    onInitiative: () -> Unit,
 | 
				
			||||||
    onHitPoint: () -> Unit,
 | 
					    onHitPoint: () -> Unit,
 | 
				
			||||||
    onResource: (ResourcePointUio) -> Unit,
 | 
					    onResource: (ResourcePointUio) -> Unit,
 | 
				
			||||||
    onDeathRoll: () -> Unit,
 | 
					    onDeathRoll: () -> Unit,
 | 
				
			||||||
| 
						 | 
					@ -57,6 +58,9 @@ fun CharacterSheetHeader(
 | 
				
			||||||
                    alignment = Alignment.CenterHorizontally
 | 
					                    alignment = Alignment.CenterHorizontally
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
            ) {
 | 
					            ) {
 | 
				
			||||||
 | 
					                header.value?.initiative?.let {
 | 
				
			||||||
 | 
					                    LabelPoint(label = it, onClick = onInitiative)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                header.value?.armorClass?.let {
 | 
					                header.value?.armorClass?.let {
 | 
				
			||||||
                    LabelPoint(label = it)
 | 
					                    LabelPoint(label = it)
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -96,6 +100,7 @@ private fun CharacterSheetHeaderPreview() {
 | 
				
			||||||
                header = rememberCharacterHeaderStatePreview(
 | 
					                header = rememberCharacterHeaderStatePreview(
 | 
				
			||||||
                    death = rememberDeathThrowUio(),
 | 
					                    death = rememberDeathThrowUio(),
 | 
				
			||||||
                ),
 | 
					                ),
 | 
				
			||||||
 | 
					                onInitiative = { },
 | 
				
			||||||
                onHitPoint = { },
 | 
					                onHitPoint = { },
 | 
				
			||||||
                onResource = { },
 | 
					                onResource = { },
 | 
				
			||||||
                onDeathRoll = { },
 | 
					                onDeathRoll = { },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,10 @@ fun rememberCharacterHeaderStatePreview(
 | 
				
			||||||
) = remember {
 | 
					) = remember {
 | 
				
			||||||
    mutableStateOf(
 | 
					    mutableStateOf(
 | 
				
			||||||
        CharacterSheetHeaderUio(
 | 
					        CharacterSheetHeaderUio(
 | 
				
			||||||
 | 
					            initiative = LabelPointUio(
 | 
				
			||||||
 | 
					                label = R.string.character_sheet_title_initiative,
 | 
				
			||||||
 | 
					                value = "+0",
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
            armorClass = LabelPointUio(
 | 
					            armorClass = LabelPointUio(
 | 
				
			||||||
                label = R.string.character_sheet_title_ca,
 | 
					                label = R.string.character_sheet_title_ca,
 | 
				
			||||||
                value = "15",
 | 
					                value = "15",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ import com.pixelized.rplexicon.ui.screens.character.composable.character.DeathTh
 | 
				
			||||||
import com.pixelized.rplexicon.ui.screens.character.composable.character.LabelPointUio
 | 
					import com.pixelized.rplexicon.ui.screens.character.composable.character.LabelPointUio
 | 
				
			||||||
import com.pixelized.rplexicon.ui.screens.character.composable.character.ResourcePointUio
 | 
					import com.pixelized.rplexicon.ui.screens.character.composable.character.ResourcePointUio
 | 
				
			||||||
import com.pixelized.rplexicon.ui.screens.character.pages.actions.HeaderViewModel
 | 
					import com.pixelized.rplexicon.ui.screens.character.pages.actions.HeaderViewModel
 | 
				
			||||||
 | 
					import com.pixelized.rplexicon.utilitary.extentions.toLabel
 | 
				
			||||||
import javax.inject.Inject
 | 
					import javax.inject.Inject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CharacterSheetHeaderUioFactory @Inject constructor(
 | 
					class CharacterSheetHeaderUioFactory @Inject constructor(
 | 
				
			||||||
| 
						 | 
					@ -23,6 +24,10 @@ class CharacterSheetHeaderUioFactory @Inject constructor(
 | 
				
			||||||
            skill = sheetHeaderData?.characterClass?.resource
 | 
					            skill = sheetHeaderData?.characterClass?.resource
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        return CharacterSheetHeaderUio(
 | 
					        return CharacterSheetHeaderUio(
 | 
				
			||||||
 | 
					            initiative = LabelPointUio(
 | 
				
			||||||
 | 
					                label = R.string.character_sheet_title_initiative,
 | 
				
			||||||
 | 
					                value = sheetHeaderData?.initiative?.toLabel()
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
            armorClass = LabelPointUio(
 | 
					            armorClass = LabelPointUio(
 | 
				
			||||||
                label = R.string.character_sheet_title_ca,
 | 
					                label = R.string.character_sheet_title_ca,
 | 
				
			||||||
                value = sheetHeaderData?.ca?.let { "$it" } ?: "  ",
 | 
					                value = sheetHeaderData?.ca?.let { "$it" } ?: "  ",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,7 @@ import com.pixelized.rplexicon.ui.screens.character.composable.character.Charact
 | 
				
			||||||
import com.pixelized.rplexicon.ui.screens.character.composable.character.ResourcePointUio
 | 
					import com.pixelized.rplexicon.ui.screens.character.composable.character.ResourcePointUio
 | 
				
			||||||
import com.pixelized.rplexicon.ui.screens.character.factory.CharacterSheetHeaderUioFactory
 | 
					import com.pixelized.rplexicon.ui.screens.character.factory.CharacterSheetHeaderUioFactory
 | 
				
			||||||
import com.pixelized.rplexicon.utilitary.extentions.local.sum
 | 
					import com.pixelized.rplexicon.utilitary.extentions.local.sum
 | 
				
			||||||
 | 
					import com.pixelized.rplexicon.utilitary.extentions.modifier
 | 
				
			||||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
					import dagger.hilt.android.lifecycle.HiltViewModel
 | 
				
			||||||
import kotlinx.coroutines.Dispatchers
 | 
					import kotlinx.coroutines.Dispatchers
 | 
				
			||||||
import kotlinx.coroutines.flow.combine
 | 
					import kotlinx.coroutines.flow.combine
 | 
				
			||||||
| 
						 | 
					@ -64,14 +65,15 @@ class HeaderViewModel @Inject constructor(
 | 
				
			||||||
                    .combine(alterationRepository.assignedAlterations) { sheet, _ -> sheet }
 | 
					                    .combine(alterationRepository.assignedAlterations) { sheet, _ -> sheet }
 | 
				
			||||||
                    .collect { sheet ->
 | 
					                    .collect { sheet ->
 | 
				
			||||||
                        if (sheet != null) {
 | 
					                        if (sheet != null) {
 | 
				
			||||||
                            val alterations = alterationRepository.getActiveAlterationsStatus(
 | 
					                            val status = alterationRepository.getActiveAlterationsStatus(
 | 
				
			||||||
                                character = sheet.name,
 | 
					                                character = sheet.name,
 | 
				
			||||||
                            )
 | 
					                            )
 | 
				
			||||||
                            val data = SheetHeaderData(
 | 
					                            val data = SheetHeaderData(
 | 
				
			||||||
                                hpMax = sheet.hitPoint + alterations[Property.HIT_POINT].sum,
 | 
					                                hpMax = sheet.hitPoint + status[Property.HIT_POINT].sum,
 | 
				
			||||||
                                characterClass = sheet.characterClass.firstOrNull(),
 | 
					                                characterClass = sheet.characterClass.firstOrNull(),
 | 
				
			||||||
 | 
					                                initiative = (sheet.dexterity + status[Property.DEXTERITY].sum).modifier + status[Property.INITIATIVE].sum,
 | 
				
			||||||
                                speed = sheet.speed,
 | 
					                                speed = sheet.speed,
 | 
				
			||||||
                                ca = sheet.armorClass + alterations[Property.ARMOR_CLASS].sum,
 | 
					                                ca = sheet.armorClass + status[Property.ARMOR_CLASS].sum,
 | 
				
			||||||
                                dc = sheet.dC,
 | 
					                                dc = sheet.dC,
 | 
				
			||||||
                            )
 | 
					                            )
 | 
				
			||||||
                            withContext(Dispatchers.Main) {
 | 
					                            withContext(Dispatchers.Main) {
 | 
				
			||||||
| 
						 | 
					@ -169,10 +171,13 @@ class HeaderViewModel @Inject constructor(
 | 
				
			||||||
        hideSkillEditDialog()
 | 
					        hideSkillEditDialog()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun initiativeRoll(): DiceThrow.Initiative = DiceThrow.Initiative(character)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Stable
 | 
					    @Stable
 | 
				
			||||||
    data class SheetHeaderData(
 | 
					    data class SheetHeaderData(
 | 
				
			||||||
        val hpMax: Int,
 | 
					        val hpMax: Int,
 | 
				
			||||||
        val characterClass: CharacterSheet.Class?,
 | 
					        val characterClass: CharacterSheet.Class?,
 | 
				
			||||||
 | 
					        val initiative: Int,
 | 
				
			||||||
        val speed: Int,
 | 
					        val speed: Int,
 | 
				
			||||||
        val ca: Int,
 | 
					        val ca: Int,
 | 
				
			||||||
        val dc: Int?,
 | 
					        val dc: Int?,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,7 @@ class SummaryFactory @Inject constructor(
 | 
				
			||||||
            hp = SummaryRowUio(label = R.string.character_sheet_title_hp),
 | 
					            hp = SummaryRowUio(label = R.string.character_sheet_title_hp),
 | 
				
			||||||
            ac = SummaryRowUio(label = R.string.character_sheet_title_ca),
 | 
					            ac = SummaryRowUio(label = R.string.character_sheet_title_ca),
 | 
				
			||||||
            dc = SummaryRowUio(label = R.string.character_sheet_title_dc),
 | 
					            dc = SummaryRowUio(label = R.string.character_sheet_title_dc),
 | 
				
			||||||
 | 
					            initiative = SummaryRowUio(label = R.string.character_sheet_title_initiative),
 | 
				
			||||||
            speed = SummaryRowUio(label = R.string.character_sheet_title_speed),
 | 
					            speed = SummaryRowUio(label = R.string.character_sheet_title_speed),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        val characteristics = CharacteristicsSummaryUio(
 | 
					        val characteristics = CharacteristicsSummaryUio(
 | 
				
			||||||
| 
						 | 
					@ -179,6 +180,8 @@ class SummaryFactory @Inject constructor(
 | 
				
			||||||
                        val status = alterationRepository.getActiveAlterationsStatus(sheet.name)
 | 
					                        val status = alterationRepository.getActiveAlterationsStatus(sheet.name)
 | 
				
			||||||
                        val fire = fires[sheet.name]
 | 
					                        val fire = fires[sheet.name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        val dexterity = sheet.dexterity + status[Property.DEXTERITY].sum
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        val hitPoint = label(
 | 
					                        val hitPoint = label(
 | 
				
			||||||
                            label = fire?.hitPoint?.let {
 | 
					                            label = fire?.hitPoint?.let {
 | 
				
			||||||
                                when (it.additional) {
 | 
					                                when (it.additional) {
 | 
				
			||||||
| 
						 | 
					@ -193,13 +196,17 @@ class SummaryFactory @Inject constructor(
 | 
				
			||||||
                        val dC = label(
 | 
					                        val dC = label(
 | 
				
			||||||
                            label = sheet.dC?.let { "$it" } ?: "",
 | 
					                            label = sheet.dC?.let { "$it" } ?: "",
 | 
				
			||||||
                        )
 | 
					                        )
 | 
				
			||||||
 | 
					                        val initiative = label(
 | 
				
			||||||
 | 
					                            label = (dexterity.modifier + status[Property.INITIATIVE].sum).toLabel()
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
                        val speed = label(
 | 
					                        val speed = label(
 | 
				
			||||||
                            label = "${sheet.speed}",
 | 
					                            label = "${sheet.speed}m",
 | 
				
			||||||
                        )
 | 
					                        )
 | 
				
			||||||
                        withContext(Dispatchers.Main) {
 | 
					                        withContext(Dispatchers.Main) {
 | 
				
			||||||
                            stats.hp.get(sheet)?.value = hitPoint
 | 
					                            stats.hp.get(sheet)?.value = hitPoint
 | 
				
			||||||
                            stats.ac.get(sheet)?.value = armorClass
 | 
					                            stats.ac.get(sheet)?.value = armorClass
 | 
				
			||||||
                            stats.dc.get(sheet)?.value = dC
 | 
					                            stats.dc.get(sheet)?.value = dC
 | 
				
			||||||
 | 
					                            stats.initiative.get(sheet)?.value = initiative
 | 
				
			||||||
                            stats.speed.get(sheet)?.value = speed
 | 
					                            stats.speed.get(sheet)?.value = speed
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ data class AttributesSummaryUio(
 | 
				
			||||||
    val hp: SummaryRowUio,
 | 
					    val hp: SummaryRowUio,
 | 
				
			||||||
    val ac: SummaryRowUio,
 | 
					    val ac: SummaryRowUio,
 | 
				
			||||||
    val dc: SummaryRowUio,
 | 
					    val dc: SummaryRowUio,
 | 
				
			||||||
 | 
					    val initiative: SummaryRowUio,
 | 
				
			||||||
    val speed: SummaryRowUio,
 | 
					    val speed: SummaryRowUio,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +57,9 @@ fun AttributesSummary(
 | 
				
			||||||
        SummaryRow(
 | 
					        SummaryRow(
 | 
				
			||||||
            row = attributes.dc,
 | 
					            row = attributes.dc,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        SummaryRow(
 | 
				
			||||||
 | 
					            row = attributes.initiative,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
        SummaryRow(
 | 
					        SummaryRow(
 | 
				
			||||||
            row = attributes.speed,
 | 
					            row = attributes.speed,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,9 @@ fun rememberStatsSummary(): AttributesSummaryUio {
 | 
				
			||||||
                c4 = mutableStateOf(label(label = "13")),
 | 
					                c4 = mutableStateOf(label(label = "13")),
 | 
				
			||||||
                c5 = mutableStateOf(label(label = "14")),
 | 
					                c5 = mutableStateOf(label(label = "14")),
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            initiative = SummaryRowUio(
 | 
				
			||||||
 | 
					                label = R.string.character_sheet_title_initiative,
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
            speed = SummaryRowUio(
 | 
					            speed = SummaryRowUio(
 | 
				
			||||||
                label = R.string.character_sheet_title_speed,
 | 
					                label = R.string.character_sheet_title_speed,
 | 
				
			||||||
                c1 = mutableStateOf(label(label = "10m")),
 | 
					                c1 = mutableStateOf(label(label = "10m")),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue