using UnityEngine; using UnityEngine.UIElements; namespace Soundings { public sealed partial class SoundingsApp { private static readonly (int HullIndex, bool Used)[] Offers = { (0, true), (0, false), (1, true), (1, false), (2, false) }; private void DrawDecks(VisualElement pageRoot) { Ship ship = Ship; if (ship == null) { var empty = Card(pageRoot, "Choose a vessel first"); empty.Add(Action("Open shipyard →", () => ChangePage(2), "primary")); return; } var stats = Add(pageRoot, "deck-stats card"); ForecastMetric(stats, "CABIN BERTHS", ship.Beds.ToString("N0")); ForecastMetric(stats, "DAILY MEAL CAPACITY", ship.Meals.ToString("N0")); ForecastMetric(stats, "SHOW SEATS", ship.Entertainment.ToString("N0")); ForecastMetric(stats, "BUNKER CAPACITY", $"{ship.Tank} t"); var workbench = Add(pageRoot, "columns second-row"); var plan = Card(workbench, ship.Name, "wide deck-card"); var tabs = Add(plan, "deck-tabs"); for (int i = 0; i < ship.Decks.Count; i++) { int floor = i; tabs.Add(Action($"Deck {i + 1}", () => { deckIndex = floor; Notify(null); Render(); }, deckIndex == i ? "active-option" : "", $"deck-{i}")); } int price = company.DeckPrice(ship); Button add = Action($"+ Deck · {Money(price)}", () => Apply(company.AddDeck(ship), "Added a new deck."), "add-deck", "add-deck"); add.SetEnabled(ship.Decks.Count < ship.Hull.MaxDecks && company.Cash >= price); tabs.Add(add); var diagram = Add(plan, "blueprint"); var axes = Add(diagram, "axes"); AddText(axes, "STERN", "eyebrow"); AddText(axes, $"DECK {deckIndex + 1:00} / {ship.Hull.Columns * ship.Hull.Rows} MODULE BERTHS", "eyebrow deck-axis"); AddText(axes, "BOW →", "eyebrow"); for (int row = 0; row < ship.Hull.Rows; row++) { var strip = Add(diagram, "cell-row"); for (int column = 0; column < ship.Hull.Columns; column++) { int cell = row * ship.Hull.Columns + column; Facility room = ship.Decks[deckIndex].Cells[cell]; string label = $"{(char)('A' + row)}{column + 1}"; Button berth = Action("", () => { Facility previous = ship.Decks[deckIndex].Cells[cell]; string success = tool == Facility.Empty ? $"Cleared berth {label}." : $"Built {Market.Facilities[(int)tool].Name.ToLowerInvariant()} at {label}."; Apply(company.Build(ship, deckIndex, cell, tool), previous == tool ? null : success); }, "berth room-" + (int)room, "berth-" + cell); bool occupied = room != Facility.Empty; FacilitySpec spec = Market.Facilities[(int)room]; berth.tooltip = $"{label} · {(occupied ? spec.Name : "Empty berth")}"; AddText(berth, label, "cell-label"); AddText(berth, occupied ? spec.Mark : "+", "cell-mark"); strip.Add(berth); } } AddText(plan, $"The current plan serves up to {ship.Capacity:N0} guests per voyage.", "body-copy deck-hint"); var exterior = Add(plan, "exterior-preview"); AddHarbor(exterior); var catalog = Card(workbench, "Facilities", "narrow"); for (int i = 1; i <= Market.Facilities.Count; i++) { int type = i % Market.Facilities.Count; FacilitySpec spec = Market.Facilities[type]; Button option = Action("", () => { tool = (Facility)type; Notify(null); Render(); }, tool == (Facility)type ? "facility active-option" : "facility", "facility-" + type); AddText(option, spec.Mark, "facility-mark room-" + type); var details = Add(option, "facility-details"); AddText(details, spec.Name, "facility-title"); AddText(details, spec.Details, "muted"); AddText(option, type > 0 ? Money(spec.Price) : "", "facility-price gold"); catalog.Add(option); } } private void DrawShipyard(VisualElement pageRoot) { var columns = Add(pageRoot, "columns"); var inventory = Card(columns, "Available hulls", "wide"); for (int item = 0; item < Offers.Length; item++) { int selection = item; var offer = Offers[item]; HullSpec hull = Market.Hulls[offer.HullIndex]; Button option = Action("", () => { yardSelection = selection; Notify(null); Render(); }, selection == yardSelection ? "yard-item active-option" : "yard-item", "yard-" + item); var itemCopy = Add(option, "yard-copy"); AddText(itemCopy, offer.Used ? $"Pre-owned {hull.Name}" : $"New {hull.Name}", "option-title"); AddText(itemCopy, offer.Used ? "Fitted with cabins, dining and entertainment. Condition 72%." : hull.Description, "muted"); AddText(option, Money(offer.Used ? Market.UsedPrice(offer.HullIndex) : hull.Price), "yard-price gold"); inventory.Add(option); } (int hullIndex, bool secondhand) = Offers[yardSelection]; HullSpec chosen = Market.Hulls[hullIndex]; var purchase = Card(columns, secondhand ? "Take delivery" : "Commission a hull", "narrow"); AddLine(purchase, "Hull class", chosen.Name); AddLine(purchase, "Decks at delivery", Market.FirstDecks.ToString()); AddLine(purchase, "Maximum decks", chosen.MaxDecks.ToString()); AddLine(purchase, "Module berths / deck", (chosen.Columns * chosen.Rows).ToString()); AddLine(purchase, "Base fuel capacity", $"{chosen.Tank} t"); AddLine(purchase, "Delivery port", "Miami"); if (!secondhand) { AddText(purchase, "VESSEL NAME", "eyebrow control-label"); var field = new TextField { value = shipName, maxLength = 24, name = "vessel-name" }; field.AddToClassList("field"); field.RegisterValueChangedCallback(evt => shipName = evt.newValue); purchase.Add(field); } string block = company.ShipyardBlock(hullIndex, secondhand); Button buy = Action(secondhand ? "Purchase vessel →" : "Commission hull →", () => { string failure = company.Acquire(hullIndex, secondhand, shipName); if (failure == null) { deckIndex = 0; ResetItinerary(); page = secondhand ? 0 : 1; } Apply(failure, secondhand ? "The vessel is ready in Miami." : "The hull is ready. Fit cabins and dining before sailing."); }, "primary full-button", "buy-ship"); buy.SetEnabled(block == null); if (block != null) AddText(purchase, block, "body-copy"); purchase.Add(buy); if (Ship == null) return; Ship ship = Ship; var service = Card(pageRoot, "Maintenance", "second-row"); var condition = Add(service, "maintenance-row"); AddText(condition, $"{ship.Name} · {ship.Condition}% condition", "body-copy"); int price = company.ServiceCost(ship); Button overhaul = Action($"Overhaul · {Money(price)}", () => { string failure = company.Service(ship); if (failure == null) SetRecommendedFuel(); Apply(failure, "The ship has been restored to 100% condition."); }, "", "overhaul"); overhaul.SetEnabled(price > 0 && company.Cash >= price); condition.Add(overhaul); } } }