Skip to content

Commit b52b8b0

Browse files
authored
Merge pull request #125 from ZiwKerman/develop
Basic KSP 1.2 Compatibility Update.
2 parents f0d8d68 + d6077f6 commit b52b8b0

File tree

9 files changed

+121
-76
lines changed

9 files changed

+121
-76
lines changed

InfernalRobotics/InfernalRobotics/Command/ServoController.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private void OnVesselChange(Vessel v)
286286
Logger.Log("[ServoController] OnVesselChange finished successfully", Logger.Level.Debug);
287287
}
288288

289-
private void OnVesselWasModified(Vessel v)
289+
private void OnVesselPartCountModified(Vessel v)
290290
{
291291
RebuildServoGroupsFlight ();
292292
}
@@ -312,7 +312,7 @@ private void Awake()
312312
if (scene == GameScenes.FLIGHT)
313313
{
314314
GameEvents.onVesselChange.Add(OnVesselChange);
315-
GameEvents.onVesselWasModified.Add(OnVesselWasModified);
315+
GameEvents.onVesselPartCountChanged.Add(OnVesselPartCountModified);
316316
GameEvents.onVesselLoaded.Add (OnVesselLoaded);
317317
GameEvents.onVesselDestroy.Add (OnVesselUnloaded);
318318
GameEvents.onVesselGoOnRails.Add (OnVesselUnloaded);
@@ -345,7 +345,16 @@ public static void SetWheelAutoStruts(bool value, Vessel v)
345345
if (!HighLogic.LoadedSceneIsFlight)
346346
return;
347347

348-
var activeVesselWheels = v.FindPartModulesImplementing<ModuleWheelBase>();
348+
/*foreach(var p in v.Parts)
349+
{
350+
if(!value)
351+
{
352+
p.autoStrutMode = Part.AutoStrutMode.Off;
353+
p.UpdateAutoStrut ();
354+
}
355+
}
356+
*/
357+
/*var activeVesselWheels = v.FindPartModulesImplementing<ModuleWheelBase>();
349358
foreach(var mwb in activeVesselWheels)
350359
{
351360
if (value)
@@ -358,7 +367,7 @@ public static void SetWheelAutoStruts(bool value, Vessel v)
358367
359368
mwb.autoStrut = value;
360369
361-
}
370+
}*/
362371
}
363372

364373

@@ -407,7 +416,7 @@ private void OnDestroy()
407416
GameEvents.onVesselChange.Remove(OnVesselChange);
408417
GameEvents.onPartAttach.Remove(OnPartAttach);
409418
GameEvents.onPartRemove.Remove(OnPartRemove);
410-
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);
419+
GameEvents.onVesselWasModified.Remove(OnVesselPartCountModified);
411420
GameEvents.onEditorShipModified.Remove(OnEditorShipModified);
412421
GameEvents.onEditorLoad.Remove(OnEditorLoad);
413422
GameEvents.onEditorRestart.Remove(OnEditorRestart);

InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void Save(bool symmetry = false)
6666
}
6767
module.presetPositionsSerialized = rawServo.presetPositionsSerialized;
6868
module.ParsePresetPositions();
69+
module.defaultPosition = rawServo.defaultPosition; //force sync the default position as well
6970
}
7071
}
7172
}

InfernalRobotics/InfernalRobotics/Gui/EditorCategory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void Awake()
2222
private void IRCustomFilter()
2323
{
2424
const string FILTER_CATEGORY = "Filter by Function";
25-
const string CUSTOM_CATEGORY_NAME = "Robotic Parts";
25+
const string CUSTOM_CATEGORY_NAME = "Robotic";
2626

2727
//var texture_on = new Texture2D(36, 36, TextureFormat.RGBA32, false);
2828
//var texture_off = new Texture2D(36, 36, TextureFormat.RGBA32, false);

InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/IRBuildAidManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class IRBuildAidManager : MonoBehaviour
1717

1818
public static Color endPoint1Color = new Color(1f, 1f, 0, 0.5f);
1919
public static Color endPoint2Color = new Color(1f, 1f, 0, 0.5f);
20-
public static Color mainLineColor1 = new Color(1f, 0.85f, 0, 0.5f);
21-
public static Color mainLineColor2 = new Color(0.85f, 1f, 0, 0.5f);
20+
public static Color mainLineColor1 = new Color(0.88f, 0.7f, 0.188f, 0.7f);
21+
public static Color mainLineColor2 = new Color(0.7f, 0.5f, 0, 0.5f);
2222
public static Color presetPositionsColor = new Color(1f, 1f, 1f, 0.5f);
2323

2424
public static Color currentPositionColor = new Color(0f, 1f, 0f, 0.5f);

InfernalRobotics/InfernalRobotics/Gui/ServoDropHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void onServoDrop(ServoDragHandler dragHandler)
4343

4444
var newGroupIndex = dragHandler.dropZone.parent.GetSiblingIndex();
4545
ServoController.MoveServo(ServoController.Instance.ServoGroups[oldGroupIndex], ServoController.Instance.ServoGroups[newGroupIndex], s);
46+
WindowManager.guiRebuildPending = true;
4647
break;
4748
}
4849
}

InfernalRobotics/InfernalRobotics/Gui/UIAssetsLoader.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,6 @@ private void LoadBundleAssets()
162162

163163
}
164164

165-
public void LoadBundleFromDisk(string path)
166-
{
167-
IRAssetBundle = AssetBundle.CreateFromFile(path);
168-
169-
LoadBundleAssets();
170-
171-
//had to move bundle unloading further down in time due to unexplained and unreproducable on my PC issues for some users
172-
//IRAssetBundle.Unload(false);
173-
}
174-
175165
public void Start()
176166
{
177167
var assemblyFile = Assembly.GetExecutingAssembly().Location;

InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,17 @@ private void InitFlightControlWindow(bool startSolid = true)
406406
foreach(var pair in _servoGroupUIControls)
407407
{
408408
pair.Key.Stop();
409-
pair.Key.MovingNegative = false;
410-
pair.Key.MovingPositive = false;
411409
}
412410
guiRebuildPending = true;
413411
//TODO: we need to reset oll Movement Toggles
414412
});
415413

416414
var stopAllTooltip = stopAllButton.gameObject.AddComponent<BasicTooltip>();
417415
stopAllTooltip.tooltipText = "Panic! Stop all servos!";
416+
417+
//toggle preset mode if needed
418+
ToggleFlightPresetMode (guiFlightPresetModeOn);
419+
418420
}
419421

420422
private void InitFlightGroupControls(GameObject newServoGroupLine, ServoController.ControlGroup g)
@@ -452,19 +454,10 @@ private void InitFlightGroupControls(GameObject newServoGroupLine, ServoControll
452454
groupMoveLeftToggle.isOn = g.MovingNegative;
453455
groupMoveLeftToggle.onValueChanged.AddListener(v =>
454456
{
455-
if (g.MovingNegative)
456-
{
457-
g.Stop();
458-
g.MovingNegative = false;
459-
g.MovingPositive = false;
460-
}
461-
else
462-
{
463-
if(g.MovingPositive)
464-
{
465-
hlg.GetChild("ServoGroupMoveRightToggleButton").GetComponent<Toggle>().isOn = false;
466-
}
467-
g.MoveLeft();
457+
g.Stop ();
458+
if (v) {
459+
hlg.GetChild ("ServoGroupMoveRightToggleButton").GetComponent<Toggle> ().isOn = false;
460+
g.MoveLeft ();
468461
g.MovingNegative = true;
469462
g.MovingPositive = false;
470463
}
@@ -500,18 +493,10 @@ private void InitFlightGroupControls(GameObject newServoGroupLine, ServoControll
500493
groupMoveRightToggle.isOn = g.MovingPositive;
501494
groupMoveRightToggle.onValueChanged.AddListener(v =>
502495
{
503-
if (g.MovingPositive)
504-
{
505-
g.Stop();
506-
g.MovingNegative = false;
507-
g.MovingPositive = false;
508-
}
509-
else
496+
g.Stop();
497+
if (v)
510498
{
511-
if (g.MovingNegative)
512-
{
513-
hlg.GetChild("ServoGroupMoveLeftToggleButton").GetComponent<Toggle>().isOn = false;
514-
}
499+
hlg.GetChild ("ServoGroupMoveLeftToggleButton").GetComponent<Toggle> ().isOn = false;
515500
g.MoveRight();
516501
g.MovingNegative = false;
517502
g.MovingPositive = true;
@@ -679,7 +664,7 @@ private void ToggleFlightPresetMode(bool value)
679664
}
680665
}
681666

682-
public void PresetInputOnEndEdit(string tmp, int i)
667+
public void PresetInputOnEndEdit(string tmp, int i, GameObject buttonRef = null)
683668
{
684669
if (presetWindowServo == null)
685670
return;
@@ -694,6 +679,7 @@ public void PresetInputOnEndEdit(string tmp, int i)
694679
}
695680
presetWindowServo.Preset[i] = tmpValue;
696681
presetWindowServo.Preset.Sort();
682+
TogglePresetEditWindow (presetWindowServo, true, buttonRef);
697683
}
698684
}
699685

@@ -731,7 +717,7 @@ public void TogglePresetEditWindow (IServo servo, bool value, GameObject buttonR
731717
//need a better way to tie them to each other
732718
_presetsWindow.transform.SetParent(UIMasterController.Instance.appCanvas.transform, false);
733719

734-
if (_presetsWindowPosition == Vector3.zero)
720+
if (_presetsWindowPosition == Vector3.zero && buttonRef != null)
735721
_presetsWindow.transform.position = buttonRef.transform.position + new Vector3(30, 0, 0);
736722
else
737723
_presetsWindow.transform.position = ClampWindowPosition(_presetsWindowPosition);
@@ -743,19 +729,33 @@ public void TogglePresetEditWindow (IServo servo, bool value, GameObject buttonR
743729
{
744730
closeButton.GetComponent<Button>().onClick.AddListener(() => {
745731
TogglePresetEditWindow(servo, false, buttonRef);
746-
buttonRef.GetComponent<Toggle>().isOn = false;
732+
if(buttonRef!= null)
733+
buttonRef.GetComponent<Toggle>().isOn = false;
734+
else
735+
{
736+
foreach (var pair in _servoUIControls) {
737+
var toggle = pair.Value.GetChild ("ServoOpenPresetsToggle");
738+
if (toggle == null)
739+
continue;
740+
toggle.GetComponent<Toggle> ().isOn = false;
741+
}
742+
}
747743
});
748744
var t = closeButton.AddComponent<BasicTooltip>();
749745
t.tooltipText = "Close preset window";
750746
}
751747

752748
var footerControls = _presetsWindow.GetChild("WindowFooter").GetChild("WindowFooterButtonsHLG");
749+
753750
var newPresetPositionInputField = footerControls.GetChild("NewPresetPositionInputField").GetComponent<InputField>();
754751
newPresetPositionInputField.text = string.Format("{0:#0.##}", servo.Mechanism.Position);
755752

756753
var addPresetButton = footerControls.GetChild("AddPresetButton").GetComponent<Button>();
757754
addPresetButton.onClick.AddListener(() =>
758755
{
756+
footerControls = _presetsWindow.GetChild ("WindowFooter").GetChild ("WindowFooterButtonsHLG");
757+
newPresetPositionInputField = footerControls.GetChild ("NewPresetPositionInputField").GetComponent<InputField> ();
758+
759759
string tmp = newPresetPositionInputField.text;
760760
float tmpValue = 0f;
761761
if (float.TryParse(tmp, out tmpValue))
@@ -787,7 +787,7 @@ public void TogglePresetEditWindow (IServo servo, bool value, GameObject buttonR
787787
var presetPositionInputField = newPresetLine.GetChild("PresetPositionInputField").GetComponent<InputField>();
788788
presetPositionInputField.text = string.Format("{0:#0.##}", servo.Preset[i]);
789789
var presetIndex = i;
790-
presetPositionInputField.onEndEdit.AddListener(tmp => PresetInputOnEndEdit(tmp, presetIndex));
790+
presetPositionInputField.onEndEdit.AddListener(tmp => PresetInputOnEndEdit(tmp, presetIndex, buttonRef));
791791

792792
var servoDefaultPositionToggle = newPresetLine.GetChild("PresetDefaultPositionToggle").GetComponent<Toggle>();
793793
servoDefaultPositionToggle.group = presetsArea.GetComponent<ToggleGroup>();
@@ -937,6 +937,8 @@ private void InitEditorWindow(bool startSolid = true)
937937
InitEditorGroupControls(newServoGroupLine, g);
938938

939939
_servoGroupUIControls.Add(g, newServoGroupLine);
940+
941+
guiRebuildPending = true;
940942
});
941943

942944
var addGroupTooltip = addGroupButton.gameObject.AddComponent<BasicTooltip>();
@@ -1075,16 +1077,23 @@ private void InitEditorGroupControls(GameObject newServoGroupLine, ServoControll
10751077
while (g.Servos.Any())
10761078
{
10771079
var s = g.Servos.First();
1078-
ServoController.MoveServo(g, ServoController.Instance.ServoGroups[0], s);
1080+
if(g != ServoController.Instance.ServoGroups[0])
1081+
ServoController.MoveServo(g, ServoController.Instance.ServoGroups[0], s);
1082+
else
1083+
ServoController.MoveServo (g, ServoController.Instance.ServoGroups [1], s);
10791084
}
1080-
10811085
ServoController.Instance.ServoGroups.Remove(g);
1082-
1086+
g = null;
10831087
RebuildUI();
1088+
return;
10841089
}
10851090
});
10861091
if (ServoController.Instance.ServoGroups.Count < 2)
1092+
{
10871093
groupDeleteButton.interactable = false;
1094+
groupDeleteButton.gameObject.SetActive (false);
1095+
}
1096+
10881097

10891098
var groupDeleteButtonTooltip = groupDeleteButton.gameObject.AddComponent<BasicTooltip>();
10901099
groupDeleteButtonTooltip.tooltipText = "Delete Group";
@@ -1379,6 +1388,8 @@ public void MoveServoToPrevGroup(GameObject servoLine, IServo s)
13791388
//later consider puting animation here, for now just change parents
13801389
ServoController.MoveServo(ServoController.Instance.ServoGroups[currentGroupIndex], ServoController.Instance.ServoGroups[currentGroupIndex - 1], s);
13811390
servoUIControls.transform.SetParent(prevGroupUIControls.GetChild("ServoGroupServosVLG").transform, false);
1391+
1392+
guiRebuildPending = true;
13821393
}
13831394

13841395
public void MoveServoToNextGroup(GameObject servoLine, IServo s)
@@ -1403,6 +1414,8 @@ public void MoveServoToNextGroup(GameObject servoLine, IServo s)
14031414
//later consider puting animation here, for now just change parents
14041415
ServoController.MoveServo(ServoController.Instance.ServoGroups[currentGroupIndex], ServoController.Instance.ServoGroups[currentGroupIndex + 1], s);
14051416
servoUIControls.transform.SetParent(nextGroupUIControls.GetChild("ServoGroupServosVLG").transform, false);
1417+
1418+
guiRebuildPending = true;
14061419
}
14071420
public void ShowServoAdvancedMode(IServo servo, bool value)
14081421
{
@@ -1534,6 +1547,19 @@ public void UpdateServoReadoutsFlight(IServo s, GameObject servoUIControls)
15341547

15351548
}
15361549

1550+
public void UpdateGroupReadoutsFlight (ServoController.ControlGroup g, GameObject groupUIControls)
1551+
{
1552+
1553+
foreach (var t in groupUIControls.GetComponentsInChildren<Toggle> ())
1554+
{
1555+
if (t.gameObject.name == "ServoGroupMoveLeftToggleButton")
1556+
t.isOn = g.MovingNegative;
1557+
else if (t.gameObject.name == "ServoGroupMoveRightToggleButton")
1558+
t.isOn = g.MovingPositive;
1559+
}
1560+
1561+
}
1562+
15371563
public void UpdateServoReadoutsEditor(IServo s, GameObject servoUIControls)
15381564
{
15391565
var servoPosition = servoUIControls.GetChild("ServoPositionInputField").GetComponent<InputField>();
@@ -1687,13 +1713,15 @@ public void Update()
16871713
return;
16881714

16891715
if(EventSystem.current.currentSelectedGameObject != null &&
1690-
(EventSystem.current.currentSelectedGameObject.name == "GroupNameInputField"
1691-
|| EventSystem.current.currentSelectedGameObject.name == "GroupMoveLeftKey"
1692-
|| EventSystem.current.currentSelectedGameObject.name == "GroupMoveRightKey"
1693-
|| EventSystem.current.currentSelectedGameObject.name == "ServoNameInputField"
1694-
|| EventSystem.current.currentSelectedGameObject.name == "ServoPositionInputField"
1695-
|| EventSystem.current.currentSelectedGameObject.name == "NewGroupNameInputField"
1696-
|| EventSystem.current.currentSelectedGameObject.name == "ServoGroupSpeedMultiplier"))
1716+
(EventSystem.current.currentSelectedGameObject.GetComponent<InputField>() != null
1717+
|| EventSystem.current.currentSelectedGameObject.GetType() == typeof(InputField)) /*
1718+
(EventSystem.current.currentSelectedGameObject.name == "GroupNameInputField"
1719+
|| EventSystem.current.currentSelectedGameObject.name == "GroupMoveLeftKey"
1720+
|| EventSystem.current.currentSelectedGameObject.name == "GroupMoveRightKey"
1721+
|| EventSystem.current.currentSelectedGameObject.name == "ServoNameInputField"
1722+
|| EventSystem.current.currentSelectedGameObject.name == "ServoPositionInputField"
1723+
|| EventSystem.current.currentSelectedGameObject.name == "NewGroupNameInputField"
1724+
|| EventSystem.current.currentSelectedGameObject.name == "ServoGroupSpeedMultiplier")*/)
16971725
{
16981726
if(!isKeyboardLocked)
16991727
KeyboardLock(true);
@@ -1720,6 +1748,13 @@ public void Update()
17201748
continue;
17211749
UpdateServoReadoutsFlight(pair.Key, pair.Value);
17221750
}
1751+
1752+
foreach (var pair in _servoGroupUIControls)
1753+
{
1754+
if (!pair.Value.activeInHierarchy)
1755+
continue;
1756+
UpdateGroupReadoutsFlight (pair.Key, pair.Value);
1757+
}
17231758
}
17241759
else
17251760
{

InfernalRobotics/InfernalRobotics/InfernalRobotics.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
<HintPath>..\..\..\KSP_LIB\Assembly-CSharp-firstpass.dll</HintPath>
3535
</Reference>
3636
<Reference Include="System" />
37-
<Reference Include="System.Core" />
38-
<Reference Include="System.Xml.Linq" />
39-
<Reference Include="System.Data.DataSetExtensions" />
4037
<Reference Include="System.Data" />
4138
<Reference Include="System.Xml" />
4239
<Reference Include="Assembly-CSharp">
@@ -51,12 +48,6 @@
5148
<Reference Include="KSPAssets">
5249
<HintPath>..\..\..\KSP_LIB\KSPAssets.dll</HintPath>
5350
</Reference>
54-
<Reference Include="KSPCore">
55-
<HintPath>..\..\..\KSP_LIB\KSPCore.dll</HintPath>
56-
</Reference>
57-
<Reference Include="KSPUtil">
58-
<HintPath>..\..\..\KSP_LIB\KSPUtil.dll</HintPath>
59-
</Reference>
6051
<Reference Include="UnityEngine.UI">
6152
<HintPath>..\..\..\KSP_LIB\UnityEngine.UI.dll</HintPath>
6253
</Reference>

0 commit comments

Comments
 (0)