Skip to content

Commit b38e584

Browse files
committed
Add display unit.
1 parent 57fa6d4 commit b38e584

28 files changed

+661
-14
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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(UpdateDisplayUnit))]
26+
public class UpdateDisplayUnitDescriptor : UnitDescriptor<UpdateDisplayUnit>
27+
{
28+
public UpdateDisplayUnitDescriptor(UpdateDisplayUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node takes in a value and sends it to the display connected through the given ID.\n\nDisplay might be able display different types of data, so depending on how you configure your display in the Visual Scripting Gamelogic Engine, you might get multiple data inputs.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay);
38+
39+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
40+
{
41+
base.DefinedPort(port, desc);
42+
43+
switch (port.key) {
44+
case nameof(UpdateDisplayUnit.NumericInput):
45+
desc.summary = "Sets the display to a new numerical value.";
46+
break;
47+
case nameof(UpdateDisplayUnit.TextInput):
48+
desc.summary = "Sets the display to a new text value.";
49+
break;
50+
case nameof(UpdateDisplayUnit.FrameInput):
51+
desc.summary = "Updates the display with new frame data.";
52+
break;
53+
}
54+
}
55+
}
56+
}

Editor/Descriptors/UpdateDisplayUnitDescriptor.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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Collections.Generic;
19+
using System.Linq;
20+
using Unity.VisualScripting;
21+
using UnityEditor;
22+
using UnityEngine;
23+
24+
namespace VisualPinball.Unity.VisualScripting.Editor
25+
{
26+
[Inspector(typeof(DisplayDefinition))]
27+
public class DisplayDefinitionInspector : GleInspector
28+
{
29+
public DisplayDefinitionInspector(Metadata metadata) : base(metadata) { }
30+
31+
protected override void OnGUI(Rect position, GUIContent label)
32+
{
33+
// can't get this from the flow
34+
var gle = Gle;
35+
if (gle != null) {
36+
if (gle.Displays == null || gle.Displays.Count(p => !string.IsNullOrEmpty(p.Id)) == 0) {
37+
ErrorMessage = "No displays defined.";
38+
39+
} else {
40+
var varNames = new List<string> { "None" }
41+
.Concat(gle.Displays.Select(d => d.Id))
42+
.ToArray();
43+
var currentDisplayDef = metadata.value as DisplayDefinition;
44+
var currentIndex = 0;
45+
if (currentDisplayDef != null) {
46+
var displayDef = gle.Displays.FirstOrDefault(p => p.Id == currentDisplayDef!.Id);
47+
currentIndex = displayDef != null ? Array.IndexOf(gle.Displays, displayDef) + 1 : 0;
48+
}
49+
50+
var newIndex = EditorGUI.Popup(position, currentIndex, varNames);
51+
metadata.RecordUndo();
52+
metadata.value = newIndex == 0 ? null : gle.Displays[newIndex - 1];
53+
ErrorMessage = null;
54+
}
55+
}
56+
57+
if (ErrorMessage != null) {
58+
position.height -= EditorGUIUtility.standardVerticalSpacing;
59+
EditorGUI.HelpBox(position, ErrorMessage, MessageType.Error);
60+
}
61+
}
62+
63+
public override float GetAdaptiveWidth() => LudiqGUIUtility.currentInspectorWidth;
64+
65+
protected override float GetHeight(float width, GUIContent label)
66+
{
67+
if (ErrorMessage != null) {
68+
var height = LudiqGUIUtility.GetHelpBoxHeight(ErrorMessage, MessageType.Error, width);
69+
height += EditorGUIUtility.standardVerticalSpacing;
70+
return height;
71+
}
72+
73+
return EditorGUIUtility.singleLineHeight;
74+
}
75+
}
76+
}

Editor/Inspectors/DisplayDefinitionInspector.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/VisualScriptingGamelogicEngineInspector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace VisualPinball.Unity.VisualScripting.Editor
2727
public class VisualScriptingGamelogicEngineInspector : BaseEditor<VisualScriptingGamelogicEngine>
2828
{
2929
private VisualScriptingGamelogicEngine _gle;
30+
private SerializedProperty _displaysProperty;
3031
private SerializedProperty _switchesProperty;
3132
private SerializedProperty _soilsProperty;
3233
private SerializedProperty _lampsProperty;
@@ -39,6 +40,7 @@ private void OnEnable()
3940
{
4041
_gle = target as VisualScriptingGamelogicEngine;
4142

43+
_displaysProperty = serializedObject.FindProperty(nameof(VisualScriptingGamelogicEngine.Displays));
4244
_switchesProperty = serializedObject.FindProperty(nameof(VisualScriptingGamelogicEngine.Switches));
4345
_soilsProperty = serializedObject.FindProperty(nameof(VisualScriptingGamelogicEngine.Coils));
4446
_lampsProperty = serializedObject.FindProperty(nameof(VisualScriptingGamelogicEngine.Lamps));
@@ -51,6 +53,7 @@ public override void OnInspectorGUI()
5153
{
5254
serializedObject.Update();
5355

56+
EditorGUILayout.PropertyField(_displaysProperty);
5457
EditorGUILayout.PropertyField(_switchesProperty);
5558
EditorGUILayout.PropertyField(_soilsProperty);
5659
EditorGUILayout.PropertyField(_lampsProperty);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 UnityEditor;
19+
using UnityEngine;
20+
21+
namespace VisualPinball.Unity.VisualScripting.Editor
22+
{
23+
[CustomPropertyDrawer(typeof(DisplayDefinition))]
24+
public class DisplayDefinitionPropertyDrawer : PropertyDrawer
25+
{
26+
private const float Padding = 2f;
27+
28+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
29+
{
30+
return 5 * (EditorGUIUtility.singleLineHeight + Padding);
31+
}
32+
33+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
34+
{
35+
var idProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Id));
36+
var widthProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Width));
37+
var heightProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Height));
38+
39+
var contentPosition = position;
40+
contentPosition.height = EditorGUIUtility.singleLineHeight;
41+
42+
//EditorGUI.BeginProperty(position, label, property);
43+
EditorGUI.PropertyField(contentPosition, idProperty, new GUIContent("ID:"));
44+
//EditorGUI.EndProperty();
45+
position.y += EditorGUIUtility.singleLineHeight + Padding;
46+
47+
contentPosition = EditorGUI.PrefixLabel(position, new GUIContent("Size:"));
48+
contentPosition.height = EditorGUIUtility.singleLineHeight;
49+
50+
var half = contentPosition.width / 2;
51+
GUI.skin.label.padding = new RectOffset(3, 3, 6, 6);
52+
53+
//show the X and Y from the point
54+
var oldLabelWidth = EditorGUIUtility.labelWidth;
55+
EditorGUIUtility.labelWidth = 14f;
56+
contentPosition.width *= 0.5f;
57+
EditorGUI.indentLevel = 0;
58+
59+
// Begin/end property & change check make each field
60+
// behave correctly when multi-object editing.
61+
EditorGUI.BeginProperty(contentPosition, label, widthProperty);
62+
{
63+
EditorGUI.BeginChangeCheck();
64+
var newVal = EditorGUI.IntField(contentPosition, new GUIContent("W"), widthProperty.intValue);
65+
if (EditorGUI.EndChangeCheck())
66+
widthProperty.intValue = newVal;
67+
}
68+
EditorGUI.EndProperty();
69+
70+
contentPosition.x += half;
71+
EditorGUI.BeginProperty(contentPosition, label, heightProperty);
72+
{
73+
EditorGUI.BeginChangeCheck();
74+
var newVal = EditorGUI.IntField(contentPosition, new GUIContent("H"), heightProperty.intValue);
75+
if (EditorGUI.EndChangeCheck())
76+
heightProperty.intValue = newVal;
77+
}
78+
EditorGUI.EndProperty();
79+
80+
EditorGUIUtility.labelWidth = oldLabelWidth;
81+
82+
var supportsNumericInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsNumericInput));
83+
var supportsTextInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsTextInput));
84+
var supportsImageInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsImageInput));
85+
86+
87+
position.y += EditorGUIUtility.singleLineHeight + Padding;
88+
contentPosition = position;
89+
contentPosition.height = EditorGUIUtility.singleLineHeight;
90+
EditorGUI.PropertyField(contentPosition, supportsNumericInputProperty, new GUIContent("Numeric:"));
91+
contentPosition.y += EditorGUIUtility.singleLineHeight + Padding;
92+
EditorGUI.PropertyField(contentPosition, supportsTextInputProperty, new GUIContent("Text:"));
93+
contentPosition.y += EditorGUIUtility.singleLineHeight + Padding;
94+
EditorGUI.PropertyField(contentPosition, supportsImageInputProperty, new GUIContent("Data:"));
95+
}
96+
}
97+
}
98+

Editor/PropertyDrawers/DisplayDefinitionPropertyDrawer.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/Widgets/GetLampUnitWidget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private IEnumerable<string> GetNameSuggestions()
4949
{
5050
return !GleAvailable
5151
? new List<string>()
52-
: Gle.AvailableLamps.Select(lamp => lamp.Id).ToList();
52+
: Gle.RequestedLamps.Select(lamp => lamp.Id).ToList();
5353
}
5454
}
5555
}

Editor/Widgets/GetSwitchUnitWidget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private IEnumerable<string> GetNameSuggestions()
5858
{
5959
return !GleAvailable
6060
? new List<string>()
61-
: Gle.AvailableSwitches.Select(sw => sw.Id).ToList();
61+
: Gle.RequestedSwitches.Select(sw => sw.Id).ToList();
6262
}
6363
}
6464
}

Editor/Widgets/LampEventUnitWidget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private IEnumerable<string> GetNameSuggestions()
4949
{
5050
return !GleAvailable
5151
? new List<string>()
52-
: Gle.AvailableLamps.Select(lamp => lamp.Id).ToList();
52+
: Gle.RequestedLamps.Select(lamp => lamp.Id).ToList();
5353

5454
}
5555
}

0 commit comments

Comments
 (0)