parent
5cd26ecbac
commit
aa6e3afcb0
@ -0,0 +1,88 @@
|
||||
package com.example.shakecraft
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.shakecraft.model.Player
|
||||
import com.example.shakecraft.model.Recipe
|
||||
import com.example.shakecraft.model.RecipeManager
|
||||
import com.example.shakecraft.view.adapter.AdapterMaterials
|
||||
|
||||
|
||||
|
||||
class CraftFragment : Fragment() {
|
||||
private lateinit var buttonBack: TextView
|
||||
private lateinit var recyclerViewMaterials: RecyclerView
|
||||
private lateinit var recipe: Recipe
|
||||
private lateinit var image: ImageView
|
||||
private lateinit var name: TextView
|
||||
private lateinit var buttonForge: Button
|
||||
private lateinit var numberCraftable: TextView
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
|
||||
|
||||
val currentPlayer = (activity as MainActivity).currentPlayer
|
||||
val view = inflater.inflate(R.layout.fragment_craft, container, false)
|
||||
recipe = arguments?.getParcelable("recipe")!!
|
||||
|
||||
initializeViews(view, currentPlayer)
|
||||
setUpRecyclerView(view,currentPlayer)
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
}
|
||||
|
||||
private fun setUpRecyclerView(view: View, currentPlayer: Player) {
|
||||
recyclerViewMaterials = view.findViewById(R.id.RecyclerviewMaterials)
|
||||
with(recyclerViewMaterials) {
|
||||
layoutManager = LinearLayoutManager(view.context)
|
||||
if(recipe.type == "Objects")
|
||||
adapter = AdapterMaterials(recipe.ingredients, currentPlayer)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun initializeViews(view: View, currentPlayer: Player) {
|
||||
buttonBack = view.findViewById(R.id.backbutton)
|
||||
buttonForge = view.findViewById(R.id.buttonForge)
|
||||
numberCraftable = view.findViewById(R.id.craftableNumber)
|
||||
|
||||
buttonBack.setOnClickListener{
|
||||
findNavController().navigate(R.id.action_craftFragment_to_forgeFragment)
|
||||
}
|
||||
image = view.findViewById(R.id.item_image)
|
||||
name = view.findViewById(R.id.item_name)
|
||||
image.setImageResource(recipe.item.image)
|
||||
name.text = recipe.item.name
|
||||
buttonForge.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer)
|
||||
numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer).toString()
|
||||
|
||||
buttonForge.setOnClickListener{
|
||||
currentPlayer.craft(recipe)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,46 @@
|
||||
package com.example.shakecraft.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
data class Item(
|
||||
|
||||
class Item(
|
||||
var name: String,
|
||||
var rarity: Int = 1,
|
||||
var stack: Int = 1,
|
||||
var image: Int,
|
||||
var xpReward: Int = 0,
|
||||
)
|
||||
) : Parcelable{
|
||||
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(name)
|
||||
parcel.writeInt(rarity)
|
||||
parcel.writeInt(stack)
|
||||
parcel.writeInt(image)
|
||||
parcel.writeInt(xpReward)
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Item> {
|
||||
override fun createFromParcel(parcel: Parcel): Item {
|
||||
return Item(
|
||||
parcel.readString()!!,
|
||||
parcel.readInt(),
|
||||
parcel.readInt(),
|
||||
parcel.readInt(),
|
||||
parcel.readInt()
|
||||
)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Item?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,29 @@
|
||||
package com.example.shakecraft.model
|
||||
|
||||
class Recipe(val item: Item, val ingredients : List<Item>, val type: String) {
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
class Recipe(val item: Item, val ingredients : List<Item>, val type: String) : Parcelable {
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(item, flags)
|
||||
parcel.writeTypedList(ingredients)
|
||||
parcel.writeString(type)
|
||||
}
|
||||
companion object CREATOR : Parcelable.Creator<Recipe> {
|
||||
override fun createFromParcel(parcel: Parcel): Recipe {
|
||||
return Recipe(
|
||||
parcel.readParcelable(Item::class.java.classLoader)!!,
|
||||
parcel.createTypedArrayList(Item.CREATOR)!!,
|
||||
parcel.readString()!!
|
||||
)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Recipe?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.example.shakecraft.view.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.Adapter
|
||||
import com.example.shakecraft.R
|
||||
import com.example.shakecraft.model.Item
|
||||
import com.example.shakecraft.model.Player
|
||||
import com.example.shakecraft.view.viewholder.ViewHolderInventory
|
||||
|
||||
|
||||
class AdapterMaterials(private val materials: List<Item>, val currentplayer: Player) : RecyclerView.Adapter<AdapterMaterials.ViewHolder>() {
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val textView: TextView
|
||||
val textViewNumberNeeded: TextView
|
||||
val textViewNumberPlayer: TextView
|
||||
var imageView: ImageView
|
||||
|
||||
|
||||
|
||||
init {
|
||||
// Define click listener for the ViewHolder's View
|
||||
|
||||
textView = view.findViewById(R.id.item_name)
|
||||
textViewNumberPlayer = view.findViewById(R.id.numberCurrentPlayer)
|
||||
textViewNumberNeeded = view.findViewById(R.id.numberNeeded)
|
||||
imageView = view.findViewById(R.id.item_image)
|
||||
}
|
||||
fun bind(item: Item, currentplayer: Player) {
|
||||
textView.text = item.name
|
||||
val itemSearch = currentplayer.items.find { it.name == item.name }
|
||||
textViewNumberNeeded.text = item.stack.toString()
|
||||
textViewNumberPlayer.text = if (itemSearch != null) itemSearch.stack.toString() else "0"
|
||||
|
||||
imageView.setImageResource(item.image)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = materials.size
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.list_craft, parent, false)
|
||||
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
val item : Item = materials[position]
|
||||
viewHolder.bind(item, currentplayer)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!--When the button is not enabled-->
|
||||
<item android:state_enabled="false" android:color="@color/grey" />
|
||||
<!--When button is enabled-->
|
||||
<item android:state_enabled="true" android:color="@color/blue" />
|
||||
<!--Default Text Color-->
|
||||
<item android:color="#db402c" />
|
||||
|
||||
</selector>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/grey_100" />
|
||||
</shape>
|
||||
|
||||
</item>
|
||||
<item android:top="1dp" android:bottom="1dp" >
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/black_800" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
|
||||
|
||||
</layer-list>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/blue" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/black_800"
|
||||
android:scaleType="center"
|
||||
tools:context=".CollectFragment">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/frameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingTop="50dp"
|
||||
android:paddingBottom="20dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/backbutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left|center_vertical"
|
||||
android:focusable="true"
|
||||
android:drawableStart="@drawable/back"
|
||||
android:drawableTint="@color/blue"
|
||||
android:text="Ancient Forge"
|
||||
android:textColor="@color/blue"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="Recipe"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@drawable/recipelistcard"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/frameLayout">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="15dp"
|
||||
android:gravity="start"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/item_image"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/item_recipe_background"
|
||||
android:contentDescription="image of item"
|
||||
app:srcCompat="@drawable/wooden_stick" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
tools:text="Wooden Stick" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
|
||||
android:background="@drawable/recipelistcard"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="15dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/linearLayout">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:text="Materials"
|
||||
android:textColor="@color/grey_400"
|
||||
android:textSize="17dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/RecyclerviewMaterials"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/list_craft" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonForge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="Forge"
|
||||
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"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toTopOf="@+id/buttonForge"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:background="@drawable/craftable_background"
|
||||
android:paddingVertical="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Craftable "
|
||||
android:textColor="@color/grey_400"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/craftableNumber"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="804"
|
||||
android:textColor="@color/white"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:contentDescription="image of item"
|
||||
android:background="@drawable/item_background"
|
||||
android:id="@+id/item_image"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
app:srcCompat="@drawable/log2" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_name"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
tools:text="Beech Log"/>
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/numberCurrentPlayer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
tools:text="804"/>
|
||||
<TextView
|
||||
android:id="@+id/item_stock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/grey_300"
|
||||
android:text="/"/>
|
||||
<TextView
|
||||
android:id="@+id/numberNeeded"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/grey_300"
|
||||
tools:text="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue