using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using UnityEngine.Localization.Settings; using UnityEditor; using DG.Tweening; public class DisplayText : MonoBehaviour { GameManager gm; GameModifiers gameMods; /*float timer = 0.0f; int colorIndex = 0; private Color startColor = Color.red;*/ private Color startColor = Color.white; private float startFontSize = 12; public enum TextType // your custom enumeration { score, minesMissing, minesTotal, flagsTotal, time, bestScore, bestScoreTitle, linesCleared, tetrisweepsCleard, scoreMultiplier, quit, level, tSpinSweeps, TESTCurrentMinoLockDelay, TESTCurrentMinoRotation, gameModeName, gameModeNameComplete, versionNumber, revealCombo, scoreTitle }; public TextType displayType; // t$$anonymous$$s public var should appear as a drop down // Start is called before the first frame update void Start() { gm = GameObject.FindGameObjectWithTag("GameController").GetComponent(); //ScoreKeeper.Instance = gm.scoreKeeper; gameMods = gm.gameMods; startColor = this.GetComponent().color; startFontSize = this.GetComponent().fontSize; if (displayType == TextType.versionNumber) { string versionStr = "v" + Application.version; if (ScoreKeeper.versionIsBeta) versionStr += "-Beta"; if (ScoreKeeper.versionIsDRMFree) versionStr += " DRM-Free"; if (ScoreKeeper.versionIsDemo) versionStr += " Demo"; /*if (ScoreKeeper.versionType == ScoreKeeper.VersionType.standard) this.GetComponent().text = "v" + Application.version; else if (ScoreKeeper.versionType == ScoreKeeper.VersionType.beta) this.GetComponent().text = "v" + Application.version + " Beta"; else if (ScoreKeeper.versionType == ScoreKeeper.VersionType.demoOnline) this.GetComponent().text = "v" + Application.version + " Demo-B"; else if (ScoreKeeper.versionType == ScoreKeeper.VersionType.demoSteam) this.GetComponent().text = "v" + Application.version + " Demo-A";*/ this.GetComponent().text = versionStr; } } // Update is called once per frame void Update() { if (displayType == TextType.score) { if (gm.GetScore() > 0) this.GetComponent().text = gm.GetScore().ToString("#,#"); else this.GetComponent().text = gm.GetScore().ToString(); if (ScoreKeeper.Instance.bestScoreToday <= gm.GetScore() && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestScoreToday > 0) this.GetComponent().enabled = true; if (ScoreKeeper.Instance.bestScore <= gm.GetScore() && ScoreKeeper.Instance.bestScore > 0) { this.GetComponent().enabled = true; this.GetComponent().enabled = true; } /*if (!gm.gameMods.detailedTimer || gm.gameMods.timeLimit < Mathf.Infinity) // Normal score mode { } else // 40L Sprint mode { displayType = TextType.bestScore; }*/ } else if (displayType == TextType.scoreTitle) { string localizedText = GameManager.GetTranslation("UIText", "GUI Score"); // "High Score" if (ScoreKeeper.Instance.bestScore <= gm.GetScore() && ScoreKeeper.Instance.bestScore > 0) { this.GetComponent().enabled = true; } /*if (!gm.gameMods.detailedTimer || gm.gameMods.timeLimit < Mathf.Infinity) // Normal score mode { } else // 40L Sprint Mode { displayType = TextType.bestScoreTitle; }*/ } else if (displayType == TextType.scoreMultiplier) { string suffix = ""; if (gm.scoreMultiplierTimer >= 25) suffix = "!!!!!"; else if (gm.scoreMultiplierTimer >= 20) suffix = "!!!!"; else if (gm.scoreMultiplierTimer >= 15) suffix = "!!!"; else if (gm.scoreMultiplierTimer >= 10) suffix = "!!"; else if (gm.scoreMultiplierTimer >= 5) suffix = "!"; else if (gm.scoreMultiplierTimer <= 0) suffix = ""; else if (gm.scoreMultiplierTimer <= 1) suffix = "..."; else if (gm.scoreMultiplierTimer <= 2) suffix = ".."; else if (gm.scoreMultiplierTimer <= 3) suffix = "."; string scoreStr = (100 + gm.scoreMultiplier).ToString(); string scoreStrFront = scoreStr.Substring(0, scoreStr.Length - 2); string scoreStrBack = ""; string scoreStrTenths = scoreStr.Substring(scoreStr.Length - 2, 1); string scoreStrHundredths = scoreStr.Substring(scoreStr.Length - 1); if (scoreStrTenths != "0" && scoreStrHundredths == "0") scoreStrBack = "." + scoreStrTenths; else if (scoreStrHundredths != "0") scoreStrBack = "." + scoreStrTenths + scoreStrHundredths; if (gm.GetScoreMultiplier() > 0) this.GetComponent().text = "x" + scoreStrFront + scoreStrBack + suffix; //(Math.Truncate(gm.scoreMultiplier * 100) / 100)); else this.GetComponent().text = ""; if (gm.scoreMultiplier >= gm.scoreMultiplierLimit) this.GetComponent().enabled = true; else { this.GetComponent().enabled = false; if (gm.scoreMultiplierTimer <= 0) this.GetComponent().color = Color.red; else this.GetComponent().color = startColor; } } else if (displayType == TextType.minesMissing) { int currentMines = gm.currentMines; int currentFlags = gm.currentFlags; int unknownMines = currentMines - currentFlags; string suffix = " *"; if (unknownMines < 0) suffix = "? *"; string localizedText = GameManager.GetTranslation("UIText", "GUI Mines"); // "Mines" this.GetComponent().text = localizedText + ": " + unknownMines + suffix; } else if (displayType == TextType.minesTotal) { /*this.GetComponent().text = "Mines Total: " + gm.currentMines;*/ } else if (displayType == TextType.flagsTotal) { /*this.GetComponent().text = "Flags Total: " + gm.currentFlags;*/ } else if (displayType == TextType.time) { string localizedText = ""; // GameManager.GetTranslation("UIText", "GUI Time") + ": "; // "Time" if (gm.gameMods.timeLimit < Mathf.Infinity) this.GetComponent().text = localizedText + GetTimeString(gm.gameMods.timeLimit - gm.GetTime()); else this.GetComponent().text = localizedText + GetTimeString(gm.GetTime()); } else if (displayType == TextType.bestScore) { if (!gm.gameMods.detailedTimer || gm.gameMods.timeLimit < Mathf.Infinity) // Normal score mode { // Display Best Score Today while your current score is under Best Score Today, unless it's the first run of the game. // Otherwise, display your total high score /*if (ScoreKeeper.Instance.bestScoreToday > 0 && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestScoreToday > gm.GetScore()) // Best Score Today this.GetComponent().text = ScoreKeeper.Instance.bestScoreToday.ToString("#,#");*/ if (ScoreKeeper.Instance.bestScore > 0) // Best Score Total this.GetComponent().text = ((float)ScoreKeeper.Instance.bestScore).ToString("#,#"); else // Hi Score = 0 this.GetComponent().text = ScoreKeeper.Instance.bestScore.ToString(); if (ScoreKeeper.Instance.bestScore <= gm.GetScore() && ScoreKeeper.Instance.bestScore > 0) { this.GetComponent().enabled = true; this.GetComponent().enabled = true; } //if (ScoreKeeper.Instance.bestScoreToday > 0 && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestScoreToday <= gm.GetScore()) //this.GetComponent().enabled = true; } else // 40L sprint mode { string bestTimeStr = GetTimeString(ScoreKeeper.Instance.bestTime); //string bestTimeTodayStr = GetTimeString(ScoreKeeper.Instance.bestTimeToday); //this.GetComponent().text = bestTimeStr + ", " + bestTimeTodayStr; this.GetComponent().text = bestTimeStr; //Debug.Log("BestTime: " + ScoreKeeper.Instance.bestTime + ", currentTime: " + gm.GetTime()); if (ScoreKeeper.Instance.bestTime >= gm.GetTime() && gm.isEndless && !gm.isGameOver) { this.GetComponent().enabled = true; this.GetComponent().enabled = true; } else { this.GetComponent().enabled = false; this.GetComponent().enabled = false; } //if (ScoreKeeper.Instance.bestTimeToday < Mathf.Infinity && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestTimeToday >= gm.GetTime()) //this.GetComponent().enabled = true; /*if (ScoreKeeper.Instance.bestTimeToday < Mathf.Infinity && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestTime < gm.GetTime()) // Best Score Today this.GetComponent().text = bestTimeTodayStr;*/ } } else if (displayType == TextType.bestScoreTitle) { string localizedText = GameManager.GetTranslation("UIText", "GUI HighScore"); // "High Score" if (!gm.gameMods.detailedTimer || gm.gameMods.timeLimit < Mathf.Infinity) // Normal score mode { /*if (ScoreKeeper.Instance.bestScoreToday > 0 && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestScoreToday > gm.GetScore()) // Best Score Today localizedText = GameManager.GetTranslation("UIText", "GUI HighScoreBestToday"); // "Best Today" if (ScoreKeeper.Instance.bestScoreToday == ScoreKeeper.Instance.bestScore)*/ localizedText = GameManager.GetTranslation("UIText", "GUI HighScore"); // "High Score" if (ScoreKeeper.Instance.bestScore <= gm.GetScore() && ScoreKeeper.Instance.bestScore > 0) { this.GetComponent().enabled = true; } } else // 40L sprint mode { localizedText = GameManager.GetTranslation("UIText", "GUI HighScoreBestTime"); // "Best Time" if (ScoreKeeper.Instance.bestTime >= gm.GetTime() && gm.isEndless && !gm.isGameOver) { this.GetComponent().enabled = true; } /*if (ScoreKeeper.Instance.bestTimeToday < Mathf.Infinity && ScoreKeeper.Instance.runs > 1 && ScoreKeeper.Instance.bestTime < gm.GetTime()) // Best Score Today localizedText = GameManager.GetTranslation("UIText", "GUI HighScoreBestToday"); // "Best Today"*/ } this.GetComponent().text = localizedText + ""; } else if (displayType == TextType.linesCleared) { //string localizedText = GameManager.GetTranslation("UIText", "GUI Lines"); // "Lines" this.GetComponent().text = gm.linesCleared.ToString(); // localizedText + ": " + gm.linesCleared; } else if (displayType == TextType.tetrisweepsCleard) { string localizedText = GameManager.GetTranslation("UIText", "GUI Tetrisweeeps"); // "Tetrisweeps" if (gm.tetrisweepsCleared == 0) this.GetComponent().text = ""; else { this.GetComponent().text = localizedText + ": " + gm.tetrisweepsCleared; this.GetComponent().enabled = true; this.GetComponent().enabled = true; } } else if (displayType == TextType.quit) { string localizedText = GameManager.GetTranslation("UIText", "Menu Quit"); // "Quit" if (Application.platform == RuntimePlatform.WebGLPlayer && gm.hasQuit) { localizedText = GameManager.GetTranslation("UIText", "Menu QuitCancel"); // "Can't Quit in Browser" this.GetComponent().text = localizedText; this.GetComponent().fontSize = 8; } else { this.GetComponent().text = localizedText; this.GetComponent().fontSize = startFontSize; } } else if (displayType == TextType.level) { //string localizedText = GameManager.GetTranslation("UIText", "GUI Level"); // "Level" this.GetComponent().text = gm.level.ToString(); // localizedText + ": " + gm.level; } else if (displayType == TextType.tSpinSweeps) { if (gm.tSpinsweepsCleared == 0) this.GetComponent().text = ""; else { string localizedText = GameManager.GetTranslation("UIText", "GUI Tspinsweeps"); // "T-Spinsweeps" this.GetComponent().text = localizedText + ": " + gm.tSpinsweepsCleared; this.GetComponent().enabled = true; this.GetComponent().enabled = true; } } else if (displayType == TextType.TESTCurrentMinoLockDelay) { if (PlayerPrefs.GetInt("LockDelayDisplayEnabled", 0) == 0) { this.GetComponent().text = ""; return; } Group activeTetromino = gm.GetActiveTetromino(); if (activeTetromino == null) { this.GetComponent().text = ""; } else { int resets = 15 - activeTetromino.lockResets; //if (resets < 0) //resets = 0; if (activeTetromino.lockDelayTimer > 0 && activeTetromino.isLocking) this.GetComponent().text = "Lock: " + activeTetromino.lockDelayTimer.ToString("#,#.#") + ", Resets: " + resets; // TODO I'm gonna remove this maybe? else this.GetComponent().text = "Lock: 0.5" + ", Resets: " + resets; } } else if (displayType == TextType.TESTCurrentMinoRotation) { Group activeTetromino = gm.GetActiveTetromino(); if (activeTetromino == null) { this.GetComponent().text = "Null"; } else { // 0 = spawn state, 1 = counter-clockwise rotation from spawn, 2 = 2 successive rotations from spawn, 3 = clockwise rotation from spawn switch (activeTetromino.currentRotation) { case 0: this.GetComponent().text = "0: spawn state"; break; case 1: this.GetComponent().text = "1: counter-clockwise"; break; case 2: this.GetComponent().text = "2: Upside-down"; break; case 3: this.GetComponent().text = "3: clockwise"; break; default: this.GetComponent().text = "?: no rotation found?"; break; } } } else if (displayType == TextType.gameModeName) { string gameMode = gameMods.gameModeName; if (gameMods.gameModeDisplayName != "") gameMode = gameMods.gameModeDisplayName; string localizedText = GameManager.GetTranslation("UIText", "GameMode " + gameMode); // Returns translation of game mode name, ex. "Marathon" if (gm.isEndless && !gm.marathonOverMenu.GetIsActive()) localizedText += " (" + GameManager.GetTranslation("UIText", "GameMode Endless") + ")"; // " (Endless)" this.GetComponent().text = localizedText; } else if (displayType == TextType.gameModeNameComplete) { string gameMode = gameMods.gameModeName; if (gameMods.gameModeDisplayName != "") gameMode = gameMods.gameModeDisplayName; string localizedText = GameManager.GetTranslation("UIText", "GameMode " + gameMode); // Returns translation of game mode name, ex. "Marathon" this.GetComponent().text = localizedText + " " + GameManager.GetTranslation("UIText", "GameMode Complete") + "!"; } else if (displayType == TextType.revealCombo) { this.GetComponent().text = ((float)gm.revealCombo).ToString("#,#.#"); /*this.GetComponent().color = startColor; if (gm.revealComboDrainTween != null) if (gm.revealComboDrainTween.IsActive()) if (gm.revealComboDrainTween.IsPlaying()) this.GetComponent().color = Color.red;*/ } } public void MouseOverTextEnter() { if (displayType == TextType.gameModeName) { string gameMode = gameMods.gameModeName; if (gameMods.gameModeDisplayName != "") gameMode = gameMods.gameModeDisplayName; //string localizedText = GameManager.GetTranslation("UIText", "Tooltip " + gameMode); // Returns translation of game mode description, ex. "Marathon" Tooltip.ShowTooltip_Static(gameMode); } } /*public void MouseOverTextExit() { if (displayType == TextType.gameModeName) Tooltip.HideTooltip_Static(); }*/ public string GetTimeString(float time) { if (time == Mathf.Infinity) return "--"; int milliseconds = (int)(time * 1000f) % 1000; int seconds = ((int)time % 60); int minutes = ((int) time / 60); string monospaceString = ""; string monospaceStringPunctuation = ""; if (gameMods.detailedTimer) { return string.Format(monospaceString + "{0:0}" + monospaceStringPunctuation + ":" + monospaceString + "{1:00}" + monospaceStringPunctuation + "." + monospaceString + "{2:000}", minutes, seconds, milliseconds); } else { return string.Format(monospaceString + "{0:0}" + monospaceStringPunctuation + ":" + monospaceString + "{1:00}", minutes, seconds); } } }