17
17
using System . Linq ;
18
18
using System . Threading ;
19
19
using Grpc . Core ;
20
- using Mono . Cecil ;
21
20
using UnityEditor ;
22
21
using UnityEditor . UIElements ;
23
22
using UnityEngine ;
24
23
using UnityEngine . UIElements ;
24
+ using VisualPinball . Engine . Mpf . Unity . MediaController ;
25
25
using VisualPinball . Unity ;
26
26
27
27
namespace VisualPinball . Engine . Mpf . Unity . Editor
@@ -38,6 +38,9 @@ public class MpfGamelogicEngineInspector : UnityEditor.Editor
38
38
private PropertyField _connectDelayField ;
39
39
private VisualElement _commandLineOptionsContainer ;
40
40
private VisualElement _startupBehaviorOptionsContainer ;
41
+ private TextField _mpfStateField ;
42
+ private TextField _mediaControllerStateField ;
43
+ private VisualElement _bcpOptionsContainer ;
41
44
42
45
public override VisualElement CreateInspectorGUI ( )
43
46
{
@@ -63,12 +66,9 @@ public override VisualElement CreateInspectorGUI()
63
66
64
67
if ( ! string . IsNullOrWhiteSpace ( path ) )
65
68
{
66
- path = path . Replace ( "\\ " , "/" ) ;
67
- if ( path . Contains ( "StreamingAssets/" ) )
68
- path = "./StreamingAssets/" + path . Split ( "StreamingAssets/" ) [ 1 ] ;
69
-
69
+ path = MpfWranglerOptions . RealPathToSerializedPath ( path ) ;
70
70
var machineFolderProp = serializedObject . FindProperty (
71
- $ "_mpfWrangler ._machineFolder"
71
+ $ "_wranglerOptions ._machineFolder"
72
72
) ;
73
73
machineFolderProp . stringValue = path ;
74
74
serializedObject . ApplyModifiedProperties ( ) ;
@@ -77,21 +77,21 @@ public override VisualElement CreateInspectorGUI()
77
77
) ;
78
78
79
79
var getDescBtn = root . Q < Button > ( "get-machine-description" ) ;
80
- var optionsBox = root . Q < GroupBox > ( "options" ) ;
80
+ var optionsBox = root . Q < VisualElement > ( "options" ) ;
81
81
if ( Application . isPlaying )
82
82
getDescBtn . SetEnabled ( false ) ;
83
83
84
84
var getDescBtnDefaultText = getDescBtn . text ;
85
85
86
86
getDescBtn . clicked += async ( ) =>
87
87
{
88
- Undo . RecordObject ( _mpfEngine , "Get machine description" ) ;
89
- PrefabUtility . RecordPrefabInstancePropertyModifications ( _mpfEngine ) ;
90
88
if ( _getMachineDescCts == null )
91
89
{
92
- _getMachineDescCts = new CancellationTokenSource ( ) ;
90
+ Undo . RecordObject ( _mpfEngine , "Get machine description" ) ;
91
+ PrefabUtility . RecordPrefabInstancePropertyModifications ( _mpfEngine ) ;
93
92
getDescBtn . text = "Cancel" ;
94
93
optionsBox . SetEnabled ( false ) ;
94
+ _getMachineDescCts = new CancellationTokenSource ( ) ;
95
95
96
96
try
97
97
{
@@ -110,17 +110,15 @@ ex is RpcException exception
110
110
{
111
111
optionsBox . SetEnabled ( true ) ;
112
112
getDescBtn . text = getDescBtnDefaultText ;
113
+ getDescBtn . SetEnabled ( true ) ;
113
114
_getMachineDescCts ? . Dispose ( ) ;
114
115
_getMachineDescCts = null ;
115
116
}
116
117
}
117
118
else
118
119
{
120
+ getDescBtn . SetEnabled ( false ) ;
119
121
_getMachineDescCts ? . Cancel ( ) ;
120
- _getMachineDescCts ? . Dispose ( ) ;
121
- _getMachineDescCts = null ;
122
- optionsBox . SetEnabled ( true ) ;
123
- getDescBtn . text = getDescBtnDefaultText ;
124
122
}
125
123
} ;
126
124
@@ -133,7 +131,8 @@ ex is RpcException exception
133
131
if (
134
132
EditorUtility . DisplayDialog (
135
133
"Mission Pinball Framework" ,
136
- "This will clear all linked switches, coils and lamps and re-populate them. Are you sure you want to do that?" ,
134
+ "This will clear all linked switches, coils and lamps and re-populate "
135
+ + "them. Are you sure you want to do that?" ,
137
136
"Yes" ,
138
137
"No"
139
138
)
@@ -177,7 +176,7 @@ ex is RpcException exception
177
176
178
177
var startupBehaviorField = root . Q < PropertyField > ( "startup-behavior" ) ;
179
178
var startupBehaviorProp = serializedObject . FindProperty (
180
- "_mpfWrangler ._startupBehavior"
179
+ "_wranglerOptions ._startupBehavior"
181
180
) ;
182
181
_connectTimeoutField = root . Q < PropertyField > ( "connect-timeout" ) ;
183
182
_connectDelayField = root . Q < PropertyField > ( "connect-delay" ) ;
@@ -188,7 +187,7 @@ ex is RpcException exception
188
187
_commandLineOptionsContainer = root . Q < VisualElement > ( "command-line-options" ) ;
189
188
_startupBehaviorOptionsContainer = root . Q < VisualElement > ( "startup-behavior-options" ) ;
190
189
var executableSourceProp = serializedObject . FindProperty (
191
- "_mpfWrangler ._executableSource"
190
+ "_wranglerOptions ._executableSource"
192
191
) ;
193
192
OnExecutableSourceChanged ( executableSourceProp ) ;
194
193
_commandLineOptionsContainer . TrackPropertyValue (
@@ -198,11 +197,31 @@ ex is RpcException exception
198
197
199
198
MachineFolderValidationBoxes ( machineFolderField ) ;
200
199
200
+ _mpfStateField = root . Q < TextField > ( "mpf-state" ) ;
201
+ UpdateMpfStateField ( _mpfEngine . MpfState ) ;
202
+ _mpfEngine . MpfStateChanged += OnMpfStateChanged ;
203
+
204
+ _mediaControllerStateField = root . Q < TextField > ( "media-controller-state" ) ;
205
+ UpdateBcpStateField ( _mpfEngine . BcpState ) ;
206
+ _mpfEngine . BcpStateChanged += OnBcpStateChanged ;
207
+
208
+ _bcpOptionsContainer = root . Q < VisualElement > ( "bcp-options" ) ;
209
+ var mediaControllerProp = serializedObject . FindProperty (
210
+ "_wranglerOptions._mediaController"
211
+ ) ;
212
+ UpdateMediaControllerUiVisibility ( mediaControllerProp ) ;
213
+ _bcpOptionsContainer . TrackPropertyValue (
214
+ mediaControllerProp ,
215
+ UpdateMediaControllerUiVisibility
216
+ ) ;
217
+
201
218
return root ;
202
219
}
203
220
204
221
private void OnDisable ( )
205
222
{
223
+ _mpfEngine . MpfStateChanged -= OnMpfStateChanged ;
224
+ _mpfEngine . BcpStateChanged -= OnBcpStateChanged ;
206
225
_getMachineDescCts ? . Cancel ( ) ;
207
226
_getMachineDescCts ? . Dispose ( ) ;
208
227
_getMachineDescCts = null ;
@@ -259,9 +278,42 @@ private void UpdateGameItemList(VisualElement parent, IEnumerable<string> itemId
259
278
}
260
279
}
261
280
281
+ private void OnMpfStateChanged ( object sender , StateChangedEventArgs < MpfState > args )
282
+ {
283
+ UpdateMpfStateField ( args . CurrentState ) ;
284
+ }
285
+
286
+ private void UpdateMpfStateField ( MpfState state )
287
+ {
288
+ _mpfStateField . value = state . ToString ( ) ;
289
+ }
290
+
291
+ private void OnBcpStateChanged (
292
+ object sender ,
293
+ StateChangedEventArgs < BcpConnectionState > args
294
+ )
295
+ {
296
+ UpdateBcpStateField ( args . CurrentState ) ;
297
+ }
298
+
299
+ private void UpdateBcpStateField ( BcpConnectionState state )
300
+ {
301
+ _mediaControllerStateField . value = state . ToString ( ) ;
302
+ }
303
+
304
+ private void UpdateMediaControllerUiVisibility ( SerializedProperty mediaControllerProp )
305
+ {
306
+ var mediaController = ( MpfMediaController ) mediaControllerProp . enumValueIndex ;
307
+ var usingIncludedMediaController = mediaController == MpfMediaController . Included ;
308
+ _mediaControllerStateField . SetEnabled ( usingIncludedMediaController ) ;
309
+ _bcpOptionsContainer . SetEnabled ( usingIncludedMediaController ) ;
310
+ }
311
+
262
312
private void MachineFolderValidationBoxes ( VisualElement machineFolderField )
263
313
{
264
- var machineFolderProp = serializedObject . FindProperty ( $ "_mpfWrangler._machineFolder") ;
314
+ var machineFolderProp = serializedObject . FindProperty (
315
+ "_wranglerOptions._machineFolder"
316
+ ) ;
265
317
var notAMachineFolderErrorBox = new HelpBox (
266
318
"The machine folder is not valid. It must contain a folder called 'config' "
267
319
+ "with at least one .yaml file inside." ,
@@ -281,7 +333,9 @@ private void MachineFolderValidationBoxes(VisualElement machineFolderField)
281
333
282
334
void UpdateVisibility ( SerializedProperty _ )
283
335
{
284
- var machineFolder = _mpfEngine . MachineFolder ;
336
+ var options = ( MpfWranglerOptions )
337
+ serializedObject . FindProperty ( "_wranglerOptions" ) . boxedValue ;
338
+ var machineFolder = options . MachineFolder ;
285
339
var isMachineFolderInStreamingAssets = machineFolder . StartsWith (
286
340
Application . streamingAssetsPath
287
341
) ;
0 commit comments