Added scrollview and sorting by high score in scoreboard

Also fixed bug in PoolCreatorInspector in Split function
This commit is contained in:
Vladimir Pirozhenko 2022-08-26 18:19:56 +04:00
parent 35f724fcc1
commit 49de54745e
3 changed files with 1073 additions and 227 deletions

File diff suppressed because it is too large Load Diff

View File

@ -157,7 +157,7 @@ public class PoolCreatorInspector : Editor
{ {
if (inputFilePath.StartsWith(separator, StringComparison.OrdinalIgnoreCase) == false && inputFilePath.Contains(separator)) if (inputFilePath.StartsWith(separator, StringComparison.OrdinalIgnoreCase) == false && inputFilePath.Contains(separator))
{ {
return inputFilePath.Split(separator).Last(); return inputFilePath.Split(separator.ToCharArray()).Last();
} }
return inputFilePath; return inputFilePath;
} }

View File

@ -2,22 +2,24 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class ScoreboardEntriesTable
{
public ScoreboardEntriesTable(List<ScoreboardEntry> entries)
{
this.entries = entries;
}
public List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
}
public class Scoreboard : MonoBehaviour, ICommandTranslator public class Scoreboard : MonoBehaviour, ICommandTranslator
{ {
[SerializeField] private int maxEntries;
private List<ScoreboardEntry> entries = new List<ScoreboardEntry>(); private List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
public event Action<ScoreboardEntry> OnEntryAdded; public event Action<ScoreboardEntry> OnEntryAdded;
[SerializeField] private ScoreboardView scoreboardView; [SerializeField] private ScoreboardView scoreboardView;
private class ScoreboardEntriesTable
{
public ScoreboardEntriesTable(List<ScoreboardEntry> entries)
{
this.entries = entries;
}
public List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
}
private void Start() private void Start()
{ {
GameSession.Instance.AddCommandTranslator(this); GameSession.Instance.AddCommandTranslator(this);
@ -28,30 +30,40 @@ public class Scoreboard : MonoBehaviour, ICommandTranslator
if (entriesTable.entries == null) if (entriesTable.entries == null)
return; return;
List<PlayerScoreboardCardData> scoreboardCardDatas = new List<PlayerScoreboardCardData>(); List<PlayerScoreboardCardData> scoreboardCardDatas = new List<PlayerScoreboardCardData>();
for (int i = 0; i < entriesTable.entries.Count; i++) for (int i = 0; i <entriesTable.entries.Count; i++)
{ {
entries.Add(entriesTable.entries[i]); entries.Add(entriesTable.entries[i]);
OnEntryAdded?.Invoke(entriesTable.entries[i]); OnEntryAdded?.Invoke(entriesTable.entries[i]);
PlayerScoreboardCardData cardData = new PlayerScoreboardCardData(entriesTable.entries[i].Name, entriesTable.entries[i].Score.ToString()); PlayerScoreboardCardData cardData = new PlayerScoreboardCardData(entriesTable.entries[i].Name, entriesTable.entries[i].Score.ToString());
scoreboardCardDatas.Add(cardData); scoreboardCardDatas.Add(cardData);
} }
SortScoreboardByHighscore();
scoreboardView.AddPlayerCards(scoreboardCardDatas); scoreboardView.AddPlayerCards(scoreboardCardDatas);
} }
public void AddScoreboardEntry(string entryName, int entryScore) public void AddScoreboardEntry(string entryName, int entryScore)
{ {
ScoreboardEntry entry = new ScoreboardEntry(entryName, entryScore); ScoreboardEntry entry = new ScoreboardEntry(entryName, entryScore);
entries.Add(entry); entries.Add(entry);
OnEntryAdded?.Invoke(entry); OnEntryAdded?.Invoke(entry);
} }
public void SortScoreboardByHighscore()
{
entries.Sort((x,y) => y.Score.CompareTo(x.Score));
}
public void AddScoreboardEntry(ScoreboardEntry entry) public void AddScoreboardEntry(ScoreboardEntry entry)
{ {
entries.Add(entry); entries.Add(entry);
OnEntryAdded?.Invoke(entry); OnEntryAdded?.Invoke(entry);
SaveScoreboardEntriesTable(); SaveScoreboardEntriesTable();
Debug.Log("SAVED");
} }
public void SaveScoreboardEntriesTable() public void SaveScoreboardEntriesTable()
{ {
SortScoreboardByHighscore();
ScoreboardEntriesTable scoreboardEntriesTable = new ScoreboardEntriesTable(entries); ScoreboardEntriesTable scoreboardEntriesTable = new ScoreboardEntriesTable(entries);
string jsonScoreboardEntries = JsonUtility.ToJson(scoreboardEntriesTable); string jsonScoreboardEntries = JsonUtility.ToJson(scoreboardEntriesTable);
PlayerPrefs.SetString("ScoreboardEntriesTableTest", jsonScoreboardEntries); PlayerPrefs.SetString("ScoreboardEntriesTableTest", jsonScoreboardEntries);