using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// 공지 1건(화면 표시용) — 서버가 내려 준 공지를 세션(Net/ServerSession)이 이 모양으로 바꿔 준다(글은 게임 언어 칸 · 없으면 한국어). public class NoticeItem { public int id; public string title = ""; public string body = ""; /// 보이기 시작 · 끝(UTC). public DateTime startAt; public DateTime endAt; } } namespace TKS.OutGame.Net { /// /// 공지사항 팝업 — 운영툴에서 등록한 공지 가운데 지금 기간 안의 것을 최근 것부터 보여 준다. 서버 모드에서만 열린다(우편함의 「공지사항」 버튼). /// 줄을 누르면 그 공지의 전체 글을 띄운다. /// 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 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"); } /// 공지 1건의 전체 글 — 닫으면 목록으로 돌아간다. static void Detail(OutGameRoot root, NoticeItem n) { root.Modal(n.title, n.body + "\n\n" + Period(n) + "", new OutGameRoot.ModalButton("목록", UiKit.Dark, () => Open(root))); } } }