|
|
|
@ -1,14 +1,11 @@
|
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.Image
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
|
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.*
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
@ -16,13 +13,20 @@ import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.geometry.Offset
|
|
|
|
|
import androidx.compose.ui.graphics.Brush
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
|
|
import androidx.compose.ui.text.TextStyle
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
|
import com.example.what_the_fantasy.data.local.QuestionStub
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun QuizPage(navController: NavController) {
|
|
|
|
|
fun QuizPage(
|
|
|
|
|
navControllerQuizEnd: (Int, Int) -> Unit,
|
|
|
|
|
navControllerQuizMenu: () -> Unit
|
|
|
|
|
) {
|
|
|
|
|
val questions = QuestionStub.allQuestions
|
|
|
|
|
var idCurrentQuestion by remember { mutableIntStateOf(0) }
|
|
|
|
|
var pts by remember { mutableIntStateOf(0) }
|
|
|
|
@ -44,59 +48,126 @@ fun QuizPage(navController: NavController) {
|
|
|
|
|
|
|
|
|
|
if (answer == correctAnswer) pts++
|
|
|
|
|
if (idCurrentQuestion < questions.size - 1) idCurrentQuestion++
|
|
|
|
|
else navController.popBackStack() // Retour menu
|
|
|
|
|
else navControllerQuizEnd(0, pts) // Retour menu
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
Column (
|
|
|
|
|
modifier = Modifier.fillMaxSize().background(Color(0xFF100C1B))
|
|
|
|
|
) {
|
|
|
|
|
// Bandeau supérieur
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.background(Color(0xFF100C1B))
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.weight(0.1f)
|
|
|
|
|
//.background(Color(0xFF300052))
|
|
|
|
|
.padding(20.dp),
|
|
|
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
|
|
) {
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.profile_icon),
|
|
|
|
|
contentDescription = "Profil"
|
|
|
|
|
)
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.toggle),
|
|
|
|
|
contentDescription = "Profil"
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Contenu princiapl
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize(),
|
|
|
|
|
.weight(0.8f)
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(horizontal = 50.dp, vertical = 20.dp),
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
val question = questions[idCurrentQuestion]
|
|
|
|
|
|
|
|
|
|
Column (
|
|
|
|
|
Column(
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
) {
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = { navController.popBackStack() },
|
|
|
|
|
modifier = Modifier.align(Alignment.TopStart)
|
|
|
|
|
) {
|
|
|
|
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Retour", tint = Color.White)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Text("Question ${question.id}", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 20.dp))
|
|
|
|
|
Text("Points : $pts", color = Color.White, fontSize = 18.sp, modifier = Modifier.padding(top = 40.dp))
|
|
|
|
|
Text(question.question, color = Color.White, fontSize = 22.sp, modifier = Modifier.padding(40.dp))
|
|
|
|
|
}
|
|
|
|
|
Text(
|
|
|
|
|
text = "▶ Quiz ◀",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
style = TextStyle(fontSize = 25.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)
|
|
|
|
|
)
|
|
|
|
|
Column (
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.background(brush = gradient, shape = RoundedCornerShape(20.dp)),
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
"Question ${question.id}",
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontSize = 18.sp,
|
|
|
|
|
modifier = Modifier.padding(top = 20.dp),
|
|
|
|
|
style = TextStyle(
|
|
|
|
|
fontSize = 25.sp,
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
textAlign = TextAlign.Center
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
Text(
|
|
|
|
|
question.question,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontSize = 22.sp,
|
|
|
|
|
modifier = Modifier.padding(40.dp)
|
|
|
|
|
)
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.padding(top = 30.dp)
|
|
|
|
|
) {
|
|
|
|
|
listOf(question.ansA, question.ansB, question.ansC, question.ansD).forEach { answer ->
|
|
|
|
|
listOf(
|
|
|
|
|
question.ansA,
|
|
|
|
|
question.ansB,
|
|
|
|
|
question.ansC,
|
|
|
|
|
question.ansD
|
|
|
|
|
).forEach { answer ->
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.width(220.dp)
|
|
|
|
|
.height(50.dp)
|
|
|
|
|
.background(brush = gradient, shape = RoundedCornerShape(16.dp))
|
|
|
|
|
.background(Color.White, shape = RoundedCornerShape(16.dp))
|
|
|
|
|
.clickable { onAnswerSelected(answer) }
|
|
|
|
|
.padding(horizontal = 8.dp),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
Text(answer, color = Color.White, fontSize = 18.sp)
|
|
|
|
|
Text(answer, color = Color.Black, fontSize = 18.sp)
|
|
|
|
|
}
|
|
|
|
|
Spacer(modifier = Modifier.height(60.dp))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bandeau inférieur
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.weight(0.1f)
|
|
|
|
|
.background(Color(0xFF300052))
|
|
|
|
|
.padding(20.dp),
|
|
|
|
|
horizontalArrangement = Arrangement.SpaceAround,
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
|
|
) {
|
|
|
|
|
// Bouton Likes
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.like_icon),
|
|
|
|
|
contentDescription = "Bouton"
|
|
|
|
|
)
|
|
|
|
|
// Bouton WhatTheFantasy
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(R.drawable.wf_logo),
|
|
|
|
|
contentDescription = "Menu Button",
|
|
|
|
|
Modifier.clickable { navControllerQuizMenu() }
|
|
|
|
|
)
|
|
|
|
|
// Bouton Quiz
|
|
|
|
|
Image(
|
|
|
|
|
painter = painterResource(id = R.drawable.quiz_icon),
|
|
|
|
|
contentDescription = "Bouton"
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|