public void UseChartInfo(SongMenu_ButtonChart button) { SongMenu_ButtonChart[] listOldButtons = FindObjectsOfType <SongMenu_ButtonChart>(); foreach (SongMenu_ButtonChart x in listOldButtons) { x.imageButton.color = Color.white; } button.imageButton.color = Color.grey; intGameType = button.intGameMode; intGameChart = button.intChart; string input = ""; ChartData chartData = ScriptableObject.CreateInstance(typeof(ChartData)) as ChartData; string chartChecksum = ""; if (isLoadCustomSongs) { string path = Directory.GetCurrentDirectory() + stringSongDirectoryPath + "/" + stringSongSelectedCurrent + "/" + stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString() + ".txt"; StreamReader reader = new StreamReader(path); input = reader.ReadToEnd(); reader.Close(); reader = new StreamReader(path); MD5 md5checksum = MD5.Create(); byte[] byteChecksum = md5checksum.ComputeHash(reader.BaseStream); foreach (byte x in byteChecksum) { chartChecksum += x; } reader.Close(); } else { string path = "Songs/" + stringSongSelectedCurrent + "/" + stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString(); TextAsset text = (TextAsset)Resources.Load(path, typeof(TextAsset)); input = text.text; } JsonUtility.FromJsonOverwrite(input, chartData); string stringMode = ""; switch (chartData.chartGameType) { case 0: stringMode = "Linear"; break; case 1: stringMode = "Double"; break; case 2: stringMode = "Quad"; break; case 3: stringMode = "Note Dodge"; break; /* * case 3: stringMode = "Powerful"; break; * case 4: stringMode = "Super"; break; * case 5: stringMode = "Ultra"; break; * case 6: stringMode = "Black Core"; break; * case 7: stringMode = "Note Dodge"; break; */ } stringMode = Translator.GetStringTranslation("SONGMENU_CHARTGAMETYPEBODY" + chartData.chartGameType, stringMode); float actualLength = chartData.songLength * 60f / chartData.songTempo; float tempoLow = chartData.songTempo; float tempoHigh = chartData.songTempo; if (chartData.listTempoChanges.Count > 0) { Vector3 lastChange = new Vector3(0f, chartData.songTempo, 0f); foreach (Vector3 x in chartData.listTempoChanges) { if (tempoHigh < x.y) { tempoHigh = x.y; } else if (tempoLow > x.y) { tempoLow = x.y; } if (lastChange.x < x.x) { lastChange = x; } } actualLength = ((chartData.songLength - lastChange.x) * 60f / lastChange.y) + lastChange.z; } // Display song details textDetailsHeader.text = chartData.songName; textDetailsBody.text = chartData.songArtist + "\n\n" + Translator.GetStringTranslation("SONGMENU_CHARTDEV", "Mapchart Producer:") + " " + chartData.chartDeveloper + "\n" + Translator.GetStringTranslation("SONGMENU_CHARTGAMETYPEBODY", "Mapchart Mode:") + " " + stringMode + "\n" + Translator.GetStringTranslation("SONGMENU_CHARTLEVEL", "Mapchart Level:") + " " + chartData.chartLevel.ToString() + "\n" + Translator.GetStringTranslation("SONGMENU_CHARTLENGTH", "Length:") + " " + Mathf.Floor(actualLength / 60f).ToString() + ":" + (actualLength % 60f).ToString("00.00") + "\n"; if (chartData.listTempoChanges.Count > 0) { textDetailsBody.text += Translator.GetStringTranslation("SONGMENU_CHARTBPM", "BPM:") + " " + chartData.songTempo.ToString("f2") + " (" + tempoLow.ToString("f2") + " - " + tempoHigh.ToString("f2") + ")\n"; } else { textDetailsBody.text += Translator.GetStringTranslation("SONGMENU_CHARTBPM", "BPM:") + " " + chartData.songTempo.ToString("f2") + "\n"; } textDetailsBody.text += Translator.GetStringTranslation("SONGMENU_CHARTJUDGELEVEL", "Judge Level:") + " " + (chartData.chartJudge + 1).ToString(); if (chartChecksum.Length > 0) { textDetailsBody.text += "\n" + Translator.GetStringTranslation("SONGMENU_CHARTCHECKSUM", "MD5 Checksum:") + " " + chartChecksum; } float floatRecordAccuracy = 0f; int intRecordPlays = 0; if (isLoadCustomSongs) { floatRecordAccuracy = PlayerPrefs.GetFloat(stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString() + "-recordaccuracy", 0f); intRecordPlays = PlayerPrefs.GetInt(stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString() + "-playcount", 0); } else { floatRecordAccuracy = PlayerPrefs.GetFloat(stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString() + "-recordaccuracy_official", 0f); intRecordPlays = PlayerPrefs.GetInt(stringSongSelectedCurrent + "-" + intGameType.ToString() + "-" + intGameChart.ToString() + "-playcount_official", 0); } textDetailsRecord.text = Translator.GetStringTranslation("SONGMENU_RECORDACCURACY", "Best Accuracy:") + " " + (100f * floatRecordAccuracy).ToString("f2") + "% | " + Translator.GetStringTranslation("SONGMENU_RECORDPLAYCOUNT", "Attempts:") + " " + intRecordPlays.ToString("n0"); textDetailsDescription.text = chartData.chartDescription; isHighscoreDisabledByChart = !chartData.isHighScoreAllowed; RefreshTexts(); /* * objectButtonPlay.transform.rotation = Quaternion.Euler(0f, 0f, -90f); * iTween.RotateTo(objectButtonPlay, iTween.Hash("rotation", Vector3.zero, "time", 0.31f, "isLocal", true, "easetype", iTween.EaseType.easeOutBack)); */ }
public void UseSongFolder(Button folder) { #if UNITY_EDITOR Debug.Log("Clicked on \"" + folder.name + "\" folder."); #endif if (!isStartup && stringSongSelectedCurrent == folder.name) { return; } isStartup = false; stringSongSelectedCurrent = folder.name; //intGameType = -1; //intGameChart = -1; // The selected folder is darkened. The rest remain at normal color. Button[] listAllButtons = FindObjectsOfType <Button>(); foreach (Button x in listAllButtons) { x.image.color = Color.white; } folder.image.color = Color.grey; // Clear all chart buttons on scene SongMenu_ButtonChart[] listOldButtons = FindObjectsOfType <SongMenu_ButtonChart>(); foreach (SongMenu_ButtonChart x in listOldButtons) { if (x.gameObject.activeSelf) { Destroy(x.gameObject); } } // Display chart information from first chart in the folder // Check for each chart in the folder SongMenu_ButtonChart firstChart = null; StreamReader reader; ChartData chartData = ScriptableObject.CreateInstance(typeof(ChartData)) as ChartData; bool gameModeExist = false; int gameModeExists = 0; bool boolResetChartPage = false; intGameChartHighest = 0; // Game mode ID for (int gameModeID = 0; gameModeID < 5; gameModeID++) { gameModeExist = false; // Chart ID for (int chartID = 0; ; chartID++) { if (intGameChartHighest < chartID) { intGameChartHighest = chartID; } string info = ""; if (isLoadCustomSongs) { string path = Directory.GetCurrentDirectory() + stringSongDirectoryPath + "/" + folder.name + "/" + folder.name + "-" + gameModeID.ToString() + "-" + chartID.ToString() + ".txt"; if (File.Exists(path)) { reader = new StreamReader(path); info = reader.ReadToEnd(); reader.Close(); } else { break; } } else { string path = "Songs/" + folder.name + "/" + folder.name + "-" + gameModeID.ToString() + "-" + chartID.ToString(); TextAsset text = (TextAsset)Resources.Load(path, typeof(TextAsset)); if (text != null) { info = text.text; } else { break; } } if (!gameModeExist) { gameModeExist = true; } // Create button from chart information if (info.Length > 0) { JsonUtility.FromJsonOverwrite(info, chartData); // Button info and positioning SongMenu_ButtonChart nb = Instantiate(buttonChartIndividual); nb.gameObject.SetActive(true); nb.transform.SetParent(rectChartListParent); nb.transform.localScale = Vector3.one; nb.transform.localPosition = (Vector3.right * ((sizePositionPerButton.x * chartID) + 4f)) + (Vector3.down * ((sizePositionPerButton.y * gameModeExists) + 2f)); nb.intGameMode = gameModeID; nb.intChart = chartID; // Button display string stringMode = ""; switch (gameModeID) { case 0: stringMode = "LN"; break; case 1: stringMode = "DB"; break; case 2: stringMode = "QD"; break; case 3: stringMode = "ND"; break; /* * case 3: stringMode = "PWF"; break; * case 4: stringMode = "SP"; break; * case 5: stringMode = "ULT"; break; * case 6: stringMode = "BC"; break; * case 7: stringMode = "ND"; break; */ } nb.textButton.text = stringMode + " " + (chartID + 1).ToString() + " - *" + chartData.chartLevel.ToString(); // If it is the first chart found, it will be selected first if (firstChart == null) { boolResetChartPage = true; firstChart = nb; } // If it was previously selected before, select this again if (intGameType >= 0 && intGameType == gameModeID && intGameChart >= 0 && intGameChart == chartID) { boolResetChartPage = false; firstChart = nb; } } } if (gameModeExist) { gameModeExists++; } } // Set maximum chart list scroll page intChartListPageMaximum = (intGameChartHighest - 3) / 2; if (intChartListPageMaximum < 0) { intChartListPageMaximum = 0; } foreach (Button x in arrayButtonChartListScroll) { x.interactable = intChartListPageMaximum > 0; } if (boolResetChartPage) { intGameType = -1; intGameChart = -1; intChartListPage = 0; rectChartListParent.transform.localPosition = Vector3.zero; } // Stop the song preview StopCoroutine("LoadClip"); audioSourcePreview.Stop(); // Automatically select the first chart in the list if (firstChart != null) { scrollViewChartList.gameObject.SetActive(true); foreach (Button x in arrayButtonChartListScroll) { x.gameObject.SetActive(true); } UseChartInfo(firstChart); // Load the song file (.ogg) in the folder StartCoroutine("LoadClip", folder.name); // Get background texture Texture textureBackground = null; if (isLoadCustomSongs) { string path = "/Songs/" + folder.name + "/background.jpg"; if (!File.Exists(Directory.GetCurrentDirectory() + path)) { #if UNITY_EDITOR Debug.LogWarning("WARNING: The image file does not exist! Path: " + path); #endif } else { WWW www = new WWW("file://" + Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + path); //textureBackground = www.texture; //www.LoadImageIntoTexture(textureBackground); textureBackground = www.textureNonReadable; } } else { string path = "Songs/" + folder.name + "/" + "background"; textureBackground = Resources.Load(path) as Texture; } if (textureBackground != null) { rawImageDetailsBackground.gameObject.SetActive(true); rawImageDetailsBackground.texture = textureBackground; } else { rawImageDetailsBackground.gameObject.SetActive(false); } // Play button enable and animate objectButtonPlay.SetActive(true); objectButtonPlay.GetComponent <Animator>().Play("clip"); } else { objectButtonPlay.SetActive(false); foreach (Button x in arrayButtonChartListScroll) { x.gameObject.SetActive(false); } rawImageDetailsBackground.gameObject.SetActive(false); scrollViewChartList.gameObject.SetActive(false); textDetailsHeader.text = ""; textDetailsBody.text = Translator.GetStringTranslation("SONGMENU_CHARTNONEXISTS", "There are no map charts in\n" + "this song folder's contents.\n" + "\n" + "Please make sure your map\n" + "chart files are named in the\n" + "correct format."); textDetailsDescription.text = ""; textDetailsRecord.text = ""; } // iTween song window tween effect float tweenDuration = 0.31f; objectGroupDetails.SetActive(true); objectGroupDetails.transform.position = positionGroupDetailsInit + Vector3.right * 1000f; iTween.MoveTo(objectGroupDetails, positionGroupDetailsInit, tweenDuration); /* * Text[] tGrpDts = objectGroupDetails.GetComponentsInChildren<Text>(); * foreach (Text x in tGrpDts) * { * x.color = new Color(1f, 1f, 1f, 0f); * iTween.ColorTo(x.gameObject, Color.white, tweenDuration); * } * Image[] iGrpDts = objectGroupDetails.GetComponentsInChildren<Image>(); * foreach (Image x in iGrpDts) * { * x.color = new Color(1f, 1f, 1f, 0f); * iTween.ColorTo(x.gameObject, Color.white, tweenDuration); * } */ }