Repository navigation
Expand file tree
/
Copy pathApplicationShell.cs
More file actions
287 lines (252 loc) · 10.4 KB
/
Copy pathApplicationShell.cs
File metadata and controls
287 lines (252 loc) · 10.4 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System.Numerics;
using ImGuiNET;
using ProxyState.Simulation;
namespace ProxyState;
/// <summary>
/// Applications that can be launched from the desktop-style program manager.
/// Keeping the identifiers separate from their labels makes the double-click
/// routing explicit and leaves room for more applications later.
/// </summary>
public enum ApplicationId
{
Dossiers,
NorthstarOpinion,
TownlineResearch,
DebugWindow
}
public readonly record struct ApplicationIcon(ApplicationId Id, string Label, string Glyph);
public static class ApplicationCatalog
{
public static IReadOnlyList<ApplicationIcon> GetAvailable(bool debugMode) =>
debugMode
? new[]
{
new ApplicationIcon(ApplicationId.Dossiers, "Dossiers", "D"),
new ApplicationIcon(ApplicationId.NorthstarOpinion, "Northstar Opinion", "N"),
new ApplicationIcon(ApplicationId.TownlineResearch, "Townline Research", "T"),
new ApplicationIcon(ApplicationId.DebugWindow, "Debug Window", "DBG")
}
: new[]
{
new ApplicationIcon(ApplicationId.Dossiers, "Dossiers", "D"),
new ApplicationIcon(ApplicationId.NorthstarOpinion, "Northstar Opinion", "N"),
new ApplicationIcon(ApplicationId.TownlineResearch, "Townline Research", "T")
};
}
/// <summary>
/// Owns the launcher state, including which application windows are open.
/// The launcher only changes presentation state; it does not read simulation
/// entities or any other Ground Truth data.
/// </summary>
public sealed class ApplicationShell
{
public const string DossiersWindowTitle = "Surveillance Terminal";
public const string DebugWindowTitle = "Debug Window";
public const string NorthstarWindowTitle = "Northstar Opinion";
public const string TownlineWindowTitle = "Townline Research";
public bool AgentsWindowOpen { get; private set; }
public bool ReportsWindowOpen { get; private set; }
private ApplicationId? _selectedApplication;
public bool DossiersOpen { get; private set; }
public bool DebugWindowOpen { get; private set; }
public bool NorthstarWindowOpen { get; private set; }
public bool TownlineWindowOpen { get; private set; }
public void OpenApplication(ApplicationId application) => Open(application);
public void CloseApplication(ApplicationId application)
{
switch (application)
{
case ApplicationId.NorthstarOpinion: NorthstarWindowOpen = false; break;
case ApplicationId.TownlineResearch: TownlineWindowOpen = false; break;
case ApplicationId.Dossiers: DossiersOpen = false; break;
case ApplicationId.DebugWindow: DebugWindowOpen = false; break;
}
}
public void DrawLauncher(bool debugMode)
{
if (!debugMode)
{
// A debug window cannot remain open if the process was not started
// in debug mode. This also keeps the launcher contract testable.
DebugWindowOpen = false;
if (_selectedApplication == ApplicationId.DebugWindow)
{
_selectedApplication = null;
}
}
ImGui.SetNextWindowPos(new Vector2(24f, 24f), ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSize(new Vector2(620f, 270f), ImGuiCond.FirstUseEver);
if (ImGui.Begin("Applications"))
{
ImGui.Text("Proxy State Program Manager");
ImGui.TextDisabled("Double-click an icon to launch");
ImGui.Separator();
// Standalone management windows remain outside the Applications catalog.
if (ImGui.Button("Agents")) AgentsWindowOpen = true;
ImGui.SameLine();
if (ImGui.Button("Reports")) ReportsWindowOpen = true;
ImGui.Separator();
foreach (var application in ApplicationCatalog.GetAvailable(debugMode))
{
DrawApplicationIcon(application);
ImGui.SameLine();
}
ImGui.NewLine();
ImGui.Separator();
ImGui.Text(_selectedApplication is null
? "No application selected"
: $"Selected: {GetLabel(_selectedApplication.Value)}");
}
ImGui.End();
}
public void DrawDossiersWindow(
PlayerIntelligenceDB intelligence,
IReadOnlyList<TraitDefinition> traits,
DossierWindow dossierWindow,
Action<InvestigationCommand> commandSink)
{
ArgumentNullException.ThrowIfNull(intelligence);
ArgumentNullException.ThrowIfNull(traits);
ArgumentNullException.ThrowIfNull(dossierWindow);
if (!DossiersOpen)
{
return;
}
var isOpen = DossiersOpen;
dossierWindow.Draw(intelligence, traits, commandSink, ref isOpen);
DossiersOpen = isOpen;
}
public void DrawDebugWindow(DebugInspectionView inspection, DebugWindow debugWindow)
{
ArgumentNullException.ThrowIfNull(inspection);
ArgumentNullException.ThrowIfNull(debugWindow);
if (!DebugWindowOpen)
{
return;
}
var isOpen = DebugWindowOpen;
debugWindow.Draw(inspection, ref isOpen);
DebugWindowOpen = isOpen;
}
public void DrawResearchWindows(IReadOnlyList<ResearchProviderProjection> providers)
{
ArgumentNullException.ThrowIfNull(providers);
var northstar = providers.FirstOrDefault(provider => provider.ProviderId == "northstar-opinion");
var townline = providers.FirstOrDefault(provider => provider.ProviderId == "townline-research");
if (NorthstarWindowOpen && northstar is not null)
{
var open = NorthstarWindowOpen;
PoliticalResearchWindow.Draw(northstar, NorthstarWindowTitle, ref open);
NorthstarWindowOpen = open;
}
if (TownlineWindowOpen && townline is not null)
{
var open = TownlineWindowOpen;
PoliticalResearchWindow.Draw(townline, TownlineWindowTitle, ref open);
TownlineWindowOpen = open;
}
}
public void DrawOperativeWindows(OperativeManagementProjection management,
PlayerIntelligenceDB intelligence, AgentsWindow agentsWindow, ReportsWindow reportsWindow,
Action<OperativeCommand> commandSink)
{
ArgumentNullException.ThrowIfNull(management);
ArgumentNullException.ThrowIfNull(intelligence);
ArgumentNullException.ThrowIfNull(agentsWindow);
ArgumentNullException.ThrowIfNull(reportsWindow);
if (AgentsWindowOpen)
{
var open = AgentsWindowOpen;
agentsWindow.Draw(management, intelligence.Agents, commandSink, ref open);
AgentsWindowOpen = open;
}
if (ReportsWindowOpen)
{
var open = ReportsWindowOpen;
reportsWindow.Draw(management, ref open);
ReportsWindowOpen = open;
}
}
private void DrawApplicationIcon(ApplicationIcon application)
{
ImGui.BeginGroup();
ImGui.PushID(application.Id.ToString());
var buttonColor = _selectedApplication == application.Id
? new Vector4(0.12f, 0.36f, 0.68f, 1f)
: new Vector4(0.28f, 0.32f, 0.38f, 1f);
ImGui.PushStyleColor(ImGuiCol.Button, buttonColor);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(0.18f, 0.46f, 0.82f, 1f));
ImGui.PushStyleColor(ImGuiCol.ButtonActive, new Vector4(0.08f, 0.25f, 0.52f, 1f));
ImGui.Button(application.Glyph, new Vector2(82f, 74f));
ImGui.PopStyleColor(3);
if (ImGui.IsItemClicked())
{
_selectedApplication = application.Id;
}
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left))
{
Open(application.Id);
}
var textWidth = ImGui.CalcTextSize(application.Label).X;
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + MathF.Max(0f, (82f - textWidth) / 2f));
ImGui.Text(application.Label);
ImGui.PopID();
ImGui.EndGroup();
}
private void Open(ApplicationId application)
{
_selectedApplication = application;
switch (application)
{
case ApplicationId.Dossiers:
DossiersOpen = true;
break;
case ApplicationId.DebugWindow:
DebugWindowOpen = true;
break;
case ApplicationId.NorthstarOpinion:
NorthstarWindowOpen = true;
break;
case ApplicationId.TownlineResearch:
TownlineWindowOpen = true;
break;
}
}
private static string GetLabel(ApplicationId application) => application switch
{
ApplicationId.Dossiers => "Dossiers",
ApplicationId.DebugWindow => "Debug Window",
_ => application.ToString()
};
}
/// <summary>
/// Applies the restrained gray, navy, and blue palette used by the launcher.
/// The terminal remains an ImGui window, but its presentation follows the
/// classic desktop utility aesthetic requested for Proxy State.
/// </summary>
public static class Windows31Theme
{
public static void Apply()
{
var style = ImGui.GetStyle();
style.WindowRounding = 0f;
style.ChildRounding = 0f;
style.FrameRounding = 0f;
style.PopupRounding = 0f;
style.ScrollbarRounding = 0f;
style.GrabRounding = 0f;
style.WindowBorderSize = 2f;
style.FrameBorderSize = 1f;
style.Colors[(int)ImGuiCol.WindowBg] = new Vector4(0.72f, 0.72f, 0.72f, 1f);
style.Colors[(int)ImGuiCol.ChildBg] = new Vector4(0.78f, 0.78f, 0.78f, 1f);
style.Colors[(int)ImGuiCol.Text] = new Vector4(0.05f, 0.05f, 0.05f, 1f);
style.Colors[(int)ImGuiCol.Border] = new Vector4(0.10f, 0.10f, 0.10f, 1f);
style.Colors[(int)ImGuiCol.TitleBg] = new Vector4(0.05f, 0.16f, 0.38f, 1f);
style.Colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.05f, 0.16f, 0.38f, 1f);
style.Colors[(int)ImGuiCol.TitleBgCollapsed] = new Vector4(0.05f, 0.16f, 0.38f, 1f);
style.Colors[(int)ImGuiCol.FrameBg] = new Vector4(0.86f, 0.86f, 0.86f, 1f);
style.Colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.92f, 0.92f, 0.92f, 1f);
style.Colors[(int)ImGuiCol.FrameBgActive] = new Vector4(1f, 1f, 1f, 1f);
style.Colors[(int)ImGuiCol.Separator] = new Vector4(0.25f, 0.25f, 0.25f, 1f);
}
}