Rebuild Soundings around harbor gameplay and guided careers
This commit is contained in:
@@ -7,23 +7,25 @@ namespace Soundings
|
||||
public sealed partial class SoundingsApp : MonoBehaviour
|
||||
{
|
||||
private const string SaveKey = "soundings.company.v1";
|
||||
private static readonly string[] Pages = { "Operations", "Deck plans", "Shipyard", "Ports", "Finance" };
|
||||
private static readonly int[] HotbarPages = { 0, 3, 1, 2, 4 };
|
||||
private static readonly string[] HotbarNames = { "Harbor", "Chart", "Deck plans", "Shipyard", "Logbook" };
|
||||
private static FontDefinition interfaceFont;
|
||||
private Company company;
|
||||
private Harbor harbor;
|
||||
private PanelSettings panel;
|
||||
private VisualElement root;
|
||||
private Font displayFont;
|
||||
private ScrollView pageScroll;
|
||||
private bool title = true;
|
||||
private Texture2D titleArt;
|
||||
private bool title = true, guidedCareer = true, paused, fleetOpen, shipActionsOpen;
|
||||
private bool? pendingStart;
|
||||
private int page, renderedPage = -1, deckIndex, destination = -1, bunkerTons, yardSelection;
|
||||
private int page, deckIndex, destination = -1, bunkerTons, yardSelection;
|
||||
private Facility tool = Facility.Cabin;
|
||||
private string shipName = "Peregrine";
|
||||
private string notice;
|
||||
private bool warning;
|
||||
private bool autoSmoke;
|
||||
private Ship Ship => company?.ActiveShip;
|
||||
private bool HarborOnScreen => underway != null || page <= 2;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
|
||||
private static void Boot()
|
||||
@@ -34,36 +36,37 @@ namespace Soundings
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
Culture();
|
||||
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
|
||||
autoSmoke = Array.IndexOf(Environment.GetCommandLineArgs(), "-soundings-smoke") >= 0;
|
||||
Application.targetFrameRate = 60;
|
||||
harbor = gameObject.AddComponent<Harbor>();
|
||||
harbor.Initialize();
|
||||
displayFont = Resources.Load<Font>("Display");
|
||||
interfaceFont = FontDefinition.FromFont(Resources.Load<Font>("Interface"));
|
||||
titleArt = Resources.Load<Texture2D>("Art/FlagshipTitle");
|
||||
panel = ScriptableObject.CreateInstance<PanelSettings>();
|
||||
panel.scaleMode = PanelScaleMode.ScaleWithScreenSize;
|
||||
panel.referenceResolution = new Vector2Int(1440, 810);
|
||||
panel.screenMatchMode = PanelScreenMatchMode.MatchWidthOrHeight;
|
||||
panel.match = 0;
|
||||
panel.match = .36f;
|
||||
panel.themeStyleSheet = Resources.Load<ThemeStyleSheet>("SoundingsTheme");
|
||||
var document = gameObject.AddComponent<UIDocument>();
|
||||
document.panelSettings = panel;
|
||||
root = document.rootVisualElement;
|
||||
root.style.flexGrow = 1;
|
||||
root.style.unityFontDefinition = interfaceFont;
|
||||
root.styleSheets.Add(Resources.Load<StyleSheet>("Soundings"));
|
||||
foreach (string sheet in new[] { "Soundings", "Shipwork", "Ledger", "FirstVoyageGuide" })
|
||||
{
|
||||
StyleSheet stylesheet = Resources.Load<StyleSheet>(sheet);
|
||||
if (stylesheet != null)
|
||||
root.styleSheets.Add(stylesheet);
|
||||
}
|
||||
company = autoSmoke ? null : Load();
|
||||
Render();
|
||||
if (autoSmoke)
|
||||
StartCoroutine(VisualSmoke());
|
||||
}
|
||||
|
||||
private static void Culture()
|
||||
{
|
||||
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
|
||||
}
|
||||
|
||||
private Company Load()
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(SaveKey))
|
||||
@@ -78,8 +81,7 @@ namespace Soundings
|
||||
{
|
||||
Debug.LogWarning("Could not read the company save. " + exception.Message);
|
||||
}
|
||||
notice = "The company save could not be read.";
|
||||
warning = true;
|
||||
Notify("The company save could not be read.", true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -94,18 +96,23 @@ namespace Soundings
|
||||
private void StartCompany(bool financed)
|
||||
{
|
||||
company = Company.Start(financed);
|
||||
title = false;
|
||||
title = paused = fleetOpen = shipActionsOpen = false;
|
||||
page = financed ? 2 : 0;
|
||||
yardSelection = 1;
|
||||
deckIndex = 0;
|
||||
inspectedPort = 1;
|
||||
selectedVoyage = 0;
|
||||
ledgerRecordOffset = 0;
|
||||
ledgerAccounts = false;
|
||||
worldChart = false;
|
||||
tool = Facility.Cabin;
|
||||
shipName = "Peregrine";
|
||||
pendingStart = null;
|
||||
harbor.ResetView(true);
|
||||
ResetItinerary();
|
||||
Notify(financed ? "Choose a hull in the shipyard to begin." : "Meridian is fueled for its first sailing to Nassau.");
|
||||
Notify(financed && !guidedCareer ? "Choose your first hull." : null);
|
||||
if (guidedCareer)
|
||||
StartGuide(financed);
|
||||
Save();
|
||||
Render();
|
||||
}
|
||||
@@ -139,7 +146,10 @@ namespace Soundings
|
||||
|
||||
private void ChangePage(int next)
|
||||
{
|
||||
if (underway != null || paused)
|
||||
return;
|
||||
page = next;
|
||||
fleetOpen = shipActionsOpen = false;
|
||||
if (destination < 0)
|
||||
ResetItinerary();
|
||||
Notify(null);
|
||||
@@ -163,77 +173,80 @@ namespace Soundings
|
||||
private void Render()
|
||||
{
|
||||
string focus = (root.focusController?.focusedElement as VisualElement)?.name;
|
||||
float scrollOffset = page == renderedPage ? pageScroll?.verticalScroller.value ?? 0 : 0;
|
||||
root.Clear();
|
||||
bool showingVessel = !title && Ship != null && (page == 0 || page == 1);
|
||||
harbor.SetVisible(showingVessel);
|
||||
if (showingVessel)
|
||||
bool showingHarbor = !title && company != null && HarborOnScreen;
|
||||
harbor.SetVisible(showingHarbor);
|
||||
if (showingHarbor)
|
||||
harbor.Show(Ship);
|
||||
|
||||
if (title || company == null)
|
||||
{
|
||||
pageScroll = null;
|
||||
renderedPage = -1;
|
||||
DrawTitle();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderedPage = page;
|
||||
RefreshGuide();
|
||||
DrawShell();
|
||||
if (paused)
|
||||
DrawPause();
|
||||
}
|
||||
|
||||
if (pageScroll != null && scrollOffset > 0)
|
||||
{
|
||||
ScrollView scroll = pageScroll;
|
||||
scroll.schedule.Execute(() => scroll.verticalScroller.value = scrollOffset);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(focus))
|
||||
if (!string.IsNullOrEmpty(focus) && root.Q<VisualElement>(focus) != null)
|
||||
root.schedule.Execute(() => root.Q<VisualElement>(focus)?.Focus());
|
||||
}
|
||||
|
||||
private void DrawTitle()
|
||||
{
|
||||
var screen = Add(root, "title-screen");
|
||||
var intro = Add(screen, "title-intro");
|
||||
var crest = Add(intro, "brand crest");
|
||||
AddMark(crest);
|
||||
AddText(intro, "CRUISE LINE SIMULATOR", "eyebrow");
|
||||
AddDisplay(intro, "Soundings", "title-display");
|
||||
AddText(intro, "From a single ship to a world-spanning cruise line.", "title-copy");
|
||||
var screen = Add(root, "game-title-screen");
|
||||
var artwork = new Image
|
||||
{
|
||||
image = titleArt,
|
||||
scaleMode = ScaleMode.ScaleAndCrop,
|
||||
pickingMode = PickingMode.Ignore
|
||||
};
|
||||
artwork.AddToClassList("title-picture");
|
||||
screen.Add(artwork);
|
||||
Shade(screen, false, (0f, new Color32(9, 16, 22, 253)), (.24f, new Color32(9, 16, 22, 249)),
|
||||
(.35f, new Color32(9, 16, 22, 205)),
|
||||
(.61f, new Color32(9, 16, 22, 38)), (1f, new Color32(9, 16, 22, 0)));
|
||||
Shade(screen, true, (0f, new Color32(6, 12, 18, 12)), (.59f, new Color32(6, 12, 18, 20)),
|
||||
(1f, new Color32(6, 12, 18, 143)));
|
||||
|
||||
var intro = Add(screen, "title-menu");
|
||||
var crest = Add(intro, "title-crest");
|
||||
GameIcon(crest, "compass");
|
||||
AddText(crest, "Cruise line simulator", "eyebrow title-kicker");
|
||||
AddDisplay(intro, "Soundings", "title-wordmark");
|
||||
|
||||
if (pendingStart.HasValue)
|
||||
{
|
||||
AddText(intro, "Replace your saved company?", "card-title");
|
||||
AddText(intro, "Starting a new company overwrites your current fleet and voyage history.", "body-copy");
|
||||
intro.Add(Action("Replace and start", () => StartCompany(pendingStart.Value), "primary title-action", "replace"));
|
||||
intro.Add(Action("Keep current company", () => { pendingStart = null; Render(); }, "title-action", "keep"));
|
||||
AddDisplay(intro, "Replace this company?", "title-question");
|
||||
AddText(intro, "A new career replaces your saved fleet and voyages.", "title-confirm-copy");
|
||||
intro.Add(Action("Start a new career", () => StartCompany(pendingStart.Value), "primary title-command", "replace"));
|
||||
intro.Add(Action("Keep my company", () => { pendingStart = null; Render(); }, "title-command", "keep"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (company != null)
|
||||
intro.Add(Action("Resume company →", () =>
|
||||
intro.Add(Action("Continue career", () =>
|
||||
{
|
||||
title = false;
|
||||
page = Ship == null ? 2 : 0;
|
||||
ResetItinerary();
|
||||
Notify(null);
|
||||
Render();
|
||||
}, "primary title-action", "resume"));
|
||||
StartOption(intro, "Take over a regional ship", "Used coastal ship · $135,000 cash · No debt", false);
|
||||
StartOption(intro, "Finance a new fleet", "$580,000 cash · $500,000 loan · Empty fleet", true);
|
||||
}, "primary title-command", "resume"));
|
||||
|
||||
StartOption(intro, "Take the helm", "Used coastal ship / $135,000 cash / No debt", false);
|
||||
StartOption(intro, "Start from the shipyard", "Empty fleet / $580,000 cash / $500,000 loan", true);
|
||||
intro.Add(Action($"First voyage guide: {(guidedCareer ? "On" : "Off")}", () =>
|
||||
{
|
||||
guidedCareer = !guidedCareer;
|
||||
Render();
|
||||
}, "title-guide-toggle", "guide-toggle"));
|
||||
}
|
||||
|
||||
AddNotice(intro);
|
||||
var picture = Add(screen, "title-visual");
|
||||
var artwork = new Image
|
||||
{
|
||||
image = Resources.Load<Texture2D>("Art/FlagshipTitle"),
|
||||
scaleMode = ScaleMode.ScaleAndCrop,
|
||||
pickingMode = PickingMode.Ignore
|
||||
};
|
||||
artwork.AddToClassList("harbor-image");
|
||||
picture.Add(artwork);
|
||||
var location = Add(picture, "splash-location");
|
||||
AddText(location, "OCEAN CLASS", "eyebrow on-image");
|
||||
AddText(location, "FLAGSHIP CONCEPT", "tag on-image");
|
||||
if (!Application.isEditor && Application.platform != RuntimePlatform.WebGLPlayer)
|
||||
intro.Add(Action("Quit game", () => Application.Quit(), "title-quit", "title-quit"));
|
||||
}
|
||||
|
||||
private void StartOption(VisualElement parent, string titleText, string description, bool financed)
|
||||
@@ -247,41 +260,150 @@ namespace Soundings
|
||||
pendingStart = financed;
|
||||
Render();
|
||||
}
|
||||
}, "start-option", financed ? "start-financed" : "start-used");
|
||||
AddText(option, titleText, "option-title");
|
||||
AddText(option, description, "muted");
|
||||
}, "career-option", financed ? "start-financed" : "start-used");
|
||||
AddText(option, titleText, "career-option-name");
|
||||
AddText(option, description, "career-option-balance");
|
||||
parent.Add(option);
|
||||
}
|
||||
|
||||
private void DrawShell()
|
||||
{
|
||||
var shell = Add(root, "shell");
|
||||
var mast = Add(shell, "mast");
|
||||
var brand = Add(mast, "brand mast-brand");
|
||||
AddMark(brand);
|
||||
AddText(brand, "Soundings", "brand-type");
|
||||
AddText(brand, "CRUISE LINE SIMULATOR", "mast-sub");
|
||||
var metrics = Add(mast, "mast-metrics");
|
||||
HeadMetric(metrics, "CASH", Money(company.Cash), "gold");
|
||||
HeadMetric(metrics, "REPUTATION", $"{company.Reputation} / 100");
|
||||
HeadMetric(metrics, "DAY", company.Day.ToString("00"));
|
||||
mast.Add(Action("Company menu", () => { title = true; Notify(null); Render(); }, "menu-button", "company-menu"));
|
||||
|
||||
var body = Add(shell, "body");
|
||||
var rail = Add(body, "rail");
|
||||
AddText(rail, "MANAGEMENT", "rail-heading eyebrow");
|
||||
for (int i = 0; i < Pages.Length; i++)
|
||||
var shell = Add(root, "game-shell");
|
||||
var world = Add(shell, "harbor-viewport");
|
||||
if (HarborOnScreen)
|
||||
{
|
||||
int target = i;
|
||||
Button nav = Action("", () => ChangePage(target), page == i ? "nav current" : "nav", "nav-" + i);
|
||||
AddText(nav, Pages[i], "nav-name");
|
||||
rail.Add(nav);
|
||||
AddHarbor(world);
|
||||
if (page == 0 || underway != null)
|
||||
{
|
||||
AttachCamera(world);
|
||||
Shade(shell, true, (0f, new Color32(5, 13, 19, 177)), (.23f, new Color32(5, 13, 19, 4)),
|
||||
(.67f, new Color32(5, 13, 19, 4)), (1f, new Color32(5, 13, 19, 231)));
|
||||
}
|
||||
else
|
||||
Add(shell, "workspace-veil").pickingMode = PickingMode.Ignore;
|
||||
}
|
||||
|
||||
AddText(rail, $"FLEET / {company.Fleet.Count:00}", "rail-heading fleet-heading eyebrow");
|
||||
var fleet = new ScrollView(ScrollViewMode.Vertical) { verticalScrollerVisibility = ScrollerVisibility.Auto };
|
||||
fleet.AddToClassList("fleet-scroll");
|
||||
rail.Add(fleet);
|
||||
var scene = Add(shell, "game-scene");
|
||||
scene.pickingMode = PickingMode.Ignore;
|
||||
scene.SetEnabled(!paused);
|
||||
if (underway != null)
|
||||
DrawUnderway(scene);
|
||||
else
|
||||
{
|
||||
switch (page)
|
||||
{
|
||||
case 0: DrawHarborScene(scene); break;
|
||||
case 1: DrawDecks(scene); break;
|
||||
case 2: DrawShipyard(scene); break;
|
||||
case 3: DrawPorts(scene); break;
|
||||
case 4: DrawFinance(scene); break;
|
||||
}
|
||||
}
|
||||
|
||||
var hud = Add(shell, "game-hud");
|
||||
hud.pickingMode = PickingMode.Ignore;
|
||||
hud.SetEnabled(!paused);
|
||||
var hudLeft = Add(hud, "hud-left");
|
||||
Button menu = Action("", () => { paused = true; Render(); }, "menu-icon", "company-menu");
|
||||
menu.tooltip = "Pause menu (Esc)";
|
||||
GameIcon(menu, "menu");
|
||||
hudLeft.Add(menu);
|
||||
AddDisplay(hudLeft, "Soundings", "hud-brand");
|
||||
|
||||
var instruments = Add(hud, "hud-instruments");
|
||||
HeadMetric(instruments, "Day", company.Day.ToString("00"));
|
||||
HeadMetric(instruments, "Reputation", company.Reputation.ToString());
|
||||
HeadMetric(instruments, "Treasury", Money(company.Cash), "hud-money");
|
||||
if (underway == null)
|
||||
{
|
||||
hudLeft.Add(Action($"Fleet {company.Fleet.Count}", () =>
|
||||
{
|
||||
fleetOpen = !fleetOpen;
|
||||
shipActionsOpen = false;
|
||||
Render();
|
||||
}, "fleet-toggle", "fleet-toggle"));
|
||||
DrawHotbar(shell).SetEnabled(!paused);
|
||||
if (fleetOpen)
|
||||
DrawFleet(shell).SetEnabled(!paused);
|
||||
if (!paused && !fleetOpen)
|
||||
DrawGuide(shell);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(notice))
|
||||
{
|
||||
var toast = Add(shell, "game-toast");
|
||||
toast.pickingMode = PickingMode.Ignore;
|
||||
AddNotice(toast);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHarborScene(VisualElement scene)
|
||||
{
|
||||
Ship ship = Ship;
|
||||
PortSpec port = Market.Ports[ship?.Port ?? 0];
|
||||
var location = Add(scene, "harbor-location");
|
||||
location.pickingMode = PickingMode.Ignore;
|
||||
AddText(location, "Port of", "eyebrow port-kicker");
|
||||
AddDisplay(location, port.Name, "harbor-port-name");
|
||||
AddText(location, $"{port.Region} / {port.Country}", "harbor-port-region");
|
||||
|
||||
if (ship == null)
|
||||
{
|
||||
var empty = Add(scene, "harbor-empty");
|
||||
AddDisplay(empty, "The berth is empty", "harbor-vessel-name");
|
||||
empty.Add(Action("Visit the shipyard", () => ChangePage(2), "primary helm-command", "open-yard"));
|
||||
return;
|
||||
}
|
||||
|
||||
var vessel = Add(scene, "harbor-docket");
|
||||
vessel.pickingMode = PickingMode.Ignore;
|
||||
AddText(vessel, $"{ship.Hull.Name} / {ship.Decks.Count} decks", "eyebrow berth-kicker");
|
||||
AddDisplay(vessel, ship.Name, "harbor-vessel-name");
|
||||
var details = Add(vessel, "berth-instruments");
|
||||
AddText(details, $"Fuel {ship.Fuel:N0} / {ship.Tank:N0} t", "berth-value");
|
||||
AddText(details, $"Condition {ship.Condition}%", "berth-value");
|
||||
if (shipActionsOpen)
|
||||
{
|
||||
var actions = Add(vessel, "ship-action-strip");
|
||||
actions.Add(Action("Refit decks", () => ChangePage(1), "", "ship-refit"));
|
||||
actions.Add(Action("Overview", () => { shipActionsOpen = false; Render(); }, "", "ship-action-close"));
|
||||
}
|
||||
|
||||
var commands = Add(scene, "helm-orders");
|
||||
commands.pickingMode = PickingMode.Ignore;
|
||||
Button plan = Action("Set course", OpenVoyageChart, "primary helm-command", "plan-voyage");
|
||||
GameIcon(plan, "chart");
|
||||
commands.Add(plan);
|
||||
var camera = Add(commands, "camera-legend");
|
||||
AddText(camera, "Drag to orbit / Scroll to zoom", "camera-copy");
|
||||
Button reset = Action("Reset", () => harbor.ResetView(), "camera-reset", "reset-camera");
|
||||
reset.tooltip = "Reset harbor camera (Home)";
|
||||
camera.Add(reset);
|
||||
}
|
||||
|
||||
private VisualElement DrawHotbar(VisualElement shell)
|
||||
{
|
||||
var bar = Add(shell, "game-hotbar");
|
||||
var tools = Add(bar, "tool-belt");
|
||||
for (int i = 0; i < HotbarPages.Length; i++)
|
||||
{
|
||||
int target = HotbarPages[i];
|
||||
Button nav = Action("", () => ChangePage(target), page == target ? "game-tool selected" : "game-tool", "nav-" + target);
|
||||
nav.tooltip = $"{HotbarNames[i]} ({i + 1})";
|
||||
GameIcon(nav, target switch { 0 => "anchor", 1 => "decks", 2 => "yard", 3 => "chart", _ => "log" });
|
||||
AddText(nav, HotbarNames[i], "game-tool-name");
|
||||
AddText(nav, (i + 1).ToString(), "game-key");
|
||||
tools.Add(nav);
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
private VisualElement DrawFleet(VisualElement shell)
|
||||
{
|
||||
var popover = Add(shell, "fleet-manifest");
|
||||
AddDisplay(popover, "Fleet", "fleet-title");
|
||||
if (company.Fleet.Count == 0)
|
||||
AddText(popover, "No ships in service.", "muted");
|
||||
for (int i = 0; i < company.Fleet.Count; i++)
|
||||
{
|
||||
int selected = i;
|
||||
@@ -290,39 +412,93 @@ namespace Soundings
|
||||
{
|
||||
company.SelectedShip = selected;
|
||||
deckIndex = 0;
|
||||
fleetOpen = false;
|
||||
ResetItinerary();
|
||||
Apply(null, null);
|
||||
}, i == company.SelectedShip ? "ship-item selected" : "ship-item", "fleet-" + i);
|
||||
AddText(entry, ship.Name, "ship-name");
|
||||
AddText(entry, Market.Ports[ship.Port].Name + " · " + ship.Hull.Name, "ship-location");
|
||||
fleet.Add(entry);
|
||||
}, i == company.SelectedShip ? "fleet-entry fleet-active" : "fleet-entry", "fleet-" + i);
|
||||
AddText(entry, ship.Name, "fleet-name");
|
||||
AddText(entry, Market.Ports[ship.Port].Name, "muted");
|
||||
popover.Add(entry);
|
||||
}
|
||||
if (company.Fleet.Count == 0)
|
||||
AddText(fleet, "No ships yet", "fleet-empty");
|
||||
popover.Add(Action("Close fleet", () => { fleetOpen = false; Render(); }, "fleet-close", "fleet-close"));
|
||||
return popover;
|
||||
}
|
||||
|
||||
var goal = Add(rail, "rail-goal");
|
||||
AddText(goal, company.Flagship ? "MILESTONE REACHED" : "FLAGSHIP MILESTONE", "eyebrow");
|
||||
AddText(goal, company.Flagship ? "Atlantic crossing complete" : "Bermuda → Lisbon", "goal-name");
|
||||
AddText(goal, company.Flagship ? "Continue running your fleet." : "Ocean Class · 320 berths · 160 show seats", "goal-detail");
|
||||
|
||||
pageScroll = new ScrollView(ScrollViewMode.Vertical);
|
||||
pageScroll.AddToClassList("page-scroll");
|
||||
body.Add(pageScroll);
|
||||
var canvas = Add(pageScroll, "page");
|
||||
var head = Add(canvas, "page-head");
|
||||
var heading = Add(head, "heading");
|
||||
AddDisplay(heading, Pages[page], "page-title");
|
||||
AddText(head, page == 0 && Ship != null ? Market.Ports[Ship.Port].Region.ToUpperInvariant()
|
||||
: $"{company.Voyages:00} VOYAGES / GLOBAL NETWORK", "page-meta eyebrow");
|
||||
AddNotice(canvas);
|
||||
switch (page)
|
||||
private void DrawPause()
|
||||
{
|
||||
var shade = Add(root, "pause-overlay");
|
||||
var menu = Add(shade, "pause-sheet");
|
||||
GameIcon(menu, "anchor");
|
||||
AddDisplay(menu, "Paused", "pause-title");
|
||||
menu.Add(Action("Resume", () => { paused = false; Render(); }, "primary pause-command", "resume-game"));
|
||||
if (underway == null)
|
||||
{
|
||||
case 0: DrawOperations(canvas); break;
|
||||
case 1: DrawDecks(canvas); break;
|
||||
case 2: DrawShipyard(canvas); break;
|
||||
case 3: DrawPorts(canvas); break;
|
||||
case 4: DrawFinance(canvas); break;
|
||||
menu.Add(Action("Restart first voyage guide", () =>
|
||||
{
|
||||
paused = false;
|
||||
RestartGuide();
|
||||
}, "pause-command", "restart-guide"));
|
||||
menu.Add(Action("Title screen", () =>
|
||||
{
|
||||
paused = fleetOpen = shipActionsOpen = false;
|
||||
title = true;
|
||||
Notify(null);
|
||||
Render();
|
||||
}, "pause-command", "return-title"));
|
||||
}
|
||||
if (!Application.isEditor && Application.platform != RuntimePlatform.WebGLPlayer)
|
||||
menu.Add(Action("Quit to desktop", () => Application.Quit(), "pause-command", "quit-game"));
|
||||
}
|
||||
|
||||
private void AttachCamera(VisualElement world)
|
||||
{
|
||||
int pointerId = -1;
|
||||
Vector2 start = Vector2.zero, last = Vector2.zero;
|
||||
bool dragging = false;
|
||||
world.RegisterCallback<PointerDownEvent>(evt =>
|
||||
{
|
||||
if (paused || pointerId >= 0 || (evt.button != 0 && evt.button != 1))
|
||||
return;
|
||||
pointerId = evt.pointerId;
|
||||
start = last = evt.localPosition;
|
||||
dragging = false;
|
||||
world.CapturePointer(pointerId);
|
||||
evt.StopPropagation();
|
||||
});
|
||||
world.RegisterCallback<PointerMoveEvent>(evt =>
|
||||
{
|
||||
if (evt.pointerId != pointerId)
|
||||
return;
|
||||
Vector2 position = evt.localPosition;
|
||||
if (dragging || (position - start).sqrMagnitude > 16)
|
||||
{
|
||||
dragging = true;
|
||||
harbor.Orbit(position - last);
|
||||
}
|
||||
last = position;
|
||||
});
|
||||
world.RegisterCallback<PointerUpEvent>(evt =>
|
||||
{
|
||||
if (evt.pointerId != pointerId)
|
||||
return;
|
||||
pointerId = -1;
|
||||
world.ReleasePointer(evt.pointerId);
|
||||
if (!dragging && evt.button == 0 && underway == null && Ship != null &&
|
||||
harbor.IsShipAt(new Vector2(evt.localPosition.x / world.resolvedStyle.width,
|
||||
1 - evt.localPosition.y / world.resolvedStyle.height)))
|
||||
{
|
||||
shipActionsOpen = !shipActionsOpen;
|
||||
Render();
|
||||
}
|
||||
});
|
||||
world.RegisterCallback<PointerCaptureOutEvent>(_ => pointerId = -1);
|
||||
world.RegisterCallback<WheelEvent>(evt =>
|
||||
{
|
||||
if (paused)
|
||||
return;
|
||||
harbor.Zoom(evt.delta.y);
|
||||
evt.StopPropagation();
|
||||
});
|
||||
}
|
||||
|
||||
private void AddHarbor(VisualElement holder)
|
||||
@@ -336,8 +512,6 @@ namespace Soundings
|
||||
return;
|
||||
float panelWidth = root.resolvedStyle.width;
|
||||
float scale = panelWidth > 0 ? Screen.width / panelWidth : 1;
|
||||
if (Application.platform != RuntimePlatform.WebGLPlayer)
|
||||
scale *= Mathf.Clamp(1250 / (evt.newRect.width * scale), 1, 2);
|
||||
int width = Mathf.Clamp(Mathf.RoundToInt(evt.newRect.width * scale), 32, SystemInfo.maxTextureSize);
|
||||
int height = Mathf.Clamp(Mathf.RoundToInt(evt.newRect.height * scale), 32, SystemInfo.maxTextureSize);
|
||||
harbor.Resize(width, height);
|
||||
@@ -349,46 +523,15 @@ namespace Soundings
|
||||
|
||||
private void AddNotice(VisualElement parent)
|
||||
{
|
||||
if (string.IsNullOrEmpty(notice))
|
||||
return;
|
||||
Label banner = AddText(parent, notice, warning ? "notice warning" : "notice");
|
||||
banner.SetEnabled(true);
|
||||
}
|
||||
|
||||
private static void AddMark(VisualElement parent)
|
||||
{
|
||||
var mark = Add(parent, "brand-mark");
|
||||
mark.generateVisualContent += context =>
|
||||
{
|
||||
Painter2D painter = context.painter2D;
|
||||
painter.lineWidth = 1.35f;
|
||||
painter.strokeColor = new Color(.91f, .74f, .48f);
|
||||
painter.BeginPath();
|
||||
painter.MoveTo(new Vector2(16, 2));
|
||||
painter.LineTo(new Vector2(29, 10));
|
||||
painter.LineTo(new Vector2(29, 24));
|
||||
painter.LineTo(new Vector2(16, 32));
|
||||
painter.LineTo(new Vector2(3, 24));
|
||||
painter.LineTo(new Vector2(3, 10));
|
||||
painter.ClosePath();
|
||||
painter.Stroke();
|
||||
painter.BeginPath();
|
||||
painter.MoveTo(new Vector2(8, 20));
|
||||
painter.LineTo(new Vector2(13, 15));
|
||||
painter.LineTo(new Vector2(16, 19));
|
||||
painter.LineTo(new Vector2(21, 13));
|
||||
painter.LineTo(new Vector2(24, 17));
|
||||
painter.MoveTo(new Vector2(8, 24));
|
||||
painter.LineTo(new Vector2(24, 24));
|
||||
painter.Stroke();
|
||||
};
|
||||
if (!string.IsNullOrEmpty(notice))
|
||||
AddText(parent, notice, warning ? "notice warning" : "notice");
|
||||
}
|
||||
|
||||
private static void HeadMetric(VisualElement parent, string label, string value, string modifier = "")
|
||||
{
|
||||
var metric = Add(parent, "head-metric");
|
||||
AddText(metric, label, "eyebrow");
|
||||
AddText(metric, value, "head-value " + modifier);
|
||||
var metric = Add(parent, "hud-metric");
|
||||
AddText(metric, label, "eyebrow hud-label");
|
||||
AddText(metric, value, "hud-value " + modifier);
|
||||
}
|
||||
|
||||
private static void Classes(VisualElement element, string classes)
|
||||
@@ -406,17 +549,11 @@ namespace Soundings
|
||||
return element;
|
||||
}
|
||||
|
||||
private static Label Text(string value, string classes)
|
||||
private static Label AddText(VisualElement parent, string value, string classes)
|
||||
{
|
||||
var label = new Label(value) { pickingMode = PickingMode.Ignore };
|
||||
label.style.unityFontDefinition = interfaceFont;
|
||||
Classes(label, classes);
|
||||
return label;
|
||||
}
|
||||
|
||||
private static Label AddText(VisualElement parent, string value, string classes)
|
||||
{
|
||||
var label = Text(value, classes);
|
||||
parent.Add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user