forked from ihsoft/KAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKASModulePort.cs
More file actions
145 lines (130 loc) · 4.98 KB
/
KASModulePort.cs
File metadata and controls
145 lines (130 loc) · 4.98 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
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
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using UnityEngine;
namespace KAS
{
public class KASModulePort : KASModuleAttachCore
{
//Part.cfg
[KSPField] public string nodeType = "kasplug";
[KSPField] public string attachNode = "bottom";
[KSPField] public string nodeTransformName = "portNode";
[KSPField] public float breakForce = 30;
[KSPField] public float rotateForce = 1f;
//Sounds
[KSPField] public string plugSndPath = "KAS/Sounds/plug";
[KSPField] public string unplugSndPath = "KAS/Sounds/unplug";
[KSPField] public string plugDockedSndPath = "KAS/Sounds/plugdocked";
[KSPField] public string unplugDockedSndPath = "KAS/Sounds/unplugdocked";
public FXGroup fxSndPlug, fxSndUnplug, fxSndPlugDocked, fxSndUnplugDocked;
public KASPlugState plugState = 0;
public enum KASPlugState
{
Ready = 0,
PreAttached = 1,
PlugUndock = 2,
PlugDock = 3,
}
public KASModuleWinch winchConnected;
public Transform portNode
{
get { return this.part.FindModelTransform(nodeTransformName);}
}
public override string GetInfo()
{
string info = base.GetInfo();
info += "---- Port ----";
info += "\n";
info += "Strength : " + breakForce;
info += "\n";
info += "Rotating force : " + rotateForce;
return info;
}
public override void OnStart(StartState state)
{
base.OnStart(state);
if (state == StartState.Editor || state == StartState.None) return;
KAS_Shared.createFXSound(this.part, fxSndPlug, plugSndPath, false);
KAS_Shared.createFXSound(this.part, fxSndUnplug, unplugSndPath, false);
KAS_Shared.createFXSound(this.part, fxSndPlugDocked, plugDockedSndPath, false);
KAS_Shared.createFXSound(this.part, fxSndUnplugDocked, unplugDockedSndPath, false);
}
public void TurnLeft()
{
Vector3 force = portNode.TransformDirection(Vector3.forward) * rotateForce;
this.part.Rigidbody.AddTorque(force, ForceMode.Force);
}
public void TurnRight()
{
Vector3 force = portNode.TransformDirection(Vector3.forward) * rotateForce;
this.part.Rigidbody.AddTorque(-force, ForceMode.Force);
}
public bool strutConnected()
{
KASModuleStrut moduleStrut = this.part.GetComponent<KASModuleStrut>();
if (moduleStrut)
{
if (moduleStrut.linkedStrutModule)
{
return true;
}
}
return false;
}
[KSPEvent(name = "ContextMenuPlugUndocked", active = true, guiActive = false, guiActiveUnfocused = true, guiName = "Plug(Undocked)")]
public void ContextMenuPlugUndocked()
{
KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
if (winchModule)
{
winchModule.PlugHead(this, KASModuleWinch.PlugState.PlugUndocked);
}
else
{
ScreenMessages.PostScreenMessage("You didn't have anything to plug !", 5, ScreenMessageStyle.UPPER_CENTER);
}
}
[KSPEvent(name = "ContextMenuPlugDocked", active = true, guiActive = false, guiActiveUnfocused = true, guiName = "Plug(Docked)")]
public void ContextMenuPlugDocked()
{
KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
if (winchModule)
{
winchModule.PlugHead(this, KASModuleWinch.PlugState.PlugDocked);
}
else
{
ScreenMessages.PostScreenMessage("You didn't have anything to plug !", 5, ScreenMessageStyle.UPPER_CENTER);
}
}
[KSPEvent(name = "ContextMenuUnplug", active = true, guiActive = true, guiActiveUnfocused = true, guiName = "Unplug")]
public void ContextMenuUnplug()
{
if (winchConnected)
{
winchConnected.UnplugHead();
}
else
{
ScreenMessages.PostScreenMessage("There is nothing to unplug !", 5, ScreenMessageStyle.UPPER_CENTER);
}
}
[KSPAction("Unplug", actionGroup = KSPActionGroup.None)]
public void ActionGroupUnplug(KSPActionParam param)
{
if (!this.part.packed)
{
if (winchConnected)
{
winchConnected.UnplugHead();
}
else
{
ScreenMessages.PostScreenMessage("There is nothing to unplug !", 5, ScreenMessageStyle.UPPER_CENTER);
}
}
}
}
}