using UnityEngine; using UnityEngine.UIElements; namespace Soundings { public sealed partial class SoundingsApp { private int inspectedPort = 1; private int selectedVoyage; private bool worldChart; private void DrawPorts(VisualElement pageRoot) { var columns = Add(pageRoot, "columns"); var chartCard = Card(columns, "Shipping lanes", "wide"); var scope = Add(chartCard, "deck-tabs"); scope.Add(Action("Atlantic", () => ChangeChart(false), worldChart ? "" : "active-option", "chart-atlantic")); scope.Add(Action("World", () => ChangeChart(true), worldChart ? "active-option" : "", "chart-world")); var chart = Add(chartCard, "chart"); var labels = Add(chartCard, "chart-legend"); AddText(labels, "● Permit held", "gain"); AddText(labels, "● Permit required", "gold"); chart.generateVisualContent += DrawChart; for (int i = 0; i < ChartPortCount; i++) { int portId = i; PortSpec port = Market.Ports[i]; var marker = Action("●", () => { inspectedPort = portId; Notify(null); Render(); }, company.Permits[i] ? "map-port gain" : "map-port gold", "map-" + i); Vector2 point = ChartPoint(port); marker.style.left = Length.Percent(point.x * 100); marker.style.top = Length.Percent(point.y * 100); marker.EnableInClassList("active-option", i == inspectedPort); marker.tooltip = port.Name; chart.Add(marker); } PortSpec current = Market.Ports[inspectedPort]; var portInfo = Card(columns, current.Name, "narrow"); AddText(portInfo, $"{current.Country} / {current.Region}", "muted"); AddLine(portInfo, "Bunker price", $"{Money(Market.FuelPrice(inspectedPort, company.Day))} / t"); AddLine(portInfo, "Arrival dues", Money(current.Fee)); AddLine(portInfo, "Destination appeal", $"{current.Appeal:P0}"); AddLine(portInfo, "Minimum hull", Market.Hulls[current.MinimumHull].Name); bool licensed = company.Permits[inspectedPort]; AddLine(portInfo, "Port access", licensed ? "Permit held" : "Permit required", licensed ? "gain" : "gold"); if (!licensed) { int portId = inspectedPort; string blocker = company.PermitBlock(portId); Button license = Action($"Acquire permit · {Money(current.Permit)}", () => { string failure = company.Permit(portId); if (failure == null && destination < 0) ResetItinerary(); Apply(failure, $"{current.Name} is now licensed."); }, "primary full-button", "permit"); license.SetEnabled(blocker == null); portInfo.Add(license); if (blocker != null) AddText(portInfo, blocker, "body-copy"); } if (Ship != null && Market.TryDistance(Ship.Port, inspectedPort, out int miles)) { AddLine(portInfo, $"From {Market.Ports[Ship.Port].Name}", $"{miles:N0} nm"); Button plan = Action("Plan this sailing →", () => { destination = inspectedPort; SetRecommendedFuel(); ChangePage(0); }, "full-button", "plan-port"); portInfo.Add(plan); } var index = Card(pageRoot, "Port directory", "second-row"); var grid = Add(index, "port-grid"); for (int i = 0; i < ChartPortCount; i++) { int portId = i; PortSpec port = Market.Ports[i]; Button option = Action("", () => { inspectedPort = portId; Notify(null); Render(); }, inspectedPort == i ? "port-row active-option" : "port-row", "port-" + i); AddText(option, port.Name, "option-title"); AddText(option, $"{port.Country} · {Money(Market.FuelPrice(i, company.Day))}/t", company.Permits[i] ? "muted" : "gold"); grid.Add(option); } } private int ChartPortCount => worldChart ? Market.Ports.Count : Market.StarterPortCount; private void ChangeChart(bool global) { worldChart = global; if (inspectedPort >= ChartPortCount) inspectedPort = Market.Lisbon; Notify(null); Render(); } private Vector2 ChartPoint(PortSpec port) => worldChart ? new Vector2((port.Longitude + 180) / 360, (76 - port.Latitude) / 137) : new Vector2(port.MapX, port.MapY); private void DrawChart(MeshGenerationContext context) { VisualElement chart = context.visualElement; float width = chart.contentRect.width; float height = chart.contentRect.height; Vector2 Point(float x, float y) => new Vector2(width * x, height * y); Painter2D painter = context.painter2D; painter.strokeColor = new Color(.18f, .32f, .36f); painter.lineWidth = 1; painter.BeginPath(); for (int i = 1; i < 12; i++) { painter.MoveTo(Point(i / 12f, 0)); painter.LineTo(Point(i / 12f, 1)); } for (int i = 1; i < 7; i++) { painter.MoveTo(Point(0, i / 7f)); painter.LineTo(Point(1, i / 7f)); } painter.Stroke(); void Polygon(Vector2[] points) { painter.BeginPath(); painter.MoveTo(Point(points[0].x, points[0].y)); for (int i = 1; i < points.Length; i++) painter.LineTo(Point(points[i].x, points[i].y)); painter.ClosePath(); painter.Fill(); painter.Stroke(); } painter.fillColor = new Color(.15f, .28f, .29f); painter.strokeColor = new Color(.30f, .43f, .42f); if (worldChart) { foreach (Vector2[] continent in WorldCoastlines.Shapes) Polygon(continent); } else { Polygon(new[] { new Vector2(0,0), new Vector2(.30f,0), new Vector2(.27f,.12f), new Vector2(.26f,.26f), new Vector2(.23f,.33f), new Vector2(.20f,.46f), new Vector2(.15f,.52f), new Vector2(.13f,.60f), new Vector2(.15f,.68f), new Vector2(.12f,.74f), new Vector2(.10f,.64f), new Vector2(.08f,.57f), new Vector2(.02f,.54f), new Vector2(0,.60f) }); Polygon(new[] { new Vector2(1,0), new Vector2(.84f,0), new Vector2(.86f,.08f), new Vector2(.88f,.13f), new Vector2(.86f,.24f), new Vector2(.90f,.30f), new Vector2(.94f,.28f), new Vector2(.95f,.33f), new Vector2(.90f,.39f), new Vector2(.86f,.52f), new Vector2(.87f,.68f), new Vector2(.95f,.83f), new Vector2(1,.83f) }); Polygon(new[] { new Vector2(0,.84f), new Vector2(.08f,.88f), new Vector2(.15f,.92f), new Vector2(.21f,.84f), new Vector2(.34f,.97f), new Vector2(.41f,1), new Vector2(0,1) }); } foreach (Lane lane in Market.Lanes) { if (lane.A >= ChartPortCount || lane.B >= ChartPortCount) continue; Vector2 a = ChartPoint(Market.Ports[lane.A]); Vector2 b = ChartPoint(Market.Ports[lane.B]); bool active = company.Permits[lane.A] && company.Permits[lane.B]; painter.strokeColor = active ? new Color(.41f, .75f, .68f, .8f) : new Color(.69f, .62f, .44f, .59f); painter.lineWidth = active ? 1.65f : 1; if (worldChart && Mathf.Abs(a.x - b.x) > .5f) { if (a.x > b.x) (a, b) = (b, a); float y = Mathf.Lerp(a.y, b.y, a.x / (a.x + 1 - b.x)); RouteSegment(a, new Vector2(0, y)); RouteSegment(new Vector2(1, y), b); } else RouteSegment(a, b); } void RouteSegment(Vector2 a, Vector2 b) { painter.BeginPath(); painter.MoveTo(Point(a.x, a.y)); float rise = worldChart ? .018f : .055f; painter.QuadraticCurveTo(Point((a.x + b.x) / 2, (a.y + b.y) / 2 - rise), Point(b.x, b.y)); painter.Stroke(); } } private void DrawFinance(VisualElement pageRoot) { var summary = Add(pageRoot, "card deck-stats"); ForecastMetric(summary, "CASH RESERVES", Money(company.Cash), "gold"); ForecastMetric(summary, "OUTSTANDING DEBT", Money(company.Debt)); ForecastMetric(summary, "LIFETIME VOYAGE PROFIT", Money(company.LifetimeProfit), company.LifetimeProfit >= 0 ? "gain" : "loss"); ForecastMetric(summary, "COMPLETED VOYAGES", company.Voyages.ToString()); var columns = Add(pageRoot, "columns second-row"); var ledger = Card(columns, "Voyage ledger", "wide"); if (company.History.Count == 0) AddText(ledger, "Completed voyages will be posted here.", "body-copy"); else { selectedVoyage = Mathf.Clamp(selectedVoyage, 0, company.History.Count - 1); var list = new ScrollView(ScrollViewMode.Vertical); list.AddToClassList("ledger-scroll"); ledger.Add(list); for (int i = 0; i < company.History.Count; i++) { int record = i; Voyage trip = company.History[i]; Button entry = Action("", () => { selectedVoyage = record; Render(); }, selectedVoyage == i ? "yard-item active-option" : "yard-item", "voyage-" + i); var detail = Add(entry, "yard-copy"); AddText(detail, $"{Market.Ports[trip.Origin].Name} → {Market.Ports[trip.Destination].Name}", "option-title"); AddText(detail, $"Day {trip.Day} · {trip.ShipName} · {trip.Guests} guests", "muted"); AddText(entry, Money(trip.NetIncome), trip.NetIncome >= 0 ? "gain" : "loss"); list.Add(entry); } } var account = Card(columns, "Financing", "narrow"); AddLine(account, "Interest", company.Debt > 0 ? "13% APR" : "No outstanding loan"); AddLine(account, "Principal per sailing day", company.Debt > 0 ? Money(850) : "—"); if (company.Debt > 0) { Button pay = Action($"Pay down · {Money(Mathf.Min(company.Debt, 25000))}", () => Apply(company.PayDownDebt(), "Principal payment posted."), "full-button", "pay-debt"); pay.SetEnabled(company.Cash >= Mathf.Min(company.Debt, 25000)); account.Add(pay); } if (company.Bridge) { Button draw = Action("Draw $125,000 bridge loan", () => Apply(company.DrawBridge(), "Bridge loan posted."), "full-button", "draw-bridge"); draw.SetEnabled(company.CanDrawBridge); account.Add(draw); if (!company.CanDrawBridge) AddText(account, "Bridge credit opens below $100,000 cash.", "body-copy"); } if (company.Flagship) AddText(account, "Flagship milestone completed.", "body-copy gain"); if (company.History.Count == 0) return; Voyage selected = company.History[selectedVoyage]; var statement = Card(pageRoot, $"Sailing statement · Day {selected.Day}", "second-row"); var breakdown = Add(statement, "columns breakdown"); var earnings = Add(breakdown, "half"); AddLine(earnings, "Ticket revenue", Money(selected.TicketSales)); AddLine(earnings, "Onboard revenue", Money(selected.OnboardSales)); AddLine(earnings, "Crew & catering", Money(-selected.Crew - selected.Catering)); AddLine(earnings, "Port dues", Money(-selected.PortFees)); var costs = Add(breakdown, "half"); AddLine(costs, "Fuel consumed from inventory", Money(-selected.FuelExpense)); AddLine(costs, "Interest", Money(-selected.LoanInterest)); AddLine(costs, "Loan principal paid", Money(-selected.Principal)); AddLine(costs, "Cash change on arrival", Money(selected.CashChange), selected.CashChange >= 0 ? "gain" : "loss"); } } }