天梯排行榜
This commit is contained in:
8
Assets/TcgEngine/Scripts/Data/RankData.meta
Normal file
8
Assets/TcgEngine/Scripts/Data/RankData.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab8fe0fffad3cfe4e95eb8d36a35cb84
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/TcgEngine/Scripts/Data/RankData/LadderConfig.cs
Normal file
28
Assets/TcgEngine/Scripts/Data/RankData/LadderConfig.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace TcgEngine
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LadderConfig
|
||||
{
|
||||
public int Id;
|
||||
public int Rank;
|
||||
public string RankName;
|
||||
public int Level;
|
||||
public int BeginStar;
|
||||
public int RankDownStar;
|
||||
public int MaxStar;
|
||||
public int WinGetStar;
|
||||
public int ExtraGetStar;
|
||||
public int LoseLostStar;
|
||||
public int LoseRankDown;
|
||||
public int RankScore;
|
||||
public int AITimes;
|
||||
public string AIDeck;
|
||||
public int WaitTime;
|
||||
public int MaxWaitTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65340b3a4e424aa5ad2989c210751a8a
|
||||
timeCreated: 1756705296
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TcgEngine
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LadderLeaderboardEntry
|
||||
{
|
||||
public string playerId; // id
|
||||
public string username; // 用户名
|
||||
public string avatar; // 头像
|
||||
public int rankId; // 天梯ID
|
||||
public int rankScore; // 王者分数
|
||||
public int stars; // 星星数
|
||||
public int totalWins; // 总胜利次数
|
||||
public int position; // 排名位置
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f6cf4bfc3415c143a6c68a31e893373
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TcgEngine
|
||||
{
|
||||
[System.Serializable]
|
||||
public class LadderPositionResponse
|
||||
{
|
||||
// 玩家在排行榜中的位置,未上榜为null
|
||||
public int? position;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90797bc114f5d254cb94bda0d32215dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/TcgEngine/Scripts/Data/RankData/PlayerLadderInfo.cs
Normal file
21
Assets/TcgEngine/Scripts/Data/RankData/PlayerLadderInfo.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TcgEngine
|
||||
{
|
||||
[System.Serializable]
|
||||
public class PlayerLadderInfo
|
||||
{
|
||||
public string playerName; // 天梯ID名称
|
||||
public string rankName; // 天梯等级
|
||||
public int level; // 天梯等级
|
||||
public bool isRankScore; // 是否王者匹配机制
|
||||
|
||||
public int score; // 王者机制
|
||||
|
||||
//星星
|
||||
public int stars;
|
||||
public int maxStars;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d4193b02a88bd94ba19e7ef6b4d1078
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
108
Assets/TcgEngine/Scripts/Menu/LadderRankLine.cs
Normal file
108
Assets/TcgEngine/Scripts/Menu/LadderRankLine.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TcgEngine.UI
|
||||
{
|
||||
public class LadderRankLine : MonoBehaviour
|
||||
{
|
||||
[Header("排名")] public Text ranking;
|
||||
|
||||
[Header("玩家名称")] public Text playerName;
|
||||
|
||||
[Header("头像")] public Image avatar;
|
||||
|
||||
[Header("天梯ID")] public Text rankId; // 天梯ID
|
||||
|
||||
[Header("天梯分数")] public Text rankScore;
|
||||
|
||||
[Header("天梯星星")] public Text stars;
|
||||
|
||||
// [Header("胜利场次")]
|
||||
// public Text totalWins;
|
||||
[Header("下划线")] public Image highlight;
|
||||
|
||||
[Header("查看牌组")] public Button viewCardButton;
|
||||
|
||||
public UnityAction<string> onClick;
|
||||
|
||||
public string username;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
highlight.enabled = false;
|
||||
}
|
||||
|
||||
public void SetLine(LadderLeaderboardEntry udata, int ranking, Sprite avatar,
|
||||
int rankId, int rankScore, int stars, bool highlight)
|
||||
{
|
||||
this.username = udata.username;
|
||||
this.ranking.text = ranking.ToString();
|
||||
this.playerName.text = username;
|
||||
this.rankId.text = rankId.ToString();
|
||||
this.rankScore.text = rankScore.ToString();
|
||||
this.stars.text = "星×" + stars;
|
||||
|
||||
this.avatar.sprite = avatar;
|
||||
|
||||
switch (rankId)
|
||||
{
|
||||
case 1:
|
||||
this.rankId.text = "青铜";
|
||||
break;
|
||||
case 2:
|
||||
this.rankId.text = "白银";
|
||||
break;
|
||||
case 3:
|
||||
this.rankId.text = "黄金";
|
||||
break;
|
||||
case 4:
|
||||
this.rankId.text = "铂金";
|
||||
break;
|
||||
case 5:
|
||||
this.rankId.text = "钻石";
|
||||
break;
|
||||
case 6:
|
||||
this.rankId.text = "王者";
|
||||
break;
|
||||
default:
|
||||
this.rankId.text = "青铜";
|
||||
break;
|
||||
}
|
||||
|
||||
if (rankScore == 0)
|
||||
{
|
||||
this.rankScore.gameObject.SetActive(true);
|
||||
this.stars.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rankScore.gameObject.SetActive(false);
|
||||
this.stars.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.highlight.enabled = highlight;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public string GetUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
onClick?.Invoke(username);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/TcgEngine/Scripts/Menu/LadderRankLine.cs.meta
Normal file
11
Assets/TcgEngine/Scripts/Menu/LadderRankLine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18b7f03bddb592d4db526b58ea061daf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -11,16 +11,41 @@ namespace TcgEngine.UI
|
||||
|
||||
public class LeaderboardPanel : UIPanel
|
||||
{
|
||||
#region 默认排行榜
|
||||
public RectTransform content;
|
||||
public RankLine line_template;
|
||||
public RankLine my_line;
|
||||
public float line_spacing = 80f;
|
||||
#endregion
|
||||
|
||||
#region 天梯排行榜
|
||||
|
||||
public RectTransform ladderContent;
|
||||
public LadderRankLine ladderLine_template;
|
||||
public LadderRankLine my_ladderLine;
|
||||
public float ladderLine_spacing = 120f;
|
||||
|
||||
#endregion
|
||||
|
||||
public Text test_text;
|
||||
|
||||
private List<RankLine> lines = new List<RankLine>();
|
||||
public bool isLadderRank = true;
|
||||
public UIPanel defaultRank;
|
||||
public UIPanel ladderRank;
|
||||
|
||||
public List<RankLine> lines = new List<RankLine>();
|
||||
public List<LadderRankLine> ladderLines = new List<LadderRankLine>();
|
||||
|
||||
private static LeaderboardPanel instance;
|
||||
|
||||
#region 临时方法
|
||||
|
||||
[SerializeField] private Button defaultRankButton;
|
||||
[SerializeField] private Button ladderRankButton;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -29,6 +54,23 @@ namespace TcgEngine.UI
|
||||
|
||||
my_line.onClick += OnClickLine;
|
||||
InitLines();
|
||||
|
||||
#region 临时方法
|
||||
|
||||
defaultRankButton.onClick.AddListener(() =>
|
||||
{
|
||||
isLadderRank = false;
|
||||
RankPanelColl();
|
||||
});
|
||||
ladderRankButton.onClick.AddListener(() =>
|
||||
{
|
||||
isLadderRank = true;
|
||||
RankPanelColl();
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -38,6 +80,8 @@ namespace TcgEngine.UI
|
||||
|
||||
private void InitLines()
|
||||
{
|
||||
#region 加载默认排行榜
|
||||
|
||||
for (int i = 0; i < content.transform.childCount; i++)
|
||||
Destroy(content.transform.GetChild(i).gameObject);
|
||||
|
||||
@@ -49,6 +93,24 @@ namespace TcgEngine.UI
|
||||
}
|
||||
|
||||
content.sizeDelta = new Vector2(content.sizeDelta.x, nlines * line_spacing + 20f);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 加载天梯排行榜
|
||||
|
||||
for (int i = 0; i < ladderContent.transform.childCount; i++)
|
||||
Destroy(ladderContent.transform.GetChild(i).gameObject);
|
||||
|
||||
int ladderNlines = 100;
|
||||
for (int i = 0; i < ladderNlines; i++)
|
||||
{
|
||||
LadderRankLine line = LadderAddLine(ladderLine_template, i);
|
||||
ladderLines.Add(line);
|
||||
}
|
||||
|
||||
ladderContent.sizeDelta = new Vector2(content.sizeDelta.x, ladderNlines * line_spacing + 20f);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private RankLine AddLine(RankLine template, int index)
|
||||
@@ -64,6 +126,19 @@ namespace TcgEngine.UI
|
||||
return rline;
|
||||
}
|
||||
|
||||
private LadderRankLine LadderAddLine(LadderRankLine template, int index)
|
||||
{
|
||||
Vector2 pos = Vector2.down * ladderLine_spacing;
|
||||
GameObject line = Instantiate(template.gameObject, ladderContent);
|
||||
RectTransform rtrans = line.GetComponent<RectTransform>();
|
||||
LadderRankLine lrline = line.GetComponent<LadderRankLine>();
|
||||
rtrans.anchorMin = new Vector2(0.5f, 1);
|
||||
rtrans.anchorMax = new Vector2(0.5f, 1f);
|
||||
rtrans.anchoredPosition = pos + Vector2.down * index * ladderLine_spacing;
|
||||
lrline.onClick += OnClickLine;
|
||||
return lrline;
|
||||
}
|
||||
|
||||
private async void RefreshPanel()
|
||||
{
|
||||
my_line.Hide();
|
||||
@@ -109,6 +184,99 @@ namespace TcgEngine.UI
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async void RefreshLadderPanel()
|
||||
{
|
||||
my_line.Hide();
|
||||
foreach (LadderRankLine line in ladderLines)
|
||||
line.Hide();
|
||||
|
||||
test_text.enabled = !Authenticator.Get().IsApi();
|
||||
|
||||
if (!Authenticator.Get().IsApi())
|
||||
return;
|
||||
|
||||
UserData udata = ApiClient.Get().UserData;
|
||||
|
||||
int index = 0;
|
||||
string url = ApiClient.ServerURL + "/ladder/leaderboard";
|
||||
WebResponse res = await ApiClient.Get().SendGetRequest(url);
|
||||
|
||||
LadderLeaderboardEntry[] users = ApiTool.JsonToArray<LadderLeaderboardEntry>(res.data);
|
||||
List<LadderLeaderboardEntry> sorted_users = new List<LadderLeaderboardEntry>(users);
|
||||
sorted_users.Sort((a, b) =>
|
||||
{
|
||||
return a.position.CompareTo(b.position);
|
||||
});
|
||||
|
||||
int previous_rank = 0;
|
||||
int previous_index = 0;
|
||||
|
||||
|
||||
if (users == null || users.Length == 0)
|
||||
{
|
||||
Debug.LogError("玩家数据为空");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"收到排行榜数据,共 {users.Length} 条");
|
||||
|
||||
foreach (LadderLeaderboardEntry rankData in sorted_users)
|
||||
{
|
||||
if (rankData.username == udata.username)
|
||||
{
|
||||
my_ladderLine.SetLine(rankData, index + 1, null, rankData.rankId,
|
||||
rankData.rankScore, rankData.stars, true);
|
||||
}
|
||||
|
||||
if (index < ladderLines.Count)
|
||||
{
|
||||
LadderRankLine line = ladderLines[index];
|
||||
int rank_order = (previous_rank == rankData.position) ? previous_index : index;
|
||||
line.SetLine(rankData, rank_order + 1,null, rankData.rankId,
|
||||
rankData.rankScore, rankData.stars, true);
|
||||
previous_rank = rankData.position;
|
||||
previous_index = rank_order;
|
||||
}
|
||||
index++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RankPanelColl()
|
||||
{
|
||||
if (isLadderRank)
|
||||
{
|
||||
ladderRank.Show();
|
||||
var lColor = ladderRankButton.image.color;
|
||||
lColor.a = 0.5f;
|
||||
ladderRankButton.image.color = lColor;
|
||||
|
||||
|
||||
defaultRank.Hide();
|
||||
var dColor = defaultRankButton.image.color;
|
||||
dColor.a = 1f;
|
||||
defaultRankButton.image.color = dColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
ladderRank.Hide();
|
||||
var lColor = ladderRankButton.image.color;
|
||||
lColor.a = 1f;
|
||||
ladderRankButton.image.color = lColor;
|
||||
|
||||
defaultRank.Show();
|
||||
var dColor = defaultRankButton.image.color;
|
||||
dColor.a = 0.5f;
|
||||
defaultRankButton.image.color = dColor;
|
||||
|
||||
}
|
||||
ladderRankButton.enabled = !isLadderRank;
|
||||
defaultRankButton.enabled = isLadderRank;
|
||||
}
|
||||
|
||||
private void OnClickLine(string username)
|
||||
@@ -120,6 +288,8 @@ namespace TcgEngine.UI
|
||||
{
|
||||
base.Show(instant);
|
||||
RefreshPanel();
|
||||
RefreshLadderPanel();
|
||||
RankPanelColl();
|
||||
}
|
||||
|
||||
public void OnClickBack()
|
||||
|
||||
Reference in New Issue
Block a user