This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
/
KreationHandler.cs
138 lines (120 loc) · 5.47 KB
/
KreationHandler.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//Copyright (c) 2014, Blake Meyler.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
//(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
//distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
//subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System.Collections;
using System.IO;
using UnityEngine;
namespace KustomKerbals
{
[KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
public class KK : MonoBehaviour
{
private static Rect windowPosition = new Rect(0, 0, 250, 160);
private static GUIStyle windowStyle = null;
private static bool buttonState = false;
public static bool windowState = true;
public static bool isKSCLocked = false;
public string stringToEdit = "Jebediah Kerman Jr.";
public float sliderValue = 0.0f;
public float sliderValue2 = 0.0f;
public int kerbal { get; set; }
public static string Path = (KSPUtil.ApplicationRootPath + HighLogic.CurrentGame + "peristent.sfs");
public void Awake()
{
RenderingManager.AddToPostDrawQueue(0, OnDraw);
}
public void Start()
{
//Sets window style to KSP default.
windowStyle = new GUIStyle(HighLogic.Skin.window);
Debug.Log("Kustom Kerbals loaded.");
}
private void OnDraw()
{
//Checks if player has toggled the window on or off.
if (windowState == true)
{
windowPosition = GUI.Window(1234, windowPosition, OnWindow, "Kustom Kerbals", windowStyle);
//Resets window position to middle of screen.
if (windowPosition.x == 0f && windowPosition.y == 0f)
{
//windowPosition = windowPosition.CenterScreen();
}
}
}
//Gets a new kerbal and sets his stats.
private void SpawnKerbal(int count)
{
ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNewKerbal();
kerbal.name = stringToEdit;
kerbal.courage = sliderValue;
kerbal.stupidity = sliderValue2;
kerbal.isBadass = buttonState;
}
//makes the new kerbal available for use.
private void SpawnKerbal(ProtoCrewMember kerbal)
{
kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
}
//Tells the window to open.
public void Update()
{
}
private void OnWindow(int windowID)
{
//Field to type in kerbal's name.
GUILayout.BeginHorizontal();
GUILayout.Label("Name:");
stringToEdit = GUILayout.TextField(stringToEdit, 50);
GUILayout.EndHorizontal();
//Sets kerbal's courage.
GUILayout.BeginHorizontal();
GUILayout.Label("Courage:");
sliderValue = GUILayout.HorizontalSlider(sliderValue, 0.0f, 1.0f);
GUILayout.EndHorizontal();
//Sets kerbal's stupidity.
GUILayout.BeginHorizontal();
GUILayout.Label("Stupidity:");
sliderValue2 = GUILayout.HorizontalSlider(sliderValue2, 0.0f, 1.0f);
GUILayout.EndHorizontal();
//Toggles badass state.
GUILayout.BeginHorizontal();
buttonState = GUILayout.Toggle(buttonState, "Badass: " + buttonState);
GUILayout.EndHorizontal();
//Button to create the kerbal using above paramaters.
if (GUI.Button(new Rect(7, 125, 150, 30), "Kreate Kustom Kerbal"))
{
if (isKSCLocked)
{
InputLockManager.RemoveControlLock("KSCLock");
isKSCLocked = false;
}
if (stringToEdit == "Jebediah Kerman Jr." && sliderValue == 0.0f && sliderValue2 == 0.0f && buttonState == false)
{
ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNewKerbal();
kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
windowState = false;
ScreenMessages.PostScreenMessage("Random Kerbal Spawned, closing window...", 1, ScreenMessageStyle.UPPER_CENTER);
}
else
{
Debug.Log("Kustom Kerbal Kreated.");
Debug.Log("KK window closed.");
SpawnKerbal(kerbal);
windowState = false;
ScreenMessages.PostScreenMessage("Kustom Kerbal Spawned, closing window...", 1, ScreenMessageStyle.UPPER_CENTER);
}
}
GUI.DragWindow();
}
}
}