|
|
@ -10,16 +10,27 @@ import androidx.activity.OnBackPressedCallback
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
|
|
|
|
|
import androidx.compose.material3.AlertDialog
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
|
|
|
|
import androidx.compose.material3.Divider
|
|
|
|
|
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
|
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
|
|
|
import androidx.compose.material3.TopAppBar
|
|
|
|
|
|
|
|
import androidx.compose.material3.TopAppBarDefaults
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.DisposableEffect
|
|
|
|
import androidx.compose.runtime.DisposableEffect
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
@ -33,6 +44,7 @@ import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
|
|
|
import com.example.mathseduc.controllers.ControllerChapter
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
import com.example.mathseduc.controllers.ControllerLobby
|
|
|
|
import com.example.mathseduc.controllers.ControllerPlayer
|
|
|
|
import com.example.mathseduc.controllers.ControllerPlayer
|
|
|
|
import com.example.mathseduc.controllers.ControllerUtiliser
|
|
|
|
import com.example.mathseduc.controllers.ControllerUtiliser
|
|
|
@ -81,17 +93,22 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
finish()
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ServerDetailPage() {
|
|
|
|
fun ServerDetailPage() {
|
|
|
|
val context = LocalContext.current
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
|
|
val serverName = intent.getStringExtra("serverName")
|
|
|
|
val serverName = intent.getStringExtra("serverName")
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId",-1)
|
|
|
|
val lobbyId = intent.getIntExtra("lobbyId",-1)
|
|
|
|
|
|
|
|
val chapterId = intent.getIntExtra("chapterId",-1)
|
|
|
|
|
|
|
|
val nbPlayers = intent.getIntExtra("nbPlayers",-1)
|
|
|
|
|
|
|
|
val lobbyDifficulty = intent.getIntExtra("lobbyDifficulty",-1)
|
|
|
|
|
|
|
|
|
|
|
|
var isCreator by rememberSaveable { mutableStateOf(false) }
|
|
|
|
var isCreator by rememberSaveable { mutableStateOf(false) }
|
|
|
|
var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
|
|
|
|
var playerListInfos: List<Player> by rememberSaveable { mutableStateOf(emptyList()) }
|
|
|
|
var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) }
|
|
|
|
var playerList by rememberSaveable { mutableStateOf(ControllerPlayer.getPlayersIdFromLobbyId(lobbyId.toString()) ?: emptyList()) }
|
|
|
|
var refreshState by rememberSaveable { mutableStateOf(true) }
|
|
|
|
var refreshState by rememberSaveable { mutableStateOf(true) }
|
|
|
|
|
|
|
|
var showDialog by rememberSaveable { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
|
|
DisposableEffect(refreshState) {
|
|
|
|
DisposableEffect(refreshState) {
|
|
|
|
val handler = Handler(Looper.getMainLooper())
|
|
|
|
val handler = Handler(Looper.getMainLooper())
|
|
|
@ -109,6 +126,9 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
val intent = Intent(context, QuizMultiActivity::class.java)
|
|
|
|
val intent = Intent(context, QuizMultiActivity::class.java)
|
|
|
|
intent.putExtra("serverName", serverName)
|
|
|
|
intent.putExtra("serverName", serverName)
|
|
|
|
intent.putExtra("lobbyId", lobbyId)
|
|
|
|
intent.putExtra("lobbyId", lobbyId)
|
|
|
|
|
|
|
|
intent.putExtra("chapterId", chapterId)
|
|
|
|
|
|
|
|
intent.putExtra("nbPlayers", nbPlayers)
|
|
|
|
|
|
|
|
intent.putExtra("lobbyDifficulty", lobbyDifficulty)
|
|
|
|
context.startActivity(intent)
|
|
|
|
context.startActivity(intent)
|
|
|
|
refreshState = false
|
|
|
|
refreshState = false
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,9 +148,29 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TopAppBar(
|
|
|
|
|
|
|
|
colors = TopAppBarDefaults.topAppBarColors(
|
|
|
|
|
|
|
|
containerColor = Color.Transparent,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
title = {},
|
|
|
|
|
|
|
|
navigationIcon = {
|
|
|
|
|
|
|
|
IconButton(
|
|
|
|
|
|
|
|
onClick = { showDialog = true },
|
|
|
|
|
|
|
|
modifier = Modifier.size(60.dp)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Icon(
|
|
|
|
|
|
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
|
|
|
|
|
|
contentDescription = "Retour",
|
|
|
|
|
|
|
|
modifier = Modifier.size(36.dp),
|
|
|
|
|
|
|
|
tint = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
val modifier = Modifier
|
|
|
|
val modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.fillMaxSize()
|
|
|
|
.padding(16.dp)
|
|
|
|
.padding(16.dp)
|
|
|
|
|
|
|
|
|
|
|
|
Column(
|
|
|
|
Column(
|
|
|
|
modifier = modifier,
|
|
|
|
modifier = modifier,
|
|
|
@ -140,12 +180,54 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = serverName!!,
|
|
|
|
text = serverName!!,
|
|
|
|
color = Color.White,
|
|
|
|
color = Color.White,
|
|
|
|
|
|
|
|
fontSize = 30.sp,
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Lobby Settings",
|
|
|
|
|
|
|
|
fontSize = 23.sp,
|
|
|
|
|
|
|
|
color = Color.White,
|
|
|
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Chapter : ${ControllerChapter.getChapterNameById(chapterId).toString()}",
|
|
|
|
|
|
|
|
fontSize = 20.sp,
|
|
|
|
|
|
|
|
color = Color.White
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Players : ${ControllerLobby.getNbPlayerInLobby(lobbyId)}/${nbPlayers}",
|
|
|
|
|
|
|
|
fontSize = 20.sp,
|
|
|
|
|
|
|
|
color = (if(ControllerLobby.getNbPlayerInLobby(lobbyId)==nbPlayers) Color.Red else Color.White)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Difficulty : $lobbyDifficulty",
|
|
|
|
|
|
|
|
fontSize = 20.sp,
|
|
|
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(30.dp))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Player Name",
|
|
|
|
|
|
|
|
fontSize = 20.sp,
|
|
|
|
|
|
|
|
color = Colors.White,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
Divider(
|
|
|
|
|
|
|
|
color = Color.Gray,
|
|
|
|
|
|
|
|
thickness = 2.dp,
|
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
|
|
|
|
|
)
|
|
|
|
LazyColumn(
|
|
|
|
LazyColumn(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.fillMaxSize()
|
|
|
|
.weight(0.75f)
|
|
|
|
.weight(0.75f)
|
|
|
|
|
|
|
|
.padding(top = 2.dp),
|
|
|
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
items(playerListInfos) { player ->
|
|
|
|
items(playerListInfos) { player ->
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
@ -153,6 +235,7 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
fontSize = 18.sp,
|
|
|
|
fontSize = 18.sp,
|
|
|
|
color = Colors.White,
|
|
|
|
color = Colors.White,
|
|
|
|
modifier = Modifier.weight(1f)
|
|
|
|
modifier = Modifier.weight(1f)
|
|
|
|
|
|
|
|
.padding(top = 5.dp)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -167,8 +250,8 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
enabled = isCreator,
|
|
|
|
enabled = isCreator,
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
colors = ButtonDefaults.buttonColors(Colors.Green),
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxWidth()
|
|
|
|
.fillMaxWidth()
|
|
|
|
.height(48.dp)
|
|
|
|
.height(48.dp)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
Text(
|
|
|
|
text = "LAUNCH",
|
|
|
|
text = "LAUNCH",
|
|
|
@ -177,6 +260,40 @@ class ServerDetailsActivity : ComponentActivity() {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showDialog) {
|
|
|
|
|
|
|
|
LeaveLobbyDialog(serverName, onConfirmLeave = {},onCancelLeave = { showDialog = false })
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun LeaveLobbyDialog(namelobby: String, onConfirmLeave: () -> Unit, onCancelLeave: () -> Unit) {
|
|
|
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
|
|
onDismissRequest = onCancelLeave,
|
|
|
|
|
|
|
|
title = { Text("Confirm leaving lobby") },
|
|
|
|
|
|
|
|
confirmButton = {
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = {
|
|
|
|
|
|
|
|
onConfirmLeave()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text("Leave")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
dismissButton = {
|
|
|
|
|
|
|
|
Button(
|
|
|
|
|
|
|
|
onClick = {
|
|
|
|
|
|
|
|
onCancelLeave()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text("Cancel")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
text = {
|
|
|
|
|
|
|
|
Text("Are you sure you want to leave the lobby $namelobby?")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|