Add player image on home screen and color to indicate not enough resource to craft 🎥

SQLite
Lucas Delanier 2 years ago
parent 8c57e59803
commit 114f329337

@ -56,8 +56,8 @@ class CraftFragment : Fragment() {
recyclerViewMaterials = view.findViewById(R.id.RecyclerviewMaterials)
with(recyclerViewMaterials) {
layoutManager = LinearLayoutManager(view.context)
if(recipe.type == "Objects")
adapter = AdapterMaterials(recipe.ingredients, currentPlayer)
adapter = AdapterMaterials(recipe.ingredients, currentPlayer)
}
}

@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
@ -23,6 +24,7 @@ class HomeFragment : Fragment() {
private lateinit var buttonCollect : ConstraintLayout
private lateinit var buttonBoss : ConstraintLayout
private lateinit var buttonForge : ConstraintLayout
private lateinit var playermage : ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -47,6 +49,7 @@ class HomeFragment : Fragment() {
rank = view.findViewById(R.id.rankTextView)
maxXp = view.findViewById(R.id.maxXpTextView)
xp = view.findViewById(R.id.xpTextView)
playermage = view.findViewById(R.id.playerImage)
buttonCollect = view.findViewById(R.id.buttonCollect)
buttonCollect.setOnClickListener{
findNavController().navigate(R.id.action_homeFragment_to_collectFragment, null, NavOptions.Builder().setPopUpTo(R.id.homeFragment, false).build())
@ -66,6 +69,7 @@ class HomeFragment : Fragment() {
maxXp.text = (currentPlayer.level*100).toString()
progressbar.progress = currentPlayer.xp
progressbar.max = currentPlayer.level*100
playermage.setImageResource(currentPlayer.image)
}

@ -11,6 +11,7 @@ class Stub {
val currentPlayer = Player("Winker",0)
val items : MutableList<Item> = mutableListOf()
items.add(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30))
items.add(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30))
currentPlayer.items = items
return currentPlayer

@ -1,45 +1,26 @@
package com.example.shakecraft.model
import com.example.shakecraft.R
class Player(val pseudo: String, var xp: Int = 0) {
var level: Int = 1
val image: Int = R.drawable.player_image
var items: MutableList<Item> = mutableListOf()
var rank: String = "Beginner"
fun changeRank(){
if(this.level<=2){
this.rank = "Beginner"
}
else if(this.level<=5){
this.rank = "Intermediate"
}
else if(this.level<=8){
this.rank = "Proficient"
}
else if(this.level<=11){
this.rank = "Expert"
}
else if(this.level<=14){
this.rank = "Master"
}
else if(this.level<=17){
this.rank = "Professional"
}
else if(this.level<=20){
this.rank = "Champion"
}
else if(this.level<=23){
this.rank = "Beginner"
}
else if(this.level<=26){
this.rank = "Legend"
}
else if(this.level<=29){
this.rank = "Invincible"
}
else if(this.level<=32){
this.rank = "Divine"
this.rank = when(level){
in 1..2 -> "Beginner"
in 3..5 -> "Intermediate"
in 6..8 -> "Proficient"
in 9..11 -> "Expert"
in 12..14 -> "Master"
in 15..17 -> "Professional"
in 18..19 -> "Champion"
in 20..22 -> "Legend"
in 23..25 -> "Invincible"
else -> {"Divine"}
}
}
fun addItem(item: Item) {

@ -1,5 +1,6 @@
package com.example.shakecraft.view.adapter
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -34,9 +35,13 @@ class AdapterMaterials(private val materials: List<Item>, val currentplayer: Pla
textView.text = item.type.name
val itemSearch = currentplayer.items.find { it.type.name == item.type.name }
textViewNumberNeeded.text = item.stack.toString()
textViewNumberPlayer.text = if (itemSearch != null) itemSearch.stack.toString() else "0"
textViewNumberPlayer.text = itemSearch?.stack?.toString() ?: "0"
imageView.setImageResource(item.type.image)
if (itemSearch != null) {
if(item.stack > itemSearch.stack) textViewNumberPlayer.setTextColor(Color.RED) else textViewNumberPlayer.setTextColor(Color.WHITE)
}
else textViewNumberPlayer.setTextColor(Color.RED)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

@ -43,12 +43,25 @@
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:contentDescription="Landscape"
android:id="@+id/imageView2"
android:layout_width="60dp"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/background" />
android:layout_marginVertical="10dp">
<ImageView
android:id="@+id/imageView2"
android:layout_gravity="bottom"
android:layout_width="60dp"
android:layout_height="95dp"
android:contentDescription="@string/landscape"
android:src="@drawable/background" />
<ImageView
android:id="@+id/playerImage"
android:layout_gravity="bottom"
android:layout_width="50dp"
android:layout_height="80dp"
android:contentDescription="Landscape" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"

Loading…
Cancel
Save