-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoGimbalManager.cs
115 lines (108 loc) · 3.78 KB
/
AutoGimbalManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP;
using InfernalRobotics;
using MuMech;
namespace AutoGimbal
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class AutoGimbalManager : MonoBehaviour
{
void Start()
{
FlightGlobals.Vessels.ForEach(vessel =>
{
vessel.FindPartModulesImplementing<AutoGimbal>().ForEach(gimbal =>
{ gimbal.manager = this; });
});
}
public class AGGroup
{
}
//Make a GUI variable to define window position.
protected static Rect windowPosn;
private string rotationTargetString = "0.0";
public float rotationTarget = 0.0f;
public bool shipsToggle;
public bool bodiesToggle;
public bool guiEnabled = false;
//TrackingState stores the current state of the gimbal commanding.
// 0 = not tracking
// 1 = tracking
public int TrackingState = 0;
IButton AutoGimbalButton;
void Awake()
{
guiEnabled = false;
var scene = HighLogic.LoadedScene;
if (ToolbarManager.ToolbarAvailable)
{
AutoGimbalButton = ToolbarManager.Instance.add("Felger", "AutoGimbalButton");
AutoGimbalButton.TexturePath = "AutoGimbal/Textures/icon_button";
AutoGimbalButton.ToolTip = "AutoGimbal Manager";
AutoGimbalButton.Visibility = new GameScenesVisibility(GameScenes.FLIGHT);
AutoGimbalButton.OnClick += (e) => guiEnabled = !guiEnabled;
AutoGimbalButton.Visible = true;
}
else if (scene == GameScenes.FLIGHT)
{
guiEnabled = true;
}
}
//Create the OnDraw function called above into the rendering queue. This will create the GUI and collect actions input to the GUI.
void OnGUI()
{
//Define the default window position, if no changes have been made:
if (windowPosn.x == 0 && windowPosn.y == 0)
{
windowPosn = new Rect(Screen.width - 300, 50, 10, 10);
}
var scene = HighLogic.LoadedScene;
if (scene == GameScenes.FLIGHT)
{
//Creates a new box, specifying the position to follow the defined position above.
if (guiEnabled)
{
windowPosn = GUILayout.Window(0, windowPosn, WindowMaker, "AutoGimbal");
}
}
}
protected void WindowMaker(int windowID)
{
GUILayout.BeginVertical();
GUILayout.Label("Target Angle:");
rotationTargetString = GUILayout.TextField(rotationTargetString);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Start"))
{
rotationTarget = float.Parse(rotationTargetString);
TrackingState = 1;
}
if (GUILayout.Button("Stop"))
{
TrackingState = 0;
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
shipsToggle = GUILayout.Toggle(shipsToggle, "Ships", "Button");
bodiesToggle = GUILayout.Toggle(bodiesToggle, "Bodies", "Button");
GUILayout.EndHorizontal();
if (GUILayout.Button("Close"))
{
guiEnabled = false;
}
GUILayout.EndVertical();
GUI.DragWindow(); //Make the GUI draggable
}
void OnDestroy()
{
if (ToolbarManager.ToolbarAvailable)
{
AutoGimbalButton.Destroy();
}
}
}
}