Skip to content

Commit a09e2f9

Browse files
committed
Add Frosthaven utils
1 parent 7675696 commit a09e2f9

7 files changed

Lines changed: 128 additions & 0 deletions

File tree

app/src/main/java/com/github/muellerma/tabletoptools/ui/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class MainActivity : AppCompatActivity() {
4646
R.id.nav_prime_fac,
4747
R.id.nav_timer,
4848
R.id.nav_buzzers,
49+
R.id.nav_frosthaven,
4950
R.id.nav_prefs
5051
),
5152
binding.drawerLayout
@@ -66,6 +67,7 @@ class MainActivity : AppCompatActivity() {
6667
getString(R.string.menu_prime_fac_value) -> R.id.nav_prime_fac
6768
getString(R.string.menu_timer_value) -> R.id.nav_timer
6869
getString(R.string.menu_buzzers_value) -> R.id.nav_buzzers
70+
getString(R.string.menu_frosthaven_value) -> R.id.nav_frosthaven
6971
else -> R.id.nav_dice
7072
}
7173
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.muellerma.tabletoptools.ui.fragments
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import androidx.core.widget.addTextChangedListener
8+
import com.github.muellerma.tabletoptools.R
9+
import com.github.muellerma.tabletoptools.databinding.FragmentFrosthavenBinding
10+
import kotlin.math.ceil
11+
12+
13+
class FrosthavenFragment : AbstractBaseFragment() {
14+
private lateinit var binding: FragmentFrosthavenBinding
15+
16+
override fun onCreateView(
17+
inflater: LayoutInflater,
18+
container: ViewGroup?,
19+
savedInstanceState: Bundle?
20+
): View {
21+
binding = FragmentFrosthavenBinding.inflate(inflater, container, false)
22+
setupScreenOn(binding.root)
23+
24+
binding.scenarioLevelInput.addTextChangedListener {
25+
binding.scenarioLevelOutput.text =
26+
getString(R.string.frosthaven_scenario_level_out, calculateScenarioLevel(it.toString()))
27+
}
28+
29+
return binding.root
30+
}
31+
32+
companion object {
33+
private fun calculateScenarioLevel(characterLevels: String): Int {
34+
val avg = "\\d+".toRegex().findAll(characterLevels).map { it.value.toInt() }.average()
35+
return ceil(avg / 2).toInt()
36+
}
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M20.79,13.95L18.46,14.57L16.46,13.44V10.56L18.46,9.43L20.79,10.05L21.31,8.12L19.54,7.65L20,5.88L18.07,5.36L17.45,7.69L15.45,8.82L13,7.38V5.12L14.71,3.41L13.29,2L12,3.29L10.71,2L9.29,3.41L11,5.12V7.38L8.5,8.82L6.5,7.69L5.92,5.36L4,5.88L4.47,7.65L2.7,8.12L3.22,10.05L5.55,9.43L7.55,10.56V13.45L5.55,14.58L3.22,13.96L2.7,15.89L4.47,16.36L4,18.12L5.93,18.64L6.55,16.31L8.55,15.18L11,16.62V18.88L9.29,20.59L10.71,22L12,20.71L13.29,22L14.7,20.59L13,18.88V16.62L15.5,15.17L17.5,16.3L18.12,18.63L20,18.12L19.53,16.35L21.3,15.88L20.79,13.95M9.5,10.56L12,9.11L14.5,10.56V13.44L12,14.89L9.5,13.44V10.56Z"/>
9+
</vector>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:fillViewport="true"
9+
tools:context=".ui.fragments.FrosthavenFragment">
10+
11+
<androidx.constraintlayout.widget.ConstraintLayout
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content">
14+
15+
<TextView
16+
android:id="@+id/scenario_level_header"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:text="@string/frosthaven_character_header"
20+
android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall"
21+
app:layout_constraintStart_toStartOf="parent"
22+
app:layout_constraintEnd_toEndOf="parent"
23+
app:layout_constraintTop_toTopOf="parent"
24+
android:layout_marginStart="16dp"
25+
android:layout_marginEnd="16dp"
26+
android:layout_marginTop="16dp" />
27+
28+
<EditText
29+
android:layout_width="0dp"
30+
android:layout_height="wrap_content"
31+
android:inputType="number"
32+
android:digits="1234567890 ,."
33+
android:gravity="start|top"
34+
android:lines="1"
35+
android:hint="@string/frosthaven_scenario_level_hint"
36+
android:id="@+id/scenario_level_input"
37+
app:layout_constraintEnd_toEndOf="parent"
38+
app:layout_constraintStart_toStartOf="parent"
39+
android:layout_marginStart="8dp"
40+
android:layout_marginEnd="8dp"
41+
android:importantForAutofill="no"
42+
tools:ignore="LabelFor"
43+
app:layout_constraintHorizontal_bias="0.0"
44+
app:layout_constraintTop_toBottomOf="@+id/scenario_level_header"
45+
android:layout_marginTop="8dp" />
46+
47+
<TextView
48+
android:layout_width="0dp"
49+
android:layout_height="0dp"
50+
android:id="@+id/scenario_level_output"
51+
app:layout_constraintTop_toBottomOf="@id/scenario_level_input"
52+
android:layout_marginTop="16dp"
53+
android:textIsSelectable="true"
54+
app:layout_constraintEnd_toEndOf="parent"
55+
app:layout_constraintStart_toStartOf="parent"
56+
android:layout_marginStart="8dp"
57+
android:layout_marginEnd="8dp"
58+
app:layout_constraintBottom_toBottomOf="parent"
59+
android:layout_marginBottom="8dp" />
60+
61+
</androidx.constraintlayout.widget.ConstraintLayout>
62+
</ScrollView>

app/src/main/res/menu/activity_main_drawer.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
android:id="@+id/nav_buzzers"
4343
android:icon="@drawable/ic_radio_button_unchecked"
4444
android:title="@string/menu_buzzers" />
45+
<item
46+
android:id="@+id/nav_frosthaven"
47+
android:icon="@drawable/snowflake"
48+
android:title="@string/menu_frosthaven" />
4549
<item
4650
android:id="@+id/nav_prefs"
4751
android:icon="@drawable/ic_outline_settings_24"

app/src/main/res/navigation/mobile_navigation.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
android:label="@string/menu_buzzers"
5959
tools:layout="@layout/fragment_buzzers" />
6060

61+
<fragment
62+
android:id="@+id/nav_frosthaven"
63+
android:name="com.github.muellerma.tabletoptools.ui.fragments.FrosthavenFragment"
64+
android:label="@string/menu_frosthaven"
65+
tools:layout="@layout/fragment_frosthaven" />
66+
6167
<fragment
6268
android:id="@+id/nav_prefs"
6369
android:name="com.github.muellerma.tabletoptools.ui.fragments.PreferenceFragment"

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<string name="menu_number_converter_value" translatable="false">converter</string>
5252
<string name="menu_prime_fac_value" translatable="false">prime_fac</string>
5353
<string name="menu_counter_value" translatable="false">counter</string>
54+
<string name="menu_frosthaven_value" translatable="false">frosthaven</string>
5455

5556
<!-- Dice -->
5657
<string name="menu_dice">Dice</string>
@@ -90,6 +91,12 @@
9091
<item quantity="other">%d buzzers</item>
9192
</plurals>
9293

94+
<!-- Frosthaven -->
95+
<string name="menu_frosthaven">Frosthaven</string>
96+
<string name="frosthaven_character_header">Calculate scenario level</string>
97+
<string name="frosthaven_scenario_level_hint">Enter character levels separated by comma</string>
98+
<string name="frosthaven_scenario_level_out">Scenario level: %d</string>
99+
93100
<!-- Preferences -->
94101
<string name="start_page">Start page</string>
95102
<string name="general">General</string>

0 commit comments

Comments
 (0)