Files
grass-cutters/Assets/Scripts/UI/StationScreen.cs
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

52 lines
2.2 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UIElements;
namespace GrassCutter
{
/// <summary>The twelve stations with how far each is, and a ticket to the ones you've found.</summary>
public class StationScreen
{
public VisualElement Card { get; }
public StationScreen(VisualElement layer, Action close)
{
Card = UIK.El("card", layer);
Card.pickingMode = PickingMode.Position;
Card.style.width = 620;
var header = UIK.El("card-header", Card);
UIK.Text(Loc.T("STATIONS"), "t-h1 t-dark", header);
UIK.Btn("X", close, "btn btn-red btn-small", header);
var ts = TeamState.Instance;
var me = PlayerAgent.Local;
if (!ts || !me) return;
var list = new ScrollView(ScrollViewMode.Vertical);
list.AddToClassList("tune-list");
Card.Add(list);
int here = Stations.Nearest(me.transform.position);
var up = Planet.Up(me.transform.position);
int hidden = 0;
for (int i = 0; i < Stations.Count; i++)
{
int id = i;
bool open = ts.StationOpen(i);
if (!open) { hidden++; continue; }
var row = UIK.El("tune-row", list.contentContainer);
var names = UIK.El("tune-names", row);
UIK.Text(Stations.Name(i), "t-small t-dark", names, false);
float metres = Mathf.Acos(Mathf.Clamp(Vector3.Dot(up, Stations.Dir(i)), -1f, 1f)) * Planet.Radius;
UIK.Text(Compass.Distance(metres), "tune-effect", names, false);
bool can = i != here && ts.Money.Value >= GameDefs.TravelPrice;
UIK.Btn(i == here ? Loc.T("HERE") : UIK.Money(GameDefs.TravelPrice), () =>
{
if (!can) { Sfx.Play("error", 0.7f); return; }
ts.TravelRpc(id);
Sfx.Play("cash_register", 0.9f);
close();
}, (can ? "btn btn-green" : "btn btn-grey") + " btn-small", row);
}
if (hidden > 0) UIK.Text(Loc.F("{0} more out there. Walk up to one and it opens.", hidden), "tune-effect", list.contentContainer, false);
}
}
}