-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartCountLaunchLimiter.cs
More file actions
88 lines (69 loc) · 2.84 KB
/
Copy pathPartCountLaunchLimiter.cs
File metadata and controls
88 lines (69 loc) · 2.84 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace TinkerTech
{
[KSPAddon(KSPAddon.Startup.EditorAny, false)] //nonpersistent, restarted on each editor scene entry
class PartCountLaunchLimiter : MonoBehaviour
{
private bool lockLaunchButton = false;
private Rect windowRect = new Rect();
private string warningMsg = "";
GUIStyle labelStyle = new GUIStyle();
void Start()
{
labelStyle = HighLogic.Skin.box;
labelStyle.normal.textColor = Color.red;
labelStyle.alignment = TextAnchor.MiddleCenter;
labelStyle.wordWrap = true;
windowRect = new Rect(Screen.width - 350, 50, 280, 100);
GameEvents.onEditorShipModified.Add(new EventData<ShipConstruct>.OnEvent(OnEditorShipModified));
}
private void OnEditorShipModified(ShipConstruct shipConstruct)
{
if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || ResearchAndDevelopment.Instance == null)
return;
int maxParts = maxPartCount();
if (shipConstruct.Parts.Count > maxParts)
{
warningMsg = "This vessel has too many parts to be built and launched at the current tech level.\nCurrent maximum is " + maxParts + ", this vessel has " + shipConstruct.Parts.Count + " parts.";
//ScreenMessages.PostScreenMessage(warningMsg, 15F, ScreenMessageStyle.UPPER_CENTER);
lockLaunchButton = true;
} else {
warningMsg = "";
if (shipConstruct.Parts.Count > 0)
lockLaunchButton = false;
else
lockLaunchButton = true;
}
}
private void OnGUI()
{
if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || ResearchAndDevelopment.Instance == null)
return;
if (lockLaunchButton)
{
EditorLogic.fetch.launchBtn.SetControlState(UIButton.CONTROL_STATE.DISABLED);
if (warningMsg.Length > 0)
{
GUI.Label(windowRect, warningMsg, labelStyle);
}
}
else
EditorLogic.fetch.launchBtn.SetControlState(UIButton.CONTROL_STATE.NORMAL);
}
private int maxPartCount()
{
int partsAllowed = 200;
if (ResearchAndDevelopment.GetTechnologyState("veryHeavyRocketry") == RDTech.State.Available)
partsAllowed += 25;
return partsAllowed;
}
void OnDestroy()
{
GameEvents.onEditorShipModified.Remove(new EventData<ShipConstruct>.OnEvent(OnEditorShipModified));
}
}
}