130 lines
5.2 KiB
C#
130 lines
5.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Soundings
|
|
{
|
|
public sealed partial class SoundingsApp
|
|
{
|
|
private VisualElement stationPrompt;
|
|
private Label stationTitle, stationCommand, stationFeedback, crewCallReadout;
|
|
private float stationFeedbackUntil;
|
|
private string stationFeedbackText;
|
|
|
|
private void DrawStationInteractions(VisualElement overlay)
|
|
{
|
|
stationPrompt = null;
|
|
if (!passageBridge && !passageExploring)
|
|
return;
|
|
|
|
var reticle = Add(overlay, "station-reticle");
|
|
reticle.pickingMode = PickingMode.Ignore;
|
|
stationPrompt = Add(overlay, "station-prompt");
|
|
stationPrompt.pickingMode = PickingMode.Ignore;
|
|
stationTitle = AddText(stationPrompt, "", "station-title");
|
|
stationCommand = AddText(stationPrompt, "", "station-command");
|
|
stationFeedback = AddText(overlay, "", "station-feedback");
|
|
stationFeedback.pickingMode = PickingMode.Ignore;
|
|
UpdateStationInteractions();
|
|
}
|
|
|
|
private void UpdateStationInteractions()
|
|
{
|
|
if (stationPrompt == null || livePassage == null)
|
|
return;
|
|
|
|
bool visible = harbor.TryGetFacingStation(out StationKind station);
|
|
stationPrompt.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
|
|
if (visible)
|
|
{
|
|
bool requested = livePassage.CrewCall == station;
|
|
string action = station == StationKind.Helm && passageHelm.Manual
|
|
? "Return to autopilot" : livePassage.StationAction(station);
|
|
string blocker = station == StationKind.Helm ? null : livePassage.StationBlock(station);
|
|
SetPassageText(stationTitle, requested ? $"{OnboardSession.StationName(station)} · Crew call" : OnboardSession.StationName(station));
|
|
SetPassageText(stationCommand, blocker ?? $"[F] {action}");
|
|
stationPrompt.EnableInClassList("station-requested", requested);
|
|
}
|
|
|
|
bool showResult = !string.IsNullOrEmpty(stationFeedbackText) && Time.unscaledTime < stationFeedbackUntil;
|
|
stationFeedback.style.display = showResult ? DisplayStyle.Flex : DisplayStyle.None;
|
|
if (showResult)
|
|
SetPassageText(stationFeedback, stationFeedbackText);
|
|
}
|
|
|
|
private bool UseFacingStation()
|
|
{
|
|
if (livePassage == null || !harbor.TryGetFacingStation(out StationKind station))
|
|
return false;
|
|
|
|
if (station == StationKind.Helm)
|
|
{
|
|
ToggleHelm();
|
|
ShowStationResult(passageHelm.Manual ? "Manual helm engaged" : "Autopilot engaged", true);
|
|
return true;
|
|
}
|
|
|
|
bool worked = livePassage.TryWorkStation(station, out string result);
|
|
if (worked)
|
|
AnnounceStation(station);
|
|
if (worked && station >= StationKind.Engine && station <= StationKind.Waste)
|
|
{
|
|
int area = (int)station - (int)StationKind.Engine;
|
|
if (area != passageServiceArea)
|
|
{
|
|
passageServiceArea = area;
|
|
Render();
|
|
}
|
|
}
|
|
ShowStationResult(result, worked);
|
|
RefreshPassageBusiness();
|
|
return worked;
|
|
}
|
|
|
|
private void ShowStationResult(string result, bool worked)
|
|
{
|
|
stationFeedbackText = result;
|
|
stationFeedbackUntil = Time.unscaledTime + 3.4f;
|
|
if (worked)
|
|
passageAudio.Confirm();
|
|
UpdateStationInteractions();
|
|
}
|
|
|
|
private void UpdateCrewCall()
|
|
{
|
|
if (crewCallReadout == null)
|
|
return;
|
|
|
|
string text;
|
|
if (livePassage.CrewCall is StationKind station)
|
|
text = $"Crew call · {OnboardSession.StationName(station)} · {StationDeck(station)} · {livePassage.CrewRoundsLeft} rounds";
|
|
else if (livePassage.CrewRequestsCompleted > 0)
|
|
text = $"Crew calls answered · {livePassage.CrewRequestsCompleted}";
|
|
else
|
|
text = "";
|
|
|
|
SetPassageText(crewCallReadout, text);
|
|
crewCallReadout.style.display = text.Length == 0 ? DisplayStyle.None : DisplayStyle.Flex;
|
|
crewCallReadout.EnableInClassList("crew-call-urgent", livePassage.CrewRoundsLeft is > 0 and <= 2);
|
|
}
|
|
|
|
private string StationDeck(StationKind station)
|
|
{
|
|
if (station <= StationKind.Waste)
|
|
return "Service deck";
|
|
|
|
Facility room = station switch
|
|
{
|
|
StationKind.Cabins => Facility.Cabin,
|
|
StationKind.Dining => Facility.Dining,
|
|
StationKind.Bar => Facility.Bar,
|
|
StationKind.Stage => Facility.Entertainment,
|
|
_ => Facility.Amenity
|
|
};
|
|
for (int i = 0; i < Ship.Decks.Count; i++)
|
|
if (System.Array.IndexOf(Ship.Decks[i].Cells, room) >= 0)
|
|
return $"Deck {i + 1}";
|
|
return "Guest decks";
|
|
}
|
|
}
|
|
}
|