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 zcmeAS@N?(olHy`uVBq!ia0y~yV6b6eV2I*iV_;x-5@>45z`)w?>Eakt!T9#z+3vaN zvd15u|GRts^F66*hMm5qqQ|dY%FLX+$Ya(by{`HOr4H}#r3x>+4o>G<%A)GQ9V-&k z!E*4yF<)NMBRVl5lR0yjPit#iG<RdzSqJsYXME0Co<IG!*!aG2tjr2yGv1=}r5n@F z&$F%m_U7j1^z-v#Iq#&L4i}pvJ7c!J;Ev9oGZHg7YaFJn*RcqW*;64|SibD$_4kU$ z<^GslK67?HM-2m5#UFl<ifFyKJv}?Di(VbKcinYYPsqu^ZL#2|xB0cgH|=-xTULIm zOUe7^k}w^t<;{gpQ(4nbw{ovn^q*(d%frU}<dU{NYuSV1<MxkpR<7du`SAPx<~cT% z_D1IQN*kEn(t6IY{No0>O;=oRPurg-UoM|`^fa8={37%BJI`|}|FGY8m8<)~2(sfr zt;9@2qu>qBhaU>OEU~JI*mYMgDecX)iIU33tkxmsoSI!t(TOJOZt5x<yQOiJt+@SG zDKzwBqGYeziC@30cBiHsJK=Nif2ZH_<`#h)Fhx4vd971~ihf*hhY4jQCpSkg%#?aE z_o`{x=@UH@XMQ-ex!)>!)mhUeyZ@UlS=;8Jv)ki#h{w(Ou1PnY&nR6AaaIwNT_Trn z^svw5v9w2Y|IKGUJCwinzV_%~y$p8ro(&(2Hd$s(xcN`WXic<=s{60G9WnCPe2itb zpZK-G?F`eUEu1T7xA43clML5=WD#WE7m={)h#ANuUDxl|iCcdCa(=@8zaMoz9XVg$ zey8-ePEqn51@?5S6SvY@-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S2)1bO<I a{mL^6<_|R2wlXj<FnGH9xvX<aXaWEt^sIOQ 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