Skip to content

Commit 3ca62e4

Browse files
committed
Refactor SetLight node. Only takes in one light for now.
1 parent 868908e commit 3ca62e4

File tree

14 files changed

+235
-32
lines changed

14 files changed

+235
-32
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 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(SetLightUnit))]
26+
public class SetLightUnitDescriptor : UnitDescriptor<SetLightUnit>
27+
{
28+
public SetLightUnitDescriptor(SetLightUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node assigns a given value to a light or light group in the scene. \n\nNote that this doesn't pass through the gamelogic engine, thus no event will be triggered. However, it allows you to drive non-mapped lights as well.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.Light(IconSize.Large, IconColor.Orange));
38+
39+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
40+
{
41+
base.DefinedPort(port, desc);
42+
43+
switch (port.key) {
44+
case nameof(SetLightUnit.LampComponent):
45+
desc.summary = "The light component whose value you want to change. Assigning a light group will change all lights in the group.";
46+
break;
47+
48+
case nameof(SetLightUnit.Value):
49+
desc.summary = "The intensity to apply (0-1).";
50+
break;
51+
52+
case nameof(SetLightUnit.ColorChannel):
53+
desc.summary = "Which color channel to use. For non-RGB lights, use alpha.";
54+
break;
55+
}
56+
}
57+
}
58+
}

Editor/Descriptors/SetLightUnitDescriptor.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.

Editor/Inspectors.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 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 Unity.VisualScripting;
18+
using UnityEditor;
19+
using UnityEngine;
20+
using VisualPinball.Unity.Editor;
21+
22+
namespace VisualPinball.Unity.VisualScripting.Editor
23+
{
24+
public class ObjectPickerInspector<T> : Inspector where T: class, IIdentifiableItemComponent
25+
{
26+
private readonly ObjectReferencePicker<T> _devicePicker;
27+
28+
public ObjectPickerInspector(Metadata metadata, string title, TableComponent tableComponent) : base(metadata)
29+
{
30+
_devicePicker = new ObjectReferencePicker<T>(title, tableComponent, true);
31+
}
32+
33+
protected override float GetHeight(float width, GUIContent label) => EditorGUIUtility.singleLineHeight;
34+
35+
protected override void OnGUI(Rect position, GUIContent label)
36+
{
37+
position = BeginLabeledBlock(metadata, position, label);
38+
_devicePicker.Render(position, (T)metadata.value, component => {
39+
if (EndBlock(metadata)) {
40+
metadata.RecordUndo();
41+
metadata.value = component;
42+
}
43+
});
44+
}
45+
}
46+
}

Editor/Inspectors/ObjectPickerInspector.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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 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 System;
20+
using Unity.VisualScripting;
21+
22+
namespace VisualPinball.Unity.VisualScripting.Editor
23+
{
24+
[Widget(typeof(SetLightUnit))]
25+
public sealed class SetLightUnitWidget : UnitWidget<SetLightUnit>
26+
{
27+
private ObjectPickerInspector<ILampDeviceComponent> _objectInspector;
28+
private readonly Func<Metadata, ObjectPickerInspector<ILampDeviceComponent>> _setObjectInspectorConstructor;
29+
30+
public SetLightUnitWidget(FlowCanvas canvas, SetLightUnit unit) : base(canvas, unit)
31+
{
32+
var tc = reference.gameObject.GetComponentInParent<TableComponent>();
33+
_setObjectInspectorConstructor = meta => new ObjectPickerInspector<ILampDeviceComponent>(meta, "Lamps", tc);
34+
}
35+
36+
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
37+
{
38+
if (port == unit.LampComponent) {
39+
InspectorProvider.instance.Renew(ref _objectInspector, meta, _setObjectInspectorConstructor);
40+
return _objectInspector;
41+
}
42+
return base.GetPortInspector(port, meta);
43+
}
44+
45+
}
46+
}

Editor/Widgets/SetLightUnitWidget.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/Coils/SetCoilUnit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace VisualPinball.Unity.VisualScripting
2121
{
2222
[UnitTitle("Set Coil")]
23+
[UnitSurtitle("Gamelogic Engine")]
2324
[UnitCategory("Visual Pinball")]
2425
public class SetCoilUnit : GleUnit
2526
{

Runtime/Nodes/GleUnit.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@ public abstract class GleUnit : Unit, IGleUnit
3333
[DoNotSerialize]
3434
protected IGamelogicEngine Gle;
3535

36+
[DoNotSerialize]
37+
protected Player Player;
38+
3639
protected bool AssertGle(Flow flow)
3740
{
3841
if (Gle != null) {
3942
return true;
4043
}
4144
Gle = flow.stack.gameObject.GetComponentInParent<IGamelogicEngine>();
42-
return Gle == null;
45+
return Gle != null;
46+
}
47+
48+
protected bool AssertPlayer(Flow flow)
49+
{
50+
if (Player != null) {
51+
return true;
52+
}
53+
Player = flow.stack.gameObject.GetComponentInParent<Player>();
54+
return Player != null;
4355
}
4456
}
4557

Runtime/Nodes/Lamps/GetLampUnit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace VisualPinball.Unity.VisualScripting
2121
{
2222
[UnitTitle("Get Lamp Value")]
23+
[UnitSurtitle("Gamelogic Engine")]
2324
[UnitCategory("Visual Pinball")]
2425
public class GetLampUnit : GleUnit
2526
{

0 commit comments

Comments
 (0)