add missing files
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f677d4ac6de4dca8e92a3efa687ff1b
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03ad9dd5bf1d46ee9cd2a6f54d17b5fa
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e05527a70e234c16af2f9089012721b8
|
||||
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Read-only card inventory. Sorting a copy never exposes or changes draw order.</summary>
|
||||
public static class CardPileView
|
||||
{
|
||||
private sealed class TabState
|
||||
{
|
||||
public string Query = string.Empty;
|
||||
public string Language = "All languages";
|
||||
public string Cost = "Any stored cost";
|
||||
public bool GroupCopies = true;
|
||||
public float Scroll;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<CardInstance> FilterAndSort(IEnumerable<CardInstance> cards, string query)
|
||||
{
|
||||
query = query?.Trim() ?? string.Empty;
|
||||
return (cards ?? Array.Empty<CardInstance>()).Where(card => card?.Definition != null)
|
||||
.Where(card => query.Length == 0 || SearchText(card).IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
.OrderBy(card => card.Definition.DisplayName, StringComparer.OrdinalIgnoreCase)
|
||||
.ThenBy(card => card.Definition.Id, StringComparer.Ordinal)
|
||||
.ThenBy(card => card.UpgradeLevel).ThenBy(card => card.MagnitudeBonus)
|
||||
.ThenBy(card => card.PermanentCostDelta).ThenBy(card => card.DrawRider)
|
||||
.ThenBy(card => card.TemporaryCostDelta).ThenBy(card => card.IsBroken)
|
||||
.ThenBy(card => card.CorruptionRoundsRemaining).ThenBy(card => card.IsLocked).ToArray();
|
||||
}
|
||||
|
||||
private static string SearchText(CardInstance card) =>
|
||||
$"{card.Definition.DisplayName} {card.Definition.Id} {card.Definition.Language} {CardEffectFactory.GetRulesText(card)} " +
|
||||
(card.IsUpgraded ? $"upgraded patch {card.UpgradeLevel}" : string.Empty);
|
||||
|
||||
public static IReadOnlyList<CardInstance[]> GroupIdenticalCopies(IEnumerable<CardInstance> cards,
|
||||
Func<CardInstance, string> costDetails = null) => FilterAndSort(cards, string.Empty)
|
||||
.GroupBy(card => new
|
||||
{
|
||||
card.Definition, card.UpgradeLevel, card.MagnitudeBonus, card.DrawRider,
|
||||
card.PermanentCostDelta, card.TemporaryCostDelta, card.IsBroken,
|
||||
card.CorruptionRoundsRemaining, card.IsLocked, card.QueuePlayCount,
|
||||
card.WasFirstCardThisTurn, card.HadFedoraNonCrashBonus,
|
||||
CostContext = costDetails?.Invoke(card) ?? string.Empty
|
||||
}).Select(group => group.ToArray()).ToArray();
|
||||
|
||||
public static VisualElement Build(string title, IReadOnlyList<CardInstance> snapshot, Action close) =>
|
||||
BuildBrowser(title, new Dictionary<string, IReadOnlyList<CardInstance>> { [title] = snapshot }, close);
|
||||
|
||||
public static VisualElement BuildBrowser(string initialPile,
|
||||
IReadOnlyDictionary<string, IReadOnlyList<CardInstance>> inventories, Action close,
|
||||
Func<CardInstance, string> costDetails = null)
|
||||
{
|
||||
var piles = inventories.ToDictionary(pair => pair.Key,
|
||||
pair => (pair.Value ?? Array.Empty<CardInstance>()).Where(card => card?.Definition != null).ToArray());
|
||||
if (piles.Count == 0) piles[initialPile] = Array.Empty<CardInstance>();
|
||||
string selected = piles.ContainsKey(initialPile) ? initialPile : piles.Keys.First();
|
||||
var states = piles.Keys.ToDictionary(key => key, _ => new TabState());
|
||||
var tabs = new Dictionary<string, Button>();
|
||||
int revision = 0;
|
||||
var cards = piles[selected];
|
||||
var panel = new VisualElement { name = "CardPileInspector" };
|
||||
panel.AddToClassList("pile-inspector");
|
||||
var header = new VisualElement();
|
||||
header.AddToClassList("pile-header");
|
||||
var heading = SoftwareCardView.Text(selected.ToUpperInvariant() + " PILE", "pile-title");
|
||||
header.Add(heading);
|
||||
var count = SoftwareCardView.Text(string.Empty, "pile-count");
|
||||
count.name = "PileCount";
|
||||
header.Add(count);
|
||||
panel.Add(header);
|
||||
panel.Add(SoftwareCardView.Text("Sorted A-Z. Draw order stays hidden. Costs on cards are stored costs.", "pile-description"));
|
||||
var tabRow = new VisualElement { name = "PileTabs" };
|
||||
tabRow.AddToClassList("pile-tabs");
|
||||
if (piles.Count > 1) panel.Add(tabRow);
|
||||
var searchRow = new VisualElement();
|
||||
searchRow.AddToClassList("pile-search-row");
|
||||
var search = new TextField("Search") { name = "PileSearch", tooltip = "Filter by card name, language, rules or upgrades." };
|
||||
search.textEdition.placeholder = "Name, language or rules...";
|
||||
search.textEdition.hidePlaceholderOnFocus = false;
|
||||
search.AddToClassList("pile-search");
|
||||
searchRow.Add(search);
|
||||
var clear = new Button(() => { search.value = string.Empty; search.Focus(); })
|
||||
{
|
||||
name = "ClearPileSearch", text = "Clear", tooltip = "Clear the search text."
|
||||
};
|
||||
clear.AddToClassList("pile-clear");
|
||||
searchRow.Add(clear);
|
||||
panel.Add(searchRow);
|
||||
var filters = new VisualElement();
|
||||
filters.AddToClassList("pile-filters");
|
||||
var languages = new List<string> { "All languages" };
|
||||
languages.AddRange(piles.Values.SelectMany(pile => pile).Select(LanguageName).Distinct().OrderBy(name => name, StringComparer.Ordinal));
|
||||
var language = new DropdownField(languages, 0) { name = "PileLanguageFilter", tooltip = "Filter by card language." };
|
||||
var cost = new DropdownField(new List<string> { "Any stored cost", "0 cycles", "1 cycle", "2 cycles", "3+ cycles" }, 0)
|
||||
{ name = "PileCostFilter", tooltip = "Filter by stored Cycles, before current combat discounts." };
|
||||
var grouped = new Toggle("Group copies") { name = "PileGroupCopies", value = true };
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "PileCards" };
|
||||
var grid = new VisualElement { name = "PileCardGrid" };
|
||||
var reset = new Button { name = "ResetPileFilters", text = "Reset filters" };
|
||||
reset.clicked += () =>
|
||||
{
|
||||
states[selected].Query = string.Empty;
|
||||
states[selected].Language = languages[0];
|
||||
states[selected].Cost = cost.choices[0];
|
||||
search.SetValueWithoutNotify(string.Empty);
|
||||
language.SetValueWithoutNotify(languages[0]);
|
||||
cost.SetValueWithoutNotify(cost.choices[0]);
|
||||
Refresh(string.Empty);
|
||||
search.Focus();
|
||||
};
|
||||
language.AddToClassList("pile-filter");
|
||||
cost.AddToClassList("pile-filter");
|
||||
grouped.AddToClassList("pile-group-toggle");
|
||||
reset.AddToClassList("pile-clear");
|
||||
filters.Add(language); filters.Add(cost); filters.Add(grouped); filters.Add(reset);
|
||||
panel.Add(filters);
|
||||
scroll.AddToClassList("pile-scroll");
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
grid.AddToClassList("pile-grid");
|
||||
scroll.Add(grid);
|
||||
panel.Add(scroll);
|
||||
void LayoutCards()
|
||||
{
|
||||
float width = scroll.contentViewport.contentRect.width;
|
||||
if (width <= 0 || float.IsNaN(width)) return;
|
||||
int columns = width >= 900 ? 3 : width >= 600 ? 2 : 1;
|
||||
float cardWidth = Mathf.Floor((width - (columns - 1) * 12) / columns);
|
||||
int index = 0;
|
||||
foreach (var face in grid.Children().Where(element => element.ClassListContains("pile-card")))
|
||||
{
|
||||
face.style.width = cardWidth;
|
||||
face.style.marginRight = ++index % columns == 0 ? 0 : 12;
|
||||
}
|
||||
}
|
||||
scroll.contentViewport.RegisterCallback<GeometryChangedEvent>(_ => LayoutCards());
|
||||
panel.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape)
|
||||
{
|
||||
close?.Invoke();
|
||||
evt.StopPropagation();
|
||||
}
|
||||
else if (evt.keyCode == KeyCode.PageUp || evt.keyCode == KeyCode.PageDown)
|
||||
{
|
||||
float delta = Mathf.Max(40, scroll.contentViewport.layout.height * 0.8f);
|
||||
scroll.scrollOffset += new Vector2(0, evt.keyCode == KeyCode.PageUp ? -delta : delta);
|
||||
evt.StopPropagation();
|
||||
}
|
||||
}, TrickleDown.TrickleDown);
|
||||
void Refresh(string query)
|
||||
{
|
||||
revision++;
|
||||
var state = states[selected];
|
||||
state.Query = query;
|
||||
grid.Clear();
|
||||
scroll.scrollOffset = Vector2.zero;
|
||||
var filtered = FilterAndSort(cards, query).Where(card =>
|
||||
(state.Language == languages[0] || LanguageName(card) == state.Language) &&
|
||||
(state.Cost == cost.choices[0] || (state.Cost == "3+ cycles"
|
||||
? CombatManager.GetCardCost(card) >= 3
|
||||
: CombatManager.GetCardCost(card) == state.Cost[0] - '0'))).ToArray();
|
||||
heading.text = selected.ToUpperInvariant() + " PILE";
|
||||
count.text = filtered.Length == cards.Length ? $"{cards.Length} {(cards.Length == 1 ? "card" : "cards")}" : $"{filtered.Length} of {cards.Length} cards";
|
||||
clear.SetEnabled(!string.IsNullOrEmpty(query));
|
||||
reset.SetEnabled(query.Length > 0 || state.Language != languages[0] || state.Cost != cost.choices[0]);
|
||||
foreach (var tab in tabs) tab.Value.EnableInClassList("selected", tab.Key == selected);
|
||||
if (filtered.Length == 0)
|
||||
{
|
||||
var empty = SoftwareCardView.Text(cards.Length == 0 ? "This pile is empty." : "No matching cards. Try another search or reset the filters.", "pile-empty");
|
||||
empty.name = "PileEmptyState";
|
||||
grid.Add(empty);
|
||||
}
|
||||
var groups = state.GroupCopies ? GroupIdenticalCopies(filtered, costDetails) : filtered.Select(card => new[] { card }).ToArray();
|
||||
foreach (var copies in groups)
|
||||
{
|
||||
var card = copies[0];
|
||||
var face = new VisualElement { name = "PileCard", userData = copies.Length };
|
||||
face.AddToClassList("pile-card");
|
||||
SoftwareCardView.Populate(face, card, CombatManager.GetCardCost(card));
|
||||
face.Q<Label>(className: "software-cost").text = $"{CombatManager.GetCardCost(card)}c stored";
|
||||
// The full rules remain inline; no hover is required for keyboard or touch readers.
|
||||
face.tooltip = string.Empty;
|
||||
if (copies.Length > 1)
|
||||
{
|
||||
var badge = SoftwareCardView.Text($"×{copies.Length} identical copies", "pile-copy-count");
|
||||
badge.name = "PileCopyCount";
|
||||
face.Insert(0, badge);
|
||||
}
|
||||
string costs = costDetails?.Invoke(card);
|
||||
if (!string.IsNullOrEmpty(costs))
|
||||
{
|
||||
int split = costs.IndexOf('\n');
|
||||
face.Add(SoftwareCardView.Text(split < 0 ? costs : costs.Substring(0, split), "pile-cost-summary"));
|
||||
if (split >= 0)
|
||||
{
|
||||
var explanation = new Foldout { text = "Cost details", value = false, name = "PileCostDetails" };
|
||||
explanation.Add(SoftwareCardView.Text(costs.Substring(split + 1), "pile-cost-explanation"));
|
||||
face.Add(explanation);
|
||||
}
|
||||
}
|
||||
if (card.IsBroken)
|
||||
face.Add(SoftwareCardView.Text(CardPreviewService.CorruptionDetails(card), "pile-status-detail"));
|
||||
var details = new List<string> { $"RAM {HandController.GetRamCost(card)}" };
|
||||
if (card.UpgradeLevel > 0) details.Add($"Patch {card.UpgradeLevel}");
|
||||
if (card.PermanentCostDelta != 0) details.Add($"cost adjustment {card.PermanentCostDelta:+0;-0;0}");
|
||||
if (card.MagnitudeBonus != 0) details.Add($"magnitude {card.MagnitudeBonus:+0;-0;0}");
|
||||
if (card.DrawRider != 0) details.Add($"draw {card.DrawRider:+0;-0;0}");
|
||||
if (card.TemporaryCostDelta != 0) details.Add($"temporary cost {card.TemporaryCostDelta:+0;-0;0}");
|
||||
face.Add(SoftwareCardView.Text(string.Join(" / ", details), "pile-upgrades"));
|
||||
grid.Add(face);
|
||||
}
|
||||
LayoutCards();
|
||||
}
|
||||
foreach (string key in piles.Keys)
|
||||
{
|
||||
string pile = key;
|
||||
var tab = new Button(() =>
|
||||
{
|
||||
if (selected == pile) return;
|
||||
states[selected].Scroll = scroll.scrollOffset.y;
|
||||
selected = pile;
|
||||
cards = piles[pile];
|
||||
var state = states[pile];
|
||||
search.SetValueWithoutNotify(state.Query);
|
||||
language.SetValueWithoutNotify(state.Language);
|
||||
cost.SetValueWithoutNotify(state.Cost);
|
||||
grouped.SetValueWithoutNotify(state.GroupCopies);
|
||||
Refresh(state.Query);
|
||||
int rendering = revision;
|
||||
panel.schedule.Execute(() =>
|
||||
{
|
||||
if (rendering == revision) scroll.scrollOffset = new Vector2(0, state.Scroll);
|
||||
}).StartingIn(16);
|
||||
}) { name = "PileTab_" + pile, text = $"{char.ToUpperInvariant(pile[0])}{pile.Substring(1)} ({piles[pile].Length})" };
|
||||
tab.AddToClassList("pile-tab");
|
||||
tabs.Add(pile, tab);
|
||||
tabRow.Add(tab);
|
||||
}
|
||||
search.RegisterValueChangedCallback(evt => Refresh(evt.newValue));
|
||||
language.RegisterValueChangedCallback(evt => { states[selected].Language = evt.newValue; Refresh(search.value); });
|
||||
cost.RegisterValueChangedCallback(evt => { states[selected].Cost = evt.newValue; Refresh(search.value); });
|
||||
grouped.RegisterValueChangedCallback(evt => { states[selected].GroupCopies = evt.newValue; Refresh(search.value); });
|
||||
Refresh(string.Empty);
|
||||
var dismiss = new Button(close) { text = "Close [Esc]", name = "ClosePileInspector" };
|
||||
dismiss.AddToClassList("primary-action");
|
||||
var footer = new VisualElement();
|
||||
footer.AddToClassList("pile-footer");
|
||||
footer.Add(SoftwareCardView.Text("PgUp / PgDn: scroll", "pile-footer-hint"));
|
||||
footer.Add(dismiss);
|
||||
panel.Add(footer);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private static string LanguageName(CardInstance card) => card.Definition.Language.ToString().Replace("CPlusPlus", "C++");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc8a03f56d32c661088f820d4f765a47
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6c581de5a6bcbc73a451ce3906547bc
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1100000000000000000000000000003
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73880a4e893003d719622694aa5ffc02
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bf334307f22465cad853cb6b3757468
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b02ec0c6f7df1d3aa8211567c3ec2a3
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fc0548ea57f35548834530e8a2ec091
|
||||
@@ -0,0 +1,100 @@
|
||||
using KernelPanic.Combat;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
internal sealed class ExecutionPreviewView
|
||||
{
|
||||
public Foldout Element { get; } = new() { text = "End-turn execution preview", name = "ExecutionPreview", value = false };
|
||||
private readonly ScrollView _rows = new(ScrollViewMode.Vertical);
|
||||
private CombatManager _combat;
|
||||
private VisualElement _popup;
|
||||
public bool IsOpen => _popup != null;
|
||||
|
||||
public ExecutionPreviewView()
|
||||
{
|
||||
Element.AddToClassList("execution-preview");
|
||||
_rows.style.maxHeight = 220;
|
||||
_rows.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
Element.Add(_rows);
|
||||
Element.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
if (!evt.newValue) { Close(); return; }
|
||||
Refresh(_combat);
|
||||
Element.schedule.Execute(() =>
|
||||
{
|
||||
if (!Element.value) return;
|
||||
var workspace = Element.GetFirstAncestorOfType<ScrollView>();
|
||||
if (workspace == null) return;
|
||||
if (workspace.contentViewport.resolvedStyle.height < 180)
|
||||
{ OpenPopup(workspace.parent); return; }
|
||||
FitRows(workspace);
|
||||
Element.schedule.Execute(() => workspace.ScrollTo(Element));
|
||||
});
|
||||
});
|
||||
Element.RegisterCallback<GeometryChangedEvent>(_ =>
|
||||
{
|
||||
if (Element.value && !IsOpen && Element.GetFirstAncestorOfType<ScrollView>() is { } workspace)
|
||||
FitRows(workspace);
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenPopup(VisualElement root)
|
||||
{
|
||||
if (IsOpen || root == null) return;
|
||||
_popup = new VisualElement { name = "ExecutionPreviewPopup", focusable = true };
|
||||
_popup.AddToClassList("execution-preview-shade");
|
||||
var panel = TerminalLayout.Section("End-turn execution preview", "ExecutionPreviewDialog");
|
||||
panel.AddToClassList("execution-preview-dialog");
|
||||
_rows.RemoveFromHierarchy();
|
||||
_rows.style.maxHeight = StyleKeyword.None;
|
||||
_rows.style.flexGrow = 1;
|
||||
_rows.style.minHeight = 0;
|
||||
panel.Add(_rows);
|
||||
var close = new Button(Close) { text = "Close / Escape", name = "CloseExecutionPreview" };
|
||||
close.AddToClassList("primary-action");
|
||||
panel.Add(close);
|
||||
_popup.Add(panel);
|
||||
_popup.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape) Close();
|
||||
evt.StopPropagation();
|
||||
});
|
||||
TerminalTheme.ConstrainModalFocus(_popup);
|
||||
root.Add(_popup);
|
||||
_popup.BringToFront();
|
||||
close.Focus();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
bool hadPopup = IsOpen;
|
||||
_popup?.RemoveFromHierarchy();
|
||||
_popup = null;
|
||||
Element.SetValueWithoutNotify(false);
|
||||
_rows.style.maxHeight = 220;
|
||||
_rows.style.flexGrow = 0;
|
||||
if (_rows.parent != Element.contentContainer) Element.Add(_rows);
|
||||
if (hadPopup) Element.Q<Toggle>()?.Focus();
|
||||
}
|
||||
|
||||
private void FitRows(ScrollView workspace)
|
||||
{
|
||||
float height = workspace.contentViewport.resolvedStyle.height;
|
||||
if (!float.IsNaN(height) && height > 0)
|
||||
_rows.style.maxHeight = System.Math.Max(36, System.Math.Min(220, height - 42));
|
||||
}
|
||||
|
||||
public void Refresh(CombatManager combat)
|
||||
{
|
||||
_combat = combat;
|
||||
bool available = combat != null && !combat.RunFinished && !combat.AwaitingWaveContinue;
|
||||
Element.style.display = available ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (!available) Close();
|
||||
if (!available || !Element.value) return;
|
||||
_rows.Clear();
|
||||
foreach (string line in ExecutionPreview.Build(combat)) _rows.Add(TerminalLayout.BodyText(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa8f89d97d7143a6b735100d9dfc677b
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a850316506e1ce241a2e74281b4b9943
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7f7ef4e16694ed9bd746278b0ddc4d8
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Observes a real battle; never changes cards, targeting or turn timing.</summary>
|
||||
public sealed class FirstBattleGuide
|
||||
{
|
||||
private const string PreferenceKey = "KernelPanic.FirstBattleGuide.v1";
|
||||
private readonly Action _remember;
|
||||
private readonly Label _title = new();
|
||||
private readonly Label _instruction = new();
|
||||
private readonly Label _receipt = new();
|
||||
private readonly Button _action;
|
||||
private readonly Button _skip;
|
||||
private RunConfig _config;
|
||||
private bool _played;
|
||||
private bool _endedTurn;
|
||||
private bool _completed;
|
||||
private bool _started;
|
||||
public VisualElement Element { get; } = new() { name = "FirstBattleGuide" };
|
||||
public bool Visible => Element.style.display.value != DisplayStyle.None;
|
||||
public string Instruction => _instruction.text;
|
||||
|
||||
public FirstBattleGuide(Action remember = null)
|
||||
{
|
||||
_remember = remember ?? Remember;
|
||||
Element.AddToClassList("first-battle-guide");
|
||||
_title.AddToClassList("guide-title");
|
||||
_instruction.AddToClassList("guide-copy");
|
||||
_receipt.AddToClassList("guide-copy");
|
||||
var header = new VisualElement();
|
||||
header.AddToClassList("guide-header");
|
||||
header.Add(_title);
|
||||
Element.Add(header);
|
||||
Element.Add(_instruction);
|
||||
Element.Add(_receipt);
|
||||
var actions = new VisualElement();
|
||||
actions.AddToClassList("guide-actions");
|
||||
_action = new Button(Advance) { text = "Ready: play a card" };
|
||||
_skip = new Button(Dismiss) { text = "Skip guide" };
|
||||
actions.Add(_action);
|
||||
actions.Add(_skip);
|
||||
header.Add(actions);
|
||||
Element.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
public void Begin(RunConfig config, bool replay = false)
|
||||
{
|
||||
_config = config;
|
||||
if (!replay && PlayerPrefs.GetInt(PreferenceKey, 0) != 0) return;
|
||||
_played = _endedTurn = _completed = _started = false;
|
||||
_receipt.text = "";
|
||||
Element.style.display = DisplayStyle.Flex;
|
||||
_action.style.display = DisplayStyle.Flex;
|
||||
_skip.style.display = DisplayStyle.Flex;
|
||||
_action.text = "Ready: play a card";
|
||||
_title.text = "First battle / 1 of 4 / read the process table";
|
||||
_instruction.text = "Uptime = health; Cycles = card budget; RAM = hand capacity. Read enemy intents, then select a card and its target. " + TrackLesson(config);
|
||||
}
|
||||
|
||||
public void Advance()
|
||||
{
|
||||
if (!Visible) return;
|
||||
if (_completed) { Dismiss(); return; }
|
||||
_started = true;
|
||||
_action.style.display = DisplayStyle.None;
|
||||
_title.text = "First battle / 2 of 4 / dispatch a card";
|
||||
_instruction.text = "Play any affordable card. Targeted cards need a living process selected. The preview explains its current effect. " + TrackLesson(_config);
|
||||
}
|
||||
|
||||
public void CardPlayed(ResolutionTrack track, string name)
|
||||
{
|
||||
if (!Visible || _completed) return;
|
||||
_played = _started = true;
|
||||
_action.style.display = DisplayStyle.None;
|
||||
_title.text = "First battle / 3 of 4 / finish your turn";
|
||||
_receipt.text = track switch
|
||||
{
|
||||
ResolutionTrack.InterpreterQueue => name + " entered the queue. It waits until end turn; the oldest queued card resolves first.",
|
||||
ResolutionTrack.LazyStack => name + " entered the stack. It waits until after the queue; the newest stacked card resolves first.",
|
||||
_ => name + " executes immediately on the Native track."
|
||||
};
|
||||
_instruction.text = "Play more cards if you have Cycles, then choose [E] end turn. Watch the scheduler: queue first, stack second, then enemies act. Shield helps absorb incoming damage.";
|
||||
}
|
||||
|
||||
public void CardResolved(string name, ResolutionTrack track)
|
||||
{
|
||||
if (!Visible || _completed) return;
|
||||
_receipt.text = name + " resolved" + (track == ResolutionTrack.Native ? " immediately." : track == ResolutionTrack.InterpreterQueue ? " from the front of the queue." : " from the top of the stack.");
|
||||
}
|
||||
|
||||
public void PhaseChanged(TurnPhase phase)
|
||||
{
|
||||
if (!Visible || _completed) return;
|
||||
if (phase == TurnPhase.Interpret)
|
||||
{
|
||||
_endedTurn = true;
|
||||
_instruction.text = "Resolving: queued cards execute oldest first, then stacked cards execute newest first. Enemy actions follow. You can inspect the journal for the result of each operation.";
|
||||
}
|
||||
if (phase == TurnPhase.Execute && _endedTurn) Complete(false);
|
||||
}
|
||||
|
||||
public void Refresh(bool waveCleared, bool runLost)
|
||||
{
|
||||
if (!Visible || _completed) return;
|
||||
if (waveCleared || runLost) Complete(waveCleared);
|
||||
}
|
||||
|
||||
private void Complete(bool waveCleared)
|
||||
{
|
||||
_completed = true;
|
||||
_title.text = "First battle / 4 of 4 / plan the next round";
|
||||
_instruction.text = waveCleared
|
||||
? "Wave cleared! Spend Bits in the repository on cards, upgrades or healing, then continue. Cleared waves earn rewards that are banked when the run ends."
|
||||
: "Check Uptime, Shield and the next enemy intents before your next move. Each completed round refreshes your turn resources. " + (_config?.Distro?.Id == "gentoo" ? "Gentoo's Compilation advances after a completed round, improving damage (and Shield at higher versions), and resets each wave. " : "") + "You can reopen this with '? guide' in dispatch.";
|
||||
if (!_played && _started) _receipt.text = "You can also end a turn without playing a card; the same execution order applies.";
|
||||
_action.text = "Got it";
|
||||
_action.style.display = DisplayStyle.Flex;
|
||||
_skip.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
public void Dismiss()
|
||||
{
|
||||
Element.style.display = DisplayStyle.None;
|
||||
_remember();
|
||||
}
|
||||
|
||||
public static string TrackLesson(RunConfig config)
|
||||
{
|
||||
string lesson = "Native cards execute now.";
|
||||
if (config?.PrimaryLanguage == Language.Python || config?.SecondaryLanguage == Language.Python)
|
||||
lesson += " Your Python cards queue until end turn (first in, first out).";
|
||||
if (config?.PrimaryLanguage == Language.Haskell || config?.SecondaryLanguage == Language.Haskell)
|
||||
lesson += " Your Haskell cards stack until end turn (last in, first out); the multiplier shown on entry scales damage and explicit Shield.";
|
||||
return lesson;
|
||||
}
|
||||
|
||||
private static void Remember()
|
||||
{
|
||||
PlayerPrefs.SetInt(PreferenceKey, 1);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2387eab1278b407bab0ab3c3af35d553
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 039fa8aea1685b643b3f109bf70ec2ff
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0915991bbd2d4fb08d438e4fdae30935
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5b4ca12d26e4e54962ab9f6658e72d2
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27a7f29e93cb4c55beac52f1e32a1bf5
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3049cf231244bd09f80e0f76801ef3b
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using KernelPanic.Data;
|
||||
using KernelPanic.Meta;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
public static class RunHistoryView
|
||||
{
|
||||
public static VisualElement Build(IReadOnlyList<RunHistoryEntry> entries, Action close)
|
||||
=> Build(entries, close, null, null, null, null);
|
||||
|
||||
public static VisualElement Build(IReadOnlyList<RunHistoryEntry> entries, Action close,
|
||||
CardDatabase cards, PackageDatabase packages, Action<RunHistoryEntry> loadBuild,
|
||||
Func<RunHistoryEntry, string> unavailableReason)
|
||||
{
|
||||
var overlay = new VisualElement { name = "RunHistoryOverlay" };
|
||||
overlay.AddToClassList("modal-overlay");
|
||||
overlay.AddToClassList("modal-open");
|
||||
var dialog = new VisualElement();
|
||||
dialog.AddToClassList("root-credit-dialog");
|
||||
dialog.AddToClassList("run-history-dialog");
|
||||
dialog.style.width = Length.Percent(94);
|
||||
dialog.style.maxWidth = 760;
|
||||
dialog.style.maxHeight = Length.Percent(92);
|
||||
overlay.Add(dialog);
|
||||
dialog.Add(SoftwareCardView.Text($"RECENT RUNS / last {RunHistory.Capacity}", "section-title"));
|
||||
dialog.Add(new Label { name = "RunHistoryNotice", enableRichText = false });
|
||||
dialog.Q<Label>("RunHistoryNotice").style.whiteSpace = WhiteSpace.Normal;
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical);
|
||||
scroll.style.flexShrink = 1;
|
||||
scroll.style.flexGrow = 1;
|
||||
scroll.style.minHeight = 0;
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
dialog.Add(scroll);
|
||||
if (entries == null || entries.Count == 0)
|
||||
scroll.Add(Text("No completed runs yet. Your next run report will appear here."));
|
||||
else for (int index = 0; index < entries.Count; index++)
|
||||
{
|
||||
var entry = entries[index];
|
||||
if (entry == null) continue;
|
||||
var item = new VisualElement();
|
||||
item.style.marginBottom = 16;
|
||||
item.Add(Text($"{entry.distroName ?? entry.distroId} V{entry.distroVersion} / {entry.languages}"));
|
||||
item.Add(Text($"Wave {entry.waveReached} reached / {entry.wavesCleared} cleared / seed {entry.seed}"));
|
||||
string when = DateTimeOffset.TryParse(entry.endedUtc, out var time) ? time.ToLocalTime().ToString("g") : entry.endedUtc;
|
||||
item.Add(Text($"{when} / {(entry.victory ? "Victory" : entry.surrendered ? "Shutdown" : "Defeat")}: {entry.cause}"));
|
||||
item.Add(Text(entry.victory && entry.finalRound == 0 ? "Combat recap unavailable after resuming the victory checkpoint."
|
||||
: $"Final round {entry.finalRound}: {entry.damageDealt} uptime dealt / {entry.damageTaken} lost / {entry.shieldBlocked} blocked by shield"));
|
||||
if (entry.finalHits?.Count > 0)
|
||||
{
|
||||
var details = new Foldout { text = "Last incoming hits", value = false };
|
||||
foreach (var hit in entry.finalHits) details.Add(Text(hit));
|
||||
item.Add(details);
|
||||
}
|
||||
var buildDetails = new Foldout { text = "Inspect original build", name = $"ArchivedBuildDetails_{index}", value = false };
|
||||
if (!RunHistory.HasBuildSnapshot(entry))
|
||||
buildDetails.Add(Text("Build snapshot unavailable for this older run. Its deck, packages and languages cannot be reconstructed."));
|
||||
else
|
||||
{
|
||||
var snapshot = entry.build;
|
||||
buildDetails.Add(Text($"Original distro: {entry.distroName ?? snapshot.distroId} V{snapshot.distroVersion}"));
|
||||
buildDetails.Add(Text("Languages: " + (snapshot.languages == null ? "unavailable" : string.Join(" + ", snapshot.languages))));
|
||||
buildDetails.Add(Text($"Original seed: {snapshot.seed.ToString(CultureInfo.InvariantCulture)}"));
|
||||
buildDetails.Add(Text("Selected exclusive cards:"));
|
||||
AddCards(buildDetails, snapshot.exclusiveCardIds, cards);
|
||||
var deck = new Foldout { text = $"Full starting deck ({snapshot.startingDeckCardIds?.Count ?? 0} cards)", value = false };
|
||||
AddCards(deck, snapshot.startingDeckCardIds, cards);
|
||||
buildDetails.Add(deck);
|
||||
buildDetails.Add(Text("Equipped packages (original levels):"));
|
||||
if (snapshot.packages == null || snapshot.packages.Count == 0) buildDetails.Add(Text("None equipped."));
|
||||
else foreach (var package in snapshot.packages)
|
||||
{
|
||||
if (package == null) { buildDetails.Add(Text("Unavailable package entry.")); continue; }
|
||||
var definition = packages == null ? null : packages.FindById(package.packageId);
|
||||
buildDetails.Add(Text($"{package.slot}: {definition?.DisplayName ?? package.packageId} +{package.upgradeLevel}"
|
||||
+ (definition == null ? " (content unavailable)" : "")));
|
||||
}
|
||||
buildDetails.Add(Text("This is the original build, before repository changes. Loading copies its selections and seed into setup using current owned versions and package levels; it does not start a run. Card rules use current content."));
|
||||
}
|
||||
string reason = unavailableReason?.Invoke(entry);
|
||||
if (!RunHistory.HasBuildSnapshot(entry)) reason = "Build snapshot unavailable for this older run.";
|
||||
if (!string.IsNullOrWhiteSpace(reason)) buildDetails.Add(Text(reason));
|
||||
var load = new Button(() => loadBuild?.Invoke(entry)) { text = "load build into setup", name = $"LoadArchivedBuild_{index}", tooltip = reason };
|
||||
load.SetEnabled(RunHistory.HasBuildSnapshot(entry) && loadBuild != null && string.IsNullOrWhiteSpace(reason));
|
||||
load.AddToClassList("terminal-button");
|
||||
buildDetails.Add(load);
|
||||
item.Add(buildDetails);
|
||||
var copySeed = new Button { text = "copy seed", name = $"CopyRunSeed_{index}" };
|
||||
copySeed.AddToClassList("terminal-button");
|
||||
copySeed.clicked += () =>
|
||||
{
|
||||
GUIUtility.systemCopyBuffer = (RunHistory.HasBuildSnapshot(entry) ? entry.build.seed : entry.seed).ToString(CultureInfo.InvariantCulture);
|
||||
copySeed.text = "seed copied";
|
||||
};
|
||||
item.Add(copySeed);
|
||||
scroll.Add(item);
|
||||
}
|
||||
var dismiss = new Button(close) { text = "Close [Esc]", name = "CloseRunHistory" };
|
||||
dismiss.AddToClassList("terminal-button");
|
||||
dismiss.style.flexShrink = 0;
|
||||
dialog.Add(dismiss);
|
||||
TerminalTheme.ConstrainModalFocus(overlay);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
private static void AddCards(VisualElement parent, IReadOnlyList<string> ids, CardDatabase cards)
|
||||
{
|
||||
if (ids == null || ids.Count == 0) { parent.Add(Text("Card list unavailable.")); return; }
|
||||
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
var order = new List<string>();
|
||||
foreach (string id in ids)
|
||||
{
|
||||
string key = string.IsNullOrWhiteSpace(id) ? "unknown card" : id;
|
||||
if (!counts.ContainsKey(key)) { counts[key] = 0; order.Add(key); }
|
||||
counts[key]++;
|
||||
}
|
||||
foreach (string id in order)
|
||||
{
|
||||
var card = cards == null ? null : cards.FindById(id);
|
||||
parent.Add(Text($"{card?.DisplayName ?? id} x{counts[id]}"
|
||||
+ (card == null ? " (content unavailable)" : $" / {card.Language} / {card.CycleCost} base Cycles")));
|
||||
}
|
||||
}
|
||||
|
||||
private static Label Text(string value)
|
||||
{
|
||||
var label = new Label(value) { enableRichText = false };
|
||||
label.style.whiteSpace = WhiteSpace.Normal;
|
||||
label.style.flexShrink = 0;
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f440079df49b3ced275f4c60f6a9f0e
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Repository decisions; all rewards and transitions remain in the run/combat model.</summary>
|
||||
internal static class RunRouteView
|
||||
{
|
||||
public static VisualElement Build(RunManager run, CombatManager combat)
|
||||
{
|
||||
var section = TerminalLayout.Section(run.CampaignChoicePending ? "KERNEL SECURED" : "Next route", "RunRouteChoices");
|
||||
section.AddToClassList("run-route-section");
|
||||
if (!string.IsNullOrEmpty(run.Journey.lastReward)) section.Add(TerminalLayout.BodyText(run.Journey.lastReward));
|
||||
if (run.CampaignChoicePending)
|
||||
{
|
||||
section.Add(TerminalLayout.BodyText("Five waves cleared. Finish this campaign and bank your rewards, or keep this build running in endless mode. Rewards are saved when the run ends."));
|
||||
section.Add(Action("Finish campaign", "FinishCampaignButton", () => combat.CompleteCampaign()));
|
||||
section.Add(Action("Continue into endless", "ContinueEndlessButton", () => combat.ContinueEndless()));
|
||||
return section;
|
||||
}
|
||||
var plan = EncounterDirector.Plan(run.CurrentWaveNumber, run.Journey.selectedRoute);
|
||||
section.Add(TerminalLayout.BodyText($"Wave {run.CurrentWaveNumber}: {plan.Title}"));
|
||||
section.Add(TerminalLayout.BodyText(plan.Advice));
|
||||
var choices = new VisualElement();
|
||||
choices.AddToClassList("route-choices");
|
||||
AddChoice(choices, run, WaveRoute.Repair, "Repair stop",
|
||||
$"Restore up to {RunJourney.RepairUptime} Uptime on departure. Fight the standard encounter.");
|
||||
AddChoice(choices, run, WaveRoute.Challenge, "Elite detour",
|
||||
$"An extra elite Daemon joins the encounter. On clear: +{RunJourney.ChallengeBits} Bits and +1 draw on the first eligible deck card without a draw rider; +{RunJourney.ChallengeBits} extra Bits if none qualify.");
|
||||
section.Add(choices);
|
||||
section.Add(TerminalLayout.BodyText("Choose freely before booting. Repairs and difficulty apply only when you leave; the elite reward requires clearing the wave."));
|
||||
return section;
|
||||
}
|
||||
|
||||
private static void AddChoice(VisualElement parent, RunManager run, WaveRoute route, string title, string detail)
|
||||
{
|
||||
var card = new VisualElement();
|
||||
card.AddToClassList("route-choice");
|
||||
bool selected = run.Journey.selectedRoute == route;
|
||||
card.EnableInClassList("route-selected", selected);
|
||||
card.Add(Action((selected ? "[selected] " : "") + title, "Route" + route,
|
||||
() => run.SelectRoute(route)));
|
||||
card.Add(TerminalLayout.BodyText(detail));
|
||||
parent.Add(card);
|
||||
}
|
||||
|
||||
private static Button Action(string title, string name, Action action)
|
||||
{
|
||||
var button = new Button(action) { text = title, name = name };
|
||||
button.AddToClassList("primary-action");
|
||||
return button;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 856aaec7209048718a4828fd240b9a8b
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bfa65b8d497538499a5b84a4d7a4e9f
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b73ddac91da44a8fb6ba634517d01003
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c81f7c3ea7de425b5ba4adf237c460
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b73ddac91da44a8fb6ba634517d01002
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Shared, wrapping terminal copy. Callers retain their names and contextual classes.</summary>
|
||||
internal static class TerminalLayout
|
||||
{
|
||||
public static VisualElement Section(string title, string name = null, string sectionClass = null, string headingClass = null)
|
||||
{
|
||||
var section = new VisualElement { name = name };
|
||||
section.AddToClassList("terminal-section");
|
||||
AddClasses(section, sectionClass);
|
||||
section.Add(Heading(title, name == null ? null : name + "Heading", headingClass));
|
||||
return section;
|
||||
}
|
||||
|
||||
public static Label Heading(string text, string name = null, string className = null)
|
||||
{
|
||||
var label = new Label(text) { name = name };
|
||||
label.AddToClassList("terminal-heading");
|
||||
AddClasses(label, className);
|
||||
return label;
|
||||
}
|
||||
|
||||
public static VisualElement StatRow(string key, string value, string name = null, string rowClass = null,
|
||||
string keyClass = null, string valueClass = null)
|
||||
{
|
||||
var row = new VisualElement { name = name };
|
||||
row.AddToClassList("terminal-stat-row");
|
||||
AddClasses(row, rowClass);
|
||||
var keyLabel = new Label(key) { name = name == null ? null : name + "Key" };
|
||||
keyLabel.AddToClassList("terminal-stat-key");
|
||||
AddClasses(keyLabel, keyClass);
|
||||
var valueLabel = new Label(value) { name = name == null ? null : name + "Value" };
|
||||
valueLabel.AddToClassList("terminal-stat-value");
|
||||
AddClasses(valueLabel, valueClass);
|
||||
row.Add(keyLabel);
|
||||
row.Add(valueLabel);
|
||||
return row;
|
||||
}
|
||||
|
||||
public static Label BodyText(string text, string name = null, string className = null)
|
||||
{
|
||||
var label = new Label(text) { name = name };
|
||||
label.AddToClassList("terminal-body");
|
||||
AddClasses(label, className);
|
||||
return label;
|
||||
}
|
||||
|
||||
private static void AddClasses(VisualElement element, string classes)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(classes)) return;
|
||||
foreach (var className in classes.Split(' '))
|
||||
if (!string.IsNullOrEmpty(className)) element.AddToClassList(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 249e31573a794e2190b0a13e875114db
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b73ddac91da44a8fb6ba634517d01001
|
||||
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Data;
|
||||
using KernelPanic.Meta;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
internal sealed class TutorialFlow : IDisposable
|
||||
{
|
||||
private readonly VisualElement _overlay;
|
||||
private readonly RunManager _run;
|
||||
private readonly CombatManager _combat;
|
||||
private readonly CardDatabase _cards;
|
||||
private readonly LanguageDeckDatabase _languages;
|
||||
private readonly SaveService _save;
|
||||
private readonly Action _returnToMenu;
|
||||
private TutorialSpotlight _spotlight;
|
||||
private Action _refresh;
|
||||
private int _lesson, _shopStep;
|
||||
private bool _leaving, _resuming;
|
||||
private string _renderKey, _error;
|
||||
public TutorialGuide Guide { get; private set; }
|
||||
public bool Reading => Guide.Reading;
|
||||
public int Lesson => _lesson;
|
||||
|
||||
public TutorialFlow(VisualElement overlay, RunManager run, CombatManager combat, CardDatabase cards,
|
||||
LanguageDeckDatabase languages, SaveService save, RunConfig config, Action returnToMenu)
|
||||
{
|
||||
_overlay = overlay; _run = run; _combat = combat; _cards = cards; _languages = languages;
|
||||
_save = save; _lesson = config.TutorialLesson; _returnToMenu = returnToMenu;
|
||||
_resuming = _lesson == 2;
|
||||
SetGuide(_lesson);
|
||||
}
|
||||
|
||||
public void SetRefresh(Action refresh) => _refresh = refresh;
|
||||
private void Redraw() { if (_refresh != null) _refresh(); else Refresh(); }
|
||||
private void SetGuide(int lesson)
|
||||
{
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
Guide = new TutorialGuide(lesson); _combat.TutorialGuide = Guide;
|
||||
_combat.TutorialReading = true; _renderKey = null;
|
||||
}
|
||||
public void ObserveCard(ResolutionTrack track) => Guide.CardPlayed(track);
|
||||
public void ObserveResolved(ResolutionTrack track) => Guide.CardResolved(track);
|
||||
public void ObservePhase(TurnPhase phase) => Guide.PhaseChanged(phase);
|
||||
public void UpdateState() { if (!_resuming) Guide.Update(_combat); }
|
||||
public void Review() => Redraw();
|
||||
public void AdvancePage() { if (_leaving || _resuming) return; Guide.Acknowledge(_combat); Redraw(); }
|
||||
|
||||
public void ResumeSecondWave()
|
||||
{
|
||||
if (!_resuming) return;
|
||||
_resuming = false;
|
||||
if (!_combat.ContinueTutorialWave()) throw new InvalidDataException("Training checkpoint is not a purchased first-wave shop.");
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (_leaving || _resuming) return;
|
||||
UpdateState();
|
||||
if (Guide.Active && !_combat.RunFinished)
|
||||
{
|
||||
_overlay.RemoveFromClassList("tutorial-overlay");
|
||||
_spotlight ??= new TutorialSpotlight(_overlay, AdvancePage);
|
||||
_spotlight.Show(Guide, _combat);
|
||||
return;
|
||||
}
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
bool cleared = _combat.AwaitingWaveContinue, lost = _combat.RunFinished;
|
||||
if (!cleared && !lost)
|
||||
{
|
||||
_overlay.RemoveFromClassList("tutorial-overlay");
|
||||
_overlay.Clear(); _overlay.style.display = DisplayStyle.None; _renderKey = null;
|
||||
return;
|
||||
}
|
||||
if (cleared && _lesson == 1 && !_run.RepositoryVisitActive)
|
||||
_run.GenerateRepositoryOffers(_cards, _languages);
|
||||
bool purchased = _run.RepositoryOffers.Any(offer => offer.Sold);
|
||||
string key = $"{_lesson}:{cleared}:{lost}:{_shopStep}:{purchased}:{_error}";
|
||||
if (_renderKey == key) return;
|
||||
_renderKey = key;
|
||||
_overlay.Clear(); _overlay.AddToClassList("tutorial-overlay"); _overlay.style.display = DisplayStyle.Flex;
|
||||
var panel = TerminalLayout.Section(lost ? "Practice ended" : _lesson == 1 ? "Wave one cleared / repository" : "Training complete", "TutorialDialog");
|
||||
panel.AddToClassList("tutorial-dialog");
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "TutorialCopy" };
|
||||
scroll.style.flexShrink = 1; scroll.style.minHeight = 0;
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden; panel.Add(scroll);
|
||||
Button action;
|
||||
if (lost)
|
||||
{
|
||||
scroll.Add(TerminalLayout.BodyText("Try again. Wave two restarts from your saved shop purchase; wave one restarts with full Uptime. Your collection is safe."));
|
||||
action = new Button(RestartLesson) { text = "Retry training", name = "TutorialRetry" };
|
||||
}
|
||||
else if (_lesson == 1)
|
||||
{
|
||||
var bits = TerminalLayout.Heading($"{_run.Bits} Bits available", "TutorialShopBits"); scroll.Add(bits);
|
||||
if (_shopStep == 0)
|
||||
{
|
||||
bits.AddToClassList("tutorial-shop-highlight");
|
||||
scroll.Add(TerminalLayout.BodyText("Every enemy is gone. Between waves, the repository is your shop. Spend Bits earned in combat to improve this run; Bits are separate from your permanent currencies."));
|
||||
action = new Button(() => { _shopStep = 1; Redraw(); }) { text = "Show an upgrade", name = "TutorialShopNext" };
|
||||
}
|
||||
else
|
||||
{
|
||||
// A real card patch keeps the five-card teaching hand intact for the scheduler lesson.
|
||||
var offer = _run.RepositoryOffers.FirstOrDefault(item => item.Kind == RepositoryOfferKind.CardUpgrade);
|
||||
if (offer == null) throw new InvalidOperationException("Training shop needs a card upgrade.");
|
||||
var item = new VisualElement(); item.AddToClassList("tutorial-shop-highlight"); scroll.Add(item);
|
||||
item.Add(TerminalLayout.Heading(offer.DisplayName));
|
||||
item.Add(TerminalLayout.BodyText(offer.Description));
|
||||
item.Add(TerminalLayout.BodyText($"Price: {offer.Price} Bits. This patch stays on the card for the rest of this run."));
|
||||
var buy = new Button(() => { _run.BuyOffer(offer, _combat.PlayerState); _renderKey = null; Redraw(); })
|
||||
{ text = purchased ? "Purchased" : $"Buy / {offer.Price} Bits", name = "TutorialBuy" };
|
||||
buy.SetEnabled(!purchased && _run.Bits >= offer.Price); item.Add(buy);
|
||||
scroll.Add(TerminalLayout.BodyText(purchased
|
||||
? "Upgrade installed. Your remaining Uptime, deck and purchase carry into wave two. Normal shops also sell new cards and stat upgrades."
|
||||
: "Buy this upgrade to practice spending Bits. Then start the next wave."));
|
||||
action = new Button(Continue) { text = "Start wave two", name = "TutorialContinue" };
|
||||
action.SetEnabled(purchased);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scroll.Add(TerminalLayout.BodyText("Both waves are clear. You have completed the combat → shop → combat loop."));
|
||||
scroll.Add(TerminalLayout.Heading($"+{TutorialCampaign.BandwidthReward:N0} Bandwidth"));
|
||||
scroll.Add(TerminalLayout.Heading($"+{TutorialCampaign.EntropyReward:N0} Entropy"));
|
||||
scroll.Add(TerminalLayout.BodyText("Enough Entropy for one standard 10-pull. This training reward is granted once per profile."));
|
||||
action = new Button(Continue) { text = "Claim rewards & finish", name = "TutorialContinue" };
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_error)) scroll.Add(TerminalLayout.BodyText("Could not save: " + _error + " Retry to continue.", "TutorialSaveError"));
|
||||
action.AddToClassList("primary-action"); panel.Add(action);
|
||||
panel.RegisterCallback<KeyDownEvent>(evt => evt.StopPropagation());
|
||||
TerminalTheme.ConstrainModalFocus(panel); _overlay.Add(panel);
|
||||
(panel.Q<Button>("TutorialBuy") is { enabledSelf: true } buyButton ? buyButton : action).Focus();
|
||||
}
|
||||
|
||||
public void Continue()
|
||||
{
|
||||
if (_leaving || Guide.Active || !_combat.AwaitingWaveContinue || _combat.RunFinished) return;
|
||||
if (_lesson == 1 && !_run.RepositoryOffers.Any(offer => offer.Sold)) return;
|
||||
if (_lesson == 2 && _run.WavesCleared < 2) return;
|
||||
try
|
||||
{
|
||||
var data = _save.Load();
|
||||
if (!TutorialCampaign.Required(data)) throw new InvalidOperationException("Training is not active.");
|
||||
if (_lesson == 1)
|
||||
{
|
||||
data.tutorialCheckpoint = _run.CaptureCheckpoint(_combat);
|
||||
data.tutorialLesson = 2;
|
||||
}
|
||||
else TutorialCampaign.Complete(data);
|
||||
_save.Save(data);
|
||||
_error = null;
|
||||
if (_lesson == 2) { _leaving = true; _returnToMenu(); return; }
|
||||
_lesson = 2; SetGuide(2);
|
||||
if (!_combat.ContinueTutorialWave()) throw new InvalidOperationException("Wave two could not start. Restart to resume the saved shop.");
|
||||
Redraw();
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is InvalidOperationException || ex is OverflowException)
|
||||
{ _error = ex.Message; _renderKey = null; Redraw(); }
|
||||
}
|
||||
|
||||
public void RestartLesson() { if (!_leaving) { _leaving = true; _returnToMenu(); } }
|
||||
public void Dispose()
|
||||
{
|
||||
_spotlight?.Dispose(); _spotlight = null;
|
||||
_combat.TutorialGuide = null; _combat.TutorialReading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da5f5d9d31e643e5a865d0d37a18420d
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Four pointer-blocking shades leave only the highlighted action exposed.</summary>
|
||||
internal sealed class TutorialSpotlight : IDisposable
|
||||
{
|
||||
private readonly VisualElement _root, _overlay, _outline, _panel;
|
||||
private readonly VisualElement[] _shades = new VisualElement[4];
|
||||
private readonly Label _title, _copy, _progress;
|
||||
private readonly Button _next;
|
||||
private readonly IVisualElementScheduledItem _placement;
|
||||
private TutorialGuide _guide;
|
||||
private VisualElement _anchor;
|
||||
private int _index = -1;
|
||||
private bool _disposed;
|
||||
public VisualElement Anchor => _anchor;
|
||||
|
||||
public TutorialSpotlight(VisualElement overlay, Action next)
|
||||
{
|
||||
_overlay = overlay; _root = overlay.parent ?? overlay;
|
||||
_overlay.Clear(); _overlay.AddToClassList("guided-overlay");
|
||||
_overlay.pickingMode = PickingMode.Ignore;
|
||||
_root.AddToClassList("tutorial-guided");
|
||||
for (int i = 0; i < _shades.Length; i++)
|
||||
{ _shades[i] = new VisualElement(); _shades[i].AddToClassList("tutorial-shade"); _overlay.Add(_shades[i]); }
|
||||
_outline = new VisualElement { name = "TutorialHighlight", pickingMode = PickingMode.Ignore };
|
||||
_outline.AddToClassList("tutorial-highlight"); _overlay.Add(_outline);
|
||||
_panel = new VisualElement { name = "TutorialCallout" };
|
||||
_panel.AddToClassList("tutorial-callout");
|
||||
_progress = TerminalLayout.BodyText("", "TutorialStepCount"); _panel.Add(_progress);
|
||||
_title = TerminalLayout.Heading("", "TutorialStepTitle"); _panel.Add(_title);
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical) { name = "TutorialStepScroll" };
|
||||
scroll.style.flexShrink = 1; scroll.style.minHeight = 0;
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
_copy = TerminalLayout.BodyText("", "TutorialInstruction"); scroll.Add(_copy); _panel.Add(scroll);
|
||||
_next = new Button(next) { name = "TutorialNext", text = "Next" };
|
||||
_next.AddToClassList("primary-action"); _panel.Add(_next); _overlay.Add(_panel);
|
||||
_root.RegisterCallback<NavigationMoveEvent>(TrapFocus, TrickleDown.TrickleDown);
|
||||
_placement = _overlay.schedule.Execute(Place).Every(33);
|
||||
}
|
||||
|
||||
public void Show(TutorialGuide guide, CombatManager combat)
|
||||
{
|
||||
_guide = guide; _overlay.style.display = DisplayStyle.Flex;
|
||||
_root.EnableInClassList("tutorial-card-focus", guide.Step.Anchor == "card");
|
||||
_anchor = ResolveAnchor();
|
||||
_progress.text = $"Wave {combat.RunConfig.TutorialLesson}/2 / step {guide.Index + 1} of {guide.Count}";
|
||||
_title.text = guide.Step.Title; _copy.text = guide.Step.Copy;
|
||||
_next.style.display = guide.Reading ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
_next.SetEnabled(combat.TutorialInputReady);
|
||||
if (_index != guide.Index)
|
||||
{
|
||||
_index = guide.Index;
|
||||
_panel.Q<ScrollView>().scrollOffset = Vector2.zero;
|
||||
_overlay.schedule.Execute(() =>
|
||||
{
|
||||
if (_disposed) return;
|
||||
_anchor = ResolveAnchor();
|
||||
for (var ancestor = _anchor?.parent; ancestor != null; ancestor = ancestor.parent)
|
||||
if (ancestor is ScrollView scroll) scroll.ScrollTo(_anchor);
|
||||
FocusAction(); Place();
|
||||
});
|
||||
}
|
||||
Place();
|
||||
}
|
||||
|
||||
private VisualElement ResolveAnchor()
|
||||
{
|
||||
if (_guide?.Step == null) return null;
|
||||
string key = _guide.Step.Anchor;
|
||||
if (key == "card") return _root.Query<Button>(className: "hand-card").ToList().FirstOrDefault(button => button.userData == _guide.Card);
|
||||
if (key is "zombie" or "zombie-intent" or "enemy" || key.StartsWith("enemy:", StringComparison.Ordinal))
|
||||
{
|
||||
string id = key.StartsWith("enemy:", StringComparison.Ordinal) ? key.Substring(6) : null;
|
||||
var enemy = _root.Query<Button>(className: "enemy-card").ToList().FirstOrDefault(button => button.userData is EnemyInstance instance
|
||||
&& (id != null ? instance.ArchetypeId == id : ReferenceEquals(instance, _guide.Enemy)));
|
||||
return key == "zombie-intent" ? enemy?.Q("ProcessIntent") : enemy;
|
||||
}
|
||||
if (key == "enemies") return _root.Q(className: "enemy-row");
|
||||
return _root.Q(key);
|
||||
}
|
||||
|
||||
private void FocusAction()
|
||||
{
|
||||
if (_guide?.Reading == true) _next.Focus();
|
||||
else if (_anchor is Button button && button.enabledInHierarchy) button.Focus();
|
||||
}
|
||||
|
||||
private void TrapFocus(NavigationMoveEvent evt)
|
||||
{
|
||||
if (_guide?.Active != true || evt.direction is not (NavigationMoveEvent.Direction.Next or NavigationMoveEvent.Direction.Previous)) return;
|
||||
_root.panel?.focusController.IgnoreEvent(evt); evt.StopImmediatePropagation(); FocusAction();
|
||||
}
|
||||
|
||||
private void Place()
|
||||
{
|
||||
if (_guide?.Active != true || _overlay.panel == null) return;
|
||||
_anchor = ResolveAnchor();
|
||||
float w = _overlay.resolvedStyle.width, h = _overlay.resolvedStyle.height;
|
||||
if (float.IsNaN(w) || w < 1 || h < 1) return;
|
||||
Rect hole = new(w / 2, h / 2, 0, 0);
|
||||
if (_anchor != null)
|
||||
{
|
||||
Rect bounds = _anchor.worldBound;
|
||||
for (var parent = _anchor.parent; parent != null; parent = parent.parent)
|
||||
if (parent is ScrollView scroll) bounds = Intersection(bounds, scroll.contentViewport.worldBound);
|
||||
Vector2 min = _overlay.WorldToLocal(bounds.min), max = _overlay.WorldToLocal(bounds.max);
|
||||
hole = Rect.MinMaxRect(Mathf.Clamp(min.x - 3, 0, w), Mathf.Clamp(min.y - 3, 0, h),
|
||||
Mathf.Clamp(max.x + 3, 0, w), Mathf.Clamp(max.y + 3, 0, h));
|
||||
}
|
||||
Position(_outline, hole);
|
||||
Position(_shades[0], new Rect(0, 0, w, hole.yMin));
|
||||
Position(_shades[1], new Rect(0, hole.yMax, w, h - hole.yMax));
|
||||
Position(_shades[2], new Rect(0, hole.yMin, hole.xMin, hole.height));
|
||||
Position(_shades[3], new Rect(hole.xMax, hole.yMin, w - hole.xMax, hole.height));
|
||||
Rect[] spaces = {
|
||||
new(10, 10, w - 20, Mathf.Max(0, hole.yMin - 20)),
|
||||
new(10, hole.yMax + 10, w - 20, Mathf.Max(0, h - hole.yMax - 20)),
|
||||
new(10, 10, Mathf.Max(0, hole.xMin - 20), h - 20),
|
||||
new(hole.xMax + 10, 10, Mathf.Max(0, w - hole.xMax - 20), h - 20)
|
||||
};
|
||||
var space = spaces.Where(rect => rect.width >= 180 && rect.height >= 95)
|
||||
.OrderByDescending(rect => Mathf.Min(rect.width, 370) * Mathf.Min(rect.height, 240)).FirstOrDefault();
|
||||
if (space.width <= 0) space = new Rect(10, 10, w - 20, Mathf.Min(180, h - 20));
|
||||
float width = Mathf.Min(370, space.width), height = Mathf.Min(240, space.height);
|
||||
Position(_panel, new Rect(space.center.x - width / 2, space.center.y - height / 2, width, height));
|
||||
}
|
||||
|
||||
private static Rect Intersection(Rect a, Rect b) => Rect.MinMaxRect(Mathf.Max(a.xMin, b.xMin), Mathf.Max(a.yMin, b.yMin),
|
||||
Mathf.Max(Mathf.Max(a.xMin, b.xMin), Mathf.Min(a.xMax, b.xMax)), Mathf.Max(Mathf.Max(a.yMin, b.yMin), Mathf.Min(a.yMax, b.yMax)));
|
||||
private static void Position(VisualElement element, Rect rect)
|
||||
{ element.style.left = rect.x; element.style.top = rect.y; element.style.width = Mathf.Max(0, rect.width); element.style.height = Mathf.Max(0, rect.height); }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
_placement.Pause(); _root.UnregisterCallback<NavigationMoveEvent>(TrapFocus, TrickleDown.TrickleDown);
|
||||
_root.RemoveFromClassList("tutorial-guided"); _overlay.RemoveFromClassList("guided-overlay");
|
||||
_root.RemoveFromClassList("tutorial-card-focus");
|
||||
_overlay.pickingMode = PickingMode.Position; _overlay.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2509fb282fdb0784498d2f39318d8e45
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1efef5d7a1b485493c2f30d64644898
|
||||
Reference in New Issue
Block a user