Enable placeable sun deck attractions and finish project rebrand
This commit is contained in:
96
Assets/BigShipTycoon/Runtime/PortCinematics.cs
Normal file
96
Assets/BigShipTycoon/Runtime/PortCinematics.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BigShipTycoon
|
||||
{
|
||||
public sealed partial class TycoonApp
|
||||
{
|
||||
private int cinematicPort;
|
||||
private bool cinematicArrival;
|
||||
private float cinematicTime;
|
||||
private VisualElement cinematicFade;
|
||||
private Label cinematicCaption;
|
||||
|
||||
private bool StartPortCinematic(int port, bool arrival)
|
||||
{
|
||||
if (!harbor.BeginPortCinematic(port, arrival))
|
||||
return false;
|
||||
|
||||
cinematicPort = port;
|
||||
cinematicArrival = arrival;
|
||||
cinematicTime = 0;
|
||||
Render();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdatePortCinematic(float delta)
|
||||
{
|
||||
cinematicTime += delta;
|
||||
if (cinematicTime >= Harbor.PortCinematicDuration)
|
||||
{
|
||||
EndPortCinematic();
|
||||
return;
|
||||
}
|
||||
|
||||
float progress = cinematicTime / Harbor.PortCinematicDuration;
|
||||
float knots = cinematicArrival ? Mathf.Lerp(9, 0, progress) : Mathf.Lerp(1, 10, progress);
|
||||
passageAudio.Mix(delta, true, knots, underway.Weather, false, false);
|
||||
PresentPortCinematicFrame(delta);
|
||||
}
|
||||
|
||||
private void PresentPortCinematicFrame(float delta)
|
||||
{
|
||||
harbor.PresentPortCinematic(cinematicTime);
|
||||
harbor.UpdatePassengers(livePassage, delta);
|
||||
UpdatePortCinematicTitles();
|
||||
}
|
||||
|
||||
private void EndPortCinematic()
|
||||
{
|
||||
if (!harbor.PortCinematicActive)
|
||||
return;
|
||||
|
||||
harbor.EndPortCinematic();
|
||||
cinematicFade = null;
|
||||
cinematicCaption = null;
|
||||
if (cinematicArrival)
|
||||
CompleteDocking();
|
||||
else
|
||||
{
|
||||
PresentVessel(0);
|
||||
Render();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPortCinematic()
|
||||
{
|
||||
var screen = Add(root, "port-cinematic");
|
||||
screen.name = "port-cinematic";
|
||||
AddHarbor(Add(screen, "harbor-viewport"));
|
||||
var top = Add(screen, "port-cinematic-bar port-cinematic-top");
|
||||
var bottom = Add(screen, "port-cinematic-bar port-cinematic-bottom");
|
||||
top.pickingMode = bottom.pickingMode = PickingMode.Ignore;
|
||||
var titleCard = Add(bottom, "port-cinematic-title-card");
|
||||
PortSpec port = Market.Ports[cinematicPort];
|
||||
string maneuver = cinematicArrival ? "ARRIVAL" : "DEPARTURE";
|
||||
AddText(titleCard, $"{maneuver} · {Ship.Name}", "port-cinematic-kicker");
|
||||
AddDisplay(titleCard, port.Name, "port-cinematic-title").name = "port-cinematic-name";
|
||||
cinematicCaption = AddText(bottom, "", "port-cinematic-caption");
|
||||
cinematicFade = Add(screen, "port-cinematic-fade");
|
||||
cinematicFade.pickingMode = PickingMode.Ignore;
|
||||
Button skip = Action("Skip · Esc", EndPortCinematic, "port-cinematic-skip", "port-cinematic-skip");
|
||||
skip.tooltip = "Skip this port cinematic";
|
||||
bottom.Add(skip);
|
||||
UpdatePortCinematicTitles();
|
||||
}
|
||||
|
||||
private void UpdatePortCinematicTitles()
|
||||
{
|
||||
float timeLeft = Harbor.PortCinematicDuration - cinematicTime;
|
||||
cinematicFade.style.opacity = 1 - Mathf.SmoothStep(0, 1, Mathf.Min(cinematicTime / .28f, timeLeft / .32f));
|
||||
string caption = passageAudio.Caption ?? "";
|
||||
if (cinematicCaption.text != caption)
|
||||
cinematicCaption.text = caption;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user