Enable placeable sun deck attractions and finish project rebrand
This commit is contained in:
176
Assets/BigShipTycoon/Runtime/ItineraryPage.cs
Normal file
176
Assets/BigShipTycoon/Runtime/ItineraryPage.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BigShipTycoon
|
||||
{
|
||||
public sealed partial class TycoonApp
|
||||
{
|
||||
private Ship itineraryEditorShip;
|
||||
|
||||
private bool EditingItinerary => Ship != null && Ship == itineraryEditorShip;
|
||||
|
||||
private static int ItineraryTail(Ship ship) => ship.Itinerary?.HasNext == true ? ship.Itinerary.LastPort : ship.Port;
|
||||
|
||||
private static bool IsPendingCall(CruiseItinerary itinerary, int port)
|
||||
{
|
||||
for (int i = itinerary.CompletedStops; i < itinerary.TotalStops; i++)
|
||||
if (itinerary.Stops[i] == port)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DrawItineraryButton(VisualElement controls, Ship ship)
|
||||
{
|
||||
int calls = ship.Itinerary?.TotalStops ?? 0;
|
||||
string label = calls > 0 ? $"Itinerary · {calls}" : "Itinerary";
|
||||
Button button = Action(label, () =>
|
||||
{
|
||||
if (EditingItinerary)
|
||||
CloseItinerary();
|
||||
else
|
||||
{
|
||||
itineraryEditorShip = ship;
|
||||
portOrdersOpen = false;
|
||||
chartScrollPosition = 0;
|
||||
Notify(null);
|
||||
Render();
|
||||
}
|
||||
}, EditingItinerary ? "chart-scope chart-scope-current" : "chart-scope", "itinerary-open");
|
||||
button.tooltip = "Plan consecutive port calls for this ship";
|
||||
controls.Add(button);
|
||||
}
|
||||
|
||||
private void DrawItineraryFolio(VisualElement parent, Ship ship)
|
||||
{
|
||||
var header = Add(parent, "chart-itinerary-header");
|
||||
AddDisplay(header, "Itinerary", "chart-itinerary-title");
|
||||
header.Add(Action("Back", CloseItinerary, "chart-ink-button chart-itinerary-mini", "itinerary-close"));
|
||||
|
||||
CruiseItinerary itinerary = ship.Itinerary;
|
||||
if (itinerary?.HasNext == true)
|
||||
{
|
||||
parent.Add(Action($"Review next leg · {Market.Ports[itinerary.NextPort].Name}",
|
||||
CloseItinerary, "chart-ink-button chart-itinerary-review", "itinerary-next"));
|
||||
}
|
||||
else if (itinerary?.TotalStops > 0)
|
||||
AddText(parent, "Itinerary complete", "chart-itinerary-note");
|
||||
|
||||
AddText(parent, "PORT CALLS", "chart-paper-kicker chart-paper-section");
|
||||
int initial = itinerary?.Origin ?? ship.Port;
|
||||
var departure = Add(parent, "chart-itinerary-row");
|
||||
AddText(departure, "START", "chart-itinerary-number");
|
||||
AddText(departure, Market.Ports[initial].Name, "chart-itinerary-port");
|
||||
if (itinerary != null)
|
||||
{
|
||||
int from = itinerary.Origin;
|
||||
for (int index = 0; index < itinerary.TotalStops; index++)
|
||||
{
|
||||
int to = itinerary.Stops[index];
|
||||
var row = Add(parent, "chart-itinerary-row");
|
||||
row.EnableInClassList("chart-itinerary-row-next", index == itinerary.CompletedStops);
|
||||
AddText(row, $"{index + 1:00}", "chart-itinerary-number");
|
||||
var copy = Add(row, "chart-itinerary-call");
|
||||
AddText(copy, Market.Ports[to].Name, "chart-itinerary-port");
|
||||
Market.TryDistance(from, to, out int miles);
|
||||
string state = index < itinerary.CompletedStops ? "Visited" : index == itinerary.CompletedStops ? "Next" : "Planned";
|
||||
AddText(copy, $"{state} · {miles:N0} nm", "chart-itinerary-note");
|
||||
from = to;
|
||||
}
|
||||
|
||||
var controls = Add(parent, "chart-itinerary-controls");
|
||||
var remove = Action("Remove last call", () => UpdateItinerary(ship,
|
||||
company.RemoveItineraryStop(ship, itinerary.TotalStops - 1), "Last call removed."),
|
||||
"chart-ink-button chart-itinerary-mini", "itinerary-remove");
|
||||
remove.SetEnabled(itinerary.HasNext);
|
||||
controls.Add(remove);
|
||||
controls.Add(Action("Clear route", () => UpdateItinerary(ship, company.ClearItinerary(ship), "Itinerary cleared."),
|
||||
"chart-ink-button chart-itinerary-mini", "itinerary-clear"));
|
||||
}
|
||||
|
||||
int tail = ItineraryTail(ship);
|
||||
DrawItineraryConnections(parent, ship, tail);
|
||||
|
||||
int selected = inspectedPort;
|
||||
string portName = Market.Ports[selected].Name;
|
||||
string blocked = company.ItineraryStopBlock(ship, selected);
|
||||
AddText(parent, portName, "chart-itinerary-selection");
|
||||
if (Market.TryDistance(tail, selected, out int distance))
|
||||
AddText(parent, $"{distance:N0} nm from {Market.Ports[tail].Name}", "chart-itinerary-note");
|
||||
|
||||
var append = Action($"Add {portName}", () => UpdateItinerary(ship, company.AppendItineraryStop(ship, selected),
|
||||
$"Added {portName} to the itinerary."), "chart-ink-button chart-itinerary-review", "itinerary-add");
|
||||
append.SetEnabled(blocked == null);
|
||||
parent.Add(append);
|
||||
if (blocked != null)
|
||||
AddText(parent, blocked, "chart-itinerary-note");
|
||||
if (!company.Permits[selected] && Market.TryDistance(tail, selected, out _))
|
||||
{
|
||||
var permit = Action($"Acquire permit · {Money(Market.Ports[selected].Permit)}", () =>
|
||||
Apply(company.Permit(selected), $"{portName} is now licensed."),
|
||||
"chart-ink-button chart-itinerary-review", "permit");
|
||||
permit.SetEnabled(company.PermitBlock(selected) == null);
|
||||
parent.Add(permit);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawItineraryConnections(VisualElement parent, Ship ship, int tail)
|
||||
{
|
||||
AddText(parent, $"CONNECTED FROM {Market.Ports[tail].Name.ToUpperInvariant()}", "chart-paper-kicker chart-paper-section");
|
||||
var connections = Add(parent, "chart-itinerary-connections");
|
||||
foreach (Lane lane in Market.Lanes)
|
||||
{
|
||||
int port = lane.Other(tail);
|
||||
if (port < 0)
|
||||
continue;
|
||||
var choice = Action(Market.Ports[port].Name, () => InspectChartPort(port),
|
||||
"chart-ink-button chart-itinerary-mini chart-itinerary-choice", $"itinerary-port-{port}");
|
||||
choice.EnableInClassList("chart-itinerary-choice-selected", port == inspectedPort);
|
||||
string blocker = company.ItineraryStopBlock(ship, port);
|
||||
choice.EnableInClassList("chart-itinerary-choice-restricted", blocker != null);
|
||||
choice.tooltip = blocker ?? $"{lane.Miles:N0} nm from {Market.Ports[tail].Name}";
|
||||
connections.Add(choice);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawNextCall(VisualElement parent, CruiseItinerary itinerary, int selected)
|
||||
{
|
||||
var strip = Add(parent, "chart-itinerary-next");
|
||||
string name = Market.Ports[itinerary.NextPort].Name;
|
||||
AddText(strip, $"LEG {itinerary.CompletedStops + 1} OF {itinerary.TotalStops}", "chart-paper-kicker");
|
||||
if (selected != itinerary.NextPort)
|
||||
strip.Add(Action($"Review {name}", CloseItinerary, "chart-ink-button chart-itinerary-mini", "itinerary-next"));
|
||||
}
|
||||
|
||||
private void CloseItinerary()
|
||||
{
|
||||
itineraryEditorShip = null;
|
||||
int planned = Ship?.Itinerary?.NextPort ?? -1;
|
||||
if (planned >= 0)
|
||||
{
|
||||
destination = planned;
|
||||
SetRecommendedFuel();
|
||||
InspectChartPort(planned);
|
||||
}
|
||||
else
|
||||
{
|
||||
chartScrollPosition = 0;
|
||||
InspectChartPort(inspectedPort);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateItinerary(Ship ship, string failure, string success)
|
||||
{
|
||||
if (failure == null)
|
||||
{
|
||||
int planned = ship.Itinerary?.NextPort ?? -1;
|
||||
if (planned >= 0)
|
||||
{
|
||||
destination = planned;
|
||||
SetRecommendedFuel();
|
||||
}
|
||||
else
|
||||
ResetItinerary();
|
||||
}
|
||||
Apply(failure, success);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user