101 lines
4.8 KiB
C#
101 lines
4.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Soundings
|
|
{
|
|
public sealed partial class SoundingsApp
|
|
{
|
|
private void DrawVoyageFolio(VisualElement folio, Ship ship, Voyage quote)
|
|
{
|
|
PortSpec origin = Market.Ports[quote.Origin];
|
|
AddText(folio, $"DEPARTURE FROM {origin.Name.ToUpperInvariant()}", "chart-paper-kicker chart-paper-section");
|
|
var passage = Add(folio, "chart-passage");
|
|
AddText(passage, $"{quote.Miles:N0} nm · {quote.Days} days", "chart-passage-distance");
|
|
AddText(passage, $"{quote.Guests} / {quote.Capacity} guests", "chart-passage-guests");
|
|
|
|
var settlement = Add(folio, "chart-settlement");
|
|
AddText(settlement, "EST. VOYAGE PROFIT", "chart-paper-kicker");
|
|
AddDisplay(settlement, Money(quote.NetIncome), quote.NetIncome >= 0 ? "chart-projected-profit" : "chart-projected-profit chart-projected-loss");
|
|
|
|
var fares = Add(folio, "chart-money-row");
|
|
AddText(fares, "Fare per guest", "chart-money-label");
|
|
ChartStepper(fares, Money(ship.Fare), "fare", () => ChangeFare(ship, -50), () => ChangeFare(ship, 50),
|
|
ship.Fare > Market.MinFare, ship.Fare < Market.MaxFare);
|
|
|
|
DrawChartBunkering(folio, ship, quote);
|
|
string blocker = company.DepartureBlock(ship, quote);
|
|
if (!string.IsNullOrEmpty(blocker))
|
|
AddText(folio, blocker, "chart-paper-note chart-departure-blocker");
|
|
else
|
|
AddText(folio, "Cleared for departure", "chart-cleared");
|
|
Button launch = Action("Cast off →", () => BeginVoyage(quote), "chart-ink-button chart-wide-button chart-cast-off", "dispatch");
|
|
launch.SetEnabled(blocker == null);
|
|
folio.Add(launch);
|
|
}
|
|
|
|
private void DrawChartBunkering(VisualElement folio, Ship ship, Voyage quote = null)
|
|
{
|
|
PortSpec dock = Market.Ports[ship.Port];
|
|
AddText(folio, "FUEL AT BERTH", "chart-paper-kicker chart-paper-section");
|
|
ChartLine(folio, "Aboard / capacity", $"{ship.Fuel} / {ship.Tank} t");
|
|
var tank = Add(folio, "chart-tank");
|
|
Add(tank, "chart-tank-fill").style.width = Length.Percent(100f * ship.Fuel / ship.Tank);
|
|
if (quote != null)
|
|
ChartLine(folio, "Burn + reserve", $"{quote.FuelBurn} + {quote.Reserve} t");
|
|
else
|
|
ChartLine(folio, "Indicative safe range", $"{ship.SafeRange:N0} nm");
|
|
ChartLine(folio, $"Price in {dock.Name}", $"{Money(Market.FuelPrice(ship.Port, company.Day))} / t");
|
|
|
|
var buying = Add(folio, "chart-buying");
|
|
ChartStepper(buying, $"{bunkerTons} t", "tons", () => ChangeQuantity(ship, -10), () => ChangeQuantity(ship, 10),
|
|
bunkerTons > 0, bunkerTons < ship.Tank - ship.Fuel);
|
|
Button buy = Action($"Buy {Money(company.BunkerCost(ship, bunkerTons))}", () =>
|
|
{
|
|
int ordered = bunkerTons;
|
|
string failure = company.Refuel(ship, ordered);
|
|
if (failure == null)
|
|
SetRecommendedFuel();
|
|
Apply(failure, $"Loaded {ordered} t of fuel in {dock.Name}.");
|
|
}, "chart-ink-button chart-buy-fuel", "buy-fuel");
|
|
buy.SetEnabled(bunkerTons > 0 && company.Cash >= company.BunkerCost(ship, bunkerTons));
|
|
buying.Add(buy);
|
|
}
|
|
|
|
private void ChangeFare(Ship ship, int amount)
|
|
{
|
|
ship.Fare = Market.Clamp(ship.Fare + amount, Market.MinFare, Market.MaxFare);
|
|
Apply(null, null);
|
|
}
|
|
|
|
private void ChangeQuantity(Ship ship, int amount)
|
|
{
|
|
bunkerTons = Mathf.Clamp(bunkerTons + amount, 0, ship.Tank - ship.Fuel);
|
|
Notify(null);
|
|
Render();
|
|
}
|
|
|
|
private static void ChartStepper(VisualElement parent, string value, string id, Action minus, Action plus, bool canMinus, bool canPlus)
|
|
{
|
|
var stepper = Add(parent, "chart-stepper");
|
|
Button down = Action("-", minus, "chart-step", id + "-minus");
|
|
down.tooltip = id == "fare" ? "Lower passenger fare by $50" : "Buy 10 fewer tons";
|
|
down.SetEnabled(canMinus);
|
|
stepper.Add(down);
|
|
AddText(stepper, value, "chart-step-value");
|
|
Button up = Action("+", plus, "chart-step", id + "-plus");
|
|
up.tooltip = id == "fare" ? "Raise passenger fare by $50" : "Buy 10 more tons";
|
|
up.SetEnabled(canPlus);
|
|
stepper.Add(up);
|
|
}
|
|
|
|
private static void ChartLine(VisualElement parent, string description, string value)
|
|
{
|
|
var line = Add(parent, "chart-paper-line");
|
|
AddText(line, description, "chart-paper-caption");
|
|
AddText(line, value, "chart-paper-value");
|
|
}
|
|
|
|
}
|
|
}
|