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