Skip to content

Commit 5e498a0

Browse files
committed
Adding Source Code
1 parent ad0fa46 commit 5e498a0

10 files changed

Lines changed: 660 additions & 0 deletions

File tree

ModuleManagerWatchDog.sln

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleManagerWatchDog", "Source\ModuleManagerWatchDog\ModuleManagerWatchDog.csproj", "{C4A875CC-E958-429F-944B-D0702EA76A89}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{5DF4A87C-15E4-4C67-9314-02E7BDCB449D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{5DF4A87C-15E4-4C67-9314-02E7BDCB449D}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{5DF4A87C-15E4-4C67-9314-02E7BDCB449D}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{5DF4A87C-15E4-4C67-9314-02E7BDCB449D}.Release|Any CPU.Build.0 = Release|Any CPU
16+
{C4A875CC-E958-429F-944B-D0702EA76A89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{C4A875CC-E958-429F-944B-D0702EA76A89}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{C4A875CC-E958-429F-944B-D0702EA76A89}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{C4A875CC-E958-429F-944B-D0702EA76A89}.Release|Any CPU.Build.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(MonoDevelopProperties) = preSolution
22+
Policies = $0
23+
$0.TextStylePolicy = $1
24+
$1.inheritsSet = null
25+
$1.scope = text/x-csharp
26+
$0.CSharpFormattingPolicy = $2
27+
$2.scope = text/x-csharp
28+
$0.TextStylePolicy = $3
29+
$3.FileWidth = 132
30+
$3.EolMarker = Unix
31+
$3.scope = text/plain
32+
EndGlobalSection
33+
EndGlobal
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
This file is part of Module Manager Watch Dog
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager Watch Dog is licensed as follows:
6+
7+
* SKL 1.0 : https://ksp.lisias.net/SKL-1_0.txt
8+
9+
And you are allowed to choose the License that better suit your needs.
10+
11+
KSP-Recall is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
15+
You should have received a copy of the SKL Standard License 1.0
16+
along with Module Manager Watch Dog. If not, see
17+
<https://ksp.lisias.net/SKL-1_0.txt>.
18+
19+
*/
20+
using UnityEngine;
21+
22+
namespace KSPe.Common.Dialogs
23+
{
24+
internal class AbstractDialog
25+
{
26+
27+
private static Texture2D windowTex = null;
28+
protected static void SetWindowBackground(GUIStyle style)
29+
{
30+
if (null == windowTex)
31+
{
32+
windowTex = new Texture2D(1, 1);
33+
windowTex.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.45f));
34+
windowTex.Apply();
35+
style.active.background =
36+
style.focused.background =
37+
style.normal.background = windowTex;
38+
}
39+
}
40+
41+
private static Texture2D textTex = null;
42+
protected static void SetTextBackground(GUIStyle style)
43+
{
44+
if (null == textTex)
45+
{
46+
textTex = new Texture2D(1, 1);
47+
textTex.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.45f));
48+
textTex.Apply();
49+
}
50+
style.active.background =
51+
style.focused.background =
52+
style.normal.background = textTex;
53+
}
54+
55+
}
56+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
This file is part of KSPe, a component for KSP API Extensions/L
3+
(C) 2018-20 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
KSPe API Extensions/L is double licensed, as follows:
6+
7+
* SKL 1.0 : https://ksp.lisias.net/SKL-1_0.txt
8+
* GPL 2.0 : https://www.gnu.org/licenses/gpl-2.0.txt
9+
10+
And you are allowed to choose the License that better suit your needs.
11+
12+
KSPe API Extensions/L is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
You should have received a copy of the SKL Standard License 1.0
17+
along with KSPe API Extensions/L. If not, see <https://ksp.lisias.net/SKL-1_0.txt>.
18+
19+
You should have received a copy of the GNU General Public License 2.0
20+
along with KSPe API Extensions/L. If not, see <https://www.gnu.org/licenses/>.
21+
22+
*/
23+
using System;
24+
using UnityEngine;
25+
using KSPe.UI;
26+
27+
namespace KSPe.Common.Dialogs
28+
{
29+
internal class ShowStopperAlertBox : AbstractDialog
30+
{
31+
private static readonly string aMSG = "close KSP and then fix the problem described above";
32+
33+
private static readonly string MSG = @"{0}
34+
35+
This is a Show Stopper problem. Your best line of action is to click the OK button to {1}.
36+
37+
If you choose to ignore this message and click Cancel to proceed, be advised that your savegames can get corrupted at any time, even when things appear to work by now - and the salvage can be harder.
38+
39+
Backup everything *NOW* if you choose to ignore this message and proceed - it's recommended to use S.A.V.E. to automate this task for you.";
40+
41+
public static void Show(string errorMessage)
42+
{
43+
Show(errorMessage, aMSG, Application.Quit);
44+
}
45+
46+
public static void Show(string errorMessage, string actionMessage, Action lambda)
47+
{
48+
GameObject go = new GameObject("KSPe.Common.Diallgs.ShowStopperAlertBox");
49+
MessageBox dlg = go.AddComponent<MessageBox>();
50+
51+
//GUIStyle win = new GUIStyle(HighLogic.Skin.window)
52+
GUIStyle win = new GUIStyle("Window")
53+
{
54+
fontSize = 26,
55+
fontStyle = FontStyle.Bold,
56+
alignment = TextAnchor.UpperCenter,
57+
wordWrap = false
58+
};
59+
win.normal.textColor = Color.red;
60+
win.border.top = 0;
61+
win.padding.top = -5;
62+
SetWindowBackground(win);
63+
win.active.background = win.focused.background = win.normal.background;
64+
65+
GUIStyle text = new GUIStyle("Label")
66+
{
67+
fontSize = 18,
68+
fontStyle = FontStyle.Normal,
69+
alignment = TextAnchor.MiddleLeft,
70+
wordWrap = true
71+
};
72+
text.normal.textColor = Color.white;
73+
text.padding.top = 8;
74+
text.padding.bottom = text.padding.top;
75+
text.padding.left = text.padding.top;
76+
text.padding.right = text.padding.top;
77+
SetTextBackground(text);
78+
79+
dlg.Show(
80+
"Houston, we have a Problem!",
81+
String.Format(MSG, errorMessage, actionMessage),
82+
lambda,
83+
win, text
84+
);
85+
}
86+
}
87+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
This file is part of Module Manager Watch Dog
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager Watch Dog is licensed as follows:
6+
7+
* SKL 1.0 : https://ksp.lisias.net/SKL-1_0.txt
8+
9+
And you are allowed to choose the License that better suit your needs.
10+
11+
KSP-Recall is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
15+
You should have received a copy of the SKL Standard License 1.0
16+
along with Module Manager Watch Dog. If not, see
17+
<https://ksp.lisias.net/SKL-1_0.txt>.
18+
19+
*/
20+
using System;
21+
using UnityEngine;
22+
using UGUI = UnityEngine.GUI;
23+
24+
namespace KSPe.UI
25+
{
26+
internal class MessageBox : MonoBehaviour
27+
{
28+
private string title;
29+
private string msg;
30+
private Action action;
31+
private GUIStyle win_style;
32+
private GUIStyle text_style;
33+
private int window_id;
34+
private Rect windowRect;
35+
36+
public void Show(string title, string msg)
37+
{
38+
Show(title, msg, null, null, null);
39+
}
40+
41+
public void Show(string title, string msg, Action action)
42+
{
43+
Show(title, msg, action, null, null);
44+
}
45+
46+
public void Show(string title, string msg, GUIStyle win_style, GUIStyle text_style)
47+
{
48+
Show(title, msg, null, win_style, text_style);
49+
}
50+
51+
public void Show(string title, string msg, Action action, GUIStyle win_style, GUIStyle text_style)
52+
{
53+
this.title = title;
54+
this.msg = msg;
55+
this.action = action;
56+
this.win_style = win_style;
57+
this.text_style = text_style;
58+
this.window_id = (int)System.DateTime.Now.Ticks;
59+
60+
this.windowRect = this.calculateWindow();
61+
}
62+
63+
private Rect calculateWindow()
64+
{
65+
const int maxWidth = 640;
66+
const int maxHeight = 480;
67+
68+
int width = Mathf.Min(maxWidth, Screen.width - 20);
69+
int height = Mathf.Min(maxHeight, Screen.height - 20);
70+
71+
return new Rect(
72+
(Screen.width - width) / 2, (Screen.height - height) / 2,
73+
width, height
74+
);
75+
76+
}
77+
78+
private void OnGUI()
79+
{
80+
this.windowRect = this.win_style is null
81+
? UGUI.ModalWindow(this.window_id, this.windowRect, WindowFunc, this.title)
82+
: UGUI.ModalWindow(this.window_id, this.windowRect, WindowFunc, this.title, this.win_style);
83+
}
84+
85+
private void WindowFunc(int windowID)
86+
{
87+
const int border = 10;
88+
const int width = 50;
89+
const int height = 25;
90+
const int spacing = 10;
91+
92+
Rect l = new Rect(
93+
border, border + spacing,
94+
this.windowRect.width - border * 2, this.windowRect.height - border * 2 - height - spacing
95+
);
96+
97+
if (this.text_style is null)
98+
UGUI.Label(l, this.msg);
99+
else
100+
UGUI.Label(l, this.msg, this.text_style);
101+
102+
Rect b = new Rect(
103+
this.windowRect.width - width - border,
104+
this.windowRect.height - height - border,
105+
width,
106+
height);
107+
108+
if (this.action is null)
109+
{
110+
if (UGUI.Button(b, "OK")) Destroy(this.gameObject);
111+
}
112+
else
113+
{
114+
if (UGUI.Button(b, "OK")) { this.action(); Destroy(this.gameObject); }
115+
116+
Rect b1 = new Rect(b);
117+
b1.x -= b.width + spacing;
118+
if (UGUI.Button(b1, "Cancel")) Destroy(this.gameObject);
119+
}
120+
}
121+
}
122+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This file is part of Module Manager Watch Dog
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager Watch Dog is licensed as follows:
6+
7+
* SKL 1.0 : https://ksp.lisias.net/SKL-1_0.txt
8+
9+
And you are allowed to choose the License that better suit your needs.
10+
11+
KSP-Recall is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
15+
You should have received a copy of the SKL Standard License 1.0
16+
along with Module Manager Watch Dog. If not, see
17+
<https://ksp.lisias.net/SKL-1_0.txt>.
18+
19+
*/
20+
using UnityEngine;
21+
22+
namespace ModuleManagerWatchDog.GUI
23+
{
24+
internal static class ShowStopperAlertBox
25+
{
26+
private static readonly string AMSG = @"to get instructions about how to Download and Install Module Manager.";
27+
28+
internal static void Show(string msg)
29+
{
30+
KSPe.Common.Dialogs.ShowStopperAlertBox.Show(
31+
msg,
32+
AMSG,
33+
() => { Application.OpenURL("https://ksp.lisias.net/add-ons/ModuleManager/WatchDog/KNOWN_ISSUES"); Application.Quit(); }
34+
);
35+
Log.detail("\"Houston, we have a Problem!\" was displayed");
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)