89 lines
5.0 KiB
C#
89 lines
5.0 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using System.Globalization;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
namespace TKS.OutGame
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 기기 우편함(2026-11-20 · 임무 메뉴 요청서 §0-6 「우편 최소 기능」 · 목업 07_pop_mail) — 로비 「우편」(기기 세이브 모드) → 목록 · 받기 · 모두 받기.
|
||
|
|
/// 우편 = SaveData.mail(임무 초기화 때 받지 않은 구간 보상) · 글 = mission_text 의 mail_<kind>_title/body · 보상 아이콘 = mission_screen reward_icon.
|
||
|
|
/// 서버 모드는 기존 서버 우편함(Net/MailPanel).
|
||
|
|
/// </summary>
|
||
|
|
public static class MailBox
|
||
|
|
{
|
||
|
|
const float RowH = 330f;
|
||
|
|
|
||
|
|
public static string Title(MailEntry m)
|
||
|
|
{
|
||
|
|
return MissionScreen.T("mail_" + m.kind + "_title");
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string Body(MailEntry m)
|
||
|
|
{
|
||
|
|
string date = m.args.Count > 0 ? m.args[0] : "";
|
||
|
|
DateTime_Parts(date, out var mo, out var dd);
|
||
|
|
var needs = new List<string>();
|
||
|
|
if (m.args.Count > 1)
|
||
|
|
foreach (var n in m.args[1].Split(';'))
|
||
|
|
if (n.Length > 0) needs.Add(MissionScreen.F("mail_need", n));
|
||
|
|
return MissionScreen.F("mail_" + m.kind + "_body", mo, dd, string.Join(" · ", needs.ToArray()));
|
||
|
|
}
|
||
|
|
|
||
|
|
static void DateTime_Parts(string yyyymmdd, out string month, out string day)
|
||
|
|
{
|
||
|
|
month = day = "";
|
||
|
|
if (yyyymmdd == null || yyyymmdd.Length != 8) return;
|
||
|
|
int mo, dd;
|
||
|
|
if (int.TryParse(yyyymmdd.Substring(4, 2), NumberStyles.Integer, CultureInfo.InvariantCulture, out mo)) month = mo.ToString(CultureInfo.InvariantCulture);
|
||
|
|
if (int.TryParse(yyyymmdd.Substring(6, 2), NumberStyles.Integer, CultureInfo.InvariantCulture, out dd)) day = dd.ToString(CultureInfo.InvariantCulture);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void Open(OutGameRoot root)
|
||
|
|
{
|
||
|
|
UiText.Use(MissionScreen.Texts);
|
||
|
|
var s = root.Session;
|
||
|
|
var items = s.Save.mail != null ? s.Save.mail.items : new List<MailEntry>();
|
||
|
|
var ids = new List<int>();
|
||
|
|
foreach (var m in items) ids.Add(m.id);
|
||
|
|
float h = Mathf.Clamp(330f + Mathf.Max(1, items.Count) * (RowH + 14f), 620f, 1500f);
|
||
|
|
var buttons = new List<OutGameRoot.ModalButton>();
|
||
|
|
if (items.Count > 0) buttons.Add(new OutGameRoot.ModalButton(MissionScreen.T("mail_claim_all"), UiKit.Coin, () => Claim(root, ids)));
|
||
|
|
buttons.Add(new OutGameRoot.ModalButton(MissionScreen.T("mail_close"), UiKit.Dark, null));
|
||
|
|
var content = root.ModalCustom(MissionScreen.T("mail_title"), h, buttons.ToArray());
|
||
|
|
var head = content.parent.Find("Head");
|
||
|
|
if (head != null && head.GetComponent<Image>() != null) head.GetComponent<Image>().color = MissionScreen.Col("pop_mail", UiKit.Header);
|
||
|
|
if (items.Count == 0)
|
||
|
|
{
|
||
|
|
UiKit.Label(content, MissionScreen.T("mail_empty"), 32, UiKit.InkSoft, TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(820f, 60f), false);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
ScrollRect sr;
|
||
|
|
var grid = UiKit.ScrollGrid("Mails", content, 0f, 0f, 0f, 0f, new Vector2(860f, RowH), new Vector2(0f, 14f), 1, out sr);
|
||
|
|
foreach (var m in items)
|
||
|
|
{
|
||
|
|
var mail = m;
|
||
|
|
var go = new GameObject("Mail_" + mail.id, typeof(RectTransform));
|
||
|
|
go.transform.SetParent(grid, false);
|
||
|
|
var cell = (RectTransform)go.transform;
|
||
|
|
UiKit.Skin(cell, "panel12", MissionScreen.Col("row", UiKit.Dark), true); // 팝업 판 = 어두운 테마 → 칸도 어둡게 · 흰 글자
|
||
|
|
UiKit.Title(UiKit.Label(cell, Title(mail), 32, MissionScreen.Col("text", UiKit.White), TextAnchor.MiddleLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(24f, -12f), new Vector2(600f, 46f)), true);
|
||
|
|
var b = UiKit.Label(cell, Body(mail), 24, MissionScreen.Col("text_dim", UiKit.InkSoft), TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(24f, -80f), new Vector2(812f, 64f), false);
|
||
|
|
b.lineSpacing = 1.1f;
|
||
|
|
MissionScreen.RewardRow(cell, mail.reward, 140f, 96f, true);
|
||
|
|
UiKit.SkinBtn(cell, "Claim", UISkin.Has("btn_l_yellow") ? "btn_l_yellow" : "button", UiKit.White, MissionScreen.T("mail_claim"), 30, UiKit.Col("text_on_yellow", UiKit.Ink), 860f - 180f, 8f, 160f, 62f, () => Claim(root, new List<int> { mail.id }));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void Claim(OutGameRoot root, List<int> ids)
|
||
|
|
{
|
||
|
|
var s = root.Session;
|
||
|
|
var got = MissionRules.ClaimMail(s.Db, s.Save, ids, s.Rng);
|
||
|
|
if (got.Count == 0) return;
|
||
|
|
s.Commit();
|
||
|
|
root.Toast(MissionScreen.F("mail_got", got.Count.ToString(CultureInfo.InvariantCulture)));
|
||
|
|
Open(root); // 받은 우편이 빠진 목록으로 다시 연다
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|