Skip to content

Commit

Permalink
Merge pull request #13 from erendrake/develop
Browse files Browse the repository at this point in the history
Pulling latest changes into my branch.
  • Loading branch information
ZiwKerman committed Mar 25, 2015
2 parents 268e3fb + 5083995 commit 1f14e94
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 246 deletions.
299 changes: 153 additions & 146 deletions InfernalRobotics/InfernalRobotics/Gui/ControlsGUI.cs

Large diffs are not rendered by default.

138 changes: 51 additions & 87 deletions InfernalRobotics/InfernalRobotics/Module/MuMechToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class MuMechToggle : PartModule
public string forwardKey
{
get { return forwardKeyStore; }
set { forwardKeyStore = value.ToLower(); }
set
{
forwardKeyStore = value.ToLower();
rotateKey = translateKey = forwardKey;
}
}

[KSPField(isPersistant = true)] public bool freeMoving = false;
Expand All @@ -39,10 +43,10 @@ public string forwardKey
[KSPField(isPersistant = true)] public bool limitTweakable = false;
[KSPField(isPersistant = true)] public bool limitTweakableFlag = false;

[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Max Range", guiFormat = "F2", guiUnits = ""), UI_FloatEdit(minValue = -360f, maxValue = 360f, incrementSlide = 0.01f, scene = UI_Scene.All)]
[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Max", guiFormat = "F2", guiUnits = ""), UI_FloatEdit(minValue = -360f, maxValue = 360f, incrementSlide = 0.01f, scene = UI_Scene.All)]
public float maxTweak = 360;

[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Min Range", guiFormat = "F2", guiUnits = ""), UI_FloatEdit(minValue = -360f, maxValue = 360f, incrementSlide = 0.01f, scene = UI_Scene.All)]
[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Min", guiFormat = "F2", guiUnits = ""), UI_FloatEdit(minValue = -360f, maxValue = 360f, incrementSlide = 0.01f, scene = UI_Scene.All)]
public float minTweak = 0;

[KSPField(isPersistant = true)] public bool on = false;
Expand All @@ -64,7 +68,11 @@ public string revRotateKey
public string reverseKey
{
get { return reverseKeyStore; }
set { reverseKeyStore = value.ToLower(); }
set
{
reverseKeyStore = value.ToLower();
revRotateKey = revTranslateKey = reverseKey;
}
}

[KSPField(isPersistant = true)] public string rotateKey = "";
Expand All @@ -83,9 +91,6 @@ public string reverseKey
UI_FloatEdit(minValue = 0.05f, incrementSlide = 0.05f, incrementSmall=0.5f, incrementLarge=1f)]
public float accelTweak = 4f;

[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Step Increment"), UI_ChooseOption(options = new[] {"0.01", "0.1", "1.0"})]
public string stepIncrement = "0.1";

[KSPField(isPersistant = true)] public float translateMax = 3;
[KSPField(isPersistant = true)] public float translateMin = 0;
[KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "Translation")]
Expand Down Expand Up @@ -193,6 +198,8 @@ public MuMechToggle()

public List<float> PresetPositions { get; set; }

public float Position { get { return rotateJoint ? rotation : translation; } }

private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
Expand Down Expand Up @@ -246,6 +253,11 @@ public bool IsSymmMaster()
return part.symmetryCounterparts.All( cp => ((MuMechToggle) cp.Modules["MuMechToggle"]).CreationOrder >= CreationOrder);
}

public float GetStepIncrement()
{
return rotateJoint ? 1f : 0.05f;
}

public void UpdateState()
{
if (on)
Expand Down Expand Up @@ -365,10 +377,6 @@ public override void OnAwake()
Fields["maxTweak"].guiActiveEditor = false;
Fields["speedTweak"].guiActive = false;
Fields["speedTweak"].guiActiveEditor = false;
Fields["speedTweakFine"].guiActive = false;
Fields["speedTweakFine"].guiActiveEditor = false;
Fields["stepIncrement"].guiActiveEditor = false;
Fields["stepIncrement"].guiActive = false;
Fields["accelTweak"].guiActive = false;
Fields["accelTweak"].guiActiveEditor = false;
Fields["rotation"].guiActive = false;
Expand Down Expand Up @@ -429,13 +437,6 @@ public override void OnSave(ConfigNode node)
Logger.Log("[OnSave] End", Logger.Level.Debug);
}

public void RefreshKeys()
{
translateKey = forwardKey;
revTranslateKey = reverseKey;
rotateKey = forwardKey;
revRotateKey = reverseKey;
}

public void ParsePresetPositions()
{
Expand Down Expand Up @@ -528,39 +529,42 @@ public override void OnLoad(ConfigNode config)
Logger.Log("[OnLoad] End", Logger.Level.Debug);
}

private void SetupMinMaxTweaks()
private void UpdateMinMaxTweaks()
{
UI_FloatEdit rangeMin;
UI_FloatEdit rangeMax;
if (HighLogic.LoadedSceneIsEditor)
if (rotateJoint)
{
rangeMin = (UI_FloatEdit)Fields["minTweak"].uiControlEditor;
rangeMax = (UI_FloatEdit)Fields["maxTweak"].uiControlEditor;
var rangeMinF = (UI_FloatEdit) Fields["minTweak"].uiControlEditor;
rangeMinF.minValue = rotateMin;
rangeMinF.maxValue = rotateMax;
var rangeMaxF = (UI_FloatEdit) Fields["maxTweak"].uiControlEditor;
rangeMaxF.minValue = rotateMin;
rangeMaxF.maxValue = rotateMax;
}
else
{
rangeMin = (UI_FloatEdit)Fields["minTweak"].uiControlFlight;
rangeMax = (UI_FloatEdit)Fields["maxTweak"].uiControlFlight;
var rangeMinF = (UI_FloatEdit) Fields["minTweak"].uiControlEditor;
rangeMinF.minValue = translateMin;
rangeMinF.maxValue = translateMax;
var rangeMaxF = (UI_FloatEdit) Fields["maxTweak"].uiControlEditor;
rangeMaxF.minValue = translateMin;
rangeMaxF.maxValue = translateMax;
}
float minimum = rotateJoint ? rotateMin : translateMin;
float maximum = rotateJoint ? rotateMax : translateMax;
rangeMin.minValue = minimum;
rangeMin.maxValue = maximum;
rangeMin.incrementSlide = float.Parse(stepIncrement);
rangeMax.minValue = minimum;
rangeMax.maxValue = maximum;
rangeMax.incrementSlide = float.Parse(stepIncrement);
}

if (rotateJoint)

private void SetupMinMaxTweaks()
{
if (HighLogic.LoadedSceneIsEditor)
{
Fields["minTweak"].guiName = "Min Rotate";
Fields["maxTweak"].guiName = "Max Rotate";
((UI_FloatEdit)Fields["minTweak"].uiControlEditor).incrementSlide = GetStepIncrement();
((UI_FloatEdit)Fields["maxTweak"].uiControlEditor).incrementSlide = GetStepIncrement();
}
else if (translateJoint)
else
{
Fields["minTweak"].guiName = "Min Translate";
Fields["maxTweak"].guiName = "Max Translate";
((UI_FloatEdit)Fields["minTweak"].uiControlFlight).incrementSlide = GetStepIncrement();
((UI_FloatEdit)Fields["maxTweak"].uiControlFlight).incrementSlide = GetStepIncrement();
}
UpdateMinMaxTweaks();
}

protected void DebugCollider(MeshCollider toDebug)
Expand Down Expand Up @@ -679,27 +683,10 @@ public override void OnStart(StartState state)
{
Logger.Log("[MMT] OnStart Start", Logger.Level.Debug);

BaseField field = Fields["stepIncrement"];

var optionsEditor = (UI_ChooseOption)field.uiControlEditor;
var optionsFlight = (UI_ChooseOption)field.uiControlFlight;

if (translateJoint)
{
optionsEditor.options = new[] { "0.01", "0.1", "1.0" };
optionsFlight.options = new[] { "0.01", "0.1", "1.0" };
}
else if (rotateJoint)
{
optionsEditor.options = new[] { "0.1", "1", "10" };
optionsFlight.options = new[] { "0.1", "1", "10" };
}

//part.stackIcon.SetIcon(DefaultIcons.STRUT);
limitTweakableFlag = rotateLimits;
float position = rotateJoint ? rotation : translation;
if (!float.IsNaN(position))
Interpolator.Position = position;
if (!float.IsNaN(Position))
Interpolator.Position = Position;

Translator.Init(Interpolator, invertAxis, isMotionLock, this);

Expand Down Expand Up @@ -1036,36 +1023,14 @@ public void RefreshTweakUI()
if (HighLogic.LoadedScene != GameScenes.EDITOR) return;
if (TweakWindow == null) return;

if (translateJoint)
{
var rangeMinF = (UI_FloatEdit) Fields["minTweak"].uiControlEditor;
rangeMinF.minValue = translateMin;
rangeMinF.maxValue = translateMax;
rangeMinF.incrementSlide = float.Parse(stepIncrement);
var rangeMaxF = (UI_FloatEdit) Fields["maxTweak"].uiControlEditor;
rangeMaxF.minValue = translateMin;
rangeMaxF.maxValue = translateMax;
rangeMaxF.incrementSlide = float.Parse(stepIncrement);
}
else if (rotateJoint)
{
var rangeMinF = (UI_FloatEdit) Fields["minTweak"].uiControlEditor;
rangeMinF.minValue = rotateMin;
rangeMinF.maxValue = rotateMax;
rangeMinF.incrementSlide = float.Parse(stepIncrement);
var rangeMaxF = (UI_FloatEdit) Fields["maxTweak"].uiControlEditor;
rangeMaxF.minValue = rotateMin;
rangeMaxF.maxValue = rotateMax;
rangeMaxF.incrementSlide = float.Parse(stepIncrement);
}
UpdateMinMaxTweaks();

if (part.symmetryCounterparts.Count > 1)
{
foreach (Part counterPart in part.symmetryCounterparts)
{
((MuMechToggle) counterPart.Modules["MuMechToggle"]).rotateMin = rotateMin;
((MuMechToggle) counterPart.Modules["MuMechToggle"]).rotateMax = rotateMax;
((MuMechToggle) counterPart.Modules["MuMechToggle"]).stepIncrement = stepIncrement;
((MuMechToggle) counterPart.Modules["MuMechToggle"]).minTweak = minTweak;
((MuMechToggle) counterPart.Modules["MuMechToggle"]).maxTweak = maxTweak;
}
Expand Down Expand Up @@ -1339,18 +1304,17 @@ public void SaveConfigXml()
public void Move(float direction)
{
float deltaPos = direction * GetAxisInversion();
float pos = rotateJoint ? rotation : translation;

deltaPos *= Translator.GetSpeedUnit()*Time.deltaTime;

if (!rotateJoint || limitTweakableFlag)
{ // enforce limits
float limitPlus = maxTweak;
float limitMinus = minTweak;
if (pos + deltaPos > limitPlus)
deltaPos = limitPlus - pos;
else if (pos + deltaPos < limitMinus)
deltaPos = limitMinus - pos;
if (Position + deltaPos > limitPlus)
deltaPos = limitPlus - Position;
else if (Position + deltaPos < limitMinus)
deltaPos = limitMinus - Position;
}

ApplyDeltaPos(deltaPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ alphaCutoff = 0

// --- node definitions ---
node_attach = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0
node_stack_bottom = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0, 0
node_stack_top = 0.0, 0.325, 0.0, 0.0, 1.0, 0.0, 0
node_stack_bottom = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0, 2
node_stack_top = 0.0, 0.325, 0.0, 0.0, 1.0, 0.0, 2

MODEL
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ alphaCutoff = 0

// --- node definitions ---
node_attach = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0
node_stack_top = 0.0, 0.0, -0.325, 0.0, 0.0, -1.0, 0
node_stack_bottom = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0, 0
node_stack_top = 0.0, 0.0, -0.325, 0.0, 0.0, -1.0, 2
node_stack_bottom = 0.0, -0.254, 0.0 , 0.0, -1.0, 0.0, 2

MODEL
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ rescaleFactor=1.25
// --- node definitions ---
node_attach = 0.0, 0.0, 0.0, 0.0, -1.0, 0.0

node_stack_top = 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 0
node_stack_bottom = 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0
node_stack_top = 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 1
node_stack_bottom = 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1

// --- editor parameters ---
TechRequired = advConstruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scale = 1.0
// --- node definitions ---
node_attach = 0.0, 0.0, 0.0, 0.0, -1.0, 0.0

node_stack_top = 0.0, 0.7, 0.0, 0.0, 1.0, 0.0
node_stack_top = 0.0, 0.7, 0.0, 0.0, 1.0, 0.0, 2

// --- editor parameters ---
TechRequired = metaMaterials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ rimFalloff = 3
alphaCutoff = 0

// --- node definitions ---
node_stack_bottom = 0.0, -0.05, 0.0, 0.0, -1.0, 0.0, 0
node_stack_top = 0.0, 0.13, 0.0, 0.0, 1.0, 0.0, 0
node_stack_bottom = 0.0, -0.05, 0.0, 0.0, -1.0, 0.0, 1
node_stack_top = 0.0, 0.13, 0.0, 0.0, 1.0, 0.0, 1
node_attach = 0.0, -0.05, 0.0, 0.0, -1.0, 0.0, 0


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ title = Docking Washer Standard
manufacturer = Magic Smoke Industries
description = Motorized docking washer. HINT: The red spot designates the fixed base.
node_attach = 0.0, -0.035, 0.0 , 0.0, -1.0, 0.0
node_stack_bottom = 0.0, -0.0175, 0.0 , 0.0, -1.0, 0.0, 0
node_stack_top = 0.0, 0.0525, 0.0, 0.0, 1.0, 0.0, 0
node_stack_bottom = 0.0, -0.0175, 0.0 , 0.0, -1.0, 0.0, 1
node_stack_top = 0.0, 0.0525, 0.0, 0.0, 1.0, 0.0, 1
attachRules = 1,1,1,1,1

// --- standard part parameters ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ title = Docking Washer Standard (Free Moving)
manufacturer = Magic Smoke Industries
description = Free moving docking washer. Does NOT lock. Doesn't respond to motor control. Moves freely when a force is acted upon it. HINT: The red spot designates the fixed base.
node_attach = 0.0, -0.035, 0.0 , 0.0, -1.0, 0.0
node_stack_bottom = 0.0, -0.0175, 0.0 , 0.0, -1.0, 0.0, 0
node_stack_top = 0.0, 0.0525, 0.0, 0.0, 1.0, 0.0, 0
node_stack_bottom = 0.0, -0.0175, 0.0 , 0.0, -1.0, 0.0, 1
node_stack_top = 0.0, 0.0525, 0.0, 0.0, 1.0, 0.0, 1
attachRules = 1,1,1,1,1
// --- standard part parameters ---
Expand Down

0 comments on commit 1f14e94

Please sign in to comment.