Skip to content

Commit 1e1bc6e

Browse files
jsm174freezy
authored andcommitted
misc: added ClearDisplayUnit
1 parent 5403fd9 commit 1e1bc6e

File tree

8 files changed

+176
-2
lines changed

8 files changed

+176
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
// ReSharper disable UnusedType.Global
18+
19+
using Unity.VisualScripting;
20+
using VisualPinball.Unity.Editor;
21+
using IconSize = VisualPinball.Unity.Editor.IconSize;
22+
23+
namespace VisualPinball.Unity.VisualScripting.Editor
24+
{
25+
[Descriptor(typeof(ClearDisplayUnit))]
26+
public class ClearDisplayUnitDescriptor : UnitDescriptor<ClearDisplayUnit>
27+
{
28+
public ClearDisplayUnitDescriptor(ClearDisplayUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node clears a display connected through the given ID.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay);
38+
}
39+
}

Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
// ReSharper disable UnusedType.Global
18+
19+
using Unity.VisualScripting;
20+
21+
namespace VisualPinball.Unity.VisualScripting.Editor
22+
{
23+
[Widget(typeof(ClearDisplayUnit))]
24+
public sealed class ClearDisplayUnitWidget : GleUnitWidget<ClearDisplayUnit>
25+
{
26+
public ClearDisplayUnitWidget(FlowCanvas canvas, ClearDisplayUnit unit) : base(canvas, unit)
27+
{
28+
}
29+
}
30+
}

Editor/Widgets/ClearDisplayUnitWidget.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I
6464
public GamelogicEngineWire[] AvailableWires => Wires;
6565

6666
public event EventHandler<RequestedDisplays> OnDisplaysRequested;
67+
public event EventHandler<DisplayClearData> OnDisplayClear;
6768
public event EventHandler<DisplayFrameData> OnDisplayUpdateFrame;
6869
public event EventHandler<DisplayAddPointsData> OnDisplayAddPoints;
6970

@@ -156,6 +157,11 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
156157
EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty);
157158
}
158159

160+
public void DisplayClear(DisplayClearData data)
161+
{
162+
OnDisplayClear?.Invoke(this, data);
163+
}
164+
159165
public void DisplayUpdateFrame(DisplayFrameData data)
160166
{
161167
OnDisplayUpdateFrame?.Invoke(this, data);
@@ -166,9 +172,9 @@ public void DisplayAddPoints(DisplayAddPointsData data)
166172
OnDisplayAddPoints?.Invoke(this, data);
167173
}
168174

169-
public void DisplayScoreEvent(string id, float score)
175+
public void DisplayScoreEvent(string id, float points, float score)
170176
{
171-
EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, score));
177+
EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, points, score));
172178
}
173179

174180
public void Switch(string id, bool isClosed)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using System;
18+
using System.Text;
19+
using Unity.VisualScripting;
20+
21+
namespace VisualPinball.Unity.VisualScripting
22+
{
23+
[UnitTitle("Clear Display")]
24+
[UnitSurtitle("Gamelogic Engine")]
25+
[UnitCategory("Visual Pinball")]
26+
public class ClearDisplayUnit : GleUnit
27+
{
28+
[Serialize, Inspectable, UnitHeaderInspectable("ID")]
29+
public DisplayDefinition Display { get; private set; }
30+
31+
[DoNotSerialize]
32+
[PortLabelHidden]
33+
public ControlInput InputTrigger;
34+
35+
[DoNotSerialize]
36+
[PortLabelHidden]
37+
public ControlOutput OutputTrigger;
38+
39+
protected override void Definition()
40+
{
41+
InputTrigger = ControlInput(nameof(InputTrigger), Process);
42+
OutputTrigger = ControlOutput(nameof(OutputTrigger));
43+
44+
Succession(InputTrigger, OutputTrigger);
45+
}
46+
47+
private ControlOutput Process(Flow flow)
48+
{
49+
if (!AssertVsGle(flow)) {
50+
throw new InvalidOperationException("Cannot retrieve GLE from unit.");
51+
}
52+
53+
if (Display != null) {
54+
VsGle.DisplayClear(new DisplayClearData(Display.Id));
55+
}
56+
57+
return OutputTrigger;
58+
}
59+
}
60+
}

Runtime/Nodes/Display/ClearDisplayUnit.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Nodes/Display/DisplayScoreEventUnit.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class DisplayScoreEventUnit : GleEventUnit<DisplayScoreEventArgs>
3232
[DisplayTypeFilterAttribute(DisplayType.ScoreReel)]
3333
public DisplayDefinition Display { get; private set; }
3434

35+
[DoNotSerialize]
36+
[PortLabel("Points")]
37+
public ValueOutput Points { get; private set; }
38+
3539
[DoNotSerialize]
3640
[PortLabel("Score")]
3741
public ValueOutput Score { get; private set; }
@@ -45,6 +49,7 @@ protected override void Definition()
4549
{
4650
base.Definition();
4751

52+
Points = ValueOutput<float>(nameof(Points));
4853
Score = ValueOutput<float>(nameof(Score));
4954
}
5055

@@ -55,6 +60,7 @@ protected override bool ShouldTrigger(Flow flow, DisplayScoreEventArgs args)
5560

5661
protected override void AssignArguments(Flow flow, DisplayScoreEventArgs args)
5762
{
63+
flow.SetValue(Points, args.Points);
5864
flow.SetValue(Score, args.Score);
5965
}
6066
}

0 commit comments

Comments
 (0)