Files
josh 290e4cb45d Add riverboat captain career and distinct ship classes
Add class-specific vessel geometry and sea motion, a guided helm qualification path, dockside sailing orders, and local excursions at all 24 ports.
2026-11-29 20:41:00 -05:00

374 lines
18 KiB
C#

using UnityEngine;
using UnityEngine.UIElements;
namespace BigShipTycoon
{
public sealed partial class TycoonApp
{
private bool sunDeckEditing, sunMoving;
private Ship sunPlanningShip;
private SunDeckZone sunZone;
private SunAttraction sunTool;
private int sunRotation, sunSelection = -1;
private System.Action refreshSunPlacement;
private static readonly (SunPoolStyle Style, string Label, string Id)[] SunPools =
{
(SunPoolStyle.Compact, "Compact", "compact"), (SunPoolStyle.Family, "Family", "family"),
(SunPoolStyle.Resort, "Resort", "resort"), (SunPoolStyle.Lagoon, "Lagoon", "lagoon")
};
private static readonly (SunAttraction Kind, string Label, string Id)[] SunAttractions =
{
(SunAttraction.Pool, "Pool", "pool"), (SunAttraction.MiniGolf, "Mini golf", "golf"),
(SunAttraction.Theater, "Outdoor theater", "theater"), (SunAttraction.GoKarts, "Go-karts", "karts"),
(SunAttraction.RollerCoaster, "Roller coaster", "coaster"), (SunAttraction.SkyGarden, "Sky garden", "garden")
};
private void DrawSunDeckEditor(VisualElement work, Ship ship)
{
if (ship.HullIndex == Market.River)
{
var fixedRoof = Add(work, "work-draft");
AddDisplay(fixedRoof, "Fixed canopy", "work-section-title");
AddText(fixedRoof, "Outdoor fittings begin with the Coastal command. The passenger deck is available to refit.", "work-caption");
return;
}
if (sunPlanningShip != ship)
{
sunPlanningShip = ship;
sunZone = SunDeckZone.Sky;
ResetSunTool();
}
var grid = new SunDeckGrid(ship, zone: sunZone);
SunDeckPlan plan = ship.SunDeckFor(sunZone);
SunPoolStyle pool = grid.SelectedPool;
if (sunSelection >= grid.Existing.Count)
ResetSunTool();
var board = Add(work, "work-draft");
bool terrace = sunZone == SunDeckZone.AftTerrace;
board.generateVisualContent += context =>
{
if (terrace)
DrawDraftGrid(context.painter2D, context.visualElement.contentRect, 26);
else
DrawDeckOutline(context, ship.Hull.Columns);
};
var markings = Add(board, "work-draft-markings");
markings.pickingMode = PickingMode.Ignore;
AddText(markings, "STERN", "work-caption");
AddText(markings, terrace ? "AFT TERRACE" : ship.HasAftTerrace ? "SKY DECK" : "SUN DECK", "work-caption");
AddText(markings, terrace ? "STAIRS TO SKY DECK →" : "BOW →", "work-caption");
var diagram = Add(board, terrace ? "sun-deck-diagram sun-terrace-diagram" : "sun-deck-diagram");
var status = AddText(Add(board, "work-placement"), "", "work-placement-text");
status.name = "sun-placement-status";
refreshSunPlacement = DrawSunGrid(diagram, status, ship, grid, pool);
var fittings = Add(work, "work-fittings sun-deck-panel");
var capacity = Add(fittings, "work-capacity-strip");
if (ship.HasAftTerrace)
{
AddSunZone(capacity, SunDeckZone.Sky, "Sky deck", "sun-zone-sky");
AddSunZone(capacity, SunDeckZone.AftTerrace, "Aft terrace", "sun-zone-terrace");
}
AddText(capacity, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity");
AddText(capacity, $"{ship.Entertainment:N0} show seats", "work-capacity");
var attractions = SunDeckOptions(fittings, "Build");
int existingPool = grid.PoolIndex;
foreach (var option in SunAttractions)
{
if (option.Kind == SunAttraction.SkyGarden && !ship.HasAftTerrace)
continue;
bool isPool = option.Kind == SunAttraction.Pool;
int minimumHull = SunDeckPlan.RequiredHull(option.Kind);
string requirement = ship.HullIndex < minimumHull ? $"Requires a {Market.Hulls[minimumHull].Name} hull" : null;
int cost = isPool && existingPool >= 0 ? 0 : Company.SunDeckPlacementPrice(ship, new SunDeckPlacement(option.Kind, 0, 0), zone: sunZone);
string detail = requirement != null ? $" · {Market.Hulls[minimumHull].Name}" : cost > 0 ? $" {Money(cost)}" : "";
Button choose = Action(option.Label + detail, () =>
{
ResetSunTool();
if (isPool && existingPool >= 0)
sunSelection = existingPool;
else
sunTool = option.Kind;
Notify(null);
Render();
}, "sun-deck-choice", "sun-attraction-" + option.Id);
choose.EnableInClassList("sun-deck-selected", !sunMoving && (sunTool == option.Kind || isPool && existingPool >= 0 && sunSelection == existingPool));
choose.SetEnabled(requirement == null);
choose.tooltip = requirement ?? (isPool
? existingPool >= 0 ? "Select the installed pool" : "Choose an open space for the configured pool"
: $"Build {option.Label.ToLowerInvariant()} · {Money(cost)}");
attractions.Add(choose);
}
var actions = SunDeckOptions(fittings, "Placement");
Button inspect = Action("Inspect", () =>
{
ResetSunTool();
Notify(null);
Render();
}, "sun-deck-choice", "sun-inspect");
inspect.EnableInClassList("sun-deck-selected", sunTool == SunAttraction.None);
actions.Add(inspect);
Button rotate = Action("Rotate R", RotateSunDeckTool, "sun-deck-choice", "sun-rotate");
rotate.SetEnabled(sunTool != SunAttraction.None || sunSelection >= 0);
rotate.tooltip = "Turn the fitting clockwise. Press R while pointing at the deck to preview the turn.";
actions.Add(rotate);
Button move = Action(sunMoving ? "Cancel move" : "Move", () =>
{
if (sunMoving)
{
int selected = sunSelection;
ResetSunTool();
sunSelection = selected;
}
else
{
SunDeckPlacement selection = grid.Existing[sunSelection];
sunTool = selection.Kind;
sunRotation = selection.Rotation;
sunMoving = true;
}
Notify(null);
Render();
}, "sun-deck-choice", "sun-move");
move.SetEnabled(sunSelection >= 0);
actions.Add(move);
Button remove = Action("Remove", () =>
{
string failure = company.RemoveSunDeck(ship, sunSelection, sunZone);
if (failure == null)
ResetSunTool();
Apply(failure, "Sun deck fitting removed.");
}, "sun-deck-choice", "sun-remove");
remove.SetEnabled(sunSelection >= 0 && !sunMoving);
actions.Add(remove);
var trim = SunDeckOptions(fittings, "Pool");
foreach (var option in SunPools)
{
if (option.Style == SunPoolStyle.Lagoon && !ship.HasAftTerrace)
continue;
var next = plan;
next.Pool = option.Style;
AddSunOption(trim, ship, next, option.Label, "sun-pool-" + option.Id, pool == option.Style,
SunDeckPlan.RequiredHull(option.Style));
}
var rectangle = plan;
rectangle.Shape = SunPoolShape.Rectangle;
AddSunOption(trim, ship, rectangle, "Rectangle", "sun-shape-rectangle", plan.Shape == SunPoolShape.Rectangle);
var oval = plan;
oval.Shape = SunPoolShape.Oval;
AddSunOption(trim, ship, oval, "Oval", "sun-shape-oval", plan.Shape == SunPoolShape.Oval);
var shade = plan;
shade.NoShade = !plan.NoShade;
AddSunOption(trim, ship, shade, "Parasols", "sun-shade", !plan.NoShade);
var seating = plan;
seating.ExtraLoungers = !plan.ExtraLoungers;
AddSunOption(trim, ship, seating, "Extra loungers", "sun-loungers", plan.ExtraLoungers);
}
private System.Action DrawSunGrid(VisualElement diagram, Label status, Ship ship, SunDeckGrid grid, SunPoolStyle pool)
{
var hovered = new Vector2Int(-1, -1);
var focused = hovered;
var preview = AddSunDiagramFit(diagram, grid.Area, default, null, "sun-diagram-preview");
for (int y = 0; y < grid.Rows; y++)
for (int x = 0; x < grid.Columns; x++)
{
var position = new Vector2Int(x, y);
int occupant = grid.At(x, y, pool);
bool blocked = grid.IsBlocked(x, y);
Button cell = Action("", () => UseSunCell(ship, position, occupant),
blocked ? "sun-deck-cell sun-deck-cell-blocked" : "sun-deck-cell", $"sun-cell-{x}-{y}");
cell.style.left = Length.Percent(100f * x / grid.Columns);
cell.style.top = Length.Percent(100f * y / grid.Rows);
cell.style.width = Length.Percent(100f / grid.Columns);
cell.style.height = Length.Percent(100f / grid.Rows);
cell.tooltip = occupant >= 0 ? SunFittingName(grid.Existing[occupant].Kind) : blocked ? "Reserved deck space" : "";
cell.RegisterCallback<PointerEnterEvent>(_ => { hovered = position; RefreshPreview(); });
cell.RegisterCallback<PointerLeaveEvent>(_ => { hovered = new Vector2Int(-1, -1); RefreshPreview(); });
cell.RegisterCallback<FocusInEvent>(_ => { focused = position; RefreshPreview(); });
cell.RegisterCallback<FocusOutEvent>(_ => { focused = new Vector2Int(-1, -1); RefreshPreview(); });
diagram.Add(cell);
}
if (sunZone == SunDeckZone.Sky)
{
AddSunDiagramFit(diagram, grid.Area, grid.Funnels, "Funnels", "sun-diagram-fixed");
AddSunDiagramFit(diagram, grid.Area, grid.Bridge, "Bridge", "sun-diagram-fixed");
}
for (int i = 0; i < grid.Existing.Count; i++)
{
var placed = grid.Existing[i];
string label = $"{SunFittingName(placed.Kind)} {SunDirection(placed.Rotation)}";
string classes = placed.Kind switch
{
SunAttraction.Pool => "sun-diagram-pool",
SunAttraction.MiniGolf or SunAttraction.SkyGarden => "sun-diagram-golf",
SunAttraction.Theater => "sun-diagram-theater",
_ => "sun-diagram-ride"
};
if (i == sunSelection)
classes += sunMoving ? " sun-diagram-moving" : " sun-diagram-selected";
var fitting = AddSunDiagramFit(diagram, grid.Area, grid.Bounds(placed, pool), label, classes);
if (placed.Kind == SunAttraction.Pool)
{
var water = new VisualElement { pickingMode = PickingMode.Ignore };
water.AddToClassList("sun-diagram-basin");
water.EnableInClassList("sun-diagram-oval", ship.SunDeckFor(sunZone).Shape == SunPoolShape.Oval);
water.EnableInClassList("sun-diagram-turned", (placed.Rotation & 1) != 0);
fitting.Insert(0, water);
}
}
preview.BringToFront();
RefreshPreview();
return RefreshPreview;
void RefreshPreview()
{
Vector2Int cursor = hovered.x >= 0 ? hovered : focused;
bool show = sunTool != SunAttraction.None && cursor.x >= 0;
preview.style.display = show ? DisplayStyle.Flex : DisplayStyle.None;
if (show)
{
var fitting = new SunDeckPlacement(sunTool, cursor.x, cursor.y, sunRotation);
string block = company.SunDeckPlacementBlock(ship, fitting, sunMoving ? sunSelection : -1, sunZone);
preview.EnableInClassList("sun-diagram-invalid", block != null);
PositionSunFit(preview, grid.Area, grid.Bounds(fitting, pool));
status.text = block ?? $"{(sunMoving ? "Move" : "Place")} {SunFittingName(sunTool)} {SunDirection(sunRotation)}";
return;
}
if (sunTool != SunAttraction.None)
{
status.text = $"{SunFittingName(sunTool)} {SunDirection(sunRotation)} · Choose a space on the deck.";
return;
}
if (sunSelection >= 0)
{
var selection = grid.Existing[sunSelection];
status.text = $"{SunFittingName(selection.Kind)} {SunDirection(selection.Rotation)} · Move, rotate, or remove this fitting.";
return;
}
status.text = "Choose a fitting to build or select one on the plan.";
}
}
private void UseSunCell(Ship ship, Vector2Int cell, int occupant)
{
if (sunTool == SunAttraction.None)
{
sunSelection = occupant;
Notify(null);
Render();
return;
}
var next = new SunDeckPlacement(sunTool, cell.x, cell.y, sunRotation);
string failure = company.PlaceSunDeck(ship, next, sunMoving ? sunSelection : -1, sunZone);
string feedback = $"{SunFittingName(sunTool)} {(sunMoving ? "moved" : "fitted")}.";
if (failure == null)
{
ResetSunTool();
var updated = new SunDeckGrid(ship, zone: sunZone);
sunSelection = updated.At(cell.x, cell.y, updated.SelectedPool);
}
Apply(failure, feedback);
}
private void RotateSunDeckTool()
{
if (sunPlanningShip != Ship)
return;
if (sunTool != SunAttraction.None)
{
sunRotation = (sunRotation + 1) & 3;
refreshSunPlacement?.Invoke();
return;
}
if (sunSelection < 0)
return;
var grid = new SunDeckGrid(Ship, zone: sunZone);
var next = grid.Existing[sunSelection];
next.Rotation = (next.Rotation + 1) & 3;
Apply(company.PlaceSunDeck(Ship, next, sunSelection, sunZone), $"{SunFittingName(next.Kind)} rotated.");
}
private void ResetSunTool()
{
sunTool = SunAttraction.None;
sunRotation = 0;
sunSelection = -1;
sunMoving = false;
}
private static string SunFittingName(SunAttraction kind)
{
foreach (var option in SunAttractions)
if (option.Kind == kind)
return option.Label;
return string.Empty;
}
private static string SunDirection(int rotation) => rotation switch { 1 => "↓", 2 => "←", 3 => "↑", _ => "→" };
private static VisualElement SunDeckOptions(VisualElement panel, string caption)
{
var row = Add(panel, "sun-deck-options");
AddText(row, caption, "sun-deck-option-label");
return row;
}
private void AddSunZone(VisualElement parent, SunDeckZone zone, string label, string id)
{
Button button = Action(label, () =>
{
sunZone = zone;
ResetSunTool();
Notify(null);
Render();
}, "sun-deck-choice", id);
button.EnableInClassList("sun-deck-selected", sunZone == zone);
parent.Add(button);
}
private void AddSunOption(VisualElement row, Ship ship, SunDeckPlan next, string label, string id, bool selected,
int minimumHull = 0)
{
next.CustomLayout = true;
string requirement = ship.HullIndex < minimumHull ? $"Requires a {Market.Hulls[minimumHull].Name} hull" : null;
int cost = Company.SunDeckCost(ship, next, sunZone);
string detail = requirement == null && cost > 0 ? $" {Money(cost)}" : "";
Button option = Action(label + detail, () => Apply(company.ChangeSunDeck(ship, next, sunZone), "Sun deck refitted."), "sun-deck-choice", id);
option.EnableInClassList("sun-deck-selected", selected);
option.SetEnabled(requirement == null && company.AvailableCash >= cost);
option.tooltip = requirement ?? (cost > 0 ? $"Refit cost {Money(cost)}" : "");
row.Add(option);
}
private static VisualElement AddSunDiagramFit(VisualElement diagram, Rect area, Rect footprint, string caption, string classes)
{
var outline = Add(diagram, "sun-diagram-fitting " + classes);
outline.pickingMode = PickingMode.Ignore;
PositionSunFit(outline, area, footprint);
if (caption != null)
AddText(outline, caption, "sun-diagram-label").pickingMode = PickingMode.Ignore;
return outline;
}
private static void PositionSunFit(VisualElement outline, Rect area, Rect footprint)
{
outline.style.left = Length.Percent(100 * (footprint.xMin - area.xMin) / area.width);
outline.style.top = Length.Percent(100 * (footprint.yMin - area.yMin) / area.height);
outline.style.width = Length.Percent(100 * footprint.width / area.width);
outline.style.height = Length.Percent(100 * footprint.height / area.height);
}
}
}