/// <summary> /// Disable the input field when we´re done typing the name AND save the name to disk /// </summary> /// <param name="otherField"></param> public void RemoveInputField(InputField otherField) { // Save the newly made name to disk at the correct index with the rest of the updated scores SaveHighscoreToDisk(scoreFieldToUpdate.scoreNameFront.text, scoreFieldToUpdate.highscoreIndex); //PlayerPrefs.SetString(highScoreNamesOnDisk[scoreFieldToUpdate.highscoreIndex], scoreFieldToUpdate.scoreNameFront.text); UpdateScoreTextFields(); scoreFieldToUpdate = null; // Disable the inputField //otherField.gameObject.SetActive(false); gameController.SetMainScreenUI(MainScreenController.UIState.Highscore); }
//Når vi har en ny score, så skal vi hente alle de scores (og navne) fra harddisken, og sammenligne med vores nye score public void UpdateScoreOnDisk(int myScore, string myName) { oldScores = new int[10]; oldNames = new string[10]; newScores = new int[10]; newNames = new string[10]; int scoreFieldIndexWeBeat = -1; for (int i = 0; i < 10; i++) { oldScores[i] = PlayerPrefs.GetInt(highScoresOnDisk[i]); oldNames[i] = PlayerPrefs.GetString(highScoreNamesOnDisk[i]); newScores[i] = oldScores[i]; newNames[i] = oldNames[i]; } // 0 is HIGHEST score, so we start looking at the LOWEST score first. If we beat it, then we move up the line. for (int i = scoreFields.Length - 1; i >= 0; i--) { //Both check the score, and if we did NOT beat the score, then stop checking. If we DID beat the score, then keep going down the list //NOTE: the array is backwards, so index 0 is the score at the top of the list, and the index at .length-1 is the last one on the highscore if (!didWeBeatTheScore(i, myScore)) { break; } else { scoreFieldIndexWeBeat = i; } } //Remember which highscore place we beat, so we can ask the user for his name if (scoreFieldIndexWeBeat != -1) { scoreFieldToUpdate = scoreFields[scoreFieldIndexWeBeat]; //and I need to keep the index for the newNames[] to store the name on disk scoreFieldToUpdate.scoreFront.text = myScore.ToString(); scoreFieldToUpdate.scoreNameFront.text = "Enter Name"; scoreFieldToUpdate.highscoreIndex = scoreFieldIndexWeBeat; //saving the index to the field´s tag Debug.Log("We beat the score. Now give me your name!"); } else { SaveHighscoreToDisk(); //we didn´t } }
public void ShowFieldWindow() { Texture2D TempScreenshot = GameManager.Instance.GetSaveManager.LoadScreenshot(); if (TempScreenshot == null) { Debug.LogError("Beim Laden des Feldscreenshots ist ein Fehler aufgetreten. Das Fenster mit dem Feld Highscore konnte nicht angezeigt werden."); return; } HighscoreField HighscoreFieldScript = (HighscoreField)FindObjectOfType(typeof(HighscoreField)); if (!HighscoreFieldScript) { Debug.LogError("In der aktuellen Scene konnte kein Script mit dem Namen: HighscoreField gefunden werden! Das Fenster mit dem Feld Highscore konnte nicht angezeigt werden."); return; } HighscoreFieldScript.EnableWindow(TempScreenshot); }
/// <summary> /// Disable the input field when we´re done typing the name AND save the name to disk /// </summary> /// <param name="otherField"></param> public void RemoveInputField(InputField otherField) { // Save the newly made name to disk at the correct index with the rest of the updated scores SaveHighscoreToDisk(scoreFieldToUpdate.scoreNameFront.text, scoreFieldToUpdate.highscoreIndex); //PlayerPrefs.SetString(highScoreNamesOnDisk[scoreFieldToUpdate.highscoreIndex], scoreFieldToUpdate.scoreNameFront.text); UpdateScoreTextFields(); scoreFieldToUpdate = null; // Fjern det navn fra input-feltet som vi lige har skrevet otherField.text = ""; // Disable the inputField //otherField.gameObject.SetActive(false); //gameController.SetMainScreenUI(MainScreenController.UIState.Highscore); }
//Når vi har en ny score, så skal vi hente alle de scores (og navne) fra harddisken, og sammenligne med vores nye score public void UpdateScoreOnDisk(int myScore, string myName) { oldScores = new int[10]; oldNames = new string[10]; newScores = new int[10]; newNames = new string[10]; int scoreFieldIndexWeBeat = -1; for (int i = 0; i < 10; i++) { oldScores[i] = PlayerPrefs.GetInt(highScoresOnDisk[i]); oldNames[i] = PlayerPrefs.GetString(highScoreNamesOnDisk[i]); newScores[i] = oldScores[i]; newNames[i] = oldNames[i]; } // 0 is HIGHEST score, so we start looking at the LOWEST score first. If we beat it, then we move up the line. for (int i = scoreFields.Length - 1; i >= 0; i--) { //Both check the score, and if we did NOT beat the score, then stop checking. If we DID beat the score, then keep going down the list //NOTE: the array is backwards, so index 0 is the score at the top of the list, and the index at .length-1 is the last one on the highscore if( !didWeBeatTheScore(i, myScore)) break; else scoreFieldIndexWeBeat = i; } //Remember which highscore place we beat, so we can ask the user for his name if (scoreFieldIndexWeBeat != -1) { scoreFieldToUpdate = scoreFields[scoreFieldIndexWeBeat]; //and I need to keep the index for the newNames[] to store the name on disk scoreFieldToUpdate.scoreFront.text = myScore.ToString(); scoreFieldToUpdate.scoreNameFront.text = "Enter Name"; scoreFieldToUpdate.highscoreIndex = scoreFieldIndexWeBeat; //saving the index to the field´s tag Debug.Log("We beat the score. Now give me your name!"); } else SaveHighscoreToDisk(); //we didn´t }