add max craft button 🎉
continuous-integration/drone/push Build is passing Details

viewmodel
Lucas Delanier 2 years ago
parent 640950bc50
commit 218e85d571

@ -26,6 +26,7 @@ class CraftFragment : Fragment() {
private lateinit var image: ImageView
private lateinit var name: TextView
private lateinit var buttonForge: Button
private lateinit var buttonForgeMax: Button
private lateinit var numberCraftable: TextView
val viewModel : MainViewModel by activityViewModels<MainViewModel>()
@ -66,6 +67,7 @@ class CraftFragment : Fragment() {
private fun initializeViews(view: View, currentPlayer: Player) {
buttonBack = view.findViewById(R.id.backbutton)
buttonForge = view.findViewById(R.id.buttonForge)
buttonForgeMax = view.findViewById(R.id.buttonForgeMax)
numberCraftable = view.findViewById(R.id.craftableNumber)
buttonBack.setOnClickListener{
@ -76,6 +78,8 @@ class CraftFragment : Fragment() {
image.setImageResource(recipe.item.type.image)
name.text = recipe.item.type.name
buttonForge.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer)
buttonForgeMax.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer)
buttonForgeMax.text = "CRAFT MAX (${RecipeManager.HowManyCraftable(recipe, currentPlayer)})"
numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer).toString()
buttonForge.setOnClickListener{
@ -83,6 +87,11 @@ class CraftFragment : Fragment() {
initializeViews(view, currentPlayer)
setUpRecyclerView(view, currentPlayer)
}
buttonForgeMax.setOnClickListener{
currentPlayer.craft(recipe, RecipeManager.HowManyCraftable(recipe, currentPlayer))
initializeViews(view, currentPlayer)
setUpRecyclerView(view, currentPlayer)
}
}

@ -66,8 +66,9 @@ class Player(var pseudo: String, var xp: Int = 0) {
return false
}
fun craft(recipe: Recipe) : Boolean{
fun craft(recipe: Recipe, count: Int = 1) : Boolean{
println("test")
for (i in 1..count) {
for (ingredient in recipe.ingredients) {
val searchedItem = items.find { it.type.name == ingredient.type.name }
if (searchedItem != null) {
@ -79,6 +80,7 @@ class Player(var pseudo: String, var xp: Int = 0) {
}
println("item:" + recipe.item.stack)
addItem(recipe.item)
}
return true
}

@ -79,7 +79,6 @@ class RecipeManager {
return 0
else{
for(element in recipe.ingredients){
println("cc")
val itemSearch = player.items.find { it.type.name == element.type.name }
if(itemSearch!= null)
divisedList.add(itemSearch.stack / element.stack)

@ -24,7 +24,7 @@
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_gravity="start|center_vertical"
android:focusable="true"
android:drawableStart="@drawable/back"
android:drawableTint="@color/blue"
@ -130,19 +130,34 @@
</LinearLayout>
<Button
android:id="@+id/buttonForgeMax"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="5dp"
android:backgroundTint="@color/button_background_color"
android:text="Forge MAX"
android:textColor="@color/grey"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonForge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/buttonForge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/button_background_color"
android:text="Forge"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:backgroundTint="@color/button_background_color"
android:textColor="@color/white"/>
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:layout_width="match_parent"
@ -150,7 +165,7 @@
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/buttonForge"
app:layout_constraintBottom_toTopOf="@+id/buttonForgeMax"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@drawable/craftable_background"

Loading…
Cancel
Save