UI update 02
This commit is contained in:
@@ -5,9 +5,14 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GameServer.Client;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SongDetailsUI : MonoBehaviour
|
||||
{
|
||||
private const string BackSceneName = "selectYourSongFirst";
|
||||
|
||||
[Header("this_song_SO")]
|
||||
public ScriptableObject this_song_SO;
|
||||
|
||||
@@ -60,6 +65,9 @@ public class SongDetailsUI : MonoBehaviour
|
||||
public Image profound_image;
|
||||
public Text detail_informations_text;
|
||||
|
||||
[Header("back to last scene")]
|
||||
[SerializeField] private Button backtoLastScene;
|
||||
|
||||
[Header("Inspector")]
|
||||
public Button Button_EZ;
|
||||
public Button Button_HD;
|
||||
@@ -69,9 +77,21 @@ public class SongDetailsUI : MonoBehaviour
|
||||
private SongData currentSong;
|
||||
private GameObject spawnedAskInstance;
|
||||
private GameObject spawnedRoomDetailsInstance;
|
||||
private SongData lastSyncedSong;
|
||||
private int lastSyncedDifficultyId = int.MinValue;
|
||||
private UnityAction difficultyEzAction;
|
||||
private UnityAction difficultyHdAction;
|
||||
private UnityAction difficultyInAction;
|
||||
private UnityAction difficultyImAction;
|
||||
|
||||
private SongData ResolveCurrentSong()
|
||||
{
|
||||
if (SongDataHolder.SelectedSongData != null)
|
||||
{
|
||||
currentSong = SongDataHolder.SelectedSongData;
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
if (currentSong != null)
|
||||
{
|
||||
return currentSong;
|
||||
@@ -83,12 +103,6 @@ public class SongDetailsUI : MonoBehaviour
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
if (SongDataHolder.SelectedSongData != null)
|
||||
{
|
||||
currentSong = SongDataHolder.SelectedSongData;
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -120,6 +134,21 @@ public class SongDetailsUI : MonoBehaviour
|
||||
roomButton.onClick.RemoveListener(OnRoomButtonClicked);
|
||||
roomButton.onClick.AddListener(OnRoomButtonClicked);
|
||||
}
|
||||
|
||||
if (backtoLastScene != null)
|
||||
{
|
||||
backtoLastScene.onClick.RemoveListener(OnBackToLastSceneClicked);
|
||||
backtoLastScene.onClick.AddListener(OnBackToLastSceneClicked);
|
||||
}
|
||||
|
||||
BindDifficultyButtons();
|
||||
PrepareDifficultyButtons();
|
||||
SyncSongDisplay(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
SyncSongDisplay(false);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -139,6 +168,13 @@ public class SongDetailsUI : MonoBehaviour
|
||||
{
|
||||
roomButton.onClick.RemoveListener(OnRoomButtonClicked);
|
||||
}
|
||||
|
||||
if (backtoLastScene != null)
|
||||
{
|
||||
backtoLastScene.onClick.RemoveListener(OnBackToLastSceneClicked);
|
||||
}
|
||||
|
||||
UnbindDifficultyButtons();
|
||||
}
|
||||
|
||||
private void HandleArenaRoomSnapshotChanged(ArenaRoomSnapshot snapshot)
|
||||
@@ -193,9 +229,55 @@ public class SongDetailsUI : MonoBehaviour
|
||||
SongDataHolder.SelectedSongData = song;
|
||||
id_of_thisSong = song.songID;
|
||||
|
||||
RefreshSongPresentation(song);
|
||||
SetDifficultyButtons(difficultyId);
|
||||
UpdateDifficultyUI(difficultyId);
|
||||
SyncSongDisplay(true);
|
||||
}
|
||||
|
||||
private void SyncSongDisplay(bool force)
|
||||
{
|
||||
SongData song = ResolveCurrentSong();
|
||||
if (song == null)
|
||||
{
|
||||
if (force || lastSyncedSong != null)
|
||||
{
|
||||
SetDifficultyButtons(-1);
|
||||
if (difficultyText != null) difficultyText.text = string.Empty;
|
||||
if (difficultyDesciptionText != null) difficultyDesciptionText.text = string.Empty;
|
||||
if (difficultyIdText != null) difficultyIdText.text = string.Empty;
|
||||
if (personalRecordText != null) personalRecordText.text = "0";
|
||||
if (idolRecordText != null) idolRecordText.text = "0";
|
||||
if (chartScoreText != null) chartScoreText.text = "0";
|
||||
if (thisSong_lastScoreText != null) thisSong_lastScoreText.text = "0";
|
||||
if (rankLevel_img != null && rc != null) rankLevel_img.sprite = rc.defaultSprite;
|
||||
if (progressImage != null) progressImage.fillAmount = 0f;
|
||||
UpdateProgressUI(0f);
|
||||
}
|
||||
|
||||
lastSyncedSong = null;
|
||||
lastSyncedDifficultyId = int.MinValue;
|
||||
return;
|
||||
}
|
||||
|
||||
currentSong = song;
|
||||
this_song_SO = song;
|
||||
id_of_thisSong = song.songID;
|
||||
|
||||
int selectedDifficulty = Mathf.Clamp(song.thisLevel_selectedDifficultyID, 0, 3);
|
||||
bool songChanged = lastSyncedSong != song;
|
||||
bool difficultyChanged = lastSyncedDifficultyId != selectedDifficulty;
|
||||
|
||||
if (force || songChanged)
|
||||
{
|
||||
RefreshSongPresentation(song);
|
||||
}
|
||||
|
||||
if (force || songChanged || difficultyChanged)
|
||||
{
|
||||
SetDifficultyButtons(selectedDifficulty);
|
||||
UpdateDifficultyUI(selectedDifficulty);
|
||||
}
|
||||
|
||||
lastSyncedSong = song;
|
||||
lastSyncedDifficultyId = selectedDifficulty;
|
||||
}
|
||||
|
||||
private void RefreshSongPresentation(SongData song)
|
||||
@@ -246,59 +328,10 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (SongDataHolder.SelectedSongData != null)
|
||||
{
|
||||
// Documentation text normalized.
|
||||
currentSong = SongDataHolder.SelectedSongData;
|
||||
this_song_SO = currentSong;
|
||||
|
||||
song_bgImage.sprite = currentSong.GetResolvedBackgroundPic();
|
||||
// Documentation text normalized.
|
||||
songNameText.text = currentSong.songName;
|
||||
artistNameText.text = currentSong.artistName;
|
||||
painterNameText.text = currentSong.painter;
|
||||
charterNameText.text = currentSong.level_creator;
|
||||
dlcNameText.text = currentSong.belongsTo_whichDLC;
|
||||
songSerialNumberText.text = currentSong.songID.ToString();
|
||||
|
||||
bpmText.text = LocalizationService.GetFormat("song.details.bpm", currentSong.bpm);
|
||||
profound_image.sprite = currentSong.GetResolvedFullscreenSongPicture();
|
||||
|
||||
if (timeSpentText != null) timeSpentText.text = LocalizationService.GetFormat("song.details.play_time", currentSong.time_totalPlayingTime.ToString("F0"));
|
||||
if (enterTimeText != null) enterTimeText.text = LocalizationService.GetFormat("song.details.play_count", currentSong.game_enterTimes);
|
||||
|
||||
id_of_thisSong = currentSong.songID;
|
||||
detail_informations_text.text = LocalizationService.GetFormat("song.details.information",
|
||||
currentSong.artistName, currentSong.songName, currentSong.painter, currentSong.level_creator, currentSong.belongsTo_whichDLC);
|
||||
if (currentSong.GetResolvedIllustration() != null)
|
||||
{
|
||||
//songImage.sprite = currentSong.illustration;
|
||||
//songImage.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(LocalizationService.GetFormat("song.details.no_song_cover", currentSong.songName));
|
||||
}
|
||||
|
||||
Debug.Log("加载歌曲数据: " + currentSong.songName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Documentation text normalized.
|
||||
}
|
||||
|
||||
picDetail.SetActive(false);
|
||||
|
||||
// Documentation text normalized.
|
||||
if (currentSong != null)
|
||||
{
|
||||
SetDifficultyButtons(currentSong.thisLevel_selectedDifficultyID);
|
||||
UpdateDifficultyUI(currentSong.thisLevel_selectedDifficultyID);
|
||||
Button_EZ.onClick.AddListener(() => OnDifficultySelected(0));
|
||||
Button_HD.onClick.AddListener(() => OnDifficultySelected(1));
|
||||
Button_IN.onClick.AddListener(() => OnDifficultySelected(2));
|
||||
Button_IM.onClick.AddListener(() => OnDifficultySelected(3));
|
||||
}
|
||||
BindDifficultyButtons();
|
||||
PrepareDifficultyButtons();
|
||||
SyncSongDisplay(true);
|
||||
}
|
||||
|
||||
public void OnRankingButtonClicked()
|
||||
@@ -319,6 +352,14 @@ public class SongDetailsUI : MonoBehaviour
|
||||
rkl.Open(song.songID.ToString(), song.songName);
|
||||
}
|
||||
|
||||
public void OnBackToLastSceneClicked()
|
||||
{
|
||||
if (!Bansonic.gTransition.LoadScene(BackSceneName, LoadSceneMode.Single))
|
||||
{
|
||||
SceneManager.LoadScene(BackSceneName, LoadSceneMode.Single);
|
||||
}
|
||||
}
|
||||
|
||||
public async void OnRoomButtonClicked()
|
||||
{
|
||||
SongData song = ResolveCurrentSong();
|
||||
@@ -605,10 +646,87 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
private void SetDifficultyButtons(int selectedDifficulty)
|
||||
{
|
||||
Button_EZ.image.color = new Color(1, 1, 1, selectedDifficulty == 0 ? 1 : 0);
|
||||
Button_HD.image.color = new Color(1, 1, 1, selectedDifficulty == 1 ? 1 : 0);
|
||||
Button_IN.image.color = new Color(1, 1, 1, selectedDifficulty == 2 ? 1 : 0);
|
||||
Button_IM.image.color = new Color(1, 1, 1, selectedDifficulty == 3 ? 1 : 0);
|
||||
SetDifficultyButtonAlpha(Button_EZ, selectedDifficulty == 0);
|
||||
SetDifficultyButtonAlpha(Button_HD, selectedDifficulty == 1);
|
||||
SetDifficultyButtonAlpha(Button_IN, selectedDifficulty == 2);
|
||||
SetDifficultyButtonAlpha(Button_IM, selectedDifficulty == 3);
|
||||
}
|
||||
|
||||
private void BindDifficultyButtons()
|
||||
{
|
||||
BindDifficultyButton(Button_EZ, 0, ref difficultyEzAction);
|
||||
BindDifficultyButton(Button_HD, 1, ref difficultyHdAction);
|
||||
BindDifficultyButton(Button_IN, 2, ref difficultyInAction);
|
||||
BindDifficultyButton(Button_IM, 3, ref difficultyImAction);
|
||||
}
|
||||
|
||||
private void UnbindDifficultyButtons()
|
||||
{
|
||||
UnbindDifficultyButton(Button_EZ, difficultyEzAction);
|
||||
UnbindDifficultyButton(Button_HD, difficultyHdAction);
|
||||
UnbindDifficultyButton(Button_IN, difficultyInAction);
|
||||
UnbindDifficultyButton(Button_IM, difficultyImAction);
|
||||
}
|
||||
|
||||
private void BindDifficultyButton(Button button, int difficultyId, ref UnityAction cachedAction)
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cachedAction != null)
|
||||
{
|
||||
button.onClick.RemoveListener(cachedAction);
|
||||
}
|
||||
|
||||
cachedAction = () => OnDifficultySelected(difficultyId);
|
||||
button.onClick.AddListener(cachedAction);
|
||||
}
|
||||
|
||||
private void UnbindDifficultyButton(Button button, UnityAction cachedAction)
|
||||
{
|
||||
if (button == null || cachedAction == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
button.onClick.RemoveListener(cachedAction);
|
||||
}
|
||||
|
||||
private void PrepareDifficultyButtons()
|
||||
{
|
||||
ForceDifficultyButtonVisualMode(Button_EZ);
|
||||
ForceDifficultyButtonVisualMode(Button_HD);
|
||||
ForceDifficultyButtonVisualMode(Button_IN);
|
||||
ForceDifficultyButtonVisualMode(Button_IM);
|
||||
}
|
||||
|
||||
private void ForceDifficultyButtonVisualMode(Button button)
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
button.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
private void SetDifficultyButtonAlpha(Button button, bool active)
|
||||
{
|
||||
if (button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Graphic graphic = button.targetGraphic != null ? button.targetGraphic : button.image;
|
||||
if (graphic == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
graphic.DOKill(false);
|
||||
graphic.DOFade(active ? 1f : 0f, 0.18f).SetEase(Ease.OutCubic);
|
||||
}
|
||||
|
||||
private void OnDifficultySelected(int difficulty)
|
||||
@@ -623,14 +741,21 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
private void UpdateDifficultyUI(int difficulty)
|
||||
{
|
||||
if (currentSong == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var entry = GetChartEntry(difficulty);
|
||||
if (entry != null)
|
||||
{
|
||||
difficultyText.text = entry.difficultyLEVEL.ToString();
|
||||
difficultyDesciptionText.text = entry.difficultyDescription;
|
||||
if (difficultyText != null)
|
||||
difficultyText.text = entry.difficultyLEVEL.ToString("0.0");
|
||||
if (difficultyDesciptionText != null)
|
||||
difficultyDesciptionText.text = string.IsNullOrEmpty(entry.difficultyDescription) ? entry.difficultyName : entry.difficultyDescription;
|
||||
|
||||
if (difficultyIdText != null)
|
||||
difficultyIdText.text = entry.difficultyLEVEL.ToString();
|
||||
difficultyIdText.text = entry.difficultyLEVEL.ToString("0.0");
|
||||
|
||||
if (progressImage != null)
|
||||
progressImage.fillAmount = entry.levelProgressForThisDifficulty;
|
||||
@@ -678,14 +803,17 @@ public class SongDetailsUI : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
difficultyText.text = difficulty.ToString();
|
||||
if (difficultyText != null)
|
||||
difficultyText.text = difficulty.ToString();
|
||||
if (difficultyIdText != null)
|
||||
difficultyIdText.text = difficulty.ToString();
|
||||
if (progressImage != null)
|
||||
progressImage.fillAmount = 0f;
|
||||
UpdateProgressUI(0f);
|
||||
difficultyDesciptionText.text = "";
|
||||
personalRecordText.text = "0";
|
||||
if (difficultyDesciptionText != null)
|
||||
difficultyDesciptionText.text = "";
|
||||
if (personalRecordText != null)
|
||||
personalRecordText.text = "0";
|
||||
if (idolRecordText != null)
|
||||
idolRecordText.text = "0";
|
||||
if (chartScoreText != null)
|
||||
@@ -730,9 +858,14 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
private ChartFileEntry GetChartEntry(int difficulty)
|
||||
{
|
||||
if (currentSong == null || currentSong.chartFiles == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var entry in currentSong.chartFiles)
|
||||
{
|
||||
if (entry.difficulty == difficulty)
|
||||
if (entry != null && entry.difficulty == difficulty)
|
||||
return entry;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user