Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Telecom/main_window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,28 @@ protected override void RenderWindowContents(int window_id) {
open_contracts_.Add(contract, false);
}
}
var ok_style = UnityEngine.GUI.skin.label;
var disconnected_style = principia.ksp_plugin_adapter.Style.Warning(ok_style);

foreach (var contract_connections in telecom_.network.connections_by_contract) {
var contract = contract_connections.Key;
var connections = contract_connections.Value;
bool all_available = connections.All(connection => {
if (connection is PointToMultipointConnection point_to_multipoint) {
return point_to_multipoint.channel_services.All(service => service.basic.available);
} else if (connection is DuplexConnection duplex) {
return duplex.basic_service.available;
} else { return false; }
});
Comment on lines +74 to +80

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm not a huge fan of this single-use in-line method definition, I suppose it works here. And is easily lift-able to another scope if this is needed in more places.

var contract_style = all_available ? ok_style : disconnected_style;
using (new UnityEngine.GUILayout.HorizontalScope()) {
if (UnityEngine.GUILayout.Button(
open_contracts_[contract] ? "−" : "+", GUILayoutWidth(1))) {
open_contracts_[contract] = !open_contracts_[contract];
ScheduleShrink();
return;
}
UnityEngine.GUILayout.Label(contract.Title);
UnityEngine.GUILayout.Label(contract.Title, contract_style);
}
if (open_contracts_[contract]) {
foreach (var connection in connections) {
Expand All @@ -86,9 +97,11 @@ protected override void RenderWindowContents(int window_id) {
var rx = telecom_.network.GetStation(point_to_multipoint.rx_names[0]);
bool available = services.basic.available;
string status = available ? "OK" : "Disconnected";
var style = available ? ok_style : disconnected_style;
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(
$"From {tx.displaynodeName} to {rx.displaynodeName}: {status}",
style,
GUILayoutWidth(15));
connection_inspectors_[connection].RenderButton();
}
Expand All @@ -104,20 +117,23 @@ protected override void RenderWindowContents(int window_id) {
var services = point_to_multipoint.channel_services[i];
bool available = services.basic.available;
string status = available ? "OK" : "Disconnected";
var style = available ? ok_style : disconnected_style;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of line R120, delete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed line 120 to keep line 122. Trying to keep the ordering consistent across dupes

var rx = telecom_.network.GetStation(point_to_multipoint.rx_names[i]);
if (point_to_multipoint.rx_names.Length > 1) {
UnityEngine.GUILayout.Label(
$@"— {rx.displaynodeName}: {status}");
$@"— {rx.displaynodeName}: {status}", style);
}
}
} else if (connection is DuplexConnection duplex) {
var trx0 = telecom_.network.GetStation(duplex.trx_names[0]);
var trx1 = telecom_.network.GetStation(duplex.trx_names[1]);
bool available = duplex.basic_service.available;
string status = available ? "OK" : "Disconnected";
var style = available ? ok_style : disconnected_style;
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(
$@"Duplex between {trx0.displaynodeName} and {trx1.displaynodeName}: {status}",
$@"Duplex between {trx0.displaynodeName} and {trx1.displaynodeName}: {status}",
style,
GUILayoutWidth(15));
connection_inspectors_[connection].RenderButton();
}
Expand Down