Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,5 @@ MigrationBackup/

# Vi swap files
*.swp

.DS_Store
39 changes: 39 additions & 0 deletions Editor/Descriptors/ClearDisplayUnitDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// ReSharper disable UnusedType.Global

using Unity.VisualScripting;
using VisualPinball.Unity.Editor;
using IconSize = VisualPinball.Unity.Editor.IconSize;

namespace VisualPinball.Unity.VisualScripting.Editor
{
[Descriptor(typeof(ClearDisplayUnit))]
public class ClearDisplayUnitDescriptor : UnitDescriptor<ClearDisplayUnit>
{
public ClearDisplayUnitDescriptor(ClearDisplayUnit target) : base(target)
{
}

protected override string DefinedSummary()
{
return "This node clears a display connected through the given ID.";
}

protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay);
}
}
11 changes: 11 additions & 0 deletions Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Editor/Descriptors/DisplayEventUnitDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// ReSharper disable UnusedType.Global

using Unity.VisualScripting;

namespace VisualPinball.Unity.VisualScripting.Editor
{
[Descriptor(typeof(DisplayEventUnit))]
public class DisplayEventUnitDescriptor : UnitDescriptor<DisplayEventUnit>
{
public DisplayEventUnitDescriptor(DisplayEventUnit target) : base(target) { }

protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.DisplayEvent);

protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
{
base.DefinedPort(port, desc);

switch (port.key)
{
case nameof(DisplayEventUnit.NumericOutput):
desc.summary = "The numerical value of the display event.";
break;
case nameof(DisplayEventUnit.TextOutput):
desc.summary = "The text value of the display event.";
break;
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/Descriptors/DisplayEventUnitDescriptor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Editor/Descriptors/UpdateDisplayUnitDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
// ReSharper disable UnusedType.Global

using Unity.VisualScripting;
using VisualPinball.Unity.Editor;
using IconSize = VisualPinball.Unity.Editor.IconSize;

namespace VisualPinball.Unity.VisualScripting.Editor
{
Expand Down
1 change: 1 addition & 0 deletions Editor/Inspectors/DisplayDefinitionInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected override void OnGUI(Rect position, GUIContent label)
var varNames = new List<string> { "None" }
.Concat(gle.Displays.Select(d => d.Id))
.ToArray();

var currentDisplayDef = metadata.value as DisplayDefinition;
var currentIndex = 0;
if (currentDisplayDef != null) {
Expand Down
30 changes: 30 additions & 0 deletions Editor/Widgets/ClearDisplayUnitWidget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// ReSharper disable UnusedType.Global

using Unity.VisualScripting;

namespace VisualPinball.Unity.VisualScripting.Editor
{
[Widget(typeof(ClearDisplayUnit))]
public sealed class ClearDisplayUnitWidget : GleUnitWidget<ClearDisplayUnit>
{
public ClearDisplayUnitWidget(FlowCanvas canvas, ClearDisplayUnit unit) : base(canvas, unit)
{
}
}
}
11 changes: 11 additions & 0 deletions Editor/Widgets/ClearDisplayUnitWidget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Editor/Widgets/DisplayEventUnitWidget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// ReSharper disable UnusedType.Global

using Unity.VisualScripting;

namespace VisualPinball.Unity.VisualScripting.Editor
{
[Widget(typeof(DisplayEventUnit))]
public sealed class DisplayEventUnitWidget : GleUnitWidget<DisplayEventUnit>
{
public DisplayEventUnitWidget(FlowCanvas canvas, DisplayEventUnit unit) : base(canvas, unit)
{
}
}
}
11 changes: 11 additions & 0 deletions Editor/Widgets/DisplayEventUnitWidget.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Runtime/Gamelogic/VisualScriptingEventNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class VisualScriptingEventNames
public const string LampEvent = "LampEvent";
public const string SwitchEvent = "SwitchEvent";
public const string CoilEvent = "CoilEvent";
public const string DisplayChangedEvent = "DisplayChangedEvent";
public const string CurrentPlayerChanged = "CurrentPlayerChanged";
public const string PlayerVariableChanged = "PlayerVariableChanged";
public const string TableVariableChanged = "TableVariableChanged";
Expand Down
26 changes: 19 additions & 7 deletions Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I
public GamelogicEngineWire[] AvailableWires => Wires;

public event EventHandler<RequestedDisplays> OnDisplaysRequested;
public event EventHandler<DisplayFrameData> OnDisplayFrame;
public event EventHandler<string> OnDisplayClear;
public event EventHandler<DisplayFrameData> OnDisplayUpdateFrame;
public event EventHandler<DisplayFrameData> OnDisplayUpdated;

public event EventHandler<LampEventArgs> OnLampChanged;
public event EventHandler<LampsEventArgs> OnLampsChanged;
public event EventHandler<CoilEventArgs> OnCoilChanged;
Expand All @@ -87,11 +90,6 @@ public PlayerState CurrentPlayerState {
}
}

public void DisplayFrame(DisplayFrameData data)
{
OnDisplayFrame?.Invoke(this, data);
}

public void SetCurrentPlayer(int value, bool forceNotify = false)
{
if (!PlayerStates.ContainsKey(value)) {
Expand Down Expand Up @@ -159,6 +157,16 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty);
}

public void DisplayClear(string id)
{
OnDisplayClear?.Invoke(this, id);
}

public void DisplayUpdateFrame(DisplayFrameData data)
{
OnDisplayUpdateFrame?.Invoke(this, data);
}

public void Switch(string id, bool isClosed)
{
var args = new SwitchEventArgs2(id, isClosed);
Expand All @@ -178,6 +186,11 @@ public void SetLamp(string id, float value, bool isCoil = false, LampSource sour
OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source));
}

public void DisplayChanged(DisplayFrameData data)
{
EventBus.Trigger(VisualScriptingEventNames.DisplayChangedEvent, new DisplayChangedEventArgs(data));
}

public LampState GetLamp(string id)
{
return _player.LampStatuses.ContainsKey(id) ? _player.LampStatuses[id] : LampState.Default;
Expand All @@ -193,7 +206,6 @@ public bool GetCoil(string id)
return _player.CoilStatuses.ContainsKey(id) && _player.CoilStatuses[id];
}


public void OnBeforeSerialize()
{
#if UNITY_EDITOR
Expand Down
60 changes: 60 additions & 0 deletions Runtime/Nodes/Display/ClearDisplayUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Text;
using Unity.VisualScripting;

namespace VisualPinball.Unity.VisualScripting
{
[UnitTitle("Clear Display")]
[UnitSurtitle("Gamelogic Engine")]
[UnitCategory("Visual Pinball")]
public class ClearDisplayUnit : GleUnit
{
[Serialize, Inspectable, UnitHeaderInspectable("ID")]
public DisplayDefinition Display { get; private set; }

[DoNotSerialize]
[PortLabelHidden]
public ControlInput InputTrigger;

[DoNotSerialize]
[PortLabelHidden]
public ControlOutput OutputTrigger;

protected override void Definition()
{
InputTrigger = ControlInput(nameof(InputTrigger), Process);
OutputTrigger = ControlOutput(nameof(OutputTrigger));

Succession(InputTrigger, OutputTrigger);
}

private ControlOutput Process(Flow flow)
{
if (!AssertVsGle(flow)) {
throw new InvalidOperationException("Cannot retrieve GLE from unit.");
}

if (Display != null) {
VsGle.DisplayClear(Display.Id);
}

return OutputTrigger;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Nodes/Display/ClearDisplayUnit.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading