Skip to content

Commit 0a338ea

Browse files
Allow pre-targeting of antenna in VAB and SPH (based on PR RemoteTechnologiesGroup#724) (Issue RemoteTechnologiesGroup#811, RemoteTechnologiesGroup#725, RemoteTechnologiesGroup#257)
1 parent 9f7058f commit 0a338ea

5 files changed

Lines changed: 388 additions & 11 deletions

File tree

src/RemoteTech/Modules/ModuleRTAntenna.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using RemoteTech.UI;
88
using UnityEngine;
99
using KSP.Localization;
10+
using KSP.UI.Screens;
1011

1112
namespace RemoteTech.Modules
1213
{
@@ -283,8 +284,11 @@ public virtual void SetState(bool state)
283284
[KSPEvent(name = "EventToggle", guiActive = false)]
284285
public void EventToggle() { if (Animating) return; if (IsRTActive) { EventClose(); } else { EventOpen(); } }
285286

286-
[KSPEvent(name = "EventTarget", guiActive = false, guiName = "#RT_ModuleUI_Target", category = "skip_delay")]//Target
287-
public void EventTarget() { (new AntennaWindow(this)).Show(); }
287+
[KSPEvent(name = "EventTarget", guiActive = false, guiActiveEditor = false, guiName = "#RT_ModuleUI_Target", category = "skip_delay")]//Target
288+
public void EventTarget() {
289+
if (HighLogic.LoadedScene == GameScenes.EDITOR) { (new AntennaWindowStandalone(this)).Show(); }
290+
else { (new AntennaWindow(this)).Show(); }
291+
}
288292

289293
[KSPEvent(name = "EventEditorOpen", guiActive = false, guiName = "#RT_ModuleUI_DeployAntenna")]//Deploy Antenna
290294
public void EventEditorOpen() { SetState(true); }
@@ -472,6 +476,7 @@ public override void OnStart(StartState state)
472476
Events["EventClose"].guiName = ActionMode0Name;
473477
Events["EventToggle"].guiName = ActionToggleName;
474478
Events["EventTarget"].guiActive = (Mode1DishRange > 0);
479+
Events["EventTarget"].guiActiveEditor = Events["EventTarget"].guiActive;
475480
Events["EventTarget"].active = Events["EventTarget"].guiActive;
476481

477482
// deactivate action close and toggle if this antenna is non retractable

src/RemoteTech/RTEditor.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using RemoteTech.Modules;
2+
using RemoteTech.UI;
3+
using System;
4+
using UnityEngine;
5+
using KSP.UI.Screens;
6+
7+
namespace RemoteTech
8+
{
9+
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
10+
public class RTEditor : MonoBehaviour
11+
{
12+
/// <summary>
13+
/// Start method for RTEditor
14+
/// </summary>
15+
public void Start()
16+
{
17+
GameEvents.onEditorNewShipDialogDismiss.Add(OnNewShip);
18+
GameEvents.onEditorPartPicked.Add(OnPartPicked);
19+
GameEvents.onEditorLoad.Add(OnEditorLoad);
20+
GameEvents.onEditorScreenChange.Add(OnScreenChange);
21+
GameEvents.onEditorRestart.Add(OnEditorRestart);
22+
}
23+
24+
/// <summary>
25+
/// Unity onGUI Method to draw
26+
/// </summary>
27+
public void OnGUI()
28+
{
29+
GUI.depth = 0; // comment: necessary to make AbstractWindow's close button clickable
30+
31+
Action windows = delegate { };
32+
var itr = AbstractWindow.Windows.GetEnumerator();
33+
while (itr.MoveNext())
34+
{
35+
var windowPair = itr.Current;
36+
windows += windowPair.Value.Draw;
37+
}
38+
windows.Invoke();
39+
}
40+
41+
/// <summary>
42+
/// Unity OnDestroy Method to clean up
43+
/// </summary>
44+
public void OnDestroy()
45+
{
46+
GameEvents.onEditorNewShipDialogDismiss.Remove(OnNewShip);
47+
GameEvents.onEditorPartPicked.Remove(OnPartPicked);
48+
GameEvents.onEditorLoad.Remove(OnEditorLoad);
49+
GameEvents.onEditorScreenChange.Remove(OnScreenChange);
50+
GameEvents.onEditorRestart.Remove(OnEditorRestart);
51+
52+
HideAllWindows();
53+
}
54+
55+
private void HideAllWindows()
56+
{
57+
Action windows = delegate { };
58+
var itr = AbstractWindow.Windows.GetEnumerator();
59+
while (itr.MoveNext())
60+
{
61+
var windowPair = itr.Current;
62+
windows += windowPair.Value.Hide;
63+
}
64+
windows.Invoke();
65+
}
66+
67+
/////////////
68+
// Bunch of editor events below that should hide RemoteTech window
69+
/////////////
70+
private void OnScreenChange(EditorScreen screen)
71+
{
72+
HideAllWindows();
73+
}
74+
75+
private void OnEditorLoad(ShipConstruct ship, CraftBrowserDialog.LoadType loadType)
76+
{
77+
HideAllWindows();
78+
}
79+
80+
private void OnPartPicked(Part part)
81+
{
82+
if (part != null)
83+
{
84+
var module = part.FindModuleImplementing<ModuleRTAntenna>();
85+
if (module != null)
86+
{
87+
HideAllWindows();
88+
}
89+
}
90+
}
91+
92+
private void OnNewShip()
93+
{
94+
HideAllWindows();
95+
}
96+
97+
private void OnEditorRestart()
98+
{
99+
HideAllWindows();
100+
}
101+
}
102+
}

src/RemoteTech/RTUtil.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,42 @@ public static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
185185

186186
public static String TargetName(Guid guid)
187187
{
188+
if (guid == System.Guid.Empty)
189+
{
190+
return Localizer.Format("#RT_ModuleUI_NoTarget");//"No Target"
191+
}
188192
if (RTCore.Instance != null && RTCore.Instance.Network != null && RTCore.Instance.Satellites != null)
189193
{
190-
if (guid == System.Guid.Empty)
191-
{
192-
return Localizer.Format("#RT_ModuleUI_NoTarget");//"No Target"
193-
}
194194
if (RTCore.Instance.Network.Planets.ContainsKey(guid))
195195
{
196196
return RTCore.Instance.Network.Planets[guid].name;
197197
}
198-
if (guid == NetworkManager.ActiveVesselGuid)
199-
{
200-
return Localizer.Format("#RT_ModuleUI_ActiveVessel");//"Active Vessel"
201-
}
202198
ISatellite sat;
203199
if ((sat = RTCore.Instance.Network[guid]) != null)
204200
{
205201
return sat.Name;
206202
}
207203
}
204+
if(HighLogic.LoadedScene == GameScenes.EDITOR)
205+
{
206+
var result = FlightGlobals.Bodies.Find(x => x.Guid() == guid);
207+
if (result != null)
208+
{
209+
return result.name; // Name of Celestial body
210+
}
211+
}
212+
if (guid == NetworkManager.ActiveVesselGuid)
213+
{
214+
return Localizer.Format("#RT_ModuleUI_ActiveVessel");//"Active Vessel"
215+
}
216+
if (RTSettings.Instance != null)
217+
{
218+
var result2 = RTSettings.Instance.GroundStations.Find(x => x.mGuid == guid);
219+
if (result2 != null)
220+
{
221+
return result2.GetName(); // Name of Misson Control
222+
}
223+
}
208224
return Localizer.Format("#RT_ModuleUI_UnknownTarget");//"Unknown Target"
209225
}
210226

src/RemoteTech/RemoteTech.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Compile Include="RangeModel\RangeModelRoot.cs" />
137137
<Compile Include="RangeModel\RangeModelExtensions.cs" />
138138
<Compile Include="RTDebugUnit.cs" />
139+
<Compile Include="RTEditor.cs" />
139140
<Compile Include="RTLog.cs" />
140141
<Compile Include="FlightComputer\DelayedCommand.cs" />
141142
<Compile Include="FlightComputer\FlightComputer.cs" />
@@ -174,6 +175,7 @@
174175
<Compile Include="UI\AbstractWindow.cs" />
175176
<Compile Include="UI\AntennaFragment.cs" />
176177
<Compile Include="UI\AntennaWindow.cs" />
178+
<Compile Include="UI\AntennaWindowStandalone.cs" />
177179
<Compile Include="UI\AttitudeFragment.cs" />
178180
<Compile Include="UI\DebugWindow.cs" />
179181
<Compile Include="UI\PIDControllerFragment.cs" />
@@ -218,4 +220,4 @@
218220
if "$(ConfigurationName)"=="Debug" (call "$(ProjectDir)..\..\buildscripts\UnityDebug_2019\prepare-debug.bat" $(TargetName))
219221
</PostBuildEvent>
220222
</PropertyGroup>
221-
</Project>
223+
</Project>

0 commit comments

Comments
 (0)