forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetInfoFragment.cs
More file actions
143 lines (129 loc) · 5.26 KB
/
Copy pathTargetInfoFragment.cs
File metadata and controls
143 lines (129 loc) · 5.26 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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace RemoteTech.UI
{
public class TargetInfoFragment : IFragment, IDisposable
{
public class Target
{
public AntennaFragment.Entry TargetEntry { get; set; }
public IAntenna Antenna { get; set; }
public KeyValuePair<string, Color> TargetInfos
{
get
{
if (TargetEntry == null || Antenna == null)
return new KeyValuePair<string, Color>("",Color.white);
return NetworkFeedback.tryConnection(Antenna, TargetEntry.Guid);
}
}
}
/// <summary>Current target infos</summary>
private Target target;
/// <summary>Style set for each row on the target pop-up</summary>
private GUIStyle guiTableRow;
/// <summary>Style set for the headline of the target pop-up</summary>
private GUIStyle guiHeadline;
/// <summary>
/// Initialize the targetinfoFragment without a target
/// </summary>
public TargetInfoFragment()
{
InitalGuiStyles();
}
/// <summary>
/// Initialize the targetinfoFragment with a targetEntry and an antenna
/// </summary>
/// <param name="targetEntry">Target from the antenna fragment</param>
/// <param name="antenna">current antenna</param>
public TargetInfoFragment(AntennaFragment.Entry targetEntry, IAntenna antenna)
: this()
{
SetTarget(targetEntry, antenna);
}
/// <summary>
/// Initialize the style sets for this fragment
/// </summary>
private void InitalGuiStyles()
{
// initial styles
guiTableRow = new GUIStyle(HighLogic.Skin.label)
{
fontSize = 12,
normal = {textColor = Color.white}
};
guiHeadline = new GUIStyle(HighLogic.Skin.label)
{
fontSize = 13,
fontStyle = FontStyle.Bold
};
}
/// <summary>
/// Set a new target to the targetfragment with a targetEntry and an antenna
/// </summary>
/// <param name="targetEntry">Target from the antenna fragment</param>
/// <param name="antenna">current antenna</param>
public void SetTarget(AntennaFragment.Entry targetEntry, IAntenna antenna)
{
target = new Target {TargetEntry = targetEntry, Antenna = antenna};
}
public void Dispose()
{
target = null;
}
/// <summary>
/// Draw the information for the target, set by the setTarget()
/// </summary>
public void Draw()
{
if(target != null)
{
KeyValuePair<string, Color> infos = target.TargetInfos;
GUILayout.Label(target.TargetEntry.Text, guiHeadline);
// Split the given informations from the target.targetInfos. Each ; is one row
var diagnostic = infos.Key.Split(';');
// Loop the rows
foreach (var diagnosticTextLines in diagnostic)
{
try
{
GUILayout.BeginHorizontal();
// If the text contains a 'label' so we also split this text into to
// seperated text parts
if (diagnosticTextLines.Trim().Contains(':'))
{
var tableString = diagnosticTextLines.Trim().Split(':');
// draw the label
GUILayout.Label(tableString[0] + ':', guiTableRow, GUILayout.Width(110));
// if the label is 'status' so change the textcolor to the color
// given by the NetworkFeedback class.
if (tableString[0].ToLower() == "status")
{
guiTableRow.normal.textColor = infos.Value;
}
// print the value for this row
GUILayout.Label(tableString[1], guiTableRow);
// restore the text color
guiTableRow.normal.textColor = Color.white;
}
else
{
// if we do not have a table style information so print the complete text
GUILayout.Label(diagnosticTextLines.Trim(), guiTableRow);
}
GUILayout.EndHorizontal();
}
catch (Exception ex)
{
RTLog.Notify("Exception {0}",ex);
// I got one exception, thrown from Unity and i don't know how to deal with it
// Exception System.ArgumentException: Getting control 4's
// position in a group with only 4 controls when doing Repaint
}
}
}
}
}
}