Adds ability scores to monster card.

This commit is contained in:
2020-09-01 21:39:36 -07:00
parent 03af5c3aa7
commit c461ca2188
5 changed files with 323 additions and 0 deletions

View File

@@ -432,4 +432,28 @@ public class Monster {
}
}
public String getStrengthDescription() {
return String.format(Locale.US, "%d (%+d)", getStrengthScore(), getStrengthModifier());
}
public String getDexterityDescription() {
return String.format(Locale.US, "%d (%+d)", getDexterityScore(), getDexterityModifier());
}
public String getConstitutionDescription() {
return String.format(Locale.US, "%d (%+d)", getConstitutionScore(), getConstitutionModifier());
}
public String getIntelligenceDescription() {
return String.format(Locale.US, "%d (%+d)", getIntelligenceScore(), getIntelligenceModifier());
}
public String getWisdomDescription() {
return String.format(Locale.US, "%d (%+d)", getWisdomScore(), getWisdomModifier());
}
public String getCharismaDescription() {
return String.format(Locale.US, "%d (%+d)", getCharismaScore(), getCharismaModifier());
}
}

View File

@@ -50,6 +50,13 @@ public class MonsterFragment extends Fragment {
monster.setSwimSpeed("0");
monster.setCustomSpeed(false);
monster.setSpeedDescription("30 ft., swim 30 ft.");
// Ability Scores
monster.setStrengthScore(Integer.parseInt("2"));
monster.setDexterityScore(Integer.parseInt("20"));
monster.setConstitutionScore(Integer.parseInt("8"));
monster.setIntelligenceScore(Integer.parseInt("10"));
monster.setWisdomScore(Integer.parseInt("14"));
monster.setCharismaScore(Integer.parseInt("15"));
// END remove block
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
@@ -96,6 +103,54 @@ public class MonsterFragment extends Fragment {
}
});
final TextView monsterStrength = root.findViewById(R.id.strength);
monsterViewModel.getStrength().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String strength) {
monsterStrength.setText(strength);
}
});
final TextView monsterDexterity = root.findViewById(R.id.dexterity);
monsterViewModel.getDexterity().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String dexterity) {
monsterDexterity.setText(dexterity);
}
});
final TextView monsterConstitution = root.findViewById(R.id.constitution);
monsterViewModel.getConstitution().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String constitution) {
monsterConstitution.setText(constitution);
}
});
final TextView monsterIntelligence = root.findViewById(R.id.intelligence);
monsterViewModel.getIntelligence().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String intelligence) {
monsterIntelligence.setText(intelligence);
}
});
final TextView monsterWisdom = root.findViewById(R.id.wisdom);
monsterViewModel.getWisdom().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String wisdom) {
monsterWisdom.setText(wisdom);
}
});
final TextView monsterCharisma = root.findViewById(R.id.charisma);
monsterViewModel.getCharisma().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(String charisma) {
monsterCharisma.setText(charisma);
}
});
return root;
}
}

View File

@@ -20,6 +20,18 @@ public class MonsterViewModel extends ViewModel {
mHitPoints.setValue("");
mSpeed = new MutableLiveData<>();
mSpeed.setValue("");
mStrength = new MutableLiveData<>();
mStrength.setValue("");
mDexterity = new MutableLiveData<>();
mDexterity.setValue("");
mConstitution = new MutableLiveData<>();
mConstitution.setValue("");
mIntelligence = new MutableLiveData<>();
mIntelligence.setValue("");
mWisdom = new MutableLiveData<>();
mWisdom.setValue("");
mCharisma = new MutableLiveData<>();
mCharisma.setValue("");
}
private MutableLiveData<String> mName;
@@ -42,6 +54,30 @@ public class MonsterViewModel extends ViewModel {
public LiveData<String> getSpeed() {
return mSpeed;
}
private MutableLiveData<String> mStrength;
public LiveData<String> getStrength() {
return mStrength;
}
private MutableLiveData<String> mDexterity;
public LiveData<String> getDexterity() {
return mDexterity;
}
private MutableLiveData<String> mConstitution;
public LiveData<String> getConstitution() {
return mConstitution;
}
private MutableLiveData<String> mIntelligence;
public LiveData<String> getIntelligence() {
return mIntelligence;
}
private MutableLiveData<String> mWisdom;
public LiveData<String> getWisdom() {
return mWisdom;
}
private MutableLiveData<String> mCharisma;
public LiveData<String> getCharisma() {
return mCharisma;
}
private Monster mMonster;
public void setMonster(Monster monster) {
@@ -51,5 +87,11 @@ public class MonsterViewModel extends ViewModel {
mArmorClass.setValue(mMonster.getArmorClass());
mHitPoints.setValue(mMonster.getHitPoints());
mSpeed.setValue(mMonster.getSpeedText());
mStrength.setValue(monster.getStrengthDescription());
mDexterity.setValue(monster.getDexterityDescription());
mConstitution.setValue(monster.getConstitutionDescription());
mIntelligence.setValue(monster.getIntelligenceDescription());
mWisdom.setValue(monster.getWisdomDescription());
mCharisma.setValue(monster.getCharismaDescription());
}
}

View File

@@ -95,5 +95,201 @@
app:layout_constraintTop_toBottomOf="@+id/hit_points"
tools:text="10 ft., fly 30 ft." />
<ImageView
android:id="@+id/divider2"
android:layout_width="0dp"
android:layout_height="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/section_divider"
android:scaleType="fitXY"
android:src="@drawable/ic_section_divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/speed" />
<!-- Strength -->
<TextView
android:id="@+id/label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/label_dex"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/strength_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/strength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_str"
app:layout_constraintEnd_toEndOf="@+id/label_str"
app:layout_constraintTop_toBottomOf="@+id/label_str"
android:textAlignment="center"
tools:text="2 (-4)" />
<!-- Dexterity -->
<TextView
android:id="@+id/label_dex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toEndOf="@+id/label_str"
app:layout_constraintEnd_toStartOf="@+id/label_con"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/dexterity_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/dexterity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_dex"
app:layout_constraintEnd_toEndOf="@+id/label_dex"
app:layout_constraintTop_toBottomOf="@+id/label_dex"
android:textAlignment="center"
tools:text="20 (+5)" />
<!-- Constitution -->
<TextView
android:id="@+id/label_con"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toEndOf="@+id/label_dex"
app:layout_constraintEnd_toStartOf="@+id/label_int"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/constitution_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/constitution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_con"
app:layout_constraintEnd_toEndOf="@+id/label_con"
app:layout_constraintTop_toBottomOf="@+id/label_con"
tools:text="8 (-1)" />
<!-- Intelligence -->
<TextView
android:id="@+id/label_int"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toEndOf="@+id/label_con"
app:layout_constraintEnd_toStartOf="@+id/label_wis"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/intelligence_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/intelligence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_int"
app:layout_constraintEnd_toEndOf="@+id/label_int"
app:layout_constraintTop_toBottomOf="@+id/label_int"
android:textAlignment="center"
tools:text="10 (+0)" />
<!-- Wisdom -->
<TextView
android:id="@+id/label_wis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toEndOf="@+id/label_int"
app:layout_constraintEnd_toStartOf="@+id/label_cha"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/wisdom_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/wisdom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_wis"
app:layout_constraintEnd_toEndOf="@+id/label_wis"
app:layout_constraintTop_toBottomOf="@+id/label_wis"
android:textAlignment="center"
tools:text="14 (+2)" />
<!-- Charisma -->
<TextView
android:id="@+id/label_cha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toEndOf="@+id/label_wis"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider2"
android:text="@string/charisma_abbreviation"
android:textAlignment="center"
android:textStyle="bold" />
<TextView
android:id="@+id/charisma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/label_cha"
app:layout_constraintEnd_toEndOf="@+id/label_cha"
app:layout_constraintTop_toBottomOf="@+id/label_cha"
android:textAlignment="center"
tools:text="15 (+2)" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@@ -7,4 +7,10 @@
<string name="action_search">Search</string>
<string name="label_search_query">Query</string>
<string name="section_divider">section divider</string>
<string name="strength_abbreviation">STR</string>
<string name="dexterity_abbreviation">DEX</string>
<string name="constitution_abbreviation">CON</string>
<string name="intelligence_abbreviation">INT</string>
<string name="wisdom_abbreviation">WIS</string>
<string name="charisma_abbreviation">CHA</string>
</resources>