Add fleet save slots and rotatable onboard venues

This commit is contained in:
josh
2026-11-28 16:04:48 -05:00
parent a9472edc35
commit c570a64840
37 changed files with 1970 additions and 310 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
@@ -8,8 +10,18 @@ namespace Soundings
private static readonly (int HullIndex, bool Used)[] Offers =
{ (0, true), (0, false), (1, true), (1, false), (2, false) };
private enum DeckTools { GuestFacilities, LargerVenues, ShipSystems }
private enum DeckTools { GuestFacilities, LargerVenues, LeisureAndRetail, ShipSystems }
private DeckTools deckTools;
private int toolRotation;
private Action refreshDeckPlacement;
private static readonly Facility[] GuestTools = { Facility.Cabin, Facility.Dining, Facility.Entertainment,
Facility.Tank, Facility.Bar, Facility.Amenity, Facility.Empty };
private static readonly Facility[] ExpandedTools = { Facility.Suite, Facility.GrandSuite, Facility.Restaurant,
Facility.GrandTheater, Facility.ResortPool, Facility.CocktailLounge, Facility.Empty };
private static readonly Facility[] LeisureTools = { Facility.Shop, Facility.ShoppingArcade, Facility.Spa, Facility.WaterPark, Facility.Empty };
private static readonly Facility[] SystemsTools = { Facility.Galley, Facility.Stores, Facility.Water,
Facility.Waste, Facility.Workshop, Facility.Empty };
private static readonly Color DraftGrid = new Color(.37f, .62f, .65f, .19f);
private static readonly Color DraftFine = new Color(.47f, .75f, .74f, .42f);
@@ -72,9 +84,9 @@ namespace Soundings
var layout = Add(board, "work-berth-grid");
var placement = Add(board, "work-placement");
var placementLabel = AddText(placement, PlacementInstruction(ship, tool), "work-placement-text");
var placementLabel = AddText(placement, PlacementInstruction(ship, tool, toolRotation), "work-placement-text");
placementLabel.name = "berth-placement";
DrawBerthGrid(layout, placementLabel, ship);
refreshDeckPlacement = DrawBerthGrid(layout, placementLabel, ship);
var fittings = Add(work, "work-fittings");
var gauges = Add(fittings, "work-capacity-strip");
@@ -91,10 +103,13 @@ namespace Soundings
AddText(gauges, rooms, "work-capacity");
AddText(gauges, $"{ship.Meals:N0} meal covers", "work-capacity");
AddText(gauges, $"{ship.Entertainment:N0} show seats", "work-capacity");
if (deckTools == DeckTools.LargerVenues)
if (deckTools == DeckTools.LargerVenues || deckTools == DeckTools.LeisureAndRetail)
{
AddText(gauges, $"{ship.PoolCapacity:N0} pool admissions", "work-capacity");
AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity");
AddText(gauges, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity");
if (deckTools == DeckTools.LeisureAndRetail)
AddText(gauges, $"{ship.RetailCapacity:N0} retail orders", "work-capacity");
else
AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity");
}
else
AddText(gauges, $"{ship.Tank:N0} t bunker capacity", "work-capacity");
@@ -104,21 +119,32 @@ namespace Soundings
var toolMode = Add(fittings, "work-fit-modes");
AddBuildToolTab(toolMode, "Guest facilities", "facility-guests", DeckTools.GuestFacilities, Facility.Cabin);
AddBuildToolTab(toolMode, "Larger venues", "facility-larger", DeckTools.LargerVenues, Facility.Suite);
AddBuildToolTab(toolMode, "Leisure & retail", "facility-leisure", DeckTools.LeisureAndRetail, Facility.Shop);
AddBuildToolTab(toolMode, "Ship systems", "facility-systems", DeckTools.ShipSystems, Facility.Galley);
FacilitySpec selectedSpec = Market.Facilities[(int)tool];
if (selectedSpec.BayCount > 1)
{
Button rotate = Action("Rotate R", RotateDeckTool, "work-tool-rotate", "facility-rotate");
rotate.tooltip = "Turn the selected fitting clockwise by 90°";
toolMode.Add(rotate);
AddText(toolMode, RotationLabel(selectedSpec), "work-tool-orientation").name = "facility-orientation";
}
var tools = Add(fittings, "work-tool-tray");
var (start, end) = deckTools switch
Facility[] options = deckTools switch
{
DeckTools.LargerVenues => (Facility.Suite, Facility.Extension),
DeckTools.ShipSystems => (Facility.Galley, Facility.Suite),
_ => (Facility.Cabin, Facility.Galley)
DeckTools.LargerVenues => ExpandedTools,
DeckTools.LeisureAndRetail => LeisureTools,
DeckTools.ShipSystems => SystemsTools,
_ => GuestTools
};
for (int i = (int)start; i <= (int)end; i++)
foreach (Facility option in options)
{
Facility option = i == (int)end ? Facility.Empty : (Facility)i;
FacilitySpec spec = Market.Facilities[(int)option];
bool locked = ship.HullIndex < spec.MinimumHull;
Button button = Action("", () =>
{
if (tool != option)
toolRotation = 0;
tool = option;
Notify(null);
Render();
@@ -131,9 +157,9 @@ namespace Soundings
copy.pickingMode = PickingMode.Ignore;
AddText(copy, spec.Name, "work-tool-name");
string price = option == Facility.Empty ? "25% refund" : Money(spec.Price);
if (spec.Length > 1)
if (spec.BayCount > 1)
{
price = $"{spec.Length} bays · {price}";
price = $"{FootprintLabel(spec, 0)} · {price}";
button.AddToClassList("work-tool-larger");
}
AddText(copy, price, "work-tool-cost");
@@ -143,11 +169,12 @@ namespace Soundings
}
}
private void DrawBerthGrid(VisualElement layout, Label instruction, Ship ship)
private Action DrawBerthGrid(VisualElement layout, Label instruction, Ship ship)
{
Deck deck = ship.Decks[deckIndex];
int columns = ship.Hull.Columns;
var berths = new Button[deck.Cells.Length];
var strips = new VisualElement[ship.Hull.Rows];
int hovered = -1, focused = -1;
void UpdatePreview()
@@ -160,24 +187,26 @@ namespace Soundings
}
if (selected < 0)
{
instruction.text = PlacementInstruction(ship, tool);
instruction.text = PlacementInstruction(ship, tool, toolRotation);
return;
}
Facility room = deck.FacilityAt(selected, columns);
int anchor = room == Facility.Empty ? selected : deck.AnchorAt(selected, columns);
Facility sizeOf = room == Facility.Empty ? tool : room;
int span = Market.Facilities[(int)sizeOf].Length;
string blocked = PlacementBlock(ship, selected, room);
instruction.text = BerthDescription(deck, columns, selected, room, tool, blocked);
int rowEnd = (anchor / columns + 1) * columns;
for (int i = anchor; i < Mathf.Min(rowEnd, anchor + span); i++)
berths[i].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked");
bool planning = room == Facility.Empty || room == tool;
FacilitySpec spec = Market.Facilities[(int)(planning ? tool : room)];
int rotation = planning ? toolRotation : deck.RotationAt(anchor);
string blocked = PlacementBlock(ship, selected);
instruction.text = BerthDescription(deck, columns, selected, room, tool, toolRotation, blocked);
foreach (Vector2Int offset in spec.Footprint(rotation))
if (deck.TryCellAt(anchor, columns, offset, out int bay))
berths[bay].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked");
}
for (int row = 0; row < ship.Hull.Rows; row++)
{
var strip = Add(layout, "work-berth-row");
strips[row] = strip;
for (int column = 0; column < columns; column++)
{
int cell = row * columns + column;
@@ -188,8 +217,6 @@ namespace Soundings
Button berth = Action("", () => BuildAtBerth(ship, deck, cell), "work-berth work-room-" + (int)existing, "berth-" + cell);
berths[cell] = berth;
slot.Add(berth);
string blocked = PlacementBlock(ship, cell, existing);
berth.tooltip = BerthDescription(deck, columns, cell, existing, tool, blocked);
berth.RegisterCallback<PointerEnterEvent>(_ => { hovered = cell; UpdatePreview(); });
berth.RegisterCallback<PointerLeaveEvent>(_ => { hovered = -1; UpdatePreview(); });
berth.RegisterCallback<FocusInEvent>(_ => { focused = cell; UpdatePreview(); });
@@ -197,36 +224,67 @@ namespace Soundings
AddText(berth, BerthName(cell, columns), "work-berth-index");
if (existing == Facility.Empty)
AddText(berth, "+", "work-berth-open");
else if (room.Length == 1)
else if (room.BayCount == 1)
AddVenueLabel(berth, existing);
else
{
berth.EnableInClassList("work-berth-join-left", anchor < cell);
berth.EnableInClassList("work-berth-join-right", anchor + room.Length - 1 > cell);
berth.EnableInClassList("work-berth-join-left", column > 0 && SameVenue(cell - 1));
berth.EnableInClassList("work-berth-join-right", column + 1 < columns && SameVenue(cell + 1));
berth.EnableInClassList("work-berth-join-top", row > 0 && SameVenue(cell - columns));
berth.EnableInClassList("work-berth-join-bottom", row + 1 < ship.Hull.Rows && SameVenue(cell + columns));
}
bool SameVenue(int other) => deck.AnchorAt(other, columns) == anchor;
}
}
for (int column = 0; column < columns; column++)
for (int anchor = 0; anchor < deck.Cells.Length; anchor++)
{
Facility room = deck.Cells[anchor];
FacilitySpec spec = Market.Facilities[(int)room];
if (spec.BayCount <= 1)
continue;
var (row, start, span) = CaptionRow(spec.Footprint(deck.RotationAt(anchor)));
var label = Add(strips[anchor / columns + row], "work-span-caption");
label.pickingMode = PickingMode.Ignore;
label.style.left = Length.Percent(100f * (anchor % columns + start) / columns);
label.style.width = Length.Percent(100f * span / columns);
AddVenueLabel(label, room);
}
Refresh();
return Refresh;
void Refresh()
{
for (int cell = 0; cell < berths.Length; cell++)
{
Facility room = deck.Cells[row * columns + column];
int span = Market.Facilities[(int)room].Length;
if (span <= 1)
continue;
var label = Add(strip, "work-span-caption");
label.pickingMode = PickingMode.Ignore;
label.style.left = Length.Percent(100f * column / columns);
label.style.width = Length.Percent(100f * span / columns);
AddVenueLabel(label, room);
Facility room = deck.FacilityAt(cell, columns);
berths[cell].tooltip = BerthDescription(deck, columns, cell, room, tool, toolRotation,
PlacementBlock(ship, cell));
}
UpdatePreview();
}
}
private string PlacementBlock(Ship ship, int cell, Facility existing)
private static (int Row, int First, int Span) CaptionRow(IReadOnlyList<Vector2Int> footprint)
{
(int row, int start, int span) = (0, 0, 1);
for (int first = 0; first < footprint.Count;)
{
int end = first + 1;
while (end < footprint.Count && footprint[end].y == footprint[first].y)
end++;
if (end - first > span)
(row, start, span) = (footprint[first].y, footprint[first].x, end - first);
first = end;
}
return (row, start, span);
}
private string PlacementBlock(Ship ship, int cell)
{
if (existing != Facility.Empty && tool != Facility.Empty)
return null;
FacilitySpec spec = Market.Facilities[(int)tool];
return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool);
return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool, toolRotation);
}
private void BuildAtBerth(Ship ship, Deck deck, int cell)
@@ -234,15 +292,18 @@ namespace Soundings
int columns = ship.Hull.Columns;
int anchor = deck.AnchorAt(cell, columns);
Facility previous = deck.FacilityAt(cell, columns);
string failure = company.Build(ship, deckIndex, cell, tool);
if (failure == null && previous != tool)
SetRecommendedFuel();
int oldRotation = deck.RotationAt(anchor);
FacilitySpec room = Market.Facilities[(int)(tool == Facility.Empty ? previous : tool)];
string area = BerthRange(tool == Facility.Empty ? anchor : cell, room.Length, columns);
int footprintRotation = tool == Facility.Empty ? oldRotation : toolRotation;
string area = BerthNames(deck, columns, previous == Facility.Empty ? cell : anchor, room.Footprint(footprintRotation));
string failure = company.Build(ship, deckIndex, cell, tool, toolRotation);
bool turned = previous == tool && previous != Facility.Empty && oldRotation != deck.RotationAt(anchor);
if (failure == null && (previous != tool || turned))
SetRecommendedFuel();
string confirmation = tool == Facility.Empty
? $"Removed {room.Name.ToLowerInvariant()} from {area}."
: $"Built {room.Name.ToLowerInvariant()} at {area}.";
Apply(failure, previous == tool ? null : confirmation);
: $"{(turned ? "Rotated" : "Built")} {room.Name.ToLowerInvariant()} at {area}.";
Apply(failure, previous == tool && !turned ? null : confirmation);
}
private void AddBuildToolTab(VisualElement parent, string label, string id, DeckTools group, Facility initial)
@@ -253,6 +314,7 @@ namespace Soundings
return;
deckTools = group;
tool = initial;
toolRotation = 0;
Notify(null);
Render();
}, deckTools == group ? "work-selected" : "", id);
@@ -273,39 +335,74 @@ namespace Soundings
return $"Requires a {hull.Name} hull. Unlock the hull with {hull.Voyages} completed voyages and {hull.Reputation} reputation.";
}
private static string PlacementInstruction(Ship ship, Facility selected)
private string RotationLabel(FacilitySpec spec) => $"{FootprintLabel(spec, toolRotation)} · {toolRotation * 90}°";
private void RotateDeckTool()
{
FacilitySpec spec = Market.Facilities[(int)tool];
if (spec.BayCount <= 1 || root.Q<Label>("facility-orientation") is not Label orientation)
return;
toolRotation = (toolRotation + 1) & 3;
orientation.text = RotationLabel(spec);
refreshDeckPlacement?.Invoke();
}
private static string PlacementInstruction(Ship ship, Facility selected, int rotation)
{
FacilitySpec spec = Market.Facilities[(int)selected];
if (selected == Facility.Empty)
return "Select any bay in a fitted room to remove it and recover 25%.";
if (ship.HullIndex < spec.MinimumHull)
return VenueRequirement(spec);
string plan = spec.Length == 1 ? "Select an open bay" : $"Select the sternmost of {spec.Length} open bays in a row";
return $"{plan} to build {spec.Name.ToLowerInvariant()}. {spec.Details} · {Money(spec.Price)}";
string plan = spec.BayCount == 1 ? "Select an open bay" : $"Point at a bay to preview the {FootprintLabel(spec, rotation)} fitting";
return $"{plan}. {spec.Name} · {spec.Details} · {Money(spec.Price)}";
}
private static string BerthName(int cell, int columns) => $"{(char)('A' + cell / columns)}{cell % columns + 1}";
private static string BerthRange(int start, int span, int columns)
private static string FootprintLabel(FacilitySpec spec, int rotation)
{
int end = Mathf.Min(start + span - 1, (start / columns + 1) * columns - 1);
return end == start ? BerthName(start, columns) : $"{BerthName(start, columns)}–{BerthName(end, columns)}";
int left = 0, right = 0, depth = 1;
foreach (Vector2Int offset in spec.Footprint(rotation))
{
left = Mathf.Min(left, offset.x);
right = Mathf.Max(right, offset.x);
depth = Mathf.Max(depth, offset.y + 1);
}
int width = right - left + 1;
return spec.BayCount == width * depth ? $"{width}×{depth} bays" : $"L-shaped · {spec.BayCount} bays";
}
private static string BerthDescription(Deck deck, int columns, int cell, Facility room, Facility selected, string blocked)
private static string BerthNames(Deck deck, int columns, int anchor, IReadOnlyList<Vector2Int> footprint)
{
var names = new List<string>(footprint.Count);
foreach (Vector2Int offset in footprint)
if (deck.TryCellAt(anchor, columns, offset, out int bay))
names.Add(BerthName(bay, columns));
return string.Join(", ", names);
}
private static string BerthDescription(Deck deck, int columns, int cell, Facility room, Facility selected, int rotation, string blocked)
{
if (blocked != null)
return $"{BerthName(cell, columns)} · {blocked}";
FacilitySpec existing = Market.Facilities[(int)room];
if (blocked != null)
return room == Facility.Empty ? $"{BerthName(cell, columns)} · {blocked}"
: $"{BerthName(cell, columns)} · {existing.Name} · {blocked}";
if (room == Facility.Empty)
{
FacilitySpec fitting = Market.Facilities[(int)selected];
string location = BerthRange(cell, fitting.Length, columns);
string location = BerthNames(deck, columns, cell, fitting.Footprint(rotation));
return selected == Facility.Empty
? $"{location} is already clear."
: $"{location} · {fitting.Name} · {fitting.Details} · {Money(fitting.Price)}";
}
string area = BerthRange(deck.AnchorAt(cell, columns), existing.Length, columns);
int anchor = deck.AnchorAt(cell, columns);
if (selected == room && rotation != deck.RotationAt(anchor))
{
string newArea = BerthNames(deck, columns, anchor, existing.Footprint(rotation));
return $"{existing.Name} · Rotate to {rotation * 90}° across {newArea}";
}
string area = BerthNames(deck, columns, anchor, existing.Footprint(deck.RotationAt(anchor)));
return selected == Facility.Empty
? $"{area} · Remove {existing.Name.ToLowerInvariant()} and recover {Money(existing.Price / 4)}"
: $"{area} · {existing.Name} · {existing.Details}";
@@ -375,10 +472,23 @@ namespace Soundings
break;
case Facility.Amenity:
case Facility.ResortPool:
case Facility.WaterPark:
Segment(4,11,6,7,10,5,14,5,18,7,20,11,4,11);
Line(12,11,12,17);
Segment(3,19,6,17,9,19,12,17,15,19,18,17,21,19);
break;
case Facility.Spa:
Segment(4,13,20,13,18,18,6,18,4,13);
Segment(8,10,7,8,9,5,8,3);
Segment(12,10,11,8,13,5,12,3);
Segment(16,10,15,8,17,5,16,3);
break;
case Facility.Shop:
case Facility.ShoppingArcade:
Segment(5,8,19,8,21,20,3,20,5,8);
Segment(9,9,9,6,10,4,14,4,15,6,15,9);
Line(8,15,16,15);
break;
case Facility.Galley:
Segment(3,13,17,13,15,18,5,18,3,13);
Line(17,13,22,11);