Skip to content

Commit d8e8f31

Browse files
committed
editor: Add button to re-populate hardware.
1 parent 2be80d9 commit d8e8f31

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.IO;
1515
using UnityEditor;
1616
using UnityEngine;
17+
using VisualPinball.Unity;
1718
using VisualPinball.Unity.Editor;
1819

1920
namespace VisualPinball.Engine.Mpf.Unity.Editor
@@ -22,17 +23,29 @@ namespace VisualPinball.Engine.Mpf.Unity.Editor
2223
public class MpfGamelogicEngineInspector : UnityEditor.Editor
2324
{
2425
private MpfGamelogicEngine _mpfEngine;
26+
private TableAuthoring _tableAuthoring;
27+
2528
private bool _foldoutSwitches;
2629
private bool _foldoutCoils;
2730
private bool _foldoutLamps;
2831

32+
private bool HasData => _mpfEngine.AvailableSwitches.Length + _mpfEngine.AvailableCoils.Length + _mpfEngine.AvailableLamps.Length > 0;
33+
2934
private void OnEnable()
3035
{
3136
_mpfEngine = target as MpfGamelogicEngine;
37+
if (_mpfEngine != null) {
38+
_tableAuthoring = _mpfEngine.gameObject.GetComponentInParent<TableAuthoring>();
39+
}
3240
}
3341

3442
public override void OnInspectorGUI()
3543
{
44+
if (!_tableAuthoring) {
45+
EditorGUILayout.HelpBox($"Cannot find table. The gamelogic engine must be applied to a table object or one of its children.", MessageType.Error);
46+
return;
47+
}
48+
3649
var pos = EditorGUILayout.GetControlRect(true, 18f);
3750
pos = EditorGUI.PrefixLabel(pos, new GUIContent("Machine Folder"));
3851

@@ -43,7 +56,7 @@ public override void OnInspectorGUI()
4356
}
4457
}
4558

46-
if (GUILayout.Button("Synchronize")) {
59+
if (GUILayout.Button("Get Machine Description")) {
4760
if (!Directory.Exists(_mpfEngine.machineFolder)) {
4861
EditorUtility.DisplayDialog("Mission Pinball Framework", "Gotta choose a valid machine folder first!", "Okay");
4962
} else if (!Directory.Exists(Path.Combine(_mpfEngine.machineFolder, "config"))) {
@@ -53,6 +66,16 @@ public override void OnInspectorGUI()
5366
}
5467
}
5568

69+
EditorGUI.BeginDisabledGroup(!HasData);
70+
if (GUILayout.Button("Populate Hardware")) {
71+
if (EditorUtility.DisplayDialog("Mission Pinball Framework", "This will clear all linked switches, coils and lamps and re-populate them. You sure you want to do that?", "Yes", "No")) {
72+
_tableAuthoring.RepopulateHardware(_mpfEngine);
73+
SceneView.RepaintAll();
74+
}
75+
}
76+
EditorGUI.EndDisabledGroup();
77+
78+
5679
var naStyle = new GUIStyle(GUI.skin.label) {
5780
fontStyle = FontStyle.Italic
5881
};

0 commit comments

Comments
 (0)