using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// 우편 1통(화면 표시용) — 서버가 내려 준 우편을 세션(Net/ServerSession)이 이 모양으로 바꿔 준다. public class MailItem { public int id; public string title = ""; public string body = ""; /// 보상 글(예 「골드 500 · 청동 상자 1」 · 없으면 ""). public string rewards = ""; public bool hasRewards; /// 우편함에서 사라지는 시각(UTC). public DateTime until; } } namespace TKS.OutGame.Net { /// /// 우편함 팝업 — 목록(받기 · 모두 받기) + 쿠폰 입력. 서버 모드에서만 열린다(로비 「우편」 버튼). /// 우편은 운영툴에서 만든다(개별 · 전체 · 쿠폰). 받은 우편은 목록에서 빠진다. /// public static class MailPanel { const float Width = 860f; const float RowH = 222f; const float CouponH = 96f; public static void Open(OutGameRoot root) { var content = root.ModalCustom("우편", 1500f, 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(560f, 64f), false); Coupon(root, content); root.Session.MailListAsync((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) { var claimable = new List(); foreach (var m in list) if (m.hasRewards) claimable.Add(m.id); status.text = list.Count == 0 ? "받은 우편이 없습니다" : "우편 " + list.Count + "통"; if (claimable.Count > 1) UiKit.Btn("ClaimAll", content, "모두 받기", 30, UiKit.Jade, UiKit.White, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(0f, 0f), new Vector2(240f, 64f), () => Claim(root, claimable)); ScrollRect sr; var grid = UiKit.ScrollGrid("Mails", content, 0f, 0f, 80f, CouponH + 24f, new Vector2(Width, RowH), new Vector2(0f, 12f), 1, out sr); foreach (var m in list) { var mail = m; var cell = UiKit.Cell(grid, "Mail_" + mail.id, UiKit.Paper, null); UiKit.Border(cell, UiKit.Line, 2f); // 위에서부터: 제목 · 내용(두 줄까지 · 넘치면 자름) · 보상 · 사라지는 날 UiKit.Label(cell.transform, mail.title, 34, UiKit.Ink, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(20f, -14f), new Vector2(610f, 46f)).verticalOverflow = VerticalWrapMode.Truncate; UiKit.Label(cell.transform, mail.body, 26, UiKit.InkSoft, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(20f, -62f), new Vector2(610f, 68f), false).verticalOverflow = VerticalWrapMode.Truncate; if (mail.until > DateTime.MinValue) UiKit.Label(cell.transform, mail.until.ToLocalTime().ToString("M월 d일 HH:mm") + " 까지", 22, UiKit.InkSoft, TextAnchor.LowerLeft, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(20f, 10f), new Vector2(610f, 30f), false); if (mail.hasRewards) { UiKit.Label(cell.transform, mail.rewards, 28, UiKit.Ink, TextAnchor.LowerLeft, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(20f, 42f), new Vector2(610f, 40f)).verticalOverflow = VerticalWrapMode.Truncate; UiKit.Btn("Claim", cell.transform, "받기", 34, UiKit.Red, UiKit.White, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2(-16f, 0f), new Vector2(190f, 110f), () => Claim(root, new List { mail.id })); } } } static void Claim(OutGameRoot root, List ids) { root.Session.MailClaimAsync(ids, (msg, ok) => { root.Toast(msg); if (ok) Open(root); // 받은 우편이 빠진 목록으로 다시 연다 }); } /// 쿠폰 입력 줄(팝업 맨 아래). static void Coupon(OutGameRoot root, RectTransform content) { var box = UiKit.Box("Coupon", content, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(Width - 260f, CouponH), UiKit.White); box.raycastTarget = true; UiKit.Border(box, UiKit.Line, 2f); var text = UiKit.FillLabel(box.transform, "", 34, UiKit.Ink, TextAnchor.MiddleLeft, false, 20f); text.supportRichText = false; var hint = UiKit.FillLabel(box.transform, "쿠폰 코드", 30, UiKit.InkSoft, TextAnchor.MiddleLeft, false, 20f); var input = box.gameObject.AddComponent(); input.textComponent = text; input.placeholder = hint; input.characterLimit = 50; input.lineType = InputField.LineType.SingleLine; UiKit.Btn("UseCoupon", content, "쿠폰 사용", 32, UiKit.Jade, UiKit.White, new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(0f, 0f), new Vector2(240f, CouponH), () => root.Session.CouponAsync(input.text, (msg, ok) => { root.Toast(msg); if (ok) Open(root); })); } } }