-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlightReadoutManager.cs
124 lines (107 loc) · 3.55 KB
/
FlightReadoutManager.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System.Collections.Generic;
using UnityEngine;
namespace FlightComputer
{
public class FlightReadoutManager : SettingListManager
{
public static bool Debug = true;
public FlightComputer Computer;
public List<FlightReadout> Readouts = new List<FlightReadout>();
public FlightReadoutManager(FlightComputer computer, string filename = null)
{
this.Logger = new LogManager("ReadoutManager", filename);
this.SettingsFile = filename;
this.Computer = computer;
this.LoadFromFile();
}
~FlightReadoutManager()
{
this.SaveToFile();
this.Readouts.Clear();
}
public override List<string> GetLinesToWrite()
{
List<string> lines = new List<string>();
foreach (FlightReadout readout in this.Readouts)
{
lines.Add(readout.Settings.SettingsFile);
}
return lines;
}
public override void AddItem(string readoutFileName = null)
{
this.Logger.Log("Adding readout to list.");
if (readoutFileName == null)
{
readoutFileName = StaticRandom.Next() + ".cfg";
}
bool listContainsReadout = false;
foreach (FlightReadout readout in this.Readouts)
{
if (readoutFileName == readout.Settings.SettingsFile)
{
listContainsReadout = true;
}
}
if (!listContainsReadout)
{
FlightReadout newReadout = new FlightReadout(this.Computer, readoutFileName);
this.Readouts.Add(newReadout);
}
}
public void RemoveItem(string readoutFileName)
{
foreach (FlightReadout readout in this.Readouts)
{
if (readoutFileName == readout.Settings.SettingsFile)
{
this.Readouts.Remove(readout);
return;
}
}
}
public void RemoveItem(FlightReadout readout)
{
this.Logger.Log("Removing readout from list.");
readout.DestroyReadout();
this.Readouts.Remove(readout);
}
public void DrawReadoutButtons()
{
foreach (FlightReadout readout in this.Readouts)
{
if (GUILayout.Button(readout.GetReadoutName()))
{
readout.ToggleReadout();
}
}
}
public void DrawReadoutManagementGUI()
{
GUILayout.BeginVertical();
{
foreach (FlightReadout readout in this.Readouts)
{
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
{
readout.SetReadoutName(GUILayout.TextField(readout.GetReadoutName(), 50));
if (GUILayout.Button("Remove"))
{
this.RemoveItem(readout);
}
}
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
{
if (GUILayout.Button("Add New Readout"))
{
this.AddItem();
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
}
}