add C++, Typescript and more stuff
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Core;
|
||||
using KernelPanic.Data;
|
||||
@@ -69,6 +70,8 @@ namespace KernelPanic.UI
|
||||
private ExecutionTrackView _queueView;
|
||||
private ExecutionTrackView _stackView;
|
||||
private ExecutionPreviewView _executionPreview;
|
||||
private TurnResolutionView _turnResolution;
|
||||
private CombatExecutionTrace _executionTrace;
|
||||
private Label _encounterBrief;
|
||||
private float _journalStartedAt;
|
||||
private readonly Dictionary<EnemyInstance, Button> _enemyCards = new();
|
||||
@@ -153,10 +156,16 @@ namespace KernelPanic.UI
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_campaignUnlocksSaved = false;
|
||||
_campaignUnlockNotice = _campaignUnlockError = null;
|
||||
_executionTrace?.Dispose();
|
||||
_executionTrace = new CombatExecutionTrace(_combatManager);
|
||||
_turnResolution?.Bind(_executionTrace);
|
||||
_runTelemetry?.Dispose();
|
||||
_runTelemetry = new CombatRunTelemetry(() => _combatManager.PlayerState, DescribeDamageSource)
|
||||
{
|
||||
SurrenderRequested = () => _combatManager.RunEndedBySurrender
|
||||
SurrenderRequested = () => _combatManager.RunEndedBySurrender,
|
||||
PerformanceSource = () => _runManager.Performance
|
||||
};
|
||||
_queueView ??= new ExecutionTrackView(_interpreterStrip, false);
|
||||
_stackView ??= new ExecutionTrackView(_lazyStackPile, true);
|
||||
@@ -296,6 +305,9 @@ namespace KernelPanic.UI
|
||||
_feedbackLayer?.Clear();
|
||||
_runTelemetry?.Dispose();
|
||||
_runTelemetry = null;
|
||||
_turnResolution?.Dispose();
|
||||
_executionTrace?.Dispose();
|
||||
_executionTrace = null;
|
||||
}
|
||||
|
||||
private void HandleKeyDown(KeyDownEvent evt)
|
||||
@@ -464,6 +476,8 @@ namespace KernelPanic.UI
|
||||
workspace.Add(_encounterBrief);
|
||||
_executionPreview = new ExecutionPreviewView();
|
||||
workspace.Add(_executionPreview.Element);
|
||||
_turnResolution = new TurnResolutionView();
|
||||
workspace.Add(_turnResolution.Element);
|
||||
VisualElement main = new();
|
||||
main.AddToClassList("main-layout");
|
||||
workspace.Add(main);
|
||||
@@ -691,6 +705,7 @@ namespace KernelPanic.UI
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
PersistCampaignUnlocks();
|
||||
if (_combatManager.PlayerState == null)
|
||||
{
|
||||
return;
|
||||
@@ -1253,6 +1268,7 @@ namespace KernelPanic.UI
|
||||
languages = $"{config?.PrimaryLanguage} + {config?.SecondaryLanguage}",
|
||||
seed = config?.RunSeed ?? 0,
|
||||
build = RunHistory.CaptureBuild(config),
|
||||
finalDeck = _runManager.FinalDeck ?? _runManager.RunDeck.Select(CheckpointCard.Capture).ToList(),
|
||||
waveReached = _combatManager.RunCompleted ? _runManager.WavesCleared : _runManager.CurrentWaveNumber,
|
||||
wavesCleared = _runManager.WavesCleared,
|
||||
surrendered = _runEndedBySurrender || _combatManager.RunEndedBySurrender,
|
||||
@@ -1461,530 +1477,6 @@ namespace KernelPanic.UI
|
||||
_overlay.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
private VisualElement BuildRunEndOverlay()
|
||||
{
|
||||
_runEndedBySurrender |= _combatManager.RunEndedBySurrender;
|
||||
VisualElement screen = new();
|
||||
screen.AddToClassList("death-overlay");
|
||||
screen.EnableInClassList("death-surrender", _runEndedBySurrender);
|
||||
screen.EnableInClassList("run-victory", _combatManager.RunCompleted);
|
||||
|
||||
if (!_runEndOverlayPresented)
|
||||
{
|
||||
_runEndOverlayPresented = true;
|
||||
if (!UIPreferences.ReducedMotion && !_combatManager.RunCompleted)
|
||||
{
|
||||
VisualElement beat = new();
|
||||
beat.AddToClassList("death-crash-beat");
|
||||
screen.Add(beat);
|
||||
screen.schedule.Execute(() => beat.AddToClassList("death-crash-beat-settled")).StartingIn(25);
|
||||
screen.schedule.Execute(() => beat.RemoveFromHierarchy()).StartingIn(260);
|
||||
}
|
||||
}
|
||||
|
||||
VisualElement content = new();
|
||||
content.AddToClassList("death-content");
|
||||
|
||||
var config = _runManager.CurrentConfig;
|
||||
VisualElement reportHeader = new();
|
||||
reportHeader.AddToClassList("death-report-header");
|
||||
reportHeader.Add(SoftwareCardView.Text("RUN REPORT", "death-eyebrow"));
|
||||
reportHeader.Add(SoftwareCardView.Text($"seed {config?.RunSeed ?? 0}", "death-seed"));
|
||||
content.Add(reportHeader);
|
||||
content.Add(OverlayTitle(_combatManager.RunCompleted ? "KERNEL SECURED" : _runEndedBySurrender ? "SYSTEM HALTED" : "KERNEL PANIC"));
|
||||
|
||||
var report = GetRunHistoryEntry();
|
||||
string cause = report.cause;
|
||||
Label causeLabel = OverlayLine(cause);
|
||||
causeLabel.AddToClassList("death-cause");
|
||||
content.Add(causeLabel);
|
||||
if (config?.Distro != null)
|
||||
content.Add(SoftwareCardView.Text($"{DisplayName(config.Distro)} V{config.DistroVersion} / {config.PrimaryLanguage} + {config.SecondaryLanguage}", "death-session"));
|
||||
|
||||
VisualElement summary = new();
|
||||
summary.AddToClassList("death-section");
|
||||
summary.AddToClassList("death-summary");
|
||||
summary.AddToClassList("death-wave-stats");
|
||||
summary.Add(DeathStat("wave reached", report.waveReached.ToString()));
|
||||
summary.Add(DeathStat("waves cleared", _runManager.WavesCleared.ToString()));
|
||||
content.Add(summary);
|
||||
|
||||
bool recapUnavailable = report.victory && report.finalRound == 0;
|
||||
content.Add(SoftwareCardView.Text(recapUnavailable ? "COMBAT RECAP" : $"FINAL ROUND {report.finalRound}", "death-eyebrow"));
|
||||
var recap = new VisualElement();
|
||||
recap.AddToClassList("death-section");
|
||||
recap.Add(OverlayLine(recapUnavailable ? "Combat recap unavailable after resuming this checkpoint."
|
||||
: $"{report.damageDealt} uptime dealt / {report.damageTaken} uptime lost / {report.shieldBlocked} blocked by shield"));
|
||||
if (report.finalHits.Count > 0)
|
||||
{
|
||||
var hits = new Foldout { text = "Last incoming hits (up to 8)", value = false };
|
||||
foreach (string hit in report.finalHits) hits.Add(OverlayLine(hit));
|
||||
recap.Add(hits);
|
||||
}
|
||||
content.Add(recap);
|
||||
|
||||
content.Add(SoftwareCardView.Text("RECOVERED RESOURCES", "death-eyebrow"));
|
||||
VisualElement rewards = new();
|
||||
rewards.AddToClassList("death-section");
|
||||
rewards.AddToClassList("death-rewards");
|
||||
rewards.Add(RewardReadout("#", _runManager.AccruedBandwidth, "bandwidth", false));
|
||||
rewards.Add(RewardReadout("*", _runManager.AccruedEntropy, "entropy", _runManager.AccruedEntropy <= 0));
|
||||
content.Add(rewards);
|
||||
content.Add(SoftwareCardView.Text("Return to your collection to prepare the next run.", "death-next-run"));
|
||||
|
||||
Button returnButton = new(() => SceneLoader.LoadMainMenu(_root)) { text = "> return to menu" };
|
||||
returnButton.AddToClassList("primary-action");
|
||||
returnButton.AddToClassList("death-return-action");
|
||||
if (!string.IsNullOrEmpty(_saveError))
|
||||
{
|
||||
content.Add(OverlayLine((_runManager.RewardsSettled ? "Could not reload saved progress: " : "Rewards are not saved yet: ") + _saveError));
|
||||
var retrySave = new Button(() => { SettleRunRewardsIfNeeded(); Refresh(); }) { text = "Retry saving rewards" };
|
||||
content.Add(retrySave);
|
||||
returnButton.SetEnabled(_runManager.RewardsSettled);
|
||||
}
|
||||
content.Add(returnButton);
|
||||
|
||||
var scroll = new ScrollView(ScrollViewMode.Vertical);
|
||||
scroll.AddToClassList("death-scroll");
|
||||
scroll.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
|
||||
// Center within the actual viewport, including Unity's internal ScrollView wrapper.
|
||||
// A minimum (not fixed) height lets short windows scroll the entire report.
|
||||
scroll.contentContainer.style.alignItems = Align.Center;
|
||||
scroll.contentContainer.style.justifyContent = Justify.Center;
|
||||
scroll.contentViewport.RegisterCallback<GeometryChangedEvent>(evt =>
|
||||
scroll.contentContainer.style.minHeight = evt.newRect.height);
|
||||
scroll.Add(content);
|
||||
screen.Add(scroll);
|
||||
return screen;
|
||||
}
|
||||
|
||||
private void SettleRunRewardsIfNeeded()
|
||||
{
|
||||
if (_runManager?.CurrentConfig?.IsTutorial == true) return;
|
||||
if (_runManager == null || _saveService == null || _runManager.IsSuspended || _runManager.CurrentConfig == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_runManager.RewardsSettled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SaveData data = _saveService.Load();
|
||||
data.bandwidthBalance = Math.Max(0, data.bandwidthBalance) + _runManager.AccruedBandwidth;
|
||||
data.entropyBalance = Math.Max(0, data.entropyBalance) + _runManager.AccruedEntropy;
|
||||
data.RecordRunStats(_runManager.CurrentConfig?.Distro?.Id,
|
||||
_combatManager.RunCompleted ? _runManager.WavesCleared : _runManager.CurrentWaveNumber);
|
||||
if (_combatManager.RunFinished) RunHistory.Record(data.recentRuns, GetRunHistoryEntry());
|
||||
if (data.activeRun?.runId == _runManager.RunId) data.activeRun = null;
|
||||
_saveService.Save(data);
|
||||
_lastKnownSave = data;
|
||||
_runManager.MarkRunRewardsSettled();
|
||||
_saveError = null;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_saveError = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private VisualElement BuildRepositoryView()
|
||||
{
|
||||
VisualElement repo = new();
|
||||
repo.AddToClassList("repository");
|
||||
repo.AddToClassList("screen-frame");
|
||||
repo.Add(BuildRepositoryHeader());
|
||||
|
||||
ScrollView body = new(ScrollViewMode.Vertical);
|
||||
body.AddToClassList("repository-body");
|
||||
body.AddToClassList("screen-frame-content");
|
||||
|
||||
VisualElement offers = new();
|
||||
offers.AddToClassList("repository-offers");
|
||||
if (_runManager.RepositoryOffers.Count == 0)
|
||||
{
|
||||
offers.Add(EmptyState("repository clean: no offers left this visit"));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < _runManager.RepositoryOffers.Count; i++)
|
||||
{
|
||||
offers.Add(RepositoryOfferTile(_runManager.RepositoryOffers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
body.Add(offers);
|
||||
body.Add(RemoveCardBlock());
|
||||
repo.Add(body);
|
||||
|
||||
VisualElement footer = new();
|
||||
footer.AddToClassList("repository-footer");
|
||||
footer.AddToClassList("screen-frame-footer");
|
||||
Button reroll = new(() => _runManager.RerollRepositoryOffers(cardDatabase, languageDeckDatabase))
|
||||
{
|
||||
text = $"apt update {_runManager.RerollCost} bits"
|
||||
};
|
||||
reroll.AddToClassList("primary-action");
|
||||
reroll.AddToClassList("repository-footer-action");
|
||||
reroll.AddToClassList("repository-reroll-action");
|
||||
reroll.EnableInClassList("repo-unaffordable", _runManager.Bits < _runManager.RerollCost);
|
||||
reroll.SetEnabled(_runManager.Bits >= _runManager.RerollCost);
|
||||
footer.Add(reroll);
|
||||
|
||||
Button leave = new(() =>
|
||||
{
|
||||
if (_runManager.Journey.campaign) SetRouteSelectionOpen(true);
|
||||
else _combatManager.ContinueToNextWave();
|
||||
}) { name = "BootNextWaveButton", text = "> boot next-wave" };
|
||||
leave.AddToClassList("primary-action");
|
||||
leave.AddToClassList("repository-leave-action");
|
||||
leave.SetEnabled(!_runManager.IsSuspended);
|
||||
VisualElement leaveBlock = new();
|
||||
leaveBlock.AddToClassList("repository-leave-block");
|
||||
leaveBlock.Add(leave);
|
||||
Label banked = new($"{_runManager.Bits} bits remaining");
|
||||
banked.AddToClassList("repository-banked-hint");
|
||||
banked.AddToClassList("screen-frame-hint");
|
||||
leaveBlock.Add(banked);
|
||||
var suspend = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save & exit" };
|
||||
suspend.AddToClassList("primary-action");
|
||||
suspend.AddToClassList("repository-leave-action");
|
||||
suspend.SetEnabled(!_runManager.IsSuspended);
|
||||
leaveBlock.Add(suspend);
|
||||
if (!string.IsNullOrEmpty(_checkpointError))
|
||||
leaveBlock.Add(TerminalLayout.BodyText("Save failed: " + _checkpointError + " Stay here and retry.", className: "screen-frame-hint"));
|
||||
footer.Add(leaveBlock);
|
||||
repo.Add(footer);
|
||||
return repo;
|
||||
}
|
||||
|
||||
private void SetRouteSelectionOpen(bool open)
|
||||
{
|
||||
_routeSelectionOpen = open;
|
||||
_routeEventOpen = false;
|
||||
RefreshOverlay();
|
||||
_overlay.Q<Button>(open ? "BackToRepositoryButton" : "BootNextWaveButton")?.Focus();
|
||||
}
|
||||
|
||||
private VisualElement BuildRouteSelectionView()
|
||||
{
|
||||
bool reward = _runManager.BuildRewardPending;
|
||||
bool eventScreen = !reward && _routeEventOpen && !_runManager.CampaignChoicePending;
|
||||
bool committed = eventScreen && !_runManager.RouteEventPending;
|
||||
var screen = new VisualElement { name = reward ? "BuildRewardScreen" : eventScreen ? "RouteEventScreen" : "RouteSelectionScreen" };
|
||||
screen.AddToClassList("repository");
|
||||
screen.AddToClassList("screen-frame");
|
||||
screen.AddToClassList("route-map-screen");
|
||||
var header = new VisualElement();
|
||||
header.AddToClassList("repository-header");
|
||||
header.AddToClassList("screen-frame-header");
|
||||
var copy = new VisualElement();
|
||||
copy.AddToClassList("repository-header-copy");
|
||||
var title = new Label(_runManager.CampaignChoicePending ? "campaign complete" : reward ? "claim your build reward"
|
||||
: eventScreen ? RunRouteMap.Title(_runManager.Journey.selectedRoute) : "choose your route");
|
||||
title.AddToClassList("screen-frame-title");
|
||||
copy.Add(title);
|
||||
var subtitle = new Label(_runManager.CampaignChoicePending
|
||||
? "bank your rewards or continue into endless"
|
||||
: reward ? "1. claim reward > 2. choose route > 3. enter stop"
|
||||
: eventScreen ? committed ? "stop complete. ready for battle" : "choose your cards. nothing changes until you confirm"
|
||||
: $"preparing wave {_runManager.CurrentWaveNumber} {_runManager.Bits} bits remaining");
|
||||
subtitle.AddToClassList("repository-subtitle");
|
||||
copy.Add(subtitle);
|
||||
header.Add(copy);
|
||||
screen.Add(header);
|
||||
|
||||
var body = new ScrollView(ScrollViewMode.Vertical);
|
||||
body.AddToClassList("repository-body");
|
||||
body.AddToClassList("screen-frame-content");
|
||||
body.Add(reward ? RunRouteView.BuildReward(_runManager)
|
||||
: eventScreen ? RunMapView.BuildEvent(_runManager) : RunRouteView.Build(_runManager, _combatManager));
|
||||
if (!reward && !eventScreen && !_runManager.CampaignChoicePending)
|
||||
{
|
||||
body.AddToClassList("route-map-body");
|
||||
body.contentViewport.RegisterCallback<GeometryChangedEvent>(evt =>
|
||||
{
|
||||
var mapScroll = body.Q<ScrollView>("RouteMapScroll");
|
||||
if (mapScroll != null)
|
||||
mapScroll.style.height = Mathf.Max(260, evt.newRect.height - 20);
|
||||
});
|
||||
}
|
||||
if (committed)
|
||||
{
|
||||
var save = new Button(SaveAndExitRun) { name = "SaveAndExitRunButton", text = "save and exit" };
|
||||
save.AddToClassList("secondary-action"); body.Add(save);
|
||||
}
|
||||
screen.Add(body);
|
||||
|
||||
var footer = new VisualElement();
|
||||
footer.AddToClassList("screen-frame-footer");
|
||||
footer.AddToClassList("route-map-footer");
|
||||
var back = new Button(() =>
|
||||
{
|
||||
if (!eventScreen) SetRouteSelectionOpen(false);
|
||||
else if (_runManager.RouteEventPending)
|
||||
{
|
||||
_routeEventOpen = false; RefreshOverlay();
|
||||
_overlay.Q<Button>("ConfirmRouteButton")?.Focus();
|
||||
}
|
||||
})
|
||||
{ name = eventScreen ? "BackToRouteButton" : "BackToRepositoryButton",
|
||||
text = committed ? "stop committed" : eventScreen ? "< back to map" : "< back to repository" };
|
||||
back.SetEnabled(!committed);
|
||||
back.AddToClassList("primary-action");
|
||||
back.AddToClassList("route-map-back");
|
||||
footer.Add(back);
|
||||
screen.RegisterCallback<KeyDownEvent>(evt =>
|
||||
{
|
||||
if (evt.keyCode != KeyCode.Escape || !back.enabledSelf) return;
|
||||
using var submit = NavigationSubmitEvent.GetPooled();
|
||||
submit.target = back; back.SendEvent(submit); evt.StopPropagation();
|
||||
});
|
||||
void MoveAction(string name, string caption = null)
|
||||
{
|
||||
var button = body.Q<Button>(name);
|
||||
if (button == null) return;
|
||||
button.RemoveFromHierarchy();
|
||||
if (caption != null) button.text = caption;
|
||||
if (name == "ResolveRouteEventButton")
|
||||
{
|
||||
string fullCaption = button.text;
|
||||
button.RegisterCallback<GeometryChangedEvent>(evt => button.text = evt.newRect.width < 160 ? "apply" : fullCaption);
|
||||
}
|
||||
button.AddToClassList("primary-action");
|
||||
button.AddToClassList(name is "ClaimBuildRewardButton" or "ResolveRouteEventButton" ? "route-map-continue" : "route-map-back");
|
||||
footer.Add(button);
|
||||
}
|
||||
if (reward)
|
||||
{
|
||||
back.text = "< back"; back.tooltip = "Back to repository";
|
||||
MoveAction("RewardBits", $"{RunManager.BuildRewardBits} Bits");
|
||||
MoveAction("ClaimBuildRewardButton", "claim");
|
||||
}
|
||||
else if (eventScreen && !committed)
|
||||
{
|
||||
back.text = "< map";
|
||||
MoveAction("SkipRouteEventButton", "pass");
|
||||
MoveAction("ResolveRouteEventButton");
|
||||
}
|
||||
else if (!_runManager.CampaignChoicePending)
|
||||
{
|
||||
var confirm = new Button(() =>
|
||||
{
|
||||
if (_runManager.RouteEventPending && !eventScreen)
|
||||
{
|
||||
_routeEventOpen = true; RefreshOverlay();
|
||||
_overlay.Q<Button>("BackToRouteButton")?.Focus();
|
||||
}
|
||||
else _combatManager.ContinueToNextWave();
|
||||
})
|
||||
{
|
||||
name = "ConfirmRouteButton",
|
||||
text = eventScreen ? committed ? "> continue to battle" : "confirm or pass above"
|
||||
: _runManager.RouteEventPending ? "> enter stop" : "> continue to battle"
|
||||
};
|
||||
confirm.AddToClassList("primary-action");
|
||||
confirm.AddToClassList("route-map-continue");
|
||||
confirm.SetEnabled((!eventScreen || committed) && !_runManager.IsSuspended);
|
||||
footer.Add(confirm);
|
||||
}
|
||||
screen.Add(footer);
|
||||
if (committed) screen.schedule.Execute(() => screen.Q<Button>("ConfirmRouteButton")?.Focus());
|
||||
return screen;
|
||||
}
|
||||
|
||||
private void SaveAndExitRun()
|
||||
{
|
||||
if (_runManager.IsSuspended || !_combatManager.AwaitingWaveContinue) return;
|
||||
try
|
||||
{
|
||||
if (_dailyQuestTracker?.Flush() == false)
|
||||
throw new IOException("Daily quest progress: " + _dailyQuestTracker.SaveError);
|
||||
RunCheckpointService.SaveAndSuspend(_saveService, _runManager, _combatManager);
|
||||
_checkpointError = null;
|
||||
_overlay.SetEnabled(false);
|
||||
SceneLoader.LoadMainMenu(_root);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException || ex is InvalidDataException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
_checkpointError = ex.Message;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private VisualElement BuildRepositoryHeader()
|
||||
{
|
||||
VisualElement header = new();
|
||||
header.AddToClassList("repository-header");
|
||||
header.AddToClassList("screen-frame-header");
|
||||
|
||||
VisualElement copy = new();
|
||||
copy.AddToClassList("repository-header-copy");
|
||||
Label title = new("repository");
|
||||
title.AddToClassList("repository-title");
|
||||
title.AddToClassList("screen-frame-title");
|
||||
Label subtitle = new($"wave {_runManager.CurrentWaveNumber - 1} cleared / {_runManager.RepositoryOffers.Count} packages indexed");
|
||||
subtitle.AddToClassList("repository-subtitle");
|
||||
copy.Add(title);
|
||||
copy.Add(subtitle);
|
||||
|
||||
VisualElement wallet = new();
|
||||
wallet.AddToClassList("repository-wallet");
|
||||
Label walletLabel = new("available bits");
|
||||
walletLabel.AddToClassList("status-label");
|
||||
Label walletValue = new($"◆ {_runManager.Bits}");
|
||||
walletValue.AddToClassList("repository-wallet-value");
|
||||
wallet.Add(walletLabel);
|
||||
wallet.Add(walletValue);
|
||||
|
||||
header.Add(copy);
|
||||
header.Add(wallet);
|
||||
return header;
|
||||
}
|
||||
|
||||
private VisualElement RepositoryOfferTile(RepositoryOffer offer)
|
||||
{
|
||||
VisualElement tile = new();
|
||||
tile.AddToClassList("repository-tile");
|
||||
tile.AddToClassList(OfferTileClass(offer.Kind));
|
||||
bool unavailable = offer.Sold || _runManager.Bits < offer.Price;
|
||||
tile.EnableInClassList("repo-unaffordable", unavailable);
|
||||
tile.EnableInClassList("repo-sold", offer.Sold);
|
||||
|
||||
VisualElement top = new();
|
||||
top.AddToClassList("repository-tile-top");
|
||||
Label kind = new($"{OfferKindIcon(offer.Kind)} {OfferKindText(offer.Kind)}");
|
||||
kind.AddToClassList("repository-kind");
|
||||
top.Add(kind);
|
||||
top.Add(PriceBadge(offer.Price, unavailable));
|
||||
tile.Add(top);
|
||||
|
||||
VisualElement content = offer.Kind switch
|
||||
{
|
||||
RepositoryOfferKind.NewCard => CardOfferContent(offer),
|
||||
RepositoryOfferKind.CardUpgrade => UpgradeOfferContent(offer),
|
||||
RepositoryOfferKind.StatUpgrade => StatOfferContent(offer),
|
||||
_ => GenericOfferContent(offer)
|
||||
};
|
||||
tile.Add(content);
|
||||
|
||||
Button buy = new(() => _runManager.BuyOffer(offer, _combatManager.PlayerState))
|
||||
{
|
||||
text = offer.Sold ? "installed" : OfferActionText(offer.Kind)
|
||||
};
|
||||
buy.tooltip = OfferCommandText(offer);
|
||||
buy.AddToClassList("repository-action");
|
||||
buy.SetEnabled(!offer.Sold && _runManager.Bits >= offer.Price);
|
||||
tile.Add(buy);
|
||||
return tile;
|
||||
}
|
||||
|
||||
private VisualElement CardOfferContent(RepositoryOffer offer)
|
||||
{
|
||||
VisualElement content = new();
|
||||
content.AddToClassList("repository-card-content");
|
||||
CardInstance preview = new(offer.CardDefinition);
|
||||
VisualElement card = CardFaceView(preview);
|
||||
card.AddToClassList("repository-card-preview");
|
||||
content.Add(card);
|
||||
|
||||
if (offer.CardDefinition != null && offer.CardDefinition.IsRunOnly)
|
||||
{
|
||||
content.Add(Tag("run-only", "repository-run-only-tag"));
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
private VisualElement UpgradeOfferContent(RepositoryOffer offer)
|
||||
{
|
||||
VisualElement content = new();
|
||||
content.AddToClassList("repository-upgrade-content");
|
||||
if (offer.TargetCard != null)
|
||||
{
|
||||
VisualElement target = CardFaceView(offer.TargetCard);
|
||||
target.AddToClassList("repository-upgrade-card");
|
||||
content.Add(target);
|
||||
}
|
||||
|
||||
VisualElement delta = new();
|
||||
delta.AddToClassList("repository-delta");
|
||||
Label arrow = new("▲");
|
||||
arrow.AddToClassList("repository-delta-icon");
|
||||
Label text = new(offer.Description);
|
||||
text.AddToClassList("repository-delta-text");
|
||||
delta.Add(arrow);
|
||||
delta.Add(text);
|
||||
content.Add(delta);
|
||||
return content;
|
||||
}
|
||||
|
||||
private VisualElement StatOfferContent(RepositoryOffer offer)
|
||||
{
|
||||
VisualElement content = new();
|
||||
content.AddToClassList("repository-stat-content");
|
||||
Label icon = new(StatOfferIcon(offer.StatUpgradeKind));
|
||||
icon.AddToClassList("repository-stat-icon");
|
||||
Label name = new(offer.DisplayName);
|
||||
name.AddToClassList("repository-name");
|
||||
Label description = new(offer.Description);
|
||||
description.AddToClassList("repository-description");
|
||||
content.Add(icon);
|
||||
content.Add(name);
|
||||
content.Add(description);
|
||||
return content;
|
||||
}
|
||||
|
||||
private static VisualElement GenericOfferContent(RepositoryOffer offer)
|
||||
{
|
||||
VisualElement content = new();
|
||||
Label name = new(offer.DisplayName);
|
||||
name.AddToClassList("repository-name");
|
||||
Label description = new(offer.Description);
|
||||
description.AddToClassList("repository-description");
|
||||
content.Add(name);
|
||||
content.Add(description);
|
||||
return content;
|
||||
}
|
||||
|
||||
private static VisualElement PriceBadge(int price, bool warning)
|
||||
{
|
||||
Label badge = new($"◆ {price}");
|
||||
badge.AddToClassList("repository-price");
|
||||
badge.EnableInClassList("repository-price-warning", warning);
|
||||
return badge;
|
||||
}
|
||||
|
||||
private VisualElement RemoveCardBlock()
|
||||
{
|
||||
VisualElement block = new();
|
||||
block.AddToClassList("repository-remove");
|
||||
Label title = new($"installed deck maintenance / remove for {CombatTuning.RemoveCardCost} bit");
|
||||
title.AddToClassList("repository-name");
|
||||
block.Add(title);
|
||||
|
||||
VisualElement rows = new();
|
||||
rows.AddToClassList("repository-remove-list");
|
||||
for (int i = 0; i < _runManager.RunDeck.Count; i++)
|
||||
{
|
||||
CardInstance card = _runManager.RunDeck[i];
|
||||
Button remove = new(() => _runManager.RemoveCard(card))
|
||||
{
|
||||
text = $"apt remove {DisplayName(card.Definition)}"
|
||||
};
|
||||
remove.AddToClassList("repo-remove-button");
|
||||
remove.EnableInClassList("repo-unaffordable", _runManager.Bits < CombatTuning.RemoveCardCost || _runManager.RunDeck.Count <= 1);
|
||||
remove.SetEnabled(_runManager.Bits >= CombatTuning.RemoveCardCost && _runManager.RunDeck.Count > 1);
|
||||
rows.Add(remove);
|
||||
}
|
||||
|
||||
block.Add(rows);
|
||||
return block;
|
||||
}
|
||||
|
||||
private VisualElement CardFace(CardInstance card)
|
||||
{
|
||||
Button button = new(() =>
|
||||
|
||||
Reference in New Issue
Block a user