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,15 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class ScoreboardEntriesTable
public class Scoreboard : MonoBehaviour, ICommandTranslator
{
private List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
public event Action<ScoreboardEntry> OnEntryAdded;
[SerializeField] private ScoreboardView scoreboardView;
private class ScoreboardEntriesTable
{ {
public ScoreboardEntriesTable(List<ScoreboardEntry> entries) public ScoreboardEntriesTable(List<ScoreboardEntry> entries)
{ {
@ -18,6 +10,16 @@ public class Scoreboard : MonoBehaviour, ICommandTranslator
} }
public List<ScoreboardEntry> entries = new List<ScoreboardEntry>(); public List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
} }
public class Scoreboard : MonoBehaviour, ICommandTranslator
{
[SerializeField] private int maxEntries;
private List<ScoreboardEntry> entries = new List<ScoreboardEntry>();
public event Action<ScoreboardEntry> OnEntryAdded;
[SerializeField] private ScoreboardView scoreboardView;
private void Start() private void Start()
{ {
GameSession.Instance.AddCommandTranslator(this); GameSession.Instance.AddCommandTranslator(this);
@ -35,23 +37,33 @@ public class Scoreboard : MonoBehaviour, ICommandTranslator
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);