forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSatelliteFragment.cs
More file actions
74 lines (65 loc) · 2.42 KB
/
Copy pathSatelliteFragment.cs
File metadata and controls
74 lines (65 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Linq;
using UnityEngine;
namespace RemoteTech.UI
{
public class SatelliteFragment : IFragment, IDisposable
{
public ISatellite Satellite
{
get { return mSatellite; }
set { if (mSatellite != value) { mSatellite = value; Antenna = null; } }
}
public IAntenna Antenna { get; private set; }
private ISatellite mSatellite;
private Vector2 mScrollPosition = Vector2.zero;
public SatelliteFragment(ISatellite sat)
{
Satellite = sat;
RTCore.Instance.Satellites.OnUnregister += Refresh;
}
public void Dispose()
{
if (RTCore.Instance != null)
{
RTCore.Instance.Satellites.OnUnregister -= Refresh;
}
}
public void Draw()
{
if (Satellite == null) return;
GUILayout.BeginHorizontal();
{
GUILayout.TextField(Satellite.Name.Truncate(25), GUILayout.ExpandWidth(true));
RTUtil.Button("Name", () =>
{
var vessel = RTUtil.GetVesselById(Satellite.Guid);
if (vessel) vessel.RenameVessel();
}, GUILayout.ExpandWidth(false), GUILayout.Height(24));
}
GUILayout.EndHorizontal();
mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, GUILayout.ExpandHeight(true));
{
Color pushColor = GUI.contentColor;
TextAnchor pushAlign = GUI.skin.button.alignment;
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
foreach (var a in Satellite.Antennas.Where(a => a.CanTarget))
{
GUI.contentColor = (a.Powered) ? XKCDColors.ElectricLime : XKCDColors.Scarlet;
String text = a.Name.Truncate(25) + Environment.NewLine + "Target: " + RTUtil.TargetName(a.Target).Truncate(18);
RTUtil.StateButton(text, Antenna, a, s =>
{
Antenna = (s > 0) ? a : null;
});
}
GUI.skin.button.alignment = pushAlign;
GUI.contentColor = pushColor;
}
GUILayout.EndScrollView();
}
private void Refresh(ISatellite sat)
{
if (sat == Satellite) Satellite = null;
}
}
}