using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
///
/// Class to handle panel with multiple choice options
///
public class PanelMultipleChoice : MonoBehaviour
{
///
/// Reference to the webcam screen
///
public RawImage webcamScreen;
///
/// Video 'play' sprite
///
public Sprite playSprite;
///
/// Video 'pause' sprite
///
public Sprite pauseSprite;
///
/// Reference to its course controller to be able to go to call NextSignMultipleChoice to go to the next panel
///
public CoursesController courseController;
///
/// Reference to instructional video player
///
public VideoPlayer videoPlayer;
///
/// Refrence to the video play/pause button
///
public Image playButton;
///
/// Reference to the image for displaying the current words sprite
///
public Transform optionContainer;
///
/// Reference to the image for displaying the current words sprite, for a fingerspelling courses
///
public Transform optionFingerspellingContainer;
///
/// Reference to the option prefab
///
public GameObject optionPrefab;
///
/// Reference to the option prefab, for a fingerspelling course
///
public GameObject optionFingerspellingPrefab;
///
/// Reference to the saved progress
///
public PersistentDataController.SavedCourseProgress progress;
///
/// The current sign that will be displayed
///
private Learnable currentSign;
///
/// Reference to all signs in this course
///
public List signs;
///
/// Index of the current sign
///
public int currentSignIndex;
///
/// Boolean used to check whether the current course is a fingerspelling course
///
public bool isFingerSpelling;
///
/// Boolean used to check whether the user has already answered the question
///
private bool hasAnswered = false;
///
/// Get a list of wrongs answers
///
/// The index of the correct sign
///
public List GetWrongOptions(int notThisIndex)
{
var test = progress.learnables.FindAll((l) => l.index != notThisIndex && l.inUse);
for (int i = test.Count - 1; i > 0; i--)
{
// Generate a random index between 0 and i (inclusive)
int j = UnityEngine.Random.Range(0, i + 1);
// Swap the values at indices i and j
(test[j], test[i]) = (test[i], test[j]);
}
List randomSigns = new List();
foreach (var sign in test.Take(3))
{
randomSigns.Add(signs[sign.index]);
}
return randomSigns;
}
///
/// Update the display of this panel
///
public void Display()
{
currentSign = signs[currentSignIndex];
videoPlayer.aspectRatio = VideoAspectRatio.FitInside;
videoPlayer.clip = currentSign.clip;
videoPlayer.Play();
// Gets three random selected signs from the list signs which are not equal to currentSign
List allOptions = GetWrongOptions(currentSignIndex);
// Add the correct sign at a random position in the list of all options
int randomIndex = UnityEngine.Random.Range(0, allOptions.Count + 1);
allOptions.Insert(randomIndex, currentSign);
var prefab = isFingerSpelling ? optionFingerspellingPrefab : optionPrefab;
var container = isFingerSpelling ? optionFingerspellingContainer : optionContainer;
foreach (Learnable option in allOptions)
{
GameObject multipleChoiceOption = GameObject.Instantiate(prefab, container);
if (!isFingerSpelling)
multipleChoiceOption.transform.Find("TextOption").GetComponent().text = option.name;
multipleChoiceOption.transform.Find("ImageOption").GetComponent().sprite = option.image;
Button button = multipleChoiceOption.GetComponent