forked from vXSovereignXv/CrewManifest
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Utilities.cs
163 lines (137 loc) · 7.77 KB
/
Utilities.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using KSP.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace CrewManifest
{
public static class ManifestUtilities
{
public static String AppPath = KSPUtil.ApplicationRootPath.Replace("\\", "/");
public static String PlugInPath = AppPath + "GameData/CrewManifest/Plugins/PluginData/CrewManifest/";
public static Vector2 DebugScrollPosition = Vector2.zero;
private static List<string> _errors = new List<string>();
public static List<string> Errors
{
get { return _errors; }
}
public static void LoadTexture(ref Texture2D tex, String FileName)
{
LogMessage(String.Format("Loading Texture - file://{0}{1}", PlugInPath, FileName), "Info");
WWW img1 = new WWW(String.Format("file://{0}{1}", PlugInPath, FileName));
img1.LoadImageIntoTexture(tex);
}
public static void LogMessage(string error, string type)
{
_errors.Add(type + ": " + error);
}
}
public static class Resources
{
public static GUIStyle WindowStyle;
public static GUIStyle IconStyle;
public static GUIStyle ButtonToggledStyle;
public static GUIStyle ButtonToggledRedStyle;
public static GUIStyle ButtonStyle;
public static GUIStyle ErrorLabelRedStyle;
public static GUIStyle LabelStyle;
public static GUIStyle LabelStyleRed;
public static GUIStyle LabelStyleYellow;
// Part selection colors.
internal static readonly Color SourceColor = Color.green;
internal static readonly Color TargetColor = Color.red;
internal static readonly Color SelectionColor = Color.yellow;
// Roster status colors.
private static readonly Color AvailableColor = Color.white;
private static readonly Color UnavailableColor = Color.yellow;
private static readonly Color DeadColor = Color.red;
public static void SetupGUI()
{
GUI.skin = HighLogic.Skin;
if (WindowStyle == null)
{
SetStyles();
}
}
public static void SetStyles()
{
WindowStyle = new GUIStyle(GUI.skin.window);
IconStyle = new GUIStyle();
ButtonToggledStyle = new GUIStyle(GUI.skin.button);
ButtonToggledStyle.normal.textColor = Resources.SourceColor;
ButtonToggledStyle.normal.background = ButtonToggledStyle.onActive.background;
ButtonToggledRedStyle = new GUIStyle(ButtonToggledStyle);
ButtonToggledRedStyle.normal.textColor = Resources.TargetColor;
ButtonStyle = new GUIStyle(GUI.skin.button);
ButtonStyle.normal.textColor = Resources.AvailableColor;
ErrorLabelRedStyle = new GUIStyle(GUI.skin.label);
ErrorLabelRedStyle.normal.textColor = Color.red;
ErrorLabelRedStyle.fontSize = 10;
LabelStyle = new GUIStyle(GUI.skin.label);
LabelStyleRed = new GUIStyle(LabelStyle);
LabelStyleRed.normal.textColor = Resources.DeadColor;
LabelStyleYellow = new GUIStyle(LabelStyle);
LabelStyleYellow.normal.textColor = Resources.UnavailableColor;
}
}
public class SettingsManager
{
public Rect ManifestPosition;
public Rect TransferPosition;
public Rect RosterPosition;
public Rect SettingsPosition;
public Rect DebuggerPosition;
public bool ShowDebugger;
public void Load()
{
ManifestUtilities.LogMessage("Settings load started...", "Info");
try
{
KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType<CrewManifestModule>();
configfile.load();
ManifestPosition = configfile.GetValue<Rect>("ManifestPosition");
TransferPosition = configfile.GetValue<Rect>("TransferPosition");
RosterPosition = configfile.GetValue<Rect>("RosterPosition");
SettingsPosition = configfile.GetValue<Rect>("SettingsPosition");
DebuggerPosition = configfile.GetValue<Rect>("DebuggerPosition");
ShowDebugger = configfile.GetValue<bool>("ShowDebugger");
ManifestUtilities.LogMessage(string.Format("ManifestPosition Loaded: {0}, {1}, {2}, {3}", ManifestPosition.xMin, ManifestPosition.xMax, ManifestPosition.yMin, ManifestPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("TransferPosition Loaded: {0}, {1}, {2}, {3}", TransferPosition.xMin, TransferPosition.xMax, TransferPosition.yMin, TransferPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("RosterPosition Loaded: {0}, {1}, {2}, {3}", RosterPosition.xMin, RosterPosition.xMax, RosterPosition.yMin, RosterPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("SettingsPosition Loaded: {0}, {1}, {2}, {3}", SettingsPosition.xMin, SettingsPosition.xMax, SettingsPosition.yMin, SettingsPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("DebuggerPosition Loaded: {0}, {1}, {2}, {3}", DebuggerPosition.xMin, DebuggerPosition.xMax, DebuggerPosition.yMin, DebuggerPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("ShowDebugger Loaded: {0}", ShowDebugger.ToString()), "Info");
}
catch(Exception e)
{
ManifestUtilities.LogMessage(string.Format("Failed to Load Settings: {0} \r\n\r\n{1}", e.Message, e.StackTrace), "Exception");
}
}
public void Save()
{
try
{
KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType<CrewManifestModule>();
configfile.SetValue("ManifestPosition", ManifestPosition);
configfile.SetValue("TransferPosition", TransferPosition);
configfile.SetValue("RosterPosition", RosterPosition);
configfile.SetValue("SettingsPosition", SettingsPosition);
configfile.SetValue("DebuggerPosition", DebuggerPosition);
configfile.SetValue("ShowDebugger", ShowDebugger);
configfile.save();
ManifestUtilities.LogMessage(string.Format("ManifestPosition Saved: {0}, {1}, {2}, {3}", ManifestPosition.xMin, ManifestPosition.xMax, ManifestPosition.yMin, ManifestPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("TransferPosition Saved: {0}, {1}, {2}, {3}", TransferPosition.xMin, TransferPosition.xMax, TransferPosition.yMin, TransferPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("RosterPosition Saved: {0}, {1}, {2}, {3}", RosterPosition.xMin, RosterPosition.xMax, RosterPosition.yMin, RosterPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("SettingsPosition Saved: {0}, {1}, {2}, {3}", SettingsPosition.xMin, SettingsPosition.xMax, SettingsPosition.yMin, SettingsPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("DebuggerPosition Saved: {0}, {1}, {2}, {3}", DebuggerPosition.xMin, DebuggerPosition.xMax, DebuggerPosition.yMin, DebuggerPosition.yMax), "Info");
ManifestUtilities.LogMessage(string.Format("ShowDebugger Saved: {0}", ShowDebugger.ToString()), "Info");
ManifestUtilities.LogMessage(string.Format("AllowRespawn Saved: {0}", ShowDebugger.ToString()), "Info");
}
catch (Exception e)
{
ManifestUtilities.LogMessage(string.Format("Failed to Save Settings: {0} \r\n\r\n{1}", e.Message, e.StackTrace), "Exception");
}
}
}
}