Skip to content

Commit

Permalink
#15: Visualize individual darts
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Dec 11, 2017
1 parent e8d0f62 commit f522d98
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.entreco.dartsscorecard.play.input

import android.databinding.BindingAdapter
import android.support.design.widget.FloatingActionButton
import android.view.View
import android.widget.TextView
import nl.entreco.dartsscorecard.R
Expand Down Expand Up @@ -34,12 +35,32 @@ class InputBindings {
}


@JvmStatic
@BindingAdapter("numDarts")
fun numDartsState(view: FloatingActionButton, dartsLeft: Int) {
when (dartsLeft) {
3 -> {
view.isSelected = true
view.isActivated = false
}
2 ->{
view.isSelected = false
view.isActivated = true
}
1 -> {
view.isSelected = false
view.isActivated = false
}
}
}


@JvmStatic
@BindingAdapter("special")
fun showSpecialEvents(view: TextView, event: SpecialEvent?) {
clear(view, 0)
if (event != null) {
when(event) {
when (event) {
is NoScoreEvent -> handleNoScore(view)
is ThrownEvent -> handleThrown(view, event.describe)
is BustEvent -> handleBust(view)
Expand All @@ -61,14 +82,14 @@ class InputBindings {
}

private fun handleNoScore(view: TextView) {
view.setText( R.string.no_score )
view.setText(R.string.no_score)
view.animate().translationX(0F).setDuration(DEFAULT_ANIMATION_TIME).withEndAction({
clear(view, 500)
}).start()
}

private fun handleBust(view: TextView) {
view.setText( R.string.bust )
view.setText(R.string.bust)
view.animate().translationX(0F).setDuration(DEFAULT_ANIMATION_TIME).withEndAction({
clear(view, 500)
}).start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ open class InputViewModel @Inject constructor(private val analytics: Analytics,
val hintProvider = ObservableField<HintKeyProvider>(HintKeyProvider(toggle.get()))
val special = ObservableField<SpecialEvent?>()
val required = ObservableField<Score>()
val dartsLeft = ObservableInt()

private val estimator = ScoreEstimator()
private var turn = Turn()
Expand Down Expand Up @@ -114,6 +115,7 @@ open class InputViewModel @Inject constructor(private val analytics: Analytics,

private fun submitDart(dart: Dart, listener: InputListener) {
turn += dart
dartsLeft.set(turn.dartsLeft())
listener.onDartThrown(turn.copy(), nextUp?.player!!)

when {
Expand Down Expand Up @@ -143,6 +145,7 @@ open class InputViewModel @Inject constructor(private val analytics: Analytics,
nextDescription.set(descriptionFromNext(next))
current.set(next.player)
turn = Turn()
dartsLeft.set(turn.dartsLeft())
}

private fun descriptionFromNext(next: Next): Int {
Expand Down
2 changes: 1 addition & 1 deletion android/DartsScorecard/app/src/main/res/drawable/dart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<item
android:id="@+id/dartsLeft_0"
android:state_pressed="true"
android:drawable="@drawable/dart_throw" />
android:drawable="@drawable/ic_dart" />

<item
android:id="@+id/dartsLeft_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="translateX"
android:valueFrom="0"
android:valueTo="-300"
android:valueTo="-500"
android:valueType="floatType" />
</aapt:attr>
</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="@drawable/ic_darts_3">

<target android:name="path1">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="fillAlpha"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType" />
</aapt:attr>
</target>
<target android:name="path2">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="fillAlpha"
android:valueFrom=".4"
android:valueTo="1"
android:valueType="floatType" />
</aapt:attr>
</target>
<target android:name="dart1">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="translateX"
android:valueFrom="0"
android:valueTo="-500"
android:valueType="floatType" />
</aapt:attr>
</target>

</animated-vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="@drawable/ic_darts_2">

<target android:name="path2">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="fillAlpha"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType" />
</aapt:attr>
</target>
<target android:name="path3">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="fillAlpha"
android:valueFrom=".4"
android:valueTo="1"
android:valueType="floatType" />
</aapt:attr>
</target>
<target android:name="dart2">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="translateX"
android:valueFrom="0"
android:valueTo="-500"
android:valueType="floatType" />
</aapt:attr>
</target>

</animated-vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="@drawable/ic_darts_1">

<target android:name="path3">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="fillAlpha"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType" />
</aapt:attr>
</target>
<target android:name="dart3">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="1000"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="translateX"
android:valueFrom="0"
android:valueTo="-500"
android:valueType="floatType" />
</aapt:attr>
</target>

</animated-vector>
53 changes: 44 additions & 9 deletions android/DartsScorecard/app/src/main/res/drawable/darts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,57 @@
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/dartsLeft_0"
android:id="@+id/dartsLeft_3"
android:drawable="@drawable/ic_darts_3"
android:state_selected="true"
android:state_activated="false"
android:state_pressed="false"/>

<item
android:id="@+id/dartsLeft_3a"
android:drawable="@drawable/ic_darts_3"
android:state_selected="true"
android:state_activated="false"
android:state_pressed="true"/>

<item
android:id="@+id/dartsLeft_2"
android:drawable="@drawable/ic_darts_2"
android:state_selected="false"
android:state_activated="true"
android:state_pressed="false"/>

<item
android:id="@+id/dartsLeft_2a"
android:drawable="@drawable/ic_darts_2"
android:state_selected="false"
android:state_activated="true"
android:state_pressed="true"/>

<item
android:id="@+id/dartsLeft_1a"
android:state_pressed="true"
android:drawable="@drawable/dart_throw" />
android:state_selected="false"
android:state_activated="false"
android:drawable="@drawable/ic_darts_1" />

<item
android:id="@+id/dartsLeft_1"
android:drawable="@drawable/ic_darts" />
android:drawable="@drawable/ic_darts_1" />

<transition
android:fromId="@id/dartsLeft_1"
android:toId="@id/dartsLeft_0"
android:drawable="@drawable/dart_throw" />
android:fromId="@id/dartsLeft_3"
android:toId="@id/dartsLeft_3a"
android:drawable="@drawable/dart_throw_first" />

<transition
android:fromId="@id/dartsLeft_0"
android:toId="@id/dartsLeft_1"
android:drawable="@drawable/dart_fade" />
android:fromId="@id/dartsLeft_2"
android:toId="@id/dartsLeft_2a"
android:drawable="@drawable/dart_throw_second" />

<transition
android:fromId="@id/dartsLeft_1"
android:toId="@id/dartsLeft_1a"
android:drawable="@drawable/dart_throw_third" />

</animated-selector>
21 changes: 21 additions & 0 deletions android/DartsScorecard/app/src/main/res/drawable/ic_darts_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="134dp"
android:height="134dp"
android:viewportHeight="134.0"
android:viewportWidth="134.0">

<group
android:name="all"
android:pivotX="72"
android:pivotY="72"
android:rotation="60">
<group android:name="dart3">
<path
android:name="path3"
android:fillColor="?attr/scoreText"
android:pathData="M96.12,69.16L38.86,71.75L37.39,73.04L22.81,73.04L18.69,68.81L3.89,68.81L0.28,67.39L3.89,66.04L18.69,66.04L22.81,61.81L37.39,61.81L38.86,63.1L95.66,65.67C96.97,64.29 99.3,61.82 103.44,57.39C109.43,50.98 124.61,45.25 131.21,56.01C132.98,58.9 132.04,62.61 128.39,67.15L133.83,67.39L133.83,67.45L128.77,67.68C132.1,72 132.92,75.55 131.21,78.33C124.61,89.09 109.43,83.36 103.44,76.95C99.75,73 97.49,70.61 96.12,69.16Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</group>
</group>
</vector>
34 changes: 34 additions & 0 deletions android/DartsScorecard/app/src/main/res/drawable/ic_darts_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="134dp"
android:height="134dp"
android:viewportHeight="134.0"
android:viewportWidth="134.0">

<group
android:name="all"
android:pivotX="72"
android:pivotY="72"
android:rotation="60">
<group android:name="dart2">
<path
android:name="path2"
android:fillColor="?attr/scoreText"
android:pathData="M96.12,69.16L38.86,71.75L37.39,73.04L22.81,73.04L18.69,68.81L3.89,68.81L0.28,67.39L3.89,66.04L18.69,66.04L22.81,61.81L37.39,61.81L38.86,63.1L95.66,65.67C96.97,64.29 99.3,61.82 103.44,57.39C109.43,50.98 124.61,45.25 131.21,56.01C132.98,58.9 132.04,62.61 128.39,67.15L133.83,67.39L133.83,67.45L128.77,67.68C132.1,72 132.92,75.55 131.21,78.33C124.61,89.09 109.43,83.36 103.44,76.95C99.75,73 97.49,70.61 96.12,69.16Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</group>
<group
android:name="dart3"
android:rotation="20"
android:translateX="24"
android:translateY="8">
<path
android:name="path3"
android:fillColor="?attr/scoreText"
android:fillAlpha="0.4"
android:pathData="M96.12,69.16L38.86,71.75L37.39,73.04L22.81,73.04L18.69,68.81L3.89,68.81L0.28,67.39L3.89,66.04L18.69,66.04L22.81,61.81L37.39,61.81L38.86,63.1L95.66,65.67C96.97,64.29 99.3,61.82 103.44,57.39C109.43,50.98 124.61,45.25 131.21,56.01C132.98,58.9 132.04,62.61 128.39,67.15L133.83,67.39L133.83,67.45L128.77,67.68C132.1,72 132.92,75.55 131.21,78.33C124.61,89.09 109.43,83.36 103.44,76.95C99.75,73 97.49,70.61 96.12,69.16Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</group>
</group>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

<group
android:name="all"
android:translateY="26">
android:pivotX="72"
android:pivotY="72"
android:rotation="60">
<group android:name="dart1">
<path
android:name="path1"
Expand All @@ -16,23 +18,25 @@
android:strokeWidth="1" />
</group>
<group android:name="dart2"
android:pivotX="0"
android:pivotY="72"
android:rotation="-20">
android:translateY="8"
android:translateX="24"
android:rotation="20">
<path
android:name="path1"
android:name="path2"
android:fillColor="?attr/scoreText"
android:fillAlpha="0.4"
android:pathData="M96.12,69.16L38.86,71.75L37.39,73.04L22.81,73.04L18.69,68.81L3.89,68.81L0.28,67.39L3.89,66.04L18.69,66.04L22.81,61.81L37.39,61.81L38.86,63.1L95.66,65.67C96.97,64.29 99.3,61.82 103.44,57.39C109.43,50.98 124.61,45.25 131.21,56.01C132.98,58.9 132.04,62.61 128.39,67.15L133.83,67.39L133.83,67.45L128.77,67.68C132.1,72 132.92,75.55 131.21,78.33C124.61,89.09 109.43,83.36 103.44,76.95C99.75,73 97.49,70.61 96.12,69.16Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</group>
<group android:name="dart3"
android:pivotX="0"
android:pivotY="72"
android:rotation="-40">
android:translateY="24"
android:translateX="48"
android:rotation="40">
<path
android:name="path1"
android:name="path3"
android:fillColor="?attr/scoreText"
android:fillAlpha="0.4"
android:pathData="M96.12,69.16L38.86,71.75L37.39,73.04L22.81,73.04L18.69,68.81L3.89,68.81L0.28,67.39L3.89,66.04L18.69,66.04L22.81,61.81L37.39,61.81L38.86,63.1L95.66,65.67C96.97,64.29 99.3,61.82 103.44,57.39C109.43,50.98 124.61,45.25 131.21,56.01C132.98,58.9 132.04,62.61 128.39,67.15L133.83,67.39L133.83,67.45L128.77,67.68C132.1,72 132.92,75.55 131.21,78.33C124.61,89.09 109.43,83.36 103.44,76.95C99.75,73 97.49,70.61 96.12,69.16Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
android:onClick="@{() -> viewModel.onSubmitScore(inputScore, listener)}"
android:scaleType="fitXY"
android:src="@{viewModel.toggle ? @drawable/darts : @drawable/dart}"
app:numDarts="@{viewModel.dartsLeft}"
fab:fabSize="normal"
fab:useCompatPadding="true" />

Expand Down
Loading

0 comments on commit f522d98

Please sign in to comment.