using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.SceneManagement; public class ResultScene_TTE : MonoBehaviour { [Header("UI Texts")] public TMP_Text levelNameText; public TMP_Text scoreText; public TMP_Text highScoreText; public TMP_Text correctText; public TMP_Text wrongText; public TMP_Text resultStatusText; [Header("Buttons")] public Button retryButton; public Button levelMapButton; public Button mainMenuButton; [Header("Audio")] public AudioSource audioSource; public AudioClip clickSound; [Header("Scene Names")] [SerializeField] private string levelMapScene = "StageLevelMap"; [SerializeField] private string mainMenuScene = "Anamen"; [SerializeField] private string gameSceneName = "LLGameScene_Level"; private int score; private int correct; private int wrong; private int selectedLevel; private int langIndex; // CEVAP DİLİ İNDEKSİ // =========================== // 20 LEVEL ADI (6 DİL) // =========================== private readonly string[,] levelNames = new string[,] { { "Temel Selamlaşma ve İnsanlar","Basic Greetings & People","Saludos Básicos y Personas","Grundbegrüßungen & Menschen","Salutations de Base & Personnes","Saudações Básicas e Pessoas" }, { "Günlük Ev Nesneleri","Daily Household Items","Objetos del Hogar Diarios","Tägliche Haushaltsgegenstände","Objets Quotidiens de la Maison","Objetos Domésticos Diários" }, { "Yiyecekler ve İçecekler","Food & Drinks","Comida y Bebida","Essen & Getränke","Nourriture & Boissons","Comidas e Bebidas" }, { "Renkler, Şekiller ve Boyutlar","Colors, Shapes & Sizes","Colores, Formas y Tamaños","Farben, Formen & Größen","Couleurs, Formes & Tailles","Cores, Formas e Tamanhos" }, { "Zaman, Günler ve Mevsimler","Time, Days & Seasons","Tiempo, Días y Estaciones","Zeit, Tage & Jahreszeiten","Temps, Jours & Saisons","Tempo, Dias e Estações" }, { "Ev İçi Alanlar ve Temizlik","Home Areas & Cleaning","Áreas del Hogar y Limpieza","Hausbereiche & Reinigung","Espaces de Maison & Nettoyage","Áreas da Casa e Limpeza" }, { "Okul, Eğitim ve Ders Araçları","School, Education & Supplies","Escuela, Educación y Útiles","Schule, Bildung & Materialien","École, Éducation & Fournitures","Escola, Educação e Materiais" }, { "Vücut Parçaları ve Sağlık","Body Parts & Health","Partes del Cuerpo y Salud","Körperteile & Gesundheit","Parties du Corps & Santé","Partes do Corpo e Saúde" }, { "Doğa, Hava ve Çevre Unsurları","Nature, Weather & Environment","Naturaleza, Clima y Medio Ambiente","Natur, Wetter & Umwelt","Nature, Météo & Environnement","Natureza, Clima e Meio Ambiente" }, { "Evcil ve Vahşi Hayvanlar","Pets & Wild Animals","Mascotas y Animales Salvajes","Haustiere & Wildtiere","Animaux Domestiques & Sauvages","Animais Domésticos e Selvagens" }, { "Ulaşım Araçları ve Trafik","Transportation & Traffic","Transporte y Tráfico","Transport & Verkehr","Transport & Circulation","Transporte e Trânsito" }, { "Alışveriş ve Mağazalar","Shopping & Stores","Compras y Tiendas","Einkaufen & Geschäfte","Shopping & Magasins","Compras e Lojas" }, { "Spor Dalları ve Ekipmanları","Sports & Equipment","Deportes y Equipamiento","Sportarten & Ausrüstung","Sports & Équipement","Esportes e Equipamentos" }, { "Meslekler ve İş Alanları","Jobs & Work Fields","Profesiones y Áreas Laborales","Berufe & Arbeitsfelder","Métiers & Domaines de Travail","Profissões e Áreas de Trabalho" }, { "Şehir, Yerler ve Binalar","City, Places & Buildings","Ciudad, Lugares y Edificios","Stadt, Orte & Gebäude","Ville, Lieux & Bâtiments","Cidade, Lugares e Edifícios" }, { "Duygular, Durumlar ve Karakter","Emotions, States & Character","Emociones, Estados y Carácter","Gefühle, Zustände & Charakter","Émotions, États & Caractère","Emoções, Estados e Caráter" }, { "Seyahat, Tatil ve Turizm","Travel, Vacation & Tourism","Viajes, Vacaciones y Turismo","Reisen, Urlaub & Tourismus","Voyage, Vacances & Tourisme","Viagem, Férias e Turismo" }, { "Teknoloji, İnternet ve Cihazlar","Technology, Internet & Devices","Tecnología, Internet y Dispositivos","Technologie, Internet & Geräte","Technologie, Internet & Appareils","Tecnologia, Internet e Dispositivos" }, { "Çevre Koruma ve Geri Dönüşüm","Environmental Protection & Recycling","Protección Ambiental y Reciclaje","Umweltschutz & Recycling","Protection de l'Environnement & Recyclage","Proteção Ambiental e Reciclagem" }, { "İleri Günlük İfadeler ve İş Hayatı","Advanced Daily Phrases & Work Life","Frases Avanzadas y Vida Laboral","Fortgeschrittene Alltagssätze & Arbeitsleben","Phrases Avancées & Vie Professionnelle","Frases Avançadas e Vida Profissional" } }; private readonly string[] labelScore = { " ", " ", " ", " ", " ", " " }; private readonly string[] labelHighScore = { " ", " ", " ", " ", " ", " " }; private readonly string[] labelCorrect = { " ", " ", " ", " ", " ", " " }; private readonly string[] labelWrong = { " ", " ", " ", " ", " ", " " }; private readonly string[] labelPassed = { "TEBRİKLER! 🎉 LEVEL GEÇİLDİ", "CONGRATULATIONS! 🎉 LEVEL CLEARED", "¡FELICIDADES! 🎉 NIVEL COMPLETADO", "GLÜCKWUNSCH! 🎉 LEVEL GESCHAFFT", "FÉLICITATIONS ! 🎉 NIVEAU RÉUSSI", "PARABÉNS! 🎉 NÍVEL CONCLUÍDO" }; private readonly string[] labelFailed = { "LEVEL BAŞARISIZ ❌", "LEVEL FAILED ❌", "NIVEL FALLIDO ❌", "LEVEL NICHT BESTANDEN ❌", "NIVEAU ÉCHOUÉ ❌", "NÍVEL REPROVADO ❌" }; // ============================================================ void Start() { // 1) Dil indexini al string ansLang = PlayerPrefs.GetString("AnswerLangCode", "tr").ToLower(); langIndex = GetLangIndex(ansLang); // 2) Sonuçları yükle + high score kaydet LoadResults(); SaveHighScore(); // 3) ÖNCE butonları bağla (Start hata alsa bile en azından buraya kadar gelsin) if (retryButton != null) { retryButton.onClick.RemoveAllListeners(); retryButton.onClick.AddListener(OnRetry); } if (levelMapButton != null) { levelMapButton.onClick.RemoveAllListeners(); levelMapButton.onClick.AddListener(OnLevelMap); } if (mainMenuButton != null) { mainMenuButton.onClick.RemoveAllListeners(); mainMenuButton.onClick.AddListener(OnMainMenu); } // 4) UI’ı güncelle (null-safe) UpdateUI(); } // ============================================================ int GetLangIndex(string code) { switch (code) { case "tr": return 0; case "en": return 1; case "es": return 2; case "de": return 3; case "fr": return 4; case "pt": return 5; } return 1; } // ============================================================ void LoadResults() { score = PlayerPrefs.GetInt("Mod2Score", 0); correct = PlayerPrefs.GetInt("Mod2Correct", 0); wrong = PlayerPrefs.GetInt("Mod2Wrong", 0); selectedLevel = Mathf.Clamp(PlayerPrefs.GetInt("SelectedLevel", 1), 1, 20); } // ============================================================ void SaveHighScore() { string key = "HighScore_Level_" + selectedLevel; int old = PlayerPrefs.GetInt(key, 0); if (score > old) { PlayerPrefs.SetInt(key, score); PlayerPrefs.Save(); } } // ============================================================ void UpdateUI() { int safeLang = Mathf.Clamp(langIndex, 0, 5); int idx = Mathf.Clamp(selectedLevel - 1, 0, 19); if (levelNameText != null) levelNameText.text = $"LEVEL {selectedLevel}\n{levelNames[idx, safeLang]}"; if (scoreText != null) scoreText.text = $"{labelScore[safeLang]} {score}"; if (highScoreText != null) highScoreText.text = $"{labelHighScore[safeLang]} {PlayerPrefs.GetInt("HighScore_Level_" + selectedLevel, 0)}"; if (correctText != null) correctText.text = $"{labelCorrect[safeLang]} {correct}"; if (wrongText != null) wrongText.text = $"{labelWrong[safeLang]} {wrong}"; if (resultStatusText != null) { if (score >= 2000) { resultStatusText.text = labelPassed[safeLang]; resultStatusText.color = Color.green; } else { resultStatusText.text = labelFailed[safeLang]; resultStatusText.color = Color.red; } } } // ============================================================ void OnRetry() { PlayClick(); if (!string.IsNullOrEmpty(gameSceneName)) SceneManager.LoadScene(gameSceneName); } void OnLevelMap() { PlayClick(); if (!string.IsNullOrEmpty(levelMapScene)) SceneManager.LoadScene(levelMapScene); } void OnMainMenu() { PlayClick(); if (!string.IsNullOrEmpty(mainMenuScene)) SceneManager.LoadScene(mainMenuScene); } void PlayClick() { if (audioSource && clickSound) audioSource.PlayOneShot(clickSound); } }