Merge branch 'main' of https://github.com/itsvraza/ToothyV
This commit is contained in:
commit
381209a405
|
@ -9,7 +9,7 @@ public class AuntMenu : Menu<AuntMenu>
|
|||
{
|
||||
[SerializeField] private GameObject loadingScreen;
|
||||
|
||||
[Header("Register")]
|
||||
[Header("Register")]
|
||||
[SerializeField] private TMP_InputField usernameFieldRegister;
|
||||
[SerializeField] private TMP_InputField nameFieldRegister;
|
||||
[SerializeField] private TMP_InputField paswordFieldRegister;
|
||||
|
@ -26,7 +26,7 @@ public class AuntMenu : Menu<AuntMenu>
|
|||
[SerializeField] private GameObject RegisterObj;
|
||||
[SerializeField] private GameObject InvalidAge;
|
||||
|
||||
[Header("Login")]
|
||||
[Header("Login")]
|
||||
[SerializeField] private TMP_InputField usernameFieldLogin;
|
||||
[SerializeField] private TMP_InputField paswordFieldLogin;
|
||||
private string usernameLogin;
|
||||
|
@ -99,20 +99,26 @@ public class AuntMenu : Menu<AuntMenu>
|
|||
paswordRegister = paswordFieldRegister.text;
|
||||
EmailRegister = EmailFieldRegister.text;
|
||||
|
||||
int day = dateAgeRegister.value + 1;
|
||||
int day = dateAgeRegister.value + 1;
|
||||
int month = monthAgeRegister.value + 1;
|
||||
int year = int.Parse(yearAgeRegister.options[yearAgeRegister.value].text);
|
||||
|
||||
DateTime birthDate = new DateTime(year, month, day);
|
||||
calculatedAge = CalculateAge(birthDate);
|
||||
//
|
||||
// if (calculatedAge < 6 || calculatedAge > 12)
|
||||
// {
|
||||
// Debug.LogWarning("Age must be between 6 and 12 years!");
|
||||
// Debug.Log(calculatedAge);
|
||||
// InvalidAge.SetActive(true);
|
||||
// return;
|
||||
// }
|
||||
// Validasi tanggal + hitung umur
|
||||
if (!TryGetValidAge(year, month, day, out calculatedAge))
|
||||
{
|
||||
Debug.LogWarning("Tanggal tidak valid!");
|
||||
InvalidAge.SetActive(true);
|
||||
ResetRegisterFields();
|
||||
return;
|
||||
}
|
||||
|
||||
if (calculatedAge < 6 || calculatedAge > 9)
|
||||
{
|
||||
Debug.LogWarning("Usia harus antara 6 sampai 9 tahun!");
|
||||
InvalidAge.SetActive(true);
|
||||
ResetRegisterFields();
|
||||
return;
|
||||
}
|
||||
|
||||
await AuthenticationManager.SignUpUsernamePassword(usernameRegister, paswordRegister, EmailRegister, calculatedAge.ToString());
|
||||
|
||||
|
@ -125,6 +131,21 @@ public class AuntMenu : Menu<AuntMenu>
|
|||
await Cloudsave.SaveData(dataToSave, "DataPlayer");
|
||||
}
|
||||
|
||||
private bool TryGetValidAge(int year, int month, int day, out int age)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime birthDate = new DateTime(year, month, day);
|
||||
age = CalculateAge(birthDate);
|
||||
return true;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
age = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private int CalculateAge(DateTime birthDate)
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
|
@ -132,4 +153,15 @@ public class AuntMenu : Menu<AuntMenu>
|
|||
if (birthDate.Date > today.AddYears(-age)) age--;
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetRegisterFields()
|
||||
{
|
||||
usernameFieldRegister.text = "";
|
||||
nameFieldRegister.text = "";
|
||||
paswordFieldRegister.text = "";
|
||||
EmailFieldRegister.text = "";
|
||||
dateAgeRegister.value = 0;
|
||||
monthAgeRegister.value = 0;
|
||||
yearAgeRegister.value = 0;
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
[SerializeField] TextMeshProUGUI questionText;
|
||||
[SerializeField] List<QuestionSO> questions = new List<QuestionSO>();
|
||||
[SerializeField] GameObject[] answerButtons;
|
||||
|
||||
[Header("Answers")]
|
||||
|
||||
[Header("Answers")]
|
||||
[SerializeField] private Sprite normalButttonSprite;
|
||||
[SerializeField] private Sprite trueAnswerSprite;
|
||||
[SerializeField] private Sprite falseAnswerSprite;
|
||||
|
@ -33,12 +33,12 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
bool isComplete = false;
|
||||
|
||||
SaveData saveData;
|
||||
int correctAnswers = 0;
|
||||
int totalQuestions = 10;
|
||||
|
||||
int correctAnswers = 0;
|
||||
int totalQuestions = 10;
|
||||
|
||||
private int indexEnable = 0;
|
||||
|
||||
|
||||
|
||||
private async void OnEnable()
|
||||
{
|
||||
indexEnable++;
|
||||
|
@ -86,7 +86,7 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
await EndGame();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Image buttonImage;
|
||||
int index = Random.Range(0, questions.Count);
|
||||
|
@ -109,10 +109,10 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
timer = timeToComplete;
|
||||
isAnswering = true;
|
||||
hasAnsweredEarly = false;
|
||||
|
||||
|
||||
audioController.Instance.StopDubbing();
|
||||
audioController.Instance.PlayDubbing(currentQuestion.dubbingName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnAnswerSelected(int index)
|
||||
|
@ -132,7 +132,7 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
|
||||
if (index == correctAnswerIndex)
|
||||
{
|
||||
correctAnswers ++;
|
||||
correctAnswers++;
|
||||
Debug.Log("Jawab Benar");
|
||||
selectedImage.sprite = trueAnswerSprite;
|
||||
questionText.text = "Jawaban Benar!";
|
||||
|
@ -146,7 +146,7 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
saveData.postTestStatistik = (int)(((float)correctAnswers / totalQuestions) * 100f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ShowCorrectAnswer()
|
||||
{
|
||||
isAnswering = false;
|
||||
|
@ -168,10 +168,22 @@ public class PostTestMenu : Menu<PostTestMenu>
|
|||
private async Task EndGame()
|
||||
{
|
||||
isComplete = true;
|
||||
int finalScore = (int)(((float)correctAnswers / totalQuestions) * 100f);
|
||||
saveData.postTestStatistik = finalScore;
|
||||
int finalScore = (int)(((float)correctAnswers / totalQuestions) * 100f);
|
||||
saveData.postTestStatistik = finalScore;
|
||||
await Cloudsave.SaveData(saveData, "DataPlayer");
|
||||
MainMenu.Open();
|
||||
SelectLevel.Open();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
audioController.Instance.StopDubbing();
|
||||
}
|
||||
|
||||
public override void OnBackPressed()
|
||||
{
|
||||
base.OnBackPressed();
|
||||
audioController.Instance.StopDubbing();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ public class PreTestMenu : Menu<PreTestMenu>
|
|||
|
||||
[Header("UI")]
|
||||
[SerializeField] TextMeshProUGUI timerText;
|
||||
|
||||
[Header("Answers")]
|
||||
|
||||
[Header("Answers")]
|
||||
[SerializeField] private Sprite normalButttonSprite;
|
||||
[SerializeField] private Sprite trueAnswerSprite;
|
||||
[SerializeField] private Sprite falseAnswerSprite;
|
||||
|
@ -31,10 +31,10 @@ public class PreTestMenu : Menu<PreTestMenu>
|
|||
|
||||
QuestionSO currentQuestion;
|
||||
bool isComplete = false;
|
||||
|
||||
|
||||
SaveData saveData;
|
||||
|
||||
int correctAnswers = 0;
|
||||
int correctAnswers = 0;
|
||||
int totalQuestions = 10;
|
||||
|
||||
private int indexEnable = 0;
|
||||
|
@ -51,15 +51,15 @@ public class PreTestMenu : Menu<PreTestMenu>
|
|||
|
||||
private async Task LoadAndRefresh()
|
||||
{
|
||||
saveData = await Cloudsave.LoadData<SaveData>("DataPlayer");
|
||||
saveData.isPreTestComplete = true;
|
||||
saveData = await Cloudsave.LoadData<SaveData>("DataPlayer");
|
||||
saveData.isPreTestComplete = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isComplete) return;
|
||||
|
||||
if(indexEnable == 0) return;
|
||||
if (indexEnable == 0) return;
|
||||
if (isComplete) return;
|
||||
|
||||
timer -= Time.deltaTime;
|
||||
|
@ -113,7 +113,7 @@ public class PreTestMenu : Menu<PreTestMenu>
|
|||
timer = timeToComplete;
|
||||
isAnswering = true;
|
||||
hasAnsweredEarly = false;
|
||||
|
||||
|
||||
audioController.Instance.StopDubbing();
|
||||
audioController.Instance.PlayDubbing(currentQuestion.dubbingName);
|
||||
}
|
||||
|
@ -169,10 +169,21 @@ public class PreTestMenu : Menu<PreTestMenu>
|
|||
private async Task EndGame()
|
||||
{
|
||||
isComplete = true;
|
||||
int finalScore = (int)(((float)correctAnswers / totalQuestions) * 100f);
|
||||
saveData.preTestStatistik = finalScore;
|
||||
int finalScore = (int)(((float)correctAnswers / totalQuestions) * 100f);
|
||||
saveData.preTestStatistik = finalScore;
|
||||
await Cloudsave.SaveData(saveData, "DataPlayer");
|
||||
MainMenu.Open();
|
||||
SelectLevel.Open();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
audioController.Instance.StopDubbing();
|
||||
}
|
||||
|
||||
public override void OnBackPressed()
|
||||
{
|
||||
base.OnBackPressed();
|
||||
audioController.Instance.StopDubbing();
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
[SerializeField] TextMeshProUGUI questionText;
|
||||
[SerializeField] QuestionSO currentQuestion;
|
||||
|
||||
[Header("Answers")]
|
||||
[Header("Answers")]
|
||||
[SerializeField] private Sprite normalButttonSprite;
|
||||
[SerializeField] private Sprite trueAnswerSprite;
|
||||
[SerializeField] private Sprite falseAnswerSprite;
|
||||
|
@ -26,7 +26,7 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
public bool isComplete = false;
|
||||
|
||||
bool isGameOver = false;
|
||||
|
||||
|
||||
//========================
|
||||
[SerializeField] float timeToCompleteQuestion = 30f;
|
||||
[SerializeField] float timeToShowCorrectAnswer = 10f;
|
||||
|
@ -46,7 +46,7 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
correctAnswerIndex = currentQuestion.answerIndex;
|
||||
|
||||
timerValue = timeToCompleteQuestion;
|
||||
isAnsweringQuestion = true;
|
||||
isAnsweringQuestion = true;
|
||||
fillFraction = 1f;
|
||||
loadNextQuestion = false;
|
||||
hasAnsweredEarly = false;
|
||||
|
@ -57,7 +57,7 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
PlayDubbingQuestion();
|
||||
audioController.Instance.bgmSource.volume = .1f;
|
||||
}
|
||||
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
isAnsweringQuestion = false;
|
||||
|
@ -75,18 +75,22 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
button.interactable = true;
|
||||
|
||||
Image buttonImage = answerButtons[i].GetComponent<Image>();
|
||||
buttonImage.color = Color.white;
|
||||
buttonImage.color = Color.white;
|
||||
}
|
||||
|
||||
if (timerImage != null)
|
||||
{
|
||||
timerImage.fillAmount = 1f;
|
||||
}
|
||||
|
||||
audioController.Instance.bgmSource.volume = 1f;
|
||||
|
||||
if (audioController.Instance != null)
|
||||
{
|
||||
audioController.Instance.StopDubbing();
|
||||
audioController.Instance.bgmSource.volume = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (gameManager == null)
|
||||
|
@ -95,13 +99,13 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
}
|
||||
StateLoadQuestion();
|
||||
UpdateTimer();
|
||||
if(isComplete)
|
||||
if (isComplete)
|
||||
{
|
||||
Debug.Log("Game Over");
|
||||
isComplete = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CancelTimer()
|
||||
{
|
||||
timerValue = 0;
|
||||
|
@ -223,11 +227,11 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
buttonImage.sprite = normalButttonSprite;
|
||||
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonText.text = currentQuestion.answers[i];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async void DelayAfterAnswerTrue()
|
||||
{
|
||||
SaveData saveData = await Cloudsave.LoadData<SaveData>("DataPlayer");
|
||||
|
@ -271,7 +275,7 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
|
||||
GameMenu.Open();
|
||||
}
|
||||
|
||||
|
||||
IEnumerator DelayAfterAnswerFalse()
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
@ -293,5 +297,13 @@ public class QuizPopUp : Menu<QuizPopUp>
|
|||
{
|
||||
audioController.Instance.StopDubbing();
|
||||
audioController.Instance.PlayDubbing(currentQuestion.dubbingName);
|
||||
|
||||
}
|
||||
|
||||
public override void OnBackPressed()
|
||||
{
|
||||
base.OnBackPressed();
|
||||
audioController.Instance.StopDubbing();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue