using System; using UnityEngine; using UnityEngine.UIElements; namespace GrassCutter { /// The twelve stations with how far each is, and a ticket to the ones you've found. 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 there = i == here; var go = UIK.Btn(there ? Loc.T("HERE") : UIK.Money(GameDefs.TravelPrice), () => { if (there || !UIK.CanPay(GameDefs.TravelPrice)) { Sfx.Play("error", 0.7f); return; } ts.TravelRpc(id); Sfx.Play("cash_register", 0.9f); close(); }, there ? "btn btn-grey btn-small" : "btn btn-small", row); if (!there) UIK.Costs(go, GameDefs.TravelPrice); } if (hidden > 0) UIK.Text(Loc.F("{0} more out there. Walk up to one and it opens.", hidden), "tune-effect", list.contentContainer, false); } } }