129 lines
7.1 KiB
C#
129 lines
7.1 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UIElements;
|
||
|
||
namespace Soundings
|
||
{
|
||
public sealed partial class SoundingsApp
|
||
{
|
||
private bool sunDeckEditing;
|
||
|
||
private static readonly (SunPoolStyle Style, string Label, string Id)[] SunPools =
|
||
{
|
||
(SunPoolStyle.Automatic, "Auto", "auto"), (SunPoolStyle.None, "None", "none"),
|
||
(SunPoolStyle.Compact, "Compact", "compact"), (SunPoolStyle.Family, "Family", "family"),
|
||
(SunPoolStyle.Resort, "Resort", "resort")
|
||
};
|
||
|
||
private static readonly (SunAttraction Fitting, string Label, string Id)[] SunAttractions =
|
||
{
|
||
(SunAttraction.Automatic, "Auto", "auto"), (SunAttraction.None, "None", "none"),
|
||
(SunAttraction.MiniGolf, "Mini golf", "golf"), (SunAttraction.Theater, "Outdoor theater", "theater"),
|
||
(SunAttraction.GoKarts, "Go-karts", "karts"), (SunAttraction.RollerCoaster, "Roller coaster", "coaster")
|
||
};
|
||
|
||
private void DrawSunDeckEditor(VisualElement work, Ship ship)
|
||
{
|
||
SunDeckPlan plan = ship.SunDeckPlan;
|
||
VesselExterior.SunDeckLayout layout = VesselExterior.SunDeck(ship);
|
||
var board = Add(work, "work-draft");
|
||
board.generateVisualContent += context => DrawDeckOutline(context, ship.Hull.Columns);
|
||
var markings = Add(board, "work-draft-markings");
|
||
AddText(markings, "STERN", "work-caption");
|
||
AddText(markings, "SUN DECK", "work-caption");
|
||
AddText(markings, "BOW →", "work-caption");
|
||
var diagram = Add(board, "sun-deck-diagram");
|
||
|
||
if (layout.Attraction != SunAttraction.None)
|
||
AddSunDiagramFit(diagram, layout, layout.AttractionCenter, layout.AttractionHalfSize.x, layout.AttractionHalfSize.y,
|
||
System.Array.Find(SunAttractions, option => option.Fitting == layout.Attraction).Label, "sun-diagram-attraction");
|
||
AddSunDiagramFit(diagram, layout, layout.Offset - layout.Length * .24f, 2.25f, layout.HalfBeam * .34f,
|
||
"Funnels", "sun-diagram-fixed");
|
||
AddSunDiagramFit(diagram, layout, VesselExterior.BridgeCenter(ship.Hull.Length, ship.Decks.Count), 4.55f,
|
||
layout.HalfBeam * .70f, "Bridge", "sun-diagram-fixed");
|
||
if (layout.HasPool)
|
||
AddSunDiagramFit(diagram, layout, layout.PoolCenter, layout.PoolHalfSize.x, layout.PoolHalfSize.y,
|
||
"Pool", layout.OvalPool ? "sun-diagram-pool sun-diagram-oval" : "sun-diagram-pool");
|
||
|
||
var fittings = Add(work, "work-fittings sun-deck-panel");
|
||
var capacity = Add(fittings, "work-capacity-strip");
|
||
AddText(capacity, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity");
|
||
AddText(capacity, $"{ship.Entertainment:N0} show seats", "work-capacity");
|
||
if (layout.HasPool)
|
||
AddText(capacity, $"Pool {layout.PoolHalfSize.x * 2:0.0} × {layout.PoolHalfSize.y * 2:0.0} m", "work-capacity");
|
||
AddText(capacity, $"{layout.Loungers * 2} loungers", "work-capacity");
|
||
|
||
var pools = SunDeckOptions(fittings, "Pool size");
|
||
foreach (var option in SunPools)
|
||
{
|
||
SunDeckPlan next = plan;
|
||
next.Pool = option.Style;
|
||
AddSunOption(pools, ship, next, option.Label, "sun-pool-" + option.Id, plan.Pool == option.Style,
|
||
option.Style == SunPoolStyle.Resort ? Market.Regional : 0);
|
||
}
|
||
|
||
var poolTrim = SunDeckOptions(fittings, "Pool layout");
|
||
foreach (SunPoolPosition position in new[] { SunPoolPosition.Aft, SunPoolPosition.Midship, SunPoolPosition.Forward })
|
||
{
|
||
SunDeckPlan next = plan;
|
||
next.Position = position;
|
||
AddSunOption(poolTrim, ship, next, position.ToString(), "sun-pool-" + position.ToString().ToLowerInvariant(), plan.Position == position);
|
||
}
|
||
var rectangle = plan;
|
||
rectangle.Shape = SunPoolShape.Rectangle;
|
||
AddSunOption(poolTrim, ship, rectangle, "Rectangle", "sun-shape-rectangle", plan.Shape == SunPoolShape.Rectangle);
|
||
var oval = plan;
|
||
oval.Shape = SunPoolShape.Oval;
|
||
AddSunOption(poolTrim, ship, oval, "Oval", "sun-shape-oval", plan.Shape == SunPoolShape.Oval);
|
||
var shade = plan;
|
||
shade.NoShade = !plan.NoShade;
|
||
AddSunOption(poolTrim, ship, shade, plan.NoShade ? "Add parasols" : "Remove parasols", "sun-shade", false);
|
||
var seating = plan;
|
||
seating.ExtraLoungers = !plan.ExtraLoungers;
|
||
AddSunOption(poolTrim, ship, seating, plan.ExtraLoungers ? "Standard seating" : "Extra loungers", "sun-loungers", false);
|
||
|
||
var attractions = SunDeckOptions(fittings, "Stern attraction");
|
||
foreach (var option in SunAttractions)
|
||
{
|
||
SunDeckPlan next = plan;
|
||
next.Attraction = option.Fitting;
|
||
AddSunOption(attractions, ship, next, option.Label, "sun-attraction-" + option.Id,
|
||
plan.Attraction == option.Fitting, SunDeckPlan.RequiredHull(option.Fitting));
|
||
}
|
||
}
|
||
|
||
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 AddSunOption(VisualElement row, Ship ship, SunDeckPlan next, string label, string id, bool selected,
|
||
int minimumHull = 0)
|
||
{
|
||
string requirement = ship.HullIndex < minimumHull ? $"Requires a {Market.Hulls[minimumHull].Name} hull" : null;
|
||
int cost = Company.SunDeckCost(ship, next);
|
||
string detail = requirement == null && cost > 0 ? $" {Money(cost)}" : "";
|
||
Button option = Action(label + detail, () => Apply(company.ChangeSunDeck(ship, next), "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)}" : "No refit charge");
|
||
row.Add(option);
|
||
}
|
||
|
||
private static void AddSunDiagramFit(VisualElement diagram, VesselExterior.SunDeckLayout layout,
|
||
float center, float halfLength, float halfWidth, string caption, string classes)
|
||
{
|
||
var outline = Add(diagram, "sun-diagram-fitting " + classes);
|
||
float x = Mathf.InverseLerp(layout.Offset - layout.Length * .50f, layout.Offset + layout.Length * .50f, center);
|
||
float width = halfLength * 174f / layout.Length;
|
||
float height = halfWidth * 69f / layout.HalfBeam;
|
||
outline.style.left = Length.Percent(6 + x * 87 - width * .5f);
|
||
outline.style.top = Length.Percent(50 - height * .5f);
|
||
outline.style.width = Length.Percent(width);
|
||
outline.style.height = Length.Percent(height);
|
||
AddText(outline, caption, "sun-diagram-label");
|
||
}
|
||
}
|
||
}
|