Skip to content

Commit

Permalink
feat(character): add skill selector
Browse files Browse the repository at this point in the history
relates to #7
  • Loading branch information
Patrick Hoefer committed Jan 2, 2021
1 parent 3c1861d commit d470341
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 47 deletions.
1 change: 1 addition & 0 deletions detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>LongMethod:CharacterFactoryView.kt$@Composable fun CharacterFactoryView()</ID>
<ID>LongMethod:CharacterFactoryView.kt$@Composable private fun Traits( traitSelection: TraitSelection, personalityTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, commanderTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, criminalTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, copingTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, healthTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, dynastyTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, descendantTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, diseaseTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, childhoodTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, educationalTraitSelectionState: SnapshotStateMap&lt;LeveledTrait, Int&gt;, physicalTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, lifestyleTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, leveledLifestyleTraitSelectionState: SnapshotStateMap&lt;LeveledTrait, Int&gt;, congenitalTraitSelectionState: SnapshotStateMap&lt;Trait, Boolean&gt;, leveledCongenitalTraitSelectionState: SnapshotStateMap&lt;LeveledTrait, Int&gt; )</ID>
<ID>ReturnCount:ProjectFileFilter.kt$ProjectFileFilter$override fun accept(file: File?): Boolean</ID>
<ID>TooManyFunctions:TraitSelection.kt$TraitSelection</ID>
</CurrentIssues>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.imageFromResource
import androidx.compose.ui.unit.TextUnit
Expand All @@ -37,9 +36,9 @@ class SkillSelection {

@Composable
fun Skills(
selectionState: SnapshotStateMap<Skill, Boolean>
selectionState: SnapshotStateMap<Skill, Int>
) {
val chunks = enumValues<Skill>().toList().chunked(5)
val chunks = enumValues<Skill>().toList().chunked(6)
chunks.forEach {
Row {
it.forEach {
Expand All @@ -52,42 +51,29 @@ class SkillSelection {
@Composable
fun SkillIcon(
skill: Skill,
selectionState: SnapshotStateMap<Skill, Boolean>
selectionState: SnapshotStateMap<Skill, Int>
) {
var isSelected by remember { mutableStateOf(false) }
var selectionModifier by remember { mutableStateOf(Modifier.alpha(0.2F)) }
var counter by remember { mutableStateOf(5) }
selectionState[skill] = counter

Column(
modifier = Modifier.size(60.dp, 75.dp),
modifier = Modifier.size(75.dp, 80.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
Modifier.clickable(
onClick = {
isSelected = !isSelected
selectionState[skill] = isSelected
selectionModifier = if (!isSelected) Modifier.alpha(0.2F) else Modifier.alpha(1F)
}
),
contentAlignment = Alignment.Center,
) {
SkillIconImage(selectionModifier, skill)
Box(contentAlignment = Alignment.Center) {
Image(modifier = Modifier.size(60.dp), bitmap = skillImage(skill))
}
Row {
Text(modifier = Modifier.clickable { counter = if (counter <= 1) 0 else counter.minus(1) }, text = "<")
Text(counter.toString())
Text(
modifier = Modifier.clickable { counter = if (counter >= 100) 100 else counter.plus(1) },
text = ">"
)
}
if (isSelected) SkillLabel(skill)
}
}

@Composable
fun SkillIconImage(
selectionModifier: Modifier,
skill: Skill
) {
Image(
modifier = selectionModifier,
bitmap = skillImage(skill)
)
}

@Composable
fun SkillLabel(skill: Skill) {
Text(
Expand All @@ -105,6 +91,6 @@ class SkillSelection {
}

companion object {
val skillIconPath = "icons/skill_icons"
const val skillIconPath = "icons/skill_icons"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ class TraitSelection {
}

companion object {
val traitIconPath = "icons/trait_icons"

const val traitIconPath = "icons/trait_icons"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun CharacterFactoryView() {
val leveledLifestyleTraitSelectionState = remember { mutableStateMapOf<LeveledTrait, Int>() }
val leveledCongenitalTraitSelectionState = remember { mutableStateMapOf<LeveledTrait, Int>() }

val skillSelectionState = remember { mutableStateMapOf<SkillSelection.Skill, Boolean>() }
val skillSelectionState = remember { mutableStateMapOf<SkillSelection.Skill, Int>() }

Column(
modifier = Modifier.padding(top = 15.dp, bottom = 7.dp).fillMaxSize(),
Expand Down Expand Up @@ -227,20 +227,22 @@ private fun Traits(
congenitalTraitSelectionState: SnapshotStateMap<Trait, Boolean>,
leveledCongenitalTraitSelectionState: SnapshotStateMap<LeveledTrait, Int>
) {
Spoiler(label = {
Box(
Modifier.background(Color.LightGray)
.sizeIn(100.dp, 30.dp)
.padding(5.dp),
contentAlignment = Alignment.Center
) {
Text(
fontSize = TextUnit.Em(1.2),
fontWeight = FontWeight.Bold,
text = "Traits"
)
Spoiler(
label = {
Box(
Modifier.background(Color.LightGray)
.sizeIn(100.dp, 30.dp)
.padding(5.dp),
contentAlignment = Alignment.Center
) {
Text(
fontSize = TextUnit.Em(1.2),
fontWeight = FontWeight.Bold,
text = "Traits"
)
}
}
}) {
) {
TraitSection("Personality Traits") {
traitSelection.Traits<PersonalityTrait>(personalityTraitSelectionState)
}
Expand Down

0 comments on commit d470341

Please sign in to comment.