From 3c5d8d2a92d70d9c5a9e9b9407173991e81ec6d3 Mon Sep 17 00:00:00 2001 From: izajime <izan.jimenez@estudiantes.uva.es> Date: Thu, 21 Nov 2024 02:30:14 +0100 Subject: [PATCH] Feature: Tienda funcional, falta actualizar las monedas en tiempo real --- .../ellegadodepintia/TiendaActivity.kt | 94 ++++++++++++++++-- .../main/res/drawable/asi_candado_tienda.png | Bin 0 -> 1480 bytes app/src/main/res/layout/activity_tienda.xml | 55 +++++++++- 3 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/asi_candado_tienda.png diff --git a/app/src/main/java/com/example/ellegadodepintia/TiendaActivity.kt b/app/src/main/java/com/example/ellegadodepintia/TiendaActivity.kt index 6db47be..a7251d3 100644 --- a/app/src/main/java/com/example/ellegadodepintia/TiendaActivity.kt +++ b/app/src/main/java/com/example/ellegadodepintia/TiendaActivity.kt @@ -1,8 +1,15 @@ package com.example.ellegadodepintia +import android.graphics.Color import android.os.Bundle +import android.view.ViewGroup import android.widget.ImageView +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import com.example.ellegadodepintia.exploradoresDePintia.ModalDetallesCompra +import com.example.ellegadodepintia.exploradoresDePintia.model.GameState +import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.ObjetoConsumible +import com.example.ellegadodepintia.repositorios.RepositorioJugador import com.example.ellegadodepintia.repositorios.RepositorioObjetos class TiendaActivity : AppCompatActivity() { @@ -10,11 +17,16 @@ class TiendaActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_tienda) - val objetos = RepositorioObjetos.obtenerObjetosAleatoriosTienda(6) + val nivelCiudad = GameState.jugador.nivelCiudad + val nObjetos = nivelCiudad * 2 + val objetos = RepositorioObjetos.obtenerObjetosAleatoriosTienda(nObjetos) + val preciosGenerados = ArrayList<Int>() - //TODO hay que hacer que dependiendo del nivel de la ciudad haga más cosas - val slots = listOf( - findViewById<ImageView>(R.id.slot01), + val textoMonedas = findViewById<TextView>(R.id.textoMonedas) + GameState.jugador.monedas.toString().also { textoMonedas.text = it } + + val slots = listOf<ImageView>( + findViewById(R.id.slot01), findViewById(R.id.slot02), findViewById(R.id.slot03), findViewById(R.id.slot04), @@ -22,8 +34,78 @@ class TiendaActivity : AppCompatActivity() { findViewById(R.id.slot06) ) + val precios = listOf<TextView>( + findViewById(R.id.precio01), + findViewById(R.id.precio02), + findViewById(R.id.precio03), + findViewById(R.id.precio04), + findViewById(R.id.precio05), + findViewById(R.id.precio06) + ) + + val monedas = listOf<ImageView>( + findViewById(R.id.moneda01), + findViewById(R.id.moneda02), + findViewById(R.id.moneda03), + findViewById(R.id.moneda04), + findViewById(R.id.moneda05), + findViewById(R.id.moneda06) + ) + + precios.forEachIndexed { index, precio -> + if (index < nObjetos) { + val resultado = (30..75).random() / nivelCiudad + preciosGenerados.add(resultado) + resultado.toString().also { precio.text = it } + } else { + val nivelTaberna = index / 2 + 1 + "Taberna lvl $nivelTaberna".also { precio.text = it } + precio.textSize = 11f + precio.setTextColor(Color.RED) + + } + } + slots.forEachIndexed { index, slot -> - slot.setImageResource(objetos[index].imagen) + if (index < nObjetos) { + slot.setImageResource(objetos[index].imagen) + slot.setOnClickListener { + val modalDetallesFragment = ModalDetallesCompra().apply { + objeto = objetos[index] + coste = preciosGenerados[index] + } + + modalDetallesFragment.onDismissListener = { accionRealizada -> + if (accionRealizada) { + ejecutarCompra(objetos[index], preciosGenerados[index]) + } + } + + modalDetallesFragment.show(supportFragmentManager, "modalDetalles") + } + } else { + slot.setImageResource(R.drawable.asi_candado_tienda) + slot.scaleType = ImageView.ScaleType.CENTER + } + } + + monedas.forEachIndexed { index, moneda -> + if (index >= nObjetos) { + val parent = moneda.parent as? ViewGroup + parent?.removeView(moneda) + } + } + } + + private fun ejecutarCompra(objeto: ObjetoConsumible, coste: Int){ + val texto = findViewById<TextView>(R.id.textoInformacion) + if (GameState.jugador.monedas < coste){ + "No hay dinero".also { texto.text = it } + }else{ + GameState.jugador.actualizarMonedas(GameState.jugador.monedas - coste) + RepositorioJugador.setMonedas(GameState.jugador.monedas) + GameState.jugador.conseguirObjeto(objeto) + "Objeto comprado y añadido al inventario".also { texto.text = it } } } -} \ No newline at end of file +} diff --git a/app/src/main/res/drawable/asi_candado_tienda.png b/app/src/main/res/drawable/asi_candado_tienda.png new file mode 100644 index 0000000000000000000000000000000000000000..54e9192f897fe5e2285dba96950d0a9b878cca18 GIT binary patch literal 1480 zcmYLJeKga1824VoE+e84zj?`Fx;Dnp@iOM8Mwb+!ybVz}8=6kuZkT!BuR^ZIxmv<4 zNs>%l<zzSWl3m<s^0v~vbW2JY-OV}9{p0&`zUT9Np3n1qpXbT{#m5t_d_Y-7Mh5N$ zy8B5^C&>!ht0dWlzP7e9GK!^M?yml+vdcXKh0GZJzL}vdcFlZel&N*Tx2;y+*hp;b z^;+<^TC0N0EP#GI;Ev&kV?7nhcN9!Om9zUo=n6g4FTLSfy_O;V*J1H@%W1S)=EKti zE@nI~aS%7uzm<fU!kpEs$6(=<p_GR)L)AyGd|To_l3dQh1f>1|?OXactDF(-`9)lv zN?4jp`2$P)lOdg{x@2k{fBavgJ_E50k2_GaH%(>-Ay$(jg00SV7PUK47W$k$Iwq|& z+*}B^5i84y>6(0Jwi@p8N(L!m+dZse$7E@ErA#rVKUd{}(TQq@VpS!1;fTc%#Y@vk zea>?i8yc0@XV$v2Z#i9dM%!fq&GLlkBCf)=ic}kFzf~tqEL`PrX5R(K+r5@w6U<+{ zEZ#HaVUY1%R_bFqU8m9-eX<$<Vn$t*?2r~HkrNTUR1WDPF^Z1<b};jTtHI$mO?(s* zLx@(sRR3lfICbiCxNb3lv$5g8jv~F}5PN>)``pdWQU7NbWO+Ox_l5@L`>^Nk)A`8A z?BL&H4+xo~wwL-jMNs9Z=Z{Jqf*S{HS?nKJ)_odi$p+u}gZvtg2tJ+*jQHb?we?vB ziRhUUo4JEva4G*iu^sufcoC#4@^(abHh)65;NlqkZ4LCjU}F={4JJM0&=?V;_k^?2 z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g6#>>OUy~!=? F>VG2itatzb literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_tienda.xml b/app/src/main/res/layout/activity_tienda.xml index 72bf1c1..0de1d78 100644 --- a/app/src/main/res/layout/activity_tienda.xml +++ b/app/src/main/res/layout/activity_tienda.xml @@ -26,6 +26,37 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + <LinearLayout + android:id="@+id/layoutMonedas" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:padding="5dp" + android:background="@drawable/style_texto_border" + android:gravity="center" + android:layout_marginBottom="8dp" + app:layout_constraintTop_toBottomOf="@id/tituloJuego" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"> + + <TextView + android:id="@+id/textoMonedas" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:fontFamily="@font/pixeled" + android:text="100" + android:textColor="#401201" + android:textSize="20sp" /> + + <ImageView + android:layout_width="20dp" + android:layout_height="20dp" + android:layout_marginStart="4dp" + android:contentDescription="Icono de moneda" + android:src="@drawable/logo_pintia" + android:scaleType="centerCrop" /> + </LinearLayout> + <GridLayout android:id="@+id/inventarioGrid" android:layout_width="wrap_content" @@ -39,7 +70,7 @@ android:rowCount="3" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tituloJuego"> + app:layout_constraintTop_toBottomOf="@id/layoutMonedas"> <LinearLayout android:orientation="vertical" @@ -86,6 +117,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda01" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -142,6 +174,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda02" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -200,6 +233,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda03" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -256,6 +290,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda04" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -312,6 +347,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda05" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -368,6 +404,7 @@ android:textSize="20sp" /> <ImageView + android:id="@+id/moneda06" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginStart="4dp" @@ -380,6 +417,22 @@ </GridLayout> + <TextView + android:id="@+id/textoInformacion" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Aquà aparecera la información relevante de las compras" + android:textSize="15sp" + android:fontFamily="@font/pixeled" + android:padding="6sp" + android:textColor="#401201" + android:background="@drawable/style_texto_border" + android:layout_marginTop="10dp" + app:layout_constraintTop_toBottomOf="@id/inventarioGrid" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:gravity="center"/> + <LinearLayout android:id="@+id/bottom_navigation" style="?android:attr/buttonBarStyle" -- GitLab