Skip to content

Commit 79cdc48

Browse files
committed
misc: added Toggle Speed button to inspector
1 parent 6e7039a commit 79cdc48

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

VisualPinball.Engine.PinMAME.Unity/Editor/PinMameGamelogicEngineInspector.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ public override void OnInspectorGUI()
197197
EditorGUILayout.Space();
198198
EditorGUILayout.Separator();
199199

200+
if (Application.isPlaying) {
201+
if (GUILayout.Button("Toggle Speed")) {
202+
_gle.ToggleSpeed();
203+
}
204+
205+
EditorGUILayout.Space();
206+
EditorGUILayout.Separator();
207+
}
208+
200209
//EditorGUI.BeginDisabledGroup(!IsGameSet || Application.isPlaying);
201210
if (GUILayout.Button("Populate Hardware")) {
202211
if (EditorUtility.DisplayDialog("PinMAME", "This will clear all linked switches, coils and lamps and re-populate them. You sure you want to do that?", "Yes", "No")) {

VisualPinball.Engine.PinMAME.Unity/Runtime/PinMameGamelogicEngine.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public GamelogicEngineLamp[] RequestedLamps {
131131
private Dictionary<int, PinMameMechComponent> _registeredMechs = new();
132132
private HashSet<int> _mechSwitches = new();
133133

134+
private bool _toggleSpeed = false;
135+
134136
#endregion
135137

136138
#region Lifecycle
@@ -197,7 +199,7 @@ private void OnDestroy()
197199
_pinMame.OnMechAvailable -= OnMechAvailable;
198200
_pinMame.OnMechUpdated -= OnMechUpdated;
199201
_pinMame.OnSolenoidUpdated -= OnSolenoidUpdated;
200-
202+
_pinMame.IsKeyPressed -= IsKeyPressed;
201203
}
202204
_frameBuffer.Clear();
203205
_dmdLevels.Clear();
@@ -255,6 +257,8 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
255257
_pinMame.OnMechAvailable += OnMechAvailable;
256258
_pinMame.OnMechUpdated += OnMechUpdated;
257259
_pinMame.OnSolenoidUpdated += OnSolenoidUpdated;
260+
_pinMame.IsKeyPressed += IsKeyPressed;
261+
258262
_player = player;
259263

260264
_solenoidsEnabled = SolenoidDelay == 0;
@@ -267,6 +271,14 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
267271
}
268272
}
269273

274+
public void ToggleSpeed()
275+
{
276+
Logger.Info($"[PinMAME] Toggle speed.");
277+
278+
_pinMame.SetHandleKeyboard(true);
279+
_toggleSpeed = true;
280+
}
281+
270282
private void OnGameStarted()
271283
{
272284
Logger.Info($"[PinMAME] Game started.");
@@ -311,7 +323,7 @@ private void UpdateCaches()
311323

312324
#region Displays
313325

314-
private void OnDisplayRequested(int index, int displayCount, PinMameDisplayLayout displayLayout)
326+
private void OnDisplayRequested(int index, int displayCount, PinMameDisplayLayout displayLayout)
315327
{
316328
if (displayLayout.IsDmd) {
317329
lock (_dispatchQueue) {
@@ -433,7 +445,7 @@ public static DisplayFrameFormat GetDisplayFrameFormat(PinMameDisplayLayout layo
433445

434446
#region Audio
435447

436-
private int OnAudioAvailable(PinMameAudioInfo audioInfo)
448+
private int OnAudioAvailable(PinMameAudioInfo audioInfo)
437449
{
438450
Logger.Info("Game audio available: " + audioInfo);
439451

@@ -700,5 +712,20 @@ private void SendMechs()
700712
}
701713

702714
#endregion
715+
716+
private int IsKeyPressed(PinMameKeycode keycode)
717+
{
718+
if (keycode == PinMameKeycode.F10) {
719+
if (_toggleSpeed) {
720+
_toggleSpeed = false;
721+
722+
_pinMame.SetHandleKeyboard(false);
723+
724+
return 1;
725+
}
726+
}
727+
728+
return 0;
729+
}
703730
}
704731
}

0 commit comments

Comments
 (0)