This commit is contained in:
Vira 2025-07-15 20:22:37 +07:00
commit 381209a405
4 changed files with 118 additions and 51 deletions

View File

@ -103,16 +103,22 @@ public class AuntMenu : Menu<AuntMenu>
int month = monthAgeRegister.value + 1; int month = monthAgeRegister.value + 1;
int year = int.Parse(yearAgeRegister.options[yearAgeRegister.value].text); int year = int.Parse(yearAgeRegister.options[yearAgeRegister.value].text);
DateTime birthDate = new DateTime(year, month, day); // Validasi tanggal + hitung umur
calculatedAge = CalculateAge(birthDate); if (!TryGetValidAge(year, month, day, out calculatedAge))
// {
// if (calculatedAge < 6 || calculatedAge > 12) Debug.LogWarning("Tanggal tidak valid!");
// { InvalidAge.SetActive(true);
// Debug.LogWarning("Age must be between 6 and 12 years!"); ResetRegisterFields();
// Debug.Log(calculatedAge); return;
// InvalidAge.SetActive(true); }
// 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()); await AuthenticationManager.SignUpUsernamePassword(usernameRegister, paswordRegister, EmailRegister, calculatedAge.ToString());
@ -125,6 +131,21 @@ public class AuntMenu : Menu<AuntMenu>
await Cloudsave.SaveData(dataToSave, "DataPlayer"); 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) private int CalculateAge(DateTime birthDate)
{ {
DateTime today = DateTime.Today; DateTime today = DateTime.Today;
@ -132,4 +153,15 @@ public class AuntMenu : Menu<AuntMenu>
if (birthDate.Date > today.AddYears(-age)) age--; if (birthDate.Date > today.AddYears(-age)) age--;
return age; return age;
} }
private void ResetRegisterFields()
{
usernameFieldRegister.text = "";
nameFieldRegister.text = "";
paswordFieldRegister.text = "";
EmailFieldRegister.text = "";
dateAgeRegister.value = 0;
monthAgeRegister.value = 0;
yearAgeRegister.value = 0;
}
} }

View File

@ -132,7 +132,7 @@ public class PostTestMenu : Menu<PostTestMenu>
if (index == correctAnswerIndex) if (index == correctAnswerIndex)
{ {
correctAnswers ++; correctAnswers++;
Debug.Log("Jawab Benar"); Debug.Log("Jawab Benar");
selectedImage.sprite = trueAnswerSprite; selectedImage.sprite = trueAnswerSprite;
questionText.text = "Jawaban Benar!"; questionText.text = "Jawaban Benar!";
@ -174,4 +174,16 @@ public class PostTestMenu : Menu<PostTestMenu>
MainMenu.Open(); MainMenu.Open();
SelectLevel.Open(); SelectLevel.Open();
} }
private void OnDisable()
{
audioController.Instance.StopDubbing();
}
public override void OnBackPressed()
{
base.OnBackPressed();
audioController.Instance.StopDubbing();
}
} }

View File

@ -59,7 +59,7 @@ public class PreTestMenu : Menu<PreTestMenu>
{ {
if (isComplete) return; if (isComplete) return;
if(indexEnable == 0) return; if (indexEnable == 0) return;
if (isComplete) return; if (isComplete) return;
timer -= Time.deltaTime; timer -= Time.deltaTime;
@ -175,4 +175,15 @@ public class PreTestMenu : Menu<PreTestMenu>
MainMenu.Open(); MainMenu.Open();
SelectLevel.Open(); SelectLevel.Open();
} }
private void OnDisable()
{
audioController.Instance.StopDubbing();
}
public override void OnBackPressed()
{
base.OnBackPressed();
audioController.Instance.StopDubbing();
}
} }

View File

@ -83,9 +83,13 @@ public class QuizPopUp : Menu<QuizPopUp>
timerImage.fillAmount = 1f; timerImage.fillAmount = 1f;
} }
if (audioController.Instance != null)
{
audioController.Instance.StopDubbing();
audioController.Instance.bgmSource.volume = 1f; audioController.Instance.bgmSource.volume = 1f;
} }
}
void Update() void Update()
{ {
@ -95,7 +99,7 @@ public class QuizPopUp : Menu<QuizPopUp>
} }
StateLoadQuestion(); StateLoadQuestion();
UpdateTimer(); UpdateTimer();
if(isComplete) if (isComplete)
{ {
Debug.Log("Game Over"); Debug.Log("Game Over");
isComplete = false; isComplete = false;
@ -293,5 +297,13 @@ public class QuizPopUp : Menu<QuizPopUp>
{ {
audioController.Instance.StopDubbing(); audioController.Instance.StopDubbing();
audioController.Instance.PlayDubbing(currentQuestion.dubbingName); audioController.Instance.PlayDubbing(currentQuestion.dubbingName);
} }
public override void OnBackPressed()
{
base.OnBackPressed();
audioController.Instance.StopDubbing();
}
} }