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 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;
}
}

View File

@ -174,4 +174,16 @@ public class PostTestMenu : Menu<PostTestMenu>
MainMenu.Open();
SelectLevel.Open();
}
private void OnDisable()
{
audioController.Instance.StopDubbing();
}
public override void OnBackPressed()
{
base.OnBackPressed();
audioController.Instance.StopDubbing();
}
}

View File

@ -175,4 +175,15 @@ public class PreTestMenu : Menu<PreTestMenu>
MainMenu.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;
}
if (audioController.Instance != null)
{
audioController.Instance.StopDubbing();
audioController.Instance.bgmSource.volume = 1f;
}
}
void Update()
{
@ -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();
}
}