using UnityEngine; using UnityEngine.UIElements; namespace Soundings { public sealed partial class SoundingsApp { private static readonly string[] PassageServices = { "rooms", "meals", "drinks", "shows", "amenities", "retail" }; private readonly Label[] passageDemand = new Label[PassageServices.Length]; private readonly Label[] passagePrices = new Label[PassageServices.Length]; private readonly Button[] passageSpecials = new Button[PassageServices.Length]; private readonly Button[] passageMinus = new Button[PassageServices.Length]; private readonly Button[] passagePlus = new Button[PassageServices.Length]; private bool passageBusinessOpen = true; private VisualElement passageProgress, passageEventHost; private Label passageRemaining, passageHappiness, passageHealth, passageSupplies, passageSales, passageEventClock, passageEventResult, passagePerformance; 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")); DrawShorePlanningLink(opener, underway, true); if (passageBusinessOpen) DrawPassageBusiness(left); else { passageHappiness = null; passageSales = null; passageHealth = null; passageSupplies = null; passagePerformance = 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 decks = Add(overlay, "voyage-deck-stack"); decks.pickingMode = PickingMode.Ignore; AddText(decks, "DECK VIEW", "voyage-caption voyage-deck-caption"); AddPassageDeckButton(decks, -1, "Exterior", "passage-deck-all"); for (int i = Ship.Decks.Count - 1; i >= 0; i--) AddPassageDeckButton(decks, i, $"Deck {i + 1}", $"passage-deck-{i}"); var footer = Add(overlay, "voyage-footer"); footer.pickingMode = PickingMode.Ignore; var controls = Add(footer, "voyage-deckbar"); controls.pickingMode = PickingMode.Ignore; 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")); Button map = Action("Voyage map", ToggleVoyageMap, PassageViewClass(voyageMapOpen), "voyage-map-toggle"); map.tooltip = "Show or close the live voyage map (M)"; controls.Add(map); 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(footer, "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"); string leg = Ship.Itinerary is { HasNext: true } itinerary ? $"LEG {itinerary.CompletedStops + 1} OF {itinerary.TotalStops}" : "UNDERWAY"; AddText(routeContext, $"{leg} / {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"); crewCallReadout = AddText(route, "", "crew-call-readout"); 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"); string cameraHelp = passageBridge && passageHelm.Manual ? "Right-drag to look · Q / E to turn" : passageBridge || passageExploring ? "WASD to walk · Q / E to turn" : "Drag or Q / E to orbit · Wheel to zoom · Middle-drag to pan"; AddText(camera, cameraHelp, "voyage-camera-help"); rail.Add(Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now")); DrawHelmControls(overlay); DrawStationInteractions(overlay); DrawVoyageMap(overlay); DrawAnnouncement(overlay); UpdatePassageUi(passageHelm.Progress); } 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; if (service == OnboardService.Retail && Ship.RetailCapacity == 0) { passageDemand[i] = null; continue; } 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.Shows && underway.Plan?.Program is EntertainmentProgram.LiveMusic or EntertainmentProgram.Headline) passagePerformance = AddText(entry, "", "voyage-service-included"); 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%", () => StartPassageSpecial(service), "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 * passageHelm.RemainingSeconds / PassageDuration(underway)); int seconds = Mathf.CeilToInt(passageHelm.RemainingSeconds / (passageSpeed * livePassage.SpeedFactor)); string status = passageHelm.PropulsionStopped ? "Engines stopped" : $"{seconds / 60}:{seconds % 60:00} estimated"; string remaining = $"{miles:N0} nm remaining · {status}"; if (passageRemaining.text != remaining) passageRemaining.text = remaining; if (Time.unscaledTime >= nextPassageReadout || livePassage.CurrentEvent?.Title != passageEventTitle) { nextPassageReadout = Time.unscaledTime + .12f; RefreshPassageBusiness(); RefreshPassageEvent(); UpdateCrewCall(); } } 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)); if (passagePerformance != null) SetPassageText(passagePerformance, livePassage.PerformanceLabel); for (int i = 0; i < PassageServices.Length; i++) { if (passageDemand[i] == null) continue; 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) { VoyageEvent? chosen = accept && livePassage.CanAcceptEvent ? livePassage.CurrentEvent : null; livePassage.ResolveEvent(accept); if (chosen?.Service == (int)OnboardService.Meals) passageAudio.Announce(PassageAnnouncement.Dining); else if (chosen?.Service == (int)OnboardService.Shows) passageAudio.Announce(PassageAnnouncement.Show); RefreshPassageBusiness(); RefreshPassageEvent(); } } }