Make Soundings voyages playable with ship operations and guided tips

This commit is contained in:
josh
2026-11-27 22:24:17 -05:00
parent 4b870fb0ce
commit 33cdd6dfa7
37 changed files with 2734 additions and 126 deletions

View File

@@ -0,0 +1,292 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace Soundings
{
public sealed partial class SoundingsApp
{
private static readonly string[] PassageServices = { "rooms", "meals", "drinks", "shows", "amenities" };
private readonly Label[] passageDemand = new Label[5];
private readonly Label[] passagePrices = new Label[5];
private readonly Button[] passageSpecials = new Button[5];
private readonly Button[] passageMinus = new Button[5];
private readonly Button[] passagePlus = new Button[5];
private bool passageBusinessOpen = true;
private VisualElement passageProgress, passageEventHost;
private Label passageRemaining, passageHappiness, passageHealth, passageSupplies, passageSales, passageEventClock, passageEventResult;
private float renderedPassageProgress = -1, nextPassageReadout;
private Button passageEventAccept;
private string passageEventTitle;
private void DrawUnderway(VisualElement workspace)
{
var overlay = Add(workspace, "voyage-overlay");
overlay.pickingMode = PickingMode.Ignore;
var left = Add(overlay, "voyage-business");
left.pickingMode = PickingMode.Ignore;
var opener = Add(left, "voyage-business-opener");
opener.pickingMode = PickingMode.Ignore;
opener.Add(Action(passageBusinessOpen ? "Onboard service −" : "Onboard service +", () =>
{
passageBusinessOpen = !passageBusinessOpen;
Render();
}, "voyage-drawer-toggle", "passage-business"));
if (passageBusinessOpen)
DrawPassageBusiness(left);
else
{
passageHappiness = null;
passageSales = null;
passageHealth = null;
passageSupplies = null;
for (int i = 0; i < PassageServices.Length; i++)
{
passageDemand[i] = null;
passagePrices[i] = null;
passageSpecials[i] = null;
passageMinus[i] = null;
passagePlus[i] = null;
}
}
passageEventHost = Add(overlay, "voyage-event-host");
passageEventHost.pickingMode = PickingMode.Ignore;
passageEventTitle = null;
passageEventClock = null;
passageEventAccept = null;
passageEventResult = null;
var controls = Add(overlay, "voyage-deckbar");
controls.pickingMode = PickingMode.Ignore;
AddText(controls, "SHIP VIEW", "voyage-caption voyage-deck-caption");
AddPassageDeckButton(controls, -1, "Exterior", "passage-deck-all");
for (int i = 0; i < Ship.Decks.Count; i++)
AddPassageDeckButton(controls, i, $"Deck {i + 1}", $"passage-deck-{i}");
controls.Add(Action("Bridge", ViewPassageBridge, PassageViewClass(passageBridge), "passage-bridge"));
controls.Add(Action("Explore", ExplorePassageDeck, PassageViewClass(passageExploring && passageServiceArea < 0), "passage-explore"));
controls.Add(Action("Service deck", () => ExploreServiceArea(0), PassageViewClass(passageServiceArea >= 0), "passage-service"));
controls.Add(Action("Reset camera", () =>
{
if (passageBridge)
ViewPassageBridge();
else if (passageServiceArea >= 0)
ExploreServiceArea(passageServiceArea);
else if (passageExploring)
ExplorePassageDeck();
else
harbor.ResetView();
}, "voyage-view-button voyage-reset", "passage-camera-reset"));
var rail = Add(overlay, "voyage-rail");
var route = Add(rail, "voyage-route");
string sea = underway.Weather switch
{
WeatherCondition.Storm => "Storm · Open decks closed",
WeatherCondition.Swell => "Swell · Limited outdoor service",
_ => "Calm seas"
};
var routeContext = Add(route, "voyage-route-context");
AddText(routeContext, $"UNDERWAY / {underway.ShipName.ToUpperInvariant()}", "voyage-caption");
AddText(routeContext, sea, underway.Weather == WeatherCondition.Storm
? "voyage-conditions voyage-conditions-warning" : "voyage-conditions");
AddDisplay(route, $"{Market.Ports[underway.Origin].Name} → {Market.Ports[underway.Destination].Name}", "voyage-route-name");
passageRemaining = AddText(route, "", "voyage-remaining");
var progress = Add(route, "voyage-progress");
passageProgress = Add(progress, "voyage-progress-fill");
renderedPassageProgress = -1;
nextPassageReadout = 0;
var speed = Add(rail, "voyage-speed");
AddText(speed, "SIMULATION SPEED", "voyage-caption");
var speeds = Add(speed, "voyage-speed-buttons");
foreach (int multiplier in new[] { 1, 2, 4 })
{
int requested = multiplier;
speeds.Add(Action($"{requested}×", () => SetPassageSpeed(requested),
requested == passageSpeed ? "voyage-view-button voyage-control-active" : "voyage-view-button",
$"passage-speed-{requested}"));
}
var camera = Add(rail, "voyage-camera");
AddText(camera, "CAMERA", "voyage-caption");
AddText(camera, passageBridge || passageExploring || passageServiceArea >= 0
? "WASD to walk · Right-drag to look"
: "Wheel to zoom · Hold RMB + WASD / Q E to fly", "voyage-camera-help");
rail.Add(Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now"));
UpdatePassageUi(Mathf.Clamp01(passageElapsed / PassageDuration(underway)));
}
private void DrawPassageBusiness(VisualElement left)
{
var book = Add(left, "voyage-business-book");
var metrics = Add(book, "voyage-business-metrics");
var happiness = Add(metrics, "voyage-business-metric");
AddText(happiness, "GUEST HAPPINESS", "voyage-caption");
passageHappiness = AddDisplay(happiness, "", "voyage-business-value");
var health = Add(metrics, "voyage-business-metric");
AddText(health, "HEALTH", "voyage-caption");
passageHealth = AddDisplay(health, "", "voyage-business-value");
var sales = Add(metrics, "voyage-business-metric");
AddText(sales, "TAKINGS", "voyage-caption");
passageSales = AddDisplay(sales, "", "voyage-business-value");
passageSupplies = AddText(book, "", "voyage-provisions");
for (int i = 0; i < PassageServices.Length; i++)
{
OnboardService service = (OnboardService)i;
string slug = PassageServices[i];
var entry = Add(book, "voyage-service");
var line = Add(entry, "voyage-service-line");
AddText(line, OnboardSession.ServiceLabel(service), "voyage-service-name");
passageDemand[i] = AddText(line, "", "voyage-service-demand");
if (service == OnboardService.Amenities && underway.Weather == WeatherCondition.Storm)
AddText(entry, "Outdoor venues closed", "voyage-service-included voyage-demand-short");
if (service == OnboardService.Rooms)
{
AddText(entry, "Included in the booked fare", "voyage-service-included");
continue;
}
var prices = Add(entry, "voyage-price-row");
passageMinus[i] = Action("−", () => AdjustPassagePrice(service, -1), "voyage-price-step", $"passage-price-{slug}-minus");
passageMinus[i].tooltip = "Lower the onboard price by $1";
prices.Add(passageMinus[i]);
passagePrices[i] = AddText(prices, "", "voyage-service-price");
passagePlus[i] = Action("+", () => AdjustPassagePrice(service, 1), "voyage-price-step", $"passage-price-{slug}-plus");
passagePlus[i].tooltip = "Raise the onboard price by $1";
prices.Add(passagePlus[i]);
passageSpecials[i] = Action("Special −25%", () =>
{
livePassage.StartSpecial(service);
RefreshPassageBusiness();
}, "voyage-special", $"passage-special-{slug}");
prices.Add(passageSpecials[i]);
}
AddText(book, "Guests served / requesting right now", "voyage-metric-help");
}
private void AddPassageDeckButton(VisualElement controls, int deck, string text, string id)
{
bool active = deck == passageDeck && !passageBridge && !passageExploring && passageServiceArea < 0;
controls.Add(Action(text, () => SelectPassageDeck(deck), PassageViewClass(active), id));
}
private static string PassageViewClass(bool active) => active
? "voyage-view-button voyage-control-active" : "voyage-view-button";
private static void SetPassageText(Label label, string text)
{
if (label.text != text)
label.text = text;
}
private void AdjustPassagePrice(OnboardService service, int delta)
{
livePassage.ChangePrice(service, delta);
RefreshPassageBusiness();
}
private void UpdatePassageUi(float progress)
{
if (underway == null || livePassage == null || passageProgress == null || passageRemaining == null)
return;
if (Mathf.Abs(progress - renderedPassageProgress) >= .002f)
{
passageProgress.style.width = Length.Percent(100 * progress);
renderedPassageProgress = progress;
}
int miles = Mathf.RoundToInt(underway.Miles * (1 - progress));
int seconds = Mathf.CeilToInt((1 - progress) * PassageDuration(underway) / (passageSpeed * livePassage.SpeedFactor));
string remaining = $"{miles:N0} nm remaining · {seconds / 60}:{seconds % 60:00} to arrival";
if (passageRemaining.text != remaining)
passageRemaining.text = remaining;
if (Time.unscaledTime >= nextPassageReadout || livePassage.CurrentEvent?.Title != passageEventTitle)
{
nextPassageReadout = Time.unscaledTime + .12f;
RefreshPassageBusiness();
RefreshPassageEvent();
}
}
private void RefreshPassageBusiness()
{
if (livePassage == null || passageHappiness == null)
return;
SetPassageText(passageHappiness, $"{livePassage.Happiness}/100");
SetPassageText(passageHealth, $"{livePassage.Health}/100");
SetPassageText(passageSupplies, $"Provisions remaining · {livePassage.ProvisionsRemaining:N0}");
SetPassageText(passageSales, Money(livePassage.Revenue));
for (int i = 0; i < PassageServices.Length; i++)
{
OnboardService service = (OnboardService)i;
OnboardSample demand = livePassage.Get(service);
SetPassageText(passageDemand[i], $"{demand.Served:N0} / {demand.Requested:N0} guests");
passageDemand[i].EnableInClassList("voyage-demand-short", demand.Served < demand.Requested);
if (i == 0)
continue;
int price = livePassage.GetPrice(service);
int ticks = livePassage.DiscountTicks(service);
SetPassageText(passagePrices[i], ticks > 0 ? Money(Mathf.Max(1, price * 3 / 4)) : Money(price));
passageMinus[i].SetEnabled(price > 0 && demand.Capacity > 0);
passagePlus[i].SetEnabled(demand.Capacity > 0);
string offer = ticks > 0 ? $"Special · {ticks} left" : "Special −25%";
if (passageSpecials[i].text != offer)
passageSpecials[i].text = offer;
passagePrices[i].tooltip = ticks > 0 ? $"Regular price: {Money(price)}" : "";
passageSpecials[i].SetEnabled(price > 0 && demand.Capacity > 0 && ticks == 0);
}
}
private void RefreshPassageEvent()
{
if (passageEventHost == null)
return;
VoyageEvent? current = livePassage.CurrentEvent;
string title = current?.Title;
if (title != passageEventTitle || title == null && passageEventResult == null && !string.IsNullOrEmpty(livePassage.EventResult))
{
passageEventTitle = title;
passageEventHost.Clear();
passageEventClock = null;
passageEventAccept = null;
passageEventResult = null;
if (current.HasValue)
{
VoyageEvent offer = current.Value;
var card = Add(passageEventHost, "voyage-event");
AddText(card, "DECK OPERATIONS", "voyage-caption");
AddDisplay(card, offer.Title, "voyage-event-title");
AddText(card, offer.Detail, "voyage-event-copy");
AddText(card, "Adds temporary service capacity and lifts guest happiness.", "voyage-event-impact");
passageEventClock = AddText(card, "", "voyage-event-clock");
passageEventAccept = Action($"{offer.Action} · {Money(offer.Cost)}", () => DecidePassageEvent(true),
"voyage-event-accept", "passage-event-0");
card.Add(passageEventAccept);
card.Add(Action(offer.Alternative, () => DecidePassageEvent(false), "voyage-event-decline", "passage-event-1"));
}
else if (!string.IsNullOrEmpty(livePassage.EventResult))
{
var result = Add(passageEventHost, "voyage-event voyage-event-result");
passageEventResult = AddText(result, livePassage.EventResult, "voyage-event-copy");
}
}
if (passageEventClock != null)
{
int ticks = livePassage.RemainingEventTicks;
SetPassageText(passageEventClock, $"{ticks} service {(ticks == 1 ? "round" : "rounds")} remaining");
passageEventAccept.SetEnabled(livePassage.CanAcceptEvent);
}
else if (passageEventResult != null)
SetPassageText(passageEventResult, livePassage.EventResult);
}
private void DecidePassageEvent(bool accept)
{
livePassage.ResolveEvent(accept);
RefreshPassageBusiness();
RefreshPassageEvent();
}
}
}