112 lines
5.3 KiB
C#
112 lines
5.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TKS.OutGame
|
|
{
|
|
/// <summary>순위 표 한 줄(화면 표시용).</summary>
|
|
public class RankRow
|
|
{
|
|
public int rank;
|
|
public string name = "";
|
|
public long score;
|
|
/// <summary>내 줄인가.</summary>
|
|
public bool me;
|
|
}
|
|
|
|
/// <summary>순위 표 — 위에서부터 서버가 정한 수만큼 + 내 순위. 서버가 내려 준 값을 세션(Net/ServerSession)이 이 모양으로 바꿔 준다.</summary>
|
|
public class RankBoard
|
|
{
|
|
/// <summary>판 종류(ArenaRules.Arena · Tower · Raid).</summary>
|
|
public string board = "";
|
|
public List<RankRow> top = new List<RankRow>();
|
|
/// <summary>내 순위(0 = 아직 점수 없음).</summary>
|
|
public int myRank;
|
|
public long myScore;
|
|
/// <summary>그 판에 점수가 있는 유저 수.</summary>
|
|
public int total;
|
|
}
|
|
}
|
|
|
|
namespace TKS.OutGame.Net
|
|
{
|
|
/// <summary>
|
|
/// 순위 표 팝업 — 투기장(이번 시즌 점수) · 천하제일 탑(최고 층) · 적장 토벌(이번 주 누적 피해) 세 판을 탭으로 바꿔 본다.
|
|
/// 서버 모드에서만 열린다(연무장 화면의 「순위 표」 버튼) — 순위는 실제 유저 사이의 순위다.
|
|
/// </summary>
|
|
public static class RankPanel
|
|
{
|
|
const float Width = 860f;
|
|
const float TabW = 272f;
|
|
const float TabH = 64f;
|
|
const float TabGap = 22f;
|
|
const float RowH = 76f;
|
|
const float ListTop = 148f;
|
|
|
|
/// <summary>판 종류 · 탭 이름 · 점수 이름.</summary>
|
|
static readonly string[,] Boards =
|
|
{
|
|
{ ArenaRules.Arena, "투기장", "주간 점수" },
|
|
{ ArenaRules.Tower, "천하제일 탑", "최고 층" },
|
|
{ ArenaRules.Raid, "적장 토벌", "누적 피해" },
|
|
};
|
|
|
|
static int IndexOf(string board)
|
|
{
|
|
for (int i = 0; i < Boards.GetLength(0); i++)
|
|
if (Boards[i, 0] == board) return i;
|
|
return 0;
|
|
}
|
|
|
|
public static void Open(OutGameRoot root, string board)
|
|
{
|
|
int at = IndexOf(board);
|
|
var content = root.ModalCustom("순위 표", 1500f, new OutGameRoot.ModalButton("닫기", UiKit.Dark, null));
|
|
for (int i = 0; i < Boards.GetLength(0); i++)
|
|
{
|
|
string key = Boards[i, 0];
|
|
bool on = i == at;
|
|
var tab = UiKit.Btn("RankTab_" + key, content, Boards[i, 1], 30, on ? UiKit.Red : UiKit.Dark, UiKit.White, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(i * (TabW + TabGap), 0f), new Vector2(TabW, TabH),
|
|
() => Open(root, key));
|
|
tab.interactable = !on;
|
|
}
|
|
var status = UiKit.Label(content, "순위를 불러오는 중…", 32, UiKit.InkSoft, TextAnchor.MiddleLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(8f, -(TabH + 12f)), new Vector2(Width - 16f, 60f), false);
|
|
root.Session.RankBoardAsync(Boards[at, 0], (b, why) =>
|
|
{
|
|
if (content == null) return; // 받는 사이에 팝업을 닫았다(또는 다른 탭으로 바꿨다)
|
|
if (b == null)
|
|
{
|
|
status.text = why;
|
|
return;
|
|
}
|
|
Fill(content, status, b, Boards[at, 2]);
|
|
});
|
|
}
|
|
|
|
static void Fill(RectTransform content, Text status, RankBoard b, string scoreName)
|
|
{
|
|
status.text = b.myRank > 0
|
|
? "내 순위 " + b.myRank.ToString("N0") + "위 / " + b.total.ToString("N0") + "명 · " + scoreName + " " + b.myScore.ToString("N0")
|
|
: "아직 기록이 없습니다 · 전체 " + b.total.ToString("N0") + "명";
|
|
if (b.top.Count == 0)
|
|
{
|
|
UiKit.Label(content, "아직 순위에 오른 유저가 없습니다", 34, UiKit.InkSoft, TextAnchor.MiddleCenter, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -ListTop - 80f), new Vector2(Width, 80f), false);
|
|
return;
|
|
}
|
|
|
|
ScrollRect sr;
|
|
var grid = UiKit.ScrollGrid("Ranks", content, 0f, 0f, ListTop, 0f, new Vector2(Width, RowH), new Vector2(0f, 8f), 1, out sr);
|
|
foreach (var row in b.top)
|
|
{
|
|
// 내 줄은 흰 바탕 + 붉은 테두리로 구분한다
|
|
var cell = UiKit.Cell(grid, "Rank_" + row.rank, row.me ? UiKit.White : UiKit.Paper, null);
|
|
UiKit.Border(cell, row.me ? UiKit.Red : UiKit.Line, row.me ? 4f : 2f);
|
|
UiKit.Label(cell.transform, row.rank.ToString("N0"), 36, UiKit.Ink, TextAnchor.MiddleCenter, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(8f, 0f), new Vector2(120f, RowH));
|
|
UiKit.Label(cell.transform, row.me ? row.name + " (나)" : row.name, 32, UiKit.Ink, TextAnchor.MiddleLeft, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(140f, 0f), new Vector2(430f, RowH), row.me)
|
|
.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
UiKit.Label(cell.transform, row.score.ToString("N0"), 34, UiKit.Ink, TextAnchor.MiddleRight, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2(-24f, 0f), new Vector2(260f, RowH));
|
|
}
|
|
}
|
|
}
|
|
}
|