648 lines
29 KiB
C#
648 lines
29 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
namespace TKS.OutGame
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 첫 실행 흐름 지휘(PD 2026-11-24 「최초 게임 실행 시 게임 Flow」 · 요청서 = 조직 레포 공유/기획팀_산출물/삼국지슬링샷/개발요청_최초실행흐름_2026-11-24.md) —
|
||
|
|
/// 타이틀 → 인트로(IntroScreen) → 서장 1 → 2 → 3막(연의 전기 화면 · 결과 화면 없이 검정 페이드로 이어짐) → 본영 로비 → 대사 줄(first_flow_lines):
|
||
|
|
/// 여인의 인사 → 「등용」 → 「10회 등용」(첫 무료 · 마지막 장 = 가신) → 가신의 한마디 → 「출정」 → (출정 1-1 첫 승리) → 가신의 진언 → 「군영」 → 군영 장소 소개 → 끝.
|
||
|
|
/// 들어가는 조건 = 기기 세이브 모드 · 서장 마지막 막을 이긴 기록이 없음 · 흐름을 끝낸 기록이 없음(세이브 firstFlow) — 서장을 이미 끝낸 세이브 = 지금처럼 로비.
|
||
|
|
/// 메모리 세이브(자동 테스트 · 검증 캡처) = 건너뜀(ForceOn 으로 켬). 진행 = 세이브 firstFlow.line(끝낸 마지막 줄) — 도중에 꺼도 다음 줄부터, 그 줄의 화면에 들어왔을 때 이어진다.
|
||
|
|
/// 값 · 문구 · 대상 · 영웅 · 배너 · 스테이지 = 표(FirstFlowData · C45). 1 ~ 3막의 연출 · 안내 · 배치 표와 연의 전기 화면의 서장 다시 보기는 건드리지 않는다.
|
||
|
|
/// </summary>
|
||
|
|
public class FirstFlow : MonoBehaviour
|
||
|
|
{
|
||
|
|
/// <summary>테스트: 메모리 세이브에서도 흐름을 켠다(기본 = 메모리 세이브는 건너뜀 · 기존 테스트 「Battle 씬 2 프레임 안 로비」).</summary>
|
||
|
|
public static bool ForceOn;
|
||
|
|
|
||
|
|
OutGameRoot root;
|
||
|
|
ScreenFader fader;
|
||
|
|
bool talking;
|
||
|
|
bool switching;
|
||
|
|
bool lastWin;
|
||
|
|
float eligibleSince = -1f;
|
||
|
|
int eligibleStep;
|
||
|
|
Coroutine chain;
|
||
|
|
Coroutine afterAct;
|
||
|
|
|
||
|
|
public FirstFlowGuide Guide { get; private set; }
|
||
|
|
/// <summary>출정 첫 스테이지의 스킬 튜토리얼(FirstFlowSortie).</summary>
|
||
|
|
public FirstFlowSortie Sortie { get; private set; }
|
||
|
|
/// <summary>지금 화면에 떠 있는 대사 줄(없으면 null · 테스트).</summary>
|
||
|
|
public FirstFlowData.Line Current { get; private set; }
|
||
|
|
|
||
|
|
public static FirstFlow Create(OutGameRoot root)
|
||
|
|
{
|
||
|
|
var go = new GameObject("FirstFlow");
|
||
|
|
go.transform.SetParent(root.transform, false);
|
||
|
|
var f = go.AddComponent<FirstFlow>();
|
||
|
|
f.root = root;
|
||
|
|
f.Sortie = FirstFlowSortie.Create(root, f);
|
||
|
|
return f;
|
||
|
|
}
|
||
|
|
|
||
|
|
OutGameSession S
|
||
|
|
{
|
||
|
|
get { return root.Session; }
|
||
|
|
}
|
||
|
|
|
||
|
|
FirstFlowState State
|
||
|
|
{
|
||
|
|
get { return S.Save.firstFlow; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>이 세션에서 첫 실행 흐름을 쓰는가 — 표 있음 · 기기 세이브 모드 · 메모리 세이브가 아님(ForceOn 이면 켬).</summary>
|
||
|
|
public bool Available
|
||
|
|
{
|
||
|
|
get { return root != null && S != null && S.FirstFlowAvailable && (ForceOn || !SaveStore.MemoryOnly) && FirstFlowData.Ready; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>흐름에 들어와 있고 아직 끝나지 않았는가.</summary>
|
||
|
|
public bool Active
|
||
|
|
{
|
||
|
|
get { return Available && State.started && !State.done; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대사 · 막 전환 · 인트로 중(뒤로 가기를 받지 않음).</summary>
|
||
|
|
public bool Busy
|
||
|
|
{
|
||
|
|
get { return talking || switching || IntroScreen.Current != null; }
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool Switching
|
||
|
|
{
|
||
|
|
get { return switching; }
|
||
|
|
}
|
||
|
|
|
||
|
|
string PrologueId
|
||
|
|
{
|
||
|
|
get { return FirstFlowData.Str("prologue_battle"); }
|
||
|
|
}
|
||
|
|
|
||
|
|
int PrologueActs
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
var b = ContentTables.Find("scenario_battles", "s_id", PrologueId);
|
||
|
|
return b != null && b.I("n_no") == 0 ? Mathf.Max(1, b.I("n_acts")) : 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool PrologueDone
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
int acts = PrologueActs;
|
||
|
|
return acts <= 0 || ScenarioModeRules.ActsCleared(S.Save, PrologueId) >= acts;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 시작(타이틀 누름 뒤 · Battle 씬) ----------
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 게임 시작 — 첫 실행(서장을 끝내지 않은 새 세이브)이면 인트로(아직 안 봤으면) → 아직 이기지 못한 첫 막을 열고 true(호출 쪽은 로비를 띄우지 않는다).
|
||
|
|
/// false = 지금처럼 본영 로비(서장을 끝낸 세이브 · 메모리 세이브 · 서버 모드 · 표 없음) — 서장 뒤 대사가 남아 있으면 로비에서 이어진다.
|
||
|
|
/// </summary>
|
||
|
|
public bool BootBegin()
|
||
|
|
{
|
||
|
|
if (!Available) return false;
|
||
|
|
var st = State;
|
||
|
|
if (st.done) return false;
|
||
|
|
bool prologueDone = PrologueDone;
|
||
|
|
if (!st.started)
|
||
|
|
{
|
||
|
|
if (prologueDone) return false; // 서장을 이미 끝낸 예전 세이브 = 흐름에 들어가지 않음
|
||
|
|
st.started = true;
|
||
|
|
if (S.IsNewUser) ResetRoster(); // 새 유저 = 표 start_heroes 만 보유(비어 있음 = 없음) → 서장 보상으로 유비 · 등용으로 가신
|
||
|
|
S.Commit();
|
||
|
|
}
|
||
|
|
if (prologueDone) return false; // 서장 뒤에 끈 세이브 = 로비에서 대사를 이어 감
|
||
|
|
int act = ScenarioModeRules.NextAct(S.Save, PrologueId, PrologueActs);
|
||
|
|
if (!st.intro && IntroScreen.CanShow)
|
||
|
|
{
|
||
|
|
root.SetBattleHud(false); // 인트로 밑에서 전투 HUD · 조작이 돌지 않게(1막을 열 때 다시 켜짐)
|
||
|
|
IntroScreen.Show(root.Cam, () =>
|
||
|
|
{
|
||
|
|
State.intro = true;
|
||
|
|
S.Commit();
|
||
|
|
if (!StartAct(act)) root.ShowLobby();
|
||
|
|
});
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return StartAct(act);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 새 유저의 보유 영웅을 표(first_flow_config start_heroes · | 로 여럿 · 비어 있음 = 없음)대로 맞춘다 — PD 2026-11-24
|
||
|
|
/// 「최초 게임 실행 시 보유한 유닛은 유비(연의 전기로 획득), 그리고 [등용] 보상으로 얻은 유닛들로만」(기본 지급 = economy.csv start_heroes 를 이 흐름에서만 뺀다).
|
||
|
|
/// </summary>
|
||
|
|
void ResetRoster()
|
||
|
|
{
|
||
|
|
var keep = new HashSet<string>();
|
||
|
|
foreach (var id in FirstFlowData.List("start_heroes"))
|
||
|
|
if (id.Trim().Length > 0) keep.Add(id.Trim());
|
||
|
|
var d = S.Save;
|
||
|
|
d.heroes.RemoveAll(h => !keep.Contains(h.id));
|
||
|
|
d.units.RemoveAll(u => !keep.Contains(u.id));
|
||
|
|
HeroRules.Sanitize(S.Db, d, S.FormationSlots); // 편성 칸에서 없는 영웅을 비움
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>출전 편성이 비어 있으면 보유 영웅을 앞 칸부터 세운다(서장 보상으로 유비를 얻은 직후 = 로비에 유비만).</summary>
|
||
|
|
void FillEmptyLineup()
|
||
|
|
{
|
||
|
|
var d = S.Save;
|
||
|
|
var p = d.ActivePreset;
|
||
|
|
if (p == null) return;
|
||
|
|
foreach (var id in p.slots)
|
||
|
|
if (!string.IsNullOrEmpty(id)) return;
|
||
|
|
int at = 0;
|
||
|
|
foreach (var h in d.heroes)
|
||
|
|
{
|
||
|
|
if (at >= p.slots.Count) break;
|
||
|
|
p.slots[at++] = h.id;
|
||
|
|
}
|
||
|
|
if (at > 0) S.Commit();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>서장 막을 연의 전기 화면 없이 연다 · false = 못 엶(표 없음 · 군량 부족 …).</summary>
|
||
|
|
bool StartAct(int act)
|
||
|
|
{
|
||
|
|
if (!root.Arena.PrologueGo(PrologueId, act, this)) return false;
|
||
|
|
return FlowRules(root.Battle) != null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>지금 전투가 첫 실행 흐름이 연 서장 막인가(그 규칙 · 아니면 null).</summary>
|
||
|
|
static PrologueRules FlowRules(BattleManager b)
|
||
|
|
{
|
||
|
|
var r = b != null && b.Mode != null ? b.Mode.rules as PrologueRules : null;
|
||
|
|
return r != null && r.WinContinue != null ? r : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 서장 막 잇기 ----------
|
||
|
|
|
||
|
|
/// <summary>막 승리 연출이 끝남(결과 화면 대신) — 막 기록 · 보상은 지금 규칙대로 처리하고 검정 페이드 → 다음 막(마지막 막 = 본영 로비).</summary>
|
||
|
|
internal bool OnActWin(PrologueRules r)
|
||
|
|
{
|
||
|
|
if (!Available) return false;
|
||
|
|
if (r.LastAct) return false; // 마지막 막 = 결과 화면으로 서장 보상(유비 획득)을 알림(PD 2026-11-24) → 닫으면 본영(OnActExit)
|
||
|
|
root.SettleMode(true);
|
||
|
|
if (afterAct != null) StopCoroutine(afterAct); // 앞 막 전환의 페이드가 아직 걷히는 중 = 그 페이드를 이어 받음
|
||
|
|
afterAct = StartCoroutine(AfterAct(r));
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
IEnumerator AfterAct(PrologueRules r)
|
||
|
|
{
|
||
|
|
switching = true;
|
||
|
|
root.SetBattleHud(false);
|
||
|
|
var f = Fader();
|
||
|
|
if (ScenarioEvent.EndedBlack) f.Alpha = 1f; // 승리 연출이 검게 끝남(3막) = 그대로 이어 받음
|
||
|
|
else yield return f.FadeTo(1f, ScenarioData.EvCfg("fade_sec"));
|
||
|
|
bool next = !r.LastAct && StartAct(r.Act + 1);
|
||
|
|
if (!next)
|
||
|
|
{
|
||
|
|
root.Battle.LeaveMode();
|
||
|
|
root.ShowLobby();
|
||
|
|
}
|
||
|
|
var io = FirstFlowData.List(next ? "act_in" : "lobby_in"); // 검정 유지 | 밝아지는 시간
|
||
|
|
yield return Hold(ScreenTable.At(io, 0, 0.15f));
|
||
|
|
yield return f.FadeTo(0f, ScreenTable.At(io, 1, 0.3f));
|
||
|
|
DropFader();
|
||
|
|
switching = false;
|
||
|
|
afterAct = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>결과 창을 닫은 뒤 — 패배 · 포기 = 그 막을 처음부터 다시(연의 전기 화면으로 나가지 않음) · 마지막 막 승리 = 본영 로비(출전 편성 = 얻은 유비).</summary>
|
||
|
|
internal void OnActExit(PrologueRules r)
|
||
|
|
{
|
||
|
|
if (!lastWin && StartAct(r.Act)) return;
|
||
|
|
FillEmptyLineup();
|
||
|
|
root.ShowLobby();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>컨텐츠 모드 결과가 채워진 직후 — 첫 실행 흐름의 서장 패배 = 버튼 글자 「다시 도전」.</summary>
|
||
|
|
internal void OnModeResult(BattleResultPanel panel, bool win)
|
||
|
|
{
|
||
|
|
lastWin = win;
|
||
|
|
if (!win && panel != null && FlowRules(root.Battle) != null) panel.SetOkText(FirstFlowData.T("ff_retry"));
|
||
|
|
}
|
||
|
|
|
||
|
|
ScreenFader Fader()
|
||
|
|
{
|
||
|
|
if (fader != null) return fader;
|
||
|
|
var fd = FirstFlowData.List("fade"); // 정렬 순서 | 색
|
||
|
|
fader = ScreenFader.Create(root.Cam, (int)ScreenTable.At(fd, 0, 940f), ScreenTable.Col(fd, 1, Color.black));
|
||
|
|
return fader;
|
||
|
|
}
|
||
|
|
|
||
|
|
void DropFader()
|
||
|
|
{
|
||
|
|
if (fader != null) Destroy(fader.gameObject);
|
||
|
|
fader = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
static IEnumerator Hold(float sec)
|
||
|
|
{
|
||
|
|
for (float t = 0f; t < sec; t += Time.unscaledDeltaTime) yield return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnDestroy()
|
||
|
|
{
|
||
|
|
DropFader();
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 대사 줄 ----------
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (talking || switching || root == null || root.Session == null) return;
|
||
|
|
if (!Active)
|
||
|
|
{
|
||
|
|
eligibleSince = -1f;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var show = Eligible();
|
||
|
|
if (show == null)
|
||
|
|
{
|
||
|
|
eligibleSince = -1f;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
// 그 화면에 들어온 뒤 잠깐 뜸을 들이고 시작(본영 로비가 밝아지고 0.5초 뒤 · 표 start_delay_sec)
|
||
|
|
if (eligibleSince < 0f || eligibleStep != show.step)
|
||
|
|
{
|
||
|
|
eligibleSince = Time.unscaledTime;
|
||
|
|
eligibleStep = show.step;
|
||
|
|
}
|
||
|
|
if (Time.unscaledTime - eligibleSince < FirstFlowData.Num("start_delay_sec", 0.5f)) return;
|
||
|
|
eligibleSince = -1f;
|
||
|
|
chain = StartCoroutine(Run(show));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>지금 화면에서 시작할 줄 — 다음 줄(건너뛰기 처리 뒤)이 이 화면의 줄이면 그 줄 · 아니고 본영 로비에 있으면 그 화면으로 이끄는 줄(n_gate) · 없으면 null.</summary>
|
||
|
|
FirstFlowData.Line Eligible()
|
||
|
|
{
|
||
|
|
if (Blocked()) return null;
|
||
|
|
var next = Next();
|
||
|
|
if (next == null) return null;
|
||
|
|
if (!WaitOk(next)) return null;
|
||
|
|
if (ScreenOk(next)) return next;
|
||
|
|
if (next.gate > 0 && OnScreen(FirstFlowData.ScreenLobby))
|
||
|
|
{
|
||
|
|
var g = FirstFlowData.LineOf(next.gate);
|
||
|
|
if (g != null && Targets(g) != null) return g;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>다른 창 · 화면 전환이 떠 있어 대사를 시작하지 않는 때.</summary>
|
||
|
|
bool Blocked()
|
||
|
|
{
|
||
|
|
return root.ModalVisible || root.ResultVisible || SceneSwitch.Current != null || BootFlow.Current != null || TitleScreen.Current != null || IntroScreen.Current != null || LoadingScreen.Current != null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>끝낸 줄의 다음 줄 — 건너뛰는 조건(s_skip_if)이 참이면 n_skip_to 로 기록을 옮긴다 · 다음 줄이 없으면 흐름 끝.</summary>
|
||
|
|
FirstFlowData.Line Next()
|
||
|
|
{
|
||
|
|
for (int guard = 0; guard < 64; guard++)
|
||
|
|
{
|
||
|
|
var l = FirstFlowData.LineOf(State.line + 1);
|
||
|
|
if (l == null)
|
||
|
|
{
|
||
|
|
Finish();
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
if (l.skipIf.Length == 0 || !SkipCond(l.skipIf)) return l;
|
||
|
|
State.line = Mathf.Max(State.line + 1, l.skipTo - 1);
|
||
|
|
S.Commit();
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool SkipCond(string cond)
|
||
|
|
{
|
||
|
|
if (cond == FirstFlowData.SkipFirstPullDone) return S.Save.gacha.total > 0;
|
||
|
|
if (cond == FirstFlowData.SkipRetainerPlaced)
|
||
|
|
{
|
||
|
|
var p = S.Save.ActivePreset;
|
||
|
|
return p != null && RetainerId.Length > 0 && p.slots.Contains(RetainerId);
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>가신 = gacha.csv first_pull_hero 의 영웅 id(첫 등용의 첫 장).</summary>
|
||
|
|
public string RetainerId
|
||
|
|
{
|
||
|
|
get { return S.Db.Gacha.FirstPullHero; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>서장 보상으로 얻는 영웅(scenario_battles 서장 편의 s_reward_hero = 유비) — 출정 첫 스테이지 스킬 튜토리얼의 주인공.</summary>
|
||
|
|
public string VictimId
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
var b = ContentTables.Find("scenario_battles", "s_id", PrologueId);
|
||
|
|
return b != null ? b.S("s_reward_hero") : "";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool WaitOk(FirstFlowData.Line l)
|
||
|
|
{
|
||
|
|
if (l.wait.Length == 0) return true;
|
||
|
|
int ch, st;
|
||
|
|
string key = FirstFlowData.Arg(l.wait, FirstFlowData.WaitStageClear);
|
||
|
|
if (key == null || !FirstFlowData.ParseStage(key, out ch, out st)) return true;
|
||
|
|
var rec = S.Save.Stage(ch, st, false);
|
||
|
|
return rec != null && rec.clears > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool ScreenOk(FirstFlowData.Line l)
|
||
|
|
{
|
||
|
|
foreach (var sc in l.screens)
|
||
|
|
if (OnScreen(sc) && (!l.HasTarget || l.targetScreen == sc))
|
||
|
|
return true;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool OnScreen(string sc)
|
||
|
|
{
|
||
|
|
switch (sc)
|
||
|
|
{
|
||
|
|
case FirstFlowData.ScreenLobby: return root.LobbyVisible;
|
||
|
|
case FirstFlowData.ScreenRecruit: return root.ScreensVisible && root.Current == root.Trade && root.Trade.Page == 0 && !root.Trade.ResultVisible;
|
||
|
|
case FirstFlowData.ScreenMap: return root.Map != null && root.Map.IsVisible && !root.Map.PopupVisible && root.Battle.Phase == BattlePhase.Setup;
|
||
|
|
case FirstFlowData.ScreenCamp: return root.ScreensVisible && root.Current == root.Arena && root.Arena.HubVisible;
|
||
|
|
case FirstFlowData.ScreenFormation: return root.ScreensVisible && root.Current == root.Formation;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
RectTransform ScreenRoot(string sc)
|
||
|
|
{
|
||
|
|
switch (sc)
|
||
|
|
{
|
||
|
|
case FirstFlowData.ScreenLobby: return root.Lobby.Rt;
|
||
|
|
case FirstFlowData.ScreenRecruit: return root.Trade.Rt;
|
||
|
|
case FirstFlowData.ScreenCamp: return root.Arena.Rt;
|
||
|
|
case FirstFlowData.ScreenFormation: return root.Formation.Rt;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>줄의 대상 오브젝트들(화면 안에서 이름으로 찾음 · 켜져 있는 것만) — 하나라도 못 찾으면 null.</summary>
|
||
|
|
List<RectTransform> Targets(FirstFlowData.Line l)
|
||
|
|
{
|
||
|
|
if (!l.HasTarget) return null;
|
||
|
|
var sr = ScreenRoot(l.targetScreen);
|
||
|
|
if (sr == null) return null;
|
||
|
|
var list = new List<RectTransform>();
|
||
|
|
var all = sr.GetComponentsInChildren<RectTransform>(false);
|
||
|
|
foreach (var raw in l.targetNames)
|
||
|
|
{
|
||
|
|
string name = raw.Replace(FirstFlowData.RetainerToken, RetainerId); // 예 C_{retainer} = 편성 화면의 가신 카드
|
||
|
|
RectTransform hit = null;
|
||
|
|
foreach (var rt in all)
|
||
|
|
if (rt.name == name)
|
||
|
|
{
|
||
|
|
hit = rt;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (hit == null) return null;
|
||
|
|
list.Add(hit);
|
||
|
|
}
|
||
|
|
return list;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>누르게 하는 줄의 대상이 눌렸는가를 받는 것 — 버튼(onClick) 또는 TapDrag(편성 화면의 영웅 카드 · OnTap).</summary>
|
||
|
|
class PressHook
|
||
|
|
{
|
||
|
|
Button btn;
|
||
|
|
TapDrag tap;
|
||
|
|
System.Action prevTap;
|
||
|
|
UnityEngine.Events.UnityAction onClick;
|
||
|
|
|
||
|
|
public static PressHook Of(List<RectTransform> targets)
|
||
|
|
{
|
||
|
|
if (targets == null) return null;
|
||
|
|
foreach (var t in targets)
|
||
|
|
{
|
||
|
|
var b = t.GetComponent<Button>() ?? t.GetComponentInChildren<Button>(false);
|
||
|
|
if (b != null) return new PressHook { btn = b };
|
||
|
|
var d = t.GetComponent<TapDrag>() ?? t.GetComponentInChildren<TapDrag>(false);
|
||
|
|
if (d != null) return new PressHook { tap = d };
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대상이 아직 화면에 있는가.</summary>
|
||
|
|
public bool Alive
|
||
|
|
{
|
||
|
|
get { return btn != null ? btn.gameObject.activeInHierarchy : tap != null && tap.gameObject.activeInHierarchy; }
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대상의 원래 동작이 끝난 바로 뒤에 onPress 를 부르게 건다.</summary>
|
||
|
|
public void Attach(System.Action onPress)
|
||
|
|
{
|
||
|
|
if (btn != null)
|
||
|
|
{
|
||
|
|
onClick = () => onPress();
|
||
|
|
btn.onClick.AddListener(onClick);
|
||
|
|
}
|
||
|
|
else if (tap != null)
|
||
|
|
{
|
||
|
|
prevTap = tap.OnTap;
|
||
|
|
tap.OnTap = () =>
|
||
|
|
{
|
||
|
|
if (prevTap != null) prevTap();
|
||
|
|
onPress();
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Detach()
|
||
|
|
{
|
||
|
|
if (btn != null && onClick != null) btn.onClick.RemoveListener(onClick);
|
||
|
|
if (tap != null) tap.OnTap = prevTap;
|
||
|
|
onClick = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>대상을 누른다(테스트).</summary>
|
||
|
|
public void Invoke()
|
||
|
|
{
|
||
|
|
if (btn != null) btn.onClick.Invoke();
|
||
|
|
else if (tap != null && tap.OnTap != null) tap.OnTap();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
IEnumerator Run(FirstFlowData.Line first)
|
||
|
|
{
|
||
|
|
talking = true;
|
||
|
|
var line = first;
|
||
|
|
while (line != null)
|
||
|
|
{
|
||
|
|
OnShow(line);
|
||
|
|
yield return null; // 배너 고름 · 화면 전환 뒤 한 프레임(자리 잡기)
|
||
|
|
while (root.Arena != null && root.Arena.Hub != null && root.Arena.Hub.Fitter != null && root.Arena.Hub.Fitter.Focusing && root.Arena.HubVisible) yield return null; // 군영 포커스 이동이 끝난 뒤 가리킴
|
||
|
|
var targets = Targets(line);
|
||
|
|
var btn = line.mode == FirstFlowData.Press ? PressHook.Of(targets) : null;
|
||
|
|
string mode = line.mode;
|
||
|
|
if (mode == FirstFlowData.Press && btn == null)
|
||
|
|
{
|
||
|
|
Debug.LogWarning("[TKS] 첫 실행 흐름: 줄 " + line.step + " 누를 대상을 찾지 못함 → 말하기로 보여 줌");
|
||
|
|
mode = FirstFlowData.Talk;
|
||
|
|
}
|
||
|
|
if (mode == FirstFlowData.Point && targets == null) mode = FirstFlowData.Talk;
|
||
|
|
EnsureGuide().Show(Request(line, mode, targets));
|
||
|
|
Current = line;
|
||
|
|
|
||
|
|
bool pressed = false;
|
||
|
|
if (btn != null)
|
||
|
|
{
|
||
|
|
var at = line;
|
||
|
|
btn.Attach(() =>
|
||
|
|
{
|
||
|
|
pressed = true;
|
||
|
|
After(at); // 눌린 그 자리에서(같은 누름으로 뽑기 · 화면 전환이 저장되는 것과 같이)
|
||
|
|
Mark(at.step);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
bool aborted = false;
|
||
|
|
while (true)
|
||
|
|
{
|
||
|
|
if (btn != null ? pressed : Guide.Taps > 0) break;
|
||
|
|
if (!StillOn(line, btn))
|
||
|
|
{
|
||
|
|
aborted = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
if (btn != null) btn.Detach();
|
||
|
|
Guide.Taps = 0;
|
||
|
|
if (aborted) break;
|
||
|
|
Sound.PlayUi(SoundKeys.UiTab);
|
||
|
|
if (btn == null) After(line);
|
||
|
|
Mark(line.step);
|
||
|
|
if (line.done == FirstFlowData.DoneEnd)
|
||
|
|
{
|
||
|
|
Finish();
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (line.done == FirstFlowData.DoneLobby) root.ShowLobby(); // 대사가 끝나면 스스로 본영 로비로(뒤로 가기를 시키지 않음)
|
||
|
|
var next = Next();
|
||
|
|
if (next == null || Blocked() || !WaitOk(next) || !ScreenOk(next)) break; // 다음 줄은 그 화면에 들어왔을 때(Update)
|
||
|
|
line = next;
|
||
|
|
}
|
||
|
|
Current = null;
|
||
|
|
if (Guide != null) Guide.Hide();
|
||
|
|
talking = false;
|
||
|
|
chain = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>줄이 뜨는 동안 그 화면이 그대로인가(화면이 바뀌면 줄을 거두고 다시 판단) — 누르기 줄은 버튼이 살아 있는가도.</summary>
|
||
|
|
bool StillOn(FirstFlowData.Line l, PressHook btn)
|
||
|
|
{
|
||
|
|
if (btn != null && !btn.Alive) return false;
|
||
|
|
if (!Active) return false;
|
||
|
|
foreach (var sc in l.screens)
|
||
|
|
if (OnScreen(sc))
|
||
|
|
return true;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>줄이 끝난 뒤 할 일(s_on_done) — save_formation = 편성 화면의 지금 편성을 저장(가신을 세운 편성이 출전 편성이 됨).</summary>
|
||
|
|
void After(FirstFlowData.Line l)
|
||
|
|
{
|
||
|
|
if (l.onDone == FirstFlowData.AfterSaveFormation && root.Formation != null && root.Current == root.Formation) root.Formation.SaveNow();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>줄을 끝냄으로 기록(다시 보여 준 앞 줄은 기록을 바꾸지 않음).</summary>
|
||
|
|
void Mark(int step)
|
||
|
|
{
|
||
|
|
if (step <= State.line) return;
|
||
|
|
State.line = step;
|
||
|
|
S.Commit();
|
||
|
|
}
|
||
|
|
|
||
|
|
void Finish()
|
||
|
|
{
|
||
|
|
if (State.done) return;
|
||
|
|
State.done = true;
|
||
|
|
S.Commit();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>줄이 뜰 때 할 일(s_on_show) — banner:<id> = 명장 등용 화면에서 그 배너를 고름.</summary>
|
||
|
|
void OnShow(FirstFlowData.Line l)
|
||
|
|
{
|
||
|
|
string bid = FirstFlowData.Arg(l.onShow, FirstFlowData.OnShowBanner);
|
||
|
|
if (bid != null && root.Trade != null && (root.Trade.Banner == null || root.Trade.Banner.id != bid)) root.Trade.SelectBanner(bid);
|
||
|
|
string spot = FirstFlowData.Arg(l.onShow, FirstFlowData.OnShowFocus); // 군영 장소 소개 = 그 장소로 화면을 옮긴 뒤 가리킴
|
||
|
|
if (spot != null && root.Arena != null && root.Arena.Hub != null && root.Arena.HubVisible) root.Arena.Hub.Focus(spot, FirstFlowData.Num("camp_focus_sec", 0.45f));
|
||
|
|
}
|
||
|
|
|
||
|
|
FirstFlowGuide EnsureGuide()
|
||
|
|
{
|
||
|
|
if (Guide == null) Guide = FirstFlowGuide.Create(root.transform, root.Cam);
|
||
|
|
return Guide;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>말하는 이(표 speaker.<id> = 이름 키 | 그림 경로 앞부분 | 임시 유닛 그림 | 이름표 색 | 받침 색) — 가신 = gacha.csv first_ten_hero 의 영웅(이름 · 그림).</summary>
|
||
|
|
FirstFlowGuide.Request Request(FirstFlowData.Line l, string mode, List<RectTransform> targets)
|
||
|
|
{
|
||
|
|
var sp = FirstFlowData.List("speaker." + l.speaker);
|
||
|
|
var q = new FirstFlowGuide.Request
|
||
|
|
{
|
||
|
|
mode = mode,
|
||
|
|
text = FirstFlowData.T(l.textKey),
|
||
|
|
targets = mode == FirstFlowData.Talk ? null : targets,
|
||
|
|
tagTint = ScreenTable.Col(sp, 3, new Color(0.45f, 0.32f, 0.2f)),
|
||
|
|
plate = ScreenTable.Col(sp, 4, new Color(1f, 1f, 1f, 0f)),
|
||
|
|
};
|
||
|
|
string nameKey = ScreenTable.Str(sp, 0), prefix = ScreenTable.Str(sp, 1), fallback = ScreenTable.Str(sp, 2);
|
||
|
|
HeroDb.Hero hero = l.speaker == FirstFlowData.Retainer ? S.Def(RetainerId) : null;
|
||
|
|
q.name = nameKey.Length > 0 ? FirstFlowData.T(nameKey) : hero != null ? hero.nameKo : "";
|
||
|
|
if (prefix.Length > 0)
|
||
|
|
{
|
||
|
|
q.portrait = Resources.Load<Sprite>(prefix + l.face); // 납품 그림(표정별)
|
||
|
|
if (q.portrait == null) q.portrait = Resources.Load<Sprite>(prefix + "normal");
|
||
|
|
}
|
||
|
|
if (q.portrait == null && hero != null) q.portrait = UiKit.ArtSprite(hero.art);
|
||
|
|
if (q.portrait == null && fallback.Length > 0) q.portrait = UnitArt.Portrait(fallback); // 납품 전 임시 = 유닛 그림
|
||
|
|
return q;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---------- 테스트 · 캡처 ----------
|
||
|
|
|
||
|
|
/// <summary>지금 왜 대사가 뜨지 않는가를 한 줄로(테스트 실패 글 · 확인용).</summary>
|
||
|
|
public string DebugState()
|
||
|
|
{
|
||
|
|
if (root == null || root.Session == null) return "세션 없음";
|
||
|
|
var n = FirstFlowData.LineOf(State.line + 1);
|
||
|
|
return "active=" + Active + " line=" + State.line + " done=" + State.done + " talking=" + talking + " switching=" + switching
|
||
|
|
+ " modal=" + root.ModalVisible + " result=" + root.ResultVisible + " scene=" + (SceneSwitch.Current != null) + " boot=" + (BootFlow.Current != null)
|
||
|
|
+ " title=" + (TitleScreen.Current != null) + " intro=" + (IntroScreen.Current != null) + " loading=" + (LoadingScreen.Current != null)
|
||
|
|
+ " lobby=" + OnScreen(FirstFlowData.ScreenLobby) + " recruit=" + OnScreen(FirstFlowData.ScreenRecruit) + " map=" + OnScreen(FirstFlowData.ScreenMap) + " camp=" + OnScreen(FirstFlowData.ScreenCamp)
|
||
|
|
+ (n != null ? " next=" + n.step + " wait=" + WaitOk(n) + " screen=" + ScreenOk(n) : " next=없음")
|
||
|
|
+ " mapVisible=" + (root.Map != null && root.Map.IsVisible) + " mapPopup=" + (root.Map != null && root.Map.PopupVisible) + " phase=" + root.Battle.Phase;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>화면 누름 1회(대사 넘김).</summary>
|
||
|
|
public void TapForTest()
|
||
|
|
{
|
||
|
|
if (Guide != null) Guide.Tap();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>누르게 하는 줄의 대상 버튼을 누른다 · 그런 줄이 떠 있지 않으면 false.</summary>
|
||
|
|
public bool PressTargetForTest()
|
||
|
|
{
|
||
|
|
if (Current == null || Guide == null || Guide.Mode != FirstFlowData.Press) return false;
|
||
|
|
var b = PressHook.Of(Targets(Current));
|
||
|
|
if (b == null) return false;
|
||
|
|
b.Invoke();
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|