80 lines
3.9 KiB
C#
80 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TKS.OutGame
|
|
{
|
|
/// <summary>공지 1건(화면 표시용) — 서버가 내려 준 공지를 세션(Net/ServerSession)이 이 모양으로 바꿔 준다(글은 게임 언어 칸 · 없으면 한국어).</summary>
|
|
public class NoticeItem
|
|
{
|
|
public int id;
|
|
public string title = "";
|
|
public string body = "";
|
|
/// <summary>보이기 시작 · 끝(UTC).</summary>
|
|
public DateTime startAt;
|
|
public DateTime endAt;
|
|
}
|
|
}
|
|
|
|
namespace TKS.OutGame.Net
|
|
{
|
|
/// <summary>
|
|
/// 공지사항 팝업 — 운영툴에서 등록한 공지 가운데 지금 기간 안의 것을 최근 것부터 보여 준다. 서버 모드에서만 열린다(우편함의 「공지사항」 버튼).
|
|
/// 줄을 누르면 그 공지의 전체 글을 띄운다.
|
|
/// </summary>
|
|
public static class NoticePanel
|
|
{
|
|
const float Width = 860f;
|
|
const float RowH = 250f;
|
|
|
|
public static void Open(OutGameRoot root)
|
|
{
|
|
var content = root.ModalCustom("공지사항", 1500f,
|
|
new OutGameRoot.ModalButton("우편", UiKit.Jade, () => MailPanel.Open(root)),
|
|
new OutGameRoot.ModalButton("닫기", UiKit.Dark, null));
|
|
var status = UiKit.Label(content, "공지를 불러오는 중…", 32, UiKit.InkSoft, TextAnchor.MiddleLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(8f, 0f), new Vector2(Width - 16f, 64f), false);
|
|
root.Session.NoticeListAsync((list, why) =>
|
|
{
|
|
if (content == null) return; // 받는 사이에 팝업을 닫았다
|
|
if (list == null)
|
|
{
|
|
status.text = why;
|
|
return;
|
|
}
|
|
Fill(root, content, status, list);
|
|
});
|
|
}
|
|
|
|
static void Fill(OutGameRoot root, RectTransform content, Text status, List<NoticeItem> list)
|
|
{
|
|
status.text = list.Count == 0 ? "지금 올라온 공지가 없습니다" : "공지 " + list.Count + "건 · 누르면 전체 글이 보입니다";
|
|
if (list.Count == 0) return;
|
|
|
|
ScrollRect sr;
|
|
var grid = UiKit.ScrollGrid("Notices", content, 0f, 0f, 80f, 0f, new Vector2(Width, RowH), new Vector2(0f, 12f), 1, out sr);
|
|
foreach (var n in list)
|
|
{
|
|
var notice = n;
|
|
var cell = UiKit.Cell(grid, "Notice_" + notice.id, UiKit.Paper, () => Detail(root, notice));
|
|
UiKit.Border(cell, UiKit.Line, 2f);
|
|
// 위에서부터: 제목 · 본문 앞부분(넘치면 자름) · 기간
|
|
UiKit.Label(cell.transform, notice.title, 36, UiKit.Ink, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(20f, -14f), new Vector2(Width - 40f, 50f)).verticalOverflow = VerticalWrapMode.Truncate;
|
|
UiKit.Label(cell.transform, notice.body, 28, UiKit.InkSoft, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(20f, -70f), new Vector2(Width - 40f, 130f), false).verticalOverflow = VerticalWrapMode.Truncate;
|
|
UiKit.Label(cell.transform, Period(notice), 22, UiKit.InkSoft, TextAnchor.LowerLeft, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(20f, 10f), new Vector2(Width - 40f, 30f), false);
|
|
}
|
|
}
|
|
|
|
static string Period(NoticeItem n)
|
|
{
|
|
return n.startAt.ToLocalTime().ToString("M월 d일 HH:mm") + " ~ " + n.endAt.ToLocalTime().ToString("M월 d일 HH:mm");
|
|
}
|
|
|
|
/// <summary>공지 1건의 전체 글 — 닫으면 목록으로 돌아간다.</summary>
|
|
static void Detail(OutGameRoot root, NoticeItem n)
|
|
{
|
|
root.Modal(n.title, n.body + "\n\n<size=26>" + Period(n) + "</size>", new OutGameRoot.ModalButton("목록", UiKit.Dark, () => Open(root)));
|
|
}
|
|
}
|
|
}
|